blob: 86c024798928568a133ca3788e733f5e189e637f [file] [log] [blame]
Damjan Marion0f8ecf02016-06-27 08:30:30 +02001/*
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:
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 */
Pavel Kotucek98765202016-10-07 08:37:28 +020015#define _GNU_SOURCE
Damjan Marion0f8ecf02016-06-27 08:30:30 +020016
17#include <vppinfra/format.h>
18#include <vlib/vlib.h>
19
20#include <vlib/threads.h>
Pavel Kotucek98765202016-10-07 08:37:28 +020021#include <vlib/unix/unix.h>
Pavel Kotucek1e765832016-09-23 08:54:14 +020022
Pavel Kotucekc08a1ed2016-09-23 08:54:14 +020023static u8 *
24format_sched_policy_and_priority (u8 * s, va_list * args)
Pavel Kotucek1e765832016-09-23 08:54:14 +020025{
Pavel Kotucekc08a1ed2016-09-23 08:54:14 +020026 long i = va_arg (*args, long);
27 struct sched_param sched_param;
Pavel Kotucek1e765832016-09-23 08:54:14 +020028 u8 *t = 0;
29
Pavel Kotucekc08a1ed2016-09-23 08:54:14 +020030 switch (sched_getscheduler (i))
Pavel Kotucek1e765832016-09-23 08:54:14 +020031 {
32#define _(v,f,str) case SCHED_POLICY_##f: t = (u8 *) str; break;
33 foreach_sched_policy
34#undef _
35 }
Pavel Kotucekc08a1ed2016-09-23 08:54:14 +020036 if (sched_getparam (i, &sched_param) == 0)
37 return format (s, "%s (%d)", t, sched_param.sched_priority);
38 else
39 return format (s, "%s (n/a)", t);
Pavel Kotucek1e765832016-09-23 08:54:14 +020040}
Damjan Marion0f8ecf02016-06-27 08:30:30 +020041
42static clib_error_t *
43show_threads_fn (vlib_main_t * vm,
Dave Barach9b8ffd92016-07-08 08:13:45 -040044 unformat_input_t * input, vlib_cli_command_t * cmd)
Damjan Marion0f8ecf02016-06-27 08:30:30 +020045{
Dave Barach9b8ffd92016-07-08 08:13:45 -040046 vlib_worker_thread_t *w;
Damjan Marion0f8ecf02016-06-27 08:30:30 +020047 int i;
48
Pavel Kotucekc08a1ed2016-09-23 08:54:14 +020049 vlib_cli_output (vm, "%-7s%-20s%-12s%-8s%-25s%-7s%-7s%-7s%-10s",
50 "ID", "Name", "Type", "LWP", "Sched Policy (Priority)",
Dave Barach9b8ffd92016-07-08 08:13:45 -040051 "lcore", "Core", "Socket", "State");
Damjan Marion0f8ecf02016-06-27 08:30:30 +020052
53#if !defined(__powerpc64__)
Dave Barach9b8ffd92016-07-08 08:13:45 -040054 for (i = 0; i < vec_len (vlib_worker_threads); i++)
Damjan Marion0f8ecf02016-06-27 08:30:30 +020055 {
56 w = vlib_worker_threads + i;
Dave Barach9b8ffd92016-07-08 08:13:45 -040057 u8 *line = NULL;
Damjan Marion0f8ecf02016-06-27 08:30:30 +020058
Dave Barach9b8ffd92016-07-08 08:13:45 -040059 line = format (line, "%-7d%-20s%-12s%-8d",
60 i,
61 w->name ? w->name : (u8 *) "",
62 w->registration ? w->registration->name : "", w->lwp);
Damjan Marion0f8ecf02016-06-27 08:30:30 +020063
Pavel Kotucekc08a1ed2016-09-23 08:54:14 +020064 line = format (line, "%-25U", format_sched_policy_and_priority, w->lwp);
Pavel Kotucek1e765832016-09-23 08:54:14 +020065
Mohsin Kazmi5d64c782018-09-11 20:27:09 +020066 int cpu_id = w->cpu_id;
67 if (cpu_id > -1)
Pavel Kotucek98765202016-10-07 08:37:28 +020068 {
Mohsin Kazmi5d64c782018-09-11 20:27:09 +020069 int core_id = w->core_id;
70 int socket_id = w->socket_id;
71 line = format (line, "%-7u%-7u%-7u%", cpu_id, core_id, socket_id);
Pavel Kotucek98765202016-10-07 08:37:28 +020072 }
73 else
74 {
Mohsin Kazmi5d64c782018-09-11 20:27:09 +020075 line = format (line, "%-7s%-7s%-7s%", "n/a", "n/a", "n/a");
Pavel Kotucek98765202016-10-07 08:37:28 +020076 }
77
Dave Barach9b8ffd92016-07-08 08:13:45 -040078 vlib_cli_output (vm, "%v", line);
79 vec_free (line);
Damjan Marion0f8ecf02016-06-27 08:30:30 +020080 }
81#endif
82
83 return 0;
84}
85
86
Dave Barach9b8ffd92016-07-08 08:13:45 -040087/* *INDENT-OFF* */
Damjan Marion0f8ecf02016-06-27 08:30:30 +020088VLIB_CLI_COMMAND (show_threads_command, static) = {
89 .path = "show threads",
90 .short_help = "Show threads",
91 .function = show_threads_fn,
92};
Dave Barach9b8ffd92016-07-08 08:13:45 -040093/* *INDENT-ON* */
Damjan Marion0f8ecf02016-06-27 08:30:30 +020094
95/*
96 * Trigger threads to grab frame queue trace data
97 */
98static clib_error_t *
Dave Barach9b8ffd92016-07-08 08:13:45 -040099trace_frame_queue (vlib_main_t * vm, unformat_input_t * input,
100 vlib_cli_command_t * cmd)
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200101{
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100102 unformat_input_t _line_input, *line_input = &_line_input;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400103 clib_error_t *error = NULL;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200104 frame_queue_trace_t *fqt;
105 frame_queue_nelt_counter_t *fqh;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400106 vlib_thread_main_t *tm = vlib_get_thread_main ();
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100107 vlib_frame_queue_main_t *fqm;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200108 u32 num_fq;
109 u32 fqix;
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100110 u32 enable = 2;
111 u32 index = ~(u32) 0;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200112
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100113 if (!unformat_user (input, unformat_line_input, line_input))
114 return 0;
115
116 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Dave Barach9b8ffd92016-07-08 08:13:45 -0400117 {
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100118 if (unformat (line_input, "on"))
119 enable = 1;
120 else if (unformat (line_input, "off"))
121 enable = 0;
Matus Fabian2d41f162017-02-21 22:27:13 -0800122 else if (unformat (line_input, "index %u", &index))
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100123 ;
124 else
Billy McFalla9a20e72017-02-15 11:39:12 -0500125 {
126 error = clib_error_return (0, "parse error: '%U'",
127 format_unformat_error, line_input);
128 goto done;
129 }
Dave Barach9b8ffd92016-07-08 08:13:45 -0400130 }
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200131
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100132 if (enable > 1)
Billy McFalla9a20e72017-02-15 11:39:12 -0500133 {
134 error = clib_error_return (0, "expecting on or off");
135 goto done;
136 }
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100137
138 if (vec_len (tm->frame_queue_mains) == 0)
Billy McFalla9a20e72017-02-15 11:39:12 -0500139 {
140 error = clib_error_return (0, "no worker handoffs exist");
141 goto done;
142 }
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100143
144 if (index > vec_len (tm->frame_queue_mains) - 1)
Billy McFalla9a20e72017-02-15 11:39:12 -0500145 {
146 error = clib_error_return (0,
147 "expecting valid worker handoff queue index");
148 goto done;
149 }
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100150
151 fqm = vec_elt_at_index (tm->frame_queue_mains, index);
152
153 num_fq = vec_len (fqm->vlib_frame_queues);
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200154 if (num_fq == 0)
155 {
Dave Barach9b8ffd92016-07-08 08:13:45 -0400156 vlib_cli_output (vm, "No frame queues exist\n");
Billy McFalla9a20e72017-02-15 11:39:12 -0500157 goto done;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200158 }
159
160 // Allocate storage for trace if necessary
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100161 vec_validate_aligned (fqm->frame_queue_traces, num_fq - 1,
Dave Barach9b8ffd92016-07-08 08:13:45 -0400162 CLIB_CACHE_LINE_BYTES);
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100163 vec_validate_aligned (fqm->frame_queue_histogram, num_fq - 1,
Dave Barach9b8ffd92016-07-08 08:13:45 -0400164 CLIB_CACHE_LINE_BYTES);
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200165
Dave Barach9b8ffd92016-07-08 08:13:45 -0400166 for (fqix = 0; fqix < num_fq; fqix++)
167 {
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100168 fqt = &fqm->frame_queue_traces[fqix];
169 fqh = &fqm->frame_queue_histogram[fqix];
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200170
Dave Barach9b8ffd92016-07-08 08:13:45 -0400171 memset (fqt->n_vectors, 0xff, sizeof (fqt->n_vectors));
172 fqt->written = 0;
173 memset (fqh, 0, sizeof (*fqh));
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100174 fqm->vlib_frame_queues[fqix]->trace = enable;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400175 }
Billy McFalla9a20e72017-02-15 11:39:12 -0500176
177done:
178 unformat_free (line_input);
179
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200180 return error;
181}
182
Dave Barach9b8ffd92016-07-08 08:13:45 -0400183/* *INDENT-OFF* */
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200184VLIB_CLI_COMMAND (cmd_trace_frame_queue,static) = {
185 .path = "trace frame-queue",
186 .short_help = "trace frame-queue (on|off)",
187 .function = trace_frame_queue,
188 .is_mp_safe = 1,
189};
Dave Barach9b8ffd92016-07-08 08:13:45 -0400190/* *INDENT-ON* */
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200191
192
193/*
194 * Adding two counters and compute percent of total
195 * Round up, e.g. 0.000001 => 1%
196 */
197static u32
Dave Barach9b8ffd92016-07-08 08:13:45 -0400198compute_percent (u64 * two_counters, u64 total)
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200199{
Dave Barach9b8ffd92016-07-08 08:13:45 -0400200 if (total == 0)
201 {
202 return 0;
203 }
204 else
205 {
206 return (((two_counters[0] + two_counters[1]) * 100) +
207 (total - 1)) / total;
208 }
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200209}
210
211/*
212 * Display frame queue trace data gathered by threads.
213 */
214static clib_error_t *
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100215show_frame_queue_internal (vlib_main_t * vm,
216 vlib_frame_queue_main_t * fqm, u32 histogram)
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200217{
Dave Barach9b8ffd92016-07-08 08:13:45 -0400218 clib_error_t *error = NULL;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200219 frame_queue_trace_t *fqt;
220 frame_queue_nelt_counter_t *fqh;
221 u32 num_fq;
222 u32 fqix;
223
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100224 num_fq = vec_len (fqm->frame_queue_traces);
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200225 if (num_fq == 0)
226 {
Dave Barach9b8ffd92016-07-08 08:13:45 -0400227 vlib_cli_output (vm, "No trace data for frame queues\n");
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200228 return error;
229 }
230
231 if (histogram)
232 {
Dave Barach9b8ffd92016-07-08 08:13:45 -0400233 vlib_cli_output (vm, "0-1 2-3 4-5 6-7 8-9 10-11 12-13 14-15 "
234 "16-17 18-19 20-21 22-23 24-25 26-27 28-29 30-31\n");
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200235 }
236
Dave Barach9b8ffd92016-07-08 08:13:45 -0400237 for (fqix = 0; fqix < num_fq; fqix++)
238 {
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100239 fqt = &(fqm->frame_queue_traces[fqix]);
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200240
Dave Barach9b8ffd92016-07-08 08:13:45 -0400241 vlib_cli_output (vm, "Thread %d %v\n", fqix,
242 vlib_worker_threads[fqix].name);
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200243
Dave Barach9b8ffd92016-07-08 08:13:45 -0400244 if (fqt->written == 0)
245 {
246 vlib_cli_output (vm, " no trace data\n");
247 continue;
248 }
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200249
Dave Barach9b8ffd92016-07-08 08:13:45 -0400250 if (histogram)
251 {
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100252 fqh = &(fqm->frame_queue_histogram[fqix]);
Dave Barach9b8ffd92016-07-08 08:13:45 -0400253 u32 nelt;
254 u64 total = 0;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200255
Dave Barach9b8ffd92016-07-08 08:13:45 -0400256 for (nelt = 0; nelt < FRAME_QUEUE_MAX_NELTS; nelt++)
257 {
258 total += fqh->count[nelt];
259 }
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200260
Dave Barach9b8ffd92016-07-08 08:13:45 -0400261 /*
262 * Print in pairs to condense the output.
263 * Allow entries with 0 counts to be clearly identified, by rounding up.
264 * Any non-zero value will be displayed as at least one percent. This
265 * also means the sum of percentages can be > 100, but that is fine. The
266 * histogram is counted from the last time "trace frame on" was issued.
267 */
268 vlib_cli_output (vm,
269 "%3d%% %3d%% %3d%% %3d%% %3d%% %3d%% %3d%% %3d%% "
270 "%3d%% %3d%% %3d%% %3d%% %3d%% %3d%% %3d%% %3d%%\n",
271 compute_percent (&fqh->count[0], total),
272 compute_percent (&fqh->count[2], total),
273 compute_percent (&fqh->count[4], total),
274 compute_percent (&fqh->count[6], total),
275 compute_percent (&fqh->count[8], total),
276 compute_percent (&fqh->count[10], total),
277 compute_percent (&fqh->count[12], total),
278 compute_percent (&fqh->count[14], total),
279 compute_percent (&fqh->count[16], total),
280 compute_percent (&fqh->count[18], total),
281 compute_percent (&fqh->count[20], total),
282 compute_percent (&fqh->count[22], total),
283 compute_percent (&fqh->count[24], total),
284 compute_percent (&fqh->count[26], total),
285 compute_percent (&fqh->count[28], total),
286 compute_percent (&fqh->count[30], total));
287 }
288 else
289 {
290 vlib_cli_output (vm,
291 " vector-threshold %d ring size %d in use %d\n",
292 fqt->threshold, fqt->nelts, fqt->n_in_use);
293 vlib_cli_output (vm, " head %12d head_hint %12d tail %12d\n",
294 fqt->head, fqt->head_hint, fqt->tail);
295 vlib_cli_output (vm,
296 " %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d\n",
297 fqt->n_vectors[0], fqt->n_vectors[1],
298 fqt->n_vectors[2], fqt->n_vectors[3],
299 fqt->n_vectors[4], fqt->n_vectors[5],
300 fqt->n_vectors[6], fqt->n_vectors[7],
301 fqt->n_vectors[8], fqt->n_vectors[9],
302 fqt->n_vectors[10], fqt->n_vectors[11],
303 fqt->n_vectors[12], fqt->n_vectors[13],
304 fqt->n_vectors[14], fqt->n_vectors[15]);
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200305
Dave Barach9b8ffd92016-07-08 08:13:45 -0400306 if (fqt->nelts > 16)
307 {
308 vlib_cli_output (vm,
309 " %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d\n",
310 fqt->n_vectors[16], fqt->n_vectors[17],
311 fqt->n_vectors[18], fqt->n_vectors[19],
312 fqt->n_vectors[20], fqt->n_vectors[21],
313 fqt->n_vectors[22], fqt->n_vectors[23],
314 fqt->n_vectors[24], fqt->n_vectors[25],
315 fqt->n_vectors[26], fqt->n_vectors[27],
316 fqt->n_vectors[28], fqt->n_vectors[29],
317 fqt->n_vectors[30], fqt->n_vectors[31]);
318 }
319 }
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200320
Dave Barach9b8ffd92016-07-08 08:13:45 -0400321 }
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200322 return error;
323}
324
325static clib_error_t *
Dave Barach9b8ffd92016-07-08 08:13:45 -0400326show_frame_queue_trace (vlib_main_t * vm, unformat_input_t * input,
327 vlib_cli_command_t * cmd)
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200328{
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100329 vlib_thread_main_t *tm = vlib_get_thread_main ();
330 vlib_frame_queue_main_t *fqm;
331 clib_error_t *error;
332
333 vec_foreach (fqm, tm->frame_queue_mains)
334 {
335 vlib_cli_output (vm, "Worker handoff queue index %u (next node '%U'):",
336 fqm - tm->frame_queue_mains,
337 format_vlib_node_name, vm, fqm->node_index);
338 error = show_frame_queue_internal (vm, fqm, 0);
339 if (error)
340 return error;
341 }
342 return 0;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200343}
344
345static clib_error_t *
Dave Barach9b8ffd92016-07-08 08:13:45 -0400346show_frame_queue_histogram (vlib_main_t * vm, unformat_input_t * input,
347 vlib_cli_command_t * cmd)
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200348{
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100349 vlib_thread_main_t *tm = vlib_get_thread_main ();
350 vlib_frame_queue_main_t *fqm;
351 clib_error_t *error;
352
353 vec_foreach (fqm, tm->frame_queue_mains)
354 {
355 vlib_cli_output (vm, "Worker handoff queue index %u (next node '%U'):",
356 fqm - tm->frame_queue_mains,
357 format_vlib_node_name, vm, fqm->node_index);
358 error = show_frame_queue_internal (vm, fqm, 1);
359 if (error)
360 return error;
361 }
362 return 0;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200363}
364
Dave Barach9b8ffd92016-07-08 08:13:45 -0400365/* *INDENT-OFF* */
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200366VLIB_CLI_COMMAND (cmd_show_frame_queue_trace,static) = {
367 .path = "show frame-queue",
368 .short_help = "show frame-queue trace",
369 .function = show_frame_queue_trace,
370};
Dave Barach9b8ffd92016-07-08 08:13:45 -0400371/* *INDENT-ON* */
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200372
Dave Barach9b8ffd92016-07-08 08:13:45 -0400373/* *INDENT-OFF* */
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200374VLIB_CLI_COMMAND (cmd_show_frame_queue_histogram,static) = {
375 .path = "show frame-queue histogram",
376 .short_help = "show frame-queue histogram",
377 .function = show_frame_queue_histogram,
378};
Dave Barach9b8ffd92016-07-08 08:13:45 -0400379/* *INDENT-ON* */
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200380
381
382/*
383 * Modify the number of elements on the frame_queues
384 */
385static clib_error_t *
Dave Barach9b8ffd92016-07-08 08:13:45 -0400386test_frame_queue_nelts (vlib_main_t * vm, unformat_input_t * input,
387 vlib_cli_command_t * cmd)
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200388{
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100389 unformat_input_t _line_input, *line_input = &_line_input;
390 vlib_thread_main_t *tm = vlib_get_thread_main ();
391 vlib_frame_queue_main_t *fqm;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400392 clib_error_t *error = NULL;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200393 u32 num_fq;
394 u32 fqix;
395 u32 nelts = 0;
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100396 u32 index = ~(u32) 0;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200397
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100398 if (!unformat_user (input, unformat_line_input, line_input))
399 return 0;
400
401 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
402 {
Dave Barach7afe9e32016-11-22 15:23:41 -0500403 if (unformat (line_input, "nelts %u", &nelts))
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100404 ;
Dave Barach7afe9e32016-11-22 15:23:41 -0500405 else if (unformat (line_input, "index %u", &index))
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100406 ;
407 else
Billy McFalla9a20e72017-02-15 11:39:12 -0500408 {
409 error = clib_error_return (0, "parse error: '%U'",
410 format_unformat_error, line_input);
411 goto done;
412 }
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100413 }
414
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100415 if (index > vec_len (tm->frame_queue_mains) - 1)
Billy McFalla9a20e72017-02-15 11:39:12 -0500416 {
417 error = clib_error_return (0,
418 "expecting valid worker handoff queue index");
419 goto done;
420 }
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100421
422 fqm = vec_elt_at_index (tm->frame_queue_mains, index);
423
424 if ((nelts != 4) && (nelts != 8) && (nelts != 16) && (nelts != 32))
Dave Barach9b8ffd92016-07-08 08:13:45 -0400425 {
Billy McFalla9a20e72017-02-15 11:39:12 -0500426 error = clib_error_return (0, "expecting 4,8,16,32");
427 goto done;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400428 }
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200429
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100430 num_fq = vec_len (fqm->vlib_frame_queues);
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200431 if (num_fq == 0)
432 {
Dave Barach9b8ffd92016-07-08 08:13:45 -0400433 vlib_cli_output (vm, "No frame queues exist\n");
Billy McFalla9a20e72017-02-15 11:39:12 -0500434 goto done;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200435 }
436
Dave Barach9b8ffd92016-07-08 08:13:45 -0400437 for (fqix = 0; fqix < num_fq; fqix++)
438 {
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100439 fqm->vlib_frame_queues[fqix]->nelts = nelts;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400440 }
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200441
Billy McFalla9a20e72017-02-15 11:39:12 -0500442done:
443 unformat_free (line_input);
444
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200445 return error;
446}
447
Dave Barach9b8ffd92016-07-08 08:13:45 -0400448/* *INDENT-OFF* */
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200449VLIB_CLI_COMMAND (cmd_test_frame_queue_nelts,static) = {
450 .path = "test frame-queue nelts",
451 .short_help = "test frame-queue nelts (4,8,16,32)",
452 .function = test_frame_queue_nelts,
453};
Dave Barach9b8ffd92016-07-08 08:13:45 -0400454/* *INDENT-ON* */
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200455
456
457/*
458 * Modify the max number of packets pulled off the frame queues
459 */
460static clib_error_t *
Dave Barach9b8ffd92016-07-08 08:13:45 -0400461test_frame_queue_threshold (vlib_main_t * vm, unformat_input_t * input,
462 vlib_cli_command_t * cmd)
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200463{
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100464 unformat_input_t _line_input, *line_input = &_line_input;
465 vlib_thread_main_t *tm = vlib_get_thread_main ();
466 vlib_frame_queue_main_t *fqm;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400467 clib_error_t *error = NULL;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200468 u32 num_fq;
469 u32 fqix;
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100470 u32 threshold = ~(u32) 0;
471 u32 index = ~(u32) 0;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200472
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100473 if (!unformat_user (input, unformat_line_input, line_input))
474 return 0;
475
476 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Dave Barach9b8ffd92016-07-08 08:13:45 -0400477 {
Dave Barach7afe9e32016-11-22 15:23:41 -0500478 if (unformat (line_input, "threshold %u", &threshold))
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100479 ;
Dave Barach7afe9e32016-11-22 15:23:41 -0500480 else if (unformat (line_input, "index %u", &index))
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100481 ;
482 else
Billy McFalla9a20e72017-02-15 11:39:12 -0500483 {
484 error = clib_error_return (0, "parse error: '%U'",
485 format_unformat_error, line_input);
486 goto done;
487 }
Dave Barach9b8ffd92016-07-08 08:13:45 -0400488 }
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100489
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100490 if (index > vec_len (tm->frame_queue_mains) - 1)
Billy McFalla9a20e72017-02-15 11:39:12 -0500491 {
492 error = clib_error_return (0,
493 "expecting valid worker handoff queue index");
494 goto done;
495 }
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100496
497 fqm = vec_elt_at_index (tm->frame_queue_mains, index);
498
499
500 if (threshold == ~(u32) 0)
Dave Barach9b8ffd92016-07-08 08:13:45 -0400501 {
502 vlib_cli_output (vm, "expecting threshold value\n");
Billy McFalla9a20e72017-02-15 11:39:12 -0500503 goto done;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400504 }
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200505
506 if (threshold == 0)
507 threshold = ~0;
508
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100509 num_fq = vec_len (fqm->vlib_frame_queues);
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200510 if (num_fq == 0)
511 {
Dave Barach9b8ffd92016-07-08 08:13:45 -0400512 vlib_cli_output (vm, "No frame queues exist\n");
Billy McFalla9a20e72017-02-15 11:39:12 -0500513 goto done;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200514 }
515
Dave Barach9b8ffd92016-07-08 08:13:45 -0400516 for (fqix = 0; fqix < num_fq; fqix++)
517 {
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100518 fqm->vlib_frame_queues[fqix]->vector_threshold = threshold;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400519 }
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200520
Billy McFalla9a20e72017-02-15 11:39:12 -0500521done:
522 unformat_free (line_input);
523
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200524 return error;
525}
526
Dave Barach9b8ffd92016-07-08 08:13:45 -0400527/* *INDENT-OFF* */
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200528VLIB_CLI_COMMAND (cmd_test_frame_queue_threshold,static) = {
529 .path = "test frame-queue threshold",
530 .short_help = "test frame-queue threshold N (0=no limit)",
531 .function = test_frame_queue_threshold,
532};
Dave Barach9b8ffd92016-07-08 08:13:45 -0400533/* *INDENT-ON* */
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200534
Dave Barach9b8ffd92016-07-08 08:13:45 -0400535/*
536 * fd.io coding-style-patch-verification: ON
537 *
538 * Local Variables:
539 * eval: (c-set-style "gnu")
540 * End:
541 */