blob: e4efe1b244e30ecad7f71096be4f21d326e8f97a [file] [log] [blame]
Florin Coras11166672020-04-13 01:20:25 +00001/*
2 * Copyright (c) 2020 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
16#include <vnet/session/session_debug.h>
17#include <vnet/session/session.h>
18
19#if SESSION_DEBUG > 0
20
21session_dbg_main_t session_dbg_main;
22
23static clib_error_t *
24show_session_dbg_clock_cycles_fn (vlib_main_t * vm, unformat_input_t * input,
25 vlib_cli_command_t * cmd)
26{
27 u32 thread;
28
29 if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
30 return clib_error_return (0, "unknown input `%U'", format_unformat_error,
31 input);
32
33 for (thread = 0; thread < vec_len (session_dbg_main.wrk); thread++)
34 {
35 vlib_cli_output (vm, "Threads %u:\n", thread);
36 session_dbg_evts_t *sdm = &session_dbg_main.wrk[thread];
37
38#define _(sym, disp, type, str) \
39 if(disp) \
40 { \
41 if (!type) \
42 vlib_cli_output (vm, "\t %25s : %12lu ", str, \
43 sdm->counters[SESS_Q_##sym].u64); \
44 else \
45 vlib_cli_output (vm, "\t %25s : %12.3f ", str, \
46 sdm->counters[SESS_Q_##sym].f64); \
47 }
48 foreach_session_events
49#undef _
50 }
51 return 0;
52}
53
54
55/* *INDENT-OFF* */
56VLIB_CLI_COMMAND (show_session_dbg_clock_cycles_command, static) =
57{
58 .path = "show session dbg clock_cycles",
59 .short_help = "show session dbg clock_cycles",
60 .function = show_session_dbg_clock_cycles_fn,
61};
62/* *INDENT-ON* */
63
Steven Luong10e5b4a2022-10-10 11:37:57 -070064static_always_inline f64
65session_dbg_time_now (u32 thread)
66{
67 vlib_main_t *vm = vlib_get_main_by_index (thread);
68
69 return clib_time_now (&vm->clib_time) + vm->time_offset;
70}
Florin Coras11166672020-04-13 01:20:25 +000071
72static clib_error_t *
73clear_session_dbg_clock_cycles_fn (vlib_main_t * vm, unformat_input_t * input,
74 vlib_cli_command_t * cmd)
75{
76 session_dbg_evts_t *sde;
77 u32 thread;
78
79 if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
80 return clib_error_return (0, "unknown input `%U'", format_unformat_error,
81 input);
82
83 for (thread = 0; thread < vec_len (session_dbg_main.wrk); thread++)
84 {
85 sde = &session_dbg_main.wrk[thread];
86 clib_memset (sde, 0, sizeof (session_dbg_evts_t));
Steven Luong10e5b4a2022-10-10 11:37:57 -070087 sde->last_time = session_dbg_time_now (thread);
Florin Coras11166672020-04-13 01:20:25 +000088 sde->start_time = sde->last_time;
89 }
90
91 return 0;
92}
93
94
95/* *INDENT-OFF* */
96VLIB_CLI_COMMAND (clear_session_clock_cycles_command, static) =
97{
98 .path = "clear session dbg clock_cycles",
99 .short_help = "clear session dbg clock_cycles",
100 .function = clear_session_dbg_clock_cycles_fn,
101};
102/* *INDENT-ON* */
103
104void
105session_debug_init (void)
106{
107 vlib_thread_main_t *vtm = vlib_get_thread_main ();
108 session_dbg_main_t *sdm = &session_dbg_main;
109 u32 num_threads, thread;
110
111 num_threads = vtm->n_vlib_mains;
112
113 vec_validate_aligned (sdm->wrk, num_threads - 1, CLIB_CACHE_LINE_BYTES);
114 for (thread = 0; thread < num_threads; thread++)
115 {
116 clib_memset (&sdm->wrk[thread], 0, sizeof (session_dbg_evts_t));
Steven Luong10e5b4a2022-10-10 11:37:57 -0700117 sdm->wrk[thread].start_time = session_dbg_time_now (thread);
Florin Coras11166672020-04-13 01:20:25 +0000118 }
119}
120#else
121void
122session_debug_init (void)
123{
124}
125#endif
126
127void
128dump_thread_0_event_queue (void)
129{
Damjan Marion6ffb7c62021-03-26 13:06:13 +0100130 vlib_main_t *vm = vlib_get_first_main ();
Florin Coras11166672020-04-13 01:20:25 +0000131 u32 my_thread_index = vm->thread_index;
132 session_event_t _e, *e = &_e;
Florin Coras86f12322021-01-22 15:05:14 -0800133 svm_msg_q_shared_queue_t *sq;
Florin Coras11166672020-04-13 01:20:25 +0000134 svm_msg_q_ring_t *ring;
135 session_t *s0;
136 svm_msg_q_msg_t *msg;
137 svm_msg_q_t *mq;
138 int i, index;
139
Florin Corasb4624182020-12-11 13:58:12 -0800140 mq = session_main_get_vpp_event_queue (my_thread_index);
Florin Coras86f12322021-01-22 15:05:14 -0800141 sq = mq->q.shr;
142 index = sq->head;
Florin Coras11166672020-04-13 01:20:25 +0000143
Florin Coras86f12322021-01-22 15:05:14 -0800144 for (i = 0; i < sq->cursize; i++)
Florin Coras11166672020-04-13 01:20:25 +0000145 {
Florin Coras86f12322021-01-22 15:05:14 -0800146 msg = (svm_msg_q_msg_t *) (&sq->data[0] + sq->elsize * index);
Florin Coras11166672020-04-13 01:20:25 +0000147 ring = svm_msg_q_ring (mq, msg->ring_index);
148 clib_memcpy_fast (e, svm_msg_q_msg_data (mq, msg), ring->elsize);
149
150 switch (e->event_type)
151 {
152 case SESSION_IO_EVT_TX:
153 s0 = session_get_if_valid (e->session_index, my_thread_index);
Florin Coras8f603182022-03-31 07:57:47 -0700154 if (!s0)
155 break;
Florin Coras11166672020-04-13 01:20:25 +0000156 fformat (stdout, "[%04d] TX session %d\n", i, s0->session_index);
157 break;
158
159 case SESSION_CTRL_EVT_CLOSE:
160 s0 = session_get_from_handle (e->session_handle);
161 fformat (stdout, "[%04d] disconnect session %d\n", i,
162 s0->session_index);
163 break;
164
165 case SESSION_IO_EVT_BUILTIN_RX:
166 s0 = session_get_if_valid (e->session_index, my_thread_index);
Florin Coras8f603182022-03-31 07:57:47 -0700167 if (!s0)
168 break;
Florin Coras11166672020-04-13 01:20:25 +0000169 fformat (stdout, "[%04d] builtin_rx %d\n", i, s0->session_index);
170 break;
171
172 case SESSION_CTRL_EVT_RPC:
173 fformat (stdout, "[%04d] RPC call %llx with %llx\n",
174 i, (u64) (uword) (e->rpc_args.fp),
175 (u64) (uword) (e->rpc_args.arg));
176 break;
177
178 default:
179 fformat (stdout, "[%04d] unhandled event type %d\n",
180 i, e->event_type);
181 break;
182 }
183
184 index++;
185
Florin Coras86f12322021-01-22 15:05:14 -0800186 if (index == sq->maxsize)
Florin Coras11166672020-04-13 01:20:25 +0000187 index = 0;
188 }
189}
190
191static u8
192session_node_cmp_event (session_event_t * e, svm_fifo_t * f)
193{
Florin Coras11166672020-04-13 01:20:25 +0000194 switch (e->event_type)
195 {
196 case SESSION_IO_EVT_RX:
197 case SESSION_IO_EVT_TX:
198 case SESSION_IO_EVT_BUILTIN_RX:
199 case SESSION_IO_EVT_BUILTIN_TX:
200 case SESSION_IO_EVT_TX_FLUSH:
Florin Corasc547e912020-12-08 17:50:45 -0800201 if (e->session_index == f->shr->master_session_index)
Florin Coras11166672020-04-13 01:20:25 +0000202 return 1;
203 break;
204 case SESSION_CTRL_EVT_CLOSE:
Florin Coras11166672020-04-13 01:20:25 +0000205 case SESSION_CTRL_EVT_RPC:
Florin Coras11166672020-04-13 01:20:25 +0000206 break;
207 default:
208 break;
209 }
210 return 0;
211}
212
213u8
214session_node_lookup_fifo_event (svm_fifo_t * f, session_event_t * e)
215{
Florin Coras86f12322021-01-22 15:05:14 -0800216 svm_msg_q_shared_queue_t *sq;
Florin Coras11166672020-04-13 01:20:25 +0000217 session_evt_elt_t *elt;
218 session_worker_t *wrk;
219 int i, index, found = 0;
220 svm_msg_q_msg_t *msg;
221 svm_msg_q_ring_t *ring;
222 svm_msg_q_t *mq;
223 u8 thread_index;
224
225 ASSERT (e);
226 thread_index = f->master_thread_index;
227 wrk = session_main_get_worker (thread_index);
228
229 /*
230 * Search evt queue
231 */
232 mq = wrk->vpp_event_queue;
Florin Coras86f12322021-01-22 15:05:14 -0800233 sq = mq->q.shr;
234 index = sq->head;
235 for (i = 0; i < sq->cursize; i++)
Florin Coras11166672020-04-13 01:20:25 +0000236 {
Florin Coras86f12322021-01-22 15:05:14 -0800237 msg = (svm_msg_q_msg_t *) (&sq->data[0] + sq->elsize * index);
Florin Coras11166672020-04-13 01:20:25 +0000238 ring = svm_msg_q_ring (mq, msg->ring_index);
239 clib_memcpy_fast (e, svm_msg_q_msg_data (mq, msg), ring->elsize);
240 found = session_node_cmp_event (e, f);
241 if (found)
242 return 1;
Florin Coras86f12322021-01-22 15:05:14 -0800243 index = (index + 1) % sq->maxsize;
Florin Coras11166672020-04-13 01:20:25 +0000244 }
245 /*
246 * Search pending events vector
247 */
248
249 /* *INDENT-OFF* */
250 clib_llist_foreach (wrk->event_elts, evt_list,
251 pool_elt_at_index (wrk->event_elts, wrk->new_head),
252 elt, ({
253 found = session_node_cmp_event (&elt->evt, f);
254 if (found)
255 {
256 clib_memcpy_fast (e, &elt->evt, sizeof (*e));
257 goto done;
258 }
259 }));
260 /* *INDENT-ON* */
261
262 /* *INDENT-OFF* */
263 clib_llist_foreach (wrk->event_elts, evt_list,
264 pool_elt_at_index (wrk->event_elts, wrk->old_head),
265 elt, ({
266 found = session_node_cmp_event (&elt->evt, f);
267 if (found)
268 {
269 clib_memcpy_fast (e, &elt->evt, sizeof (*e));
270 goto done;
271 }
272 }));
273 /* *INDENT-ON* */
274
275done:
276 return found;
277}
278
279/*
280 * fd.io coding-style-patch-verification: ON
281 *
282 * Local Variables:
283 * eval: (c-set-style "gnu")
284 * End:
285 */