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_EVENT_QUEUE_CFG_ATOMIC_ONLY,
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]);
126 eth_tx_buffer_retry(struct rte_mbuf **pkts, uint16_t unsent,
129 int port_id = (uintptr_t) userdata;
130 unsigned int _sent = 0;
133 /* Note: hard-coded TX queue */
134 _sent += rte_eth_tx_burst(port_id, 0, &pkts[_sent],
136 } while (_sent != unsent);
142 const uint64_t freq_khz = rte_get_timer_hz() / 1000;
143 struct rte_event packets[BATCH_SIZE];
145 static uint64_t received;
146 static uint64_t last_pkts;
147 static uint64_t last_time;
148 static uint64_t start_time;
150 uint8_t dev_id = cons_data.dev_id;
151 uint8_t port_id = cons_data.port_id;
153 uint16_t n = rte_event_dequeue_burst(dev_id, port_id,
154 packets, RTE_DIM(packets), 0);
157 for (j = 0; j < rte_eth_dev_count(); j++)
158 rte_eth_tx_buffer_flush(j, 0, fdata->tx_buf[j]);
162 last_time = start_time = rte_get_timer_cycles();
165 for (i = 0; i < n; i++) {
166 uint8_t outport = packets[i].mbuf->port;
167 rte_eth_tx_buffer(outport, 0, fdata->tx_buf[outport],
171 /* Print out mpps every 1<22 packets */
172 if (!cdata.quiet && received >= last_pkts + (1<<22)) {
173 const uint64_t now = rte_get_timer_cycles();
174 const uint64_t total_ms = (now - start_time) / freq_khz;
175 const uint64_t delta_ms = (now - last_time) / freq_khz;
176 uint64_t delta_pkts = received - last_pkts;
178 printf("# consumer RX=%"PRIu64", time %"PRIu64 "ms, "
179 "avg %.3f mpps [current %.3f mpps]\n",
182 received / (total_ms * 1000.0),
183 delta_pkts / (delta_ms * 1000.0));
184 last_pkts = received;
188 cdata.num_packets -= n;
189 if (cdata.num_packets <= 0)
198 static uint8_t eth_port;
199 struct rte_mbuf *mbufs[BATCH_SIZE+2];
200 struct rte_event ev[BATCH_SIZE+2];
201 uint32_t i, num_ports = prod_data.num_nic_ports;
202 int32_t qid = prod_data.qid;
203 uint8_t dev_id = prod_data.dev_id;
204 uint8_t port_id = prod_data.port_id;
205 uint32_t prio_idx = 0;
207 const uint16_t nb_rx = rte_eth_rx_burst(eth_port, 0, mbufs, BATCH_SIZE);
208 if (++eth_port == num_ports)
215 for (i = 0; i < nb_rx; i++) {
216 ev[i].flow_id = mbufs[i]->hash.rss;
217 ev[i].op = RTE_EVENT_OP_NEW;
218 ev[i].sched_type = cdata.queue_type;
219 ev[i].queue_id = qid;
220 ev[i].event_type = RTE_EVENT_TYPE_ETHDEV;
221 ev[i].sub_event_type = 0;
222 ev[i].priority = RTE_EVENT_DEV_PRIORITY_NORMAL;
223 ev[i].mbuf = mbufs[i];
224 RTE_SET_USED(prio_idx);
227 const int nb_tx = rte_event_enqueue_burst(dev_id, port_id, ev, nb_rx);
228 if (nb_tx != nb_rx) {
229 for (i = nb_tx; i < nb_rx; i++)
230 rte_pktmbuf_free(mbufs[i]);
237 schedule_devices(uint8_t dev_id, unsigned int lcore_id)
239 if (fdata->rx_core[lcore_id] && (fdata->rx_single ||
240 rte_atomic32_cmpset(&(fdata->rx_lock), 0, 1))) {
242 rte_atomic32_clear((rte_atomic32_t *)&(fdata->rx_lock));
245 if (fdata->sched_core[lcore_id] && (fdata->sched_single ||
246 rte_atomic32_cmpset(&(fdata->sched_lock), 0, 1))) {
247 rte_event_schedule(dev_id);
248 if (cdata.dump_dev_signal) {
249 rte_event_dev_dump(0, stdout);
250 cdata.dump_dev_signal = 0;
252 rte_atomic32_clear((rte_atomic32_t *)&(fdata->sched_lock));
255 if (fdata->tx_core[lcore_id] && (fdata->tx_single ||
256 rte_atomic32_cmpset(&(fdata->tx_lock), 0, 1))) {
258 rte_atomic32_clear((rte_atomic32_t *)&(fdata->tx_lock));
263 work(struct rte_mbuf *m)
265 struct ether_hdr *eth;
266 struct ether_addr addr;
268 /* change mac addresses on packet (to use mbuf data) */
270 * FIXME Swap mac address properly and also handle the
271 * case for both odd and even number of stages that the
272 * addresses end up the same at the end of the pipeline
274 eth = rte_pktmbuf_mtod(m, struct ether_hdr *);
275 ether_addr_copy(ð->d_addr, &addr);
276 ether_addr_copy(&addr, ð->d_addr);
278 /* do a number of cycles of work per packet */
279 volatile uint64_t start_tsc = rte_rdtsc();
280 while (rte_rdtsc() < start_tsc + cdata.worker_cycles)
287 struct rte_event events[BATCH_SIZE];
289 struct worker_data *data = (struct worker_data *)arg;
290 uint8_t dev_id = data->dev_id;
291 uint8_t port_id = data->port_id;
292 size_t sent = 0, received = 0;
293 unsigned int lcore_id = rte_lcore_id();
295 while (!fdata->done) {
298 schedule_devices(dev_id, lcore_id);
300 if (!fdata->worker_core[lcore_id]) {
305 const uint16_t nb_rx = rte_event_dequeue_burst(dev_id, port_id,
306 events, RTE_DIM(events), 0);
314 for (i = 0; i < nb_rx; i++) {
316 /* The first worker stage does classification */
317 if (events[i].queue_id == cdata.qid[0])
318 events[i].flow_id = events[i].mbuf->hash.rss
321 events[i].queue_id = cdata.next_qid[events[i].queue_id];
322 events[i].op = RTE_EVENT_OP_FORWARD;
323 events[i].sched_type = cdata.queue_type;
325 work(events[i].mbuf);
327 uint16_t nb_tx = rte_event_enqueue_burst(dev_id, port_id,
329 while (nb_tx < nb_rx && !fdata->done)
330 nb_tx += rte_event_enqueue_burst(dev_id, port_id,
337 printf(" worker %u thread done. RX=%zu TX=%zu\n",
338 rte_lcore_id(), received, sent);
344 * Parse the coremask given as argument (hexadecimal string) and fill
345 * the global configuration (core role and core count) with the parsed
348 static int xdigit2val(unsigned char c)
362 parse_coremask(const char *coremask)
365 unsigned int count = 0;
369 const int32_t BITS_HEX = 4;
371 if (coremask == NULL)
373 /* Remove all blank characters ahead and after .
374 * Remove 0x/0X if exists.
376 while (isblank(*coremask))
378 if (coremask[0] == '0' && ((coremask[1] == 'x')
379 || (coremask[1] == 'X')))
381 i = strlen(coremask);
382 while ((i > 0) && isblank(coremask[i - 1]))
387 for (i = i - 1; i >= 0 && idx < MAX_NUM_CORE; i--) {
389 if (isxdigit(c) == 0) {
390 /* invalid characters */
394 for (j = 0; j < BITS_HEX && idx < MAX_NUM_CORE; j++, idx++) {
395 if ((1 << j) & val) {
396 mask |= (1UL << idx);
402 if (coremask[i] != '0')
409 static struct option long_options[] = {
410 {"workers", required_argument, 0, 'w'},
411 {"packets", required_argument, 0, 'n'},
412 {"atomic-flows", required_argument, 0, 'f'},
413 {"num_stages", required_argument, 0, 's'},
414 {"rx-mask", required_argument, 0, 'r'},
415 {"tx-mask", required_argument, 0, 't'},
416 {"sched-mask", required_argument, 0, 'e'},
417 {"cq-depth", required_argument, 0, 'c'},
418 {"work-cycles", required_argument, 0, 'W'},
419 {"queue-priority", no_argument, 0, 'P'},
420 {"parallel", no_argument, 0, 'p'},
421 {"ordered", no_argument, 0, 'o'},
422 {"quiet", no_argument, 0, 'q'},
423 {"dump", no_argument, 0, 'D'},
430 const char *usage_str =
431 " Usage: eventdev_demo [options]\n"
433 " -n, --packets=N Send N packets (default ~32M), 0 implies no limit\n"
434 " -f, --atomic-flows=N Use N random flows from 1 to N (default 16)\n"
435 " -s, --num_stages=N Use N atomic stages (default 1)\n"
436 " -r, --rx-mask=core mask Run NIC rx on CPUs in core mask\n"
437 " -w, --worker-mask=core mask Run worker on CPUs in core mask\n"
438 " -t, --tx-mask=core mask Run NIC tx on CPUs in core mask\n"
439 " -e --sched-mask=core mask Run scheduler on CPUs in core mask\n"
440 " -c --cq-depth=N Worker CQ depth (default 16)\n"
441 " -W --work-cycles=N Worker cycles (default 0)\n"
442 " -P --queue-priority Enable scheduler queue prioritization\n"
443 " -o, --ordered Use ordered scheduling\n"
444 " -p, --parallel Use parallel scheduling\n"
445 " -q, --quiet Minimize printed output\n"
446 " -D, --dump Print detailed statistics before exit"
448 fprintf(stderr, "%s", usage_str);
453 parse_app_args(int argc, char **argv)
455 /* Parse cli options*/
459 uint64_t rx_lcore_mask = 0;
460 uint64_t tx_lcore_mask = 0;
461 uint64_t sched_lcore_mask = 0;
462 uint64_t worker_lcore_mask = 0;
466 c = getopt_long(argc, argv, "r:t:e:c:w:n:f:s:poPqDW:",
467 long_options, &option_index);
474 cdata.num_packets = (unsigned long)atol(optarg);
477 cdata.num_fids = (unsigned int)atoi(optarg);
480 cdata.num_stages = (unsigned int)atoi(optarg);
483 cdata.worker_cq_depth = (unsigned int)atoi(optarg);
486 cdata.worker_cycles = (unsigned int)atoi(optarg);
489 cdata.enable_queue_priorities = 1;
492 cdata.queue_type = RTE_EVENT_QUEUE_CFG_ORDERED_ONLY;
495 cdata.queue_type = RTE_EVENT_QUEUE_CFG_PARALLEL_ONLY;
504 worker_lcore_mask = parse_coremask(optarg);
507 rx_lcore_mask = parse_coremask(optarg);
508 popcnt = __builtin_popcountll(rx_lcore_mask);
509 fdata->rx_single = (popcnt == 1);
512 tx_lcore_mask = parse_coremask(optarg);
513 popcnt = __builtin_popcountll(tx_lcore_mask);
514 fdata->tx_single = (popcnt == 1);
517 sched_lcore_mask = parse_coremask(optarg);
518 popcnt = __builtin_popcountll(sched_lcore_mask);
519 fdata->sched_single = (popcnt == 1);
526 if (worker_lcore_mask == 0 || rx_lcore_mask == 0 ||
527 sched_lcore_mask == 0 || tx_lcore_mask == 0) {
528 printf("Core part of pipeline was not assigned any cores. "
529 "This will stall the pipeline, please check core masks "
530 "(use -h for details on setting core masks):\n"
531 "\trx: %"PRIu64"\n\ttx: %"PRIu64"\n\tsched: %"PRIu64
532 "\n\tworkers: %"PRIu64"\n",
533 rx_lcore_mask, tx_lcore_mask, sched_lcore_mask,
535 rte_exit(-1, "Fix core masks\n");
537 if (cdata.num_stages == 0 || cdata.num_stages > MAX_NUM_STAGES)
540 for (i = 0; i < MAX_NUM_CORE; i++) {
541 fdata->rx_core[i] = !!(rx_lcore_mask & (1UL << i));
542 fdata->tx_core[i] = !!(tx_lcore_mask & (1UL << i));
543 fdata->sched_core[i] = !!(sched_lcore_mask & (1UL << i));
544 fdata->worker_core[i] = !!(worker_lcore_mask & (1UL << i));
546 if (fdata->worker_core[i])
549 cdata.active_cores++;
554 * Initializes a given port using global settings and with the RX buffers
555 * coming from the mbuf_pool passed as a parameter.
558 port_init(uint8_t port, struct rte_mempool *mbuf_pool)
560 static const struct rte_eth_conf port_conf_default = {
562 .mq_mode = ETH_MQ_RX_RSS,
563 .max_rx_pkt_len = ETHER_MAX_LEN
567 .rss_hf = ETH_RSS_IP |
573 const uint16_t rx_rings = 1, tx_rings = 1;
574 const uint16_t rx_ring_size = 512, tx_ring_size = 512;
575 struct rte_eth_conf port_conf = port_conf_default;
579 if (port >= rte_eth_dev_count())
582 /* Configure the Ethernet device. */
583 retval = rte_eth_dev_configure(port, rx_rings, tx_rings, &port_conf);
587 /* Allocate and set up 1 RX queue per Ethernet port. */
588 for (q = 0; q < rx_rings; q++) {
589 retval = rte_eth_rx_queue_setup(port, q, rx_ring_size,
590 rte_eth_dev_socket_id(port), NULL, mbuf_pool);
595 /* Allocate and set up 1 TX queue per Ethernet port. */
596 for (q = 0; q < tx_rings; q++) {
597 retval = rte_eth_tx_queue_setup(port, q, tx_ring_size,
598 rte_eth_dev_socket_id(port), NULL);
603 /* Start the Ethernet port. */
604 retval = rte_eth_dev_start(port);
608 /* Display the port MAC address. */
609 struct ether_addr addr;
610 rte_eth_macaddr_get(port, &addr);
611 printf("Port %u MAC: %02" PRIx8 " %02" PRIx8 " %02" PRIx8
612 " %02" PRIx8 " %02" PRIx8 " %02" PRIx8 "\n",
614 addr.addr_bytes[0], addr.addr_bytes[1],
615 addr.addr_bytes[2], addr.addr_bytes[3],
616 addr.addr_bytes[4], addr.addr_bytes[5]);
618 /* Enable RX in promiscuous mode for the Ethernet device. */
619 rte_eth_promiscuous_enable(port);
625 init_ports(unsigned int num_ports)
630 struct rte_mempool *mp = rte_pktmbuf_pool_create("packet_pool",
631 /* mbufs */ 16384 * num_ports,
632 /* cache_size */ 512,
634 /* data_room_size */ RTE_MBUF_DEFAULT_BUF_SIZE,
637 for (portid = 0; portid < num_ports; portid++)
638 if (port_init(portid, mp) != 0)
639 rte_exit(EXIT_FAILURE, "Cannot init port %"PRIu8 "\n",
642 for (i = 0; i < num_ports; i++) {
643 void *userdata = (void *)(uintptr_t) i;
645 rte_malloc(NULL, RTE_ETH_TX_BUFFER_SIZE(32), 0);
646 if (fdata->tx_buf[i] == NULL)
647 rte_panic("Out of memory\n");
648 rte_eth_tx_buffer_init(fdata->tx_buf[i], 32);
649 rte_eth_tx_buffer_set_err_callback(fdata->tx_buf[i],
663 setup_eventdev(struct prod_data *prod_data,
664 struct cons_data *cons_data,
665 struct worker_data *worker_data)
667 const uint8_t dev_id = 0;
668 /* +1 stages is for a SINGLE_LINK TX stage */
669 const uint8_t nb_queues = cdata.num_stages + 1;
670 /* + 2 is one port for producer and one for consumer */
671 const uint8_t nb_ports = cdata.num_workers + 2;
672 struct rte_event_dev_config config = {
673 .nb_event_queues = nb_queues,
674 .nb_event_ports = nb_ports,
675 .nb_events_limit = 4096,
676 .nb_event_queue_flows = 1024,
677 .nb_event_port_dequeue_depth = 128,
678 .nb_event_port_enqueue_depth = 128,
680 struct rte_event_port_conf wkr_p_conf = {
681 .dequeue_depth = cdata.worker_cq_depth,
683 .new_event_threshold = 4096,
685 struct rte_event_queue_conf wkr_q_conf = {
686 .event_queue_cfg = cdata.queue_type,
687 .priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
688 .nb_atomic_flows = 1024,
689 .nb_atomic_order_sequences = 1024,
691 struct rte_event_port_conf tx_p_conf = {
692 .dequeue_depth = 128,
693 .enqueue_depth = 128,
694 .new_event_threshold = 4096,
696 const struct rte_event_queue_conf tx_q_conf = {
697 .priority = RTE_EVENT_DEV_PRIORITY_HIGHEST,
699 RTE_EVENT_QUEUE_CFG_ATOMIC_ONLY |
700 RTE_EVENT_QUEUE_CFG_SINGLE_LINK,
701 .nb_atomic_flows = 1024,
702 .nb_atomic_order_sequences = 1024,
705 struct port_link worker_queues[MAX_NUM_STAGES];
706 struct port_link tx_queue;
709 int ret, ndev = rte_event_dev_count();
711 printf("%d: No Eventdev Devices Found\n", __LINE__);
715 struct rte_event_dev_info dev_info;
716 ret = rte_event_dev_info_get(dev_id, &dev_info);
717 printf("\tEventdev %d: %s\n", dev_id, dev_info.driver_name);
719 if (dev_info.max_event_port_dequeue_depth <
720 config.nb_event_port_dequeue_depth)
721 config.nb_event_port_dequeue_depth =
722 dev_info.max_event_port_dequeue_depth;
723 if (dev_info.max_event_port_enqueue_depth <
724 config.nb_event_port_enqueue_depth)
725 config.nb_event_port_enqueue_depth =
726 dev_info.max_event_port_enqueue_depth;
728 ret = rte_event_dev_configure(dev_id, &config);
730 printf("%d: Error configuring device\n", __LINE__);
734 /* Q creation - one load balanced per pipeline stage*/
735 printf(" Stages:\n");
736 for (i = 0; i < cdata.num_stages; i++) {
737 if (rte_event_queue_setup(dev_id, i, &wkr_q_conf) < 0) {
738 printf("%d: error creating qid %d\n", __LINE__, i);
742 cdata.next_qid[i] = i+1;
743 worker_queues[i].queue_id = i;
744 if (cdata.enable_queue_priorities) {
745 /* calculate priority stepping for each stage, leaving
746 * headroom of 1 for the SINGLE_LINK TX below
748 const uint32_t prio_delta =
749 (RTE_EVENT_DEV_PRIORITY_LOWEST-1) / nb_queues;
751 /* higher priority for queues closer to tx */
752 wkr_q_conf.priority =
753 RTE_EVENT_DEV_PRIORITY_LOWEST - prio_delta * i;
756 const char *type_str = "Atomic";
757 switch (wkr_q_conf.event_queue_cfg) {
758 case RTE_EVENT_QUEUE_CFG_ORDERED_ONLY:
759 type_str = "Ordered";
761 case RTE_EVENT_QUEUE_CFG_PARALLEL_ONLY:
762 type_str = "Parallel";
765 printf("\tStage %d, Type %s\tPriority = %d\n", i, type_str,
766 wkr_q_conf.priority);
770 /* final queue for sending to TX core */
771 if (rte_event_queue_setup(dev_id, i, &tx_q_conf) < 0) {
772 printf("%d: error creating qid %d\n", __LINE__, i);
775 tx_queue.queue_id = i;
776 tx_queue.priority = RTE_EVENT_DEV_PRIORITY_HIGHEST;
778 if (wkr_p_conf.dequeue_depth > config.nb_event_port_dequeue_depth)
779 wkr_p_conf.dequeue_depth = config.nb_event_port_dequeue_depth;
780 if (wkr_p_conf.enqueue_depth > config.nb_event_port_enqueue_depth)
781 wkr_p_conf.enqueue_depth = config.nb_event_port_enqueue_depth;
783 /* set up one port per worker, linking to all stage queues */
784 for (i = 0; i < cdata.num_workers; i++) {
785 struct worker_data *w = &worker_data[i];
787 if (rte_event_port_setup(dev_id, i, &wkr_p_conf) < 0) {
788 printf("Error setting up port %d\n", i);
793 for (s = 0; s < cdata.num_stages; s++) {
794 if (rte_event_port_link(dev_id, i,
795 &worker_queues[s].queue_id,
796 &worker_queues[s].priority,
798 printf("%d: error creating link for port %d\n",
806 if (tx_p_conf.dequeue_depth > config.nb_event_port_dequeue_depth)
807 tx_p_conf.dequeue_depth = config.nb_event_port_dequeue_depth;
808 if (tx_p_conf.enqueue_depth > config.nb_event_port_enqueue_depth)
809 tx_p_conf.enqueue_depth = config.nb_event_port_enqueue_depth;
811 /* port for consumer, linked to TX queue */
812 if (rte_event_port_setup(dev_id, i, &tx_p_conf) < 0) {
813 printf("Error setting up port %d\n", i);
816 if (rte_event_port_link(dev_id, i, &tx_queue.queue_id,
817 &tx_queue.priority, 1) != 1) {
818 printf("%d: error creating link for port %d\n",
822 /* port for producer, no links */
823 struct rte_event_port_conf rx_p_conf = {
826 .new_event_threshold = 1200,
829 if (rx_p_conf.dequeue_depth > config.nb_event_port_dequeue_depth)
830 rx_p_conf.dequeue_depth = config.nb_event_port_dequeue_depth;
831 if (rx_p_conf.enqueue_depth > config.nb_event_port_enqueue_depth)
832 rx_p_conf.enqueue_depth = config.nb_event_port_enqueue_depth;
834 if (rte_event_port_setup(dev_id, i + 1, &rx_p_conf) < 0) {
835 printf("Error setting up port %d\n", i);
839 *prod_data = (struct prod_data){.dev_id = dev_id,
841 .qid = cdata.qid[0] };
842 *cons_data = (struct cons_data){.dev_id = dev_id,
845 if (rte_event_dev_start(dev_id) < 0) {
846 printf("Error starting eventdev\n");
854 signal_handler(int signum)
857 rte_exit(1, "Exiting on signal %d\n", signum);
858 if (signum == SIGINT || signum == SIGTERM) {
859 printf("\n\nSignal %d received, preparing to exit...\n",
863 if (signum == SIGTSTP)
864 rte_event_dev_dump(0, stdout);
867 static inline uint64_t
868 port_stat(int dev_id, int32_t p)
871 snprintf(statname, sizeof(statname), "port_%u_rx", p);
872 return rte_event_dev_xstats_by_name_get(dev_id, statname, NULL);
876 main(int argc, char **argv)
878 struct worker_data *worker_data;
879 unsigned int num_ports;
883 signal(SIGINT, signal_handler);
884 signal(SIGTERM, signal_handler);
885 signal(SIGTSTP, signal_handler);
887 err = rte_eal_init(argc, argv);
889 rte_panic("Invalid EAL arguments\n");
894 fdata = rte_malloc(NULL, sizeof(struct fastpath_data), 0);
896 rte_panic("Out of memory\n");
898 /* Parse cli options*/
899 parse_app_args(argc, argv);
901 num_ports = rte_eth_dev_count();
903 rte_panic("No ethernet ports found\n");
905 const unsigned int cores_needed = cdata.active_cores;
908 printf(" Config:\n");
909 printf("\tports: %u\n", num_ports);
910 printf("\tworkers: %u\n", cdata.num_workers);
911 printf("\tpackets: %lu\n", cdata.num_packets);
912 printf("\tQueue-prio: %u\n", cdata.enable_queue_priorities);
913 if (cdata.queue_type == RTE_EVENT_QUEUE_CFG_ORDERED_ONLY)
914 printf("\tqid0 type: ordered\n");
915 if (cdata.queue_type == RTE_EVENT_QUEUE_CFG_ATOMIC_ONLY)
916 printf("\tqid0 type: atomic\n");
917 printf("\tCores available: %u\n", rte_lcore_count());
918 printf("\tCores used: %u\n", cores_needed);
921 if (rte_lcore_count() < cores_needed)
922 rte_panic("Too few cores (%d < %d)\n", rte_lcore_count(),
925 const unsigned int ndevs = rte_event_dev_count();
927 rte_panic("No dev_id devs found. Pasl in a --vdev eventdev.\n");
929 fprintf(stderr, "Warning: More than one eventdev, using idx 0");
931 worker_data = rte_calloc(0, cdata.num_workers,
932 sizeof(worker_data[0]), 0);
933 if (worker_data == NULL)
934 rte_panic("rte_calloc failed\n");
936 int dev_id = setup_eventdev(&prod_data, &cons_data, worker_data);
938 rte_exit(EXIT_FAILURE, "Error setting up eventdev\n");
940 prod_data.num_nic_ports = num_ports;
941 init_ports(num_ports);
944 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
945 if (lcore_id >= MAX_NUM_CORE)
948 if (!fdata->rx_core[lcore_id] &&
949 !fdata->worker_core[lcore_id] &&
950 !fdata->tx_core[lcore_id] &&
951 !fdata->sched_core[lcore_id])
954 if (fdata->rx_core[lcore_id])
956 "[%s()] lcore %d executing NIC Rx, and using eventdev port %u\n",
957 __func__, lcore_id, prod_data.port_id);
959 if (fdata->tx_core[lcore_id])
961 "[%s()] lcore %d executing NIC Tx, and using eventdev port %u\n",
962 __func__, lcore_id, cons_data.port_id);
964 if (fdata->sched_core[lcore_id])
965 printf("[%s()] lcore %d executing scheduler\n",
968 if (fdata->worker_core[lcore_id])
970 "[%s()] lcore %d executing worker, using eventdev port %u\n",
972 worker_data[worker_idx].port_id);
974 err = rte_eal_remote_launch(worker, &worker_data[worker_idx],
977 rte_panic("Failed to launch worker on core %d\n",
981 if (fdata->worker_core[lcore_id])
985 lcore_id = rte_lcore_id();
987 if (core_in_use(lcore_id))
988 worker(&worker_data[worker_idx++]);
990 rte_eal_mp_wait_lcore();
993 rte_event_dev_dump(dev_id, stdout);
995 if (!cdata.quiet && (port_stat(dev_id, worker_data[0].port_id) !=
996 (uint64_t)-ENOTSUP)) {
997 printf("\nPort Workload distribution:\n");
999 uint64_t tot_pkts = 0;
1000 uint64_t pkts_per_wkr[RTE_MAX_LCORE] = {0};
1001 for (i = 0; i < cdata.num_workers; i++) {
1003 port_stat(dev_id, worker_data[i].port_id);
1004 tot_pkts += pkts_per_wkr[i];
1006 for (i = 0; i < cdata.num_workers; i++) {
1007 float pc = pkts_per_wkr[i] * 100 /
1009 printf("worker %i :\t%.1f %% (%"PRIu64" pkts)\n",
1010 i, pc, pkts_per_wkr[i]);