blob: eb11f1a00b91aec1a6f5c14825d92483fab8f763 [file] [log] [blame]
Florin Corase69f4952017-03-07 10:06:24 -08001/*
2 * Copyright (c) 2017 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>
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 Corase69f4952017-03-07 10:06:24 -080026
27typedef enum _session_evt_dbg
28{
29#define _(sym, str) SESSION_EVT_##sym,
30 foreach_session_dbg_evt
31#undef _
32} session_evt_dbg_e;
33
Florin Coras6792ec02017-03-13 03:49:51 -070034#define SESSION_DBG (0)
35#define SESSION_DEQ_NODE_EVTS (0)
Florin Coras3e350af2017-03-30 02:54:28 -070036#define SESSION_EVT_POLL_DBG (1)
Florin Coras6792ec02017-03-13 03:49:51 -070037
38#if TRANSPORT_DEBUG && SESSION_DBG
Florin Corase69f4952017-03-07 10:06:24 -080039
40#define DEC_SESSION_ETD(_s, _e, _size) \
41 struct \
42 { \
43 u32 data[_size]; \
44 } * ed; \
45 transport_proto_vft_t *vft = \
46 session_get_transport_vft (_s->session_type); \
47 transport_connection_t *_tc = \
48 vft->get_connection (_s->connection_index, _s->thread_index); \
49 ed = ELOG_TRACK_DATA (&vlib_global_main.elog_main, \
50 _e, _tc->elog_track)
51
Florin Coras6792ec02017-03-13 03:49:51 -070052#define DEC_SESSION_ED(_e, _size) \
53 struct \
54 { \
55 u32 data[_size]; \
56 } * ed; \
57 ed = ELOG_DATA (&vlib_global_main.elog_main, _e)
Florin Corase69f4952017-03-07 10:06:24 -080058
59#define SESSION_EVT_DEQ_HANDLER(_s, _body) \
60{ \
61 ELOG_TYPE_DECLARE (_e) = \
62 { \
63 .format = "deq: id %d len %d rd %d wnd %d", \
64 .format_args = "i4i4i4i4", \
65 }; \
66 DEC_SESSION_ETD(_s, _e, 4); \
67 do { _body; } while (0); \
68}
69
70#define SESSION_EVT_ENQ_HANDLER(_s, _body) \
71{ \
72 ELOG_TYPE_DECLARE (_e) = \
73 { \
74 .format = "enq: id %d length %d", \
75 .format_args = "i4i4", \
76 }; \
77 DEC_SESSION_ETD(_s, _e, 2); \
78 do { _body; } while (0); \
79}
80
Florin Coras6792ec02017-03-13 03:49:51 -070081#if SESSION_DEQ_NODE_EVTS
82#define SESSION_EVT_DEQ_NODE_HANDLER(_node_evt) \
83{ \
84 ELOG_TYPE_DECLARE (_e) = \
85 { \
86 .format = "deq-node: %s", \
87 .format_args = "t4", \
88 .n_enum_strings = 2, \
89 .enum_strings = { \
90 "start", \
91 "end", \
92 }, \
93 }; \
94 DEC_SESSION_ED(_e, 1); \
95 ed->data[0] = _node_evt; \
96}
97#else
98#define SESSION_EVT_DEQ_NODE_HANDLER(_node_evt)
99#endif
100
Florin Coras3e350af2017-03-30 02:54:28 -0700101#if SESSION_DBG && SESSION_EVT_POLL_DBG
102#define SESSION_EVT_POLL_GAP(_smm, _my_thread_index) \
103{ \
104 ELOG_TYPE_DECLARE (_e) = \
105 { \
106 .format = "nixon-gap: %d MS", \
107 .format_args = "i4", \
108 }; \
109 DEC_SESSION_ED(_e, 1); \
110 ed->data[0] = (u32) ((now - \
111 _smm->last_event_poll_by_thread[my_thread_index])*1000.0); \
112}
113#define SESSION_EVT_POLL_GAP_TRACK_HANDLER(_smm, _my_thread_index) \
114{ \
115 if (PREDICT_TRUE( \
116 smm->last_event_poll_by_thread[my_thread_index] != 0.0)) \
117 if (now > smm->last_event_poll_by_thread[_my_thread_index] + 500e-6)\
118 SESSION_EVT_POLL_GAP(smm, my_thread_index); \
119 _smm->last_event_poll_by_thread[my_thread_index] = now; \
120}
121
122#else
123#define SESSION_EVT_POLL_GAP(_smm, _my_thread_index)
124#define SESSION_EVT_POLL_GAP_TRACK_HANDLER(_smm, _my_thread_index)
125#endif
126
Florin Corase69f4952017-03-07 10:06:24 -0800127#define CONCAT_HELPER(_a, _b) _a##_b
128#define CC(_a, _b) CONCAT_HELPER(_a, _b)
Florin Coras6792ec02017-03-13 03:49:51 -0700129#define SESSION_EVT_DBG(_evt, _args...) CC(_evt, _HANDLER)(_args)
Florin Corase69f4952017-03-07 10:06:24 -0800130
131#else
Florin Coras6792ec02017-03-13 03:49:51 -0700132#define SESSION_EVT_DBG(_evt, _args...)
Florin Corase69f4952017-03-07 10:06:24 -0800133#endif
134
135#endif /* SRC_VNET_SESSION_SESSION_DEBUG_H_ */
136/*
137 * fd.io coding-style-patch-verification: ON
138 *
139 * Local Variables:
140 * eval: (c-set-style "gnu")
141 * End:
142 */