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.
15 #include <vnet/vnet.h>
16 #include <vppinfra/vec.h>
17 #include <vppinfra/error.h>
18 #include <vppinfra/format.h>
19 #include <vppinfra/xxhash.h>
21 #include <vnet/ethernet/ethernet.h>
22 #include <vnet/devices/dpdk/dpdk.h>
23 #include <vnet/classify/vnet_classify.h>
24 #include <vnet/mpls-gre/packet.h>
26 #include "dpdk_priv.h"
29 pcap_trace_command_fn (vlib_main_t * vm,
30 unformat_input_t * input,
31 vlib_cli_command_t * cmd)
33 dpdk_main_t * dm = &dpdk_main;
37 clib_error_t * error = 0;
39 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
41 if (unformat (input, "on"))
43 if (dm->tx_pcap_enable == 0)
45 if (dm->pcap_filename == 0)
46 dm->pcap_filename = format (0, "/tmp/vpe.pcap%c", 0);
48 memset (&dm->pcap_main, 0, sizeof (dm->pcap_main));
49 dm->pcap_main.file_name = (char *) dm->pcap_filename;
50 dm->pcap_main.n_packets_to_capture = 100;
51 if (dm->pcap_pkts_to_capture)
52 dm->pcap_main.n_packets_to_capture = dm->pcap_pkts_to_capture;
54 dm->pcap_main.packet_type = PCAP_PACKET_TYPE_ethernet;
55 dm->tx_pcap_enable = 1;
57 vlib_cli_output (vm, "pcap tx capture on...");
61 vlib_cli_output (vm, "pcap tx capture already on...");
65 else if (unformat (input, "off"))
67 if (dm->tx_pcap_enable)
69 vlib_cli_output (vm, "captured %d pkts...",
70 dm->pcap_main.n_packets_captured+1);
71 if (dm->pcap_main.n_packets_captured)
73 dm->pcap_main.n_packets_to_capture =
74 dm->pcap_main.n_packets_captured;
75 error = pcap_write (&dm->pcap_main);
77 clib_error_report (error);
79 vlib_cli_output (vm, "saved to %s...", dm->pcap_filename);
84 vlib_cli_output (vm, "pcap tx capture already off...");
87 dm->tx_pcap_enable = 0;
90 else if (unformat (input, "max %d", &max))
92 dm->pcap_pkts_to_capture = max;
96 else if (unformat (input, "intfc %U",
97 unformat_vnet_sw_interface, dm->vnet_main,
98 &dm->pcap_sw_if_index))
100 else if (unformat (input, "intfc any"))
102 dm->pcap_sw_if_index = 0;
105 else if (unformat (input, "file %s", &filename))
107 u8 * chroot_filename;
108 /* Brain-police user path input */
109 if (strstr((char *)filename, "..") || index((char *)filename, '/'))
111 vlib_cli_output (vm, "illegal characters in filename '%s'",
116 chroot_filename = format (0, "/tmp/%s%c", filename, 0);
119 if (dm->pcap_filename)
120 vec_free (dm->pcap_filename);
121 vec_add1 (filename, 0);
122 dm->pcap_filename = chroot_filename;
125 else if (unformat (input, "status"))
127 if (dm->tx_pcap_enable == 0)
129 vlib_cli_output (vm, "pcap tx capture is off...");
133 vlib_cli_output (vm, "pcap tx capture: %d of %d pkts...",
134 dm->pcap_main.n_packets_captured,
135 dm->pcap_main.n_packets_to_capture);
144 return clib_error_return (0, "unknown input `%U'",
145 format_unformat_error, input);
150 VLIB_CLI_COMMAND (pcap_trace_command, static) = {
151 .path = "pcap tx trace",
153 "pcap tx trace on off max <nn> intfc <intfc> file <name> status",
154 .function = pcap_trace_command_fn,
158 static clib_error_t *
159 show_dpdk_buffer (vlib_main_t * vm, unformat_input_t * input,
160 vlib_cli_command_t * cmd)
162 struct rte_mempool * rmp;
165 for(i = 0; i < vec_len(vm->buffer_main->pktmbuf_pools); i++)
167 rmp = vm->buffer_main->pktmbuf_pools[i];
170 unsigned count = rte_mempool_count(rmp);
171 unsigned free_count = rte_mempool_free_count(rmp);
173 vlib_cli_output(vm, "name=\"%s\" available = %7d allocated = %7d total = %7d\n",
174 rmp->name, (u32)count, (u32)free_count,
175 (u32)(count+free_count));
179 vlib_cli_output(vm, "rte_mempool is NULL (!)\n");
185 VLIB_CLI_COMMAND (cmd_show_dpdk_bufferr,static) = {
186 .path = "show dpdk buffer",
187 .short_help = "show dpdk buffer state",
188 .function = show_dpdk_buffer,
192 static clib_error_t *
193 test_dpdk_buffer (vlib_main_t * vm, unformat_input_t * input,
194 vlib_cli_command_t * cmd)
196 static u32 * allocated_buffers;
199 u32 first, actual_alloc;
201 while (unformat_check_input(input) != UNFORMAT_END_OF_INPUT)
203 if (unformat (input, "allocate %d", &n_alloc))
205 else if (unformat (input, "free %d", &n_free))
213 if (vec_len (allocated_buffers) < n_free)
214 return clib_error_return (0, "Can't free %d, only %d allocated",
215 n_free, vec_len (allocated_buffers));
217 first = vec_len(allocated_buffers) - n_free;
218 vlib_buffer_free (vm, allocated_buffers + first, n_free);
219 _vec_len (allocated_buffers) = first;
223 first = vec_len (allocated_buffers);
224 vec_validate (allocated_buffers,
225 vec_len (allocated_buffers) + n_alloc - 1);
227 actual_alloc = vlib_buffer_alloc (vm, allocated_buffers + first,
229 _vec_len (allocated_buffers) = first + actual_alloc;
231 if (actual_alloc < n_alloc)
232 vlib_cli_output (vm, "WARNING: only allocated %d buffers",
236 vlib_cli_output (vm, "Currently %d buffers allocated",
237 vec_len (allocated_buffers));
239 if (allocated_buffers && vec_len(allocated_buffers) == 0)
240 vec_free(allocated_buffers);
245 VLIB_CLI_COMMAND (cmd_test_dpdk_buffer,static) = {
246 .path = "test dpdk buffer",
247 .short_help = "test dpdk buffer [allocate <nn>][free <nn>]",
248 .function = test_dpdk_buffer,
253 show_dpdk_device_stats (vlib_main_t * vm, dpdk_device_t * xd)
257 " last_burst_sz %d\n"
259 " full_frames_cnt %u\n"
260 " consec_full_frames_cnt %u\n"
261 " congestion_cnt %d\n"
262 " last_poll_time %llu\n"
263 " max_poll_delay %llu\n"
265 " total_packet_cnt %u\n",
267 xd->efd_agent.last_burst_sz,
268 xd->efd_agent.max_burst_sz,
269 xd->efd_agent.full_frames_cnt,
270 xd->efd_agent.consec_full_frames_cnt,
271 xd->efd_agent.congestion_cnt,
272 xd->efd_agent.last_poll_time,
273 xd->efd_agent.max_poll_delay,
274 xd->efd_agent.discard_cnt,
275 xd->efd_agent.total_packet_cnt);
277 u32 device_queue_sz = rte_eth_rx_queue_count(xd->device_index,
280 " device_queue_sz %u\n",
286 * Trigger threads to grab frame queue trace data
288 static clib_error_t *
289 trace_frame_queue (vlib_main_t *vm, unformat_input_t *input,
290 vlib_cli_command_t *cmd)
292 clib_error_t * error = NULL;
293 frame_queue_trace_t *fqt;
294 frame_queue_nelt_counter_t *fqh;
299 if (unformat(input, "on")) {
301 } else if (unformat(input, "off")) {
304 return clib_error_return(0, "expecting on or off");
307 num_fq = vec_len(vlib_frame_queues);
310 vlib_cli_output(vm, "No frame queues exist\n");
314 // Allocate storage for trace if necessary
315 vec_validate_aligned(dpdk_main.frame_queue_traces, num_fq-1, CLIB_CACHE_LINE_BYTES);
316 vec_validate_aligned(dpdk_main.frame_queue_histogram, num_fq-1, CLIB_CACHE_LINE_BYTES);
318 for (fqix=0; fqix<num_fq; fqix++) {
319 fqt = &dpdk_main.frame_queue_traces[fqix];
320 fqh = &dpdk_main.frame_queue_histogram[fqix];
322 memset(fqt->n_vectors, 0xff, sizeof(fqt->n_vectors));
324 memset(fqh, 0, sizeof(*fqh));
325 vlib_frame_queues[fqix]->trace = enable;
330 VLIB_CLI_COMMAND (cmd_trace_frame_queue,static) = {
331 .path = "trace frame-queue",
332 .short_help = "trace frame-queue (on|off)",
333 .function = trace_frame_queue,
339 * Adding two counters and compute percent of total
340 * Round up, e.g. 0.000001 => 1%
343 compute_percent (u64 *two_counters, u64 total)
351 return (((two_counters[0] + two_counters[1]) * 100) + (total-1)) / total;
356 * Display frame queue trace data gathered by threads.
358 static clib_error_t *
359 show_frame_queue_internal (vlib_main_t *vm,
362 clib_error_t * error = NULL;
363 frame_queue_trace_t *fqt;
364 frame_queue_nelt_counter_t *fqh;
368 num_fq = vec_len(dpdk_main.frame_queue_traces);
371 vlib_cli_output(vm, "No trace data for frame queues\n");
377 vlib_cli_output(vm, "0-1 2-3 4-5 6-7 8-9 10-11 12-13 14-15 "
378 "16-17 18-19 20-21 22-23 24-25 26-27 28-29 30-31\n");
381 for (fqix=0; fqix<num_fq; fqix++) {
382 fqt = &(dpdk_main.frame_queue_traces[fqix]);
384 vlib_cli_output(vm, "Thread %d %v\n", fqix, vlib_worker_threads[fqix].name);
386 if (fqt->written == 0)
388 vlib_cli_output(vm, " no trace data\n");
394 fqh = &(dpdk_main.frame_queue_histogram[fqix]);
398 for (nelt=0; nelt<MAX_NELTS; nelt++) {
399 total += fqh->count[nelt];
403 * Print in pairs to condense the output.
404 * Allow entries with 0 counts to be clearly identified, by rounding up.
405 * Any non-zero value will be displayed as at least one percent. This
406 * also means the sum of percentages can be > 100, but that is fine. The
407 * histogram is counted from the last time "trace frame on" was issued.
410 "%3d%% %3d%% %3d%% %3d%% %3d%% %3d%% %3d%% %3d%% "
411 "%3d%% %3d%% %3d%% %3d%% %3d%% %3d%% %3d%% %3d%%\n",
412 compute_percent(&fqh->count[ 0], total),
413 compute_percent(&fqh->count[ 2], total),
414 compute_percent(&fqh->count[ 4], total),
415 compute_percent(&fqh->count[ 6], total),
416 compute_percent(&fqh->count[ 8], total),
417 compute_percent(&fqh->count[10], total),
418 compute_percent(&fqh->count[12], total),
419 compute_percent(&fqh->count[14], total),
420 compute_percent(&fqh->count[16], total),
421 compute_percent(&fqh->count[18], total),
422 compute_percent(&fqh->count[20], total),
423 compute_percent(&fqh->count[22], total),
424 compute_percent(&fqh->count[24], total),
425 compute_percent(&fqh->count[26], total),
426 compute_percent(&fqh->count[28], total),
427 compute_percent(&fqh->count[30], total));
431 vlib_cli_output(vm, " vector-threshold %d ring size %d in use %d\n",
432 fqt->threshold, fqt->nelts, fqt->n_in_use);
433 vlib_cli_output(vm, " head %12d head_hint %12d tail %12d\n",
434 fqt->head, fqt->head_hint, fqt->tail);
435 vlib_cli_output(vm, " %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d\n",
436 fqt->n_vectors[0], fqt->n_vectors[1], fqt->n_vectors[2], fqt->n_vectors[3],
437 fqt->n_vectors[4], fqt->n_vectors[5], fqt->n_vectors[6], fqt->n_vectors[7],
438 fqt->n_vectors[8], fqt->n_vectors[9], fqt->n_vectors[10], fqt->n_vectors[11],
439 fqt->n_vectors[12], fqt->n_vectors[13], fqt->n_vectors[14], fqt->n_vectors[15]);
443 vlib_cli_output(vm, " %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d\n",
444 fqt->n_vectors[16], fqt->n_vectors[17], fqt->n_vectors[18], fqt->n_vectors[19],
445 fqt->n_vectors[20], fqt->n_vectors[21], fqt->n_vectors[22], fqt->n_vectors[23],
446 fqt->n_vectors[24], fqt->n_vectors[25], fqt->n_vectors[26], fqt->n_vectors[27],
447 fqt->n_vectors[28], fqt->n_vectors[29], fqt->n_vectors[30], fqt->n_vectors[31]);
455 static clib_error_t *
456 show_frame_queue_trace (vlib_main_t *vm, unformat_input_t *input,
457 vlib_cli_command_t *cmd)
459 return show_frame_queue_internal (vm, 0);
462 static clib_error_t *
463 show_frame_queue_histogram (vlib_main_t *vm, unformat_input_t *input,
464 vlib_cli_command_t *cmd)
466 return show_frame_queue_internal (vm, 1);
469 VLIB_CLI_COMMAND (cmd_show_frame_queue_trace,static) = {
470 .path = "show frame-queue",
471 .short_help = "show frame-queue trace",
472 .function = show_frame_queue_trace,
475 VLIB_CLI_COMMAND (cmd_show_frame_queue_histogram,static) = {
476 .path = "show frame-queue histogram",
477 .short_help = "show frame-queue histogram",
478 .function = show_frame_queue_histogram,
483 * Modify the number of elements on the frame_queues
485 static clib_error_t *
486 test_frame_queue_nelts (vlib_main_t *vm, unformat_input_t *input,
487 vlib_cli_command_t *cmd)
489 clib_error_t * error = NULL;
494 unformat(input, "%d", &nelts);
495 if ((nelts != 4) && (nelts != 8) && (nelts != 16) && (nelts != 32)) {
496 return clib_error_return(0, "expecting 4,8,16,32");
499 num_fq = vec_len(vlib_frame_queues);
502 vlib_cli_output(vm, "No frame queues exist\n");
506 for (fqix=0; fqix<num_fq; fqix++) {
507 vlib_frame_queues[fqix]->nelts = nelts;
513 VLIB_CLI_COMMAND (cmd_test_frame_queue_nelts,static) = {
514 .path = "test frame-queue nelts",
515 .short_help = "test frame-queue nelts (4,8,16,32)",
516 .function = test_frame_queue_nelts,
521 * Modify the max number of packets pulled off the frame queues
523 static clib_error_t *
524 test_frame_queue_threshold (vlib_main_t *vm, unformat_input_t *input,
525 vlib_cli_command_t *cmd)
527 clib_error_t * error = NULL;
532 if (unformat(input, "%d", &threshold)) {
534 vlib_cli_output(vm, "expecting threshold value\n");
541 num_fq = vec_len(vlib_frame_queues);
544 vlib_cli_output(vm, "No frame queues exist\n");
548 for (fqix=0; fqix<num_fq; fqix++) {
549 vlib_frame_queues[fqix]->vector_threshold = threshold;
555 VLIB_CLI_COMMAND (cmd_test_frame_queue_threshold,static) = {
556 .path = "test frame-queue threshold",
557 .short_help = "test frame-queue threshold N (0=no limit)",
558 .function = test_frame_queue_threshold,
562 show_efd_config (vlib_main_t * vm)
564 vlib_thread_main_t * tm = vlib_get_thread_main();
565 dpdk_main_t * dm = &dpdk_main;
568 "dpdk: (0x%04x) enabled:%d monitor:%d drop_all:%d\n"
569 " dpdk_queue_hi_thresh %d\n"
570 " consec_full_frames_hi_thresh %d\n"
572 "worker: (0x%04x) enabled:%d monitor:%d\n"
573 " worker_queue_hi_thresh %d\n",
575 ((dm->efd.enabled & DPDK_EFD_DISCARD_ENABLED) ? 1:0),
576 ((dm->efd.enabled & DPDK_EFD_MONITOR_ENABLED) ? 1:0),
577 ((dm->efd.enabled & DPDK_EFD_DROPALL_ENABLED) ? 1:0),
578 dm->efd.queue_hi_thresh,
579 dm->efd.consec_full_frames_hi_thresh,
581 ((tm->efd.enabled & VLIB_EFD_DISCARD_ENABLED) ? 1:0),
582 ((dm->efd.enabled & VLIB_EFD_MONITOR_ENABLED) ? 1:0),
583 tm->efd.queue_hi_thresh);
586 "ip_prec_bitmap 0x%02x\n"
587 "mpls_exp_bitmap 0x%02x\n"
588 "vlan_cos_bitmap 0x%02x\n",
589 tm->efd.ip_prec_bitmap,
590 tm->efd.mpls_exp_bitmap,
591 tm->efd.vlan_cos_bitmap);
594 static clib_error_t *
595 show_efd (vlib_main_t * vm,
596 unformat_input_t * input,
597 vlib_cli_command_t * cmd)
600 if (unformat(input, "config")) {
602 } else if (unformat(input, "dpdk")) {
603 dpdk_main_t * dm = &dpdk_main;
607 unformat(input, "device %d", &device_id);
608 vec_foreach (xd, dm->devices) {
609 if ((xd->device_index == device_id) || (device_id == ~0)) {
610 show_dpdk_device_stats(vm, xd);
613 } else if (unformat(input, "worker")) {
614 vlib_thread_main_t * tm = vlib_get_thread_main();
615 vlib_frame_queue_t *fq;
616 vlib_thread_registration_t * tr;
619 u32 first_worker_index = 0;
622 p = hash_get_mem (tm->thread_registrations_by_name, "workers");
624 tr = (vlib_thread_registration_t *) p[0];
627 num_workers = tr->count;
628 first_worker_index = tr->first_index;
633 "first_worker_index %d\n"
634 "vlib_frame_queues[%d]:\n",
639 for (thread_id = 0; thread_id < tm->n_vlib_mains; thread_id++) {
640 fq = vlib_frame_queues[thread_id];
643 "%2d: frames_queued %u\n"
644 " frames_queued_hint %u\n"
645 " enqueue_full_events %u\n"
646 " enqueue_efd_discards %u\n",
648 (fq->tail - fq->head),
649 (fq->tail - fq->head_hint),
650 fq->enqueue_full_events,
651 fq->enqueue_efd_discards);
654 } else if (unformat(input, "help")) {
655 vlib_cli_output(vm, "Usage: show efd config | "
656 "dpdk [device <id>] | worker\n");
664 VLIB_CLI_COMMAND (show_efd_command, static) = {
666 .short_help = "Show efd [device <id>] | [config]",
667 .function = show_efd,
670 static clib_error_t *
671 clear_efd (vlib_main_t * vm,
672 unformat_input_t * input,
673 vlib_cli_command_t * cmd)
675 dpdk_main_t * dm = &dpdk_main;
677 vlib_thread_main_t * tm = vlib_get_thread_main();
678 vlib_frame_queue_t *fq;
681 vec_foreach (xd, dm->devices) {
682 xd->efd_agent.last_burst_sz = 0;
683 xd->efd_agent.max_burst_sz = 0;
684 xd->efd_agent.full_frames_cnt = 0;
685 xd->efd_agent.consec_full_frames_cnt = 0;
686 xd->efd_agent.congestion_cnt = 0;
687 xd->efd_agent.last_poll_time = 0;
688 xd->efd_agent.max_poll_delay = 0;
689 xd->efd_agent.discard_cnt = 0;
690 xd->efd_agent.total_packet_cnt = 0;
693 for (thread_id = 0; thread_id < tm->n_vlib_mains; thread_id++) {
694 fq = vlib_frame_queues[thread_id];
696 fq->enqueue_full_events = 0;
697 fq->enqueue_efd_discards = 0;
704 VLIB_CLI_COMMAND (clear_efd_command,static) = {
706 .short_help = "Clear early-fast-discard counters",
707 .function = clear_efd,
710 static clib_error_t *
711 parse_op_and_prec (vlib_main_t *vm, unformat_input_t *input,
712 vlib_cli_command_t *cmd,
713 char *prec_type, u8 *prec_bitmap)
715 clib_error_t * error = NULL;
719 if (unformat(input, "ge")) {
720 op = EFD_OPERATION_GREATER_OR_EQUAL;
721 } else if (unformat(input, "lt")) {
722 op = EFD_OPERATION_LESS_THAN;
723 } else if (unformat(input, "help")) {
725 "enter operation [ge | lt] and precedence <0-7>)");
728 return clib_error_return(0, "unknown input `%U'",
729 format_unformat_error, input);
732 if (unformat (input, "%u", &prec)) {
734 return clib_error_return(0, "precedence %d is out of range <0-7>",
738 return clib_error_return(0, "unknown input `%U'",
739 format_unformat_error, input);
742 set_efd_bitmap(prec_bitmap, prec, op);
745 "EFD will be set for %s precedence %s%u%s.",
747 (op == EFD_OPERATION_LESS_THAN) ? "less than " : "",
749 (op == EFD_OPERATION_GREATER_OR_EQUAL) ? " and greater" : "");
755 static clib_error_t *
756 set_efd (vlib_main_t *vm, unformat_input_t *input,
757 vlib_cli_command_t *cmd)
759 dpdk_main_t * dm = &dpdk_main;
760 vlib_thread_main_t * tm = vlib_get_thread_main();
761 clib_error_t * error = NULL;
762 vlib_node_runtime_t * rt = vlib_node_get_runtime (vm, dpdk_input_node.index);
764 if (unformat(input, "enable")) {
765 if (unformat(input, "dpdk")) {
766 dm->efd.enabled |= DPDK_EFD_DISCARD_ENABLED;
767 } else if (unformat(input, "worker")) {
768 tm->efd.enabled |= VLIB_EFD_DISCARD_ENABLED;
769 } else if (unformat(input, "monitor")) {
770 dm->efd.enabled |= DPDK_EFD_MONITOR_ENABLED;
771 tm->efd.enabled |= VLIB_EFD_MONITOR_ENABLED;
772 } else if (unformat(input, "drop_all")) {
773 dm->efd.enabled |= DPDK_EFD_DROPALL_ENABLED;
774 } else if (unformat(input, "default")) {
775 dm->efd.enabled = (DPDK_EFD_DISCARD_ENABLED |
776 DPDK_EFD_MONITOR_ENABLED);
777 tm->efd.enabled = (VLIB_EFD_DISCARD_ENABLED |
778 VLIB_EFD_MONITOR_ENABLED);
780 return clib_error_return(0, "Usage: set efd enable [dpdk | "
781 "worker | monitor | drop_all | default]");
783 } else if (unformat(input, "disable")) {
784 if (unformat(input, "dpdk")) {
785 dm->efd.enabled &= ~DPDK_EFD_DISCARD_ENABLED;
786 } else if (unformat(input, "worker")) {
787 tm->efd.enabled &= ~VLIB_EFD_DISCARD_ENABLED;
788 } else if (unformat(input, "monitor")) {
789 dm->efd.enabled &= ~DPDK_EFD_MONITOR_ENABLED;
790 tm->efd.enabled &= ~VLIB_EFD_MONITOR_ENABLED;
791 } else if (unformat(input, "drop_all")) {
792 dm->efd.enabled &= ~DPDK_EFD_DROPALL_ENABLED;
793 } else if (unformat(input, "all")) {
797 return clib_error_return(0, "Usage: set efd disable [dpdk | "
798 "worker | monitor | drop_all | all]");
800 } else if (unformat(input, "worker_queue_hi_thresh")) {
802 if (unformat (input, "%u", &mark)) {
803 tm->efd.queue_hi_thresh = mark;
805 return clib_error_return(0, "unknown input `%U'",
806 format_unformat_error, input);
808 } else if (unformat(input, "dpdk_device_hi_thresh")) {
810 if (unformat (input, "%u", &thresh)) {
811 dm->efd.queue_hi_thresh = thresh;
813 return clib_error_return(0, "unknown input `%U'",
814 format_unformat_error, input);
816 } else if (unformat(input, "consec_full_frames_hi_thresh")) {
818 if (unformat (input, "%u", &thresh)) {
819 dm->efd.consec_full_frames_hi_thresh = thresh;
821 return clib_error_return(0, "unknown input `%U'",
822 format_unformat_error, input);
824 } else if (unformat(input, "ip-prec")) {
825 return (parse_op_and_prec(vm, input, cmd,
826 "ip", &tm->efd.ip_prec_bitmap));
827 } else if (unformat(input, "mpls-exp")) {
828 return (parse_op_and_prec(vm, input, cmd,
829 "mpls", &tm->efd.mpls_exp_bitmap));
830 } else if (unformat(input, "vlan-cos")) {
831 return (parse_op_and_prec(vm, input, cmd,
832 "vlan", &tm->efd.vlan_cos_bitmap));
833 } else if (unformat(input, "help")) {
836 " set efd enable <dpdk | worker | monitor | drop_all | default> |\n"
837 " set efd disable <dpdk | worker | monitor | drop_all | all> |\n"
838 " set efd <ip-prec | mpls-exp | vlan-cos> <ge | lt> <0-7>\n"
839 " set efd worker_queue_hi_thresh <0-32> |\n"
840 " set efd dpdk_device_hi_thresh <0-%d> |\n"
841 " set efd consec_full_frames_hi_thresh <count> |\n",
842 DPDK_NB_RX_DESC_10GE);
844 return clib_error_return(0, "unknown input `%U'",
845 format_unformat_error, input);
849 rt->function = dpdk_input_efd_multiarch_select();
850 else if (dm->use_rss)
851 rt->function = dpdk_input_rss_multiarch_select();
853 rt->function = dpdk_input_multiarch_select();
858 VLIB_CLI_COMMAND (cmd_set_efd,static) = {
860 .short_help = "set early-fast-discard commands",
864 static clib_error_t *
865 set_dpdk_if_desc (vlib_main_t *vm, unformat_input_t *input,
866 vlib_cli_command_t *cmd)
868 unformat_input_t _line_input, * line_input = &_line_input;
869 dpdk_main_t * dm = &dpdk_main;
870 vnet_hw_interface_t * hw;
872 u32 hw_if_index = (u32) ~0;
873 u32 nb_rx_desc = (u32) ~0;
874 u32 nb_tx_desc = (u32) ~0;
877 if (! unformat_user (input, unformat_line_input, line_input))
880 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
881 if (unformat (line_input, "%U", unformat_vnet_hw_interface, dm->vnet_main,
884 else if (unformat (line_input, "tx %d", &nb_tx_desc))
886 else if (unformat (line_input, "rx %d", &nb_rx_desc))
889 return clib_error_return (0, "parse error: '%U'",
890 format_unformat_error, line_input);
893 unformat_free (line_input);
895 if (hw_if_index == (u32) ~0)
896 return clib_error_return (0, "please specify valid interface name");
898 hw = vnet_get_hw_interface (dm->vnet_main, hw_if_index);
899 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
901 if (xd->dev_type != VNET_DPDK_DEV_ETH)
902 return clib_error_return (0, "number of descriptors can be set only for "
905 if ((nb_rx_desc == (u32) ~0 || nb_rx_desc == xd->nb_rx_desc) &&
906 (nb_tx_desc == (u32) ~0 || nb_tx_desc == xd->nb_tx_desc))
907 return clib_error_return (0, "nothing changed");
909 if (nb_rx_desc != (u32) ~0)
910 xd->nb_rx_desc = nb_rx_desc;
912 if (nb_tx_desc != (u32) ~0)
913 xd->nb_rx_desc = nb_rx_desc;
915 rv = dpdk_port_setup(dm, xd);
917 return rv < 0 ? rv : 0;
920 VLIB_CLI_COMMAND (cmd_set_dpdk_if_desc,static) = {
921 .path = "set dpdk interface descriptors",
922 .short_help = "set dpdk interface descriptors <if-name> [rx <n>] [tx <n>]",
923 .function = set_dpdk_if_desc,
926 static clib_error_t *
927 show_dpdk_if_placement (vlib_main_t *vm, unformat_input_t *input,
928 vlib_cli_command_t *cmd)
930 vlib_thread_main_t * tm = vlib_get_thread_main();
931 dpdk_main_t * dm = &dpdk_main;
932 dpdk_device_and_queue_t * dq;
935 if (tm->n_vlib_mains == 1)
936 vlib_cli_output(vm, "All interfaces are handled by main thread");
938 for(cpu = 0; cpu < vec_len(dm->devices_by_cpu); cpu++)
940 if (vec_len(dm->devices_by_cpu[cpu]))
941 vlib_cli_output(vm, "Thread %u (%s at lcore %u):", cpu,
942 vlib_worker_threads[cpu].name,
943 vlib_worker_threads[cpu].dpdk_lcore_id);
945 vec_foreach(dq, dm->devices_by_cpu[cpu])
947 u32 hw_if_index = dm->devices[dq->device].vlib_hw_if_index;
948 vnet_hw_interface_t * hi = vnet_get_hw_interface(dm->vnet_main, hw_if_index);
949 vlib_cli_output(vm, " %v queue %u", hi->name, dq->queue_id);
955 VLIB_CLI_COMMAND (cmd_show_dpdk_if_placement,static) = {
956 .path = "show dpdk interface placement",
957 .short_help = "show dpdk interface placement",
958 .function = show_dpdk_if_placement,
962 dpdk_device_queue_sort(void * a1, void * a2)
964 dpdk_device_and_queue_t * dq1 = a1;
965 dpdk_device_and_queue_t * dq2 = a2;
967 if (dq1->device > dq2->device)
969 else if (dq1->device < dq2->device)
971 else if (dq1->queue_id > dq2->queue_id)
973 else if (dq1->queue_id < dq2->queue_id)
979 static clib_error_t *
980 set_dpdk_if_placement (vlib_main_t *vm, unformat_input_t *input,
981 vlib_cli_command_t *cmd)
983 unformat_input_t _line_input, * line_input = &_line_input;
984 dpdk_main_t * dm = &dpdk_main;
985 dpdk_device_and_queue_t * dq;
986 vnet_hw_interface_t * hw;
988 u32 hw_if_index = (u32) ~0;
993 if (! unformat_user (input, unformat_line_input, line_input))
996 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
997 if (unformat (line_input, "%U", unformat_vnet_hw_interface, dm->vnet_main,
1000 else if (unformat (line_input, "queue %d", &queue))
1002 else if (unformat (line_input, "thread %d", &cpu))
1005 return clib_error_return (0, "parse error: '%U'",
1006 format_unformat_error, line_input);
1009 unformat_free (line_input);
1011 if (hw_if_index == (u32) ~0)
1012 return clib_error_return (0, "please specify valid interface name");
1014 if (cpu < dm->input_cpu_first_index ||
1015 cpu >= (dm->input_cpu_first_index + dm->input_cpu_count))
1016 return clib_error_return (0, "please specify valid thread id");
1018 hw = vnet_get_hw_interface (dm->vnet_main, hw_if_index);
1019 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1021 for(i = 0; i < vec_len(dm->devices_by_cpu); i++)
1023 vec_foreach(dq, dm->devices_by_cpu[i])
1025 if (hw_if_index == dm->devices[dq->device].vlib_hw_if_index &&
1026 queue == dq->queue_id)
1028 if (cpu == i) /* nothing to do */
1031 vec_del1(dm->devices_by_cpu[i], dq - dm->devices_by_cpu[i]);
1032 vec_add2(dm->devices_by_cpu[cpu], dq, 1);
1033 dq->queue_id = queue;
1034 dq->device = xd->device_index;
1035 xd->cpu_socket_id_by_queue[queue] =
1036 rte_lcore_to_socket_id(vlib_worker_threads[cpu].dpdk_lcore_id);
1038 vec_sort_with_function(dm->devices_by_cpu[i],
1039 dpdk_device_queue_sort);
1041 vec_sort_with_function(dm->devices_by_cpu[cpu],
1042 dpdk_device_queue_sort);
1044 if (vec_len(dm->devices_by_cpu[i]) == 0)
1045 vlib_node_set_state (vlib_mains[i], dpdk_input_node.index,
1046 VLIB_NODE_STATE_DISABLED);
1048 if (vec_len(dm->devices_by_cpu[cpu]) == 1)
1049 vlib_node_set_state (vlib_mains[cpu], dpdk_input_node.index,
1050 VLIB_NODE_STATE_POLLING);
1057 return clib_error_return (0, "not found");
1060 VLIB_CLI_COMMAND (cmd_set_dpdk_if_placement,static) = {
1061 .path = "set dpdk interface placement",
1062 .short_help = "set dpdk interface placement <if-name> [queue <n>] thread <n>",
1063 .function = set_dpdk_if_placement,
1067 dpdk_cli_init (vlib_main_t * vm)
1072 VLIB_INIT_FUNCTION (dpdk_cli_init);