blob: 228c1b36ac6deb022c98941fcf755450adb93997 [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 Coras371ca502018-02-21 12:07:41 -080040#define SESSION_EVT_POLL_DBG (0)
Florin Coras6416e622019-04-03 17:52:43 -070041#define SESSION_SM (0)
Florin Coras6792ec02017-03-13 03:49:51 -070042
Florin Corascea194d2017-10-02 00:18:51 -070043#if SESSION_DEBUG
44
45#define SESSION_DBG(_fmt, _args...) clib_warning (_fmt, ##_args)
Florin Corase69f4952017-03-07 10:06:24 -080046
47#define DEC_SESSION_ETD(_s, _e, _size) \
48 struct \
49 { \
50 u32 data[_size]; \
51 } * ed; \
Florin Corasc1a448b2018-04-20 10:51:49 -070052 transport_connection_t *_tc = session_get_transport (_s); \
Florin Corase69f4952017-03-07 10:06:24 -080053 ed = ELOG_TRACK_DATA (&vlib_global_main.elog_main, \
54 _e, _tc->elog_track)
55
Florin Coras6792ec02017-03-13 03:49:51 -070056#define DEC_SESSION_ED(_e, _size) \
57 struct \
58 { \
59 u32 data[_size]; \
60 } * ed; \
61 ed = ELOG_DATA (&vlib_global_main.elog_main, _e)
Florin Corase69f4952017-03-07 10:06:24 -080062
Florin Coras6416e622019-04-03 17:52:43 -070063#if SESSION_SM
64#define SESSION_EVT_FREE_HANDLER(_s) \
65{ \
66 ELOG_TYPE_DECLARE (_e) = \
67 { \
68 .format = "free: idx %u", \
69 .format_args = "i4", \
70 }; \
71 DEC_SESSION_ETD(_s, _e, 1); \
72 ed->data[0] = _s->session_index; \
73}
74#else
75#define SESSION_EVT_FREE_HANDLER(_s)
76#endif
77
Florin Corascca96182019-07-19 07:34:13 -070078#if SESSION_DEQ_EVTS
79#define SESSION_EVT_DEQ_HANDLER(_s, _now, _max, _has_evt, _ts) \
Florin Corase69f4952017-03-07 10:06:24 -080080{ \
81 ELOG_TYPE_DECLARE (_e) = \
82 { \
Florin Corascca96182019-07-19 07:34:13 -070083 .format = "deq: now %u max %d evt %u ts %d", \
Florin Corase69f4952017-03-07 10:06:24 -080084 .format_args = "i4i4i4i4", \
85 }; \
86 DEC_SESSION_ETD(_s, _e, 4); \
Florin Corascca96182019-07-19 07:34:13 -070087 ed->data[0] = _now; \
88 ed->data[1] = _max; \
89 ed->data[2] = _has_evt; \
90 ed->data[3] = _ts * 1000000.0; \
Florin Corase69f4952017-03-07 10:06:24 -080091}
92
Florin Corascca96182019-07-19 07:34:13 -070093#define SESSION_EVT_ENQ_HANDLER(_s, _len) \
Florin Corase69f4952017-03-07 10:06:24 -080094{ \
95 ELOG_TYPE_DECLARE (_e) = \
96 { \
Florin Corascca96182019-07-19 07:34:13 -070097 .format = "enq: length %d", \
98 .format_args = "i4", \
Florin Corase69f4952017-03-07 10:06:24 -080099 }; \
Florin Corascca96182019-07-19 07:34:13 -0700100 DEC_SESSION_ETD(_s, _e, 1); \
101 ed->data[0] = _len; \
Florin Corase69f4952017-03-07 10:06:24 -0800102}
103
Florin Coras6792ec02017-03-13 03:49:51 -0700104#define SESSION_EVT_DEQ_NODE_HANDLER(_node_evt) \
105{ \
106 ELOG_TYPE_DECLARE (_e) = \
107 { \
108 .format = "deq-node: %s", \
109 .format_args = "t4", \
110 .n_enum_strings = 2, \
111 .enum_strings = { \
112 "start", \
113 "end", \
114 }, \
115 }; \
116 DEC_SESSION_ED(_e, 1); \
117 ed->data[0] = _node_evt; \
118}
119#else
Florin Coras8b20bf52018-06-14 14:55:50 -0700120#define SESSION_EVT_DEQ_HANDLER(_s, _body)
121#define SESSION_EVT_ENQ_HANDLER(_s, _body)
Florin Coras6792ec02017-03-13 03:49:51 -0700122#define SESSION_EVT_DEQ_NODE_HANDLER(_node_evt)
Florin Corascea194d2017-10-02 00:18:51 -0700123#endif /* SESSION_DEQ_NODE_EVTS */
Florin Coras6792ec02017-03-13 03:49:51 -0700124
Florin Corascea194d2017-10-02 00:18:51 -0700125#if SESSION_EVT_POLL_DBG && SESSION_DEBUG > 1
Florin Corascca96182019-07-19 07:34:13 -0700126#define SESSION_EVT_POLL_GAP(_wrk) \
Florin Coras3e350af2017-03-30 02:54:28 -0700127{ \
128 ELOG_TYPE_DECLARE (_e) = \
129 { \
Florin Corasc1a448b2018-04-20 10:51:49 -0700130 .format = "nixon-gap: %d us", \
Florin Coras3e350af2017-03-30 02:54:28 -0700131 .format_args = "i4", \
132 }; \
133 DEC_SESSION_ED(_e, 1); \
Florin Corascca96182019-07-19 07:34:13 -0700134 ed->data[0] = (u32) ((now - _wrk->last_event_poll)*1000000.0); \
Florin Coras3e350af2017-03-30 02:54:28 -0700135}
Florin Corascca96182019-07-19 07:34:13 -0700136#define SESSION_EVT_POLL_GAP_TRACK_HANDLER(_wrk) \
Florin Coras3e350af2017-03-30 02:54:28 -0700137{ \
Florin Corascca96182019-07-19 07:34:13 -0700138 if (PREDICT_TRUE (smm->last_event_poll != 0.0)) \
139 if (now > smm->last_event_poll + 500e-6) \
Florin Corasc1a448b2018-04-20 10:51:49 -0700140 SESSION_EVT_POLL_GAP(smm, _ti); \
Florin Corascca96182019-07-19 07:34:13 -0700141 _wrk->last_event_poll = now; \
Florin Coras3e350af2017-03-30 02:54:28 -0700142}
143
Florin Corascca96182019-07-19 07:34:13 -0700144#define SESSION_EVT_POLL_DISPATCH_TIME_HANDLER(_wrk) \
Florin Coras8b20bf52018-06-14 14:55:50 -0700145{ \
Florin Corascca96182019-07-19 07:34:13 -0700146 f64 diff = vlib_time_now (vlib_get_main ()) - _wrk->last_event_poll; \
Florin Coras8b20bf52018-06-14 14:55:50 -0700147 if (diff > 5e-2) \
148 { \
149 ELOG_TYPE_DECLARE (_e) = \
150 { \
151 .format = "dispatch time: %d us", \
152 .format_args = "i4", \
153 }; \
154 DEC_SESSION_ED(_e, 1); \
155 ed->data[0] = diff *1000000.0; \
156 } \
157}
158
Florin Coras3e350af2017-03-30 02:54:28 -0700159#else
Florin Corascca96182019-07-19 07:34:13 -0700160#define SESSION_EVT_POLL_GAP(_wrk)
161#define SESSION_EVT_POLL_GAP_TRACK_HANDLER(_wrk)
162#define SESSION_EVT_POLL_DISPATCH_TIME_HANDLER(_wrk)
Florin Corascea194d2017-10-02 00:18:51 -0700163#endif /* SESSION_EVT_POLL_DBG */
Florin Coras3e350af2017-03-30 02:54:28 -0700164
Florin Corascca96182019-07-19 07:34:13 -0700165#define SESSION_EVT_DISPATCH_START_HANDLER(_wrk) \
Florin Coras8b20bf52018-06-14 14:55:50 -0700166{ \
Florin Corascca96182019-07-19 07:34:13 -0700167 if (SESSION_DEQ_EVTS > 1) \
168 SESSION_EVT_DEQ_NODE_HANDLER (0); \
169 SESSION_EVT_POLL_GAP_TRACK_HANDLER (wrk); \
170}
171
172#define SESSION_EVT_DISPATCH_END_HANDLER(_wrk, _ntx) \
173{ \
174 if (SESSION_DEQ_EVTS > 1 || _ntx) \
175 SESSION_EVT_DEQ_NODE_HANDLER (1); \
176 SESSION_EVT_POLL_DISPATCH_TIME_HANDLER(_wrk); \
Florin Coras8b20bf52018-06-14 14:55:50 -0700177}
178
Florin Corase69f4952017-03-07 10:06:24 -0800179#define CONCAT_HELPER(_a, _b) _a##_b
180#define CC(_a, _b) CONCAT_HELPER(_a, _b)
Florin Corascca96182019-07-19 07:34:13 -0700181#define SESSION_EVT(_evt, _args...) CC(_evt, _HANDLER)(_args)
Florin Corase69f4952017-03-07 10:06:24 -0800182
183#else
Florin Corascca96182019-07-19 07:34:13 -0700184#define SESSION_EVT(_evt, _args...)
Florin Corascea194d2017-10-02 00:18:51 -0700185#define SESSION_DBG(_fmt, _args...)
186#endif /* SESSION_DEBUG */
Florin Corase69f4952017-03-07 10:06:24 -0800187
188#endif /* SRC_VNET_SESSION_SESSION_DEBUG_H_ */
189/*
190 * fd.io coding-style-patch-verification: ON
191 *
192 * Local Variables:
193 * eval: (c-set-style "gnu")
194 * End:
195 */