2 * SPDX-License-Identifier: BSD-3-Clause
3 * Copyright 2017 Cavium, Inc.
6 #include "test_pipeline_common.h"
8 /* See http://doc.dpdk.org/guides/tools/testeventdev.html for test details */
10 static __rte_always_inline int
11 pipeline_queue_nb_event_queues(struct evt_options *opt)
13 uint16_t eth_count = rte_eth_dev_count_avail();
15 return (eth_count * opt->nb_stages) + eth_count;
18 static __rte_noinline int
19 pipeline_queue_worker_single_stage_tx(void *arg)
21 PIPELINE_WORKER_SINGLE_STAGE_INIT;
23 while (t->done == false) {
24 uint16_t event = rte_event_dequeue_burst(dev, port, &ev, 1, 0);
31 if (ev.sched_type == RTE_SCHED_TYPE_ATOMIC) {
32 pipeline_event_tx(dev, port, &ev);
36 pipeline_fwd_event(&ev, RTE_SCHED_TYPE_ATOMIC);
37 pipeline_event_enqueue(dev, port, &ev);
44 static __rte_noinline int
45 pipeline_queue_worker_single_stage_fwd(void *arg)
47 PIPELINE_WORKER_SINGLE_STAGE_INIT;
48 const uint8_t *tx_queue = t->tx_evqueue_id;
50 while (t->done == false) {
51 uint16_t event = rte_event_dequeue_burst(dev, port, &ev, 1, 0);
58 ev.queue_id = tx_queue[ev.mbuf->port];
59 rte_event_eth_tx_adapter_txq_set(ev.mbuf, 0);
60 pipeline_fwd_event(&ev, RTE_SCHED_TYPE_ATOMIC);
61 pipeline_event_enqueue(dev, port, &ev);
68 static __rte_noinline int
69 pipeline_queue_worker_single_stage_burst_tx(void *arg)
71 PIPELINE_WORKER_SINGLE_STAGE_BURST_INIT;
73 while (t->done == false) {
74 uint16_t nb_rx = rte_event_dequeue_burst(dev, port, ev,
82 for (i = 0; i < nb_rx; i++) {
83 rte_prefetch0(ev[i + 1].mbuf);
84 if (ev[i].sched_type == RTE_SCHED_TYPE_ATOMIC) {
85 pipeline_event_tx(dev, port, &ev[i]);
89 pipeline_fwd_event(&ev[i],
90 RTE_SCHED_TYPE_ATOMIC);
91 pipeline_event_enqueue_burst(dev, port, ev,
100 static __rte_noinline int
101 pipeline_queue_worker_single_stage_burst_fwd(void *arg)
103 PIPELINE_WORKER_SINGLE_STAGE_BURST_INIT;
104 const uint8_t *tx_queue = t->tx_evqueue_id;
106 while (t->done == false) {
107 uint16_t nb_rx = rte_event_dequeue_burst(dev, port, ev,
115 for (i = 0; i < nb_rx; i++) {
116 rte_prefetch0(ev[i + 1].mbuf);
117 ev[i].queue_id = tx_queue[ev[i].mbuf->port];
118 rte_event_eth_tx_adapter_txq_set(ev[i].mbuf, 0);
119 pipeline_fwd_event(&ev[i], RTE_SCHED_TYPE_ATOMIC);
122 pipeline_event_enqueue_burst(dev, port, ev, nb_rx);
123 w->processed_pkts += nb_rx;
130 static __rte_noinline int
131 pipeline_queue_worker_multi_stage_tx(void *arg)
133 PIPELINE_WORKER_MULTI_STAGE_INIT;
134 const uint8_t *tx_queue = t->tx_evqueue_id;
136 while (t->done == false) {
137 uint16_t event = rte_event_dequeue_burst(dev, port, &ev, 1, 0);
144 cq_id = ev.queue_id % nb_stages;
146 if (ev.queue_id == tx_queue[ev.mbuf->port]) {
147 pipeline_event_tx(dev, port, &ev);
153 pipeline_fwd_event(&ev, cq_id != last_queue ?
154 sched_type_list[cq_id] :
155 RTE_SCHED_TYPE_ATOMIC);
156 pipeline_event_enqueue(dev, port, &ev);
162 static __rte_noinline int
163 pipeline_queue_worker_multi_stage_fwd(void *arg)
165 PIPELINE_WORKER_MULTI_STAGE_INIT;
166 const uint8_t *tx_queue = t->tx_evqueue_id;
168 while (t->done == false) {
169 uint16_t event = rte_event_dequeue_burst(dev, port, &ev, 1, 0);
176 cq_id = ev.queue_id % nb_stages;
178 if (cq_id == last_queue) {
179 ev.queue_id = tx_queue[ev.mbuf->port];
180 rte_event_eth_tx_adapter_txq_set(ev.mbuf, 0);
181 pipeline_fwd_event(&ev, RTE_SCHED_TYPE_ATOMIC);
182 pipeline_event_enqueue(dev, port, &ev);
186 pipeline_fwd_event(&ev, sched_type_list[cq_id]);
187 pipeline_event_enqueue(dev, port, &ev);
194 static __rte_noinline int
195 pipeline_queue_worker_multi_stage_burst_tx(void *arg)
197 PIPELINE_WORKER_MULTI_STAGE_BURST_INIT;
198 const uint8_t *tx_queue = t->tx_evqueue_id;
200 while (t->done == false) {
201 uint16_t nb_rx = rte_event_dequeue_burst(dev, port, ev,
209 for (i = 0; i < nb_rx; i++) {
210 rte_prefetch0(ev[i + 1].mbuf);
211 cq_id = ev[i].queue_id % nb_stages;
213 if (ev[i].queue_id == tx_queue[ev[i].mbuf->port]) {
214 pipeline_event_tx(dev, port, &ev[i]);
220 pipeline_fwd_event(&ev[i], cq_id != last_queue ?
221 sched_type_list[cq_id] :
222 RTE_SCHED_TYPE_ATOMIC);
223 pipeline_event_enqueue_burst(dev, port, ev, nb_rx);
230 static __rte_noinline int
231 pipeline_queue_worker_multi_stage_burst_fwd(void *arg)
233 PIPELINE_WORKER_MULTI_STAGE_BURST_INIT;
234 const uint8_t *tx_queue = t->tx_evqueue_id;
236 while (t->done == false) {
237 uint16_t processed_pkts = 0;
238 uint16_t nb_rx = rte_event_dequeue_burst(dev, port, ev,
246 for (i = 0; i < nb_rx; i++) {
247 rte_prefetch0(ev[i + 1].mbuf);
248 cq_id = ev[i].queue_id % nb_stages;
250 if (cq_id == last_queue) {
251 ev[i].queue_id = tx_queue[ev[i].mbuf->port];
252 rte_event_eth_tx_adapter_txq_set(ev[i].mbuf, 0);
253 pipeline_fwd_event(&ev[i],
254 RTE_SCHED_TYPE_ATOMIC);
258 pipeline_fwd_event(&ev[i],
259 sched_type_list[cq_id]);
263 pipeline_event_enqueue_burst(dev, port, ev, nb_rx);
264 w->processed_pkts += processed_pkts;
271 worker_wrapper(void *arg)
273 struct worker_data *w = arg;
274 struct evt_options *opt = w->t->opt;
275 const bool burst = evt_has_burst_mode(w->dev_id);
276 const bool internal_port = w->t->internal_port;
277 const uint8_t nb_stages = opt->nb_stages;
280 if (nb_stages == 1) {
281 if (!burst && internal_port)
282 return pipeline_queue_worker_single_stage_tx(arg);
283 else if (!burst && !internal_port)
284 return pipeline_queue_worker_single_stage_fwd(arg);
285 else if (burst && internal_port)
286 return pipeline_queue_worker_single_stage_burst_tx(arg);
287 else if (burst && !internal_port)
288 return pipeline_queue_worker_single_stage_burst_fwd(
291 if (!burst && internal_port)
292 return pipeline_queue_worker_multi_stage_tx(arg);
293 else if (!burst && !internal_port)
294 return pipeline_queue_worker_multi_stage_fwd(arg);
295 else if (burst && internal_port)
296 return pipeline_queue_worker_multi_stage_burst_tx(arg);
297 else if (burst && !internal_port)
298 return pipeline_queue_worker_multi_stage_burst_fwd(arg);
301 rte_panic("invalid worker\n");
305 pipeline_queue_launch_lcores(struct evt_test *test, struct evt_options *opt)
307 return pipeline_launch_lcores(test, opt, worker_wrapper);
311 pipeline_queue_eventdev_setup(struct evt_test *test, struct evt_options *opt)
316 int nb_stages = opt->nb_stages;
318 uint8_t tx_evport_id = 0;
319 uint8_t tx_evqueue_id[RTE_MAX_ETHPORTS];
320 uint8_t queue_arr[RTE_EVENT_MAX_QUEUES_PER_DEV];
321 uint8_t nb_worker_queues = 0;
323 struct rte_event_dev_info info;
324 struct test_pipeline *t = evt_test_priv(test);
326 nb_ports = evt_nr_active_lcores(opt->wlcores);
327 nb_queues = rte_eth_dev_count_avail() * (nb_stages);
329 /* One queue for Tx adapter per port */
330 nb_queues += rte_eth_dev_count_avail();
332 memset(tx_evqueue_id, 0, sizeof(uint8_t) * RTE_MAX_ETHPORTS);
333 memset(queue_arr, 0, sizeof(uint8_t) * RTE_EVENT_MAX_QUEUES_PER_DEV);
335 rte_event_dev_info_get(opt->dev_id, &info);
336 ret = evt_configure_eventdev(opt, nb_queues, nb_ports);
338 evt_err("failed to configure eventdev %d", opt->dev_id);
342 struct rte_event_queue_conf q_conf = {
343 .priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
344 .nb_atomic_flows = opt->nb_flows,
345 .nb_atomic_order_sequences = opt->nb_flows,
347 /* queue configurations */
348 for (queue = 0; queue < nb_queues; queue++) {
351 q_conf.event_queue_cfg = 0;
352 slot = queue % (nb_stages + 1);
353 if (slot == nb_stages) {
354 q_conf.schedule_type = RTE_SCHED_TYPE_ATOMIC;
355 if (!t->internal_port) {
356 q_conf.event_queue_cfg =
357 RTE_EVENT_QUEUE_CFG_SINGLE_LINK;
359 tx_evqueue_id[prod++] = queue;
361 q_conf.schedule_type = opt->sched_type_list[slot];
362 queue_arr[nb_worker_queues] = queue;
366 ret = rte_event_queue_setup(opt->dev_id, queue, &q_conf);
368 evt_err("failed to setup queue=%d", queue);
373 if (opt->wkr_deq_dep > info.max_event_port_dequeue_depth)
374 opt->wkr_deq_dep = info.max_event_port_dequeue_depth;
376 /* port configuration */
377 const struct rte_event_port_conf p_conf = {
378 .dequeue_depth = opt->wkr_deq_dep,
379 .enqueue_depth = info.max_event_port_dequeue_depth,
380 .new_event_threshold = info.max_num_events,
383 if (!t->internal_port) {
384 ret = pipeline_event_port_setup(test, opt, queue_arr,
385 nb_worker_queues, p_conf);
389 ret = pipeline_event_port_setup(test, opt, NULL, nb_queues,
395 * The pipelines are setup in the following manner:
397 * eth_dev_count = 2, nb_stages = 2.
402 * event queue pipelines:
403 * eth0 -> q0 -> q1 -> (q2->tx)
404 * eth1 -> q3 -> q4 -> (q5->tx)
406 * q2, q5 configured as ATOMIC | SINGLE_LINK
409 ret = pipeline_event_rx_adapter_setup(opt, nb_stages + 1, p_conf);
413 ret = pipeline_event_tx_adapter_setup(opt, p_conf);
417 if (!evt_has_distributed_sched(opt->dev_id)) {
419 rte_event_dev_service_id_get(opt->dev_id, &service_id);
420 ret = evt_service_setup(service_id);
422 evt_err("No service lcore found to run event dev.");
427 /* Connect the tx_evqueue_id to the Tx adapter port */
428 if (!t->internal_port) {
429 RTE_ETH_FOREACH_DEV(prod) {
430 ret = rte_event_eth_tx_adapter_event_port_get(prod,
433 evt_err("Unable to get Tx adptr[%d] evprt[%d]",
438 if (rte_event_port_link(opt->dev_id, tx_evport_id,
439 &tx_evqueue_id[prod],
441 evt_err("Unable to link Tx adptr[%d] evprt[%d]",
448 ret = rte_event_dev_start(opt->dev_id);
450 evt_err("failed to start eventdev %d", opt->dev_id);
455 RTE_ETH_FOREACH_DEV(prod) {
456 ret = rte_eth_dev_start(prod);
458 evt_err("Ethernet dev [%d] failed to start."
459 " Using synthetic producer", prod);
465 RTE_ETH_FOREACH_DEV(prod) {
466 ret = rte_event_eth_rx_adapter_start(prod);
468 evt_err("Rx adapter[%d] start failed", prod);
472 ret = rte_event_eth_tx_adapter_start(prod);
474 evt_err("Tx adapter[%d] start failed", prod);
479 memcpy(t->tx_evqueue_id, tx_evqueue_id, sizeof(uint8_t) *
486 pipeline_queue_opt_dump(struct evt_options *opt)
488 pipeline_opt_dump(opt, pipeline_queue_nb_event_queues(opt));
492 pipeline_queue_opt_check(struct evt_options *opt)
494 return pipeline_opt_check(opt, pipeline_queue_nb_event_queues(opt));
498 pipeline_queue_capability_check(struct evt_options *opt)
500 struct rte_event_dev_info dev_info;
502 rte_event_dev_info_get(opt->dev_id, &dev_info);
503 if (dev_info.max_event_queues < pipeline_queue_nb_event_queues(opt) ||
504 dev_info.max_event_ports <
505 evt_nr_active_lcores(opt->wlcores)) {
506 evt_err("not enough eventdev queues=%d/%d or ports=%d/%d",
507 pipeline_queue_nb_event_queues(opt),
508 dev_info.max_event_queues,
509 evt_nr_active_lcores(opt->wlcores),
510 dev_info.max_event_ports);
516 static const struct evt_test_ops pipeline_queue = {
517 .cap_check = pipeline_queue_capability_check,
518 .opt_check = pipeline_queue_opt_check,
519 .opt_dump = pipeline_queue_opt_dump,
520 .test_setup = pipeline_test_setup,
521 .mempool_setup = pipeline_mempool_setup,
522 .ethdev_setup = pipeline_ethdev_setup,
523 .eventdev_setup = pipeline_queue_eventdev_setup,
524 .launch_lcores = pipeline_queue_launch_lcores,
525 .eventdev_destroy = pipeline_eventdev_destroy,
526 .mempool_destroy = pipeline_mempool_destroy,
527 .ethdev_destroy = pipeline_ethdev_destroy,
528 .test_result = pipeline_test_result,
529 .test_destroy = pipeline_test_destroy,
532 EVT_TEST_REGISTER(pipeline_queue);