1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2016-2017 Intel Corporation
10 #include <sys/queue.h>
12 #include <rte_memory.h>
13 #include <rte_launch.h>
15 #include <rte_per_lcore.h>
16 #include <rte_lcore.h>
17 #include <rte_debug.h>
18 #include <rte_ethdev.h>
19 #include <rte_cycles.h>
20 #include <rte_eventdev.h>
21 #include <rte_pause.h>
22 #include <rte_service.h>
23 #include <rte_service_component.h>
24 #include <rte_bus_vdev.h>
30 #define NUM_PACKETS (1<<18)
35 struct rte_mempool *mbuf_pool;
36 uint8_t port[MAX_PORTS];
37 uint8_t qid[MAX_QIDS];
42 static struct rte_event release_ev;
44 static inline struct rte_mbuf *
45 rte_gen_arp(int portid, struct rte_mempool *mp)
49 * ARP, Request who-has 10.0.0.1 tell 10.0.0.2, length 46
51 static const uint8_t arp_request[] = {
52 /*0x0000:*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xec, 0xa8,
53 0x6b, 0xfd, 0x02, 0x29, 0x08, 0x06, 0x00, 0x01,
54 /*0x0010:*/ 0x08, 0x00, 0x06, 0x04, 0x00, 0x01, 0xec, 0xa8,
55 0x6b, 0xfd, 0x02, 0x29, 0x0a, 0x00, 0x00, 0x01,
56 /*0x0020:*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00,
57 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
58 /*0x0030:*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
59 0x00, 0x00, 0x00, 0x00
62 int pkt_len = sizeof(arp_request) - 1;
64 m = rte_pktmbuf_alloc(mp);
68 memcpy((void *)((uintptr_t)m->buf_addr + m->data_off),
69 arp_request, pkt_len);
70 rte_pktmbuf_pkt_len(m) = pkt_len;
71 rte_pktmbuf_data_len(m) = pkt_len;
81 const uint32_t XSTATS_MAX = 1024;
83 uint32_t ids[XSTATS_MAX];
84 uint64_t values[XSTATS_MAX];
85 struct rte_event_dev_xstats_name xstats_names[XSTATS_MAX];
87 for (i = 0; i < XSTATS_MAX; i++)
90 /* Device names / values */
91 int ret = rte_event_dev_xstats_names_get(evdev,
92 RTE_EVENT_DEV_XSTATS_DEVICE, 0,
93 xstats_names, ids, XSTATS_MAX);
95 printf("%d: xstats names get() returned error\n",
99 ret = rte_event_dev_xstats_get(evdev,
100 RTE_EVENT_DEV_XSTATS_DEVICE,
101 0, ids, values, ret);
102 if (ret > (signed int)XSTATS_MAX)
103 printf("%s %d: more xstats available than space\n",
105 for (i = 0; (signed int)i < ret; i++) {
106 printf("%d : %s : %"PRIu64"\n",
107 i, xstats_names[i].name, values[i]);
110 /* Port names / values */
111 ret = rte_event_dev_xstats_names_get(evdev,
112 RTE_EVENT_DEV_XSTATS_PORT, 0,
113 xstats_names, ids, XSTATS_MAX);
114 ret = rte_event_dev_xstats_get(evdev,
115 RTE_EVENT_DEV_XSTATS_PORT, 1,
117 if (ret > (signed int)XSTATS_MAX)
118 printf("%s %d: more xstats available than space\n",
120 for (i = 0; (signed int)i < ret; i++) {
121 printf("%d : %s : %"PRIu64"\n",
122 i, xstats_names[i].name, values[i]);
125 /* Queue names / values */
126 ret = rte_event_dev_xstats_names_get(evdev,
127 RTE_EVENT_DEV_XSTATS_QUEUE, 0,
128 xstats_names, ids, XSTATS_MAX);
129 ret = rte_event_dev_xstats_get(evdev,
130 RTE_EVENT_DEV_XSTATS_QUEUE,
131 1, ids, values, ret);
132 if (ret > (signed int)XSTATS_MAX)
133 printf("%s %d: more xstats available than space\n",
135 for (i = 0; (signed int)i < ret; i++) {
136 printf("%d : %s : %"PRIu64"\n",
137 i, xstats_names[i].name, values[i]);
141 /* initialization and config */
143 init(struct test *t, int nb_queues, int nb_ports)
145 struct rte_event_dev_config config = {
146 .nb_event_queues = nb_queues,
147 .nb_event_ports = nb_ports,
148 .nb_event_queue_flows = 1024,
149 .nb_events_limit = 4096,
150 .nb_event_port_dequeue_depth = 128,
151 .nb_event_port_enqueue_depth = 128,
155 void *temp = t->mbuf_pool; /* save and restore mbuf pool */
157 memset(t, 0, sizeof(*t));
160 ret = rte_event_dev_configure(evdev, &config);
162 printf("%d: Error configuring device\n", __LINE__);
167 create_ports(struct test *t, int num_ports)
170 static const struct rte_event_port_conf conf = {
171 .new_event_threshold = 1024,
174 .disable_implicit_release = 0,
176 if (num_ports > MAX_PORTS)
179 for (i = 0; i < num_ports; i++) {
180 if (rte_event_port_setup(evdev, i, &conf) < 0) {
181 printf("Error setting up port %d\n", i);
191 create_lb_qids(struct test *t, int num_qids, uint32_t flags)
196 const struct rte_event_queue_conf conf = {
197 .schedule_type = flags,
198 .priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
199 .nb_atomic_flows = 1024,
200 .nb_atomic_order_sequences = 1024,
203 for (i = t->nb_qids; i < t->nb_qids + num_qids; i++) {
204 if (rte_event_queue_setup(evdev, i, &conf) < 0) {
205 printf("%d: error creating qid %d\n", __LINE__, i);
210 t->nb_qids += num_qids;
211 if (t->nb_qids > MAX_QIDS)
218 create_atomic_qids(struct test *t, int num_qids)
220 return create_lb_qids(t, num_qids, RTE_SCHED_TYPE_ATOMIC);
224 create_ordered_qids(struct test *t, int num_qids)
226 return create_lb_qids(t, num_qids, RTE_SCHED_TYPE_ORDERED);
231 create_unordered_qids(struct test *t, int num_qids)
233 return create_lb_qids(t, num_qids, RTE_SCHED_TYPE_PARALLEL);
237 create_directed_qids(struct test *t, int num_qids, const uint8_t ports[])
242 static const struct rte_event_queue_conf conf = {
243 .priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
244 .event_queue_cfg = RTE_EVENT_QUEUE_CFG_SINGLE_LINK,
247 for (i = t->nb_qids; i < t->nb_qids + num_qids; i++) {
248 if (rte_event_queue_setup(evdev, i, &conf) < 0) {
249 printf("%d: error creating qid %d\n", __LINE__, i);
254 if (rte_event_port_link(evdev, ports[i - t->nb_qids],
255 &t->qid[i], NULL, 1) != 1) {
256 printf("%d: error creating link for qid %d\n",
261 t->nb_qids += num_qids;
262 if (t->nb_qids > MAX_QIDS)
270 cleanup(struct test *t __rte_unused)
272 rte_event_dev_stop(evdev);
273 rte_event_dev_close(evdev);
277 struct test_event_dev_stats {
278 uint64_t rx_pkts; /**< Total packets received */
279 uint64_t rx_dropped; /**< Total packets dropped (Eg Invalid QID) */
280 uint64_t tx_pkts; /**< Total packets transmitted */
282 /** Packets received on this port */
283 uint64_t port_rx_pkts[MAX_PORTS];
284 /** Packets dropped on this port */
285 uint64_t port_rx_dropped[MAX_PORTS];
286 /** Packets inflight on this port */
287 uint64_t port_inflight[MAX_PORTS];
288 /** Packets transmitted on this port */
289 uint64_t port_tx_pkts[MAX_PORTS];
290 /** Packets received on this qid */
291 uint64_t qid_rx_pkts[MAX_QIDS];
292 /** Packets dropped on this qid */
293 uint64_t qid_rx_dropped[MAX_QIDS];
294 /** Packets transmitted on this qid */
295 uint64_t qid_tx_pkts[MAX_QIDS];
299 test_event_dev_stats_get(int dev_id, struct test_event_dev_stats *stats)
302 static uint32_t total_ids[3]; /* rx, tx and drop */
303 static uint32_t port_rx_pkts_ids[MAX_PORTS];
304 static uint32_t port_rx_dropped_ids[MAX_PORTS];
305 static uint32_t port_inflight_ids[MAX_PORTS];
306 static uint32_t port_tx_pkts_ids[MAX_PORTS];
307 static uint32_t qid_rx_pkts_ids[MAX_QIDS];
308 static uint32_t qid_rx_dropped_ids[MAX_QIDS];
309 static uint32_t qid_tx_pkts_ids[MAX_QIDS];
312 stats->rx_pkts = rte_event_dev_xstats_by_name_get(dev_id,
313 "dev_rx", &total_ids[0]);
314 stats->rx_dropped = rte_event_dev_xstats_by_name_get(dev_id,
315 "dev_drop", &total_ids[1]);
316 stats->tx_pkts = rte_event_dev_xstats_by_name_get(dev_id,
317 "dev_tx", &total_ids[2]);
318 for (i = 0; i < MAX_PORTS; i++) {
320 snprintf(name, sizeof(name), "port_%u_rx", i);
321 stats->port_rx_pkts[i] = rte_event_dev_xstats_by_name_get(
322 dev_id, name, &port_rx_pkts_ids[i]);
323 snprintf(name, sizeof(name), "port_%u_drop", i);
324 stats->port_rx_dropped[i] = rte_event_dev_xstats_by_name_get(
325 dev_id, name, &port_rx_dropped_ids[i]);
326 snprintf(name, sizeof(name), "port_%u_inflight", i);
327 stats->port_inflight[i] = rte_event_dev_xstats_by_name_get(
328 dev_id, name, &port_inflight_ids[i]);
329 snprintf(name, sizeof(name), "port_%u_tx", i);
330 stats->port_tx_pkts[i] = rte_event_dev_xstats_by_name_get(
331 dev_id, name, &port_tx_pkts_ids[i]);
333 for (i = 0; i < MAX_QIDS; i++) {
335 snprintf(name, sizeof(name), "qid_%u_rx", i);
336 stats->qid_rx_pkts[i] = rte_event_dev_xstats_by_name_get(
337 dev_id, name, &qid_rx_pkts_ids[i]);
338 snprintf(name, sizeof(name), "qid_%u_drop", i);
339 stats->qid_rx_dropped[i] = rte_event_dev_xstats_by_name_get(
340 dev_id, name, &qid_rx_dropped_ids[i]);
341 snprintf(name, sizeof(name), "qid_%u_tx", i);
342 stats->qid_tx_pkts[i] = rte_event_dev_xstats_by_name_get(
343 dev_id, name, &qid_tx_pkts_ids[i]);
349 /* run_prio_packet_test
350 * This performs a basic packet priority check on the test instance passed in.
351 * It is factored out of the main priority tests as the same tests must be
352 * performed to ensure prioritization of each type of QID.
355 * - An initialized test structure, including mempool
356 * - t->port[0] is initialized for both Enq / Deq of packets to the QID
357 * - t->qid[0] is the QID to be tested
358 * - if LB QID, the CQ must be mapped to the QID.
361 run_prio_packet_test(struct test *t)
364 const uint32_t MAGIC_SEQN[] = {4711, 1234};
365 const uint32_t PRIORITY[] = {
366 RTE_EVENT_DEV_PRIORITY_NORMAL,
367 RTE_EVENT_DEV_PRIORITY_HIGHEST
370 for (i = 0; i < RTE_DIM(MAGIC_SEQN); i++) {
371 /* generate pkt and enqueue */
373 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
375 printf("%d: gen of pkt failed\n", __LINE__);
378 arp->seqn = MAGIC_SEQN[i];
380 ev = (struct rte_event){
381 .priority = PRIORITY[i],
382 .op = RTE_EVENT_OP_NEW,
383 .queue_id = t->qid[0],
386 err = rte_event_enqueue_burst(evdev, t->port[0], &ev, 1);
388 printf("%d: error failed to enqueue\n", __LINE__);
393 rte_service_run_iter_on_app_lcore(t->service_id, 1);
395 struct test_event_dev_stats stats;
396 err = test_event_dev_stats_get(evdev, &stats);
398 printf("%d: error failed to get stats\n", __LINE__);
402 if (stats.port_rx_pkts[t->port[0]] != 2) {
403 printf("%d: error stats incorrect for directed port\n",
405 rte_event_dev_dump(evdev, stdout);
409 struct rte_event ev, ev2;
411 deq_pkts = rte_event_dequeue_burst(evdev, t->port[0], &ev, 1, 0);
413 printf("%d: error failed to deq\n", __LINE__);
414 rte_event_dev_dump(evdev, stdout);
417 if (ev.mbuf->seqn != MAGIC_SEQN[1]) {
418 printf("%d: first packet out not highest priority\n",
420 rte_event_dev_dump(evdev, stdout);
423 rte_pktmbuf_free(ev.mbuf);
425 deq_pkts = rte_event_dequeue_burst(evdev, t->port[0], &ev2, 1, 0);
427 printf("%d: error failed to deq\n", __LINE__);
428 rte_event_dev_dump(evdev, stdout);
431 if (ev2.mbuf->seqn != MAGIC_SEQN[0]) {
432 printf("%d: second packet out not lower priority\n",
434 rte_event_dev_dump(evdev, stdout);
437 rte_pktmbuf_free(ev2.mbuf);
444 test_single_directed_packet(struct test *t)
446 const int rx_enq = 0;
447 const int wrk_enq = 2;
450 /* Create instance with 3 directed QIDs going to 3 ports */
451 if (init(t, 3, 3) < 0 ||
452 create_ports(t, 3) < 0 ||
453 create_directed_qids(t, 3, t->port) < 0)
456 if (rte_event_dev_start(evdev) < 0) {
457 printf("%d: Error with start call\n", __LINE__);
461 /************** FORWARD ****************/
462 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
463 struct rte_event ev = {
464 .op = RTE_EVENT_OP_NEW,
470 printf("%d: gen of pkt failed\n", __LINE__);
474 const uint32_t MAGIC_SEQN = 4711;
475 arp->seqn = MAGIC_SEQN;
477 /* generate pkt and enqueue */
478 err = rte_event_enqueue_burst(evdev, rx_enq, &ev, 1);
480 printf("%d: error failed to enqueue\n", __LINE__);
484 /* Run schedule() as dir packets may need to be re-ordered */
485 rte_service_run_iter_on_app_lcore(t->service_id, 1);
487 struct test_event_dev_stats stats;
488 err = test_event_dev_stats_get(evdev, &stats);
490 printf("%d: error failed to get stats\n", __LINE__);
494 if (stats.port_rx_pkts[rx_enq] != 1) {
495 printf("%d: error stats incorrect for directed port\n",
501 deq_pkts = rte_event_dequeue_burst(evdev, wrk_enq, &ev, 1, 0);
503 printf("%d: error failed to deq\n", __LINE__);
507 err = test_event_dev_stats_get(evdev, &stats);
508 if (stats.port_rx_pkts[wrk_enq] != 0 &&
509 stats.port_rx_pkts[wrk_enq] != 1) {
510 printf("%d: error directed stats post-dequeue\n", __LINE__);
514 if (ev.mbuf->seqn != MAGIC_SEQN) {
515 printf("%d: error magic sequence number not dequeued\n",
520 rte_pktmbuf_free(ev.mbuf);
526 test_directed_forward_credits(struct test *t)
531 if (init(t, 1, 1) < 0 ||
532 create_ports(t, 1) < 0 ||
533 create_directed_qids(t, 1, t->port) < 0)
536 if (rte_event_dev_start(evdev) < 0) {
537 printf("%d: Error with start call\n", __LINE__);
541 struct rte_event ev = {
542 .op = RTE_EVENT_OP_NEW,
546 for (i = 0; i < 1000; i++) {
547 err = rte_event_enqueue_burst(evdev, 0, &ev, 1);
549 printf("%d: error failed to enqueue\n", __LINE__);
552 rte_service_run_iter_on_app_lcore(t->service_id, 1);
555 deq_pkts = rte_event_dequeue_burst(evdev, 0, &ev, 1, 0);
557 printf("%d: error failed to deq\n", __LINE__);
561 /* re-write event to be a forward, and continue looping it */
562 ev.op = RTE_EVENT_OP_FORWARD;
571 test_priority_directed(struct test *t)
573 if (init(t, 1, 1) < 0 ||
574 create_ports(t, 1) < 0 ||
575 create_directed_qids(t, 1, t->port) < 0) {
576 printf("%d: Error initializing device\n", __LINE__);
580 if (rte_event_dev_start(evdev) < 0) {
581 printf("%d: Error with start call\n", __LINE__);
585 return run_prio_packet_test(t);
589 test_priority_atomic(struct test *t)
591 if (init(t, 1, 1) < 0 ||
592 create_ports(t, 1) < 0 ||
593 create_atomic_qids(t, 1) < 0) {
594 printf("%d: Error initializing device\n", __LINE__);
599 if (rte_event_port_link(evdev, t->port[0], &t->qid[0], NULL, 1) != 1) {
600 printf("%d: error mapping qid to port\n", __LINE__);
603 if (rte_event_dev_start(evdev) < 0) {
604 printf("%d: Error with start call\n", __LINE__);
608 return run_prio_packet_test(t);
612 test_priority_ordered(struct test *t)
614 if (init(t, 1, 1) < 0 ||
615 create_ports(t, 1) < 0 ||
616 create_ordered_qids(t, 1) < 0) {
617 printf("%d: Error initializing device\n", __LINE__);
622 if (rte_event_port_link(evdev, t->port[0], &t->qid[0], NULL, 1) != 1) {
623 printf("%d: error mapping qid to port\n", __LINE__);
626 if (rte_event_dev_start(evdev) < 0) {
627 printf("%d: Error with start call\n", __LINE__);
631 return run_prio_packet_test(t);
635 test_priority_unordered(struct test *t)
637 if (init(t, 1, 1) < 0 ||
638 create_ports(t, 1) < 0 ||
639 create_unordered_qids(t, 1) < 0) {
640 printf("%d: Error initializing device\n", __LINE__);
645 if (rte_event_port_link(evdev, t->port[0], &t->qid[0], NULL, 1) != 1) {
646 printf("%d: error mapping qid to port\n", __LINE__);
649 if (rte_event_dev_start(evdev) < 0) {
650 printf("%d: Error with start call\n", __LINE__);
654 return run_prio_packet_test(t);
658 burst_packets(struct test *t)
660 /************** CONFIG ****************/
665 /* Create instance with 2 ports and 2 queues */
666 if (init(t, 2, 2) < 0 ||
667 create_ports(t, 2) < 0 ||
668 create_atomic_qids(t, 2) < 0) {
669 printf("%d: Error initializing device\n", __LINE__);
673 /* CQ mapping to QID */
674 ret = rte_event_port_link(evdev, t->port[0], &t->qid[0], NULL, 1);
676 printf("%d: error mapping lb qid0\n", __LINE__);
679 ret = rte_event_port_link(evdev, t->port[1], &t->qid[1], NULL, 1);
681 printf("%d: error mapping lb qid1\n", __LINE__);
685 if (rte_event_dev_start(evdev) < 0) {
686 printf("%d: Error with start call\n", __LINE__);
690 /************** FORWARD ****************/
691 const uint32_t rx_port = 0;
692 const uint32_t NUM_PKTS = 2;
694 for (i = 0; i < NUM_PKTS; i++) {
695 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
697 printf("%d: error generating pkt\n", __LINE__);
701 struct rte_event ev = {
702 .op = RTE_EVENT_OP_NEW,
707 /* generate pkt and enqueue */
708 err = rte_event_enqueue_burst(evdev, t->port[rx_port], &ev, 1);
710 printf("%d: Failed to enqueue\n", __LINE__);
714 rte_service_run_iter_on_app_lcore(t->service_id, 1);
716 /* Check stats for all NUM_PKTS arrived to sched core */
717 struct test_event_dev_stats stats;
719 err = test_event_dev_stats_get(evdev, &stats);
721 printf("%d: failed to get stats\n", __LINE__);
724 if (stats.rx_pkts != NUM_PKTS || stats.tx_pkts != NUM_PKTS) {
725 printf("%d: Sched core didn't receive all %d pkts\n",
727 rte_event_dev_dump(evdev, stdout);
735 /******** DEQ QID 1 *******/
738 p = rte_event_dequeue_burst(evdev, t->port[0], &ev, 1, 0);
740 rte_pktmbuf_free(ev.mbuf);
743 if (deq_pkts != NUM_PKTS/2) {
744 printf("%d: Half of NUM_PKTS didn't arrive at port 1\n",
749 /******** DEQ QID 2 *******/
753 p = rte_event_dequeue_burst(evdev, t->port[1], &ev, 1, 0);
755 rte_pktmbuf_free(ev.mbuf);
757 if (deq_pkts != NUM_PKTS/2) {
758 printf("%d: Half of NUM_PKTS didn't arrive at port 2\n",
768 abuse_inflights(struct test *t)
770 const int rx_enq = 0;
771 const int wrk_enq = 2;
774 /* Create instance with 4 ports */
775 if (init(t, 1, 4) < 0 ||
776 create_ports(t, 4) < 0 ||
777 create_atomic_qids(t, 1) < 0) {
778 printf("%d: Error initializing device\n", __LINE__);
782 /* CQ mapping to QID */
783 err = rte_event_port_link(evdev, t->port[wrk_enq], NULL, NULL, 0);
785 printf("%d: error mapping lb qid\n", __LINE__);
790 if (rte_event_dev_start(evdev) < 0) {
791 printf("%d: Error with start call\n", __LINE__);
795 /* Enqueue op only */
796 err = rte_event_enqueue_burst(evdev, t->port[rx_enq], &release_ev, 1);
798 printf("%d: Failed to enqueue\n", __LINE__);
803 rte_service_run_iter_on_app_lcore(t->service_id, 1);
805 struct test_event_dev_stats stats;
807 err = test_event_dev_stats_get(evdev, &stats);
809 printf("%d: failed to get stats\n", __LINE__);
813 if (stats.rx_pkts != 0 ||
814 stats.tx_pkts != 0 ||
815 stats.port_inflight[wrk_enq] != 0) {
816 printf("%d: Sched core didn't handle pkt as expected\n",
826 xstats_tests(struct test *t)
828 const int wrk_enq = 2;
831 /* Create instance with 4 ports */
832 if (init(t, 1, 4) < 0 ||
833 create_ports(t, 4) < 0 ||
834 create_atomic_qids(t, 1) < 0) {
835 printf("%d: Error initializing device\n", __LINE__);
839 /* CQ mapping to QID */
840 err = rte_event_port_link(evdev, t->port[wrk_enq], NULL, NULL, 0);
842 printf("%d: error mapping lb qid\n", __LINE__);
847 if (rte_event_dev_start(evdev) < 0) {
848 printf("%d: Error with start call\n", __LINE__);
852 const uint32_t XSTATS_MAX = 1024;
855 uint32_t ids[XSTATS_MAX];
856 uint64_t values[XSTATS_MAX];
857 struct rte_event_dev_xstats_name xstats_names[XSTATS_MAX];
859 for (i = 0; i < XSTATS_MAX; i++)
862 /* Device names / values */
863 int ret = rte_event_dev_xstats_names_get(evdev,
864 RTE_EVENT_DEV_XSTATS_DEVICE,
865 0, xstats_names, ids, XSTATS_MAX);
867 printf("%d: expected 6 stats, got return %d\n", __LINE__, ret);
870 ret = rte_event_dev_xstats_get(evdev,
871 RTE_EVENT_DEV_XSTATS_DEVICE,
872 0, ids, values, ret);
874 printf("%d: expected 6 stats, got return %d\n", __LINE__, ret);
878 /* Port names / values */
879 ret = rte_event_dev_xstats_names_get(evdev,
880 RTE_EVENT_DEV_XSTATS_PORT, 0,
881 xstats_names, ids, XSTATS_MAX);
883 printf("%d: expected 21 stats, got return %d\n", __LINE__, ret);
886 ret = rte_event_dev_xstats_get(evdev,
887 RTE_EVENT_DEV_XSTATS_PORT, 0,
890 printf("%d: expected 21 stats, got return %d\n", __LINE__, ret);
894 /* Queue names / values */
895 ret = rte_event_dev_xstats_names_get(evdev,
896 RTE_EVENT_DEV_XSTATS_QUEUE,
897 0, xstats_names, ids, XSTATS_MAX);
899 printf("%d: expected 16 stats, got return %d\n", __LINE__, ret);
903 /* NEGATIVE TEST: with wrong queue passed, 0 stats should be returned */
904 ret = rte_event_dev_xstats_get(evdev,
905 RTE_EVENT_DEV_XSTATS_QUEUE,
906 1, ids, values, ret);
907 if (ret != -EINVAL) {
908 printf("%d: expected 0 stats, got return %d\n", __LINE__, ret);
912 ret = rte_event_dev_xstats_get(evdev,
913 RTE_EVENT_DEV_XSTATS_QUEUE,
914 0, ids, values, ret);
916 printf("%d: expected 16 stats, got return %d\n", __LINE__, ret);
920 /* enqueue packets to check values */
921 for (i = 0; i < 3; i++) {
923 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
925 printf("%d: gen of pkt failed\n", __LINE__);
928 ev.queue_id = t->qid[i];
929 ev.op = RTE_EVENT_OP_NEW;
934 int err = rte_event_enqueue_burst(evdev, t->port[0], &ev, 1);
936 printf("%d: Failed to enqueue\n", __LINE__);
941 rte_service_run_iter_on_app_lcore(t->service_id, 1);
943 /* Device names / values */
944 int num_stats = rte_event_dev_xstats_names_get(evdev,
945 RTE_EVENT_DEV_XSTATS_DEVICE, 0,
946 xstats_names, ids, XSTATS_MAX);
949 ret = rte_event_dev_xstats_get(evdev,
950 RTE_EVENT_DEV_XSTATS_DEVICE,
951 0, ids, values, num_stats);
952 static const uint64_t expected[] = {3, 3, 0, 1, 0, 0};
953 for (i = 0; (signed int)i < ret; i++) {
954 if (expected[i] != values[i]) {
956 "%d Error xstat %d (id %d) %s : %"PRIu64
957 ", expect %"PRIu64"\n",
958 __LINE__, i, ids[i], xstats_names[i].name,
959 values[i], expected[i]);
964 ret = rte_event_dev_xstats_reset(evdev, RTE_EVENT_DEV_XSTATS_DEVICE,
967 /* ensure reset statistics are zero-ed */
968 static const uint64_t expected_zero[] = {0, 0, 0, 0, 0, 0};
969 ret = rte_event_dev_xstats_get(evdev,
970 RTE_EVENT_DEV_XSTATS_DEVICE,
971 0, ids, values, num_stats);
972 for (i = 0; (signed int)i < ret; i++) {
973 if (expected_zero[i] != values[i]) {
975 "%d Error, xstat %d (id %d) %s : %"PRIu64
976 ", expect %"PRIu64"\n",
977 __LINE__, i, ids[i], xstats_names[i].name,
978 values[i], expected_zero[i]);
983 /* port reset checks */
984 num_stats = rte_event_dev_xstats_names_get(evdev,
985 RTE_EVENT_DEV_XSTATS_PORT, 0,
986 xstats_names, ids, XSTATS_MAX);
989 ret = rte_event_dev_xstats_get(evdev, RTE_EVENT_DEV_XSTATS_PORT,
990 0, ids, values, num_stats);
992 static const uint64_t port_expected[] = {
997 0 /* avg pkt cycles */,
999 0 /* rx ring used */,
1000 4096 /* rx ring free */,
1001 0 /* cq ring used */,
1002 32 /* cq ring free */,
1003 0 /* dequeue calls */,
1004 /* 10 dequeue burst buckets */
1008 if (ret != RTE_DIM(port_expected)) {
1010 "%s %d: wrong number of port stats (%d), expected %zu\n",
1011 __func__, __LINE__, ret, RTE_DIM(port_expected));
1014 for (i = 0; (signed int)i < ret; i++) {
1015 if (port_expected[i] != values[i]) {
1017 "%s : %d: Error stat %s is %"PRIu64
1018 ", expected %"PRIu64"\n",
1019 __func__, __LINE__, xstats_names[i].name,
1020 values[i], port_expected[i]);
1025 ret = rte_event_dev_xstats_reset(evdev, RTE_EVENT_DEV_XSTATS_PORT,
1028 /* ensure reset statistics are zero-ed */
1029 static const uint64_t port_expected_zero[] = {
1034 0 /* avg pkt cycles */,
1036 0 /* rx ring used */,
1037 4096 /* rx ring free */,
1038 0 /* cq ring used */,
1039 32 /* cq ring free */,
1040 0 /* dequeue calls */,
1041 /* 10 dequeue burst buckets */
1045 ret = rte_event_dev_xstats_get(evdev,
1046 RTE_EVENT_DEV_XSTATS_PORT,
1047 0, ids, values, num_stats);
1048 for (i = 0; (signed int)i < ret; i++) {
1049 if (port_expected_zero[i] != values[i]) {
1051 "%d, Error, xstat %d (id %d) %s : %"PRIu64
1052 ", expect %"PRIu64"\n",
1053 __LINE__, i, ids[i], xstats_names[i].name,
1054 values[i], port_expected_zero[i]);
1059 /* QUEUE STATS TESTS */
1060 num_stats = rte_event_dev_xstats_names_get(evdev,
1061 RTE_EVENT_DEV_XSTATS_QUEUE, 0,
1062 xstats_names, ids, XSTATS_MAX);
1063 ret = rte_event_dev_xstats_get(evdev, RTE_EVENT_DEV_XSTATS_QUEUE,
1064 0, ids, values, num_stats);
1066 printf("xstats get returned %d\n", ret);
1069 if ((unsigned int)ret > XSTATS_MAX)
1070 printf("%s %d: more xstats available than space\n",
1071 __func__, __LINE__);
1073 static const uint64_t queue_expected[] = {
1078 0, 0, 0, 0, /* iq 0, 1, 2, 3 used */
1079 /* QID-to-Port: pinned_flows, packets */
1085 for (i = 0; (signed int)i < ret; i++) {
1086 if (queue_expected[i] != values[i]) {
1088 "%d, Error, xstat %d (id %d) %s : %"PRIu64
1089 ", expect %"PRIu64"\n",
1090 __LINE__, i, ids[i], xstats_names[i].name,
1091 values[i], queue_expected[i]);
1096 /* Reset the queue stats here */
1097 ret = rte_event_dev_xstats_reset(evdev,
1098 RTE_EVENT_DEV_XSTATS_QUEUE, 0,
1102 /* Verify that the resetable stats are reset, and others are not */
1103 static const uint64_t queue_expected_zero[] = {
1108 0, 0, 0, 0, /* 4 iq used */
1109 /* QID-to-Port: pinned_flows, packets */
1116 ret = rte_event_dev_xstats_get(evdev, RTE_EVENT_DEV_XSTATS_QUEUE, 0,
1117 ids, values, num_stats);
1119 for (i = 0; (signed int)i < ret; i++) {
1120 if (queue_expected_zero[i] != values[i]) {
1122 "%d, Error, xstat %d (id %d) %s : %"PRIu64
1123 ", expect %"PRIu64"\n",
1124 __LINE__, i, ids[i], xstats_names[i].name,
1125 values[i], queue_expected_zero[i]);
1130 printf("%d : %d of values were not as expected above\n",
1139 rte_event_dev_dump(0, stdout);
1146 xstats_id_abuse_tests(struct test *t)
1149 const uint32_t XSTATS_MAX = 1024;
1150 const uint32_t link_port = 2;
1152 uint32_t ids[XSTATS_MAX];
1153 struct rte_event_dev_xstats_name xstats_names[XSTATS_MAX];
1155 /* Create instance with 4 ports */
1156 if (init(t, 1, 4) < 0 ||
1157 create_ports(t, 4) < 0 ||
1158 create_atomic_qids(t, 1) < 0) {
1159 printf("%d: Error initializing device\n", __LINE__);
1163 err = rte_event_port_link(evdev, t->port[link_port], NULL, NULL, 0);
1165 printf("%d: error mapping lb qid\n", __LINE__);
1169 if (rte_event_dev_start(evdev) < 0) {
1170 printf("%d: Error with start call\n", __LINE__);
1174 /* no test for device, as it ignores the port/q number */
1175 int num_stats = rte_event_dev_xstats_names_get(evdev,
1176 RTE_EVENT_DEV_XSTATS_PORT,
1177 UINT8_MAX-1, xstats_names, ids,
1179 if (num_stats != 0) {
1180 printf("%d: expected %d stats, got return %d\n", __LINE__,
1185 num_stats = rte_event_dev_xstats_names_get(evdev,
1186 RTE_EVENT_DEV_XSTATS_QUEUE,
1187 UINT8_MAX-1, xstats_names, ids,
1189 if (num_stats != 0) {
1190 printf("%d: expected %d stats, got return %d\n", __LINE__,
1203 port_reconfig_credits(struct test *t)
1205 if (init(t, 1, 1) < 0) {
1206 printf("%d: Error initializing device\n", __LINE__);
1211 const uint32_t NUM_ITERS = 32;
1212 for (i = 0; i < NUM_ITERS; i++) {
1213 const struct rte_event_queue_conf conf = {
1214 .schedule_type = RTE_SCHED_TYPE_ATOMIC,
1215 .priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
1216 .nb_atomic_flows = 1024,
1217 .nb_atomic_order_sequences = 1024,
1219 if (rte_event_queue_setup(evdev, 0, &conf) < 0) {
1220 printf("%d: error creating qid\n", __LINE__);
1225 static const struct rte_event_port_conf port_conf = {
1226 .new_event_threshold = 128,
1227 .dequeue_depth = 32,
1228 .enqueue_depth = 64,
1229 .disable_implicit_release = 0,
1231 if (rte_event_port_setup(evdev, 0, &port_conf) < 0) {
1232 printf("%d Error setting up port\n", __LINE__);
1236 int links = rte_event_port_link(evdev, 0, NULL, NULL, 0);
1238 printf("%d: error mapping lb qid\n", __LINE__);
1242 if (rte_event_dev_start(evdev) < 0) {
1243 printf("%d: Error with start call\n", __LINE__);
1247 const uint32_t NPKTS = 1;
1249 for (j = 0; j < NPKTS; j++) {
1250 struct rte_event ev;
1251 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
1253 printf("%d: gen of pkt failed\n", __LINE__);
1256 ev.queue_id = t->qid[0];
1257 ev.op = RTE_EVENT_OP_NEW;
1259 int err = rte_event_enqueue_burst(evdev, 0, &ev, 1);
1261 printf("%d: Failed to enqueue\n", __LINE__);
1262 rte_event_dev_dump(0, stdout);
1267 rte_service_run_iter_on_app_lcore(t->service_id, 1);
1269 struct rte_event ev[NPKTS];
1270 int deq = rte_event_dequeue_burst(evdev, t->port[0], ev,
1273 printf("%d error; no packet dequeued\n", __LINE__);
1275 /* let cleanup below stop the device on last iter */
1276 if (i != NUM_ITERS-1)
1277 rte_event_dev_stop(evdev);
1288 port_single_lb_reconfig(struct test *t)
1290 if (init(t, 2, 2) < 0) {
1291 printf("%d: Error initializing device\n", __LINE__);
1295 static const struct rte_event_queue_conf conf_lb_atomic = {
1296 .priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
1297 .schedule_type = RTE_SCHED_TYPE_ATOMIC,
1298 .nb_atomic_flows = 1024,
1299 .nb_atomic_order_sequences = 1024,
1301 if (rte_event_queue_setup(evdev, 0, &conf_lb_atomic) < 0) {
1302 printf("%d: error creating qid\n", __LINE__);
1306 static const struct rte_event_queue_conf conf_single_link = {
1307 .priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
1308 .event_queue_cfg = RTE_EVENT_QUEUE_CFG_SINGLE_LINK,
1310 if (rte_event_queue_setup(evdev, 1, &conf_single_link) < 0) {
1311 printf("%d: error creating qid\n", __LINE__);
1315 struct rte_event_port_conf port_conf = {
1316 .new_event_threshold = 128,
1317 .dequeue_depth = 32,
1318 .enqueue_depth = 64,
1319 .disable_implicit_release = 0,
1321 if (rte_event_port_setup(evdev, 0, &port_conf) < 0) {
1322 printf("%d Error setting up port\n", __LINE__);
1325 if (rte_event_port_setup(evdev, 1, &port_conf) < 0) {
1326 printf("%d Error setting up port\n", __LINE__);
1330 /* link port to lb queue */
1331 uint8_t queue_id = 0;
1332 if (rte_event_port_link(evdev, 0, &queue_id, NULL, 1) != 1) {
1333 printf("%d: error creating link for qid\n", __LINE__);
1337 int ret = rte_event_port_unlink(evdev, 0, &queue_id, 1);
1339 printf("%d: Error unlinking lb port\n", __LINE__);
1344 if (rte_event_port_link(evdev, 0, &queue_id, NULL, 1) != 1) {
1345 printf("%d: error creating link for qid\n", __LINE__);
1350 int err = rte_event_port_link(evdev, 1, &queue_id, NULL, 1);
1352 printf("%d: error mapping lb qid\n", __LINE__);
1356 if (rte_event_dev_start(evdev) < 0) {
1357 printf("%d: Error with start call\n", __LINE__);
1369 xstats_brute_force(struct test *t)
1372 const uint32_t XSTATS_MAX = 1024;
1373 uint32_t ids[XSTATS_MAX];
1374 uint64_t values[XSTATS_MAX];
1375 struct rte_event_dev_xstats_name xstats_names[XSTATS_MAX];
1378 /* Create instance with 4 ports */
1379 if (init(t, 1, 4) < 0 ||
1380 create_ports(t, 4) < 0 ||
1381 create_atomic_qids(t, 1) < 0) {
1382 printf("%d: Error initializing device\n", __LINE__);
1386 int err = rte_event_port_link(evdev, t->port[0], NULL, NULL, 0);
1388 printf("%d: error mapping lb qid\n", __LINE__);
1392 if (rte_event_dev_start(evdev) < 0) {
1393 printf("%d: Error with start call\n", __LINE__);
1397 for (i = 0; i < XSTATS_MAX; i++)
1400 for (i = 0; i < 3; i++) {
1401 uint32_t mode = RTE_EVENT_DEV_XSTATS_DEVICE + i;
1403 for (j = 0; j < UINT8_MAX; j++) {
1404 rte_event_dev_xstats_names_get(evdev, mode,
1405 j, xstats_names, ids, XSTATS_MAX);
1407 rte_event_dev_xstats_get(evdev, mode, j, ids,
1408 values, XSTATS_MAX);
1420 xstats_id_reset_tests(struct test *t)
1422 const int wrk_enq = 2;
1425 /* Create instance with 4 ports */
1426 if (init(t, 1, 4) < 0 ||
1427 create_ports(t, 4) < 0 ||
1428 create_atomic_qids(t, 1) < 0) {
1429 printf("%d: Error initializing device\n", __LINE__);
1433 /* CQ mapping to QID */
1434 err = rte_event_port_link(evdev, t->port[wrk_enq], NULL, NULL, 0);
1436 printf("%d: error mapping lb qid\n", __LINE__);
1440 if (rte_event_dev_start(evdev) < 0) {
1441 printf("%d: Error with start call\n", __LINE__);
1445 #define XSTATS_MAX 1024
1448 uint32_t ids[XSTATS_MAX];
1449 uint64_t values[XSTATS_MAX];
1450 struct rte_event_dev_xstats_name xstats_names[XSTATS_MAX];
1452 for (i = 0; i < XSTATS_MAX; i++)
1455 #define NUM_DEV_STATS 6
1456 /* Device names / values */
1457 int num_stats = rte_event_dev_xstats_names_get(evdev,
1458 RTE_EVENT_DEV_XSTATS_DEVICE,
1459 0, xstats_names, ids, XSTATS_MAX);
1460 if (num_stats != NUM_DEV_STATS) {
1461 printf("%d: expected %d stats, got return %d\n", __LINE__,
1462 NUM_DEV_STATS, num_stats);
1465 ret = rte_event_dev_xstats_get(evdev,
1466 RTE_EVENT_DEV_XSTATS_DEVICE,
1467 0, ids, values, num_stats);
1468 if (ret != NUM_DEV_STATS) {
1469 printf("%d: expected %d stats, got return %d\n", __LINE__,
1470 NUM_DEV_STATS, ret);
1475 for (i = 0; i < NPKTS; i++) {
1476 struct rte_event ev;
1477 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
1479 printf("%d: gen of pkt failed\n", __LINE__);
1482 ev.queue_id = t->qid[i];
1483 ev.op = RTE_EVENT_OP_NEW;
1487 int err = rte_event_enqueue_burst(evdev, t->port[0], &ev, 1);
1489 printf("%d: Failed to enqueue\n", __LINE__);
1494 rte_service_run_iter_on_app_lcore(t->service_id, 1);
1496 static const char * const dev_names[] = {
1497 "dev_rx", "dev_tx", "dev_drop", "dev_sched_calls",
1498 "dev_sched_no_iq_enq", "dev_sched_no_cq_enq",
1500 uint64_t dev_expected[] = {NPKTS, NPKTS, 0, 1, 0, 0};
1501 for (i = 0; (int)i < ret; i++) {
1503 uint64_t val = rte_event_dev_xstats_by_name_get(evdev,
1507 printf("%d: %s id incorrect, expected %d got %d\n",
1508 __LINE__, dev_names[i], i, id);
1511 if (val != dev_expected[i]) {
1512 printf("%d: %s value incorrect, expected %"
1513 PRIu64" got %d\n", __LINE__, dev_names[i],
1514 dev_expected[i], id);
1518 int reset_ret = rte_event_dev_xstats_reset(evdev,
1519 RTE_EVENT_DEV_XSTATS_DEVICE, 0,
1523 printf("%d: failed to reset successfully\n", __LINE__);
1526 dev_expected[i] = 0;
1527 /* check value again */
1528 val = rte_event_dev_xstats_by_name_get(evdev, dev_names[i], 0);
1529 if (val != dev_expected[i]) {
1530 printf("%d: %s value incorrect, expected %"PRIu64
1531 " got %"PRIu64"\n", __LINE__, dev_names[i],
1532 dev_expected[i], val);
1537 /* 48 is stat offset from start of the devices whole xstats.
1538 * This WILL break every time we add a statistic to a port
1539 * or the device, but there is no other way to test
1542 /* num stats for the tested port. CQ size adds more stats to a port */
1543 #define NUM_PORT_STATS 21
1544 /* the port to test. */
1546 num_stats = rte_event_dev_xstats_names_get(evdev,
1547 RTE_EVENT_DEV_XSTATS_PORT, PORT,
1548 xstats_names, ids, XSTATS_MAX);
1549 if (num_stats != NUM_PORT_STATS) {
1550 printf("%d: expected %d stats, got return %d\n",
1551 __LINE__, NUM_PORT_STATS, num_stats);
1554 ret = rte_event_dev_xstats_get(evdev, RTE_EVENT_DEV_XSTATS_PORT, PORT,
1555 ids, values, num_stats);
1557 if (ret != NUM_PORT_STATS) {
1558 printf("%d: expected %d stats, got return %d\n",
1559 __LINE__, NUM_PORT_STATS, ret);
1562 static const char * const port_names[] = {
1567 "port_2_avg_pkt_cycles",
1569 "port_2_rx_ring_used",
1570 "port_2_rx_ring_free",
1571 "port_2_cq_ring_used",
1572 "port_2_cq_ring_free",
1573 "port_2_dequeue_calls",
1574 "port_2_dequeues_returning_0",
1575 "port_2_dequeues_returning_1-4",
1576 "port_2_dequeues_returning_5-8",
1577 "port_2_dequeues_returning_9-12",
1578 "port_2_dequeues_returning_13-16",
1579 "port_2_dequeues_returning_17-20",
1580 "port_2_dequeues_returning_21-24",
1581 "port_2_dequeues_returning_25-28",
1582 "port_2_dequeues_returning_29-32",
1583 "port_2_dequeues_returning_33-36",
1585 uint64_t port_expected[] = {
1589 NPKTS, /* inflight */
1590 0, /* avg pkt cycles */
1592 0, /* rx ring used */
1593 4096, /* rx ring free */
1594 NPKTS, /* cq ring used */
1595 25, /* cq ring free */
1596 0, /* dequeue zero calls */
1597 0, 0, 0, 0, 0, /* 10 dequeue buckets */
1600 uint64_t port_expected_zero[] = {
1604 NPKTS, /* inflight */
1605 0, /* avg pkt cycles */
1607 0, /* rx ring used */
1608 4096, /* rx ring free */
1609 NPKTS, /* cq ring used */
1610 25, /* cq ring free */
1611 0, /* dequeue zero calls */
1612 0, 0, 0, 0, 0, /* 10 dequeue buckets */
1615 if (RTE_DIM(port_expected) != NUM_PORT_STATS ||
1616 RTE_DIM(port_names) != NUM_PORT_STATS) {
1617 printf("%d: port array of wrong size\n", __LINE__);
1622 for (i = 0; (int)i < ret; i++) {
1624 uint64_t val = rte_event_dev_xstats_by_name_get(evdev,
1627 if (id != i + PORT_OFF) {
1628 printf("%d: %s id incorrect, expected %d got %d\n",
1629 __LINE__, port_names[i], i+PORT_OFF,
1633 if (val != port_expected[i]) {
1634 printf("%d: %s value incorrect, expected %"PRIu64
1635 " got %d\n", __LINE__, port_names[i],
1636 port_expected[i], id);
1640 int reset_ret = rte_event_dev_xstats_reset(evdev,
1641 RTE_EVENT_DEV_XSTATS_PORT, PORT,
1645 printf("%d: failed to reset successfully\n", __LINE__);
1648 /* check value again */
1649 val = rte_event_dev_xstats_by_name_get(evdev, port_names[i], 0);
1650 if (val != port_expected_zero[i]) {
1651 printf("%d: %s value incorrect, expected %"PRIu64
1652 " got %"PRIu64"\n", __LINE__, port_names[i],
1653 port_expected_zero[i], val);
1660 /* num queue stats */
1661 #define NUM_Q_STATS 16
1662 /* queue offset from start of the devices whole xstats.
1663 * This will break every time we add a statistic to a device/port/queue
1665 #define QUEUE_OFF 90
1666 const uint32_t queue = 0;
1667 num_stats = rte_event_dev_xstats_names_get(evdev,
1668 RTE_EVENT_DEV_XSTATS_QUEUE, queue,
1669 xstats_names, ids, XSTATS_MAX);
1670 if (num_stats != NUM_Q_STATS) {
1671 printf("%d: expected %d stats, got return %d\n",
1672 __LINE__, NUM_Q_STATS, num_stats);
1675 ret = rte_event_dev_xstats_get(evdev, RTE_EVENT_DEV_XSTATS_QUEUE,
1676 queue, ids, values, num_stats);
1677 if (ret != NUM_Q_STATS) {
1678 printf("%d: expected 21 stats, got return %d\n", __LINE__, ret);
1681 static const char * const queue_names[] = {
1690 "qid_0_port_0_pinned_flows",
1691 "qid_0_port_0_packets",
1692 "qid_0_port_1_pinned_flows",
1693 "qid_0_port_1_packets",
1694 "qid_0_port_2_pinned_flows",
1695 "qid_0_port_2_packets",
1696 "qid_0_port_3_pinned_flows",
1697 "qid_0_port_3_packets",
1699 uint64_t queue_expected[] = {
1708 /* QID-to-Port: pinned_flows, packets */
1714 uint64_t queue_expected_zero[] = {
1723 /* QID-to-Port: pinned_flows, packets */
1729 if (RTE_DIM(queue_expected) != NUM_Q_STATS ||
1730 RTE_DIM(queue_expected_zero) != NUM_Q_STATS ||
1731 RTE_DIM(queue_names) != NUM_Q_STATS) {
1732 printf("%d : queue array of wrong size\n", __LINE__);
1737 for (i = 0; (int)i < ret; i++) {
1739 uint64_t val = rte_event_dev_xstats_by_name_get(evdev,
1742 if (id != i + QUEUE_OFF) {
1743 printf("%d: %s id incorrect, expected %d got %d\n",
1744 __LINE__, queue_names[i], i+QUEUE_OFF,
1748 if (val != queue_expected[i]) {
1749 printf("%d: %d: %s value , expected %"PRIu64
1750 " got %"PRIu64"\n", i, __LINE__,
1751 queue_names[i], queue_expected[i], val);
1755 int reset_ret = rte_event_dev_xstats_reset(evdev,
1756 RTE_EVENT_DEV_XSTATS_QUEUE,
1759 printf("%d: failed to reset successfully\n", __LINE__);
1762 /* check value again */
1763 val = rte_event_dev_xstats_by_name_get(evdev, queue_names[i],
1765 if (val != queue_expected_zero[i]) {
1766 printf("%d: %s value incorrect, expected %"PRIu64
1767 " got %"PRIu64"\n", __LINE__, queue_names[i],
1768 queue_expected_zero[i], val);
1784 ordered_reconfigure(struct test *t)
1786 if (init(t, 1, 1) < 0 ||
1787 create_ports(t, 1) < 0) {
1788 printf("%d: Error initializing device\n", __LINE__);
1792 const struct rte_event_queue_conf conf = {
1793 .schedule_type = RTE_SCHED_TYPE_ORDERED,
1794 .priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
1795 .nb_atomic_flows = 1024,
1796 .nb_atomic_order_sequences = 1024,
1799 if (rte_event_queue_setup(evdev, 0, &conf) < 0) {
1800 printf("%d: error creating qid\n", __LINE__);
1804 if (rte_event_queue_setup(evdev, 0, &conf) < 0) {
1805 printf("%d: error creating qid, for 2nd time\n", __LINE__);
1809 rte_event_port_link(evdev, t->port[0], NULL, NULL, 0);
1810 if (rte_event_dev_start(evdev) < 0) {
1811 printf("%d: Error with start call\n", __LINE__);
1823 qid_priorities(struct test *t)
1825 /* Test works by having a CQ with enough empty space for all packets,
1826 * and enqueueing 3 packets to 3 QIDs. They must return based on the
1827 * priority of the QID, not the ingress order, to pass the test
1830 /* Create instance with 1 ports, and 3 qids */
1831 if (init(t, 3, 1) < 0 ||
1832 create_ports(t, 1) < 0) {
1833 printf("%d: Error initializing device\n", __LINE__);
1837 for (i = 0; i < 3; i++) {
1839 const struct rte_event_queue_conf conf = {
1840 .schedule_type = RTE_SCHED_TYPE_ATOMIC,
1841 /* increase priority (0 == highest), as we go */
1842 .priority = RTE_EVENT_DEV_PRIORITY_NORMAL - i,
1843 .nb_atomic_flows = 1024,
1844 .nb_atomic_order_sequences = 1024,
1847 if (rte_event_queue_setup(evdev, i, &conf) < 0) {
1848 printf("%d: error creating qid %d\n", __LINE__, i);
1854 /* map all QIDs to port */
1855 rte_event_port_link(evdev, t->port[0], NULL, NULL, 0);
1857 if (rte_event_dev_start(evdev) < 0) {
1858 printf("%d: Error with start call\n", __LINE__);
1862 /* enqueue 3 packets, setting seqn and QID to check priority */
1863 for (i = 0; i < 3; i++) {
1864 struct rte_event ev;
1865 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
1867 printf("%d: gen of pkt failed\n", __LINE__);
1870 ev.queue_id = t->qid[i];
1871 ev.op = RTE_EVENT_OP_NEW;
1875 int err = rte_event_enqueue_burst(evdev, t->port[0], &ev, 1);
1877 printf("%d: Failed to enqueue\n", __LINE__);
1882 rte_service_run_iter_on_app_lcore(t->service_id, 1);
1884 /* dequeue packets, verify priority was upheld */
1885 struct rte_event ev[32];
1887 rte_event_dequeue_burst(evdev, t->port[0], ev, 32, 0);
1888 if (deq_pkts != 3) {
1889 printf("%d: failed to deq packets\n", __LINE__);
1890 rte_event_dev_dump(evdev, stdout);
1893 for (i = 0; i < 3; i++) {
1894 if (ev[i].mbuf->seqn != 2-i) {
1896 "%d: qid priority test: seqn %d incorrectly prioritized\n",
1906 load_balancing(struct test *t)
1908 const int rx_enq = 0;
1912 if (init(t, 1, 4) < 0 ||
1913 create_ports(t, 4) < 0 ||
1914 create_atomic_qids(t, 1) < 0) {
1915 printf("%d: Error initializing device\n", __LINE__);
1919 for (i = 0; i < 3; i++) {
1920 /* map port 1 - 3 inclusive */
1921 if (rte_event_port_link(evdev, t->port[i+1], &t->qid[0],
1923 printf("%d: error mapping qid to port %d\n",
1929 if (rte_event_dev_start(evdev) < 0) {
1930 printf("%d: Error with start call\n", __LINE__);
1934 /************** FORWARD ****************/
1936 * Create a set of flows that test the load-balancing operation of the
1937 * implementation. Fill CQ 0 and 1 with flows 0 and 1, and test
1938 * with a new flow, which should be sent to the 3rd mapped CQ
1940 static uint32_t flows[] = {0, 1, 1, 0, 0, 2, 2, 0, 2};
1942 for (i = 0; i < RTE_DIM(flows); i++) {
1943 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
1945 printf("%d: gen of pkt failed\n", __LINE__);
1949 struct rte_event ev = {
1950 .op = RTE_EVENT_OP_NEW,
1951 .queue_id = t->qid[0],
1952 .flow_id = flows[i],
1955 /* generate pkt and enqueue */
1956 err = rte_event_enqueue_burst(evdev, t->port[rx_enq], &ev, 1);
1958 printf("%d: Failed to enqueue\n", __LINE__);
1963 rte_service_run_iter_on_app_lcore(t->service_id, 1);
1965 struct test_event_dev_stats stats;
1966 err = test_event_dev_stats_get(evdev, &stats);
1968 printf("%d: failed to get stats\n", __LINE__);
1972 if (stats.port_inflight[1] != 4) {
1973 printf("%d:%s: port 1 inflight not correct\n", __LINE__,
1977 if (stats.port_inflight[2] != 2) {
1978 printf("%d:%s: port 2 inflight not correct\n", __LINE__,
1982 if (stats.port_inflight[3] != 3) {
1983 printf("%d:%s: port 3 inflight not correct\n", __LINE__,
1993 load_balancing_history(struct test *t)
1995 struct test_event_dev_stats stats = {0};
1996 const int rx_enq = 0;
2000 /* Create instance with 1 atomic QID going to 3 ports + 1 prod port */
2001 if (init(t, 1, 4) < 0 ||
2002 create_ports(t, 4) < 0 ||
2003 create_atomic_qids(t, 1) < 0)
2006 /* CQ mapping to QID */
2007 if (rte_event_port_link(evdev, t->port[1], &t->qid[0], NULL, 1) != 1) {
2008 printf("%d: error mapping port 1 qid\n", __LINE__);
2011 if (rte_event_port_link(evdev, t->port[2], &t->qid[0], NULL, 1) != 1) {
2012 printf("%d: error mapping port 2 qid\n", __LINE__);
2015 if (rte_event_port_link(evdev, t->port[3], &t->qid[0], NULL, 1) != 1) {
2016 printf("%d: error mapping port 3 qid\n", __LINE__);
2019 if (rte_event_dev_start(evdev) < 0) {
2020 printf("%d: Error with start call\n", __LINE__);
2025 * Create a set of flows that test the load-balancing operation of the
2026 * implementation. Fill CQ 0, 1 and 2 with flows 0, 1 and 2, drop
2027 * the packet from CQ 0, send in a new set of flows. Ensure that:
2028 * 1. The new flow 3 gets into the empty CQ0
2029 * 2. packets for existing flow gets added into CQ1
2030 * 3. Next flow 0 pkt is now onto CQ2, since CQ0 and CQ1 now contain
2031 * more outstanding pkts
2033 * This test makes sure that when a flow ends (i.e. all packets
2034 * have been completed for that flow), that the flow can be moved
2035 * to a different CQ when new packets come in for that flow.
2037 static uint32_t flows1[] = {0, 1, 1, 2};
2039 for (i = 0; i < RTE_DIM(flows1); i++) {
2040 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
2041 struct rte_event ev = {
2042 .flow_id = flows1[i],
2043 .op = RTE_EVENT_OP_NEW,
2044 .queue_id = t->qid[0],
2045 .event_type = RTE_EVENT_TYPE_CPU,
2046 .priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
2051 printf("%d: gen of pkt failed\n", __LINE__);
2054 arp->hash.rss = flows1[i];
2055 err = rte_event_enqueue_burst(evdev, t->port[rx_enq], &ev, 1);
2057 printf("%d: Failed to enqueue\n", __LINE__);
2062 /* call the scheduler */
2063 rte_service_run_iter_on_app_lcore(t->service_id, 1);
2065 /* Dequeue the flow 0 packet from port 1, so that we can then drop */
2066 struct rte_event ev;
2067 if (!rte_event_dequeue_burst(evdev, t->port[1], &ev, 1, 0)) {
2068 printf("%d: failed to dequeue\n", __LINE__);
2071 if (ev.mbuf->hash.rss != flows1[0]) {
2072 printf("%d: unexpected flow received\n", __LINE__);
2076 /* drop the flow 0 packet from port 1 */
2077 rte_event_enqueue_burst(evdev, t->port[1], &release_ev, 1);
2079 /* call the scheduler */
2080 rte_service_run_iter_on_app_lcore(t->service_id, 1);
2083 * Set up the next set of flows, first a new flow to fill up
2084 * CQ 0, so that the next flow 0 packet should go to CQ2
2086 static uint32_t flows2[] = { 3, 3, 3, 1, 1, 0 };
2088 for (i = 0; i < RTE_DIM(flows2); i++) {
2089 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
2090 struct rte_event ev = {
2091 .flow_id = flows2[i],
2092 .op = RTE_EVENT_OP_NEW,
2093 .queue_id = t->qid[0],
2094 .event_type = RTE_EVENT_TYPE_CPU,
2095 .priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
2100 printf("%d: gen of pkt failed\n", __LINE__);
2103 arp->hash.rss = flows2[i];
2105 err = rte_event_enqueue_burst(evdev, t->port[rx_enq], &ev, 1);
2107 printf("%d: Failed to enqueue\n", __LINE__);
2113 rte_service_run_iter_on_app_lcore(t->service_id, 1);
2115 err = test_event_dev_stats_get(evdev, &stats);
2117 printf("%d:failed to get stats\n", __LINE__);
2122 * Now check the resulting inflights on each port.
2124 if (stats.port_inflight[1] != 3) {
2125 printf("%d:%s: port 1 inflight not correct\n", __LINE__,
2127 printf("Inflights, ports 1, 2, 3: %u, %u, %u\n",
2128 (unsigned int)stats.port_inflight[1],
2129 (unsigned int)stats.port_inflight[2],
2130 (unsigned int)stats.port_inflight[3]);
2133 if (stats.port_inflight[2] != 4) {
2134 printf("%d:%s: port 2 inflight not correct\n", __LINE__,
2136 printf("Inflights, ports 1, 2, 3: %u, %u, %u\n",
2137 (unsigned int)stats.port_inflight[1],
2138 (unsigned int)stats.port_inflight[2],
2139 (unsigned int)stats.port_inflight[3]);
2142 if (stats.port_inflight[3] != 2) {
2143 printf("%d:%s: port 3 inflight not correct\n", __LINE__,
2145 printf("Inflights, ports 1, 2, 3: %u, %u, %u\n",
2146 (unsigned int)stats.port_inflight[1],
2147 (unsigned int)stats.port_inflight[2],
2148 (unsigned int)stats.port_inflight[3]);
2152 for (i = 1; i <= 3; i++) {
2153 struct rte_event ev;
2154 while (rte_event_dequeue_burst(evdev, i, &ev, 1, 0))
2155 rte_event_enqueue_burst(evdev, i, &release_ev, 1);
2157 rte_service_run_iter_on_app_lcore(t->service_id, 1);
2164 invalid_qid(struct test *t)
2166 struct test_event_dev_stats stats;
2167 const int rx_enq = 0;
2171 if (init(t, 1, 4) < 0 ||
2172 create_ports(t, 4) < 0 ||
2173 create_atomic_qids(t, 1) < 0) {
2174 printf("%d: Error initializing device\n", __LINE__);
2178 /* CQ mapping to QID */
2179 for (i = 0; i < 4; i++) {
2180 err = rte_event_port_link(evdev, t->port[i], &t->qid[0],
2183 printf("%d: error mapping port 1 qid\n", __LINE__);
2188 if (rte_event_dev_start(evdev) < 0) {
2189 printf("%d: Error with start call\n", __LINE__);
2194 * Send in a packet with an invalid qid to the scheduler.
2195 * We should see the packed enqueued OK, but the inflights for
2196 * that packet should not be incremented, and the rx_dropped
2197 * should be incremented.
2199 static uint32_t flows1[] = {20};
2201 for (i = 0; i < RTE_DIM(flows1); i++) {
2202 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
2204 printf("%d: gen of pkt failed\n", __LINE__);
2208 struct rte_event ev = {
2209 .op = RTE_EVENT_OP_NEW,
2210 .queue_id = t->qid[0] + flows1[i],
2214 /* generate pkt and enqueue */
2215 err = rte_event_enqueue_burst(evdev, t->port[rx_enq], &ev, 1);
2217 printf("%d: Failed to enqueue\n", __LINE__);
2222 /* call the scheduler */
2223 rte_service_run_iter_on_app_lcore(t->service_id, 1);
2225 err = test_event_dev_stats_get(evdev, &stats);
2227 printf("%d: failed to get stats\n", __LINE__);
2232 * Now check the resulting inflights on the port, and the rx_dropped.
2234 if (stats.port_inflight[0] != 0) {
2235 printf("%d:%s: port 1 inflight count not correct\n", __LINE__,
2237 rte_event_dev_dump(evdev, stdout);
2240 if (stats.port_rx_dropped[0] != 1) {
2241 printf("%d:%s: port 1 drops\n", __LINE__, __func__);
2242 rte_event_dev_dump(evdev, stdout);
2245 /* each packet drop should only be counted in one place - port or dev */
2246 if (stats.rx_dropped != 0) {
2247 printf("%d:%s: port 1 dropped count not correct\n", __LINE__,
2249 rte_event_dev_dump(evdev, stdout);
2258 single_packet(struct test *t)
2260 const uint32_t MAGIC_SEQN = 7321;
2261 struct rte_event ev;
2262 struct test_event_dev_stats stats;
2263 const int rx_enq = 0;
2264 const int wrk_enq = 2;
2267 /* Create instance with 4 ports */
2268 if (init(t, 1, 4) < 0 ||
2269 create_ports(t, 4) < 0 ||
2270 create_atomic_qids(t, 1) < 0) {
2271 printf("%d: Error initializing device\n", __LINE__);
2275 /* CQ mapping to QID */
2276 err = rte_event_port_link(evdev, t->port[wrk_enq], NULL, NULL, 0);
2278 printf("%d: error mapping lb qid\n", __LINE__);
2283 if (rte_event_dev_start(evdev) < 0) {
2284 printf("%d: Error with start call\n", __LINE__);
2288 /************** Gen pkt and enqueue ****************/
2289 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
2291 printf("%d: gen of pkt failed\n", __LINE__);
2295 ev.op = RTE_EVENT_OP_NEW;
2296 ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL;
2300 arp->seqn = MAGIC_SEQN;
2302 err = rte_event_enqueue_burst(evdev, t->port[rx_enq], &ev, 1);
2304 printf("%d: Failed to enqueue\n", __LINE__);
2308 rte_service_run_iter_on_app_lcore(t->service_id, 1);
2310 err = test_event_dev_stats_get(evdev, &stats);
2312 printf("%d: failed to get stats\n", __LINE__);
2316 if (stats.rx_pkts != 1 ||
2317 stats.tx_pkts != 1 ||
2318 stats.port_inflight[wrk_enq] != 1) {
2319 printf("%d: Sched core didn't handle pkt as expected\n",
2321 rte_event_dev_dump(evdev, stdout);
2327 deq_pkts = rte_event_dequeue_burst(evdev, t->port[wrk_enq], &ev, 1, 0);
2329 printf("%d: Failed to deq\n", __LINE__);
2333 err = test_event_dev_stats_get(evdev, &stats);
2335 printf("%d: failed to get stats\n", __LINE__);
2339 err = test_event_dev_stats_get(evdev, &stats);
2340 if (ev.mbuf->seqn != MAGIC_SEQN) {
2341 printf("%d: magic sequence number not dequeued\n", __LINE__);
2345 rte_pktmbuf_free(ev.mbuf);
2346 err = rte_event_enqueue_burst(evdev, t->port[wrk_enq], &release_ev, 1);
2348 printf("%d: Failed to enqueue\n", __LINE__);
2351 rte_service_run_iter_on_app_lcore(t->service_id, 1);
2353 err = test_event_dev_stats_get(evdev, &stats);
2354 if (stats.port_inflight[wrk_enq] != 0) {
2355 printf("%d: port inflight not correct\n", __LINE__);
2364 inflight_counts(struct test *t)
2366 struct rte_event ev;
2367 struct test_event_dev_stats stats;
2368 const int rx_enq = 0;
2374 /* Create instance with 4 ports */
2375 if (init(t, 2, 3) < 0 ||
2376 create_ports(t, 3) < 0 ||
2377 create_atomic_qids(t, 2) < 0) {
2378 printf("%d: Error initializing device\n", __LINE__);
2382 /* CQ mapping to QID */
2383 err = rte_event_port_link(evdev, t->port[p1], &t->qid[0], NULL, 1);
2385 printf("%d: error mapping lb qid\n", __LINE__);
2389 err = rte_event_port_link(evdev, t->port[p2], &t->qid[1], NULL, 1);
2391 printf("%d: error mapping lb qid\n", __LINE__);
2396 if (rte_event_dev_start(evdev) < 0) {
2397 printf("%d: Error with start call\n", __LINE__);
2401 /************** FORWARD ****************/
2403 for (i = 0; i < QID1_NUM; i++) {
2404 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
2407 printf("%d: gen of pkt failed\n", __LINE__);
2411 ev.queue_id = t->qid[0];
2412 ev.op = RTE_EVENT_OP_NEW;
2414 err = rte_event_enqueue_burst(evdev, t->port[rx_enq], &ev, 1);
2416 printf("%d: Failed to enqueue\n", __LINE__);
2421 for (i = 0; i < QID2_NUM; i++) {
2422 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
2425 printf("%d: gen of pkt failed\n", __LINE__);
2428 ev.queue_id = t->qid[1];
2429 ev.op = RTE_EVENT_OP_NEW;
2431 err = rte_event_enqueue_burst(evdev, t->port[rx_enq], &ev, 1);
2433 printf("%d: Failed to enqueue\n", __LINE__);
2439 rte_service_run_iter_on_app_lcore(t->service_id, 1);
2441 err = test_event_dev_stats_get(evdev, &stats);
2443 printf("%d: failed to get stats\n", __LINE__);
2447 if (stats.rx_pkts != QID1_NUM + QID2_NUM ||
2448 stats.tx_pkts != QID1_NUM + QID2_NUM) {
2449 printf("%d: Sched core didn't handle pkt as expected\n",
2454 if (stats.port_inflight[p1] != QID1_NUM) {
2455 printf("%d: %s port 1 inflight not correct\n", __LINE__,
2459 if (stats.port_inflight[p2] != QID2_NUM) {
2460 printf("%d: %s port 2 inflight not correct\n", __LINE__,
2465 /************** DEQUEUE INFLIGHT COUNT CHECKS ****************/
2467 struct rte_event events[QID1_NUM + QID2_NUM];
2468 uint32_t deq_pkts = rte_event_dequeue_burst(evdev, t->port[p1], events,
2469 RTE_DIM(events), 0);
2471 if (deq_pkts != QID1_NUM) {
2472 printf("%d: Port 1: DEQUEUE inflight failed\n", __LINE__);
2475 err = test_event_dev_stats_get(evdev, &stats);
2476 if (stats.port_inflight[p1] != QID1_NUM) {
2477 printf("%d: port 1 inflight decrement after DEQ != 0\n",
2481 for (i = 0; i < QID1_NUM; i++) {
2482 err = rte_event_enqueue_burst(evdev, t->port[p1], &release_ev,
2485 printf("%d: %s rte enqueue of inf release failed\n",
2486 __LINE__, __func__);
2492 * As the scheduler core decrements inflights, it needs to run to
2493 * process packets to act on the drop messages
2495 rte_service_run_iter_on_app_lcore(t->service_id, 1);
2497 err = test_event_dev_stats_get(evdev, &stats);
2498 if (stats.port_inflight[p1] != 0) {
2499 printf("%d: port 1 inflight NON NULL after DROP\n", __LINE__);
2504 deq_pkts = rte_event_dequeue_burst(evdev, t->port[p2], events,
2505 RTE_DIM(events), 0);
2506 if (deq_pkts != QID2_NUM) {
2507 printf("%d: Port 2: DEQUEUE inflight failed\n", __LINE__);
2510 err = test_event_dev_stats_get(evdev, &stats);
2511 if (stats.port_inflight[p2] != QID2_NUM) {
2512 printf("%d: port 1 inflight decrement after DEQ != 0\n",
2516 for (i = 0; i < QID2_NUM; i++) {
2517 err = rte_event_enqueue_burst(evdev, t->port[p2], &release_ev,
2520 printf("%d: %s rte enqueue of inf release failed\n",
2521 __LINE__, __func__);
2527 * As the scheduler core decrements inflights, it needs to run to
2528 * process packets to act on the drop messages
2530 rte_service_run_iter_on_app_lcore(t->service_id, 1);
2532 err = test_event_dev_stats_get(evdev, &stats);
2533 if (stats.port_inflight[p2] != 0) {
2534 printf("%d: port 2 inflight NON NULL after DROP\n", __LINE__);
2541 rte_event_dev_dump(evdev, stdout);
2547 parallel_basic(struct test *t, int check_order)
2549 const uint8_t rx_port = 0;
2550 const uint8_t w1_port = 1;
2551 const uint8_t w3_port = 3;
2552 const uint8_t tx_port = 4;
2555 uint32_t deq_pkts, j;
2556 struct rte_mbuf *mbufs[3];
2557 struct rte_mbuf *mbufs_out[3] = { 0 };
2558 const uint32_t MAGIC_SEQN = 1234;
2560 /* Create instance with 4 ports */
2561 if (init(t, 2, tx_port + 1) < 0 ||
2562 create_ports(t, tx_port + 1) < 0 ||
2563 (check_order ? create_ordered_qids(t, 1) :
2564 create_unordered_qids(t, 1)) < 0 ||
2565 create_directed_qids(t, 1, &tx_port)) {
2566 printf("%d: Error initializing device\n", __LINE__);
2572 * We need three ports, all mapped to the same ordered qid0. Then we'll
2573 * take a packet out to each port, re-enqueue in reverse order,
2574 * then make sure the reordering has taken place properly when we
2575 * dequeue from the tx_port.
2577 * Simplified test setup diagram:
2581 * qid0 - w2_port - qid1
2585 /* CQ mapping to QID for LB ports (directed mapped on create) */
2586 for (i = w1_port; i <= w3_port; i++) {
2587 err = rte_event_port_link(evdev, t->port[i], &t->qid[0], NULL,
2590 printf("%d: error mapping lb qid\n", __LINE__);
2596 if (rte_event_dev_start(evdev) < 0) {
2597 printf("%d: Error with start call\n", __LINE__);
2601 /* Enqueue 3 packets to the rx port */
2602 for (i = 0; i < 3; i++) {
2603 struct rte_event ev;
2604 mbufs[i] = rte_gen_arp(0, t->mbuf_pool);
2606 printf("%d: gen of pkt failed\n", __LINE__);
2610 ev.queue_id = t->qid[0];
2611 ev.op = RTE_EVENT_OP_NEW;
2613 mbufs[i]->seqn = MAGIC_SEQN + i;
2615 /* generate pkt and enqueue */
2616 err = rte_event_enqueue_burst(evdev, t->port[rx_port], &ev, 1);
2618 printf("%d: Failed to enqueue pkt %u, retval = %u\n",
2624 rte_service_run_iter_on_app_lcore(t->service_id, 1);
2626 /* use extra slot to make logic in loops easier */
2627 struct rte_event deq_ev[w3_port + 1];
2629 /* Dequeue the 3 packets, one from each worker port */
2630 for (i = w1_port; i <= w3_port; i++) {
2631 deq_pkts = rte_event_dequeue_burst(evdev, t->port[i],
2633 if (deq_pkts != 1) {
2634 printf("%d: Failed to deq\n", __LINE__);
2635 rte_event_dev_dump(evdev, stdout);
2640 /* Enqueue each packet in reverse order, flushing after each one */
2641 for (i = w3_port; i >= w1_port; i--) {
2643 deq_ev[i].op = RTE_EVENT_OP_FORWARD;
2644 deq_ev[i].queue_id = t->qid[1];
2645 err = rte_event_enqueue_burst(evdev, t->port[i], &deq_ev[i], 1);
2647 printf("%d: Failed to enqueue\n", __LINE__);
2651 rte_service_run_iter_on_app_lcore(t->service_id, 1);
2653 /* dequeue from the tx ports, we should get 3 packets */
2654 deq_pkts = rte_event_dequeue_burst(evdev, t->port[tx_port], deq_ev,
2657 /* Check to see if we've got all 3 packets */
2658 if (deq_pkts != 3) {
2659 printf("%d: expected 3 pkts at tx port got %d from port %d\n",
2660 __LINE__, deq_pkts, tx_port);
2661 rte_event_dev_dump(evdev, stdout);
2665 /* Check to see if the sequence numbers are in expected order */
2667 for (j = 0 ; j < deq_pkts ; j++) {
2668 if (deq_ev[j].mbuf->seqn != MAGIC_SEQN + j) {
2670 "%d: Incorrect sequence number(%d) from port %d\n",
2671 __LINE__, mbufs_out[j]->seqn, tx_port);
2677 /* Destroy the instance */
2683 ordered_basic(struct test *t)
2685 return parallel_basic(t, 1);
2689 unordered_basic(struct test *t)
2691 return parallel_basic(t, 0);
2695 holb(struct test *t) /* test to check we avoid basic head-of-line blocking */
2697 const struct rte_event new_ev = {
2698 .op = RTE_EVENT_OP_NEW
2699 /* all other fields zero */
2701 struct rte_event ev = new_ev;
2702 unsigned int rx_port = 0; /* port we get the first flow on */
2703 char rx_port_used_stat[64];
2704 char rx_port_free_stat[64];
2705 char other_port_used_stat[64];
2707 if (init(t, 1, 2) < 0 ||
2708 create_ports(t, 2) < 0 ||
2709 create_atomic_qids(t, 1) < 0) {
2710 printf("%d: Error initializing device\n", __LINE__);
2713 int nb_links = rte_event_port_link(evdev, t->port[1], NULL, NULL, 0);
2714 if (rte_event_port_link(evdev, t->port[0], NULL, NULL, 0) != 1 ||
2716 printf("%d: Error links queue to ports\n", __LINE__);
2719 if (rte_event_dev_start(evdev) < 0) {
2720 printf("%d: Error with start call\n", __LINE__);
2724 /* send one packet and see where it goes, port 0 or 1 */
2725 if (rte_event_enqueue_burst(evdev, t->port[0], &ev, 1) != 1) {
2726 printf("%d: Error doing first enqueue\n", __LINE__);
2729 rte_service_run_iter_on_app_lcore(t->service_id, 1);
2731 if (rte_event_dev_xstats_by_name_get(evdev, "port_0_cq_ring_used", NULL)
2735 snprintf(rx_port_used_stat, sizeof(rx_port_used_stat),
2736 "port_%u_cq_ring_used", rx_port);
2737 snprintf(rx_port_free_stat, sizeof(rx_port_free_stat),
2738 "port_%u_cq_ring_free", rx_port);
2739 snprintf(other_port_used_stat, sizeof(other_port_used_stat),
2740 "port_%u_cq_ring_used", rx_port ^ 1);
2741 if (rte_event_dev_xstats_by_name_get(evdev, rx_port_used_stat, NULL)
2743 printf("%d: Error, first event not scheduled\n", __LINE__);
2747 /* now fill up the rx port's queue with one flow to cause HOLB */
2750 if (rte_event_enqueue_burst(evdev, t->port[0], &ev, 1) != 1) {
2751 printf("%d: Error with enqueue\n", __LINE__);
2754 rte_service_run_iter_on_app_lcore(t->service_id, 1);
2755 } while (rte_event_dev_xstats_by_name_get(evdev,
2756 rx_port_free_stat, NULL) != 0);
2758 /* one more packet, which needs to stay in IQ - i.e. HOLB */
2760 if (rte_event_enqueue_burst(evdev, t->port[0], &ev, 1) != 1) {
2761 printf("%d: Error with enqueue\n", __LINE__);
2764 rte_service_run_iter_on_app_lcore(t->service_id, 1);
2766 /* check that the other port still has an empty CQ */
2767 if (rte_event_dev_xstats_by_name_get(evdev, other_port_used_stat, NULL)
2769 printf("%d: Error, second port CQ is not empty\n", __LINE__);
2772 /* check IQ now has one packet */
2773 if (rte_event_dev_xstats_by_name_get(evdev, "qid_0_iq_0_used", NULL)
2775 printf("%d: Error, QID does not have exactly 1 packet\n",
2780 /* send another flow, which should pass the other IQ entry */
2783 if (rte_event_enqueue_burst(evdev, t->port[0], &ev, 1) != 1) {
2784 printf("%d: Error with enqueue\n", __LINE__);
2787 rte_service_run_iter_on_app_lcore(t->service_id, 1);
2789 if (rte_event_dev_xstats_by_name_get(evdev, other_port_used_stat, NULL)
2791 printf("%d: Error, second flow did not pass out first\n",
2796 if (rte_event_dev_xstats_by_name_get(evdev, "qid_0_iq_0_used", NULL)
2798 printf("%d: Error, QID does not have exactly 1 packet\n",
2805 rte_event_dev_dump(evdev, stdout);
2811 worker_loopback_worker_fn(void *arg)
2813 struct test *t = arg;
2814 uint8_t port = t->port[1];
2819 * Takes packets from the input port and then loops them back through
2820 * the Eventdev. Each packet gets looped through QIDs 0-8, 16 times
2821 * so each packet goes through 8*16 = 128 times.
2823 printf("%d: \tWorker function started\n", __LINE__);
2824 while (count < NUM_PACKETS) {
2825 #define BURST_SIZE 32
2826 struct rte_event ev[BURST_SIZE];
2827 uint16_t i, nb_rx = rte_event_dequeue_burst(evdev, port, ev,
2834 for (i = 0; i < nb_rx; i++) {
2836 if (ev[i].queue_id != 8) {
2837 ev[i].op = RTE_EVENT_OP_FORWARD;
2838 enqd = rte_event_enqueue_burst(evdev, port,
2841 printf("%d: Can't enqueue FWD!!\n",
2849 ev[i].mbuf->udata64++;
2850 if (ev[i].mbuf->udata64 != 16) {
2851 ev[i].op = RTE_EVENT_OP_FORWARD;
2852 enqd = rte_event_enqueue_burst(evdev, port,
2855 printf("%d: Can't enqueue FWD!!\n",
2861 /* we have hit 16 iterations through system - drop */
2862 rte_pktmbuf_free(ev[i].mbuf);
2864 ev[i].op = RTE_EVENT_OP_RELEASE;
2865 enqd = rte_event_enqueue_burst(evdev, port, &ev[i], 1);
2867 printf("%d drop enqueue failed\n", __LINE__);
2877 worker_loopback_producer_fn(void *arg)
2879 struct test *t = arg;
2880 uint8_t port = t->port[0];
2883 printf("%d: \tProducer function started\n", __LINE__);
2884 while (count < NUM_PACKETS) {
2885 struct rte_mbuf *m = 0;
2887 m = rte_pktmbuf_alloc(t->mbuf_pool);
2888 } while (m == NULL);
2892 struct rte_event ev = {
2893 .op = RTE_EVENT_OP_NEW,
2894 .queue_id = t->qid[0],
2895 .flow_id = (uintptr_t)m & 0xFFFF,
2899 if (rte_event_enqueue_burst(evdev, port, &ev, 1) != 1) {
2900 while (rte_event_enqueue_burst(evdev, port, &ev, 1) !=
2912 worker_loopback(struct test *t, uint8_t disable_implicit_release)
2914 /* use a single producer core, and a worker core to see what happens
2915 * if the worker loops packets back multiple times
2917 struct test_event_dev_stats stats;
2918 uint64_t print_cycles = 0, cycles = 0;
2919 uint64_t tx_pkts = 0;
2921 int w_lcore, p_lcore;
2923 if (init(t, 8, 2) < 0 ||
2924 create_atomic_qids(t, 8) < 0) {
2925 printf("%d: Error initializing device\n", __LINE__);
2929 /* RX with low max events */
2930 static struct rte_event_port_conf conf = {
2931 .dequeue_depth = 32,
2932 .enqueue_depth = 64,
2934 /* beware: this cannot be initialized in the static above as it would
2935 * only be initialized once - and this needs to be set for multiple runs
2937 conf.new_event_threshold = 512;
2938 conf.disable_implicit_release = disable_implicit_release;
2940 if (rte_event_port_setup(evdev, 0, &conf) < 0) {
2941 printf("Error setting up RX port\n");
2945 /* TX with higher max events */
2946 conf.new_event_threshold = 4096;
2947 if (rte_event_port_setup(evdev, 1, &conf) < 0) {
2948 printf("Error setting up TX port\n");
2953 /* CQ mapping to QID */
2954 err = rte_event_port_link(evdev, t->port[1], NULL, NULL, 0);
2955 if (err != 8) { /* should have mapped all queues*/
2956 printf("%d: error mapping port 2 to all qids\n", __LINE__);
2960 if (rte_event_dev_start(evdev) < 0) {
2961 printf("%d: Error with start call\n", __LINE__);
2965 p_lcore = rte_get_next_lcore(
2966 /* start core */ -1,
2967 /* skip master */ 1,
2969 w_lcore = rte_get_next_lcore(p_lcore, 1, 0);
2971 rte_eal_remote_launch(worker_loopback_producer_fn, t, p_lcore);
2972 rte_eal_remote_launch(worker_loopback_worker_fn, t, w_lcore);
2974 print_cycles = cycles = rte_get_timer_cycles();
2975 while (rte_eal_get_lcore_state(p_lcore) != FINISHED ||
2976 rte_eal_get_lcore_state(w_lcore) != FINISHED) {
2978 rte_service_run_iter_on_app_lcore(t->service_id, 1);
2980 uint64_t new_cycles = rte_get_timer_cycles();
2982 if (new_cycles - print_cycles > rte_get_timer_hz()) {
2983 test_event_dev_stats_get(evdev, &stats);
2985 "%d: \tSched Rx = %"PRIu64", Tx = %"PRIu64"\n",
2986 __LINE__, stats.rx_pkts, stats.tx_pkts);
2988 print_cycles = new_cycles;
2990 if (new_cycles - cycles > rte_get_timer_hz() * 3) {
2991 test_event_dev_stats_get(evdev, &stats);
2992 if (stats.tx_pkts == tx_pkts) {
2993 rte_event_dev_dump(evdev, stdout);
2994 printf("Dumping xstats:\n");
2997 "%d: No schedules for seconds, deadlock\n",
3001 tx_pkts = stats.tx_pkts;
3002 cycles = new_cycles;
3005 rte_service_run_iter_on_app_lcore(t->service_id, 1);
3006 /* ensure all completions are flushed */
3008 rte_eal_mp_wait_lcore();
3014 static struct rte_mempool *eventdev_func_mempool;
3017 test_sw_eventdev(void)
3022 t = malloc(sizeof(struct test));
3025 /* manually initialize the op, older gcc's complain on static
3026 * initialization of struct elements that are a bitfield.
3028 release_ev.op = RTE_EVENT_OP_RELEASE;
3030 const char *eventdev_name = "event_sw";
3031 evdev = rte_event_dev_get_dev_id(eventdev_name);
3033 printf("%d: Eventdev %s not found - creating.\n",
3034 __LINE__, eventdev_name);
3035 if (rte_vdev_init(eventdev_name, NULL) < 0) {
3036 printf("Error creating eventdev\n");
3039 evdev = rte_event_dev_get_dev_id(eventdev_name);
3041 printf("Error finding newly created eventdev\n");
3046 if (rte_event_dev_service_id_get(evdev, &t->service_id) < 0) {
3047 printf("Failed to get service ID for software event dev\n");
3051 rte_service_runstate_set(t->service_id, 1);
3052 rte_service_set_runstate_mapped_check(t->service_id, 0);
3054 /* Only create mbuf pool once, reuse for each test run */
3055 if (!eventdev_func_mempool) {
3056 eventdev_func_mempool = rte_pktmbuf_pool_create(
3057 "EVENTDEV_SW_SA_MBUF_POOL",
3058 (1<<12), /* 4k buffers */
3059 32 /*MBUF_CACHE_SIZE*/,
3061 512, /* use very small mbufs */
3063 if (!eventdev_func_mempool) {
3064 printf("ERROR creating mempool\n");
3068 t->mbuf_pool = eventdev_func_mempool;
3069 printf("*** Running Single Directed Packet test...\n");
3070 ret = test_single_directed_packet(t);
3072 printf("ERROR - Single Directed Packet test FAILED.\n");
3075 printf("*** Running Directed Forward Credit test...\n");
3076 ret = test_directed_forward_credits(t);
3078 printf("ERROR - Directed Forward Credit test FAILED.\n");
3081 printf("*** Running Single Load Balanced Packet test...\n");
3082 ret = single_packet(t);
3084 printf("ERROR - Single Packet test FAILED.\n");
3087 printf("*** Running Unordered Basic test...\n");
3088 ret = unordered_basic(t);
3090 printf("ERROR - Unordered Basic test FAILED.\n");
3093 printf("*** Running Ordered Basic test...\n");
3094 ret = ordered_basic(t);
3096 printf("ERROR - Ordered Basic test FAILED.\n");
3099 printf("*** Running Burst Packets test...\n");
3100 ret = burst_packets(t);
3102 printf("ERROR - Burst Packets test FAILED.\n");
3105 printf("*** Running Load Balancing test...\n");
3106 ret = load_balancing(t);
3108 printf("ERROR - Load Balancing test FAILED.\n");
3111 printf("*** Running Prioritized Directed test...\n");
3112 ret = test_priority_directed(t);
3114 printf("ERROR - Prioritized Directed test FAILED.\n");
3117 printf("*** Running Prioritized Atomic test...\n");
3118 ret = test_priority_atomic(t);
3120 printf("ERROR - Prioritized Atomic test FAILED.\n");
3124 printf("*** Running Prioritized Ordered test...\n");
3125 ret = test_priority_ordered(t);
3127 printf("ERROR - Prioritized Ordered test FAILED.\n");
3130 printf("*** Running Prioritized Unordered test...\n");
3131 ret = test_priority_unordered(t);
3133 printf("ERROR - Prioritized Unordered test FAILED.\n");
3136 printf("*** Running Invalid QID test...\n");
3137 ret = invalid_qid(t);
3139 printf("ERROR - Invalid QID test FAILED.\n");
3142 printf("*** Running Load Balancing History test...\n");
3143 ret = load_balancing_history(t);
3145 printf("ERROR - Load Balancing History test FAILED.\n");
3148 printf("*** Running Inflight Count test...\n");
3149 ret = inflight_counts(t);
3151 printf("ERROR - Inflight Count test FAILED.\n");
3154 printf("*** Running Abuse Inflights test...\n");
3155 ret = abuse_inflights(t);
3157 printf("ERROR - Abuse Inflights test FAILED.\n");
3160 printf("*** Running XStats test...\n");
3161 ret = xstats_tests(t);
3163 printf("ERROR - XStats test FAILED.\n");
3166 printf("*** Running XStats ID Reset test...\n");
3167 ret = xstats_id_reset_tests(t);
3169 printf("ERROR - XStats ID Reset test FAILED.\n");
3172 printf("*** Running XStats Brute Force test...\n");
3173 ret = xstats_brute_force(t);
3175 printf("ERROR - XStats Brute Force test FAILED.\n");
3178 printf("*** Running XStats ID Abuse test...\n");
3179 ret = xstats_id_abuse_tests(t);
3181 printf("ERROR - XStats ID Abuse test FAILED.\n");
3184 printf("*** Running QID Priority test...\n");
3185 ret = qid_priorities(t);
3187 printf("ERROR - QID Priority test FAILED.\n");
3190 printf("*** Running Ordered Reconfigure test...\n");
3191 ret = ordered_reconfigure(t);
3193 printf("ERROR - Ordered Reconfigure test FAILED.\n");
3196 printf("*** Running Port LB Single Reconfig test...\n");
3197 ret = port_single_lb_reconfig(t);
3199 printf("ERROR - Port LB Single Reconfig test FAILED.\n");
3202 printf("*** Running Port Reconfig Credits test...\n");
3203 ret = port_reconfig_credits(t);
3205 printf("ERROR - Port Reconfig Credits Reset test FAILED.\n");
3208 printf("*** Running Head-of-line-blocking test...\n");
3211 printf("ERROR - Head-of-line-blocking test FAILED.\n");
3214 if (rte_lcore_count() >= 3) {
3215 printf("*** Running Worker loopback test...\n");
3216 ret = worker_loopback(t, 0);
3218 printf("ERROR - Worker loopback test FAILED.\n");
3222 printf("*** Running Worker loopback test (implicit release disabled)...\n");
3223 ret = worker_loopback(t, 1);
3225 printf("ERROR - Worker loopback test FAILED.\n");
3229 printf("### Not enough cores for worker loopback tests.\n");
3230 printf("### Need at least 3 cores for the tests.\n");
3234 * Free test instance, leaving mempool initialized, and a pointer to it
3235 * in static eventdev_func_mempool, as it is re-used on re-runs
3239 printf("SW Eventdev Selftest Successful.\n");
3243 printf("SW Eventdev Selftest Failed.\n");