4 * Copyright(c) 2017 Cavium networks. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of Cavium networks nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <rte_atomic.h>
34 #include <rte_common.h>
35 #include <rte_cycles.h>
36 #include <rte_debug.h>
38 #include <rte_ethdev.h>
39 #include <rte_eventdev.h>
40 #include <rte_hexdump.h>
42 #include <rte_malloc.h>
43 #include <rte_memcpy.h>
44 #include <rte_launch.h>
45 #include <rte_lcore.h>
46 #include <rte_per_lcore.h>
47 #include <rte_random.h>
51 #define NUM_PACKETS (1 << 18)
52 #define MAX_EVENTS (16 * 1024)
55 static struct rte_mempool *eventdev_test_mempool;
60 uint8_t sub_event_type;
69 const char *eventdev_name = "event_octeontx";
71 evdev = rte_event_dev_get_dev_id(eventdev_name);
73 printf("%d: Eventdev %s not found - creating.\n",
74 __LINE__, eventdev_name);
75 if (rte_eal_vdev_init(eventdev_name, NULL) < 0) {
76 printf("Error creating eventdev %s\n", eventdev_name);
79 evdev = rte_event_dev_get_dev_id(eventdev_name);
81 printf("Error finding newly created eventdev\n");
90 testsuite_teardown(void)
92 rte_event_dev_close(evdev);
96 devconf_set_default_sane_values(struct rte_event_dev_config *dev_conf,
97 struct rte_event_dev_info *info)
99 memset(dev_conf, 0, sizeof(struct rte_event_dev_config));
100 dev_conf->dequeue_timeout_ns = info->min_dequeue_timeout_ns;
101 dev_conf->nb_event_ports = info->max_event_ports;
102 dev_conf->nb_event_queues = info->max_event_queues;
103 dev_conf->nb_event_queue_flows = info->max_event_queue_flows;
104 dev_conf->nb_event_port_dequeue_depth =
105 info->max_event_port_dequeue_depth;
106 dev_conf->nb_event_port_enqueue_depth =
107 info->max_event_port_enqueue_depth;
108 dev_conf->nb_event_port_enqueue_depth =
109 info->max_event_port_enqueue_depth;
110 dev_conf->nb_events_limit =
111 info->max_num_events;
115 TEST_EVENTDEV_SETUP_DEFAULT,
116 TEST_EVENTDEV_SETUP_PRIORITY,
117 TEST_EVENTDEV_SETUP_DEQUEUE_TIMEOUT,
121 _eventdev_setup(int mode)
124 struct rte_event_dev_config dev_conf;
125 struct rte_event_dev_info info;
126 const char *pool_name = "evdev_octeontx_test_pool";
128 /* Create and destrory pool for each test case to make it standalone */
129 eventdev_test_mempool = rte_pktmbuf_pool_create(pool_name,
131 0 /*MBUF_CACHE_SIZE*/,
133 512, /* Use very small mbufs */
135 if (!eventdev_test_mempool) {
136 printf("ERROR creating mempool\n");
140 ret = rte_event_dev_info_get(evdev, &info);
141 TEST_ASSERT_SUCCESS(ret, "Failed to get event dev info");
142 TEST_ASSERT(info.max_num_events >= (int32_t)MAX_EVENTS,
143 "max_num_events=%d < max_events=%d",
144 info.max_num_events, MAX_EVENTS);
146 devconf_set_default_sane_values(&dev_conf, &info);
147 if (mode == TEST_EVENTDEV_SETUP_DEQUEUE_TIMEOUT)
148 dev_conf.event_dev_cfg |= RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT;
150 ret = rte_event_dev_configure(evdev, &dev_conf);
151 TEST_ASSERT_SUCCESS(ret, "Failed to configure eventdev");
153 if (mode == TEST_EVENTDEV_SETUP_PRIORITY) {
154 /* Configure event queues(0 to n) with
155 * RTE_EVENT_DEV_PRIORITY_HIGHEST to
156 * RTE_EVENT_DEV_PRIORITY_LOWEST
158 uint8_t step = (RTE_EVENT_DEV_PRIORITY_LOWEST + 1) /
159 rte_event_queue_count(evdev);
160 for (i = 0; i < rte_event_queue_count(evdev); i++) {
161 struct rte_event_queue_conf queue_conf;
163 ret = rte_event_queue_default_conf_get(evdev, i,
165 TEST_ASSERT_SUCCESS(ret, "Failed to get def_conf%d", i);
166 queue_conf.priority = i * step;
167 ret = rte_event_queue_setup(evdev, i, &queue_conf);
168 TEST_ASSERT_SUCCESS(ret, "Failed to setup queue=%d", i);
172 /* Configure event queues with default priority */
173 for (i = 0; i < rte_event_queue_count(evdev); i++) {
174 ret = rte_event_queue_setup(evdev, i, NULL);
175 TEST_ASSERT_SUCCESS(ret, "Failed to setup queue=%d", i);
178 /* Configure event ports */
179 for (i = 0; i < rte_event_port_count(evdev); i++) {
180 ret = rte_event_port_setup(evdev, i, NULL);
181 TEST_ASSERT_SUCCESS(ret, "Failed to setup port=%d", i);
182 ret = rte_event_port_link(evdev, i, NULL, NULL, 0);
183 TEST_ASSERT(ret >= 0, "Failed to link all queues port=%d", i);
186 ret = rte_event_dev_start(evdev);
187 TEST_ASSERT_SUCCESS(ret, "Failed to start device");
195 return _eventdev_setup(TEST_EVENTDEV_SETUP_DEFAULT);
199 eventdev_teardown(void)
201 rte_event_dev_stop(evdev);
202 rte_mempool_free(eventdev_test_mempool);
206 update_event_and_validation_attr(struct rte_mbuf *m, struct rte_event *ev,
207 uint32_t flow_id, uint8_t event_type,
208 uint8_t sub_event_type, uint8_t sched_type,
209 uint8_t queue, uint8_t port)
211 struct event_attr *attr;
213 /* Store the event attributes in mbuf for future reference */
214 attr = rte_pktmbuf_mtod(m, struct event_attr *);
215 attr->flow_id = flow_id;
216 attr->event_type = event_type;
217 attr->sub_event_type = sub_event_type;
218 attr->sched_type = sched_type;
222 ev->flow_id = flow_id;
223 ev->sub_event_type = sub_event_type;
224 ev->event_type = event_type;
225 /* Inject the new event */
226 ev->op = RTE_EVENT_OP_NEW;
227 ev->sched_type = sched_type;
228 ev->queue_id = queue;
233 inject_events(uint32_t flow_id, uint8_t event_type, uint8_t sub_event_type,
234 uint8_t sched_type, uint8_t queue, uint8_t port,
240 for (i = 0; i < events; i++) {
241 struct rte_event ev = {.event = 0, .u64 = 0};
243 m = rte_pktmbuf_alloc(eventdev_test_mempool);
244 TEST_ASSERT_NOT_NULL(m, "mempool alloc failed");
247 update_event_and_validation_attr(m, &ev, flow_id, event_type,
248 sub_event_type, sched_type, queue, port);
249 rte_event_enqueue_burst(evdev, port, &ev, 1);
255 check_excess_events(uint8_t port)
258 uint16_t valid_event;
261 /* Check for excess events, try for a few times and exit */
262 for (i = 0; i < 32; i++) {
263 valid_event = rte_event_dequeue_burst(evdev, port, &ev, 1, 0);
265 TEST_ASSERT_SUCCESS(valid_event, "Unexpected valid event=%d",
272 generate_random_events(const unsigned int total_events)
274 struct rte_event_dev_info info;
278 ret = rte_event_dev_info_get(evdev, &info);
279 TEST_ASSERT_SUCCESS(ret, "Failed to get event dev info");
280 for (i = 0; i < total_events; i++) {
282 rte_rand() % info.max_event_queue_flows /*flow_id */,
283 rte_rand() % (RTE_EVENT_TYPE_CPU + 1) /* event_type */,
284 rte_rand() % 256 /* sub_event_type */,
285 rte_rand() % (RTE_SCHED_TYPE_PARALLEL + 1),
286 rte_rand() % rte_event_queue_count(evdev) /* queue */,
297 validate_event(struct rte_event *ev)
299 struct event_attr *attr;
301 attr = rte_pktmbuf_mtod(ev->mbuf, struct event_attr *);
302 TEST_ASSERT_EQUAL(attr->flow_id, ev->flow_id,
303 "flow_id mismatch enq=%d deq =%d",
304 attr->flow_id, ev->flow_id);
305 TEST_ASSERT_EQUAL(attr->event_type, ev->event_type,
306 "event_type mismatch enq=%d deq =%d",
307 attr->event_type, ev->event_type);
308 TEST_ASSERT_EQUAL(attr->sub_event_type, ev->sub_event_type,
309 "sub_event_type mismatch enq=%d deq =%d",
310 attr->sub_event_type, ev->sub_event_type);
311 TEST_ASSERT_EQUAL(attr->sched_type, ev->sched_type,
312 "sched_type mismatch enq=%d deq =%d",
313 attr->sched_type, ev->sched_type);
314 TEST_ASSERT_EQUAL(attr->queue, ev->queue_id,
315 "queue mismatch enq=%d deq =%d",
316 attr->queue, ev->queue_id);
320 typedef int (*validate_event_cb)(uint32_t index, uint8_t port,
321 struct rte_event *ev);
324 consume_events(uint8_t port, const uint32_t total_events, validate_event_cb fn)
327 uint16_t valid_event;
328 uint32_t events = 0, forward_progress_cnt = 0, index = 0;
332 if (++forward_progress_cnt > UINT16_MAX) {
333 printf("Detected deadlock\n");
337 valid_event = rte_event_dequeue_burst(evdev, port, &ev, 1, 0);
341 forward_progress_cnt = 0;
342 ret = validate_event(&ev);
347 ret = fn(index, port, &ev);
348 TEST_ASSERT_SUCCESS(ret,
349 "Failed to validate test specific event");
354 rte_pktmbuf_free(ev.mbuf);
355 if (++events >= total_events)
359 return check_excess_events(port);
363 validate_simple_enqdeq(uint32_t index, uint8_t port, struct rte_event *ev)
366 TEST_ASSERT_EQUAL(index, ev->mbuf->seqn, "index=%d != seqn=%d", index,
372 test_simple_enqdeq(uint8_t sched_type)
376 ret = inject_events(0 /*flow_id */,
377 RTE_EVENT_TYPE_CPU /* event_type */,
378 0 /* sub_event_type */,
386 return consume_events(0 /* port */, MAX_EVENTS, validate_simple_enqdeq);
390 test_simple_enqdeq_ordered(void)
392 return test_simple_enqdeq(RTE_SCHED_TYPE_ORDERED);
396 test_simple_enqdeq_atomic(void)
398 return test_simple_enqdeq(RTE_SCHED_TYPE_ATOMIC);
402 test_simple_enqdeq_parallel(void)
404 return test_simple_enqdeq(RTE_SCHED_TYPE_PARALLEL);
408 * Generate a prescribed number of events and spread them across available
409 * queues. On dequeue, using single event port(port 0) verify the enqueued
413 test_multi_queue_enq_single_port_deq(void)
417 ret = generate_random_events(MAX_EVENTS);
421 return consume_events(0 /* port */, MAX_EVENTS, NULL);
424 static struct unit_test_suite eventdev_octeontx_testsuite = {
425 .suite_name = "eventdev octeontx unit test suite",
426 .setup = testsuite_setup,
427 .teardown = testsuite_teardown,
429 TEST_CASE_ST(eventdev_setup, eventdev_teardown,
430 test_simple_enqdeq_ordered),
431 TEST_CASE_ST(eventdev_setup, eventdev_teardown,
432 test_simple_enqdeq_atomic),
433 TEST_CASE_ST(eventdev_setup, eventdev_teardown,
434 test_simple_enqdeq_parallel),
435 TEST_CASE_ST(eventdev_setup, eventdev_teardown,
436 test_multi_queue_enq_single_port_deq),
437 TEST_CASES_END() /**< NULL terminate unit test array */
442 test_eventdev_octeontx(void)
444 return unit_test_suite_runner(&eventdev_octeontx_testsuite);
447 REGISTER_TEST_COMMAND(eventdev_octeontx_autotest, test_eventdev_octeontx);