1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2017 Intel Corporation
12 #include <rte_ethdev.h>
13 #include <rte_cycles.h>
14 #include <rte_malloc.h>
15 #include <rte_debug.h>
16 #include <rte_prefetch.h>
17 #include <rte_distributor.h>
18 #include <rte_pause.h>
19 #include <rte_power.h>
21 #define RX_RING_SIZE 1024
22 #define TX_RING_SIZE 1024
23 #define NUM_MBUFS ((64*1024)-1)
24 #define MBUF_CACHE_SIZE 128
26 #define SCHED_RX_RING_SZ 8192
27 #define SCHED_TX_RING_SZ 65536
28 #define BURST_SIZE_TX 32
30 #define RTE_LOGTYPE_DISTRAPP RTE_LOGTYPE_USER1
32 #define ANSI_COLOR_RED "\x1b[31m"
33 #define ANSI_COLOR_RESET "\x1b[0m"
35 /* mask of enabled ports */
36 static uint32_t enabled_port_mask;
37 volatile uint8_t quit_signal;
38 volatile uint8_t quit_signal_rx;
39 volatile uint8_t quit_signal_dist;
40 volatile uint8_t quit_signal_work;
41 unsigned int power_lib_initialised;
43 static volatile struct app_stats {
46 uint64_t returned_pkts;
47 uint64_t enqueued_pkts;
48 uint64_t enqdrop_pkts;
49 } rx __rte_cache_aligned;
50 int pad1 __rte_cache_aligned;
56 uint64_t enqdrop_pkts;
57 } dist __rte_cache_aligned;
58 int pad2 __rte_cache_aligned;
61 uint64_t dequeue_pkts;
63 uint64_t enqdrop_pkts;
64 } tx __rte_cache_aligned;
65 int pad3 __rte_cache_aligned;
67 uint64_t worker_pkts[64] __rte_cache_aligned;
69 int pad4 __rte_cache_aligned;
71 uint64_t worker_bursts[64][8] __rte_cache_aligned;
73 int pad5 __rte_cache_aligned;
75 uint64_t port_rx_pkts[64] __rte_cache_aligned;
76 uint64_t port_tx_pkts[64] __rte_cache_aligned;
79 struct app_stats prev_app_stats;
81 static const struct rte_eth_conf port_conf_default = {
83 .mq_mode = ETH_MQ_RX_RSS,
84 .max_rx_pkt_len = RTE_ETHER_MAX_LEN,
87 .mq_mode = ETH_MQ_TX_NONE,
91 .rss_hf = ETH_RSS_IP | ETH_RSS_UDP |
92 ETH_RSS_TCP | ETH_RSS_SCTP,
97 struct output_buffer {
99 struct rte_mbuf *mbufs[BURST_SIZE];
102 static void print_stats(void);
105 * Initialises a given port using global settings and with the rx buffers
106 * coming from the mbuf_pool passed as parameter
109 port_init(uint16_t port, struct rte_mempool *mbuf_pool)
111 struct rte_eth_conf port_conf = port_conf_default;
112 const uint16_t rxRings = 1, txRings = rte_lcore_count() - 1;
115 uint16_t nb_rxd = RX_RING_SIZE;
116 uint16_t nb_txd = TX_RING_SIZE;
117 struct rte_eth_dev_info dev_info;
118 struct rte_eth_txconf txconf;
120 if (!rte_eth_dev_is_valid_port(port))
123 retval = rte_eth_dev_info_get(port, &dev_info);
125 printf("Error during getting device (port %u) info: %s\n",
126 port, strerror(-retval));
130 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
131 port_conf.txmode.offloads |=
132 DEV_TX_OFFLOAD_MBUF_FAST_FREE;
134 port_conf.rx_adv_conf.rss_conf.rss_hf &=
135 dev_info.flow_type_rss_offloads;
136 if (port_conf.rx_adv_conf.rss_conf.rss_hf !=
137 port_conf_default.rx_adv_conf.rss_conf.rss_hf) {
138 printf("Port %u modified RSS hash function based on hardware support,"
139 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
141 port_conf_default.rx_adv_conf.rss_conf.rss_hf,
142 port_conf.rx_adv_conf.rss_conf.rss_hf);
145 retval = rte_eth_dev_configure(port, rxRings, txRings, &port_conf);
149 retval = rte_eth_dev_adjust_nb_rx_tx_desc(port, &nb_rxd, &nb_txd);
153 for (q = 0; q < rxRings; q++) {
154 retval = rte_eth_rx_queue_setup(port, q, nb_rxd,
155 rte_eth_dev_socket_id(port),
161 txconf = dev_info.default_txconf;
162 txconf.offloads = port_conf.txmode.offloads;
163 for (q = 0; q < txRings; q++) {
164 retval = rte_eth_tx_queue_setup(port, q, nb_txd,
165 rte_eth_dev_socket_id(port),
171 retval = rte_eth_dev_start(port);
175 struct rte_eth_link link;
176 rte_eth_link_get_nowait(port, &link);
177 while (!link.link_status) {
178 printf("Waiting for Link up on port %"PRIu16"\n", port);
180 rte_eth_link_get_nowait(port, &link);
183 if (!link.link_status) {
184 printf("Link down on port %"PRIu16"\n", port);
188 struct rte_ether_addr addr;
189 rte_eth_macaddr_get(port, &addr);
190 printf("Port %u MAC: %02"PRIx8" %02"PRIx8" %02"PRIx8
191 " %02"PRIx8" %02"PRIx8" %02"PRIx8"\n",
193 addr.addr_bytes[0], addr.addr_bytes[1],
194 addr.addr_bytes[2], addr.addr_bytes[3],
195 addr.addr_bytes[4], addr.addr_bytes[5]);
197 rte_eth_promiscuous_enable(port);
202 struct lcore_params {
204 struct rte_distributor *d;
205 struct rte_ring *rx_dist_ring;
206 struct rte_ring *dist_tx_ring;
207 struct rte_mempool *mem_pool;
211 lcore_rx(struct lcore_params *p)
213 const uint16_t nb_ports = rte_eth_dev_count_avail();
214 const int socket_id = rte_socket_id();
216 struct rte_mbuf *bufs[BURST_SIZE*2];
218 RTE_ETH_FOREACH_DEV(port) {
219 /* skip ports that are not enabled */
220 if ((enabled_port_mask & (1 << port)) == 0)
223 if (rte_eth_dev_socket_id(port) > 0 &&
224 rte_eth_dev_socket_id(port) != socket_id)
225 printf("WARNING, port %u is on remote NUMA node to "
226 "RX thread.\n\tPerformance will not "
227 "be optimal.\n", port);
230 printf("\nCore %u doing packet RX.\n", rte_lcore_id());
232 while (!quit_signal_rx) {
234 /* skip ports that are not enabled */
235 if ((enabled_port_mask & (1 << port)) == 0) {
236 if (++port == nb_ports)
240 const uint16_t nb_rx = rte_eth_rx_burst(port, 0, bufs,
242 if (unlikely(nb_rx == 0)) {
243 if (++port == nb_ports)
247 app_stats.rx.rx_pkts += nb_rx;
250 * You can run the distributor on the rx core with this code. Returned
251 * packets are then send straight to the tx core.
254 rte_distributor_process(d, bufs, nb_rx);
255 const uint16_t nb_ret = rte_distributor_returned_pktsd,
258 app_stats.rx.returned_pkts += nb_ret;
259 if (unlikely(nb_ret == 0)) {
260 if (++port == nb_ports)
265 struct rte_ring *tx_ring = p->dist_tx_ring;
266 uint16_t sent = rte_ring_enqueue_burst(tx_ring,
267 (void *)bufs, nb_ret, NULL);
269 uint16_t nb_ret = nb_rx;
271 * Swap the following two lines if you want the rx traffic
272 * to go directly to tx, no distribution.
274 struct rte_ring *out_ring = p->rx_dist_ring;
275 /* struct rte_ring *out_ring = p->dist_tx_ring; */
277 uint16_t sent = rte_ring_enqueue_burst(out_ring,
278 (void *)bufs, nb_ret, NULL);
281 app_stats.rx.enqueued_pkts += sent;
282 if (unlikely(sent < nb_ret)) {
283 app_stats.rx.enqdrop_pkts += nb_ret - sent;
284 RTE_LOG_DP(DEBUG, DISTRAPP,
285 "%s:Packet loss due to full ring\n", __func__);
286 while (sent < nb_ret)
287 rte_pktmbuf_free(bufs[sent++]);
289 if (++port == nb_ports)
292 if (power_lib_initialised)
293 rte_power_exit(rte_lcore_id());
294 /* set worker & tx threads quit flag */
295 printf("\nCore %u exiting rx task.\n", rte_lcore_id());
301 flush_one_port(struct output_buffer *outbuf, uint8_t outp)
303 unsigned int nb_tx = rte_eth_tx_burst(outp, 0,
304 outbuf->mbufs, outbuf->count);
305 app_stats.tx.tx_pkts += outbuf->count;
307 if (unlikely(nb_tx < outbuf->count)) {
308 app_stats.tx.enqdrop_pkts += outbuf->count - nb_tx;
310 rte_pktmbuf_free(outbuf->mbufs[nb_tx]);
311 } while (++nb_tx < outbuf->count);
317 flush_all_ports(struct output_buffer *tx_buffers)
321 RTE_ETH_FOREACH_DEV(outp) {
322 /* skip ports that are not enabled */
323 if ((enabled_port_mask & (1 << outp)) == 0)
326 if (tx_buffers[outp].count == 0)
329 flush_one_port(&tx_buffers[outp], outp);
336 lcore_distributor(struct lcore_params *p)
338 struct rte_ring *in_r = p->rx_dist_ring;
339 struct rte_ring *out_r = p->dist_tx_ring;
340 struct rte_mbuf *bufs[BURST_SIZE * 4];
341 struct rte_distributor *d = p->d;
343 printf("\nCore %u acting as distributor core.\n", rte_lcore_id());
344 while (!quit_signal_dist) {
345 const uint16_t nb_rx = rte_ring_dequeue_burst(in_r,
346 (void *)bufs, BURST_SIZE*1, NULL);
348 app_stats.dist.in_pkts += nb_rx;
350 /* Distribute the packets */
351 rte_distributor_process(d, bufs, nb_rx);
353 const uint16_t nb_ret =
354 rte_distributor_returned_pkts(d,
357 if (unlikely(nb_ret == 0))
359 app_stats.dist.ret_pkts += nb_ret;
361 uint16_t sent = rte_ring_enqueue_burst(out_r,
362 (void *)bufs, nb_ret, NULL);
363 app_stats.dist.sent_pkts += sent;
364 if (unlikely(sent < nb_ret)) {
365 app_stats.dist.enqdrop_pkts += nb_ret - sent;
366 RTE_LOG(DEBUG, DISTRAPP,
367 "%s:Packet loss due to full out ring\n",
369 while (sent < nb_ret)
370 rte_pktmbuf_free(bufs[sent++]);
374 printf("\nCore %u exiting distributor task.\n", rte_lcore_id());
375 quit_signal_work = 1;
376 if (power_lib_initialised)
377 rte_power_exit(rte_lcore_id());
378 rte_distributor_flush(d);
379 /* Unblock any returns so workers can exit */
380 rte_distributor_clear_returns(d);
387 lcore_tx(struct rte_ring *in_r)
389 static struct output_buffer tx_buffers[RTE_MAX_ETHPORTS];
390 const int socket_id = rte_socket_id();
393 RTE_ETH_FOREACH_DEV(port) {
394 /* skip ports that are not enabled */
395 if ((enabled_port_mask & (1 << port)) == 0)
398 if (rte_eth_dev_socket_id(port) > 0 &&
399 rte_eth_dev_socket_id(port) != socket_id)
400 printf("WARNING, port %u is on remote NUMA node to "
401 "TX thread.\n\tPerformance will not "
402 "be optimal.\n", port);
405 printf("\nCore %u doing packet TX.\n", rte_lcore_id());
406 while (!quit_signal) {
408 RTE_ETH_FOREACH_DEV(port) {
409 /* skip ports that are not enabled */
410 if ((enabled_port_mask & (1 << port)) == 0)
413 struct rte_mbuf *bufs[BURST_SIZE_TX];
414 const uint16_t nb_rx = rte_ring_dequeue_burst(in_r,
415 (void *)bufs, BURST_SIZE_TX, NULL);
416 app_stats.tx.dequeue_pkts += nb_rx;
418 /* if we get no traffic, flush anything we have */
419 if (unlikely(nb_rx == 0)) {
420 flush_all_ports(tx_buffers);
424 /* for traffic we receive, queue it up for transmit */
426 rte_prefetch_non_temporal((void *)bufs[0]);
427 rte_prefetch_non_temporal((void *)bufs[1]);
428 rte_prefetch_non_temporal((void *)bufs[2]);
429 for (i = 0; i < nb_rx; i++) {
430 struct output_buffer *outbuf;
432 rte_prefetch_non_temporal((void *)bufs[i + 3]);
434 * workers should update in_port to hold the
437 outp = bufs[i]->port;
438 /* skip ports that are not enabled */
439 if ((enabled_port_mask & (1 << outp)) == 0)
442 outbuf = &tx_buffers[outp];
443 outbuf->mbufs[outbuf->count++] = bufs[i];
444 if (outbuf->count == BURST_SIZE_TX)
445 flush_one_port(outbuf, outp);
449 if (power_lib_initialised)
450 rte_power_exit(rte_lcore_id());
451 printf("\nCore %u exiting tx task.\n", rte_lcore_id());
456 int_handler(int sig_num)
458 printf("Exiting on signal %d\n", sig_num);
459 /* set quit flag for rx thread to exit */
460 quit_signal_dist = 1;
466 struct rte_eth_stats eth_stats;
468 const unsigned int num_workers = rte_lcore_count() - 4;
470 RTE_ETH_FOREACH_DEV(i) {
471 rte_eth_stats_get(i, ð_stats);
472 app_stats.port_rx_pkts[i] = eth_stats.ipackets;
473 app_stats.port_tx_pkts[i] = eth_stats.opackets;
476 printf("\n\nRX Thread:\n");
477 RTE_ETH_FOREACH_DEV(i) {
478 printf("Port %u Pktsin : %5.2f\n", i,
479 (app_stats.port_rx_pkts[i] -
480 prev_app_stats.port_rx_pkts[i])/1000000.0);
481 prev_app_stats.port_rx_pkts[i] = app_stats.port_rx_pkts[i];
483 printf(" - Received: %5.2f\n",
484 (app_stats.rx.rx_pkts -
485 prev_app_stats.rx.rx_pkts)/1000000.0);
486 printf(" - Returned: %5.2f\n",
487 (app_stats.rx.returned_pkts -
488 prev_app_stats.rx.returned_pkts)/1000000.0);
489 printf(" - Enqueued: %5.2f\n",
490 (app_stats.rx.enqueued_pkts -
491 prev_app_stats.rx.enqueued_pkts)/1000000.0);
492 printf(" - Dropped: %s%5.2f%s\n", ANSI_COLOR_RED,
493 (app_stats.rx.enqdrop_pkts -
494 prev_app_stats.rx.enqdrop_pkts)/1000000.0,
497 printf("Distributor thread:\n");
498 printf(" - In: %5.2f\n",
499 (app_stats.dist.in_pkts -
500 prev_app_stats.dist.in_pkts)/1000000.0);
501 printf(" - Returned: %5.2f\n",
502 (app_stats.dist.ret_pkts -
503 prev_app_stats.dist.ret_pkts)/1000000.0);
504 printf(" - Sent: %5.2f\n",
505 (app_stats.dist.sent_pkts -
506 prev_app_stats.dist.sent_pkts)/1000000.0);
507 printf(" - Dropped %s%5.2f%s\n", ANSI_COLOR_RED,
508 (app_stats.dist.enqdrop_pkts -
509 prev_app_stats.dist.enqdrop_pkts)/1000000.0,
512 printf("TX thread:\n");
513 printf(" - Dequeued: %5.2f\n",
514 (app_stats.tx.dequeue_pkts -
515 prev_app_stats.tx.dequeue_pkts)/1000000.0);
516 RTE_ETH_FOREACH_DEV(i) {
517 printf("Port %u Pktsout: %5.2f\n",
518 i, (app_stats.port_tx_pkts[i] -
519 prev_app_stats.port_tx_pkts[i])/1000000.0);
520 prev_app_stats.port_tx_pkts[i] = app_stats.port_tx_pkts[i];
522 printf(" - Transmitted: %5.2f\n",
523 (app_stats.tx.tx_pkts -
524 prev_app_stats.tx.tx_pkts)/1000000.0);
525 printf(" - Dropped: %s%5.2f%s\n", ANSI_COLOR_RED,
526 (app_stats.tx.enqdrop_pkts -
527 prev_app_stats.tx.enqdrop_pkts)/1000000.0,
530 prev_app_stats.rx.rx_pkts = app_stats.rx.rx_pkts;
531 prev_app_stats.rx.returned_pkts = app_stats.rx.returned_pkts;
532 prev_app_stats.rx.enqueued_pkts = app_stats.rx.enqueued_pkts;
533 prev_app_stats.rx.enqdrop_pkts = app_stats.rx.enqdrop_pkts;
534 prev_app_stats.dist.in_pkts = app_stats.dist.in_pkts;
535 prev_app_stats.dist.ret_pkts = app_stats.dist.ret_pkts;
536 prev_app_stats.dist.sent_pkts = app_stats.dist.sent_pkts;
537 prev_app_stats.dist.enqdrop_pkts = app_stats.dist.enqdrop_pkts;
538 prev_app_stats.tx.dequeue_pkts = app_stats.tx.dequeue_pkts;
539 prev_app_stats.tx.tx_pkts = app_stats.tx.tx_pkts;
540 prev_app_stats.tx.enqdrop_pkts = app_stats.tx.enqdrop_pkts;
542 for (i = 0; i < num_workers; i++) {
543 printf("Worker %02u Pkts: %5.2f. Bursts(1-8): ", i,
544 (app_stats.worker_pkts[i] -
545 prev_app_stats.worker_pkts[i])/1000000.0);
546 for (j = 0; j < 8; j++) {
547 printf("%"PRIu64" ", app_stats.worker_bursts[i][j]);
548 app_stats.worker_bursts[i][j] = 0;
551 prev_app_stats.worker_pkts[i] = app_stats.worker_pkts[i];
556 lcore_worker(struct lcore_params *p)
558 struct rte_distributor *d = p->d;
559 const unsigned id = p->worker_id;
560 unsigned int num = 0;
564 * for single port, xor_val will be zero so we won't modify the output
565 * port, otherwise we send traffic from 0 to 1, 2 to 3, and vice versa
567 const unsigned xor_val = (rte_eth_dev_count_avail() > 1);
568 struct rte_mbuf *buf[8] __rte_cache_aligned;
570 for (i = 0; i < 8; i++)
573 app_stats.worker_pkts[p->worker_id] = 1;
575 printf("\nCore %u acting as worker core.\n", rte_lcore_id());
576 while (!quit_signal_work) {
577 num = rte_distributor_get_pkt(d, id, buf, buf, num);
578 /* Do a little bit of work for each packet */
579 for (i = 0; i < num; i++) {
580 uint64_t t = rte_rdtsc()+100;
582 while (rte_rdtsc() < t)
584 buf[i]->port ^= xor_val;
587 app_stats.worker_pkts[p->worker_id] += num;
589 app_stats.worker_bursts[p->worker_id][num-1]++;
591 if (power_lib_initialised)
592 rte_power_exit(rte_lcore_id());
598 init_power_library(void)
600 int ret = 0, lcore_id;
601 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
602 /* init power management library */
603 ret = rte_power_init(lcore_id);
606 "Library initialization failed on core %u\n",
609 * Return on first failure, we'll fall back
610 * to non-power operation
620 print_usage(const char *prgname)
622 printf("%s [EAL options] -- -p PORTMASK\n"
623 " -p PORTMASK: hexadecimal bitmask of ports to configure\n",
628 parse_portmask(const char *portmask)
633 /* parse hexadecimal string */
634 pm = strtoul(portmask, &end, 16);
635 if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0'))
644 /* Parse the argument given in the command line of the application */
646 parse_args(int argc, char **argv)
651 char *prgname = argv[0];
652 static struct option lgopts[] = {
658 while ((opt = getopt_long(argc, argvopt, "p:",
659 lgopts, &option_index)) != EOF) {
664 enabled_port_mask = parse_portmask(optarg);
665 if (enabled_port_mask == 0) {
666 printf("invalid portmask\n");
667 print_usage(prgname);
673 print_usage(prgname);
679 print_usage(prgname);
683 argv[optind-1] = prgname;
685 optind = 1; /* reset getopt lib */
689 /* Main function, does initialization and calls the per-lcore functions */
691 main(int argc, char *argv[])
693 struct rte_mempool *mbuf_pool;
694 struct rte_distributor *d;
695 struct rte_ring *dist_tx_ring;
696 struct rte_ring *rx_dist_ring;
697 struct rte_power_core_capabilities lcore_cap;
698 unsigned int lcore_id, worker_id = 0;
699 int distr_core_id = -1, rx_core_id = -1, tx_core_id = -1;
702 uint16_t nb_ports_available;
705 /* catch ctrl-c so we can print on exit */
706 signal(SIGINT, int_handler);
709 int ret = rte_eal_init(argc, argv);
711 rte_exit(EXIT_FAILURE, "Error with EAL initialization\n");
715 /* parse application arguments (after the EAL ones) */
716 ret = parse_args(argc, argv);
718 rte_exit(EXIT_FAILURE, "Invalid distributor parameters\n");
720 if (rte_lcore_count() < 5)
721 rte_exit(EXIT_FAILURE, "Error, This application needs at "
722 "least 5 logical cores to run:\n"
723 "1 lcore for stats (can be core 0)\n"
724 "1 lcore for packet RX\n"
725 "1 lcore for distribution\n"
726 "1 lcore for packet TX\n"
727 "and at least 1 lcore for worker threads\n");
729 if (init_power_library() == 0)
730 power_lib_initialised = 1;
732 nb_ports = rte_eth_dev_count_avail();
734 rte_exit(EXIT_FAILURE, "Error: no ethernet ports detected\n");
735 if (nb_ports != 1 && (nb_ports & 1))
736 rte_exit(EXIT_FAILURE, "Error: number of ports must be even, except "
737 "when using a single port\n");
739 mbuf_pool = rte_pktmbuf_pool_create("MBUF_POOL",
740 NUM_MBUFS * nb_ports, MBUF_CACHE_SIZE, 0,
741 RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());
742 if (mbuf_pool == NULL)
743 rte_exit(EXIT_FAILURE, "Cannot create mbuf pool\n");
744 nb_ports_available = nb_ports;
746 /* initialize all ports */
747 RTE_ETH_FOREACH_DEV(portid) {
748 /* skip ports that are not enabled */
749 if ((enabled_port_mask & (1 << portid)) == 0) {
750 printf("\nSkipping disabled port %d\n", portid);
751 nb_ports_available--;
755 printf("Initializing port %u... done\n", portid);
757 if (port_init(portid, mbuf_pool) != 0)
758 rte_exit(EXIT_FAILURE, "Cannot initialize port %u\n",
762 if (!nb_ports_available) {
763 rte_exit(EXIT_FAILURE,
764 "All available ports are disabled. Please set portmask.\n");
767 d = rte_distributor_create("PKT_DIST", rte_socket_id(),
768 rte_lcore_count() - 4,
771 rte_exit(EXIT_FAILURE, "Cannot create distributor\n");
774 * scheduler ring is read by the transmitter core, and written to
777 dist_tx_ring = rte_ring_create("Output_ring", SCHED_TX_RING_SZ,
778 rte_socket_id(), RING_F_SC_DEQ | RING_F_SP_ENQ);
779 if (dist_tx_ring == NULL)
780 rte_exit(EXIT_FAILURE, "Cannot create output ring\n");
782 rx_dist_ring = rte_ring_create("Input_ring", SCHED_RX_RING_SZ,
783 rte_socket_id(), RING_F_SC_DEQ | RING_F_SP_ENQ);
784 if (rx_dist_ring == NULL)
785 rte_exit(EXIT_FAILURE, "Cannot create output ring\n");
787 if (power_lib_initialised) {
789 * Here we'll pre-assign lcore ids to the rx, tx and
790 * distributor workloads if there's higher frequency
791 * on those cores e.g. if Turbo Boost is enabled.
792 * It's also worth mentioning that it will assign cores in a
793 * specific order, so that if there's less than three
794 * available, the higher frequency cores will go to the
795 * distributor first, then rx, then tx.
797 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
799 rte_power_get_capabilities(lcore_id, &lcore_cap);
801 if (lcore_cap.priority != 1)
804 if (distr_core_id < 0) {
805 distr_core_id = lcore_id;
806 printf("Distributor on priority core %d\n",
810 if (rx_core_id < 0) {
811 rx_core_id = lcore_id;
812 printf("Rx on priority core %d\n",
816 if (tx_core_id < 0) {
817 tx_core_id = lcore_id;
818 printf("Tx on priority core %d\n",
826 * If there's any of the key workloads left without an lcore_id
827 * after the high performing core assignment above, pre-assign
830 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
831 if (lcore_id == (unsigned int)distr_core_id ||
832 lcore_id == (unsigned int)rx_core_id ||
833 lcore_id == (unsigned int)tx_core_id)
835 if (distr_core_id < 0) {
836 distr_core_id = lcore_id;
837 printf("Distributor on core %d\n", lcore_id);
840 if (rx_core_id < 0) {
841 rx_core_id = lcore_id;
842 printf("Rx on core %d\n", lcore_id);
845 if (tx_core_id < 0) {
846 tx_core_id = lcore_id;
847 printf("Tx on core %d\n", lcore_id);
852 printf(" tx id %d, dist id %d, rx id %d\n",
858 * Kick off all the worker threads first, avoiding the pre-assigned
859 * lcore_ids for tx, rx and distributor workloads.
861 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
862 if (lcore_id == (unsigned int)distr_core_id ||
863 lcore_id == (unsigned int)rx_core_id ||
864 lcore_id == (unsigned int)tx_core_id)
866 printf("Starting thread %d as worker, lcore_id %d\n",
867 worker_id, lcore_id);
868 struct lcore_params *p =
869 rte_malloc(NULL, sizeof(*p), 0);
871 rte_panic("malloc failure\n");
872 *p = (struct lcore_params){worker_id++, d, rx_dist_ring,
873 dist_tx_ring, mbuf_pool};
875 rte_eal_remote_launch((lcore_function_t *)lcore_worker,
880 rte_eal_remote_launch((lcore_function_t *)lcore_tx,
881 dist_tx_ring, tx_core_id);
883 /* Start distributor core */
884 struct lcore_params *pd =
885 rte_malloc(NULL, sizeof(*pd), 0);
887 rte_panic("malloc failure\n");
888 *pd = (struct lcore_params){worker_id++, d,
889 rx_dist_ring, dist_tx_ring, mbuf_pool};
890 rte_eal_remote_launch(
891 (lcore_function_t *)lcore_distributor,
895 struct lcore_params *pr =
896 rte_malloc(NULL, sizeof(*pr), 0);
898 rte_panic("malloc failure\n");
899 *pr = (struct lcore_params){worker_id++, d, rx_dist_ring,
900 dist_tx_ring, mbuf_pool};
901 rte_eal_remote_launch((lcore_function_t *)lcore_rx,
904 freq = rte_get_timer_hz();
905 t = rte_rdtsc() + freq;
906 while (!quit_signal_dist) {
907 if (t < rte_rdtsc()) {
909 t = rte_rdtsc() + freq;
914 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
915 if (rte_eal_wait_lcore(lcore_id) < 0)