tcp: do not delete session on establish pop
[vpp.git] / src / vnet / session / session_debug.h
1 /*
2  * Copyright (c) 2017-2019 Cisco and/or its affiliates.
3  * 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>
19 #include <vlib/vlib.h>
20
21 #define foreach_session_dbg_evt         \
22   _(ENQ, "enqueue")                     \
23   _(DEQ, "dequeue")                     \
24   _(DEQ_NODE, "dequeue")                \
25   _(POLL_GAP_TRACK, "poll gap track")   \
26   _(POLL_DISPATCH_TIME, "dispatch time")\
27   _(DISPATCH_END, "dispatch end")       \
28   _(FREE, "session free")               \
29
30 typedef 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
37 #define SESSION_DEBUG 0 * (TRANSPORT_DEBUG > 0)
38 #define SESSION_DEQ_NODE_EVTS (0)
39 #define SESSION_EVT_POLL_DBG (0)
40 #define SESSION_SM (0)
41
42 #if SESSION_DEBUG
43
44 #define SESSION_DBG(_fmt, _args...) clib_warning (_fmt, ##_args)
45
46 #define DEC_SESSION_ETD(_s, _e, _size)                                  \
47   struct                                                                \
48   {                                                                     \
49     u32 data[_size];                                                    \
50   } * ed;                                                               \
51   transport_connection_t *_tc = session_get_transport (_s);             \
52   ed = ELOG_TRACK_DATA (&vlib_global_main.elog_main,                    \
53                         _e, _tc->elog_track)
54
55 #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)
61
62 #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
77 #if SESSION_DEQ_NODE_EVTS && SESSION_DEBUG > 1
78 #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
100 #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
116 #define SESSION_EVT_DEQ_HANDLER(_s, _body)
117 #define SESSION_EVT_ENQ_HANDLER(_s, _body)
118 #define SESSION_EVT_DEQ_NODE_HANDLER(_node_evt)
119 #endif /* SESSION_DEQ_NODE_EVTS */
120
121 #if SESSION_EVT_POLL_DBG && SESSION_DEBUG > 1
122 #define SESSION_EVT_POLL_GAP(_smm, _ti)                                 \
123 {                                                                       \
124   ELOG_TYPE_DECLARE (_e) =                                              \
125   {                                                                     \
126     .format = "nixon-gap: %d us",                                       \
127     .format_args = "i4",                                                \
128   };                                                                    \
129   DEC_SESSION_ED(_e, 1);                                                \
130   ed->data[0] = (u32) ((now -                                           \
131       _smm->last_event_poll_by_thread[_ti])*1000000.0);                 \
132 }
133 #define SESSION_EVT_POLL_GAP_TRACK_HANDLER(_smm, _ti)                   \
134 {                                                                       \
135   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;                           \
139 }
140
141 #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
157 #else
158 #define SESSION_EVT_POLL_GAP(_smm, _my_thread_index)
159 #define SESSION_EVT_POLL_GAP_TRACK_HANDLER(_smm, _my_thread_index)
160 #define SESSION_EVT_POLL_DISPATCH_TIME_HANDLER(_smm, _ti)
161 #endif /* SESSION_EVT_POLL_DBG */
162
163 #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
169 #define CONCAT_HELPER(_a, _b) _a##_b
170 #define CC(_a, _b) CONCAT_HELPER(_a, _b)
171 #define SESSION_EVT_DBG(_evt, _args...) CC(_evt, _HANDLER)(_args)
172
173 #else
174 #define SESSION_EVT_DBG(_evt, _args...)
175 #define SESSION_DBG(_fmt, _args...)
176 #endif /* SESSION_DEBUG */
177
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  */