blob: a57b02d228ef17637895f3c251ae1219ad0df6b5 [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")\
Florin Corascca96182019-07-19 07:34:13 -070027 _(DISPATCH_START, "dispatch start") \
Florin Coras8b20bf52018-06-14 14:55:50 -070028 _(DISPATCH_END, "dispatch end") \
Florin Coras6416e622019-04-03 17:52:43 -070029 _(FREE, "session free") \
Florin Corase69f4952017-03-07 10:06:24 -080030
31typedef enum _session_evt_dbg
32{
33#define _(sym, str) SESSION_EVT_##sym,
34 foreach_session_dbg_evt
35#undef _
36} session_evt_dbg_e;
37
Florin Coras8b20bf52018-06-14 14:55:50 -070038#define SESSION_DEBUG 0 * (TRANSPORT_DEBUG > 0)
Florin Corascca96182019-07-19 07:34:13 -070039#define SESSION_DEQ_EVTS (0)
Florin Corasba13c3b2019-10-30 17:11:53 -070040#define SESSION_DISPATCH_DBG (0)
Florin Coras371ca502018-02-21 12:07:41 -080041#define SESSION_EVT_POLL_DBG (0)
Florin Coras6416e622019-04-03 17:52:43 -070042#define SESSION_SM (0)
Florin Coras6792ec02017-03-13 03:49:51 -070043
Florin Corascea194d2017-10-02 00:18:51 -070044#if SESSION_DEBUG
45
46#define SESSION_DBG(_fmt, _args...) clib_warning (_fmt, ##_args)
Florin Corase69f4952017-03-07 10:06:24 -080047
48#define DEC_SESSION_ETD(_s, _e, _size) \
49 struct \
50 { \
51 u32 data[_size]; \
52 } * ed; \
Florin Corasc1a448b2018-04-20 10:51:49 -070053 transport_connection_t *_tc = session_get_transport (_s); \
Florin Corase69f4952017-03-07 10:06:24 -080054 ed = ELOG_TRACK_DATA (&vlib_global_main.elog_main, \
55 _e, _tc->elog_track)
56
Florin Coras6792ec02017-03-13 03:49:51 -070057#define DEC_SESSION_ED(_e, _size) \
58 struct \
59 { \
60 u32 data[_size]; \
61 } * ed; \
62 ed = ELOG_DATA (&vlib_global_main.elog_main, _e)
Florin Corase69f4952017-03-07 10:06:24 -080063
Florin Coras6416e622019-04-03 17:52:43 -070064#if SESSION_SM
65#define SESSION_EVT_FREE_HANDLER(_s) \
66{ \
67 ELOG_TYPE_DECLARE (_e) = \
68 { \
69 .format = "free: idx %u", \
70 .format_args = "i4", \
71 }; \
72 DEC_SESSION_ETD(_s, _e, 1); \
73 ed->data[0] = _s->session_index; \
74}
75#else
76#define SESSION_EVT_FREE_HANDLER(_s)
77#endif
78
Florin Corascca96182019-07-19 07:34:13 -070079#if SESSION_DEQ_EVTS
80#define SESSION_EVT_DEQ_HANDLER(_s, _now, _max, _has_evt, _ts) \
Florin Corase69f4952017-03-07 10:06:24 -080081{ \
82 ELOG_TYPE_DECLARE (_e) = \
83 { \
Florin Corascca96182019-07-19 07:34:13 -070084 .format = "deq: now %u max %d evt %u ts %d", \
Florin Corase69f4952017-03-07 10:06:24 -080085 .format_args = "i4i4i4i4", \
86 }; \
87 DEC_SESSION_ETD(_s, _e, 4); \
Florin Corascca96182019-07-19 07:34:13 -070088 ed->data[0] = _now; \
89 ed->data[1] = _max; \
90 ed->data[2] = _has_evt; \
91 ed->data[3] = _ts * 1000000.0; \
Florin Corase69f4952017-03-07 10:06:24 -080092}
93
Florin Corascca96182019-07-19 07:34:13 -070094#define SESSION_EVT_ENQ_HANDLER(_s, _len) \
Florin Corase69f4952017-03-07 10:06:24 -080095{ \
96 ELOG_TYPE_DECLARE (_e) = \
97 { \
Florin Corascca96182019-07-19 07:34:13 -070098 .format = "enq: length %d", \
99 .format_args = "i4", \
Florin Corase69f4952017-03-07 10:06:24 -0800100 }; \
Florin Corascca96182019-07-19 07:34:13 -0700101 DEC_SESSION_ETD(_s, _e, 1); \
102 ed->data[0] = _len; \
Florin Corase69f4952017-03-07 10:06:24 -0800103}
Florin Corasba13c3b2019-10-30 17:11:53 -0700104#else
105#define SESSION_EVT_DEQ_HANDLER(_s, _now, _max, _has_evt, _ts)
106#define SESSION_EVT_ENQ_HANDLER(_s, _body)
107#endif /* SESSION_DEQ_NODE_EVTS */
Florin Corase69f4952017-03-07 10:06:24 -0800108
Florin Corasba13c3b2019-10-30 17:11:53 -0700109#if SESSION_DISPATCH_DBG
110#define SESSION_EVT_DEQ_NODE_HANDLER(_wrk, _node_evt, _ntx) \
Florin Coras6792ec02017-03-13 03:49:51 -0700111{ \
112 ELOG_TYPE_DECLARE (_e) = \
113 { \
Florin Corasba13c3b2019-10-30 17:11:53 -0700114 .format = "dispatch: %s pkts %u re-entry: %u dispatch %u", \
115 .format_args = "t4i4i4i4", \
Florin Coras6792ec02017-03-13 03:49:51 -0700116 .n_enum_strings = 2, \
117 .enum_strings = { \
118 "start", \
119 "end", \
120 }, \
121 }; \
Florin Corasba13c3b2019-10-30 17:11:53 -0700122 DEC_SESSION_ED(_e, 4); \
Florin Coras6792ec02017-03-13 03:49:51 -0700123 ed->data[0] = _node_evt; \
Florin Corasba13c3b2019-10-30 17:11:53 -0700124 ed->data[1] = _ntx; \
125 ed->data[2] = (_wrk->last_vlib_time - _wrk->last_event_poll) \
126 * 1000000.0; \
127 ed->data[3] = (vlib_time_now (_wrk->vm) - _wrk->last_vlib_time) \
128 * 1000000.0; \
Florin Coras6792ec02017-03-13 03:49:51 -0700129}
130#else
Florin Corasba13c3b2019-10-30 17:11:53 -0700131#define SESSION_EVT_DEQ_NODE_HANDLER(_node_evt, _ntx)
132#endif /* SESSION_DISPATCH_DBG */
Florin Coras6792ec02017-03-13 03:49:51 -0700133
Florin Corascea194d2017-10-02 00:18:51 -0700134#if SESSION_EVT_POLL_DBG && SESSION_DEBUG > 1
Florin Corascca96182019-07-19 07:34:13 -0700135#define SESSION_EVT_POLL_GAP(_wrk) \
Florin Coras3e350af2017-03-30 02:54:28 -0700136{ \
137 ELOG_TYPE_DECLARE (_e) = \
138 { \
Florin Corasc1a448b2018-04-20 10:51:49 -0700139 .format = "nixon-gap: %d us", \
Florin Coras3e350af2017-03-30 02:54:28 -0700140 .format_args = "i4", \
141 }; \
142 DEC_SESSION_ED(_e, 1); \
Florin Corasba13c3b2019-10-30 17:11:53 -0700143 ed->data[0] = (u32) ((_wrk->last_vlib_time - _wrk->last_event_poll) \
144 *1000000.0); \
Florin Coras3e350af2017-03-30 02:54:28 -0700145}
Florin Corascca96182019-07-19 07:34:13 -0700146#define SESSION_EVT_POLL_GAP_TRACK_HANDLER(_wrk) \
Florin Coras3e350af2017-03-30 02:54:28 -0700147{ \
Florin Corasba13c3b2019-10-30 17:11:53 -0700148 if (PREDICT_TRUE (_wrk->last_event_poll != 0.0)) \
149 if (_wrk->last_vlib_time > _wrk->last_event_poll + 500e-6) \
150 SESSION_EVT_POLL_GAP(_wrk); \
151 _wrk->last_event_poll = _wrk->last_vlib_time; \
Florin Coras3e350af2017-03-30 02:54:28 -0700152}
153
Florin Corascca96182019-07-19 07:34:13 -0700154#define SESSION_EVT_POLL_DISPATCH_TIME_HANDLER(_wrk) \
Florin Coras8b20bf52018-06-14 14:55:50 -0700155{ \
Florin Corascca96182019-07-19 07:34:13 -0700156 f64 diff = vlib_time_now (vlib_get_main ()) - _wrk->last_event_poll; \
Florin Coras8b20bf52018-06-14 14:55:50 -0700157 if (diff > 5e-2) \
158 { \
159 ELOG_TYPE_DECLARE (_e) = \
160 { \
161 .format = "dispatch time: %d us", \
162 .format_args = "i4", \
163 }; \
164 DEC_SESSION_ED(_e, 1); \
165 ed->data[0] = diff *1000000.0; \
166 } \
167}
168
Florin Coras3e350af2017-03-30 02:54:28 -0700169#else
Florin Corascca96182019-07-19 07:34:13 -0700170#define SESSION_EVT_POLL_GAP(_wrk)
171#define SESSION_EVT_POLL_GAP_TRACK_HANDLER(_wrk)
172#define SESSION_EVT_POLL_DISPATCH_TIME_HANDLER(_wrk)
Florin Corascea194d2017-10-02 00:18:51 -0700173#endif /* SESSION_EVT_POLL_DBG */
Florin Coras3e350af2017-03-30 02:54:28 -0700174
Florin Corascca96182019-07-19 07:34:13 -0700175#define SESSION_EVT_DISPATCH_START_HANDLER(_wrk) \
Florin Coras8b20bf52018-06-14 14:55:50 -0700176{ \
Florin Corascca96182019-07-19 07:34:13 -0700177 if (SESSION_DEQ_EVTS > 1) \
Florin Corasba13c3b2019-10-30 17:11:53 -0700178 SESSION_EVT_DEQ_NODE_HANDLER (_wrk, 0, 0); \
Florin Corascca96182019-07-19 07:34:13 -0700179 SESSION_EVT_POLL_GAP_TRACK_HANDLER (wrk); \
180}
181
182#define SESSION_EVT_DISPATCH_END_HANDLER(_wrk, _ntx) \
183{ \
Florin Corasba13c3b2019-10-30 17:11:53 -0700184 if (_ntx) \
185 SESSION_EVT_DEQ_NODE_HANDLER (_wrk, 1, _ntx); \
Florin Corascca96182019-07-19 07:34:13 -0700186 SESSION_EVT_POLL_DISPATCH_TIME_HANDLER(_wrk); \
Florin Corasba13c3b2019-10-30 17:11:53 -0700187 _wrk->last_event_poll = vlib_time_now (_wrk->vm); \
Florin Coras8b20bf52018-06-14 14:55:50 -0700188}
189
Florin Corase69f4952017-03-07 10:06:24 -0800190#define CONCAT_HELPER(_a, _b) _a##_b
191#define CC(_a, _b) CONCAT_HELPER(_a, _b)
Florin Corascca96182019-07-19 07:34:13 -0700192#define SESSION_EVT(_evt, _args...) CC(_evt, _HANDLER)(_args)
Florin Corase69f4952017-03-07 10:06:24 -0800193
194#else
Florin Corascca96182019-07-19 07:34:13 -0700195#define SESSION_EVT(_evt, _args...)
Florin Corascea194d2017-10-02 00:18:51 -0700196#define SESSION_DBG(_fmt, _args...)
197#endif /* SESSION_DEBUG */
Florin Corase69f4952017-03-07 10:06:24 -0800198
199#endif /* SRC_VNET_SESSION_SESSION_DEBUG_H_ */
200/*
201 * fd.io coding-style-patch-verification: ON
202 *
203 * Local Variables:
204 * eval: (c-set-style "gnu")
205 * End:
206 */