dfbff0023865fbab322e0b579ff6e549e4799185
[dpdk.git] / test / test / test_eventdev_sw.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2016-2017 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
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
16  *       distribution.
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.
20  *
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.
32  */
33
34 #include <stdio.h>
35 #include <string.h>
36 #include <stdint.h>
37 #include <errno.h>
38 #include <unistd.h>
39 #include <sys/queue.h>
40
41 #include <rte_memory.h>
42 #include <rte_memzone.h>
43 #include <rte_launch.h>
44 #include <rte_eal.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
51 #include <rte_eventdev.h>
52 #include "test.h"
53
54 #define MAX_PORTS 16
55 #define MAX_QIDS 16
56 #define NUM_PACKETS (1<<18)
57
58 static int evdev;
59
60 struct test {
61         struct rte_mempool *mbuf_pool;
62         uint8_t port[MAX_PORTS];
63         uint8_t qid[MAX_QIDS];
64         int nb_qids;
65 };
66
67
68 struct test_event_dev_stats {
69         uint64_t rx_pkts;       /**< Total packets received */
70         uint64_t rx_dropped;    /**< Total packets dropped (Eg Invalid QID) */
71         uint64_t tx_pkts;       /**< Total packets transmitted */
72
73         /** Packets received on this port */
74         uint64_t port_rx_pkts[MAX_PORTS];
75         /** Packets dropped on this port */
76         uint64_t port_rx_dropped[MAX_PORTS];
77         /** Packets inflight on this port */
78         uint64_t port_inflight[MAX_PORTS];
79         /** Packets transmitted on this port */
80         uint64_t port_tx_pkts[MAX_PORTS];
81         /** Packets received on this qid */
82         uint64_t qid_rx_pkts[MAX_QIDS];
83         /** Packets dropped on this qid */
84         uint64_t qid_rx_dropped[MAX_QIDS];
85         /** Packets transmitted on this qid */
86         uint64_t qid_tx_pkts[MAX_QIDS];
87 };
88
89 static struct rte_mempool *eventdev_func_mempool;
90
91 static int
92 test_sw_eventdev(void)
93 {
94         struct test *t = malloc(sizeof(struct test));
95
96         const char *eventdev_name = "event_sw0";
97         evdev = rte_event_dev_get_dev_id(eventdev_name);
98         if (evdev < 0) {
99                 printf("%d: Eventdev %s not found - creating.\n",
100                                 __LINE__, eventdev_name);
101                 if (rte_eal_vdev_init(eventdev_name, NULL) < 0) {
102                         printf("Error creating eventdev\n");
103                         return -1;
104                 }
105                 evdev = rte_event_dev_get_dev_id(eventdev_name);
106                 if (evdev < 0) {
107                         printf("Error finding newly created eventdev\n");
108                         return -1;
109                 }
110         }
111
112         /* Only create mbuf pool once, reuse for each test run */
113         if (!eventdev_func_mempool) {
114                 eventdev_func_mempool = rte_pktmbuf_pool_create(
115                                 "EVENTDEV_SW_SA_MBUF_POOL",
116                                 (1<<12), /* 4k buffers */
117                                 32 /*MBUF_CACHE_SIZE*/,
118                                 0,
119                                 512, /* use very small mbufs */
120                                 rte_socket_id());
121                 if (!eventdev_func_mempool) {
122                         printf("ERROR creating mempool\n");
123                         return -1;
124                 }
125         }
126         t->mbuf_pool = eventdev_func_mempool;
127
128         /*
129          * Free test instance, leaving mempool initialized, and a pointer to it
130          * in static eventdev_func_mempool, as it is re-used on re-runs
131          */
132         free(t);
133
134         return 0;
135 }
136
137 REGISTER_TEST_COMMAND(eventdev_sw_autotest, test_sw_eventdev);