blob: 02bdea5cb0f6f40b7728ca2fe0aa6f7d6d7482f6 [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>
Damjan Marion01914ce2017-09-14 19:04:50 +020018#include <vppinfra/linux/sysfs.h>
Damjan Marion0f8ecf02016-06-27 08:30:30 +020019#include <vlib/vlib.h>
20
21#include <vlib/threads.h>
Pavel Kotucek98765202016-10-07 08:37:28 +020022#include <vlib/unix/unix.h>
Pavel Kotucek1e765832016-09-23 08:54:14 +020023
Pavel Kotucekc08a1ed2016-09-23 08:54:14 +020024static u8 *
25format_sched_policy_and_priority (u8 * s, va_list * args)
Pavel Kotucek1e765832016-09-23 08:54:14 +020026{
Pavel Kotucekc08a1ed2016-09-23 08:54:14 +020027 long i = va_arg (*args, long);
28 struct sched_param sched_param;
Pavel Kotucek1e765832016-09-23 08:54:14 +020029 u8 *t = 0;
30
Pavel Kotucekc08a1ed2016-09-23 08:54:14 +020031 switch (sched_getscheduler (i))
Pavel Kotucek1e765832016-09-23 08:54:14 +020032 {
33#define _(v,f,str) case SCHED_POLICY_##f: t = (u8 *) str; break;
34 foreach_sched_policy
35#undef _
36 }
Pavel Kotucekc08a1ed2016-09-23 08:54:14 +020037 if (sched_getparam (i, &sched_param) == 0)
38 return format (s, "%s (%d)", t, sched_param.sched_priority);
39 else
40 return format (s, "%s (n/a)", t);
Pavel Kotucek1e765832016-09-23 08:54:14 +020041}
Damjan Marion0f8ecf02016-06-27 08:30:30 +020042
43static clib_error_t *
44show_threads_fn (vlib_main_t * vm,
Dave Barach9b8ffd92016-07-08 08:13:45 -040045 unformat_input_t * input, vlib_cli_command_t * cmd)
Damjan Marion0f8ecf02016-06-27 08:30:30 +020046{
Dave Barach9b8ffd92016-07-08 08:13:45 -040047 vlib_worker_thread_t *w;
Damjan Marion0f8ecf02016-06-27 08:30:30 +020048 int i;
49
Pavel Kotucekc08a1ed2016-09-23 08:54:14 +020050 vlib_cli_output (vm, "%-7s%-20s%-12s%-8s%-25s%-7s%-7s%-7s%-10s",
51 "ID", "Name", "Type", "LWP", "Sched Policy (Priority)",
Dave Barach9b8ffd92016-07-08 08:13:45 -040052 "lcore", "Core", "Socket", "State");
Damjan Marion0f8ecf02016-06-27 08:30:30 +020053
54#if !defined(__powerpc64__)
Dave Barach9b8ffd92016-07-08 08:13:45 -040055 for (i = 0; i < vec_len (vlib_worker_threads); i++)
Damjan Marion0f8ecf02016-06-27 08:30:30 +020056 {
57 w = vlib_worker_threads + i;
Dave Barach9b8ffd92016-07-08 08:13:45 -040058 u8 *line = NULL;
Damjan Marion0f8ecf02016-06-27 08:30:30 +020059
Dave Barach9b8ffd92016-07-08 08:13:45 -040060 line = format (line, "%-7d%-20s%-12s%-8d",
61 i,
62 w->name ? w->name : (u8 *) "",
63 w->registration ? w->registration->name : "", w->lwp);
Damjan Marion0f8ecf02016-06-27 08:30:30 +020064
Pavel Kotucekc08a1ed2016-09-23 08:54:14 +020065 line = format (line, "%-25U", format_sched_policy_and_priority, w->lwp);
Pavel Kotucek1e765832016-09-23 08:54:14 +020066
Pavel Kotucek98765202016-10-07 08:37:28 +020067 int lcore = -1;
68 cpu_set_t cpuset;
69 CPU_ZERO (&cpuset);
70 int ret = -1;
71
72 ret =
73 pthread_getaffinity_np (w->thread_id, sizeof (cpu_set_t), &cpuset);
74 if (!ret)
75 {
76 int c;
77 for (c = 0; c < CPU_SETSIZE; c++)
78 if (CPU_ISSET (c, &cpuset))
79 {
80 if (lcore > -1)
81 {
82 lcore = -2;
83 break;
84 }
85 lcore = c;
86 }
87 }
88 else
89 {
90 lcore = w->lcore_id;
91 }
92
Damjan Marion0f8ecf02016-06-27 08:30:30 +020093 if (lcore > -1)
Dave Barach9b8ffd92016-07-08 08:13:45 -040094 {
Pavel Kotucek98765202016-10-07 08:37:28 +020095 const char *sys_cpu_path = "/sys/devices/system/cpu/cpu";
96 int socket_id = -1;
97 int core_id = -1;
98 u8 *p = 0;
Damjan Marion0f8ecf02016-06-27 08:30:30 +020099
Pavel Kotucek98765202016-10-07 08:37:28 +0200100 p = format (p, "%s%u/topology/core_id%c", sys_cpu_path, lcore, 0);
Damjan Marion01914ce2017-09-14 19:04:50 +0200101 clib_sysfs_read ((char *) p, "%d", &core_id);
Pavel Kotucek98765202016-10-07 08:37:28 +0200102
103 vec_reset_length (p);
104 p =
105 format (p,
106 "%s%u/topology/physical_package_id%c",
107 sys_cpu_path, lcore, 0);
Damjan Marion01914ce2017-09-14 19:04:50 +0200108 clib_sysfs_read ((char *) p, "%d", &socket_id);
Pavel Kotucek98765202016-10-07 08:37:28 +0200109 vec_free (p);
110
111 line = format (line, "%-7u%-7u%-7u%", lcore, core_id, socket_id);
Pavel Kotucek98765202016-10-07 08:37:28 +0200112 }
113 else
114 {
115 line =
116 format (line, "%-7s%-7s%-7s%", (lcore == -2) ? "M" : "n/a", "n/a",
117 "n/a");
118 }
119
Dave Barach9b8ffd92016-07-08 08:13:45 -0400120 vlib_cli_output (vm, "%v", line);
121 vec_free (line);
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200122 }
123#endif
124
125 return 0;
126}
127
128
Dave Barach9b8ffd92016-07-08 08:13:45 -0400129/* *INDENT-OFF* */
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200130VLIB_CLI_COMMAND (show_threads_command, static) = {
131 .path = "show threads",
132 .short_help = "Show threads",
133 .function = show_threads_fn,
134};
Dave Barach9b8ffd92016-07-08 08:13:45 -0400135/* *INDENT-ON* */
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200136
137/*
138 * Trigger threads to grab frame queue trace data
139 */
140static clib_error_t *
Dave Barach9b8ffd92016-07-08 08:13:45 -0400141trace_frame_queue (vlib_main_t * vm, unformat_input_t * input,
142 vlib_cli_command_t * cmd)
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200143{
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100144 unformat_input_t _line_input, *line_input = &_line_input;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400145 clib_error_t *error = NULL;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200146 frame_queue_trace_t *fqt;
147 frame_queue_nelt_counter_t *fqh;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400148 vlib_thread_main_t *tm = vlib_get_thread_main ();
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100149 vlib_frame_queue_main_t *fqm;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200150 u32 num_fq;
151 u32 fqix;
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100152 u32 enable = 2;
153 u32 index = ~(u32) 0;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200154
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100155 if (!unformat_user (input, unformat_line_input, line_input))
156 return 0;
157
158 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Dave Barach9b8ffd92016-07-08 08:13:45 -0400159 {
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100160 if (unformat (line_input, "on"))
161 enable = 1;
162 else if (unformat (line_input, "off"))
163 enable = 0;
Matus Fabian2d41f162017-02-21 22:27:13 -0800164 else if (unformat (line_input, "index %u", &index))
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100165 ;
166 else
Billy McFalla9a20e72017-02-15 11:39:12 -0500167 {
168 error = clib_error_return (0, "parse error: '%U'",
169 format_unformat_error, line_input);
170 goto done;
171 }
Dave Barach9b8ffd92016-07-08 08:13:45 -0400172 }
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200173
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100174 if (enable > 1)
Billy McFalla9a20e72017-02-15 11:39:12 -0500175 {
176 error = clib_error_return (0, "expecting on or off");
177 goto done;
178 }
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100179
180 if (vec_len (tm->frame_queue_mains) == 0)
Billy McFalla9a20e72017-02-15 11:39:12 -0500181 {
182 error = clib_error_return (0, "no worker handoffs exist");
183 goto done;
184 }
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100185
186 if (index > vec_len (tm->frame_queue_mains) - 1)
Billy McFalla9a20e72017-02-15 11:39:12 -0500187 {
188 error = clib_error_return (0,
189 "expecting valid worker handoff queue index");
190 goto done;
191 }
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100192
193 fqm = vec_elt_at_index (tm->frame_queue_mains, index);
194
195 num_fq = vec_len (fqm->vlib_frame_queues);
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200196 if (num_fq == 0)
197 {
Dave Barach9b8ffd92016-07-08 08:13:45 -0400198 vlib_cli_output (vm, "No frame queues exist\n");
Billy McFalla9a20e72017-02-15 11:39:12 -0500199 goto done;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200200 }
201
202 // Allocate storage for trace if necessary
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100203 vec_validate_aligned (fqm->frame_queue_traces, num_fq - 1,
Dave Barach9b8ffd92016-07-08 08:13:45 -0400204 CLIB_CACHE_LINE_BYTES);
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100205 vec_validate_aligned (fqm->frame_queue_histogram, num_fq - 1,
Dave Barach9b8ffd92016-07-08 08:13:45 -0400206 CLIB_CACHE_LINE_BYTES);
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200207
Dave Barach9b8ffd92016-07-08 08:13:45 -0400208 for (fqix = 0; fqix < num_fq; fqix++)
209 {
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100210 fqt = &fqm->frame_queue_traces[fqix];
211 fqh = &fqm->frame_queue_histogram[fqix];
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200212
Dave Barach9b8ffd92016-07-08 08:13:45 -0400213 memset (fqt->n_vectors, 0xff, sizeof (fqt->n_vectors));
214 fqt->written = 0;
215 memset (fqh, 0, sizeof (*fqh));
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100216 fqm->vlib_frame_queues[fqix]->trace = enable;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400217 }
Billy McFalla9a20e72017-02-15 11:39:12 -0500218
219done:
220 unformat_free (line_input);
221
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200222 return error;
223}
224
Dave Barach9b8ffd92016-07-08 08:13:45 -0400225/* *INDENT-OFF* */
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200226VLIB_CLI_COMMAND (cmd_trace_frame_queue,static) = {
227 .path = "trace frame-queue",
228 .short_help = "trace frame-queue (on|off)",
229 .function = trace_frame_queue,
230 .is_mp_safe = 1,
231};
Dave Barach9b8ffd92016-07-08 08:13:45 -0400232/* *INDENT-ON* */
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200233
234
235/*
236 * Adding two counters and compute percent of total
237 * Round up, e.g. 0.000001 => 1%
238 */
239static u32
Dave Barach9b8ffd92016-07-08 08:13:45 -0400240compute_percent (u64 * two_counters, u64 total)
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200241{
Dave Barach9b8ffd92016-07-08 08:13:45 -0400242 if (total == 0)
243 {
244 return 0;
245 }
246 else
247 {
248 return (((two_counters[0] + two_counters[1]) * 100) +
249 (total - 1)) / total;
250 }
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200251}
252
253/*
254 * Display frame queue trace data gathered by threads.
255 */
256static clib_error_t *
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100257show_frame_queue_internal (vlib_main_t * vm,
258 vlib_frame_queue_main_t * fqm, u32 histogram)
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200259{
Dave Barach9b8ffd92016-07-08 08:13:45 -0400260 clib_error_t *error = NULL;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200261 frame_queue_trace_t *fqt;
262 frame_queue_nelt_counter_t *fqh;
263 u32 num_fq;
264 u32 fqix;
265
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100266 num_fq = vec_len (fqm->frame_queue_traces);
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200267 if (num_fq == 0)
268 {
Dave Barach9b8ffd92016-07-08 08:13:45 -0400269 vlib_cli_output (vm, "No trace data for frame queues\n");
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200270 return error;
271 }
272
273 if (histogram)
274 {
Dave Barach9b8ffd92016-07-08 08:13:45 -0400275 vlib_cli_output (vm, "0-1 2-3 4-5 6-7 8-9 10-11 12-13 14-15 "
276 "16-17 18-19 20-21 22-23 24-25 26-27 28-29 30-31\n");
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200277 }
278
Dave Barach9b8ffd92016-07-08 08:13:45 -0400279 for (fqix = 0; fqix < num_fq; fqix++)
280 {
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100281 fqt = &(fqm->frame_queue_traces[fqix]);
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200282
Dave Barach9b8ffd92016-07-08 08:13:45 -0400283 vlib_cli_output (vm, "Thread %d %v\n", fqix,
284 vlib_worker_threads[fqix].name);
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200285
Dave Barach9b8ffd92016-07-08 08:13:45 -0400286 if (fqt->written == 0)
287 {
288 vlib_cli_output (vm, " no trace data\n");
289 continue;
290 }
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200291
Dave Barach9b8ffd92016-07-08 08:13:45 -0400292 if (histogram)
293 {
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100294 fqh = &(fqm->frame_queue_histogram[fqix]);
Dave Barach9b8ffd92016-07-08 08:13:45 -0400295 u32 nelt;
296 u64 total = 0;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200297
Dave Barach9b8ffd92016-07-08 08:13:45 -0400298 for (nelt = 0; nelt < FRAME_QUEUE_MAX_NELTS; nelt++)
299 {
300 total += fqh->count[nelt];
301 }
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200302
Dave Barach9b8ffd92016-07-08 08:13:45 -0400303 /*
304 * Print in pairs to condense the output.
305 * Allow entries with 0 counts to be clearly identified, by rounding up.
306 * Any non-zero value will be displayed as at least one percent. This
307 * also means the sum of percentages can be > 100, but that is fine. The
308 * histogram is counted from the last time "trace frame on" was issued.
309 */
310 vlib_cli_output (vm,
311 "%3d%% %3d%% %3d%% %3d%% %3d%% %3d%% %3d%% %3d%% "
312 "%3d%% %3d%% %3d%% %3d%% %3d%% %3d%% %3d%% %3d%%\n",
313 compute_percent (&fqh->count[0], total),
314 compute_percent (&fqh->count[2], total),
315 compute_percent (&fqh->count[4], total),
316 compute_percent (&fqh->count[6], total),
317 compute_percent (&fqh->count[8], total),
318 compute_percent (&fqh->count[10], total),
319 compute_percent (&fqh->count[12], total),
320 compute_percent (&fqh->count[14], total),
321 compute_percent (&fqh->count[16], total),
322 compute_percent (&fqh->count[18], total),
323 compute_percent (&fqh->count[20], total),
324 compute_percent (&fqh->count[22], total),
325 compute_percent (&fqh->count[24], total),
326 compute_percent (&fqh->count[26], total),
327 compute_percent (&fqh->count[28], total),
328 compute_percent (&fqh->count[30], total));
329 }
330 else
331 {
332 vlib_cli_output (vm,
333 " vector-threshold %d ring size %d in use %d\n",
334 fqt->threshold, fqt->nelts, fqt->n_in_use);
335 vlib_cli_output (vm, " head %12d head_hint %12d tail %12d\n",
336 fqt->head, fqt->head_hint, fqt->tail);
337 vlib_cli_output (vm,
338 " %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d\n",
339 fqt->n_vectors[0], fqt->n_vectors[1],
340 fqt->n_vectors[2], fqt->n_vectors[3],
341 fqt->n_vectors[4], fqt->n_vectors[5],
342 fqt->n_vectors[6], fqt->n_vectors[7],
343 fqt->n_vectors[8], fqt->n_vectors[9],
344 fqt->n_vectors[10], fqt->n_vectors[11],
345 fqt->n_vectors[12], fqt->n_vectors[13],
346 fqt->n_vectors[14], fqt->n_vectors[15]);
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200347
Dave Barach9b8ffd92016-07-08 08:13:45 -0400348 if (fqt->nelts > 16)
349 {
350 vlib_cli_output (vm,
351 " %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d\n",
352 fqt->n_vectors[16], fqt->n_vectors[17],
353 fqt->n_vectors[18], fqt->n_vectors[19],
354 fqt->n_vectors[20], fqt->n_vectors[21],
355 fqt->n_vectors[22], fqt->n_vectors[23],
356 fqt->n_vectors[24], fqt->n_vectors[25],
357 fqt->n_vectors[26], fqt->n_vectors[27],
358 fqt->n_vectors[28], fqt->n_vectors[29],
359 fqt->n_vectors[30], fqt->n_vectors[31]);
360 }
361 }
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200362
Dave Barach9b8ffd92016-07-08 08:13:45 -0400363 }
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200364 return error;
365}
366
367static clib_error_t *
Dave Barach9b8ffd92016-07-08 08:13:45 -0400368show_frame_queue_trace (vlib_main_t * vm, unformat_input_t * input,
369 vlib_cli_command_t * cmd)
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200370{
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100371 vlib_thread_main_t *tm = vlib_get_thread_main ();
372 vlib_frame_queue_main_t *fqm;
373 clib_error_t *error;
374
375 vec_foreach (fqm, tm->frame_queue_mains)
376 {
377 vlib_cli_output (vm, "Worker handoff queue index %u (next node '%U'):",
378 fqm - tm->frame_queue_mains,
379 format_vlib_node_name, vm, fqm->node_index);
380 error = show_frame_queue_internal (vm, fqm, 0);
381 if (error)
382 return error;
383 }
384 return 0;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200385}
386
387static clib_error_t *
Dave Barach9b8ffd92016-07-08 08:13:45 -0400388show_frame_queue_histogram (vlib_main_t * vm, unformat_input_t * input,
389 vlib_cli_command_t * cmd)
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200390{
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100391 vlib_thread_main_t *tm = vlib_get_thread_main ();
392 vlib_frame_queue_main_t *fqm;
393 clib_error_t *error;
394
395 vec_foreach (fqm, tm->frame_queue_mains)
396 {
397 vlib_cli_output (vm, "Worker handoff queue index %u (next node '%U'):",
398 fqm - tm->frame_queue_mains,
399 format_vlib_node_name, vm, fqm->node_index);
400 error = show_frame_queue_internal (vm, fqm, 1);
401 if (error)
402 return error;
403 }
404 return 0;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200405}
406
Dave Barach9b8ffd92016-07-08 08:13:45 -0400407/* *INDENT-OFF* */
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200408VLIB_CLI_COMMAND (cmd_show_frame_queue_trace,static) = {
409 .path = "show frame-queue",
410 .short_help = "show frame-queue trace",
411 .function = show_frame_queue_trace,
412};
Dave Barach9b8ffd92016-07-08 08:13:45 -0400413/* *INDENT-ON* */
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200414
Dave Barach9b8ffd92016-07-08 08:13:45 -0400415/* *INDENT-OFF* */
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200416VLIB_CLI_COMMAND (cmd_show_frame_queue_histogram,static) = {
417 .path = "show frame-queue histogram",
418 .short_help = "show frame-queue histogram",
419 .function = show_frame_queue_histogram,
420};
Dave Barach9b8ffd92016-07-08 08:13:45 -0400421/* *INDENT-ON* */
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200422
423
424/*
425 * Modify the number of elements on the frame_queues
426 */
427static clib_error_t *
Dave Barach9b8ffd92016-07-08 08:13:45 -0400428test_frame_queue_nelts (vlib_main_t * vm, unformat_input_t * input,
429 vlib_cli_command_t * cmd)
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200430{
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100431 unformat_input_t _line_input, *line_input = &_line_input;
432 vlib_thread_main_t *tm = vlib_get_thread_main ();
433 vlib_frame_queue_main_t *fqm;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400434 clib_error_t *error = NULL;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200435 u32 num_fq;
436 u32 fqix;
437 u32 nelts = 0;
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100438 u32 index = ~(u32) 0;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200439
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100440 if (!unformat_user (input, unformat_line_input, line_input))
441 return 0;
442
443 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
444 {
Dave Barach7afe9e32016-11-22 15:23:41 -0500445 if (unformat (line_input, "nelts %u", &nelts))
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100446 ;
Dave Barach7afe9e32016-11-22 15:23:41 -0500447 else if (unformat (line_input, "index %u", &index))
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100448 ;
449 else
Billy McFalla9a20e72017-02-15 11:39:12 -0500450 {
451 error = clib_error_return (0, "parse error: '%U'",
452 format_unformat_error, line_input);
453 goto done;
454 }
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100455 }
456
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100457 if (index > vec_len (tm->frame_queue_mains) - 1)
Billy McFalla9a20e72017-02-15 11:39:12 -0500458 {
459 error = clib_error_return (0,
460 "expecting valid worker handoff queue index");
461 goto done;
462 }
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100463
464 fqm = vec_elt_at_index (tm->frame_queue_mains, index);
465
466 if ((nelts != 4) && (nelts != 8) && (nelts != 16) && (nelts != 32))
Dave Barach9b8ffd92016-07-08 08:13:45 -0400467 {
Billy McFalla9a20e72017-02-15 11:39:12 -0500468 error = clib_error_return (0, "expecting 4,8,16,32");
469 goto done;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400470 }
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200471
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100472 num_fq = vec_len (fqm->vlib_frame_queues);
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200473 if (num_fq == 0)
474 {
Dave Barach9b8ffd92016-07-08 08:13:45 -0400475 vlib_cli_output (vm, "No frame queues exist\n");
Billy McFalla9a20e72017-02-15 11:39:12 -0500476 goto done;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200477 }
478
Dave Barach9b8ffd92016-07-08 08:13:45 -0400479 for (fqix = 0; fqix < num_fq; fqix++)
480 {
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100481 fqm->vlib_frame_queues[fqix]->nelts = nelts;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400482 }
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200483
Billy McFalla9a20e72017-02-15 11:39:12 -0500484done:
485 unformat_free (line_input);
486
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200487 return error;
488}
489
Dave Barach9b8ffd92016-07-08 08:13:45 -0400490/* *INDENT-OFF* */
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200491VLIB_CLI_COMMAND (cmd_test_frame_queue_nelts,static) = {
492 .path = "test frame-queue nelts",
493 .short_help = "test frame-queue nelts (4,8,16,32)",
494 .function = test_frame_queue_nelts,
495};
Dave Barach9b8ffd92016-07-08 08:13:45 -0400496/* *INDENT-ON* */
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200497
498
499/*
500 * Modify the max number of packets pulled off the frame queues
501 */
502static clib_error_t *
Dave Barach9b8ffd92016-07-08 08:13:45 -0400503test_frame_queue_threshold (vlib_main_t * vm, unformat_input_t * input,
504 vlib_cli_command_t * cmd)
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200505{
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100506 unformat_input_t _line_input, *line_input = &_line_input;
507 vlib_thread_main_t *tm = vlib_get_thread_main ();
508 vlib_frame_queue_main_t *fqm;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400509 clib_error_t *error = NULL;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200510 u32 num_fq;
511 u32 fqix;
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100512 u32 threshold = ~(u32) 0;
513 u32 index = ~(u32) 0;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200514
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100515 if (!unformat_user (input, unformat_line_input, line_input))
516 return 0;
517
518 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Dave Barach9b8ffd92016-07-08 08:13:45 -0400519 {
Dave Barach7afe9e32016-11-22 15:23:41 -0500520 if (unformat (line_input, "threshold %u", &threshold))
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100521 ;
Dave Barach7afe9e32016-11-22 15:23:41 -0500522 else if (unformat (line_input, "index %u", &index))
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100523 ;
524 else
Billy McFalla9a20e72017-02-15 11:39:12 -0500525 {
526 error = clib_error_return (0, "parse error: '%U'",
527 format_unformat_error, line_input);
528 goto done;
529 }
Dave Barach9b8ffd92016-07-08 08:13:45 -0400530 }
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100531
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100532 if (index > vec_len (tm->frame_queue_mains) - 1)
Billy McFalla9a20e72017-02-15 11:39:12 -0500533 {
534 error = clib_error_return (0,
535 "expecting valid worker handoff queue index");
536 goto done;
537 }
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100538
539 fqm = vec_elt_at_index (tm->frame_queue_mains, index);
540
541
542 if (threshold == ~(u32) 0)
Dave Barach9b8ffd92016-07-08 08:13:45 -0400543 {
544 vlib_cli_output (vm, "expecting threshold value\n");
Billy McFalla9a20e72017-02-15 11:39:12 -0500545 goto done;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400546 }
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200547
548 if (threshold == 0)
549 threshold = ~0;
550
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100551 num_fq = vec_len (fqm->vlib_frame_queues);
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200552 if (num_fq == 0)
553 {
Dave Barach9b8ffd92016-07-08 08:13:45 -0400554 vlib_cli_output (vm, "No frame queues exist\n");
Billy McFalla9a20e72017-02-15 11:39:12 -0500555 goto done;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200556 }
557
Dave Barach9b8ffd92016-07-08 08:13:45 -0400558 for (fqix = 0; fqix < num_fq; fqix++)
559 {
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100560 fqm->vlib_frame_queues[fqix]->vector_threshold = threshold;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400561 }
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200562
Billy McFalla9a20e72017-02-15 11:39:12 -0500563done:
564 unformat_free (line_input);
565
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200566 return error;
567}
568
Dave Barach9b8ffd92016-07-08 08:13:45 -0400569/* *INDENT-OFF* */
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200570VLIB_CLI_COMMAND (cmd_test_frame_queue_threshold,static) = {
571 .path = "test frame-queue threshold",
572 .short_help = "test frame-queue threshold N (0=no limit)",
573 .function = test_frame_queue_threshold,
574};
Dave Barach9b8ffd92016-07-08 08:13:45 -0400575/* *INDENT-ON* */
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200576
Dave Barach9b8ffd92016-07-08 08:13:45 -0400577
578/*
579 * fd.io coding-style-patch-verification: ON
580 *
581 * Local Variables:
582 * eval: (c-set-style "gnu")
583 * End:
584 */