blob: f62af1cf8393f82af3e2b28a186b55271ac79095 [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
64
65static clib_error_t *
66clear_session_dbg_clock_cycles_fn (vlib_main_t * vm, unformat_input_t * input,
67 vlib_cli_command_t * cmd)
68{
69 session_dbg_evts_t *sde;
70 u32 thread;
71
72 if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
73 return clib_error_return (0, "unknown input `%U'", format_unformat_error,
74 input);
75
76 for (thread = 0; thread < vec_len (session_dbg_main.wrk); thread++)
77 {
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;
82 }
83
84 return 0;
85}
86
87
88/* *INDENT-OFF* */
89VLIB_CLI_COMMAND (clear_session_clock_cycles_command, static) =
90{
91 .path = "clear session dbg clock_cycles",
92 .short_help = "clear session dbg clock_cycles",
93 .function = clear_session_dbg_clock_cycles_fn,
94};
95/* *INDENT-ON* */
96
97void
98session_debug_init (void)
99{
100 vlib_thread_main_t *vtm = vlib_get_thread_main ();
101 session_dbg_main_t *sdm = &session_dbg_main;
102 u32 num_threads, thread;
103
104 num_threads = vtm->n_vlib_mains;
105
106 vec_validate_aligned (sdm->wrk, num_threads - 1, CLIB_CACHE_LINE_BYTES);
107 for (thread = 0; thread < num_threads; thread++)
108 {
109 clib_memset (&sdm->wrk[thread], 0, sizeof (session_dbg_evts_t));
110 sdm->wrk[thread].start_time = vlib_time_now (vlib_mains[thread]);
111 }
112}
113#else
114void
115session_debug_init (void)
116{
117}
118#endif
119
120void
121dump_thread_0_event_queue (void)
122{
Damjan Marion6ffb7c62021-03-26 13:06:13 +0100123 vlib_main_t *vm = vlib_get_first_main ();
Florin Coras11166672020-04-13 01:20:25 +0000124 u32 my_thread_index = vm->thread_index;
125 session_event_t _e, *e = &_e;
Florin Coras86f12322021-01-22 15:05:14 -0800126 svm_msg_q_shared_queue_t *sq;
Florin Coras11166672020-04-13 01:20:25 +0000127 svm_msg_q_ring_t *ring;
128 session_t *s0;
129 svm_msg_q_msg_t *msg;
130 svm_msg_q_t *mq;
131 int i, index;
132
Florin Corasb4624182020-12-11 13:58:12 -0800133 mq = session_main_get_vpp_event_queue (my_thread_index);
Florin Coras86f12322021-01-22 15:05:14 -0800134 sq = mq->q.shr;
135 index = sq->head;
Florin Coras11166672020-04-13 01:20:25 +0000136
Florin Coras86f12322021-01-22 15:05:14 -0800137 for (i = 0; i < sq->cursize; i++)
Florin Coras11166672020-04-13 01:20:25 +0000138 {
Florin Coras86f12322021-01-22 15:05:14 -0800139 msg = (svm_msg_q_msg_t *) (&sq->data[0] + sq->elsize * index);
Florin Coras11166672020-04-13 01:20:25 +0000140 ring = svm_msg_q_ring (mq, msg->ring_index);
141 clib_memcpy_fast (e, svm_msg_q_msg_data (mq, msg), ring->elsize);
142
143 switch (e->event_type)
144 {
145 case SESSION_IO_EVT_TX:
146 s0 = session_get_if_valid (e->session_index, my_thread_index);
147 fformat (stdout, "[%04d] TX session %d\n", i, s0->session_index);
148 break;
149
150 case SESSION_CTRL_EVT_CLOSE:
151 s0 = session_get_from_handle (e->session_handle);
152 fformat (stdout, "[%04d] disconnect session %d\n", i,
153 s0->session_index);
154 break;
155
156 case SESSION_IO_EVT_BUILTIN_RX:
157 s0 = session_get_if_valid (e->session_index, my_thread_index);
158 fformat (stdout, "[%04d] builtin_rx %d\n", i, s0->session_index);
159 break;
160
161 case SESSION_CTRL_EVT_RPC:
162 fformat (stdout, "[%04d] RPC call %llx with %llx\n",
163 i, (u64) (uword) (e->rpc_args.fp),
164 (u64) (uword) (e->rpc_args.arg));
165 break;
166
167 default:
168 fformat (stdout, "[%04d] unhandled event type %d\n",
169 i, e->event_type);
170 break;
171 }
172
173 index++;
174
Florin Coras86f12322021-01-22 15:05:14 -0800175 if (index == sq->maxsize)
Florin Coras11166672020-04-13 01:20:25 +0000176 index = 0;
177 }
178}
179
180static u8
181session_node_cmp_event (session_event_t * e, svm_fifo_t * f)
182{
Florin Coras11166672020-04-13 01:20:25 +0000183 switch (e->event_type)
184 {
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:
Florin Corasc547e912020-12-08 17:50:45 -0800190 if (e->session_index == f->shr->master_session_index)
Florin Coras11166672020-04-13 01:20:25 +0000191 return 1;
192 break;
193 case SESSION_CTRL_EVT_CLOSE:
Florin Coras11166672020-04-13 01:20:25 +0000194 case SESSION_CTRL_EVT_RPC:
Florin Coras11166672020-04-13 01:20:25 +0000195 break;
196 default:
197 break;
198 }
199 return 0;
200}
201
202u8
203session_node_lookup_fifo_event (svm_fifo_t * f, session_event_t * e)
204{
Florin Coras86f12322021-01-22 15:05:14 -0800205 svm_msg_q_shared_queue_t *sq;
Florin Coras11166672020-04-13 01:20:25 +0000206 session_evt_elt_t *elt;
207 session_worker_t *wrk;
208 int i, index, found = 0;
209 svm_msg_q_msg_t *msg;
210 svm_msg_q_ring_t *ring;
211 svm_msg_q_t *mq;
212 u8 thread_index;
213
214 ASSERT (e);
215 thread_index = f->master_thread_index;
216 wrk = session_main_get_worker (thread_index);
217
218 /*
219 * Search evt queue
220 */
221 mq = wrk->vpp_event_queue;
Florin Coras86f12322021-01-22 15:05:14 -0800222 sq = mq->q.shr;
223 index = sq->head;
224 for (i = 0; i < sq->cursize; i++)
Florin Coras11166672020-04-13 01:20:25 +0000225 {
Florin Coras86f12322021-01-22 15:05:14 -0800226 msg = (svm_msg_q_msg_t *) (&sq->data[0] + sq->elsize * index);
Florin Coras11166672020-04-13 01:20:25 +0000227 ring = svm_msg_q_ring (mq, msg->ring_index);
228 clib_memcpy_fast (e, svm_msg_q_msg_data (mq, msg), ring->elsize);
229 found = session_node_cmp_event (e, f);
230 if (found)
231 return 1;
Florin Coras86f12322021-01-22 15:05:14 -0800232 index = (index + 1) % sq->maxsize;
Florin Coras11166672020-04-13 01:20:25 +0000233 }
234 /*
235 * Search pending events vector
236 */
237
238 /* *INDENT-OFF* */
239 clib_llist_foreach (wrk->event_elts, evt_list,
240 pool_elt_at_index (wrk->event_elts, wrk->new_head),
241 elt, ({
242 found = session_node_cmp_event (&elt->evt, f);
243 if (found)
244 {
245 clib_memcpy_fast (e, &elt->evt, sizeof (*e));
246 goto done;
247 }
248 }));
249 /* *INDENT-ON* */
250
251 /* *INDENT-OFF* */
252 clib_llist_foreach (wrk->event_elts, evt_list,
253 pool_elt_at_index (wrk->event_elts, wrk->old_head),
254 elt, ({
255 found = session_node_cmp_event (&elt->evt, f);
256 if (found)
257 {
258 clib_memcpy_fast (e, &elt->evt, sizeof (*e));
259 goto done;
260 }
261 }));
262 /* *INDENT-ON* */
263
264done:
265 return found;
266}
267
268/*
269 * fd.io coding-style-patch-verification: ON
270 *
271 * Local Variables:
272 * eval: (c-set-style "gnu")
273 * End:
274 */