blob: a26cd7f2636e1823c86bb70815b9cf1a3518b853 [file] [log] [blame]
Florin Corase69f4952017-03-07 10:06:24 -08001/*
Florin Coras288eaab2019-02-03 15:26:14 -08002 * Copyright (c) 2017-2019 Cisco and/or its affiliates.
Florin Corase69f4952017-03-07 10:06:24 -08003 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#ifndef SRC_VNET_SESSION_SESSION_DEBUG_H_
16#define SRC_VNET_SESSION_SESSION_DEBUG_H_
17
18#include <vnet/session/transport.h>
Florin Corase69f4952017-03-07 10:06:24 -080019#include <vlib/vlib.h>
20
21#define foreach_session_dbg_evt \
22 _(ENQ, "enqueue") \
Florin Coras6792ec02017-03-13 03:49:51 -070023 _(DEQ, "dequeue") \
Florin Coras3e350af2017-03-30 02:54:28 -070024 _(DEQ_NODE, "dequeue") \
25 _(POLL_GAP_TRACK, "poll gap track") \
Florin Coras8b20bf52018-06-14 14:55:50 -070026 _(POLL_DISPATCH_TIME, "dispatch time")\
27 _(DISPATCH_END, "dispatch end") \
Florin Coras6416e622019-04-03 17:52:43 -070028 _(FREE, "session free") \
Florin Corase69f4952017-03-07 10:06:24 -080029
30typedef enum _session_evt_dbg
31{
32#define _(sym, str) SESSION_EVT_##sym,
33 foreach_session_dbg_evt
34#undef _
35} session_evt_dbg_e;
36
Florin Coras8b20bf52018-06-14 14:55:50 -070037#define SESSION_DEBUG 0 * (TRANSPORT_DEBUG > 0)
Florin Coras6792ec02017-03-13 03:49:51 -070038#define SESSION_DEQ_NODE_EVTS (0)
Florin Coras371ca502018-02-21 12:07:41 -080039#define SESSION_EVT_POLL_DBG (0)
Florin Coras6416e622019-04-03 17:52:43 -070040#define SESSION_SM (0)
Florin Coras6792ec02017-03-13 03:49:51 -070041
Florin Corascea194d2017-10-02 00:18:51 -070042#if SESSION_DEBUG
43
44#define SESSION_DBG(_fmt, _args...) clib_warning (_fmt, ##_args)
Florin Corase69f4952017-03-07 10:06:24 -080045
46#define DEC_SESSION_ETD(_s, _e, _size) \
47 struct \
48 { \
49 u32 data[_size]; \
50 } * ed; \
Florin Corasc1a448b2018-04-20 10:51:49 -070051 transport_connection_t *_tc = session_get_transport (_s); \
Florin Corase69f4952017-03-07 10:06:24 -080052 ed = ELOG_TRACK_DATA (&vlib_global_main.elog_main, \
53 _e, _tc->elog_track)
54
Florin Coras6792ec02017-03-13 03:49:51 -070055#define DEC_SESSION_ED(_e, _size) \
56 struct \
57 { \
58 u32 data[_size]; \
59 } * ed; \
60 ed = ELOG_DATA (&vlib_global_main.elog_main, _e)
Florin Corase69f4952017-03-07 10:06:24 -080061
Florin Coras6416e622019-04-03 17:52:43 -070062#if SESSION_SM
63#define SESSION_EVT_FREE_HANDLER(_s) \
64{ \
65 ELOG_TYPE_DECLARE (_e) = \
66 { \
67 .format = "free: idx %u", \
68 .format_args = "i4", \
69 }; \
70 DEC_SESSION_ETD(_s, _e, 1); \
71 ed->data[0] = _s->session_index; \
72}
73#else
74#define SESSION_EVT_FREE_HANDLER(_s)
75#endif
76
Florin Coras8b20bf52018-06-14 14:55:50 -070077#if SESSION_DEQ_NODE_EVTS && SESSION_DEBUG > 1
Florin Corase69f4952017-03-07 10:06:24 -080078#define SESSION_EVT_DEQ_HANDLER(_s, _body) \
79{ \
80 ELOG_TYPE_DECLARE (_e) = \
81 { \
82 .format = "deq: id %d len %d rd %d wnd %d", \
83 .format_args = "i4i4i4i4", \
84 }; \
85 DEC_SESSION_ETD(_s, _e, 4); \
86 do { _body; } while (0); \
87}
88
89#define SESSION_EVT_ENQ_HANDLER(_s, _body) \
90{ \
91 ELOG_TYPE_DECLARE (_e) = \
92 { \
93 .format = "enq: id %d length %d", \
94 .format_args = "i4i4", \
95 }; \
96 DEC_SESSION_ETD(_s, _e, 2); \
97 do { _body; } while (0); \
98}
99
Florin Coras6792ec02017-03-13 03:49:51 -0700100#define SESSION_EVT_DEQ_NODE_HANDLER(_node_evt) \
101{ \
102 ELOG_TYPE_DECLARE (_e) = \
103 { \
104 .format = "deq-node: %s", \
105 .format_args = "t4", \
106 .n_enum_strings = 2, \
107 .enum_strings = { \
108 "start", \
109 "end", \
110 }, \
111 }; \
112 DEC_SESSION_ED(_e, 1); \
113 ed->data[0] = _node_evt; \
114}
115#else
Florin Coras8b20bf52018-06-14 14:55:50 -0700116#define SESSION_EVT_DEQ_HANDLER(_s, _body)
117#define SESSION_EVT_ENQ_HANDLER(_s, _body)
Florin Coras6792ec02017-03-13 03:49:51 -0700118#define SESSION_EVT_DEQ_NODE_HANDLER(_node_evt)
Florin Corascea194d2017-10-02 00:18:51 -0700119#endif /* SESSION_DEQ_NODE_EVTS */
Florin Coras6792ec02017-03-13 03:49:51 -0700120
Florin Corascea194d2017-10-02 00:18:51 -0700121#if SESSION_EVT_POLL_DBG && SESSION_DEBUG > 1
Florin Corasc1a448b2018-04-20 10:51:49 -0700122#define SESSION_EVT_POLL_GAP(_smm, _ti) \
Florin Coras3e350af2017-03-30 02:54:28 -0700123{ \
124 ELOG_TYPE_DECLARE (_e) = \
125 { \
Florin Corasc1a448b2018-04-20 10:51:49 -0700126 .format = "nixon-gap: %d us", \
Florin Coras3e350af2017-03-30 02:54:28 -0700127 .format_args = "i4", \
128 }; \
129 DEC_SESSION_ED(_e, 1); \
130 ed->data[0] = (u32) ((now - \
Florin Corasc1a448b2018-04-20 10:51:49 -0700131 _smm->last_event_poll_by_thread[_ti])*1000000.0); \
Florin Coras3e350af2017-03-30 02:54:28 -0700132}
Florin Corasc1a448b2018-04-20 10:51:49 -0700133#define SESSION_EVT_POLL_GAP_TRACK_HANDLER(_smm, _ti) \
Florin Coras3e350af2017-03-30 02:54:28 -0700134{ \
Florin Corasc1a448b2018-04-20 10:51:49 -0700135 if (PREDICT_TRUE (smm->last_event_poll_by_thread[_ti] != 0.0)) \
136 if (now > smm->last_event_poll_by_thread[_ti] + 500e-6) \
137 SESSION_EVT_POLL_GAP(smm, _ti); \
138 _smm->last_event_poll_by_thread[_ti] = now; \
Florin Coras3e350af2017-03-30 02:54:28 -0700139}
140
Florin Coras8b20bf52018-06-14 14:55:50 -0700141#define SESSION_EVT_POLL_DISPATCH_TIME_HANDLER(_smm, _ti) \
142{ \
143 f64 diff = vlib_time_now (vlib_get_main ()) - \
144 _smm->last_event_poll_by_thread[_ti]; \
145 if (diff > 5e-2) \
146 { \
147 ELOG_TYPE_DECLARE (_e) = \
148 { \
149 .format = "dispatch time: %d us", \
150 .format_args = "i4", \
151 }; \
152 DEC_SESSION_ED(_e, 1); \
153 ed->data[0] = diff *1000000.0; \
154 } \
155}
156
Florin Coras3e350af2017-03-30 02:54:28 -0700157#else
158#define SESSION_EVT_POLL_GAP(_smm, _my_thread_index)
159#define SESSION_EVT_POLL_GAP_TRACK_HANDLER(_smm, _my_thread_index)
Florin Coras8b20bf52018-06-14 14:55:50 -0700160#define SESSION_EVT_POLL_DISPATCH_TIME_HANDLER(_smm, _ti)
Florin Corascea194d2017-10-02 00:18:51 -0700161#endif /* SESSION_EVT_POLL_DBG */
Florin Coras3e350af2017-03-30 02:54:28 -0700162
Florin Coras8b20bf52018-06-14 14:55:50 -0700163#define SESSION_EVT_DISPATCH_END_HANDLER(_smm, _ti) \
164{ \
165 SESSION_EVT_DEQ_NODE_HANDLER(1); \
166 SESSION_EVT_POLL_DISPATCH_TIME_HANDLER(_smm, _ti); \
167}
168
Florin Corase69f4952017-03-07 10:06:24 -0800169#define CONCAT_HELPER(_a, _b) _a##_b
170#define CC(_a, _b) CONCAT_HELPER(_a, _b)
Florin Coras6792ec02017-03-13 03:49:51 -0700171#define SESSION_EVT_DBG(_evt, _args...) CC(_evt, _HANDLER)(_args)
Florin Corase69f4952017-03-07 10:06:24 -0800172
173#else
Florin Coras6792ec02017-03-13 03:49:51 -0700174#define SESSION_EVT_DBG(_evt, _args...)
Florin Corascea194d2017-10-02 00:18:51 -0700175#define SESSION_DBG(_fmt, _args...)
176#endif /* SESSION_DEBUG */
Florin Corase69f4952017-03-07 10:06:24 -0800177
178#endif /* SRC_VNET_SESSION_SESSION_DEBUG_H_ */
179/*
180 * fd.io coding-style-patch-verification: ON
181 *
182 * Local Variables:
183 * eval: (c-set-style "gnu")
184 * End:
185 */