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,
24 vlib_cli_command_t * cmd)
26 vlib_worker_thread_t * w;
29 vlib_cli_output (vm, "%-7s%-20s%-12s%-8s%-7s%-7s%-7s%-10s",
30 "ID", "Name", "Type", "LWP",
31 "lcore", "Core", "Socket", "State");
33 #if !defined(__powerpc64__)
34 for (i = 0; i < vec_len(vlib_worker_threads); i++)
36 w = vlib_worker_threads + i;
39 line = format(line, "%-7d%-20s%-12s%-8d",
41 w->name ? w->name : (u8 *) "",
42 w->registration ? w->registration->name : "",
46 int lcore = w->dpdk_lcore_id;
49 line = format(line, "%-7u%-7u%-7u",
51 lcore_config[lcore].core_id,
52 lcore_config[lcore].socket_id);
54 switch(lcore_config[lcore].state)
57 line = format(line, "wait");
60 line = format(line, "running");
63 line = format(line, "finished");
66 line = format(line, "unknown");
70 vlib_cli_output(vm, "%v", line);
79 VLIB_CLI_COMMAND (show_threads_command, static) = {
80 .path = "show threads",
81 .short_help = "Show threads",
82 .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")) {
102 } else if (unformat(input, "off")) {
105 return clib_error_return(0, "expecting on or off");
108 num_fq = vec_len(vlib_frame_queues);
111 vlib_cli_output(vm, "No frame queues exist\n");
115 // Allocate storage for trace if necessary
116 vec_validate_aligned(tm->frame_queue_traces, num_fq-1, CLIB_CACHE_LINE_BYTES);
117 vec_validate_aligned(tm->frame_queue_histogram, num_fq-1, CLIB_CACHE_LINE_BYTES);
119 for (fqix=0; fqix<num_fq; fqix++) {
120 fqt = &tm->frame_queue_traces[fqix];
121 fqh = &tm->frame_queue_histogram[fqix];
123 memset(fqt->n_vectors, 0xff, sizeof(fqt->n_vectors));
125 memset(fqh, 0, sizeof(*fqh));
126 vlib_frame_queues[fqix]->trace = enable;
131 VLIB_CLI_COMMAND (cmd_trace_frame_queue,static) = {
132 .path = "trace frame-queue",
133 .short_help = "trace frame-queue (on|off)",
134 .function = trace_frame_queue,
140 * Adding two counters and compute percent of total
141 * Round up, e.g. 0.000001 => 1%
144 compute_percent (u64 *two_counters, u64 total)
152 return (((two_counters[0] + two_counters[1]) * 100) + (total-1)) / total;
157 * Display frame queue trace data gathered by threads.
159 static clib_error_t *
160 show_frame_queue_internal (vlib_main_t *vm,
163 vlib_thread_main_t *tm = vlib_get_thread_main();
164 clib_error_t * error = NULL;
165 frame_queue_trace_t *fqt;
166 frame_queue_nelt_counter_t *fqh;
170 num_fq = vec_len(tm->frame_queue_traces);
173 vlib_cli_output(vm, "No trace data for frame queues\n");
179 vlib_cli_output(vm, "0-1 2-3 4-5 6-7 8-9 10-11 12-13 14-15 "
180 "16-17 18-19 20-21 22-23 24-25 26-27 28-29 30-31\n");
183 for (fqix=0; fqix<num_fq; fqix++) {
184 fqt = &(tm->frame_queue_traces[fqix]);
186 vlib_cli_output(vm, "Thread %d %v\n", fqix, vlib_worker_threads[fqix].name);
188 if (fqt->written == 0)
190 vlib_cli_output(vm, " no trace data\n");
196 fqh = &(tm->frame_queue_histogram[fqix]);
200 for (nelt=0; nelt<FRAME_QUEUE_MAX_NELTS; nelt++) {
201 total += fqh->count[nelt];
205 * Print in pairs to condense the output.
206 * Allow entries with 0 counts to be clearly identified, by rounding up.
207 * Any non-zero value will be displayed as at least one percent. This
208 * also means the sum of percentages can be > 100, but that is fine. The
209 * histogram is counted from the last time "trace frame on" was issued.
212 "%3d%% %3d%% %3d%% %3d%% %3d%% %3d%% %3d%% %3d%% "
213 "%3d%% %3d%% %3d%% %3d%% %3d%% %3d%% %3d%% %3d%%\n",
214 compute_percent(&fqh->count[ 0], total),
215 compute_percent(&fqh->count[ 2], total),
216 compute_percent(&fqh->count[ 4], total),
217 compute_percent(&fqh->count[ 6], total),
218 compute_percent(&fqh->count[ 8], total),
219 compute_percent(&fqh->count[10], total),
220 compute_percent(&fqh->count[12], total),
221 compute_percent(&fqh->count[14], total),
222 compute_percent(&fqh->count[16], total),
223 compute_percent(&fqh->count[18], total),
224 compute_percent(&fqh->count[20], total),
225 compute_percent(&fqh->count[22], total),
226 compute_percent(&fqh->count[24], total),
227 compute_percent(&fqh->count[26], total),
228 compute_percent(&fqh->count[28], total),
229 compute_percent(&fqh->count[30], total));
233 vlib_cli_output(vm, " vector-threshold %d ring size %d in use %d\n",
234 fqt->threshold, fqt->nelts, fqt->n_in_use);
235 vlib_cli_output(vm, " head %12d head_hint %12d tail %12d\n",
236 fqt->head, fqt->head_hint, fqt->tail);
237 vlib_cli_output(vm, " %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d\n",
238 fqt->n_vectors[0], fqt->n_vectors[1], fqt->n_vectors[2], fqt->n_vectors[3],
239 fqt->n_vectors[4], fqt->n_vectors[5], fqt->n_vectors[6], fqt->n_vectors[7],
240 fqt->n_vectors[8], fqt->n_vectors[9], fqt->n_vectors[10], fqt->n_vectors[11],
241 fqt->n_vectors[12], fqt->n_vectors[13], fqt->n_vectors[14], fqt->n_vectors[15]);
245 vlib_cli_output(vm, " %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d\n",
246 fqt->n_vectors[16], fqt->n_vectors[17], fqt->n_vectors[18], fqt->n_vectors[19],
247 fqt->n_vectors[20], fqt->n_vectors[21], fqt->n_vectors[22], fqt->n_vectors[23],
248 fqt->n_vectors[24], fqt->n_vectors[25], fqt->n_vectors[26], fqt->n_vectors[27],
249 fqt->n_vectors[28], fqt->n_vectors[29], fqt->n_vectors[30], fqt->n_vectors[31]);
257 static clib_error_t *
258 show_frame_queue_trace (vlib_main_t *vm, unformat_input_t *input,
259 vlib_cli_command_t *cmd)
261 return show_frame_queue_internal (vm, 0);
264 static clib_error_t *
265 show_frame_queue_histogram (vlib_main_t *vm, unformat_input_t *input,
266 vlib_cli_command_t *cmd)
268 return show_frame_queue_internal (vm, 1);
271 VLIB_CLI_COMMAND (cmd_show_frame_queue_trace,static) = {
272 .path = "show frame-queue",
273 .short_help = "show frame-queue trace",
274 .function = show_frame_queue_trace,
277 VLIB_CLI_COMMAND (cmd_show_frame_queue_histogram,static) = {
278 .path = "show frame-queue histogram",
279 .short_help = "show frame-queue histogram",
280 .function = show_frame_queue_histogram,
285 * Modify the number of elements on the frame_queues
287 static clib_error_t *
288 test_frame_queue_nelts (vlib_main_t *vm, unformat_input_t *input,
289 vlib_cli_command_t *cmd)
291 clib_error_t * error = NULL;
296 unformat(input, "%d", &nelts);
297 if ((nelts != 4) && (nelts != 8) && (nelts != 16) && (nelts != 32)) {
298 return clib_error_return(0, "expecting 4,8,16,32");
301 num_fq = vec_len(vlib_frame_queues);
304 vlib_cli_output(vm, "No frame queues exist\n");
308 for (fqix=0; fqix<num_fq; fqix++) {
309 vlib_frame_queues[fqix]->nelts = nelts;
315 VLIB_CLI_COMMAND (cmd_test_frame_queue_nelts,static) = {
316 .path = "test frame-queue nelts",
317 .short_help = "test frame-queue nelts (4,8,16,32)",
318 .function = test_frame_queue_nelts,
323 * Modify the max number of packets pulled off the frame queues
325 static clib_error_t *
326 test_frame_queue_threshold (vlib_main_t *vm, unformat_input_t *input,
327 vlib_cli_command_t *cmd)
329 clib_error_t * error = NULL;
334 if (unformat(input, "%d", &threshold)) {
336 vlib_cli_output(vm, "expecting threshold value\n");
343 num_fq = vec_len(vlib_frame_queues);
346 vlib_cli_output(vm, "No frame queues exist\n");
350 for (fqix=0; fqix<num_fq; fqix++) {
351 vlib_frame_queues[fqix]->vector_threshold = threshold;
357 VLIB_CLI_COMMAND (cmd_test_frame_queue_threshold,static) = {
358 .path = "test frame-queue threshold",
359 .short_help = "test frame-queue threshold N (0=no limit)",
360 .function = test_frame_queue_threshold,