blob: ee632279db57d6942ab8b2cf1b1fb45913280db8 [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
Damjan Marion67655492016-11-15 12:50:28 +010023#if DPDK==1
24#include <rte_config.h>
25#include <rte_common.h>
26#include <rte_eal.h>
27#include <rte_launch.h>
28#include <rte_lcore.h>
29#endif
30
Pavel Kotucekc08a1ed2016-09-23 08:54:14 +020031static u8 *
32format_sched_policy_and_priority (u8 * s, va_list * args)
Pavel Kotucek1e765832016-09-23 08:54:14 +020033{
Pavel Kotucekc08a1ed2016-09-23 08:54:14 +020034 long i = va_arg (*args, long);
35 struct sched_param sched_param;
Pavel Kotucek1e765832016-09-23 08:54:14 +020036 u8 *t = 0;
37
Pavel Kotucekc08a1ed2016-09-23 08:54:14 +020038 switch (sched_getscheduler (i))
Pavel Kotucek1e765832016-09-23 08:54:14 +020039 {
40#define _(v,f,str) case SCHED_POLICY_##f: t = (u8 *) str; break;
41 foreach_sched_policy
42#undef _
43 }
Pavel Kotucekc08a1ed2016-09-23 08:54:14 +020044 if (sched_getparam (i, &sched_param) == 0)
45 return format (s, "%s (%d)", t, sched_param.sched_priority);
46 else
47 return format (s, "%s (n/a)", t);
Pavel Kotucek1e765832016-09-23 08:54:14 +020048}
Damjan Marion0f8ecf02016-06-27 08:30:30 +020049
50static clib_error_t *
51show_threads_fn (vlib_main_t * vm,
Dave Barach9b8ffd92016-07-08 08:13:45 -040052 unformat_input_t * input, vlib_cli_command_t * cmd)
Damjan Marion0f8ecf02016-06-27 08:30:30 +020053{
Dave Barach9b8ffd92016-07-08 08:13:45 -040054 vlib_worker_thread_t *w;
Damjan Marion0f8ecf02016-06-27 08:30:30 +020055 int i;
56
Pavel Kotucekc08a1ed2016-09-23 08:54:14 +020057 vlib_cli_output (vm, "%-7s%-20s%-12s%-8s%-25s%-7s%-7s%-7s%-10s",
58 "ID", "Name", "Type", "LWP", "Sched Policy (Priority)",
Dave Barach9b8ffd92016-07-08 08:13:45 -040059 "lcore", "Core", "Socket", "State");
Damjan Marion0f8ecf02016-06-27 08:30:30 +020060
61#if !defined(__powerpc64__)
Dave Barach9b8ffd92016-07-08 08:13:45 -040062 for (i = 0; i < vec_len (vlib_worker_threads); i++)
Damjan Marion0f8ecf02016-06-27 08:30:30 +020063 {
64 w = vlib_worker_threads + i;
Dave Barach9b8ffd92016-07-08 08:13:45 -040065 u8 *line = NULL;
Damjan Marion0f8ecf02016-06-27 08:30:30 +020066
Dave Barach9b8ffd92016-07-08 08:13:45 -040067 line = format (line, "%-7d%-20s%-12s%-8d",
68 i,
69 w->name ? w->name : (u8 *) "",
70 w->registration ? w->registration->name : "", w->lwp);
Damjan Marion0f8ecf02016-06-27 08:30:30 +020071
Pavel Kotucekc08a1ed2016-09-23 08:54:14 +020072 line = format (line, "%-25U", format_sched_policy_and_priority, w->lwp);
Pavel Kotucek1e765832016-09-23 08:54:14 +020073
Pavel Kotucek98765202016-10-07 08:37:28 +020074 int lcore = -1;
75 cpu_set_t cpuset;
76 CPU_ZERO (&cpuset);
77 int ret = -1;
78
79 ret =
80 pthread_getaffinity_np (w->thread_id, sizeof (cpu_set_t), &cpuset);
81 if (!ret)
82 {
83 int c;
84 for (c = 0; c < CPU_SETSIZE; c++)
85 if (CPU_ISSET (c, &cpuset))
86 {
87 if (lcore > -1)
88 {
89 lcore = -2;
90 break;
91 }
92 lcore = c;
93 }
94 }
95 else
96 {
97 lcore = w->lcore_id;
98 }
99
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200100 if (lcore > -1)
Dave Barach9b8ffd92016-07-08 08:13:45 -0400101 {
Pavel Kotucek98765202016-10-07 08:37:28 +0200102 const char *sys_cpu_path = "/sys/devices/system/cpu/cpu";
103 int socket_id = -1;
104 int core_id = -1;
105 u8 *p = 0;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200106
Pavel Kotucek98765202016-10-07 08:37:28 +0200107 p = format (p, "%s%u/topology/core_id%c", sys_cpu_path, lcore, 0);
108 vlib_sysfs_read ((char *) p, "%d", &core_id);
109
110 vec_reset_length (p);
111 p =
112 format (p,
113 "%s%u/topology/physical_package_id%c",
114 sys_cpu_path, lcore, 0);
115 vlib_sysfs_read ((char *) p, "%d", &socket_id);
116 vec_free (p);
117
118 line = format (line, "%-7u%-7u%-7u%", lcore, core_id, socket_id);
119#if DPDK==1
Damjan Mariondac225e2016-11-14 10:22:48 +0100120 ASSERT (lcore <= RTE_MAX_LCORE);
Dave Barach9b8ffd92016-07-08 08:13:45 -0400121 switch (lcore_config[lcore].state)
122 {
123 case WAIT:
124 line = format (line, "wait");
125 break;
126 case RUNNING:
127 line = format (line, "running");
128 break;
129 case FINISHED:
130 line = format (line, "finished");
131 break;
132 default:
133 line = format (line, "unknown");
134 }
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200135#endif
Pavel Kotucek98765202016-10-07 08:37:28 +0200136 }
137 else
138 {
139 line =
140 format (line, "%-7s%-7s%-7s%", (lcore == -2) ? "M" : "n/a", "n/a",
141 "n/a");
142 }
143
Dave Barach9b8ffd92016-07-08 08:13:45 -0400144 vlib_cli_output (vm, "%v", line);
145 vec_free (line);
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200146 }
147#endif
148
149 return 0;
150}
151
152
Dave Barach9b8ffd92016-07-08 08:13:45 -0400153/* *INDENT-OFF* */
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200154VLIB_CLI_COMMAND (show_threads_command, static) = {
155 .path = "show threads",
156 .short_help = "Show threads",
157 .function = show_threads_fn,
158};
Dave Barach9b8ffd92016-07-08 08:13:45 -0400159/* *INDENT-ON* */
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200160
161/*
162 * Trigger threads to grab frame queue trace data
163 */
164static clib_error_t *
Dave Barach9b8ffd92016-07-08 08:13:45 -0400165trace_frame_queue (vlib_main_t * vm, unformat_input_t * input,
166 vlib_cli_command_t * cmd)
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200167{
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100168 unformat_input_t _line_input, *line_input = &_line_input;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400169 clib_error_t *error = NULL;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200170 frame_queue_trace_t *fqt;
171 frame_queue_nelt_counter_t *fqh;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400172 vlib_thread_main_t *tm = vlib_get_thread_main ();
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100173 vlib_frame_queue_main_t *fqm;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200174 u32 num_fq;
175 u32 fqix;
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100176 u32 enable = 2;
177 u32 index = ~(u32) 0;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200178
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100179 if (!unformat_user (input, unformat_line_input, line_input))
180 return 0;
181
182 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Dave Barach9b8ffd92016-07-08 08:13:45 -0400183 {
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100184 if (unformat (line_input, "on"))
185 enable = 1;
186 else if (unformat (line_input, "off"))
187 enable = 0;
188 else if (unformat (line_input, "index %u"), &index)
189 ;
190 else
191 return clib_error_return (0, "parse error: '%U'",
192 format_unformat_error, line_input);
Dave Barach9b8ffd92016-07-08 08:13:45 -0400193 }
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200194
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100195 unformat_free (line_input);
196
197 if (enable > 1)
198 return clib_error_return (0, "expecting on or off");
199
200 if (vec_len (tm->frame_queue_mains) == 0)
201 return clib_error_return (0, "no worker handoffs exist");
202
203 if (index > vec_len (tm->frame_queue_mains) - 1)
204 return clib_error_return (0,
205 "expecting valid worker handoff queue index");
206
207 fqm = vec_elt_at_index (tm->frame_queue_mains, index);
208
209 num_fq = vec_len (fqm->vlib_frame_queues);
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200210 if (num_fq == 0)
211 {
Dave Barach9b8ffd92016-07-08 08:13:45 -0400212 vlib_cli_output (vm, "No frame queues exist\n");
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200213 return error;
214 }
215
216 // Allocate storage for trace if necessary
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100217 vec_validate_aligned (fqm->frame_queue_traces, num_fq - 1,
Dave Barach9b8ffd92016-07-08 08:13:45 -0400218 CLIB_CACHE_LINE_BYTES);
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100219 vec_validate_aligned (fqm->frame_queue_histogram, num_fq - 1,
Dave Barach9b8ffd92016-07-08 08:13:45 -0400220 CLIB_CACHE_LINE_BYTES);
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200221
Dave Barach9b8ffd92016-07-08 08:13:45 -0400222 for (fqix = 0; fqix < num_fq; fqix++)
223 {
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100224 fqt = &fqm->frame_queue_traces[fqix];
225 fqh = &fqm->frame_queue_histogram[fqix];
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200226
Dave Barach9b8ffd92016-07-08 08:13:45 -0400227 memset (fqt->n_vectors, 0xff, sizeof (fqt->n_vectors));
228 fqt->written = 0;
229 memset (fqh, 0, sizeof (*fqh));
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100230 fqm->vlib_frame_queues[fqix]->trace = enable;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400231 }
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200232 return error;
233}
234
Dave Barach9b8ffd92016-07-08 08:13:45 -0400235/* *INDENT-OFF* */
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200236VLIB_CLI_COMMAND (cmd_trace_frame_queue,static) = {
237 .path = "trace frame-queue",
238 .short_help = "trace frame-queue (on|off)",
239 .function = trace_frame_queue,
240 .is_mp_safe = 1,
241};
Dave Barach9b8ffd92016-07-08 08:13:45 -0400242/* *INDENT-ON* */
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200243
244
245/*
246 * Adding two counters and compute percent of total
247 * Round up, e.g. 0.000001 => 1%
248 */
249static u32
Dave Barach9b8ffd92016-07-08 08:13:45 -0400250compute_percent (u64 * two_counters, u64 total)
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200251{
Dave Barach9b8ffd92016-07-08 08:13:45 -0400252 if (total == 0)
253 {
254 return 0;
255 }
256 else
257 {
258 return (((two_counters[0] + two_counters[1]) * 100) +
259 (total - 1)) / total;
260 }
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200261}
262
263/*
264 * Display frame queue trace data gathered by threads.
265 */
266static clib_error_t *
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100267show_frame_queue_internal (vlib_main_t * vm,
268 vlib_frame_queue_main_t * fqm, u32 histogram)
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200269{
Dave Barach9b8ffd92016-07-08 08:13:45 -0400270 clib_error_t *error = NULL;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200271 frame_queue_trace_t *fqt;
272 frame_queue_nelt_counter_t *fqh;
273 u32 num_fq;
274 u32 fqix;
275
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100276 num_fq = vec_len (fqm->frame_queue_traces);
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200277 if (num_fq == 0)
278 {
Dave Barach9b8ffd92016-07-08 08:13:45 -0400279 vlib_cli_output (vm, "No trace data for frame queues\n");
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200280 return error;
281 }
282
283 if (histogram)
284 {
Dave Barach9b8ffd92016-07-08 08:13:45 -0400285 vlib_cli_output (vm, "0-1 2-3 4-5 6-7 8-9 10-11 12-13 14-15 "
286 "16-17 18-19 20-21 22-23 24-25 26-27 28-29 30-31\n");
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200287 }
288
Dave Barach9b8ffd92016-07-08 08:13:45 -0400289 for (fqix = 0; fqix < num_fq; fqix++)
290 {
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100291 fqt = &(fqm->frame_queue_traces[fqix]);
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200292
Dave Barach9b8ffd92016-07-08 08:13:45 -0400293 vlib_cli_output (vm, "Thread %d %v\n", fqix,
294 vlib_worker_threads[fqix].name);
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200295
Dave Barach9b8ffd92016-07-08 08:13:45 -0400296 if (fqt->written == 0)
297 {
298 vlib_cli_output (vm, " no trace data\n");
299 continue;
300 }
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200301
Dave Barach9b8ffd92016-07-08 08:13:45 -0400302 if (histogram)
303 {
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100304 fqh = &(fqm->frame_queue_histogram[fqix]);
Dave Barach9b8ffd92016-07-08 08:13:45 -0400305 u32 nelt;
306 u64 total = 0;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200307
Dave Barach9b8ffd92016-07-08 08:13:45 -0400308 for (nelt = 0; nelt < FRAME_QUEUE_MAX_NELTS; nelt++)
309 {
310 total += fqh->count[nelt];
311 }
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200312
Dave Barach9b8ffd92016-07-08 08:13:45 -0400313 /*
314 * Print in pairs to condense the output.
315 * Allow entries with 0 counts to be clearly identified, by rounding up.
316 * Any non-zero value will be displayed as at least one percent. This
317 * also means the sum of percentages can be > 100, but that is fine. The
318 * histogram is counted from the last time "trace frame on" was issued.
319 */
320 vlib_cli_output (vm,
321 "%3d%% %3d%% %3d%% %3d%% %3d%% %3d%% %3d%% %3d%% "
322 "%3d%% %3d%% %3d%% %3d%% %3d%% %3d%% %3d%% %3d%%\n",
323 compute_percent (&fqh->count[0], total),
324 compute_percent (&fqh->count[2], total),
325 compute_percent (&fqh->count[4], total),
326 compute_percent (&fqh->count[6], total),
327 compute_percent (&fqh->count[8], total),
328 compute_percent (&fqh->count[10], total),
329 compute_percent (&fqh->count[12], total),
330 compute_percent (&fqh->count[14], total),
331 compute_percent (&fqh->count[16], total),
332 compute_percent (&fqh->count[18], total),
333 compute_percent (&fqh->count[20], total),
334 compute_percent (&fqh->count[22], total),
335 compute_percent (&fqh->count[24], total),
336 compute_percent (&fqh->count[26], total),
337 compute_percent (&fqh->count[28], total),
338 compute_percent (&fqh->count[30], total));
339 }
340 else
341 {
342 vlib_cli_output (vm,
343 " vector-threshold %d ring size %d in use %d\n",
344 fqt->threshold, fqt->nelts, fqt->n_in_use);
345 vlib_cli_output (vm, " head %12d head_hint %12d tail %12d\n",
346 fqt->head, fqt->head_hint, fqt->tail);
347 vlib_cli_output (vm,
348 " %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d\n",
349 fqt->n_vectors[0], fqt->n_vectors[1],
350 fqt->n_vectors[2], fqt->n_vectors[3],
351 fqt->n_vectors[4], fqt->n_vectors[5],
352 fqt->n_vectors[6], fqt->n_vectors[7],
353 fqt->n_vectors[8], fqt->n_vectors[9],
354 fqt->n_vectors[10], fqt->n_vectors[11],
355 fqt->n_vectors[12], fqt->n_vectors[13],
356 fqt->n_vectors[14], fqt->n_vectors[15]);
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200357
Dave Barach9b8ffd92016-07-08 08:13:45 -0400358 if (fqt->nelts > 16)
359 {
360 vlib_cli_output (vm,
361 " %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d\n",
362 fqt->n_vectors[16], fqt->n_vectors[17],
363 fqt->n_vectors[18], fqt->n_vectors[19],
364 fqt->n_vectors[20], fqt->n_vectors[21],
365 fqt->n_vectors[22], fqt->n_vectors[23],
366 fqt->n_vectors[24], fqt->n_vectors[25],
367 fqt->n_vectors[26], fqt->n_vectors[27],
368 fqt->n_vectors[28], fqt->n_vectors[29],
369 fqt->n_vectors[30], fqt->n_vectors[31]);
370 }
371 }
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200372
Dave Barach9b8ffd92016-07-08 08:13:45 -0400373 }
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200374 return error;
375}
376
377static clib_error_t *
Dave Barach9b8ffd92016-07-08 08:13:45 -0400378show_frame_queue_trace (vlib_main_t * vm, unformat_input_t * input,
379 vlib_cli_command_t * cmd)
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200380{
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100381 vlib_thread_main_t *tm = vlib_get_thread_main ();
382 vlib_frame_queue_main_t *fqm;
383 clib_error_t *error;
384
385 vec_foreach (fqm, tm->frame_queue_mains)
386 {
387 vlib_cli_output (vm, "Worker handoff queue index %u (next node '%U'):",
388 fqm - tm->frame_queue_mains,
389 format_vlib_node_name, vm, fqm->node_index);
390 error = show_frame_queue_internal (vm, fqm, 0);
391 if (error)
392 return error;
393 }
394 return 0;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200395}
396
397static clib_error_t *
Dave Barach9b8ffd92016-07-08 08:13:45 -0400398show_frame_queue_histogram (vlib_main_t * vm, unformat_input_t * input,
399 vlib_cli_command_t * cmd)
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200400{
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100401 vlib_thread_main_t *tm = vlib_get_thread_main ();
402 vlib_frame_queue_main_t *fqm;
403 clib_error_t *error;
404
405 vec_foreach (fqm, tm->frame_queue_mains)
406 {
407 vlib_cli_output (vm, "Worker handoff queue index %u (next node '%U'):",
408 fqm - tm->frame_queue_mains,
409 format_vlib_node_name, vm, fqm->node_index);
410 error = show_frame_queue_internal (vm, fqm, 1);
411 if (error)
412 return error;
413 }
414 return 0;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200415}
416
Dave Barach9b8ffd92016-07-08 08:13:45 -0400417/* *INDENT-OFF* */
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200418VLIB_CLI_COMMAND (cmd_show_frame_queue_trace,static) = {
419 .path = "show frame-queue",
420 .short_help = "show frame-queue trace",
421 .function = show_frame_queue_trace,
422};
Dave Barach9b8ffd92016-07-08 08:13:45 -0400423/* *INDENT-ON* */
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200424
Dave Barach9b8ffd92016-07-08 08:13:45 -0400425/* *INDENT-OFF* */
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200426VLIB_CLI_COMMAND (cmd_show_frame_queue_histogram,static) = {
427 .path = "show frame-queue histogram",
428 .short_help = "show frame-queue histogram",
429 .function = show_frame_queue_histogram,
430};
Dave Barach9b8ffd92016-07-08 08:13:45 -0400431/* *INDENT-ON* */
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200432
433
434/*
435 * Modify the number of elements on the frame_queues
436 */
437static clib_error_t *
Dave Barach9b8ffd92016-07-08 08:13:45 -0400438test_frame_queue_nelts (vlib_main_t * vm, unformat_input_t * input,
439 vlib_cli_command_t * cmd)
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200440{
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100441 unformat_input_t _line_input, *line_input = &_line_input;
442 vlib_thread_main_t *tm = vlib_get_thread_main ();
443 vlib_frame_queue_main_t *fqm;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400444 clib_error_t *error = NULL;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200445 u32 num_fq;
446 u32 fqix;
447 u32 nelts = 0;
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100448 u32 index = ~(u32) 0;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200449
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100450 if (!unformat_user (input, unformat_line_input, line_input))
451 return 0;
452
453 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
454 {
Dave Barach7afe9e32016-11-22 15:23:41 -0500455 if (unformat (line_input, "nelts %u", &nelts))
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100456 ;
Dave Barach7afe9e32016-11-22 15:23:41 -0500457 else if (unformat (line_input, "index %u", &index))
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100458 ;
459 else
460 return clib_error_return (0, "parse error: '%U'",
461 format_unformat_error, line_input);
462 }
463
464 unformat_free (line_input);
465
466 if (index > vec_len (tm->frame_queue_mains) - 1)
467 return clib_error_return (0,
468 "expecting valid worker handoff queue index");
469
470 fqm = vec_elt_at_index (tm->frame_queue_mains, index);
471
472 if ((nelts != 4) && (nelts != 8) && (nelts != 16) && (nelts != 32))
Dave Barach9b8ffd92016-07-08 08:13:45 -0400473 {
474 return clib_error_return (0, "expecting 4,8,16,32");
475 }
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200476
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100477 num_fq = vec_len (fqm->vlib_frame_queues);
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200478 if (num_fq == 0)
479 {
Dave Barach9b8ffd92016-07-08 08:13:45 -0400480 vlib_cli_output (vm, "No frame queues exist\n");
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200481 return error;
482 }
483
Dave Barach9b8ffd92016-07-08 08:13:45 -0400484 for (fqix = 0; fqix < num_fq; fqix++)
485 {
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100486 fqm->vlib_frame_queues[fqix]->nelts = nelts;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400487 }
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200488
489 return error;
490}
491
Dave Barach9b8ffd92016-07-08 08:13:45 -0400492/* *INDENT-OFF* */
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200493VLIB_CLI_COMMAND (cmd_test_frame_queue_nelts,static) = {
494 .path = "test frame-queue nelts",
495 .short_help = "test frame-queue nelts (4,8,16,32)",
496 .function = test_frame_queue_nelts,
497};
Dave Barach9b8ffd92016-07-08 08:13:45 -0400498/* *INDENT-ON* */
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200499
500
501/*
502 * Modify the max number of packets pulled off the frame queues
503 */
504static clib_error_t *
Dave Barach9b8ffd92016-07-08 08:13:45 -0400505test_frame_queue_threshold (vlib_main_t * vm, unformat_input_t * input,
506 vlib_cli_command_t * cmd)
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200507{
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100508 unformat_input_t _line_input, *line_input = &_line_input;
509 vlib_thread_main_t *tm = vlib_get_thread_main ();
510 vlib_frame_queue_main_t *fqm;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400511 clib_error_t *error = NULL;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200512 u32 num_fq;
513 u32 fqix;
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100514 u32 threshold = ~(u32) 0;
515 u32 index = ~(u32) 0;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200516
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100517 if (!unformat_user (input, unformat_line_input, line_input))
518 return 0;
519
520 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Dave Barach9b8ffd92016-07-08 08:13:45 -0400521 {
Dave Barach7afe9e32016-11-22 15:23:41 -0500522 if (unformat (line_input, "threshold %u", &threshold))
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100523 ;
Dave Barach7afe9e32016-11-22 15:23:41 -0500524 else if (unformat (line_input, "index %u", &index))
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100525 ;
526 else
527 return clib_error_return (0, "parse error: '%U'",
528 format_unformat_error, line_input);
Dave Barach9b8ffd92016-07-08 08:13:45 -0400529 }
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100530
531 unformat_free (line_input);
532
533 if (index > vec_len (tm->frame_queue_mains) - 1)
534 return clib_error_return (0,
535 "expecting valid worker handoff queue index");
536
537 fqm = vec_elt_at_index (tm->frame_queue_mains, index);
538
539
540 if (threshold == ~(u32) 0)
Dave Barach9b8ffd92016-07-08 08:13:45 -0400541 {
542 vlib_cli_output (vm, "expecting threshold value\n");
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200543 return error;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400544 }
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200545
546 if (threshold == 0)
547 threshold = ~0;
548
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100549 num_fq = vec_len (fqm->vlib_frame_queues);
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200550 if (num_fq == 0)
551 {
Dave Barach9b8ffd92016-07-08 08:13:45 -0400552 vlib_cli_output (vm, "No frame queues exist\n");
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200553 return error;
554 }
555
Dave Barach9b8ffd92016-07-08 08:13:45 -0400556 for (fqix = 0; fqix < num_fq; fqix++)
557 {
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100558 fqm->vlib_frame_queues[fqix]->vector_threshold = threshold;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400559 }
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200560
561 return error;
562}
563
Dave Barach9b8ffd92016-07-08 08:13:45 -0400564/* *INDENT-OFF* */
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200565VLIB_CLI_COMMAND (cmd_test_frame_queue_threshold,static) = {
566 .path = "test frame-queue threshold",
567 .short_help = "test frame-queue threshold N (0=no limit)",
568 .function = test_frame_queue_threshold,
569};
Dave Barach9b8ffd92016-07-08 08:13:45 -0400570/* *INDENT-ON* */
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200571
Dave Barach9b8ffd92016-07-08 08:13:45 -0400572
573/*
574 * fd.io coding-style-patch-verification: ON
575 *
576 * Local Variables:
577 * eval: (c-set-style "gnu")
578 * End:
579 */