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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include <vnet/session/session_debug.h>
17 #include <vnet/session/session.h>
21 session_dbg_main_t session_dbg_main;
24 show_session_dbg_clock_cycles_fn (vlib_main_t * vm, unformat_input_t * input,
25 vlib_cli_command_t * cmd)
29 if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
30 return clib_error_return (0, "unknown input `%U'", format_unformat_error,
33 for (thread = 0; thread < vec_len (session_dbg_main.wrk); thread++)
35 vlib_cli_output (vm, "Threads %u:\n", thread);
36 session_dbg_evts_t *sdm = &session_dbg_main.wrk[thread];
38 #define _(sym, disp, type, str) \
42 vlib_cli_output (vm, "\t %25s : %12lu ", str, \
43 sdm->counters[SESS_Q_##sym].u64); \
45 vlib_cli_output (vm, "\t %25s : %12.3f ", str, \
46 sdm->counters[SESS_Q_##sym].f64); \
48 foreach_session_events
55 VLIB_CLI_COMMAND (show_session_dbg_clock_cycles_command, static) =
57 .path = "show session dbg clock_cycles",
58 .short_help = "show session dbg clock_cycles",
59 .function = show_session_dbg_clock_cycles_fn,
62 static_always_inline f64
63 session_dbg_time_now (u32 thread)
65 vlib_main_t *vm = vlib_get_main_by_index (thread);
67 return clib_time_now (&vm->clib_time) + vm->time_offset;
71 clear_session_dbg_clock_cycles_fn (vlib_main_t * vm, unformat_input_t * input,
72 vlib_cli_command_t * cmd)
74 session_dbg_evts_t *sde;
77 if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
78 return clib_error_return (0, "unknown input `%U'", format_unformat_error,
81 for (thread = 0; thread < vec_len (session_dbg_main.wrk); thread++)
83 sde = &session_dbg_main.wrk[thread];
84 clib_memset (sde, 0, sizeof (session_dbg_evts_t));
85 sde->last_time = session_dbg_time_now (thread);
86 sde->start_time = sde->last_time;
93 VLIB_CLI_COMMAND (clear_session_clock_cycles_command, static) =
95 .path = "clear session dbg clock_cycles",
96 .short_help = "clear session dbg clock_cycles",
97 .function = clear_session_dbg_clock_cycles_fn,
101 session_debug_init (void)
103 vlib_thread_main_t *vtm = vlib_get_thread_main ();
104 session_dbg_main_t *sdm = &session_dbg_main;
105 u32 num_threads, thread;
107 num_threads = vtm->n_vlib_mains;
109 vec_validate_aligned (sdm->wrk, num_threads - 1, CLIB_CACHE_LINE_BYTES);
110 for (thread = 0; thread < num_threads; thread++)
112 clib_memset (&sdm->wrk[thread], 0, sizeof (session_dbg_evts_t));
113 sdm->wrk[thread].start_time = session_dbg_time_now (thread);
117 static const char *session_evt_grp_str[] = {
118 #define _(sym, str) str,
119 foreach_session_evt_grp
124 session_debug_show_groups (vlib_main_t *vm)
126 session_dbg_main_t *sdm = &session_dbg_main;
129 vlib_cli_output (vm, "%-10s%-30s%-10s", "Index", "Group", "Level");
131 for (i = 0; i < SESSION_EVT_N_GRP; i++)
132 vlib_cli_output (vm, "%-10d%-30s%-10d", i, session_evt_grp_str[i],
133 sdm->grp_dbg_lvl[i]);
136 static clib_error_t *
137 session_debug_fn (vlib_main_t *vm, unformat_input_t *input,
138 vlib_cli_command_t *cmd)
140 session_dbg_main_t *sdm = &session_dbg_main;
141 u32 group, level = ~0;
142 clib_error_t *error = 0;
146 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
148 if (unformat (input, "show"))
150 else if (unformat (input, "group %U", unformat_bitmap_list, &bitmap))
152 else if (unformat (input, "level %d", &level))
156 error = clib_error_return (0, "unknown input `%U'",
157 format_unformat_error, input);
164 session_debug_show_groups (vm);
169 vlib_cli_output (vm, "level must be entered");
173 group = clib_bitmap_last_set (bitmap);
176 vlib_cli_output (vm, "group must be entered");
179 if (group >= SESSION_EVT_N_GRP)
181 vlib_cli_output (vm, "group out of bounds");
184 clib_bitmap_foreach (group, bitmap)
185 sdm->grp_dbg_lvl[group] = level;
189 clib_bitmap_free (bitmap);
193 VLIB_CLI_COMMAND (session_debug_command, static) = {
194 .path = "session debug",
195 .short_help = "session debug {show | debug group <list> level <n>}",
196 .function = session_debug_fn,
202 session_debug_init (void)
205 #endif /* SESSION_DEBUG */
208 dump_thread_0_event_queue (void)
210 vlib_main_t *vm = vlib_get_first_main ();
211 u32 my_thread_index = vm->thread_index;
212 session_event_t _e, *e = &_e;
213 svm_msg_q_shared_queue_t *sq;
214 svm_msg_q_ring_t *ring;
216 svm_msg_q_msg_t *msg;
220 mq = session_main_get_vpp_event_queue (my_thread_index);
224 for (i = 0; i < sq->cursize; i++)
226 msg = (svm_msg_q_msg_t *) (&sq->data[0] + sq->elsize * index);
227 ring = svm_msg_q_ring (mq, msg->ring_index);
228 clib_memcpy_fast (e, svm_msg_q_msg_data (mq, msg), ring->elsize);
230 switch (e->event_type)
232 case SESSION_IO_EVT_TX:
233 s0 = session_get_if_valid (e->session_index, my_thread_index);
236 fformat (stdout, "[%04d] TX session %d\n", i, s0->session_index);
239 case SESSION_CTRL_EVT_CLOSE:
240 s0 = session_get_from_handle (e->session_handle);
241 fformat (stdout, "[%04d] disconnect session %d\n", i,
245 case SESSION_IO_EVT_BUILTIN_RX:
246 s0 = session_get_if_valid (e->session_index, my_thread_index);
249 fformat (stdout, "[%04d] builtin_rx %d\n", i, s0->session_index);
252 case SESSION_CTRL_EVT_RPC:
253 fformat (stdout, "[%04d] RPC call %llx with %llx\n",
254 i, (u64) (uword) (e->rpc_args.fp),
255 (u64) (uword) (e->rpc_args.arg));
259 fformat (stdout, "[%04d] unhandled event type %d\n",
266 if (index == sq->maxsize)
272 session_node_cmp_event (session_event_t * e, svm_fifo_t * f)
274 switch (e->event_type)
276 case SESSION_IO_EVT_RX:
277 case SESSION_IO_EVT_TX:
278 case SESSION_IO_EVT_BUILTIN_RX:
279 case SESSION_IO_EVT_TX_MAIN:
280 case SESSION_IO_EVT_TX_FLUSH:
281 if (e->session_index == f->shr->master_session_index)
284 case SESSION_CTRL_EVT_CLOSE:
285 case SESSION_CTRL_EVT_RPC:
294 session_node_lookup_fifo_event (svm_fifo_t * f, session_event_t * e)
296 svm_msg_q_shared_queue_t *sq;
297 session_evt_elt_t *elt;
298 session_worker_t *wrk;
299 int i, index, found = 0;
300 svm_msg_q_msg_t *msg;
305 thread_index = f->master_thread_index;
306 wrk = session_main_get_worker (thread_index);
311 mq = wrk->vpp_event_queue;
314 for (i = 0; i < sq->cursize; i++)
316 msg = (svm_msg_q_msg_t *) (&sq->data[0] + sq->elsize * index);
317 clib_memcpy_fast (e, svm_msg_q_msg_data (mq, msg), sizeof (*e));
318 found = session_node_cmp_event (e, f);
321 index = (index + 1) % sq->maxsize;
324 * Search pending events vector
327 clib_llist_foreach (wrk->event_elts, evt_list,
328 pool_elt_at_index (wrk->event_elts, wrk->new_head),
330 found = session_node_cmp_event (&elt->evt, f);
333 clib_memcpy_fast (e, &elt->evt, sizeof (*e));
338 clib_llist_foreach (wrk->event_elts, evt_list,
339 pool_elt_at_index (wrk->event_elts, wrk->old_head),
341 found = session_node_cmp_event (&elt->evt, f);
344 clib_memcpy_fast (e, &elt->evt, sizeof (*e));
354 * fd.io coding-style-patch-verification: ON
357 * eval: (c-set-style "gnu")