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
56 VLIB_CLI_COMMAND (show_session_dbg_clock_cycles_command, static) =
58 .path = "show session dbg clock_cycles",
59 .short_help = "show session dbg clock_cycles",
60 .function = show_session_dbg_clock_cycles_fn,
66 clear_session_dbg_clock_cycles_fn (vlib_main_t * vm, unformat_input_t * input,
67 vlib_cli_command_t * cmd)
69 session_dbg_evts_t *sde;
72 if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
73 return clib_error_return (0, "unknown input `%U'", format_unformat_error,
76 for (thread = 0; thread < vec_len (session_dbg_main.wrk); thread++)
78 sde = &session_dbg_main.wrk[thread];
79 clib_memset (sde, 0, sizeof (session_dbg_evts_t));
80 sde->last_time = vlib_time_now (vlib_mains[thread]);
81 sde->start_time = sde->last_time;
89 VLIB_CLI_COMMAND (clear_session_clock_cycles_command, static) =
91 .path = "clear session dbg clock_cycles",
92 .short_help = "clear session dbg clock_cycles",
93 .function = clear_session_dbg_clock_cycles_fn,
98 session_debug_init (void)
100 vlib_thread_main_t *vtm = vlib_get_thread_main ();
101 session_dbg_main_t *sdm = &session_dbg_main;
102 u32 num_threads, thread;
104 num_threads = vtm->n_vlib_mains;
106 vec_validate_aligned (sdm->wrk, num_threads - 1, CLIB_CACHE_LINE_BYTES);
107 for (thread = 0; thread < num_threads; thread++)
109 clib_memset (&sdm->wrk[thread], 0, sizeof (session_dbg_evts_t));
110 sdm->wrk[thread].start_time = vlib_time_now (vlib_mains[thread]);
115 session_debug_init (void)
121 dump_thread_0_event_queue (void)
123 session_main_t *smm = vnet_get_session_main ();
124 vlib_main_t *vm = &vlib_global_main;
125 u32 my_thread_index = vm->thread_index;
126 session_event_t _e, *e = &_e;
127 svm_msg_q_ring_t *ring;
129 svm_msg_q_msg_t *msg;
133 mq = smm->wrk[my_thread_index].vpp_event_queue;
136 for (i = 0; i < mq->q->cursize; i++)
138 msg = (svm_msg_q_msg_t *) (&mq->q->data[0] + mq->q->elsize * index);
139 ring = svm_msg_q_ring (mq, msg->ring_index);
140 clib_memcpy_fast (e, svm_msg_q_msg_data (mq, msg), ring->elsize);
142 switch (e->event_type)
144 case SESSION_IO_EVT_TX:
145 s0 = session_get_if_valid (e->session_index, my_thread_index);
146 fformat (stdout, "[%04d] TX session %d\n", i, s0->session_index);
149 case SESSION_CTRL_EVT_CLOSE:
150 s0 = session_get_from_handle (e->session_handle);
151 fformat (stdout, "[%04d] disconnect session %d\n", i,
155 case SESSION_IO_EVT_BUILTIN_RX:
156 s0 = session_get_if_valid (e->session_index, my_thread_index);
157 fformat (stdout, "[%04d] builtin_rx %d\n", i, s0->session_index);
160 case SESSION_CTRL_EVT_RPC:
161 fformat (stdout, "[%04d] RPC call %llx with %llx\n",
162 i, (u64) (uword) (e->rpc_args.fp),
163 (u64) (uword) (e->rpc_args.arg));
167 fformat (stdout, "[%04d] unhandled event type %d\n",
174 if (index == mq->q->maxsize)
180 session_node_cmp_event (session_event_t * e, svm_fifo_t * f)
183 switch (e->event_type)
185 case SESSION_IO_EVT_RX:
186 case SESSION_IO_EVT_TX:
187 case SESSION_IO_EVT_BUILTIN_RX:
188 case SESSION_IO_EVT_BUILTIN_TX:
189 case SESSION_IO_EVT_TX_FLUSH:
190 if (e->session_index == f->master_session_index)
193 case SESSION_CTRL_EVT_CLOSE:
195 case SESSION_CTRL_EVT_RPC:
196 s = session_get_from_handle (e->session_handle);
199 clib_warning ("session has event but doesn't exist!");
202 if (s->rx_fifo == f || s->tx_fifo == f)
212 session_node_lookup_fifo_event (svm_fifo_t * f, session_event_t * e)
214 session_evt_elt_t *elt;
215 session_worker_t *wrk;
216 int i, index, found = 0;
217 svm_msg_q_msg_t *msg;
218 svm_msg_q_ring_t *ring;
223 thread_index = f->master_thread_index;
224 wrk = session_main_get_worker (thread_index);
229 mq = wrk->vpp_event_queue;
231 for (i = 0; i < mq->q->cursize; i++)
233 msg = (svm_msg_q_msg_t *) (&mq->q->data[0] + mq->q->elsize * index);
234 ring = svm_msg_q_ring (mq, msg->ring_index);
235 clib_memcpy_fast (e, svm_msg_q_msg_data (mq, msg), ring->elsize);
236 found = session_node_cmp_event (e, f);
239 index = (index + 1) % mq->q->maxsize;
242 * Search pending events vector
246 clib_llist_foreach (wrk->event_elts, evt_list,
247 pool_elt_at_index (wrk->event_elts, wrk->new_head),
249 found = session_node_cmp_event (&elt->evt, f);
252 clib_memcpy_fast (e, &elt->evt, sizeof (*e));
259 clib_llist_foreach (wrk->event_elts, evt_list,
260 pool_elt_at_index (wrk->event_elts, wrk->old_head),
262 found = session_node_cmp_event (&elt->evt, f);
265 clib_memcpy_fast (e, &elt->evt, sizeof (*e));
276 * fd.io coding-style-patch-verification: ON
279 * eval: (c-set-style "gnu")