4 * Copyright(c) 2016-2017 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 #include <sys/queue.h>
41 #include <rte_memory.h>
42 #include <rte_memzone.h>
43 #include <rte_launch.h>
45 #include <rte_per_lcore.h>
46 #include <rte_lcore.h>
47 #include <rte_debug.h>
48 #include <rte_ethdev.h>
49 #include <rte_cycles.h>
50 #include <rte_eventdev.h>
51 #include <rte_pause.h>
57 #define NUM_PACKETS (1<<18)
62 struct rte_mempool *mbuf_pool;
63 uint8_t port[MAX_PORTS];
64 uint8_t qid[MAX_QIDS];
68 static struct rte_event release_ev;
70 static inline struct rte_mbuf *
71 rte_gen_arp(int portid, struct rte_mempool *mp)
75 * ARP, Request who-has 10.0.0.1 tell 10.0.0.2, length 46
77 static const uint8_t arp_request[] = {
78 /*0x0000:*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xec, 0xa8,
79 0x6b, 0xfd, 0x02, 0x29, 0x08, 0x06, 0x00, 0x01,
80 /*0x0010:*/ 0x08, 0x00, 0x06, 0x04, 0x00, 0x01, 0xec, 0xa8,
81 0x6b, 0xfd, 0x02, 0x29, 0x0a, 0x00, 0x00, 0x01,
82 /*0x0020:*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00,
83 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
84 /*0x0030:*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
85 0x00, 0x00, 0x00, 0x00
88 int pkt_len = sizeof(arp_request) - 1;
90 m = rte_pktmbuf_alloc(mp);
94 memcpy((void *)((uintptr_t)m->buf_addr + m->data_off),
95 arp_request, pkt_len);
96 rte_pktmbuf_pkt_len(m) = pkt_len;
97 rte_pktmbuf_data_len(m) = pkt_len;
107 const uint32_t XSTATS_MAX = 1024;
109 uint32_t ids[XSTATS_MAX];
110 uint64_t values[XSTATS_MAX];
111 struct rte_event_dev_xstats_name xstats_names[XSTATS_MAX];
113 for (i = 0; i < XSTATS_MAX; i++)
116 /* Device names / values */
117 int ret = rte_event_dev_xstats_names_get(evdev,
118 RTE_EVENT_DEV_XSTATS_DEVICE, 0,
119 xstats_names, ids, XSTATS_MAX);
121 printf("%d: xstats names get() returned error\n",
125 ret = rte_event_dev_xstats_get(evdev,
126 RTE_EVENT_DEV_XSTATS_DEVICE,
127 0, ids, values, ret);
128 if (ret > (signed int)XSTATS_MAX)
129 printf("%s %d: more xstats available than space\n",
131 for (i = 0; (signed int)i < ret; i++) {
132 printf("%d : %s : %"PRIu64"\n",
133 i, xstats_names[i].name, values[i]);
136 /* Port names / values */
137 ret = rte_event_dev_xstats_names_get(evdev,
138 RTE_EVENT_DEV_XSTATS_PORT, 0,
139 xstats_names, ids, XSTATS_MAX);
140 ret = rte_event_dev_xstats_get(evdev,
141 RTE_EVENT_DEV_XSTATS_PORT, 1,
143 if (ret > (signed int)XSTATS_MAX)
144 printf("%s %d: more xstats available than space\n",
146 for (i = 0; (signed int)i < ret; i++) {
147 printf("%d : %s : %"PRIu64"\n",
148 i, xstats_names[i].name, values[i]);
151 /* Queue names / values */
152 ret = rte_event_dev_xstats_names_get(evdev,
153 RTE_EVENT_DEV_XSTATS_QUEUE, 0,
154 xstats_names, ids, XSTATS_MAX);
155 ret = rte_event_dev_xstats_get(evdev,
156 RTE_EVENT_DEV_XSTATS_QUEUE,
157 1, ids, values, ret);
158 if (ret > (signed int)XSTATS_MAX)
159 printf("%s %d: more xstats available than space\n",
161 for (i = 0; (signed int)i < ret; i++) {
162 printf("%d : %s : %"PRIu64"\n",
163 i, xstats_names[i].name, values[i]);
167 /* initialization and config */
169 init(struct test *t, int nb_queues, int nb_ports)
171 struct rte_event_dev_config config = {
172 .nb_event_queues = nb_queues,
173 .nb_event_ports = nb_ports,
174 .nb_event_queue_flows = 1024,
175 .nb_events_limit = 4096,
176 .nb_event_port_dequeue_depth = 128,
177 .nb_event_port_enqueue_depth = 128,
181 void *temp = t->mbuf_pool; /* save and restore mbuf pool */
183 memset(t, 0, sizeof(*t));
186 ret = rte_event_dev_configure(evdev, &config);
188 printf("%d: Error configuring device\n", __LINE__);
193 create_ports(struct test *t, int num_ports)
196 static const struct rte_event_port_conf conf = {
197 .new_event_threshold = 1024,
201 if (num_ports > MAX_PORTS)
204 for (i = 0; i < num_ports; i++) {
205 if (rte_event_port_setup(evdev, i, &conf) < 0) {
206 printf("Error setting up port %d\n", i);
216 create_lb_qids(struct test *t, int num_qids, uint32_t flags)
221 const struct rte_event_queue_conf conf = {
222 .event_queue_cfg = flags,
223 .priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
224 .nb_atomic_flows = 1024,
225 .nb_atomic_order_sequences = 1024,
228 for (i = t->nb_qids; i < t->nb_qids + num_qids; i++) {
229 if (rte_event_queue_setup(evdev, i, &conf) < 0) {
230 printf("%d: error creating qid %d\n", __LINE__, i);
235 t->nb_qids += num_qids;
236 if (t->nb_qids > MAX_QIDS)
243 create_atomic_qids(struct test *t, int num_qids)
245 return create_lb_qids(t, num_qids, RTE_EVENT_QUEUE_CFG_ATOMIC_ONLY);
249 create_ordered_qids(struct test *t, int num_qids)
251 return create_lb_qids(t, num_qids, RTE_EVENT_QUEUE_CFG_ORDERED_ONLY);
256 create_unordered_qids(struct test *t, int num_qids)
258 return create_lb_qids(t, num_qids, RTE_EVENT_QUEUE_CFG_PARALLEL_ONLY);
262 create_directed_qids(struct test *t, int num_qids, const uint8_t ports[])
267 static const struct rte_event_queue_conf conf = {
268 .priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
269 .event_queue_cfg = RTE_EVENT_QUEUE_CFG_SINGLE_LINK,
270 .nb_atomic_flows = 1024,
271 .nb_atomic_order_sequences = 1024,
274 for (i = t->nb_qids; i < t->nb_qids + num_qids; i++) {
275 if (rte_event_queue_setup(evdev, i, &conf) < 0) {
276 printf("%d: error creating qid %d\n", __LINE__, i);
281 if (rte_event_port_link(evdev, ports[i - t->nb_qids],
282 &t->qid[i], NULL, 1) != 1) {
283 printf("%d: error creating link for qid %d\n",
288 t->nb_qids += num_qids;
289 if (t->nb_qids > MAX_QIDS)
297 cleanup(struct test *t __rte_unused)
299 rte_event_dev_stop(evdev);
300 rte_event_dev_close(evdev);
304 struct test_event_dev_stats {
305 uint64_t rx_pkts; /**< Total packets received */
306 uint64_t rx_dropped; /**< Total packets dropped (Eg Invalid QID) */
307 uint64_t tx_pkts; /**< Total packets transmitted */
309 /** Packets received on this port */
310 uint64_t port_rx_pkts[MAX_PORTS];
311 /** Packets dropped on this port */
312 uint64_t port_rx_dropped[MAX_PORTS];
313 /** Packets inflight on this port */
314 uint64_t port_inflight[MAX_PORTS];
315 /** Packets transmitted on this port */
316 uint64_t port_tx_pkts[MAX_PORTS];
317 /** Packets received on this qid */
318 uint64_t qid_rx_pkts[MAX_QIDS];
319 /** Packets dropped on this qid */
320 uint64_t qid_rx_dropped[MAX_QIDS];
321 /** Packets transmitted on this qid */
322 uint64_t qid_tx_pkts[MAX_QIDS];
326 test_event_dev_stats_get(int dev_id, struct test_event_dev_stats *stats)
329 static uint32_t total_ids[3]; /* rx, tx and drop */
330 static uint32_t port_rx_pkts_ids[MAX_PORTS];
331 static uint32_t port_rx_dropped_ids[MAX_PORTS];
332 static uint32_t port_inflight_ids[MAX_PORTS];
333 static uint32_t port_tx_pkts_ids[MAX_PORTS];
334 static uint32_t qid_rx_pkts_ids[MAX_QIDS];
335 static uint32_t qid_rx_dropped_ids[MAX_QIDS];
336 static uint32_t qid_tx_pkts_ids[MAX_QIDS];
339 stats->rx_pkts = rte_event_dev_xstats_by_name_get(dev_id,
340 "dev_rx", &total_ids[0]);
341 stats->rx_dropped = rte_event_dev_xstats_by_name_get(dev_id,
342 "dev_drop", &total_ids[1]);
343 stats->tx_pkts = rte_event_dev_xstats_by_name_get(dev_id,
344 "dev_tx", &total_ids[2]);
345 for (i = 0; i < MAX_PORTS; i++) {
347 snprintf(name, sizeof(name), "port_%u_rx", i);
348 stats->port_rx_pkts[i] = rte_event_dev_xstats_by_name_get(
349 dev_id, name, &port_rx_pkts_ids[i]);
350 snprintf(name, sizeof(name), "port_%u_drop", i);
351 stats->port_rx_dropped[i] = rte_event_dev_xstats_by_name_get(
352 dev_id, name, &port_rx_dropped_ids[i]);
353 snprintf(name, sizeof(name), "port_%u_inflight", i);
354 stats->port_inflight[i] = rte_event_dev_xstats_by_name_get(
355 dev_id, name, &port_inflight_ids[i]);
356 snprintf(name, sizeof(name), "port_%u_tx", i);
357 stats->port_tx_pkts[i] = rte_event_dev_xstats_by_name_get(
358 dev_id, name, &port_tx_pkts_ids[i]);
360 for (i = 0; i < MAX_QIDS; i++) {
362 snprintf(name, sizeof(name), "qid_%u_rx", i);
363 stats->qid_rx_pkts[i] = rte_event_dev_xstats_by_name_get(
364 dev_id, name, &qid_rx_pkts_ids[i]);
365 snprintf(name, sizeof(name), "qid_%u_drop", i);
366 stats->qid_rx_dropped[i] = rte_event_dev_xstats_by_name_get(
367 dev_id, name, &qid_rx_dropped_ids[i]);
368 snprintf(name, sizeof(name), "qid_%u_tx", i);
369 stats->qid_tx_pkts[i] = rte_event_dev_xstats_by_name_get(
370 dev_id, name, &qid_tx_pkts_ids[i]);
376 /* run_prio_packet_test
377 * This performs a basic packet priority check on the test instance passed in.
378 * It is factored out of the main priority tests as the same tests must be
379 * performed to ensure prioritization of each type of QID.
382 * - An initialized test structure, including mempool
383 * - t->port[0] is initialized for both Enq / Deq of packets to the QID
384 * - t->qid[0] is the QID to be tested
385 * - if LB QID, the CQ must be mapped to the QID.
388 run_prio_packet_test(struct test *t)
391 const uint32_t MAGIC_SEQN[] = {4711, 1234};
392 const uint32_t PRIORITY[] = {
393 RTE_EVENT_DEV_PRIORITY_NORMAL,
394 RTE_EVENT_DEV_PRIORITY_HIGHEST
397 for (i = 0; i < RTE_DIM(MAGIC_SEQN); i++) {
398 /* generate pkt and enqueue */
400 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
402 printf("%d: gen of pkt failed\n", __LINE__);
405 arp->seqn = MAGIC_SEQN[i];
407 ev = (struct rte_event){
408 .priority = PRIORITY[i],
409 .op = RTE_EVENT_OP_NEW,
410 .queue_id = t->qid[0],
413 err = rte_event_enqueue_burst(evdev, t->port[0], &ev, 1);
415 printf("%d: error failed to enqueue\n", __LINE__);
420 rte_event_schedule(evdev);
422 struct test_event_dev_stats stats;
423 err = test_event_dev_stats_get(evdev, &stats);
425 printf("%d: error failed to get stats\n", __LINE__);
429 if (stats.port_rx_pkts[t->port[0]] != 2) {
430 printf("%d: error stats incorrect for directed port\n",
432 rte_event_dev_dump(evdev, stdout);
436 struct rte_event ev, ev2;
438 deq_pkts = rte_event_dequeue_burst(evdev, t->port[0], &ev, 1, 0);
440 printf("%d: error failed to deq\n", __LINE__);
441 rte_event_dev_dump(evdev, stdout);
444 if (ev.mbuf->seqn != MAGIC_SEQN[1]) {
445 printf("%d: first packet out not highest priority\n",
447 rte_event_dev_dump(evdev, stdout);
450 rte_pktmbuf_free(ev.mbuf);
452 deq_pkts = rte_event_dequeue_burst(evdev, t->port[0], &ev2, 1, 0);
454 printf("%d: error failed to deq\n", __LINE__);
455 rte_event_dev_dump(evdev, stdout);
458 if (ev2.mbuf->seqn != MAGIC_SEQN[0]) {
459 printf("%d: second packet out not lower priority\n",
461 rte_event_dev_dump(evdev, stdout);
464 rte_pktmbuf_free(ev2.mbuf);
471 test_single_directed_packet(struct test *t)
473 const int rx_enq = 0;
474 const int wrk_enq = 2;
477 /* Create instance with 3 directed QIDs going to 3 ports */
478 if (init(t, 3, 3) < 0 ||
479 create_ports(t, 3) < 0 ||
480 create_directed_qids(t, 3, t->port) < 0)
483 if (rte_event_dev_start(evdev) < 0) {
484 printf("%d: Error with start call\n", __LINE__);
488 /************** FORWARD ****************/
489 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
490 struct rte_event ev = {
491 .op = RTE_EVENT_OP_NEW,
497 printf("%d: gen of pkt failed\n", __LINE__);
501 const uint32_t MAGIC_SEQN = 4711;
502 arp->seqn = MAGIC_SEQN;
504 /* generate pkt and enqueue */
505 err = rte_event_enqueue_burst(evdev, rx_enq, &ev, 1);
507 printf("%d: error failed to enqueue\n", __LINE__);
511 /* Run schedule() as dir packets may need to be re-ordered */
512 rte_event_schedule(evdev);
514 struct test_event_dev_stats stats;
515 err = test_event_dev_stats_get(evdev, &stats);
517 printf("%d: error failed to get stats\n", __LINE__);
521 if (stats.port_rx_pkts[rx_enq] != 1) {
522 printf("%d: error stats incorrect for directed port\n",
528 deq_pkts = rte_event_dequeue_burst(evdev, wrk_enq, &ev, 1, 0);
530 printf("%d: error failed to deq\n", __LINE__);
534 err = test_event_dev_stats_get(evdev, &stats);
535 if (stats.port_rx_pkts[wrk_enq] != 0 &&
536 stats.port_rx_pkts[wrk_enq] != 1) {
537 printf("%d: error directed stats post-dequeue\n", __LINE__);
541 if (ev.mbuf->seqn != MAGIC_SEQN) {
542 printf("%d: error magic sequence number not dequeued\n",
547 rte_pktmbuf_free(ev.mbuf);
553 test_directed_forward_credits(struct test *t)
558 if (init(t, 1, 1) < 0 ||
559 create_ports(t, 1) < 0 ||
560 create_directed_qids(t, 1, t->port) < 0)
563 if (rte_event_dev_start(evdev) < 0) {
564 printf("%d: Error with start call\n", __LINE__);
568 struct rte_event ev = {
569 .op = RTE_EVENT_OP_NEW,
573 for (i = 0; i < 1000; i++) {
574 err = rte_event_enqueue_burst(evdev, 0, &ev, 1);
576 printf("%d: error failed to enqueue\n", __LINE__);
579 rte_event_schedule(evdev);
582 deq_pkts = rte_event_dequeue_burst(evdev, 0, &ev, 1, 0);
584 printf("%d: error failed to deq\n", __LINE__);
588 /* re-write event to be a forward, and continue looping it */
589 ev.op = RTE_EVENT_OP_FORWARD;
598 test_priority_directed(struct test *t)
600 if (init(t, 1, 1) < 0 ||
601 create_ports(t, 1) < 0 ||
602 create_directed_qids(t, 1, t->port) < 0) {
603 printf("%d: Error initializing device\n", __LINE__);
607 if (rte_event_dev_start(evdev) < 0) {
608 printf("%d: Error with start call\n", __LINE__);
612 return run_prio_packet_test(t);
616 test_priority_atomic(struct test *t)
618 if (init(t, 1, 1) < 0 ||
619 create_ports(t, 1) < 0 ||
620 create_atomic_qids(t, 1) < 0) {
621 printf("%d: Error initializing device\n", __LINE__);
626 if (rte_event_port_link(evdev, t->port[0], &t->qid[0], NULL, 1) != 1) {
627 printf("%d: error mapping qid to port\n", __LINE__);
630 if (rte_event_dev_start(evdev) < 0) {
631 printf("%d: Error with start call\n", __LINE__);
635 return run_prio_packet_test(t);
639 test_priority_ordered(struct test *t)
641 if (init(t, 1, 1) < 0 ||
642 create_ports(t, 1) < 0 ||
643 create_ordered_qids(t, 1) < 0) {
644 printf("%d: Error initializing device\n", __LINE__);
649 if (rte_event_port_link(evdev, t->port[0], &t->qid[0], NULL, 1) != 1) {
650 printf("%d: error mapping qid to port\n", __LINE__);
653 if (rte_event_dev_start(evdev) < 0) {
654 printf("%d: Error with start call\n", __LINE__);
658 return run_prio_packet_test(t);
662 test_priority_unordered(struct test *t)
664 if (init(t, 1, 1) < 0 ||
665 create_ports(t, 1) < 0 ||
666 create_unordered_qids(t, 1) < 0) {
667 printf("%d: Error initializing device\n", __LINE__);
672 if (rte_event_port_link(evdev, t->port[0], &t->qid[0], NULL, 1) != 1) {
673 printf("%d: error mapping qid to port\n", __LINE__);
676 if (rte_event_dev_start(evdev) < 0) {
677 printf("%d: Error with start call\n", __LINE__);
681 return run_prio_packet_test(t);
685 burst_packets(struct test *t)
687 /************** CONFIG ****************/
692 /* Create instance with 2 ports and 2 queues */
693 if (init(t, 2, 2) < 0 ||
694 create_ports(t, 2) < 0 ||
695 create_atomic_qids(t, 2) < 0) {
696 printf("%d: Error initializing device\n", __LINE__);
700 /* CQ mapping to QID */
701 ret = rte_event_port_link(evdev, t->port[0], &t->qid[0], NULL, 1);
703 printf("%d: error mapping lb qid0\n", __LINE__);
706 ret = rte_event_port_link(evdev, t->port[1], &t->qid[1], NULL, 1);
708 printf("%d: error mapping lb qid1\n", __LINE__);
712 if (rte_event_dev_start(evdev) < 0) {
713 printf("%d: Error with start call\n", __LINE__);
717 /************** FORWARD ****************/
718 const uint32_t rx_port = 0;
719 const uint32_t NUM_PKTS = 2;
721 for (i = 0; i < NUM_PKTS; i++) {
722 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
724 printf("%d: error generating pkt\n", __LINE__);
728 struct rte_event ev = {
729 .op = RTE_EVENT_OP_NEW,
734 /* generate pkt and enqueue */
735 err = rte_event_enqueue_burst(evdev, t->port[rx_port], &ev, 1);
737 printf("%d: Failed to enqueue\n", __LINE__);
741 rte_event_schedule(evdev);
743 /* Check stats for all NUM_PKTS arrived to sched core */
744 struct test_event_dev_stats stats;
746 err = test_event_dev_stats_get(evdev, &stats);
748 printf("%d: failed to get stats\n", __LINE__);
751 if (stats.rx_pkts != NUM_PKTS || stats.tx_pkts != NUM_PKTS) {
752 printf("%d: Sched core didn't receive all %d pkts\n",
754 rte_event_dev_dump(evdev, stdout);
762 /******** DEQ QID 1 *******/
765 p = rte_event_dequeue_burst(evdev, t->port[0], &ev, 1, 0);
767 rte_pktmbuf_free(ev.mbuf);
770 if (deq_pkts != NUM_PKTS/2) {
771 printf("%d: Half of NUM_PKTS didn't arrive at port 1\n",
776 /******** DEQ QID 2 *******/
780 p = rte_event_dequeue_burst(evdev, t->port[1], &ev, 1, 0);
782 rte_pktmbuf_free(ev.mbuf);
784 if (deq_pkts != NUM_PKTS/2) {
785 printf("%d: Half of NUM_PKTS didn't arrive at port 2\n",
795 abuse_inflights(struct test *t)
797 const int rx_enq = 0;
798 const int wrk_enq = 2;
801 /* Create instance with 4 ports */
802 if (init(t, 1, 4) < 0 ||
803 create_ports(t, 4) < 0 ||
804 create_atomic_qids(t, 1) < 0) {
805 printf("%d: Error initializing device\n", __LINE__);
809 /* CQ mapping to QID */
810 err = rte_event_port_link(evdev, t->port[wrk_enq], NULL, NULL, 0);
812 printf("%d: error mapping lb qid\n", __LINE__);
817 if (rte_event_dev_start(evdev) < 0) {
818 printf("%d: Error with start call\n", __LINE__);
822 /* Enqueue op only */
823 err = rte_event_enqueue_burst(evdev, t->port[rx_enq], &release_ev, 1);
825 printf("%d: Failed to enqueue\n", __LINE__);
830 rte_event_schedule(evdev);
832 struct test_event_dev_stats stats;
834 err = test_event_dev_stats_get(evdev, &stats);
836 printf("%d: failed to get stats\n", __LINE__);
840 if (stats.rx_pkts != 0 ||
841 stats.tx_pkts != 0 ||
842 stats.port_inflight[wrk_enq] != 0) {
843 printf("%d: Sched core didn't handle pkt as expected\n",
853 xstats_tests(struct test *t)
855 const int wrk_enq = 2;
858 /* Create instance with 4 ports */
859 if (init(t, 1, 4) < 0 ||
860 create_ports(t, 4) < 0 ||
861 create_atomic_qids(t, 1) < 0) {
862 printf("%d: Error initializing device\n", __LINE__);
866 /* CQ mapping to QID */
867 err = rte_event_port_link(evdev, t->port[wrk_enq], NULL, NULL, 0);
869 printf("%d: error mapping lb qid\n", __LINE__);
874 if (rte_event_dev_start(evdev) < 0) {
875 printf("%d: Error with start call\n", __LINE__);
879 const uint32_t XSTATS_MAX = 1024;
882 uint32_t ids[XSTATS_MAX];
883 uint64_t values[XSTATS_MAX];
884 struct rte_event_dev_xstats_name xstats_names[XSTATS_MAX];
886 for (i = 0; i < XSTATS_MAX; i++)
889 /* Device names / values */
890 int ret = rte_event_dev_xstats_names_get(evdev,
891 RTE_EVENT_DEV_XSTATS_DEVICE,
892 0, xstats_names, ids, XSTATS_MAX);
894 printf("%d: expected 6 stats, got return %d\n", __LINE__, ret);
897 ret = rte_event_dev_xstats_get(evdev,
898 RTE_EVENT_DEV_XSTATS_DEVICE,
899 0, ids, values, ret);
901 printf("%d: expected 6 stats, got return %d\n", __LINE__, ret);
905 /* Port names / values */
906 ret = rte_event_dev_xstats_names_get(evdev,
907 RTE_EVENT_DEV_XSTATS_PORT, 0,
908 xstats_names, ids, XSTATS_MAX);
910 printf("%d: expected 21 stats, got return %d\n", __LINE__, ret);
913 ret = rte_event_dev_xstats_get(evdev,
914 RTE_EVENT_DEV_XSTATS_PORT, 0,
917 printf("%d: expected 21 stats, got return %d\n", __LINE__, ret);
921 /* Queue names / values */
922 ret = rte_event_dev_xstats_names_get(evdev,
923 RTE_EVENT_DEV_XSTATS_QUEUE,
924 0, xstats_names, ids, XSTATS_MAX);
926 printf("%d: expected 17 stats, got return %d\n", __LINE__, ret);
930 /* NEGATIVE TEST: with wrong queue passed, 0 stats should be returned */
931 ret = rte_event_dev_xstats_get(evdev,
932 RTE_EVENT_DEV_XSTATS_QUEUE,
933 1, ids, values, ret);
934 if (ret != -EINVAL) {
935 printf("%d: expected 0 stats, got return %d\n", __LINE__, ret);
939 ret = rte_event_dev_xstats_get(evdev,
940 RTE_EVENT_DEV_XSTATS_QUEUE,
941 0, ids, values, ret);
943 printf("%d: expected 17 stats, got return %d\n", __LINE__, ret);
947 /* enqueue packets to check values */
948 for (i = 0; i < 3; i++) {
950 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
952 printf("%d: gen of pkt failed\n", __LINE__);
955 ev.queue_id = t->qid[i];
956 ev.op = RTE_EVENT_OP_NEW;
961 int err = rte_event_enqueue_burst(evdev, t->port[0], &ev, 1);
963 printf("%d: Failed to enqueue\n", __LINE__);
968 rte_event_schedule(evdev);
970 /* Device names / values */
971 int num_stats = rte_event_dev_xstats_names_get(evdev,
972 RTE_EVENT_DEV_XSTATS_DEVICE, 0,
973 xstats_names, ids, XSTATS_MAX);
976 ret = rte_event_dev_xstats_get(evdev,
977 RTE_EVENT_DEV_XSTATS_DEVICE,
978 0, ids, values, num_stats);
979 static const uint64_t expected[] = {3, 3, 0, 1, 0, 0};
980 for (i = 0; (signed int)i < ret; i++) {
981 if (expected[i] != values[i]) {
983 "%d Error xstat %d (id %d) %s : %"PRIu64
984 ", expect %"PRIu64"\n",
985 __LINE__, i, ids[i], xstats_names[i].name,
986 values[i], expected[i]);
991 ret = rte_event_dev_xstats_reset(evdev, RTE_EVENT_DEV_XSTATS_DEVICE,
994 /* ensure reset statistics are zero-ed */
995 static const uint64_t expected_zero[] = {0, 0, 0, 0, 0, 0};
996 ret = rte_event_dev_xstats_get(evdev,
997 RTE_EVENT_DEV_XSTATS_DEVICE,
998 0, ids, values, num_stats);
999 for (i = 0; (signed int)i < ret; i++) {
1000 if (expected_zero[i] != values[i]) {
1002 "%d Error, xstat %d (id %d) %s : %"PRIu64
1003 ", expect %"PRIu64"\n",
1004 __LINE__, i, ids[i], xstats_names[i].name,
1005 values[i], expected_zero[i]);
1010 /* port reset checks */
1011 num_stats = rte_event_dev_xstats_names_get(evdev,
1012 RTE_EVENT_DEV_XSTATS_PORT, 0,
1013 xstats_names, ids, XSTATS_MAX);
1016 ret = rte_event_dev_xstats_get(evdev, RTE_EVENT_DEV_XSTATS_PORT,
1017 0, ids, values, num_stats);
1019 static const uint64_t port_expected[] = {
1024 0 /* avg pkt cycles */,
1026 0 /* rx ring used */,
1027 4096 /* rx ring free */,
1028 0 /* cq ring used */,
1029 32 /* cq ring free */,
1030 0 /* dequeue calls */,
1031 /* 10 dequeue burst buckets */
1035 if (ret != RTE_DIM(port_expected)) {
1037 "%s %d: wrong number of port stats (%d), expected %zu\n",
1038 __func__, __LINE__, ret, RTE_DIM(port_expected));
1041 for (i = 0; (signed int)i < ret; i++) {
1042 if (port_expected[i] != values[i]) {
1044 "%s : %d: Error stat %s is %"PRIu64
1045 ", expected %"PRIu64"\n",
1046 __func__, __LINE__, xstats_names[i].name,
1047 values[i], port_expected[i]);
1052 ret = rte_event_dev_xstats_reset(evdev, RTE_EVENT_DEV_XSTATS_PORT,
1055 /* ensure reset statistics are zero-ed */
1056 static const uint64_t port_expected_zero[] = {
1061 0 /* avg pkt cycles */,
1063 0 /* rx ring used */,
1064 4096 /* rx ring free */,
1065 0 /* cq ring used */,
1066 32 /* cq ring free */,
1067 0 /* dequeue calls */,
1068 /* 10 dequeue burst buckets */
1072 ret = rte_event_dev_xstats_get(evdev,
1073 RTE_EVENT_DEV_XSTATS_PORT,
1074 0, ids, values, num_stats);
1075 for (i = 0; (signed int)i < ret; i++) {
1076 if (port_expected_zero[i] != values[i]) {
1078 "%d, Error, xstat %d (id %d) %s : %"PRIu64
1079 ", expect %"PRIu64"\n",
1080 __LINE__, i, ids[i], xstats_names[i].name,
1081 values[i], port_expected_zero[i]);
1086 /* QUEUE STATS TESTS */
1087 num_stats = rte_event_dev_xstats_names_get(evdev,
1088 RTE_EVENT_DEV_XSTATS_QUEUE, 0,
1089 xstats_names, ids, XSTATS_MAX);
1090 ret = rte_event_dev_xstats_get(evdev, RTE_EVENT_DEV_XSTATS_QUEUE,
1091 0, ids, values, num_stats);
1093 printf("xstats get returned %d\n", ret);
1096 if ((unsigned int)ret > XSTATS_MAX)
1097 printf("%s %d: more xstats available than space\n",
1098 __func__, __LINE__);
1100 static const uint64_t queue_expected[] = {
1106 0, 0, 0, 0, /* iq 0, 1, 2, 3 used */
1107 /* QID-to-Port: pinned_flows, packets */
1113 for (i = 0; (signed int)i < ret; i++) {
1114 if (queue_expected[i] != values[i]) {
1116 "%d, Error, xstat %d (id %d) %s : %"PRIu64
1117 ", expect %"PRIu64"\n",
1118 __LINE__, i, ids[i], xstats_names[i].name,
1119 values[i], queue_expected[i]);
1124 /* Reset the queue stats here */
1125 ret = rte_event_dev_xstats_reset(evdev,
1126 RTE_EVENT_DEV_XSTATS_QUEUE, 0,
1130 /* Verify that the resetable stats are reset, and others are not */
1131 static const uint64_t queue_expected_zero[] = {
1137 0, 0, 0, 0, /* 4 iq used */
1138 /* QID-to-Port: pinned_flows, packets */
1145 ret = rte_event_dev_xstats_get(evdev, RTE_EVENT_DEV_XSTATS_QUEUE, 0,
1146 ids, values, num_stats);
1148 for (i = 0; (signed int)i < ret; i++) {
1149 if (queue_expected_zero[i] != values[i]) {
1151 "%d, Error, xstat %d (id %d) %s : %"PRIu64
1152 ", expect %"PRIu64"\n",
1153 __LINE__, i, ids[i], xstats_names[i].name,
1154 values[i], queue_expected_zero[i]);
1159 printf("%d : %d of values were not as expected above\n",
1168 rte_event_dev_dump(0, stdout);
1175 xstats_id_abuse_tests(struct test *t)
1178 const uint32_t XSTATS_MAX = 1024;
1179 const uint32_t link_port = 2;
1181 uint32_t ids[XSTATS_MAX];
1182 struct rte_event_dev_xstats_name xstats_names[XSTATS_MAX];
1184 /* Create instance with 4 ports */
1185 if (init(t, 1, 4) < 0 ||
1186 create_ports(t, 4) < 0 ||
1187 create_atomic_qids(t, 1) < 0) {
1188 printf("%d: Error initializing device\n", __LINE__);
1192 err = rte_event_port_link(evdev, t->port[link_port], NULL, NULL, 0);
1194 printf("%d: error mapping lb qid\n", __LINE__);
1198 if (rte_event_dev_start(evdev) < 0) {
1199 printf("%d: Error with start call\n", __LINE__);
1203 /* no test for device, as it ignores the port/q number */
1204 int num_stats = rte_event_dev_xstats_names_get(evdev,
1205 RTE_EVENT_DEV_XSTATS_PORT,
1206 UINT8_MAX-1, xstats_names, ids,
1208 if (num_stats != 0) {
1209 printf("%d: expected %d stats, got return %d\n", __LINE__,
1214 num_stats = rte_event_dev_xstats_names_get(evdev,
1215 RTE_EVENT_DEV_XSTATS_QUEUE,
1216 UINT8_MAX-1, xstats_names, ids,
1218 if (num_stats != 0) {
1219 printf("%d: expected %d stats, got return %d\n", __LINE__,
1232 port_reconfig_credits(struct test *t)
1234 if (init(t, 1, 1) < 0) {
1235 printf("%d: Error initializing device\n", __LINE__);
1240 const uint32_t NUM_ITERS = 32;
1241 for (i = 0; i < NUM_ITERS; i++) {
1242 const struct rte_event_queue_conf conf = {
1243 .event_queue_cfg = RTE_EVENT_QUEUE_CFG_ATOMIC_ONLY,
1244 .priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
1245 .nb_atomic_flows = 1024,
1246 .nb_atomic_order_sequences = 1024,
1248 if (rte_event_queue_setup(evdev, 0, &conf) < 0) {
1249 printf("%d: error creating qid\n", __LINE__);
1254 static const struct rte_event_port_conf port_conf = {
1255 .new_event_threshold = 128,
1256 .dequeue_depth = 32,
1257 .enqueue_depth = 64,
1259 if (rte_event_port_setup(evdev, 0, &port_conf) < 0) {
1260 printf("%d Error setting up port\n", __LINE__);
1264 int links = rte_event_port_link(evdev, 0, NULL, NULL, 0);
1266 printf("%d: error mapping lb qid\n", __LINE__);
1270 if (rte_event_dev_start(evdev) < 0) {
1271 printf("%d: Error with start call\n", __LINE__);
1275 const uint32_t NPKTS = 1;
1277 for (j = 0; j < NPKTS; j++) {
1278 struct rte_event ev;
1279 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
1281 printf("%d: gen of pkt failed\n", __LINE__);
1284 ev.queue_id = t->qid[0];
1285 ev.op = RTE_EVENT_OP_NEW;
1287 int err = rte_event_enqueue_burst(evdev, 0, &ev, 1);
1289 printf("%d: Failed to enqueue\n", __LINE__);
1290 rte_event_dev_dump(0, stdout);
1295 rte_event_schedule(evdev);
1297 struct rte_event ev[NPKTS];
1298 int deq = rte_event_dequeue_burst(evdev, t->port[0], ev,
1301 printf("%d error; no packet dequeued\n", __LINE__);
1303 /* let cleanup below stop the device on last iter */
1304 if (i != NUM_ITERS-1)
1305 rte_event_dev_stop(evdev);
1316 port_single_lb_reconfig(struct test *t)
1318 if (init(t, 2, 2) < 0) {
1319 printf("%d: Error initializing device\n", __LINE__);
1323 static const struct rte_event_queue_conf conf_lb_atomic = {
1324 .priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
1325 .event_queue_cfg = RTE_EVENT_QUEUE_CFG_ATOMIC_ONLY,
1326 .nb_atomic_flows = 1024,
1327 .nb_atomic_order_sequences = 1024,
1329 if (rte_event_queue_setup(evdev, 0, &conf_lb_atomic) < 0) {
1330 printf("%d: error creating qid\n", __LINE__);
1334 static const struct rte_event_queue_conf conf_single_link = {
1335 .priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
1336 .event_queue_cfg = RTE_EVENT_QUEUE_CFG_SINGLE_LINK,
1337 .nb_atomic_flows = 1024,
1338 .nb_atomic_order_sequences = 1024,
1340 if (rte_event_queue_setup(evdev, 1, &conf_single_link) < 0) {
1341 printf("%d: error creating qid\n", __LINE__);
1345 struct rte_event_port_conf port_conf = {
1346 .new_event_threshold = 128,
1347 .dequeue_depth = 32,
1348 .enqueue_depth = 64,
1350 if (rte_event_port_setup(evdev, 0, &port_conf) < 0) {
1351 printf("%d Error setting up port\n", __LINE__);
1354 if (rte_event_port_setup(evdev, 1, &port_conf) < 0) {
1355 printf("%d Error setting up port\n", __LINE__);
1359 /* link port to lb queue */
1360 uint8_t queue_id = 0;
1361 if (rte_event_port_link(evdev, 0, &queue_id, NULL, 1) != 1) {
1362 printf("%d: error creating link for qid\n", __LINE__);
1366 int ret = rte_event_port_unlink(evdev, 0, &queue_id, 1);
1368 printf("%d: Error unlinking lb port\n", __LINE__);
1373 if (rte_event_port_link(evdev, 0, &queue_id, NULL, 1) != 1) {
1374 printf("%d: error creating link for qid\n", __LINE__);
1379 int err = rte_event_port_link(evdev, 1, &queue_id, NULL, 1);
1381 printf("%d: error mapping lb qid\n", __LINE__);
1385 if (rte_event_dev_start(evdev) < 0) {
1386 printf("%d: Error with start call\n", __LINE__);
1398 xstats_brute_force(struct test *t)
1401 const uint32_t XSTATS_MAX = 1024;
1402 uint32_t ids[XSTATS_MAX];
1403 uint64_t values[XSTATS_MAX];
1404 struct rte_event_dev_xstats_name xstats_names[XSTATS_MAX];
1407 /* Create instance with 4 ports */
1408 if (init(t, 1, 4) < 0 ||
1409 create_ports(t, 4) < 0 ||
1410 create_atomic_qids(t, 1) < 0) {
1411 printf("%d: Error initializing device\n", __LINE__);
1415 int err = rte_event_port_link(evdev, t->port[0], NULL, NULL, 0);
1417 printf("%d: error mapping lb qid\n", __LINE__);
1421 if (rte_event_dev_start(evdev) < 0) {
1422 printf("%d: Error with start call\n", __LINE__);
1426 for (i = 0; i < XSTATS_MAX; i++)
1429 for (i = 0; i < 3; i++) {
1430 uint32_t mode = RTE_EVENT_DEV_XSTATS_DEVICE + i;
1432 for (j = 0; j < UINT8_MAX; j++) {
1433 rte_event_dev_xstats_names_get(evdev, mode,
1434 j, xstats_names, ids, XSTATS_MAX);
1436 rte_event_dev_xstats_get(evdev, mode, j, ids,
1437 values, XSTATS_MAX);
1449 xstats_id_reset_tests(struct test *t)
1451 const int wrk_enq = 2;
1454 /* Create instance with 4 ports */
1455 if (init(t, 1, 4) < 0 ||
1456 create_ports(t, 4) < 0 ||
1457 create_atomic_qids(t, 1) < 0) {
1458 printf("%d: Error initializing device\n", __LINE__);
1462 /* CQ mapping to QID */
1463 err = rte_event_port_link(evdev, t->port[wrk_enq], NULL, NULL, 0);
1465 printf("%d: error mapping lb qid\n", __LINE__);
1469 if (rte_event_dev_start(evdev) < 0) {
1470 printf("%d: Error with start call\n", __LINE__);
1474 #define XSTATS_MAX 1024
1477 uint32_t ids[XSTATS_MAX];
1478 uint64_t values[XSTATS_MAX];
1479 struct rte_event_dev_xstats_name xstats_names[XSTATS_MAX];
1481 for (i = 0; i < XSTATS_MAX; i++)
1484 #define NUM_DEV_STATS 6
1485 /* Device names / values */
1486 int num_stats = rte_event_dev_xstats_names_get(evdev,
1487 RTE_EVENT_DEV_XSTATS_DEVICE,
1488 0, xstats_names, ids, XSTATS_MAX);
1489 if (num_stats != NUM_DEV_STATS) {
1490 printf("%d: expected %d stats, got return %d\n", __LINE__,
1491 NUM_DEV_STATS, num_stats);
1494 ret = rte_event_dev_xstats_get(evdev,
1495 RTE_EVENT_DEV_XSTATS_DEVICE,
1496 0, ids, values, num_stats);
1497 if (ret != NUM_DEV_STATS) {
1498 printf("%d: expected %d stats, got return %d\n", __LINE__,
1499 NUM_DEV_STATS, ret);
1504 for (i = 0; i < NPKTS; i++) {
1505 struct rte_event ev;
1506 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
1508 printf("%d: gen of pkt failed\n", __LINE__);
1511 ev.queue_id = t->qid[i];
1512 ev.op = RTE_EVENT_OP_NEW;
1516 int err = rte_event_enqueue_burst(evdev, t->port[0], &ev, 1);
1518 printf("%d: Failed to enqueue\n", __LINE__);
1523 rte_event_schedule(evdev);
1525 static const char * const dev_names[] = {
1526 "dev_rx", "dev_tx", "dev_drop", "dev_sched_calls",
1527 "dev_sched_no_iq_enq", "dev_sched_no_cq_enq",
1529 uint64_t dev_expected[] = {NPKTS, NPKTS, 0, 1, 0, 0};
1530 for (i = 0; (int)i < ret; i++) {
1532 uint64_t val = rte_event_dev_xstats_by_name_get(evdev,
1536 printf("%d: %s id incorrect, expected %d got %d\n",
1537 __LINE__, dev_names[i], i, id);
1540 if (val != dev_expected[i]) {
1541 printf("%d: %s value incorrect, expected %"
1542 PRIu64" got %d\n", __LINE__, dev_names[i],
1543 dev_expected[i], id);
1547 int reset_ret = rte_event_dev_xstats_reset(evdev,
1548 RTE_EVENT_DEV_XSTATS_DEVICE, 0,
1552 printf("%d: failed to reset successfully\n", __LINE__);
1555 dev_expected[i] = 0;
1556 /* check value again */
1557 val = rte_event_dev_xstats_by_name_get(evdev, dev_names[i], 0);
1558 if (val != dev_expected[i]) {
1559 printf("%d: %s value incorrect, expected %"PRIu64
1560 " got %"PRIu64"\n", __LINE__, dev_names[i],
1561 dev_expected[i], val);
1566 /* 48 is stat offset from start of the devices whole xstats.
1567 * This WILL break every time we add a statistic to a port
1568 * or the device, but there is no other way to test
1571 /* num stats for the tested port. CQ size adds more stats to a port */
1572 #define NUM_PORT_STATS 21
1573 /* the port to test. */
1575 num_stats = rte_event_dev_xstats_names_get(evdev,
1576 RTE_EVENT_DEV_XSTATS_PORT, PORT,
1577 xstats_names, ids, XSTATS_MAX);
1578 if (num_stats != NUM_PORT_STATS) {
1579 printf("%d: expected %d stats, got return %d\n",
1580 __LINE__, NUM_PORT_STATS, num_stats);
1583 ret = rte_event_dev_xstats_get(evdev, RTE_EVENT_DEV_XSTATS_PORT, PORT,
1584 ids, values, num_stats);
1586 if (ret != NUM_PORT_STATS) {
1587 printf("%d: expected %d stats, got return %d\n",
1588 __LINE__, NUM_PORT_STATS, ret);
1591 static const char * const port_names[] = {
1596 "port_2_avg_pkt_cycles",
1598 "port_2_rx_ring_used",
1599 "port_2_rx_ring_free",
1600 "port_2_cq_ring_used",
1601 "port_2_cq_ring_free",
1602 "port_2_dequeue_calls",
1603 "port_2_dequeues_returning_0",
1604 "port_2_dequeues_returning_1-4",
1605 "port_2_dequeues_returning_5-8",
1606 "port_2_dequeues_returning_9-12",
1607 "port_2_dequeues_returning_13-16",
1608 "port_2_dequeues_returning_17-20",
1609 "port_2_dequeues_returning_21-24",
1610 "port_2_dequeues_returning_25-28",
1611 "port_2_dequeues_returning_29-32",
1612 "port_2_dequeues_returning_33-36",
1614 uint64_t port_expected[] = {
1618 NPKTS, /* inflight */
1619 0, /* avg pkt cycles */
1621 0, /* rx ring used */
1622 4096, /* rx ring free */
1623 NPKTS, /* cq ring used */
1624 25, /* cq ring free */
1625 0, /* dequeue zero calls */
1626 0, 0, 0, 0, 0, /* 10 dequeue buckets */
1629 uint64_t port_expected_zero[] = {
1633 NPKTS, /* inflight */
1634 0, /* avg pkt cycles */
1636 0, /* rx ring used */
1637 4096, /* rx ring free */
1638 NPKTS, /* cq ring used */
1639 25, /* cq ring free */
1640 0, /* dequeue zero calls */
1641 0, 0, 0, 0, 0, /* 10 dequeue buckets */
1644 if (RTE_DIM(port_expected) != NUM_PORT_STATS ||
1645 RTE_DIM(port_names) != NUM_PORT_STATS) {
1646 printf("%d: port array of wrong size\n", __LINE__);
1651 for (i = 0; (int)i < ret; i++) {
1653 uint64_t val = rte_event_dev_xstats_by_name_get(evdev,
1656 if (id != i + PORT_OFF) {
1657 printf("%d: %s id incorrect, expected %d got %d\n",
1658 __LINE__, port_names[i], i+PORT_OFF,
1662 if (val != port_expected[i]) {
1663 printf("%d: %s value incorrect, expected %"PRIu64
1664 " got %d\n", __LINE__, port_names[i],
1665 port_expected[i], id);
1669 int reset_ret = rte_event_dev_xstats_reset(evdev,
1670 RTE_EVENT_DEV_XSTATS_PORT, PORT,
1674 printf("%d: failed to reset successfully\n", __LINE__);
1677 /* check value again */
1678 val = rte_event_dev_xstats_by_name_get(evdev, port_names[i], 0);
1679 if (val != port_expected_zero[i]) {
1680 printf("%d: %s value incorrect, expected %"PRIu64
1681 " got %"PRIu64"\n", __LINE__, port_names[i],
1682 port_expected_zero[i], val);
1689 /* num queue stats */
1690 #define NUM_Q_STATS 17
1691 /* queue offset from start of the devices whole xstats.
1692 * This will break every time we add a statistic to a device/port/queue
1694 #define QUEUE_OFF 90
1695 const uint32_t queue = 0;
1696 num_stats = rte_event_dev_xstats_names_get(evdev,
1697 RTE_EVENT_DEV_XSTATS_QUEUE, queue,
1698 xstats_names, ids, XSTATS_MAX);
1699 if (num_stats != NUM_Q_STATS) {
1700 printf("%d: expected %d stats, got return %d\n",
1701 __LINE__, NUM_Q_STATS, num_stats);
1704 ret = rte_event_dev_xstats_get(evdev, RTE_EVENT_DEV_XSTATS_QUEUE,
1705 queue, ids, values, num_stats);
1706 if (ret != NUM_Q_STATS) {
1707 printf("%d: expected 21 stats, got return %d\n", __LINE__, ret);
1710 static const char * const queue_names[] = {
1720 "qid_0_port_0_pinned_flows",
1721 "qid_0_port_0_packets",
1722 "qid_0_port_1_pinned_flows",
1723 "qid_0_port_1_packets",
1724 "qid_0_port_2_pinned_flows",
1725 "qid_0_port_2_packets",
1726 "qid_0_port_3_pinned_flows",
1727 "qid_0_port_3_packets",
1729 uint64_t queue_expected[] = {
1739 /* QID-to-Port: pinned_flows, packets */
1745 uint64_t queue_expected_zero[] = {
1755 /* QID-to-Port: pinned_flows, packets */
1761 if (RTE_DIM(queue_expected) != NUM_Q_STATS ||
1762 RTE_DIM(queue_expected_zero) != NUM_Q_STATS ||
1763 RTE_DIM(queue_names) != NUM_Q_STATS) {
1764 printf("%d : queue array of wrong size\n", __LINE__);
1769 for (i = 0; (int)i < ret; i++) {
1771 uint64_t val = rte_event_dev_xstats_by_name_get(evdev,
1774 if (id != i + QUEUE_OFF) {
1775 printf("%d: %s id incorrect, expected %d got %d\n",
1776 __LINE__, queue_names[i], i+QUEUE_OFF,
1780 if (val != queue_expected[i]) {
1781 printf("%d: %d: %s value , expected %"PRIu64
1782 " got %"PRIu64"\n", i, __LINE__,
1783 queue_names[i], queue_expected[i], val);
1787 int reset_ret = rte_event_dev_xstats_reset(evdev,
1788 RTE_EVENT_DEV_XSTATS_QUEUE,
1791 printf("%d: failed to reset successfully\n", __LINE__);
1794 /* check value again */
1795 val = rte_event_dev_xstats_by_name_get(evdev, queue_names[i],
1797 if (val != queue_expected_zero[i]) {
1798 printf("%d: %s value incorrect, expected %"PRIu64
1799 " got %"PRIu64"\n", __LINE__, queue_names[i],
1800 queue_expected_zero[i], val);
1816 ordered_reconfigure(struct test *t)
1818 if (init(t, 1, 1) < 0 ||
1819 create_ports(t, 1) < 0) {
1820 printf("%d: Error initializing device\n", __LINE__);
1824 const struct rte_event_queue_conf conf = {
1825 .event_queue_cfg = RTE_EVENT_QUEUE_CFG_ORDERED_ONLY,
1826 .priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
1827 .nb_atomic_flows = 1024,
1828 .nb_atomic_order_sequences = 1024,
1831 if (rte_event_queue_setup(evdev, 0, &conf) < 0) {
1832 printf("%d: error creating qid\n", __LINE__);
1836 if (rte_event_queue_setup(evdev, 0, &conf) < 0) {
1837 printf("%d: error creating qid, for 2nd time\n", __LINE__);
1841 rte_event_port_link(evdev, t->port[0], NULL, NULL, 0);
1842 if (rte_event_dev_start(evdev) < 0) {
1843 printf("%d: Error with start call\n", __LINE__);
1855 qid_priorities(struct test *t)
1857 /* Test works by having a CQ with enough empty space for all packets,
1858 * and enqueueing 3 packets to 3 QIDs. They must return based on the
1859 * priority of the QID, not the ingress order, to pass the test
1862 /* Create instance with 1 ports, and 3 qids */
1863 if (init(t, 3, 1) < 0 ||
1864 create_ports(t, 1) < 0) {
1865 printf("%d: Error initializing device\n", __LINE__);
1869 for (i = 0; i < 3; i++) {
1871 const struct rte_event_queue_conf conf = {
1872 .event_queue_cfg = RTE_EVENT_QUEUE_CFG_ATOMIC_ONLY,
1873 /* increase priority (0 == highest), as we go */
1874 .priority = RTE_EVENT_DEV_PRIORITY_NORMAL - i,
1875 .nb_atomic_flows = 1024,
1876 .nb_atomic_order_sequences = 1024,
1879 if (rte_event_queue_setup(evdev, i, &conf) < 0) {
1880 printf("%d: error creating qid %d\n", __LINE__, i);
1886 /* map all QIDs to port */
1887 rte_event_port_link(evdev, t->port[0], NULL, NULL, 0);
1889 if (rte_event_dev_start(evdev) < 0) {
1890 printf("%d: Error with start call\n", __LINE__);
1894 /* enqueue 3 packets, setting seqn and QID to check priority */
1895 for (i = 0; i < 3; i++) {
1896 struct rte_event ev;
1897 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
1899 printf("%d: gen of pkt failed\n", __LINE__);
1902 ev.queue_id = t->qid[i];
1903 ev.op = RTE_EVENT_OP_NEW;
1907 int err = rte_event_enqueue_burst(evdev, t->port[0], &ev, 1);
1909 printf("%d: Failed to enqueue\n", __LINE__);
1914 rte_event_schedule(evdev);
1916 /* dequeue packets, verify priority was upheld */
1917 struct rte_event ev[32];
1919 rte_event_dequeue_burst(evdev, t->port[0], ev, 32, 0);
1920 if (deq_pkts != 3) {
1921 printf("%d: failed to deq packets\n", __LINE__);
1922 rte_event_dev_dump(evdev, stdout);
1925 for (i = 0; i < 3; i++) {
1926 if (ev[i].mbuf->seqn != 2-i) {
1928 "%d: qid priority test: seqn %d incorrectly prioritized\n",
1938 load_balancing(struct test *t)
1940 const int rx_enq = 0;
1944 if (init(t, 1, 4) < 0 ||
1945 create_ports(t, 4) < 0 ||
1946 create_atomic_qids(t, 1) < 0) {
1947 printf("%d: Error initializing device\n", __LINE__);
1951 for (i = 0; i < 3; i++) {
1952 /* map port 1 - 3 inclusive */
1953 if (rte_event_port_link(evdev, t->port[i+1], &t->qid[0],
1955 printf("%d: error mapping qid to port %d\n",
1961 if (rte_event_dev_start(evdev) < 0) {
1962 printf("%d: Error with start call\n", __LINE__);
1966 /************** FORWARD ****************/
1968 * Create a set of flows that test the load-balancing operation of the
1969 * implementation. Fill CQ 0 and 1 with flows 0 and 1, and test
1970 * with a new flow, which should be sent to the 3rd mapped CQ
1972 static uint32_t flows[] = {0, 1, 1, 0, 0, 2, 2, 0, 2};
1974 for (i = 0; i < RTE_DIM(flows); i++) {
1975 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
1977 printf("%d: gen of pkt failed\n", __LINE__);
1981 struct rte_event ev = {
1982 .op = RTE_EVENT_OP_NEW,
1983 .queue_id = t->qid[0],
1984 .flow_id = flows[i],
1987 /* generate pkt and enqueue */
1988 err = rte_event_enqueue_burst(evdev, t->port[rx_enq], &ev, 1);
1990 printf("%d: Failed to enqueue\n", __LINE__);
1995 rte_event_schedule(evdev);
1997 struct test_event_dev_stats stats;
1998 err = test_event_dev_stats_get(evdev, &stats);
2000 printf("%d: failed to get stats\n", __LINE__);
2004 if (stats.port_inflight[1] != 4) {
2005 printf("%d:%s: port 1 inflight not correct\n", __LINE__,
2009 if (stats.port_inflight[2] != 2) {
2010 printf("%d:%s: port 2 inflight not correct\n", __LINE__,
2014 if (stats.port_inflight[3] != 3) {
2015 printf("%d:%s: port 3 inflight not correct\n", __LINE__,
2025 load_balancing_history(struct test *t)
2027 struct test_event_dev_stats stats = {0};
2028 const int rx_enq = 0;
2032 /* Create instance with 1 atomic QID going to 3 ports + 1 prod port */
2033 if (init(t, 1, 4) < 0 ||
2034 create_ports(t, 4) < 0 ||
2035 create_atomic_qids(t, 1) < 0)
2038 /* CQ mapping to QID */
2039 if (rte_event_port_link(evdev, t->port[1], &t->qid[0], NULL, 1) != 1) {
2040 printf("%d: error mapping port 1 qid\n", __LINE__);
2043 if (rte_event_port_link(evdev, t->port[2], &t->qid[0], NULL, 1) != 1) {
2044 printf("%d: error mapping port 2 qid\n", __LINE__);
2047 if (rte_event_port_link(evdev, t->port[3], &t->qid[0], NULL, 1) != 1) {
2048 printf("%d: error mapping port 3 qid\n", __LINE__);
2051 if (rte_event_dev_start(evdev) < 0) {
2052 printf("%d: Error with start call\n", __LINE__);
2057 * Create a set of flows that test the load-balancing operation of the
2058 * implementation. Fill CQ 0, 1 and 2 with flows 0, 1 and 2, drop
2059 * the packet from CQ 0, send in a new set of flows. Ensure that:
2060 * 1. The new flow 3 gets into the empty CQ0
2061 * 2. packets for existing flow gets added into CQ1
2062 * 3. Next flow 0 pkt is now onto CQ2, since CQ0 and CQ1 now contain
2063 * more outstanding pkts
2065 * This test makes sure that when a flow ends (i.e. all packets
2066 * have been completed for that flow), that the flow can be moved
2067 * to a different CQ when new packets come in for that flow.
2069 static uint32_t flows1[] = {0, 1, 1, 2};
2071 for (i = 0; i < RTE_DIM(flows1); i++) {
2072 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
2073 struct rte_event ev = {
2074 .flow_id = flows1[i],
2075 .op = RTE_EVENT_OP_NEW,
2076 .queue_id = t->qid[0],
2077 .event_type = RTE_EVENT_TYPE_CPU,
2078 .priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
2083 printf("%d: gen of pkt failed\n", __LINE__);
2086 arp->hash.rss = flows1[i];
2087 err = rte_event_enqueue_burst(evdev, t->port[rx_enq], &ev, 1);
2089 printf("%d: Failed to enqueue\n", __LINE__);
2094 /* call the scheduler */
2095 rte_event_schedule(evdev);
2097 /* Dequeue the flow 0 packet from port 1, so that we can then drop */
2098 struct rte_event ev;
2099 if (!rte_event_dequeue_burst(evdev, t->port[1], &ev, 1, 0)) {
2100 printf("%d: failed to dequeue\n", __LINE__);
2103 if (ev.mbuf->hash.rss != flows1[0]) {
2104 printf("%d: unexpected flow received\n", __LINE__);
2108 /* drop the flow 0 packet from port 1 */
2109 rte_event_enqueue_burst(evdev, t->port[1], &release_ev, 1);
2111 /* call the scheduler */
2112 rte_event_schedule(evdev);
2115 * Set up the next set of flows, first a new flow to fill up
2116 * CQ 0, so that the next flow 0 packet should go to CQ2
2118 static uint32_t flows2[] = { 3, 3, 3, 1, 1, 0 };
2120 for (i = 0; i < RTE_DIM(flows2); i++) {
2121 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
2122 struct rte_event ev = {
2123 .flow_id = flows2[i],
2124 .op = RTE_EVENT_OP_NEW,
2125 .queue_id = t->qid[0],
2126 .event_type = RTE_EVENT_TYPE_CPU,
2127 .priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
2132 printf("%d: gen of pkt failed\n", __LINE__);
2135 arp->hash.rss = flows2[i];
2137 err = rte_event_enqueue_burst(evdev, t->port[rx_enq], &ev, 1);
2139 printf("%d: Failed to enqueue\n", __LINE__);
2145 rte_event_schedule(evdev);
2147 err = test_event_dev_stats_get(evdev, &stats);
2149 printf("%d:failed to get stats\n", __LINE__);
2154 * Now check the resulting inflights on each port.
2156 if (stats.port_inflight[1] != 3) {
2157 printf("%d:%s: port 1 inflight not correct\n", __LINE__,
2159 printf("Inflights, ports 1, 2, 3: %u, %u, %u\n",
2160 (unsigned int)stats.port_inflight[1],
2161 (unsigned int)stats.port_inflight[2],
2162 (unsigned int)stats.port_inflight[3]);
2165 if (stats.port_inflight[2] != 4) {
2166 printf("%d:%s: port 2 inflight not correct\n", __LINE__,
2168 printf("Inflights, ports 1, 2, 3: %u, %u, %u\n",
2169 (unsigned int)stats.port_inflight[1],
2170 (unsigned int)stats.port_inflight[2],
2171 (unsigned int)stats.port_inflight[3]);
2174 if (stats.port_inflight[3] != 2) {
2175 printf("%d:%s: port 3 inflight not correct\n", __LINE__,
2177 printf("Inflights, ports 1, 2, 3: %u, %u, %u\n",
2178 (unsigned int)stats.port_inflight[1],
2179 (unsigned int)stats.port_inflight[2],
2180 (unsigned int)stats.port_inflight[3]);
2184 for (i = 1; i <= 3; i++) {
2185 struct rte_event ev;
2186 while (rte_event_dequeue_burst(evdev, i, &ev, 1, 0))
2187 rte_event_enqueue_burst(evdev, i, &release_ev, 1);
2189 rte_event_schedule(evdev);
2196 invalid_qid(struct test *t)
2198 struct test_event_dev_stats stats;
2199 const int rx_enq = 0;
2203 if (init(t, 1, 4) < 0 ||
2204 create_ports(t, 4) < 0 ||
2205 create_atomic_qids(t, 1) < 0) {
2206 printf("%d: Error initializing device\n", __LINE__);
2210 /* CQ mapping to QID */
2211 for (i = 0; i < 4; i++) {
2212 err = rte_event_port_link(evdev, t->port[i], &t->qid[0],
2215 printf("%d: error mapping port 1 qid\n", __LINE__);
2220 if (rte_event_dev_start(evdev) < 0) {
2221 printf("%d: Error with start call\n", __LINE__);
2226 * Send in a packet with an invalid qid to the scheduler.
2227 * We should see the packed enqueued OK, but the inflights for
2228 * that packet should not be incremented, and the rx_dropped
2229 * should be incremented.
2231 static uint32_t flows1[] = {20};
2233 for (i = 0; i < RTE_DIM(flows1); i++) {
2234 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
2236 printf("%d: gen of pkt failed\n", __LINE__);
2240 struct rte_event ev = {
2241 .op = RTE_EVENT_OP_NEW,
2242 .queue_id = t->qid[0] + flows1[i],
2246 /* generate pkt and enqueue */
2247 err = rte_event_enqueue_burst(evdev, t->port[rx_enq], &ev, 1);
2249 printf("%d: Failed to enqueue\n", __LINE__);
2254 /* call the scheduler */
2255 rte_event_schedule(evdev);
2257 err = test_event_dev_stats_get(evdev, &stats);
2259 printf("%d: failed to get stats\n", __LINE__);
2264 * Now check the resulting inflights on the port, and the rx_dropped.
2266 if (stats.port_inflight[0] != 0) {
2267 printf("%d:%s: port 1 inflight count not correct\n", __LINE__,
2269 rte_event_dev_dump(evdev, stdout);
2272 if (stats.port_rx_dropped[0] != 1) {
2273 printf("%d:%s: port 1 drops\n", __LINE__, __func__);
2274 rte_event_dev_dump(evdev, stdout);
2277 /* each packet drop should only be counted in one place - port or dev */
2278 if (stats.rx_dropped != 0) {
2279 printf("%d:%s: port 1 dropped count not correct\n", __LINE__,
2281 rte_event_dev_dump(evdev, stdout);
2290 single_packet(struct test *t)
2292 const uint32_t MAGIC_SEQN = 7321;
2293 struct rte_event ev;
2294 struct test_event_dev_stats stats;
2295 const int rx_enq = 0;
2296 const int wrk_enq = 2;
2299 /* Create instance with 4 ports */
2300 if (init(t, 1, 4) < 0 ||
2301 create_ports(t, 4) < 0 ||
2302 create_atomic_qids(t, 1) < 0) {
2303 printf("%d: Error initializing device\n", __LINE__);
2307 /* CQ mapping to QID */
2308 err = rte_event_port_link(evdev, t->port[wrk_enq], NULL, NULL, 0);
2310 printf("%d: error mapping lb qid\n", __LINE__);
2315 if (rte_event_dev_start(evdev) < 0) {
2316 printf("%d: Error with start call\n", __LINE__);
2320 /************** Gen pkt and enqueue ****************/
2321 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
2323 printf("%d: gen of pkt failed\n", __LINE__);
2327 ev.op = RTE_EVENT_OP_NEW;
2328 ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL;
2332 arp->seqn = MAGIC_SEQN;
2334 err = rte_event_enqueue_burst(evdev, t->port[rx_enq], &ev, 1);
2336 printf("%d: Failed to enqueue\n", __LINE__);
2340 rte_event_schedule(evdev);
2342 err = test_event_dev_stats_get(evdev, &stats);
2344 printf("%d: failed to get stats\n", __LINE__);
2348 if (stats.rx_pkts != 1 ||
2349 stats.tx_pkts != 1 ||
2350 stats.port_inflight[wrk_enq] != 1) {
2351 printf("%d: Sched core didn't handle pkt as expected\n",
2353 rte_event_dev_dump(evdev, stdout);
2359 deq_pkts = rte_event_dequeue_burst(evdev, t->port[wrk_enq], &ev, 1, 0);
2361 printf("%d: Failed to deq\n", __LINE__);
2365 err = test_event_dev_stats_get(evdev, &stats);
2367 printf("%d: failed to get stats\n", __LINE__);
2371 err = test_event_dev_stats_get(evdev, &stats);
2372 if (ev.mbuf->seqn != MAGIC_SEQN) {
2373 printf("%d: magic sequence number not dequeued\n", __LINE__);
2377 rte_pktmbuf_free(ev.mbuf);
2378 err = rte_event_enqueue_burst(evdev, t->port[wrk_enq], &release_ev, 1);
2380 printf("%d: Failed to enqueue\n", __LINE__);
2383 rte_event_schedule(evdev);
2385 err = test_event_dev_stats_get(evdev, &stats);
2386 if (stats.port_inflight[wrk_enq] != 0) {
2387 printf("%d: port inflight not correct\n", __LINE__);
2396 inflight_counts(struct test *t)
2398 struct rte_event ev;
2399 struct test_event_dev_stats stats;
2400 const int rx_enq = 0;
2406 /* Create instance with 4 ports */
2407 if (init(t, 2, 3) < 0 ||
2408 create_ports(t, 3) < 0 ||
2409 create_atomic_qids(t, 2) < 0) {
2410 printf("%d: Error initializing device\n", __LINE__);
2414 /* CQ mapping to QID */
2415 err = rte_event_port_link(evdev, t->port[p1], &t->qid[0], NULL, 1);
2417 printf("%d: error mapping lb qid\n", __LINE__);
2421 err = rte_event_port_link(evdev, t->port[p2], &t->qid[1], NULL, 1);
2423 printf("%d: error mapping lb qid\n", __LINE__);
2428 if (rte_event_dev_start(evdev) < 0) {
2429 printf("%d: Error with start call\n", __LINE__);
2433 /************** FORWARD ****************/
2435 for (i = 0; i < QID1_NUM; i++) {
2436 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
2439 printf("%d: gen of pkt failed\n", __LINE__);
2443 ev.queue_id = t->qid[0];
2444 ev.op = RTE_EVENT_OP_NEW;
2446 err = rte_event_enqueue_burst(evdev, t->port[rx_enq], &ev, 1);
2448 printf("%d: Failed to enqueue\n", __LINE__);
2453 for (i = 0; i < QID2_NUM; i++) {
2454 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
2457 printf("%d: gen of pkt failed\n", __LINE__);
2460 ev.queue_id = t->qid[1];
2461 ev.op = RTE_EVENT_OP_NEW;
2463 err = rte_event_enqueue_burst(evdev, t->port[rx_enq], &ev, 1);
2465 printf("%d: Failed to enqueue\n", __LINE__);
2471 rte_event_schedule(evdev);
2473 err = test_event_dev_stats_get(evdev, &stats);
2475 printf("%d: failed to get stats\n", __LINE__);
2479 if (stats.rx_pkts != QID1_NUM + QID2_NUM ||
2480 stats.tx_pkts != QID1_NUM + QID2_NUM) {
2481 printf("%d: Sched core didn't handle pkt as expected\n",
2486 if (stats.port_inflight[p1] != QID1_NUM) {
2487 printf("%d: %s port 1 inflight not correct\n", __LINE__,
2491 if (stats.port_inflight[p2] != QID2_NUM) {
2492 printf("%d: %s port 2 inflight not correct\n", __LINE__,
2497 /************** DEQUEUE INFLIGHT COUNT CHECKS ****************/
2499 struct rte_event events[QID1_NUM + QID2_NUM];
2500 uint32_t deq_pkts = rte_event_dequeue_burst(evdev, t->port[p1], events,
2501 RTE_DIM(events), 0);
2503 if (deq_pkts != QID1_NUM) {
2504 printf("%d: Port 1: DEQUEUE inflight failed\n", __LINE__);
2507 err = test_event_dev_stats_get(evdev, &stats);
2508 if (stats.port_inflight[p1] != QID1_NUM) {
2509 printf("%d: port 1 inflight decrement after DEQ != 0\n",
2513 for (i = 0; i < QID1_NUM; i++) {
2514 err = rte_event_enqueue_burst(evdev, t->port[p1], &release_ev,
2517 printf("%d: %s rte enqueue of inf release failed\n",
2518 __LINE__, __func__);
2524 * As the scheduler core decrements inflights, it needs to run to
2525 * process packets to act on the drop messages
2527 rte_event_schedule(evdev);
2529 err = test_event_dev_stats_get(evdev, &stats);
2530 if (stats.port_inflight[p1] != 0) {
2531 printf("%d: port 1 inflight NON NULL after DROP\n", __LINE__);
2536 deq_pkts = rte_event_dequeue_burst(evdev, t->port[p2], events,
2537 RTE_DIM(events), 0);
2538 if (deq_pkts != QID2_NUM) {
2539 printf("%d: Port 2: DEQUEUE inflight failed\n", __LINE__);
2542 err = test_event_dev_stats_get(evdev, &stats);
2543 if (stats.port_inflight[p2] != QID2_NUM) {
2544 printf("%d: port 1 inflight decrement after DEQ != 0\n",
2548 for (i = 0; i < QID2_NUM; i++) {
2549 err = rte_event_enqueue_burst(evdev, t->port[p2], &release_ev,
2552 printf("%d: %s rte enqueue of inf release failed\n",
2553 __LINE__, __func__);
2559 * As the scheduler core decrements inflights, it needs to run to
2560 * process packets to act on the drop messages
2562 rte_event_schedule(evdev);
2564 err = test_event_dev_stats_get(evdev, &stats);
2565 if (stats.port_inflight[p2] != 0) {
2566 printf("%d: port 2 inflight NON NULL after DROP\n", __LINE__);
2573 rte_event_dev_dump(evdev, stdout);
2579 parallel_basic(struct test *t, int check_order)
2581 const uint8_t rx_port = 0;
2582 const uint8_t w1_port = 1;
2583 const uint8_t w3_port = 3;
2584 const uint8_t tx_port = 4;
2587 uint32_t deq_pkts, j;
2588 struct rte_mbuf *mbufs[3];
2589 struct rte_mbuf *mbufs_out[3] = { 0 };
2590 const uint32_t MAGIC_SEQN = 1234;
2592 /* Create instance with 4 ports */
2593 if (init(t, 2, tx_port + 1) < 0 ||
2594 create_ports(t, tx_port + 1) < 0 ||
2595 (check_order ? create_ordered_qids(t, 1) :
2596 create_unordered_qids(t, 1)) < 0 ||
2597 create_directed_qids(t, 1, &tx_port)) {
2598 printf("%d: Error initializing device\n", __LINE__);
2604 * We need three ports, all mapped to the same ordered qid0. Then we'll
2605 * take a packet out to each port, re-enqueue in reverse order,
2606 * then make sure the reordering has taken place properly when we
2607 * dequeue from the tx_port.
2609 * Simplified test setup diagram:
2613 * qid0 - w2_port - qid1
2617 /* CQ mapping to QID for LB ports (directed mapped on create) */
2618 for (i = w1_port; i <= w3_port; i++) {
2619 err = rte_event_port_link(evdev, t->port[i], &t->qid[0], NULL,
2622 printf("%d: error mapping lb qid\n", __LINE__);
2628 if (rte_event_dev_start(evdev) < 0) {
2629 printf("%d: Error with start call\n", __LINE__);
2633 /* Enqueue 3 packets to the rx port */
2634 for (i = 0; i < 3; i++) {
2635 struct rte_event ev;
2636 mbufs[i] = rte_gen_arp(0, t->mbuf_pool);
2638 printf("%d: gen of pkt failed\n", __LINE__);
2642 ev.queue_id = t->qid[0];
2643 ev.op = RTE_EVENT_OP_NEW;
2645 mbufs[i]->seqn = MAGIC_SEQN + i;
2647 /* generate pkt and enqueue */
2648 err = rte_event_enqueue_burst(evdev, t->port[rx_port], &ev, 1);
2650 printf("%d: Failed to enqueue pkt %u, retval = %u\n",
2656 rte_event_schedule(evdev);
2658 /* use extra slot to make logic in loops easier */
2659 struct rte_event deq_ev[w3_port + 1];
2661 /* Dequeue the 3 packets, one from each worker port */
2662 for (i = w1_port; i <= w3_port; i++) {
2663 deq_pkts = rte_event_dequeue_burst(evdev, t->port[i],
2665 if (deq_pkts != 1) {
2666 printf("%d: Failed to deq\n", __LINE__);
2667 rte_event_dev_dump(evdev, stdout);
2672 /* Enqueue each packet in reverse order, flushing after each one */
2673 for (i = w3_port; i >= w1_port; i--) {
2675 deq_ev[i].op = RTE_EVENT_OP_FORWARD;
2676 deq_ev[i].queue_id = t->qid[1];
2677 err = rte_event_enqueue_burst(evdev, t->port[i], &deq_ev[i], 1);
2679 printf("%d: Failed to enqueue\n", __LINE__);
2683 rte_event_schedule(evdev);
2685 /* dequeue from the tx ports, we should get 3 packets */
2686 deq_pkts = rte_event_dequeue_burst(evdev, t->port[tx_port], deq_ev,
2689 /* Check to see if we've got all 3 packets */
2690 if (deq_pkts != 3) {
2691 printf("%d: expected 3 pkts at tx port got %d from port %d\n",
2692 __LINE__, deq_pkts, tx_port);
2693 rte_event_dev_dump(evdev, stdout);
2697 /* Check to see if the sequence numbers are in expected order */
2699 for (j = 0 ; j < deq_pkts ; j++) {
2700 if (deq_ev[j].mbuf->seqn != MAGIC_SEQN + j) {
2702 "%d: Incorrect sequence number(%d) from port %d\n",
2703 __LINE__, mbufs_out[j]->seqn, tx_port);
2709 /* Destroy the instance */
2715 ordered_basic(struct test *t)
2717 return parallel_basic(t, 1);
2721 unordered_basic(struct test *t)
2723 return parallel_basic(t, 0);
2727 holb(struct test *t) /* test to check we avoid basic head-of-line blocking */
2729 const struct rte_event new_ev = {
2730 .op = RTE_EVENT_OP_NEW
2731 /* all other fields zero */
2733 struct rte_event ev = new_ev;
2734 unsigned int rx_port = 0; /* port we get the first flow on */
2735 char rx_port_used_stat[64];
2736 char rx_port_free_stat[64];
2737 char other_port_used_stat[64];
2739 if (init(t, 1, 2) < 0 ||
2740 create_ports(t, 2) < 0 ||
2741 create_atomic_qids(t, 1) < 0) {
2742 printf("%d: Error initializing device\n", __LINE__);
2745 int nb_links = rte_event_port_link(evdev, t->port[1], NULL, NULL, 0);
2746 if (rte_event_port_link(evdev, t->port[0], NULL, NULL, 0) != 1 ||
2748 printf("%d: Error links queue to ports\n", __LINE__);
2751 if (rte_event_dev_start(evdev) < 0) {
2752 printf("%d: Error with start call\n", __LINE__);
2756 /* send one packet and see where it goes, port 0 or 1 */
2757 if (rte_event_enqueue_burst(evdev, t->port[0], &ev, 1) != 1) {
2758 printf("%d: Error doing first enqueue\n", __LINE__);
2761 rte_event_schedule(evdev);
2763 if (rte_event_dev_xstats_by_name_get(evdev, "port_0_cq_ring_used", NULL)
2767 snprintf(rx_port_used_stat, sizeof(rx_port_used_stat),
2768 "port_%u_cq_ring_used", rx_port);
2769 snprintf(rx_port_free_stat, sizeof(rx_port_free_stat),
2770 "port_%u_cq_ring_free", rx_port);
2771 snprintf(other_port_used_stat, sizeof(other_port_used_stat),
2772 "port_%u_cq_ring_used", rx_port ^ 1);
2773 if (rte_event_dev_xstats_by_name_get(evdev, rx_port_used_stat, NULL)
2775 printf("%d: Error, first event not scheduled\n", __LINE__);
2779 /* now fill up the rx port's queue with one flow to cause HOLB */
2782 if (rte_event_enqueue_burst(evdev, t->port[0], &ev, 1) != 1) {
2783 printf("%d: Error with enqueue\n", __LINE__);
2786 rte_event_schedule(evdev);
2787 } while (rte_event_dev_xstats_by_name_get(evdev,
2788 rx_port_free_stat, NULL) != 0);
2790 /* one more packet, which needs to stay in IQ - i.e. HOLB */
2792 if (rte_event_enqueue_burst(evdev, t->port[0], &ev, 1) != 1) {
2793 printf("%d: Error with enqueue\n", __LINE__);
2796 rte_event_schedule(evdev);
2798 /* check that the other port still has an empty CQ */
2799 if (rte_event_dev_xstats_by_name_get(evdev, other_port_used_stat, NULL)
2801 printf("%d: Error, second port CQ is not empty\n", __LINE__);
2804 /* check IQ now has one packet */
2805 if (rte_event_dev_xstats_by_name_get(evdev, "qid_0_iq_0_used", NULL)
2807 printf("%d: Error, QID does not have exactly 1 packet\n",
2812 /* send another flow, which should pass the other IQ entry */
2815 if (rte_event_enqueue_burst(evdev, t->port[0], &ev, 1) != 1) {
2816 printf("%d: Error with enqueue\n", __LINE__);
2819 rte_event_schedule(evdev);
2821 if (rte_event_dev_xstats_by_name_get(evdev, other_port_used_stat, NULL)
2823 printf("%d: Error, second flow did not pass out first\n",
2828 if (rte_event_dev_xstats_by_name_get(evdev, "qid_0_iq_0_used", NULL)
2830 printf("%d: Error, QID does not have exactly 1 packet\n",
2837 rte_event_dev_dump(evdev, stdout);
2843 worker_loopback_worker_fn(void *arg)
2845 struct test *t = arg;
2846 uint8_t port = t->port[1];
2851 * Takes packets from the input port and then loops them back through
2852 * the Eventdev. Each packet gets looped through QIDs 0-8, 16 times
2853 * so each packet goes through 8*16 = 128 times.
2855 printf("%d: \tWorker function started\n", __LINE__);
2856 while (count < NUM_PACKETS) {
2857 #define BURST_SIZE 32
2858 struct rte_event ev[BURST_SIZE];
2859 uint16_t i, nb_rx = rte_event_dequeue_burst(evdev, port, ev,
2866 for (i = 0; i < nb_rx; i++) {
2868 if (ev[i].queue_id != 8) {
2869 ev[i].op = RTE_EVENT_OP_FORWARD;
2870 enqd = rte_event_enqueue_burst(evdev, port,
2873 printf("%d: Can't enqueue FWD!!\n",
2881 ev[i].mbuf->udata64++;
2882 if (ev[i].mbuf->udata64 != 16) {
2883 ev[i].op = RTE_EVENT_OP_FORWARD;
2884 enqd = rte_event_enqueue_burst(evdev, port,
2887 printf("%d: Can't enqueue FWD!!\n",
2893 /* we have hit 16 iterations through system - drop */
2894 rte_pktmbuf_free(ev[i].mbuf);
2896 ev[i].op = RTE_EVENT_OP_RELEASE;
2897 enqd = rte_event_enqueue_burst(evdev, port, &ev[i], 1);
2899 printf("%d drop enqueue failed\n", __LINE__);
2909 worker_loopback_producer_fn(void *arg)
2911 struct test *t = arg;
2912 uint8_t port = t->port[0];
2915 printf("%d: \tProducer function started\n", __LINE__);
2916 while (count < NUM_PACKETS) {
2917 struct rte_mbuf *m = 0;
2919 m = rte_pktmbuf_alloc(t->mbuf_pool);
2920 } while (m == NULL);
2924 struct rte_event ev = {
2925 .op = RTE_EVENT_OP_NEW,
2926 .queue_id = t->qid[0],
2927 .flow_id = (uintptr_t)m & 0xFFFF,
2931 if (rte_event_enqueue_burst(evdev, port, &ev, 1) != 1) {
2932 while (rte_event_enqueue_burst(evdev, port, &ev, 1) !=
2944 worker_loopback(struct test *t)
2946 /* use a single producer core, and a worker core to see what happens
2947 * if the worker loops packets back multiple times
2949 struct test_event_dev_stats stats;
2950 uint64_t print_cycles = 0, cycles = 0;
2951 uint64_t tx_pkts = 0;
2953 int w_lcore, p_lcore;
2955 if (init(t, 8, 2) < 0 ||
2956 create_atomic_qids(t, 8) < 0) {
2957 printf("%d: Error initializing device\n", __LINE__);
2961 /* RX with low max events */
2962 static struct rte_event_port_conf conf = {
2963 .dequeue_depth = 32,
2964 .enqueue_depth = 64,
2966 /* beware: this cannot be initialized in the static above as it would
2967 * only be initialized once - and this needs to be set for multiple runs
2969 conf.new_event_threshold = 512;
2971 if (rte_event_port_setup(evdev, 0, &conf) < 0) {
2972 printf("Error setting up RX port\n");
2976 /* TX with higher max events */
2977 conf.new_event_threshold = 4096;
2978 if (rte_event_port_setup(evdev, 1, &conf) < 0) {
2979 printf("Error setting up TX port\n");
2984 /* CQ mapping to QID */
2985 err = rte_event_port_link(evdev, t->port[1], NULL, NULL, 0);
2986 if (err != 8) { /* should have mapped all queues*/
2987 printf("%d: error mapping port 2 to all qids\n", __LINE__);
2991 if (rte_event_dev_start(evdev) < 0) {
2992 printf("%d: Error with start call\n", __LINE__);
2996 p_lcore = rte_get_next_lcore(
2997 /* start core */ -1,
2998 /* skip master */ 1,
3000 w_lcore = rte_get_next_lcore(p_lcore, 1, 0);
3002 rte_eal_remote_launch(worker_loopback_producer_fn, t, p_lcore);
3003 rte_eal_remote_launch(worker_loopback_worker_fn, t, w_lcore);
3005 print_cycles = cycles = rte_get_timer_cycles();
3006 while (rte_eal_get_lcore_state(p_lcore) != FINISHED ||
3007 rte_eal_get_lcore_state(w_lcore) != FINISHED) {
3009 rte_event_schedule(evdev);
3011 uint64_t new_cycles = rte_get_timer_cycles();
3013 if (new_cycles - print_cycles > rte_get_timer_hz()) {
3014 test_event_dev_stats_get(evdev, &stats);
3016 "%d: \tSched Rx = %"PRIu64", Tx = %"PRIu64"\n",
3017 __LINE__, stats.rx_pkts, stats.tx_pkts);
3019 print_cycles = new_cycles;
3021 if (new_cycles - cycles > rte_get_timer_hz() * 3) {
3022 test_event_dev_stats_get(evdev, &stats);
3023 if (stats.tx_pkts == tx_pkts) {
3024 rte_event_dev_dump(evdev, stdout);
3025 printf("Dumping xstats:\n");
3028 "%d: No schedules for seconds, deadlock\n",
3032 tx_pkts = stats.tx_pkts;
3033 cycles = new_cycles;
3036 rte_event_schedule(evdev); /* ensure all completions are flushed */
3038 rte_eal_mp_wait_lcore();
3044 static struct rte_mempool *eventdev_func_mempool;
3047 test_sw_eventdev(void)
3049 struct test *t = malloc(sizeof(struct test));
3052 /* manually initialize the op, older gcc's complain on static
3053 * initialization of struct elements that are a bitfield.
3055 release_ev.op = RTE_EVENT_OP_RELEASE;
3057 const char *eventdev_name = "event_sw0";
3058 evdev = rte_event_dev_get_dev_id(eventdev_name);
3060 printf("%d: Eventdev %s not found - creating.\n",
3061 __LINE__, eventdev_name);
3062 if (rte_vdev_init(eventdev_name, NULL) < 0) {
3063 printf("Error creating eventdev\n");
3066 evdev = rte_event_dev_get_dev_id(eventdev_name);
3068 printf("Error finding newly created eventdev\n");
3073 /* Only create mbuf pool once, reuse for each test run */
3074 if (!eventdev_func_mempool) {
3075 eventdev_func_mempool = rte_pktmbuf_pool_create(
3076 "EVENTDEV_SW_SA_MBUF_POOL",
3077 (1<<12), /* 4k buffers */
3078 32 /*MBUF_CACHE_SIZE*/,
3080 512, /* use very small mbufs */
3082 if (!eventdev_func_mempool) {
3083 printf("ERROR creating mempool\n");
3087 t->mbuf_pool = eventdev_func_mempool;
3088 printf("*** Running Single Directed Packet test...\n");
3089 ret = test_single_directed_packet(t);
3091 printf("ERROR - Single Directed Packet test FAILED.\n");
3094 printf("*** Running Directed Forward Credit test...\n");
3095 ret = test_directed_forward_credits(t);
3097 printf("ERROR - Directed Forward Credit test FAILED.\n");
3100 printf("*** Running Single Load Balanced Packet test...\n");
3101 ret = single_packet(t);
3103 printf("ERROR - Single Packet test FAILED.\n");
3106 printf("*** Running Unordered Basic test...\n");
3107 ret = unordered_basic(t);
3109 printf("ERROR - Unordered Basic test FAILED.\n");
3112 printf("*** Running Ordered Basic test...\n");
3113 ret = ordered_basic(t);
3115 printf("ERROR - Ordered Basic test FAILED.\n");
3118 printf("*** Running Burst Packets test...\n");
3119 ret = burst_packets(t);
3121 printf("ERROR - Burst Packets test FAILED.\n");
3124 printf("*** Running Load Balancing test...\n");
3125 ret = load_balancing(t);
3127 printf("ERROR - Load Balancing test FAILED.\n");
3130 printf("*** Running Prioritized Directed test...\n");
3131 ret = test_priority_directed(t);
3133 printf("ERROR - Prioritized Directed test FAILED.\n");
3136 printf("*** Running Prioritized Atomic test...\n");
3137 ret = test_priority_atomic(t);
3139 printf("ERROR - Prioritized Atomic test FAILED.\n");
3143 printf("*** Running Prioritized Ordered test...\n");
3144 ret = test_priority_ordered(t);
3146 printf("ERROR - Prioritized Ordered test FAILED.\n");
3149 printf("*** Running Prioritized Unordered test...\n");
3150 ret = test_priority_unordered(t);
3152 printf("ERROR - Prioritized Unordered test FAILED.\n");
3155 printf("*** Running Invalid QID test...\n");
3156 ret = invalid_qid(t);
3158 printf("ERROR - Invalid QID test FAILED.\n");
3161 printf("*** Running Load Balancing History test...\n");
3162 ret = load_balancing_history(t);
3164 printf("ERROR - Load Balancing History test FAILED.\n");
3167 printf("*** Running Inflight Count test...\n");
3168 ret = inflight_counts(t);
3170 printf("ERROR - Inflight Count test FAILED.\n");
3173 printf("*** Running Abuse Inflights test...\n");
3174 ret = abuse_inflights(t);
3176 printf("ERROR - Abuse Inflights test FAILED.\n");
3179 printf("*** Running XStats test...\n");
3180 ret = xstats_tests(t);
3182 printf("ERROR - XStats test FAILED.\n");
3185 printf("*** Running XStats ID Reset test...\n");
3186 ret = xstats_id_reset_tests(t);
3188 printf("ERROR - XStats ID Reset test FAILED.\n");
3191 printf("*** Running XStats Brute Force test...\n");
3192 ret = xstats_brute_force(t);
3194 printf("ERROR - XStats Brute Force test FAILED.\n");
3197 printf("*** Running XStats ID Abuse test...\n");
3198 ret = xstats_id_abuse_tests(t);
3200 printf("ERROR - XStats ID Abuse test FAILED.\n");
3203 printf("*** Running QID Priority test...\n");
3204 ret = qid_priorities(t);
3206 printf("ERROR - QID Priority test FAILED.\n");
3209 printf("*** Running Ordered Reconfigure test...\n");
3210 ret = ordered_reconfigure(t);
3212 printf("ERROR - Ordered Reconfigure test FAILED.\n");
3215 printf("*** Running Port LB Single Reconfig test...\n");
3216 ret = port_single_lb_reconfig(t);
3218 printf("ERROR - Port LB Single Reconfig test FAILED.\n");
3221 printf("*** Running Port Reconfig Credits test...\n");
3222 ret = port_reconfig_credits(t);
3224 printf("ERROR - Port Reconfig Credits Reset test FAILED.\n");
3227 printf("*** Running Head-of-line-blocking test...\n");
3230 printf("ERROR - Head-of-line-blocking test FAILED.\n");
3233 if (rte_lcore_count() >= 3) {
3234 printf("*** Running Worker loopback test...\n");
3235 ret = worker_loopback(t);
3237 printf("ERROR - Worker loopback test FAILED.\n");
3241 printf("### Not enough cores for worker loopback test.\n");
3242 printf("### Need at least 3 cores for test.\n");
3245 * Free test instance, leaving mempool initialized, and a pointer to it
3246 * in static eventdev_func_mempool, as it is re-used on re-runs
3253 REGISTER_TEST_COMMAND(eventdev_sw_autotest, test_sw_eventdev);