2 * Copyright (c) 2015 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 <vppinfra/format.h>
17 #include <vlib/vlib.h>
19 #include <vlib/threads.h>
22 show_threads_fn (vlib_main_t * vm,
23 unformat_input_t * input, vlib_cli_command_t * cmd)
25 vlib_worker_thread_t *w;
28 vlib_cli_output (vm, "%-7s%-20s%-12s%-8s%-7s%-7s%-7s%-10s",
29 "ID", "Name", "Type", "LWP",
30 "lcore", "Core", "Socket", "State");
32 #if !defined(__powerpc64__)
33 for (i = 0; i < vec_len (vlib_worker_threads); i++)
35 w = vlib_worker_threads + i;
38 line = format (line, "%-7d%-20s%-12s%-8d",
40 w->name ? w->name : (u8 *) "",
41 w->registration ? w->registration->name : "", w->lwp);
44 int lcore = w->dpdk_lcore_id;
47 line = format (line, "%-7u%-7u%-7u",
49 lcore_config[lcore].core_id,
50 lcore_config[lcore].socket_id);
52 switch (lcore_config[lcore].state)
55 line = format (line, "wait");
58 line = format (line, "running");
61 line = format (line, "finished");
64 line = format (line, "unknown");
68 vlib_cli_output (vm, "%v", line);
78 VLIB_CLI_COMMAND (show_threads_command, static) = {
79 .path = "show threads",
80 .short_help = "Show threads",
81 .function = show_threads_fn,
86 * Trigger threads to grab frame queue trace data
89 trace_frame_queue (vlib_main_t * vm, unformat_input_t * input,
90 vlib_cli_command_t * cmd)
92 clib_error_t *error = NULL;
93 frame_queue_trace_t *fqt;
94 frame_queue_nelt_counter_t *fqh;
95 vlib_thread_main_t *tm = vlib_get_thread_main ();
100 if (unformat (input, "on"))
104 else if (unformat (input, "off"))
110 return clib_error_return (0, "expecting on or off");
113 num_fq = vec_len (vlib_frame_queues);
116 vlib_cli_output (vm, "No frame queues exist\n");
120 // Allocate storage for trace if necessary
121 vec_validate_aligned (tm->frame_queue_traces, num_fq - 1,
122 CLIB_CACHE_LINE_BYTES);
123 vec_validate_aligned (tm->frame_queue_histogram, num_fq - 1,
124 CLIB_CACHE_LINE_BYTES);
126 for (fqix = 0; fqix < num_fq; fqix++)
128 fqt = &tm->frame_queue_traces[fqix];
129 fqh = &tm->frame_queue_histogram[fqix];
131 memset (fqt->n_vectors, 0xff, sizeof (fqt->n_vectors));
133 memset (fqh, 0, sizeof (*fqh));
134 vlib_frame_queues[fqix]->trace = enable;
140 VLIB_CLI_COMMAND (cmd_trace_frame_queue,static) = {
141 .path = "trace frame-queue",
142 .short_help = "trace frame-queue (on|off)",
143 .function = trace_frame_queue,
150 * Adding two counters and compute percent of total
151 * Round up, e.g. 0.000001 => 1%
154 compute_percent (u64 * two_counters, u64 total)
162 return (((two_counters[0] + two_counters[1]) * 100) +
163 (total - 1)) / total;
168 * Display frame queue trace data gathered by threads.
170 static clib_error_t *
171 show_frame_queue_internal (vlib_main_t * vm, u32 histogram)
173 vlib_thread_main_t *tm = vlib_get_thread_main ();
174 clib_error_t *error = NULL;
175 frame_queue_trace_t *fqt;
176 frame_queue_nelt_counter_t *fqh;
180 num_fq = vec_len (tm->frame_queue_traces);
183 vlib_cli_output (vm, "No trace data for frame queues\n");
189 vlib_cli_output (vm, "0-1 2-3 4-5 6-7 8-9 10-11 12-13 14-15 "
190 "16-17 18-19 20-21 22-23 24-25 26-27 28-29 30-31\n");
193 for (fqix = 0; fqix < num_fq; fqix++)
195 fqt = &(tm->frame_queue_traces[fqix]);
197 vlib_cli_output (vm, "Thread %d %v\n", fqix,
198 vlib_worker_threads[fqix].name);
200 if (fqt->written == 0)
202 vlib_cli_output (vm, " no trace data\n");
208 fqh = &(tm->frame_queue_histogram[fqix]);
212 for (nelt = 0; nelt < FRAME_QUEUE_MAX_NELTS; nelt++)
214 total += fqh->count[nelt];
218 * Print in pairs to condense the output.
219 * Allow entries with 0 counts to be clearly identified, by rounding up.
220 * Any non-zero value will be displayed as at least one percent. This
221 * also means the sum of percentages can be > 100, but that is fine. The
222 * histogram is counted from the last time "trace frame on" was issued.
225 "%3d%% %3d%% %3d%% %3d%% %3d%% %3d%% %3d%% %3d%% "
226 "%3d%% %3d%% %3d%% %3d%% %3d%% %3d%% %3d%% %3d%%\n",
227 compute_percent (&fqh->count[0], total),
228 compute_percent (&fqh->count[2], total),
229 compute_percent (&fqh->count[4], total),
230 compute_percent (&fqh->count[6], total),
231 compute_percent (&fqh->count[8], total),
232 compute_percent (&fqh->count[10], total),
233 compute_percent (&fqh->count[12], total),
234 compute_percent (&fqh->count[14], total),
235 compute_percent (&fqh->count[16], total),
236 compute_percent (&fqh->count[18], total),
237 compute_percent (&fqh->count[20], total),
238 compute_percent (&fqh->count[22], total),
239 compute_percent (&fqh->count[24], total),
240 compute_percent (&fqh->count[26], total),
241 compute_percent (&fqh->count[28], total),
242 compute_percent (&fqh->count[30], total));
247 " vector-threshold %d ring size %d in use %d\n",
248 fqt->threshold, fqt->nelts, fqt->n_in_use);
249 vlib_cli_output (vm, " head %12d head_hint %12d tail %12d\n",
250 fqt->head, fqt->head_hint, fqt->tail);
252 " %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d\n",
253 fqt->n_vectors[0], fqt->n_vectors[1],
254 fqt->n_vectors[2], fqt->n_vectors[3],
255 fqt->n_vectors[4], fqt->n_vectors[5],
256 fqt->n_vectors[6], fqt->n_vectors[7],
257 fqt->n_vectors[8], fqt->n_vectors[9],
258 fqt->n_vectors[10], fqt->n_vectors[11],
259 fqt->n_vectors[12], fqt->n_vectors[13],
260 fqt->n_vectors[14], fqt->n_vectors[15]);
265 " %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d\n",
266 fqt->n_vectors[16], fqt->n_vectors[17],
267 fqt->n_vectors[18], fqt->n_vectors[19],
268 fqt->n_vectors[20], fqt->n_vectors[21],
269 fqt->n_vectors[22], fqt->n_vectors[23],
270 fqt->n_vectors[24], fqt->n_vectors[25],
271 fqt->n_vectors[26], fqt->n_vectors[27],
272 fqt->n_vectors[28], fqt->n_vectors[29],
273 fqt->n_vectors[30], fqt->n_vectors[31]);
281 static clib_error_t *
282 show_frame_queue_trace (vlib_main_t * vm, unformat_input_t * input,
283 vlib_cli_command_t * cmd)
285 return show_frame_queue_internal (vm, 0);
288 static clib_error_t *
289 show_frame_queue_histogram (vlib_main_t * vm, unformat_input_t * input,
290 vlib_cli_command_t * cmd)
292 return show_frame_queue_internal (vm, 1);
296 VLIB_CLI_COMMAND (cmd_show_frame_queue_trace,static) = {
297 .path = "show frame-queue",
298 .short_help = "show frame-queue trace",
299 .function = show_frame_queue_trace,
304 VLIB_CLI_COMMAND (cmd_show_frame_queue_histogram,static) = {
305 .path = "show frame-queue histogram",
306 .short_help = "show frame-queue histogram",
307 .function = show_frame_queue_histogram,
313 * Modify the number of elements on the frame_queues
315 static clib_error_t *
316 test_frame_queue_nelts (vlib_main_t * vm, unformat_input_t * input,
317 vlib_cli_command_t * cmd)
319 clib_error_t *error = NULL;
324 unformat (input, "%d", &nelts);
325 if ((nelts != 4) && (nelts != 8) && (nelts != 16) && (nelts != 32))
327 return clib_error_return (0, "expecting 4,8,16,32");
330 num_fq = vec_len (vlib_frame_queues);
333 vlib_cli_output (vm, "No frame queues exist\n");
337 for (fqix = 0; fqix < num_fq; fqix++)
339 vlib_frame_queues[fqix]->nelts = nelts;
346 VLIB_CLI_COMMAND (cmd_test_frame_queue_nelts,static) = {
347 .path = "test frame-queue nelts",
348 .short_help = "test frame-queue nelts (4,8,16,32)",
349 .function = test_frame_queue_nelts,
355 * Modify the max number of packets pulled off the frame queues
357 static clib_error_t *
358 test_frame_queue_threshold (vlib_main_t * vm, unformat_input_t * input,
359 vlib_cli_command_t * cmd)
361 clib_error_t *error = NULL;
366 if (unformat (input, "%d", &threshold))
371 vlib_cli_output (vm, "expecting threshold value\n");
378 num_fq = vec_len (vlib_frame_queues);
381 vlib_cli_output (vm, "No frame queues exist\n");
385 for (fqix = 0; fqix < num_fq; fqix++)
387 vlib_frame_queues[fqix]->vector_threshold = threshold;
394 VLIB_CLI_COMMAND (cmd_test_frame_queue_threshold,static) = {
395 .path = "test frame-queue threshold",
396 .short_help = "test frame-queue threshold N (0=no limit)",
397 .function = test_frame_queue_threshold,
403 * fd.io coding-style-patch-verification: ON
406 * eval: (c-set-style "gnu")