4 * Copyright(c) 2016-2017 Intel Corporation. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of Intel Corporation nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 #include <rte_mempool.h>
43 #include <rte_launch.h>
44 #include <rte_malloc.h>
45 #include <rte_random.h>
46 #include <rte_cycles.h>
47 #include <rte_ethdev.h>
48 #include <rte_eventdev.h>
50 #define MAX_NUM_STAGES 8
52 #define MAX_NUM_CORE 64
58 unsigned int num_nic_ports;
59 } __rte_cache_aligned;
64 } __rte_cache_aligned;
66 static struct prod_data prod_data;
67 static struct cons_data cons_data;
72 } __rte_cache_aligned;
74 struct fastpath_data {
82 unsigned int rx_core[MAX_NUM_CORE];
83 unsigned int tx_core[MAX_NUM_CORE];
84 unsigned int sched_core[MAX_NUM_CORE];
85 unsigned int worker_core[MAX_NUM_CORE];
86 struct rte_eth_dev_tx_buffer *tx_buf[RTE_MAX_ETHPORTS];
89 static struct fastpath_data *fdata;
92 unsigned int active_cores;
93 unsigned int num_workers;
95 unsigned int num_fids;
98 int enable_queue_priorities;
102 unsigned int num_stages;
103 unsigned int worker_cq_depth;
104 int16_t next_qid[MAX_NUM_STAGES+2];
105 int16_t qid[MAX_NUM_STAGES];
108 static struct config_data cdata = {
109 .num_packets = (1L << 25), /* do ~32M packets */
111 .queue_type = RTE_SCHED_TYPE_ATOMIC,
115 .worker_cq_depth = 16
119 core_in_use(unsigned int lcore_id) {
120 return (fdata->rx_core[lcore_id] || fdata->sched_core[lcore_id] ||
121 fdata->tx_core[lcore_id] || fdata->worker_core[lcore_id]);
125 eth_tx_buffer_retry(struct rte_mbuf **pkts, uint16_t unsent,
128 int port_id = (uintptr_t) userdata;
129 unsigned int _sent = 0;
132 /* Note: hard-coded TX queue */
133 _sent += rte_eth_tx_burst(port_id, 0, &pkts[_sent],
135 } while (_sent != unsent);
141 const uint64_t freq_khz = rte_get_timer_hz() / 1000;
142 struct rte_event packets[BATCH_SIZE];
144 static uint64_t received;
145 static uint64_t last_pkts;
146 static uint64_t last_time;
147 static uint64_t start_time;
149 uint8_t dev_id = cons_data.dev_id;
150 uint8_t port_id = cons_data.port_id;
152 uint16_t n = rte_event_dequeue_burst(dev_id, port_id,
153 packets, RTE_DIM(packets), 0);
156 for (j = 0; j < rte_eth_dev_count(); j++)
157 rte_eth_tx_buffer_flush(j, 0, fdata->tx_buf[j]);
161 last_time = start_time = rte_get_timer_cycles();
164 for (i = 0; i < n; i++) {
165 uint8_t outport = packets[i].mbuf->port;
166 rte_eth_tx_buffer(outport, 0, fdata->tx_buf[outport],
170 /* Print out mpps every 1<22 packets */
171 if (!cdata.quiet && received >= last_pkts + (1<<22)) {
172 const uint64_t now = rte_get_timer_cycles();
173 const uint64_t total_ms = (now - start_time) / freq_khz;
174 const uint64_t delta_ms = (now - last_time) / freq_khz;
175 uint64_t delta_pkts = received - last_pkts;
177 printf("# consumer RX=%"PRIu64", time %"PRIu64 "ms, "
178 "avg %.3f mpps [current %.3f mpps]\n",
181 received / (total_ms * 1000.0),
182 delta_pkts / (delta_ms * 1000.0));
183 last_pkts = received;
187 cdata.num_packets -= n;
188 if (cdata.num_packets <= 0)
197 static uint8_t eth_port;
198 struct rte_mbuf *mbufs[BATCH_SIZE+2];
199 struct rte_event ev[BATCH_SIZE+2];
200 uint32_t i, num_ports = prod_data.num_nic_ports;
201 int32_t qid = prod_data.qid;
202 uint8_t dev_id = prod_data.dev_id;
203 uint8_t port_id = prod_data.port_id;
204 uint32_t prio_idx = 0;
206 const uint16_t nb_rx = rte_eth_rx_burst(eth_port, 0, mbufs, BATCH_SIZE);
207 if (++eth_port == num_ports)
214 for (i = 0; i < nb_rx; i++) {
215 ev[i].flow_id = mbufs[i]->hash.rss;
216 ev[i].op = RTE_EVENT_OP_NEW;
217 ev[i].sched_type = cdata.queue_type;
218 ev[i].queue_id = qid;
219 ev[i].event_type = RTE_EVENT_TYPE_ETHDEV;
220 ev[i].sub_event_type = 0;
221 ev[i].priority = RTE_EVENT_DEV_PRIORITY_NORMAL;
222 ev[i].mbuf = mbufs[i];
223 RTE_SET_USED(prio_idx);
226 const int nb_tx = rte_event_enqueue_burst(dev_id, port_id, ev, nb_rx);
227 if (nb_tx != nb_rx) {
228 for (i = nb_tx; i < nb_rx; i++)
229 rte_pktmbuf_free(mbufs[i]);
236 schedule_devices(uint8_t dev_id, unsigned int lcore_id)
238 if (fdata->rx_core[lcore_id] && (fdata->rx_single ||
239 rte_atomic32_cmpset(&(fdata->rx_lock), 0, 1))) {
241 rte_atomic32_clear((rte_atomic32_t *)&(fdata->rx_lock));
244 if (fdata->sched_core[lcore_id] && (fdata->sched_single ||
245 rte_atomic32_cmpset(&(fdata->sched_lock), 0, 1))) {
246 rte_event_schedule(dev_id);
247 if (cdata.dump_dev_signal) {
248 rte_event_dev_dump(0, stdout);
249 cdata.dump_dev_signal = 0;
251 rte_atomic32_clear((rte_atomic32_t *)&(fdata->sched_lock));
254 if (fdata->tx_core[lcore_id] && (fdata->tx_single ||
255 rte_atomic32_cmpset(&(fdata->tx_lock), 0, 1))) {
257 rte_atomic32_clear((rte_atomic32_t *)&(fdata->tx_lock));
262 work(struct rte_mbuf *m)
264 struct ether_hdr *eth;
265 struct ether_addr addr;
267 /* change mac addresses on packet (to use mbuf data) */
269 * FIXME Swap mac address properly and also handle the
270 * case for both odd and even number of stages that the
271 * addresses end up the same at the end of the pipeline
273 eth = rte_pktmbuf_mtod(m, struct ether_hdr *);
274 ether_addr_copy(ð->d_addr, &addr);
275 ether_addr_copy(&addr, ð->d_addr);
277 /* do a number of cycles of work per packet */
278 volatile uint64_t start_tsc = rte_rdtsc();
279 while (rte_rdtsc() < start_tsc + cdata.worker_cycles)
286 struct rte_event events[BATCH_SIZE];
288 struct worker_data *data = (struct worker_data *)arg;
289 uint8_t dev_id = data->dev_id;
290 uint8_t port_id = data->port_id;
291 size_t sent = 0, received = 0;
292 unsigned int lcore_id = rte_lcore_id();
294 while (!fdata->done) {
297 schedule_devices(dev_id, lcore_id);
299 if (!fdata->worker_core[lcore_id]) {
304 const uint16_t nb_rx = rte_event_dequeue_burst(dev_id, port_id,
305 events, RTE_DIM(events), 0);
313 for (i = 0; i < nb_rx; i++) {
315 /* The first worker stage does classification */
316 if (events[i].queue_id == cdata.qid[0])
317 events[i].flow_id = events[i].mbuf->hash.rss
320 events[i].queue_id = cdata.next_qid[events[i].queue_id];
321 events[i].op = RTE_EVENT_OP_FORWARD;
322 events[i].sched_type = cdata.queue_type;
324 work(events[i].mbuf);
326 uint16_t nb_tx = rte_event_enqueue_burst(dev_id, port_id,
328 while (nb_tx < nb_rx && !fdata->done)
329 nb_tx += rte_event_enqueue_burst(dev_id, port_id,
336 printf(" worker %u thread done. RX=%zu TX=%zu\n",
337 rte_lcore_id(), received, sent);
343 * Parse the coremask given as argument (hexadecimal string) and fill
344 * the global configuration (core role and core count) with the parsed
347 static int xdigit2val(unsigned char c)
361 parse_coremask(const char *coremask)
364 unsigned int count = 0;
368 const int32_t BITS_HEX = 4;
370 if (coremask == NULL)
372 /* Remove all blank characters ahead and after .
373 * Remove 0x/0X if exists.
375 while (isblank(*coremask))
377 if (coremask[0] == '0' && ((coremask[1] == 'x')
378 || (coremask[1] == 'X')))
380 i = strlen(coremask);
381 while ((i > 0) && isblank(coremask[i - 1]))
386 for (i = i - 1; i >= 0 && idx < MAX_NUM_CORE; i--) {
388 if (isxdigit(c) == 0) {
389 /* invalid characters */
393 for (j = 0; j < BITS_HEX && idx < MAX_NUM_CORE; j++, idx++) {
394 if ((1 << j) & val) {
395 mask |= (1UL << idx);
401 if (coremask[i] != '0')
408 static struct option long_options[] = {
409 {"workers", required_argument, 0, 'w'},
410 {"packets", required_argument, 0, 'n'},
411 {"atomic-flows", required_argument, 0, 'f'},
412 {"num_stages", required_argument, 0, 's'},
413 {"rx-mask", required_argument, 0, 'r'},
414 {"tx-mask", required_argument, 0, 't'},
415 {"sched-mask", required_argument, 0, 'e'},
416 {"cq-depth", required_argument, 0, 'c'},
417 {"work-cycles", required_argument, 0, 'W'},
418 {"queue-priority", no_argument, 0, 'P'},
419 {"parallel", no_argument, 0, 'p'},
420 {"ordered", no_argument, 0, 'o'},
421 {"quiet", no_argument, 0, 'q'},
422 {"dump", no_argument, 0, 'D'},
429 const char *usage_str =
430 " Usage: eventdev_demo [options]\n"
432 " -n, --packets=N Send N packets (default ~32M), 0 implies no limit\n"
433 " -f, --atomic-flows=N Use N random flows from 1 to N (default 16)\n"
434 " -s, --num_stages=N Use N atomic stages (default 1)\n"
435 " -r, --rx-mask=core mask Run NIC rx on CPUs in core mask\n"
436 " -w, --worker-mask=core mask Run worker on CPUs in core mask\n"
437 " -t, --tx-mask=core mask Run NIC tx on CPUs in core mask\n"
438 " -e --sched-mask=core mask Run scheduler on CPUs in core mask\n"
439 " -c --cq-depth=N Worker CQ depth (default 16)\n"
440 " -W --work-cycles=N Worker cycles (default 0)\n"
441 " -P --queue-priority Enable scheduler queue prioritization\n"
442 " -o, --ordered Use ordered scheduling\n"
443 " -p, --parallel Use parallel scheduling\n"
444 " -q, --quiet Minimize printed output\n"
445 " -D, --dump Print detailed statistics before exit"
447 fprintf(stderr, "%s", usage_str);
452 parse_app_args(int argc, char **argv)
454 /* Parse cli options*/
458 uint64_t rx_lcore_mask = 0;
459 uint64_t tx_lcore_mask = 0;
460 uint64_t sched_lcore_mask = 0;
461 uint64_t worker_lcore_mask = 0;
465 c = getopt_long(argc, argv, "r:t:e:c:w:n:f:s:poPqDW:",
466 long_options, &option_index);
473 cdata.num_packets = (int64_t)atol(optarg);
474 if (cdata.num_packets == 0)
475 cdata.num_packets = INT64_MAX;
478 cdata.num_fids = (unsigned int)atoi(optarg);
481 cdata.num_stages = (unsigned int)atoi(optarg);
484 cdata.worker_cq_depth = (unsigned int)atoi(optarg);
487 cdata.worker_cycles = (unsigned int)atoi(optarg);
490 cdata.enable_queue_priorities = 1;
493 cdata.queue_type = RTE_SCHED_TYPE_ORDERED;
496 cdata.queue_type = RTE_SCHED_TYPE_PARALLEL;
505 worker_lcore_mask = parse_coremask(optarg);
508 rx_lcore_mask = parse_coremask(optarg);
509 popcnt = __builtin_popcountll(rx_lcore_mask);
510 fdata->rx_single = (popcnt == 1);
513 tx_lcore_mask = parse_coremask(optarg);
514 popcnt = __builtin_popcountll(tx_lcore_mask);
515 fdata->tx_single = (popcnt == 1);
518 sched_lcore_mask = parse_coremask(optarg);
519 popcnt = __builtin_popcountll(sched_lcore_mask);
520 fdata->sched_single = (popcnt == 1);
527 if (worker_lcore_mask == 0 || rx_lcore_mask == 0 ||
528 sched_lcore_mask == 0 || tx_lcore_mask == 0) {
529 printf("Core part of pipeline was not assigned any cores. "
530 "This will stall the pipeline, please check core masks "
531 "(use -h for details on setting core masks):\n"
532 "\trx: %"PRIu64"\n\ttx: %"PRIu64"\n\tsched: %"PRIu64
533 "\n\tworkers: %"PRIu64"\n",
534 rx_lcore_mask, tx_lcore_mask, sched_lcore_mask,
536 rte_exit(-1, "Fix core masks\n");
538 if (cdata.num_stages == 0 || cdata.num_stages > MAX_NUM_STAGES)
541 for (i = 0; i < MAX_NUM_CORE; i++) {
542 fdata->rx_core[i] = !!(rx_lcore_mask & (1UL << i));
543 fdata->tx_core[i] = !!(tx_lcore_mask & (1UL << i));
544 fdata->sched_core[i] = !!(sched_lcore_mask & (1UL << i));
545 fdata->worker_core[i] = !!(worker_lcore_mask & (1UL << i));
547 if (fdata->worker_core[i])
550 cdata.active_cores++;
555 * Initializes a given port using global settings and with the RX buffers
556 * coming from the mbuf_pool passed as a parameter.
559 port_init(uint8_t port, struct rte_mempool *mbuf_pool)
561 static const struct rte_eth_conf port_conf_default = {
563 .mq_mode = ETH_MQ_RX_RSS,
564 .max_rx_pkt_len = ETHER_MAX_LEN
568 .rss_hf = ETH_RSS_IP |
574 const uint16_t rx_rings = 1, tx_rings = 1;
575 const uint16_t rx_ring_size = 512, tx_ring_size = 512;
576 struct rte_eth_conf port_conf = port_conf_default;
580 if (port >= rte_eth_dev_count())
583 /* Configure the Ethernet device. */
584 retval = rte_eth_dev_configure(port, rx_rings, tx_rings, &port_conf);
588 /* Allocate and set up 1 RX queue per Ethernet port. */
589 for (q = 0; q < rx_rings; q++) {
590 retval = rte_eth_rx_queue_setup(port, q, rx_ring_size,
591 rte_eth_dev_socket_id(port), NULL, mbuf_pool);
596 /* Allocate and set up 1 TX queue per Ethernet port. */
597 for (q = 0; q < tx_rings; q++) {
598 retval = rte_eth_tx_queue_setup(port, q, tx_ring_size,
599 rte_eth_dev_socket_id(port), NULL);
604 /* Start the Ethernet port. */
605 retval = rte_eth_dev_start(port);
609 /* Display the port MAC address. */
610 struct ether_addr addr;
611 rte_eth_macaddr_get(port, &addr);
612 printf("Port %u MAC: %02" PRIx8 " %02" PRIx8 " %02" PRIx8
613 " %02" PRIx8 " %02" PRIx8 " %02" PRIx8 "\n",
615 addr.addr_bytes[0], addr.addr_bytes[1],
616 addr.addr_bytes[2], addr.addr_bytes[3],
617 addr.addr_bytes[4], addr.addr_bytes[5]);
619 /* Enable RX in promiscuous mode for the Ethernet device. */
620 rte_eth_promiscuous_enable(port);
626 init_ports(unsigned int num_ports)
631 struct rte_mempool *mp = rte_pktmbuf_pool_create("packet_pool",
632 /* mbufs */ 16384 * num_ports,
633 /* cache_size */ 512,
635 /* data_room_size */ RTE_MBUF_DEFAULT_BUF_SIZE,
638 for (portid = 0; portid < num_ports; portid++)
639 if (port_init(portid, mp) != 0)
640 rte_exit(EXIT_FAILURE, "Cannot init port %"PRIu8 "\n",
643 for (i = 0; i < num_ports; i++) {
644 void *userdata = (void *)(uintptr_t) i;
646 rte_malloc(NULL, RTE_ETH_TX_BUFFER_SIZE(32), 0);
647 if (fdata->tx_buf[i] == NULL)
648 rte_panic("Out of memory\n");
649 rte_eth_tx_buffer_init(fdata->tx_buf[i], 32);
650 rte_eth_tx_buffer_set_err_callback(fdata->tx_buf[i],
664 setup_eventdev(struct prod_data *prod_data,
665 struct cons_data *cons_data,
666 struct worker_data *worker_data)
668 const uint8_t dev_id = 0;
669 /* +1 stages is for a SINGLE_LINK TX stage */
670 const uint8_t nb_queues = cdata.num_stages + 1;
671 /* + 2 is one port for producer and one for consumer */
672 const uint8_t nb_ports = cdata.num_workers + 2;
673 struct rte_event_dev_config config = {
674 .nb_event_queues = nb_queues,
675 .nb_event_ports = nb_ports,
676 .nb_events_limit = 4096,
677 .nb_event_queue_flows = 1024,
678 .nb_event_port_dequeue_depth = 128,
679 .nb_event_port_enqueue_depth = 128,
681 struct rte_event_port_conf wkr_p_conf = {
682 .dequeue_depth = cdata.worker_cq_depth,
684 .new_event_threshold = 4096,
686 struct rte_event_queue_conf wkr_q_conf = {
687 .schedule_type = cdata.queue_type,
688 .priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
689 .nb_atomic_flows = 1024,
690 .nb_atomic_order_sequences = 1024,
692 struct rte_event_port_conf tx_p_conf = {
693 .dequeue_depth = 128,
694 .enqueue_depth = 128,
695 .new_event_threshold = 4096,
697 const struct rte_event_queue_conf tx_q_conf = {
698 .priority = RTE_EVENT_DEV_PRIORITY_HIGHEST,
699 .event_queue_cfg = RTE_EVENT_QUEUE_CFG_SINGLE_LINK,
702 struct port_link worker_queues[MAX_NUM_STAGES];
703 struct port_link tx_queue;
706 int ret, ndev = rte_event_dev_count();
708 printf("%d: No Eventdev Devices Found\n", __LINE__);
712 struct rte_event_dev_info dev_info;
713 ret = rte_event_dev_info_get(dev_id, &dev_info);
714 printf("\tEventdev %d: %s\n", dev_id, dev_info.driver_name);
716 if (dev_info.max_event_port_dequeue_depth <
717 config.nb_event_port_dequeue_depth)
718 config.nb_event_port_dequeue_depth =
719 dev_info.max_event_port_dequeue_depth;
720 if (dev_info.max_event_port_enqueue_depth <
721 config.nb_event_port_enqueue_depth)
722 config.nb_event_port_enqueue_depth =
723 dev_info.max_event_port_enqueue_depth;
725 ret = rte_event_dev_configure(dev_id, &config);
727 printf("%d: Error configuring device\n", __LINE__);
731 /* Q creation - one load balanced per pipeline stage*/
732 printf(" Stages:\n");
733 for (i = 0; i < cdata.num_stages; i++) {
734 if (rte_event_queue_setup(dev_id, i, &wkr_q_conf) < 0) {
735 printf("%d: error creating qid %d\n", __LINE__, i);
739 cdata.next_qid[i] = i+1;
740 worker_queues[i].queue_id = i;
741 if (cdata.enable_queue_priorities) {
742 /* calculate priority stepping for each stage, leaving
743 * headroom of 1 for the SINGLE_LINK TX below
745 const uint32_t prio_delta =
746 (RTE_EVENT_DEV_PRIORITY_LOWEST-1) / nb_queues;
748 /* higher priority for queues closer to tx */
749 wkr_q_conf.priority =
750 RTE_EVENT_DEV_PRIORITY_LOWEST - prio_delta * i;
753 const char *type_str = "Atomic";
754 switch (wkr_q_conf.schedule_type) {
755 case RTE_SCHED_TYPE_ORDERED:
756 type_str = "Ordered";
758 case RTE_SCHED_TYPE_PARALLEL:
759 type_str = "Parallel";
762 printf("\tStage %d, Type %s\tPriority = %d\n", i, type_str,
763 wkr_q_conf.priority);
767 /* final queue for sending to TX core */
768 if (rte_event_queue_setup(dev_id, i, &tx_q_conf) < 0) {
769 printf("%d: error creating qid %d\n", __LINE__, i);
772 tx_queue.queue_id = i;
773 tx_queue.priority = RTE_EVENT_DEV_PRIORITY_HIGHEST;
775 if (wkr_p_conf.dequeue_depth > config.nb_event_port_dequeue_depth)
776 wkr_p_conf.dequeue_depth = config.nb_event_port_dequeue_depth;
777 if (wkr_p_conf.enqueue_depth > config.nb_event_port_enqueue_depth)
778 wkr_p_conf.enqueue_depth = config.nb_event_port_enqueue_depth;
780 /* set up one port per worker, linking to all stage queues */
781 for (i = 0; i < cdata.num_workers; i++) {
782 struct worker_data *w = &worker_data[i];
784 if (rte_event_port_setup(dev_id, i, &wkr_p_conf) < 0) {
785 printf("Error setting up port %d\n", i);
790 for (s = 0; s < cdata.num_stages; s++) {
791 if (rte_event_port_link(dev_id, i,
792 &worker_queues[s].queue_id,
793 &worker_queues[s].priority,
795 printf("%d: error creating link for port %d\n",
803 if (tx_p_conf.dequeue_depth > config.nb_event_port_dequeue_depth)
804 tx_p_conf.dequeue_depth = config.nb_event_port_dequeue_depth;
805 if (tx_p_conf.enqueue_depth > config.nb_event_port_enqueue_depth)
806 tx_p_conf.enqueue_depth = config.nb_event_port_enqueue_depth;
808 /* port for consumer, linked to TX queue */
809 if (rte_event_port_setup(dev_id, i, &tx_p_conf) < 0) {
810 printf("Error setting up port %d\n", i);
813 if (rte_event_port_link(dev_id, i, &tx_queue.queue_id,
814 &tx_queue.priority, 1) != 1) {
815 printf("%d: error creating link for port %d\n",
819 /* port for producer, no links */
820 struct rte_event_port_conf rx_p_conf = {
823 .new_event_threshold = 1200,
826 if (rx_p_conf.dequeue_depth > config.nb_event_port_dequeue_depth)
827 rx_p_conf.dequeue_depth = config.nb_event_port_dequeue_depth;
828 if (rx_p_conf.enqueue_depth > config.nb_event_port_enqueue_depth)
829 rx_p_conf.enqueue_depth = config.nb_event_port_enqueue_depth;
831 if (rte_event_port_setup(dev_id, i + 1, &rx_p_conf) < 0) {
832 printf("Error setting up port %d\n", i);
836 *prod_data = (struct prod_data){.dev_id = dev_id,
838 .qid = cdata.qid[0] };
839 *cons_data = (struct cons_data){.dev_id = dev_id,
842 if (rte_event_dev_start(dev_id) < 0) {
843 printf("Error starting eventdev\n");
851 signal_handler(int signum)
854 rte_exit(1, "Exiting on signal %d\n", signum);
855 if (signum == SIGINT || signum == SIGTERM) {
856 printf("\n\nSignal %d received, preparing to exit...\n",
860 if (signum == SIGTSTP)
861 rte_event_dev_dump(0, stdout);
864 static inline uint64_t
865 port_stat(int dev_id, int32_t p)
868 snprintf(statname, sizeof(statname), "port_%u_rx", p);
869 return rte_event_dev_xstats_by_name_get(dev_id, statname, NULL);
873 main(int argc, char **argv)
875 struct worker_data *worker_data;
876 unsigned int num_ports;
880 signal(SIGINT, signal_handler);
881 signal(SIGTERM, signal_handler);
882 signal(SIGTSTP, signal_handler);
884 err = rte_eal_init(argc, argv);
886 rte_panic("Invalid EAL arguments\n");
891 fdata = rte_malloc(NULL, sizeof(struct fastpath_data), 0);
893 rte_panic("Out of memory\n");
895 /* Parse cli options*/
896 parse_app_args(argc, argv);
898 num_ports = rte_eth_dev_count();
900 rte_panic("No ethernet ports found\n");
902 const unsigned int cores_needed = cdata.active_cores;
905 printf(" Config:\n");
906 printf("\tports: %u\n", num_ports);
907 printf("\tworkers: %u\n", cdata.num_workers);
908 printf("\tpackets: %"PRIi64"\n", cdata.num_packets);
909 printf("\tQueue-prio: %u\n", cdata.enable_queue_priorities);
910 if (cdata.queue_type == RTE_SCHED_TYPE_ORDERED)
911 printf("\tqid0 type: ordered\n");
912 if (cdata.queue_type == RTE_SCHED_TYPE_ATOMIC)
913 printf("\tqid0 type: atomic\n");
914 printf("\tCores available: %u\n", rte_lcore_count());
915 printf("\tCores used: %u\n", cores_needed);
918 if (rte_lcore_count() < cores_needed)
919 rte_panic("Too few cores (%d < %d)\n", rte_lcore_count(),
922 const unsigned int ndevs = rte_event_dev_count();
924 rte_panic("No dev_id devs found. Pasl in a --vdev eventdev.\n");
926 fprintf(stderr, "Warning: More than one eventdev, using idx 0");
928 worker_data = rte_calloc(0, cdata.num_workers,
929 sizeof(worker_data[0]), 0);
930 if (worker_data == NULL)
931 rte_panic("rte_calloc failed\n");
933 int dev_id = setup_eventdev(&prod_data, &cons_data, worker_data);
935 rte_exit(EXIT_FAILURE, "Error setting up eventdev\n");
937 prod_data.num_nic_ports = num_ports;
938 init_ports(num_ports);
941 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
942 if (lcore_id >= MAX_NUM_CORE)
945 if (!fdata->rx_core[lcore_id] &&
946 !fdata->worker_core[lcore_id] &&
947 !fdata->tx_core[lcore_id] &&
948 !fdata->sched_core[lcore_id])
951 if (fdata->rx_core[lcore_id])
953 "[%s()] lcore %d executing NIC Rx, and using eventdev port %u\n",
954 __func__, lcore_id, prod_data.port_id);
956 if (fdata->tx_core[lcore_id])
958 "[%s()] lcore %d executing NIC Tx, and using eventdev port %u\n",
959 __func__, lcore_id, cons_data.port_id);
961 if (fdata->sched_core[lcore_id])
962 printf("[%s()] lcore %d executing scheduler\n",
965 if (fdata->worker_core[lcore_id])
967 "[%s()] lcore %d executing worker, using eventdev port %u\n",
969 worker_data[worker_idx].port_id);
971 err = rte_eal_remote_launch(worker, &worker_data[worker_idx],
974 rte_panic("Failed to launch worker on core %d\n",
978 if (fdata->worker_core[lcore_id])
982 lcore_id = rte_lcore_id();
984 if (core_in_use(lcore_id))
985 worker(&worker_data[worker_idx++]);
987 rte_eal_mp_wait_lcore();
990 rte_event_dev_dump(dev_id, stdout);
992 if (!cdata.quiet && (port_stat(dev_id, worker_data[0].port_id) !=
993 (uint64_t)-ENOTSUP)) {
994 printf("\nPort Workload distribution:\n");
996 uint64_t tot_pkts = 0;
997 uint64_t pkts_per_wkr[RTE_MAX_LCORE] = {0};
998 for (i = 0; i < cdata.num_workers; i++) {
1000 port_stat(dev_id, worker_data[i].port_id);
1001 tot_pkts += pkts_per_wkr[i];
1003 for (i = 0; i < cdata.num_workers; i++) {
1004 float pc = pkts_per_wkr[i] * 100 /
1006 printf("worker %i :\t%.1f %% (%"PRIu64" pkts)\n",
1007 i, pc, pkts_per_wkr[i]);