2 * SPDX-License-Identifier: BSD-3-Clause
3 * Copyright 2017 Cavium, Inc.
6 #include "test_pipeline_common.h"
9 pipeline_test_result(struct evt_test *test, struct evt_options *opt)
14 struct test_pipeline *t = evt_test_priv(test);
16 evt_info("Packet distribution across worker cores :");
17 for (i = 0; i < t->nb_workers; i++)
18 total += t->worker[i].processed_pkts;
19 for (i = 0; i < t->nb_workers; i++)
20 evt_info("Worker %d packets: "CLGRN"%"PRIx64""CLNRM" percentage:"
21 CLGRN" %3.2f"CLNRM, i,
22 t->worker[i].processed_pkts,
23 (((double)t->worker[i].processed_pkts)/total)
29 pipeline_opt_dump(struct evt_options *opt, uint8_t nb_queues)
31 evt_dump("nb_worker_lcores", "%d", evt_nr_active_lcores(opt->wlcores));
32 evt_dump_worker_lcores(opt);
33 evt_dump_nb_stages(opt);
34 evt_dump("nb_evdev_ports", "%d", pipeline_nb_event_ports(opt));
35 evt_dump("nb_evdev_queues", "%d", nb_queues);
36 evt_dump_queue_priority(opt);
37 evt_dump_sched_type_list(opt);
38 evt_dump_producer_type(opt);
39 evt_dump("nb_eth_rx_queues", "%d", opt->eth_queues);
40 evt_dump("event_vector", "%d", opt->ena_vector);
41 if (opt->ena_vector) {
42 evt_dump("vector_size", "%d", opt->vector_size);
43 evt_dump("vector_tmo_ns", "%" PRIu64 "", opt->vector_tmo_nsec);
47 static inline uint64_t
48 processed_pkts(struct test_pipeline *t)
53 for (i = 0; i < t->nb_workers; i++)
54 total += t->worker[i].processed_pkts;
60 pipeline_launch_lcores(struct evt_test *test, struct evt_options *opt,
61 int (*worker)(void *))
64 struct test_pipeline *t = evt_test_priv(test);
68 RTE_LCORE_FOREACH_WORKER(lcore_id) {
69 if (!(opt->wlcores[lcore_id]))
72 ret = rte_eal_remote_launch(worker,
73 &t->worker[port_idx], lcore_id);
75 evt_err("failed to launch worker %d", lcore_id);
81 uint64_t perf_cycles = rte_get_timer_cycles();
82 const uint64_t perf_sample = rte_get_timer_hz();
84 static float total_mpps;
85 static uint64_t samples;
87 uint64_t prev_pkts = 0;
89 while (t->done == false) {
90 const uint64_t new_cycles = rte_get_timer_cycles();
92 if ((new_cycles - perf_cycles) > perf_sample) {
93 const uint64_t curr_pkts = processed_pkts(t);
95 float mpps = (float)(curr_pkts - prev_pkts)/1000000;
97 prev_pkts = curr_pkts;
98 perf_cycles = new_cycles;
101 printf(CLGRN"\r%.3f mpps avg %.3f mpps"CLNRM,
102 mpps, total_mpps/samples);
111 pipeline_opt_check(struct evt_options *opt, uint64_t nb_queues)
115 /* N worker + main */
118 if (opt->prod_type != EVT_PROD_TYPE_ETH_RX_ADPTR) {
119 evt_err("Invalid producer type '%s' valid producer '%s'",
120 evt_prod_id_to_name(opt->prod_type),
121 evt_prod_id_to_name(EVT_PROD_TYPE_ETH_RX_ADPTR));
125 if (!rte_eth_dev_count_avail()) {
126 evt_err("test needs minimum 1 ethernet dev");
130 if (rte_lcore_count() < lcores) {
131 evt_err("test need minimum %d lcores", lcores);
135 /* Validate worker lcores */
136 if (evt_lcores_has_overlap(opt->wlcores, rte_get_main_lcore())) {
137 evt_err("worker lcores overlaps with main lcore");
140 if (evt_has_disabled_lcore(opt->wlcores)) {
141 evt_err("one or more workers lcores are not enabled");
144 if (!evt_has_active_lcore(opt->wlcores)) {
145 evt_err("minimum one worker is required");
149 if (nb_queues > EVT_MAX_QUEUES) {
150 evt_err("number of queues exceeds %d", EVT_MAX_QUEUES);
153 if (pipeline_nb_event_ports(opt) > EVT_MAX_PORTS) {
154 evt_err("number of ports exceeds %d", EVT_MAX_PORTS);
158 if (evt_has_invalid_stage(opt))
161 if (evt_has_invalid_sched_type(opt))
167 #define NB_RX_DESC 128
168 #define NB_TX_DESC 512
170 pipeline_ethdev_setup(struct evt_test *test, struct evt_options *opt)
174 uint8_t nb_queues = 1;
175 struct test_pipeline *t = evt_test_priv(test);
176 struct rte_eth_rxconf rx_conf;
177 struct rte_eth_conf port_conf = {
179 .mq_mode = ETH_MQ_RX_RSS,
184 .rss_hf = ETH_RSS_IP,
189 if (!rte_eth_dev_count_avail()) {
190 evt_err("No ethernet ports found.");
194 if (opt->max_pkt_sz < RTE_ETHER_MIN_LEN) {
195 evt_err("max_pkt_sz can not be less than %d",
200 port_conf.rxmode.mtu = opt->max_pkt_sz - RTE_ETHER_HDR_LEN -
202 if (port_conf.rxmode.mtu > RTE_ETHER_MTU)
203 port_conf.rxmode.offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
205 t->internal_port = 1;
206 RTE_ETH_FOREACH_DEV(i) {
207 struct rte_eth_dev_info dev_info;
208 struct rte_eth_conf local_port_conf = port_conf;
211 ret = rte_event_eth_tx_adapter_caps_get(opt->dev_id, i, &caps);
213 evt_err("failed to get event tx adapter[%d] caps", i);
217 if (!(caps & RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT))
218 t->internal_port = 0;
220 ret = rte_event_eth_rx_adapter_caps_get(opt->dev_id, i, &caps);
222 evt_err("failed to get event tx adapter[%d] caps", i);
226 if (!(caps & RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT))
227 local_port_conf.rxmode.offloads |=
228 DEV_RX_OFFLOAD_RSS_HASH;
230 ret = rte_eth_dev_info_get(i, &dev_info);
232 evt_err("Error during getting device (port %u) info: %s\n",
237 /* Enable mbuf fast free if PMD has the capability. */
238 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
239 local_port_conf.txmode.offloads |=
240 DEV_TX_OFFLOAD_MBUF_FAST_FREE;
242 rx_conf = dev_info.default_rxconf;
243 rx_conf.offloads = port_conf.rxmode.offloads;
245 local_port_conf.rx_adv_conf.rss_conf.rss_hf &=
246 dev_info.flow_type_rss_offloads;
247 if (local_port_conf.rx_adv_conf.rss_conf.rss_hf !=
248 port_conf.rx_adv_conf.rss_conf.rss_hf) {
249 evt_info("Port %u modified RSS hash function based on hardware support,"
250 "requested:%#"PRIx64" configured:%#"PRIx64"",
252 port_conf.rx_adv_conf.rss_conf.rss_hf,
253 local_port_conf.rx_adv_conf.rss_conf.rss_hf);
256 if (rte_eth_dev_configure(i, opt->eth_queues, nb_queues,
257 &local_port_conf) < 0) {
258 evt_err("Failed to configure eth port [%d]", i);
262 for (j = 0; j < opt->eth_queues; j++) {
263 if (rte_eth_rx_queue_setup(
264 i, j, NB_RX_DESC, rte_socket_id(), &rx_conf,
265 opt->per_port_pool ? t->pool[i] :
267 evt_err("Failed to setup eth port [%d] rx_queue: %d.",
273 if (rte_eth_tx_queue_setup(i, 0, NB_TX_DESC,
274 rte_socket_id(), NULL) < 0) {
275 evt_err("Failed to setup eth port [%d] tx_queue: %d.",
280 ret = rte_eth_promiscuous_enable(i);
282 evt_err("Failed to enable promiscuous mode for eth port [%d]: %s",
283 i, rte_strerror(-ret));
292 pipeline_event_port_setup(struct evt_test *test, struct evt_options *opt,
293 uint8_t *queue_arr, uint8_t nb_queues,
294 const struct rte_event_port_conf p_conf)
298 struct test_pipeline *t = evt_test_priv(test);
301 /* setup one port per worker, linking to all queues */
302 for (port = 0; port < evt_nr_active_lcores(opt->wlcores); port++) {
303 struct worker_data *w = &t->worker[port];
305 w->dev_id = opt->dev_id;
308 w->processed_pkts = 0;
310 ret = rte_event_port_setup(opt->dev_id, port, &p_conf);
312 evt_err("failed to setup port %d", port);
316 if (rte_event_port_link(opt->dev_id, port, queue_arr, NULL,
317 nb_queues) != nb_queues)
324 evt_err("failed to link queues to port %d", port);
329 pipeline_event_rx_adapter_setup(struct evt_options *opt, uint8_t stride,
330 struct rte_event_port_conf prod_conf)
334 struct rte_mempool *vector_pool = NULL;
335 struct rte_event_eth_rx_adapter_queue_conf queue_conf;
336 struct rte_event_eth_rx_adapter_event_vector_config vec_conf;
338 memset(&queue_conf, 0,
339 sizeof(struct rte_event_eth_rx_adapter_queue_conf));
340 queue_conf.ev.sched_type = opt->sched_type_list[0];
341 if (opt->ena_vector) {
342 unsigned int nb_elem = (opt->pool_sz / opt->vector_size) << 1;
344 nb_elem = nb_elem ? nb_elem : 1;
345 vector_pool = rte_event_vector_pool_create(
346 "vector_pool", nb_elem, 0, opt->vector_size,
348 if (vector_pool == NULL) {
349 evt_err("failed to create event vector pool");
353 RTE_ETH_FOREACH_DEV(prod) {
354 struct rte_event_eth_rx_adapter_vector_limits limits;
357 ret = rte_event_eth_rx_adapter_caps_get(opt->dev_id,
360 evt_err("failed to get event rx adapter[%d]"
366 if (opt->ena_vector) {
367 memset(&limits, 0, sizeof(limits));
368 ret = rte_event_eth_rx_adapter_vector_limits_get(
369 opt->dev_id, prod, &limits);
371 evt_err("failed to get vector limits");
375 if (opt->vector_size < limits.min_sz ||
376 opt->vector_size > limits.max_sz) {
377 evt_err("Vector size [%d] not within limits max[%d] min[%d]",
378 opt->vector_size, limits.min_sz,
383 if (limits.log2_sz &&
384 !rte_is_power_of_2(opt->vector_size)) {
385 evt_err("Vector size [%d] not power of 2",
390 if (opt->vector_tmo_nsec > limits.max_timeout_ns ||
391 opt->vector_tmo_nsec < limits.min_timeout_ns) {
392 evt_err("Vector timeout [%" PRIu64
393 "] not within limits max[%" PRIu64
394 "] min[%" PRIu64 "]",
395 opt->vector_tmo_nsec,
396 limits.max_timeout_ns,
397 limits.min_timeout_ns);
401 if (cap & RTE_EVENT_ETH_RX_ADAPTER_CAP_EVENT_VECTOR) {
402 queue_conf.rx_queue_flags |=
403 RTE_EVENT_ETH_RX_ADAPTER_QUEUE_EVENT_VECTOR;
405 evt_err("Rx adapter doesn't support event vector");
409 queue_conf.ev.queue_id = prod * stride;
410 ret = rte_event_eth_rx_adapter_create(prod, opt->dev_id,
413 evt_err("failed to create rx adapter[%d]", prod);
416 ret = rte_event_eth_rx_adapter_queue_add(prod, prod, -1,
419 evt_err("failed to add rx queues to adapter[%d]", prod);
423 if (opt->ena_vector) {
424 vec_conf.vector_sz = opt->vector_size;
425 vec_conf.vector_timeout_ns = opt->vector_tmo_nsec;
426 vec_conf.vector_mp = vector_pool;
427 if (rte_event_eth_rx_adapter_queue_event_vector_config(
428 prod, prod, -1, &vec_conf) < 0) {
429 evt_err("Failed to configure event vectorization for Rx adapter");
434 if (!(cap & RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT)) {
435 uint32_t service_id = -1U;
437 rte_event_eth_rx_adapter_service_id_get(prod,
439 ret = evt_service_setup(service_id);
441 evt_err("Failed to setup service core"
447 evt_info("Port[%d] using Rx adapter[%d] configured", prod,
455 pipeline_event_tx_adapter_setup(struct evt_options *opt,
456 struct rte_event_port_conf port_conf)
461 RTE_ETH_FOREACH_DEV(consm) {
464 ret = rte_event_eth_tx_adapter_caps_get(opt->dev_id,
467 evt_err("failed to get event tx adapter[%d] caps",
472 if (opt->ena_vector) {
474 RTE_EVENT_ETH_TX_ADAPTER_CAP_EVENT_VECTOR)) {
475 evt_err("Tx adapter doesn't support event vector");
480 ret = rte_event_eth_tx_adapter_create(consm, opt->dev_id,
483 evt_err("failed to create tx adapter[%d]", consm);
487 ret = rte_event_eth_tx_adapter_queue_add(consm, consm, -1);
489 evt_err("failed to add tx queues to adapter[%d]",
494 if (!(cap & RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT)) {
495 uint32_t service_id = -1U;
497 ret = rte_event_eth_tx_adapter_service_id_get(consm,
499 if (ret != -ESRCH && ret != 0) {
500 evt_err("Failed to get Tx adptr service ID");
503 ret = evt_service_setup(service_id);
505 evt_err("Failed to setup service core"
511 evt_info("Port[%d] using Tx adapter[%d] Configured", consm,
519 pipeline_ethdev_destroy(struct evt_test *test, struct evt_options *opt)
525 RTE_ETH_FOREACH_DEV(i) {
526 rte_event_eth_rx_adapter_stop(i);
527 rte_event_eth_tx_adapter_stop(i);
533 pipeline_eventdev_destroy(struct evt_test *test, struct evt_options *opt)
537 rte_event_dev_stop(opt->dev_id);
538 rte_event_dev_close(opt->dev_id);
542 pipeline_mempool_setup(struct evt_test *test, struct evt_options *opt)
544 struct test_pipeline *t = evt_test_priv(test);
548 opt->mbuf_sz = RTE_MBUF_DEFAULT_BUF_SIZE;
550 if (!opt->max_pkt_sz)
551 opt->max_pkt_sz = RTE_ETHER_MAX_LEN;
553 RTE_ETH_FOREACH_DEV(i) {
554 struct rte_eth_dev_info dev_info;
555 uint16_t data_size = 0;
557 memset(&dev_info, 0, sizeof(dev_info));
558 ret = rte_eth_dev_info_get(i, &dev_info);
560 evt_err("Error during getting device (port %u) info: %s\n",
565 if (dev_info.rx_desc_lim.nb_mtu_seg_max != UINT16_MAX &&
566 dev_info.rx_desc_lim.nb_mtu_seg_max != 0) {
567 data_size = opt->max_pkt_sz /
568 dev_info.rx_desc_lim.nb_mtu_seg_max;
569 data_size += RTE_PKTMBUF_HEADROOM;
571 if (data_size > opt->mbuf_sz)
572 opt->mbuf_sz = data_size;
574 if (opt->per_port_pool) {
575 char name[RTE_MEMPOOL_NAMESIZE];
577 snprintf(name, RTE_MEMPOOL_NAMESIZE, "%s-%d",
579 t->pool[i] = rte_pktmbuf_pool_create(
580 name, /* mempool name */
581 opt->pool_sz, /* number of elements*/
583 0, opt->mbuf_sz, opt->socket_id); /* flags */
585 if (t->pool[i] == NULL) {
586 evt_err("failed to create mempool %s", name);
592 if (!opt->per_port_pool) {
593 t->pool[0] = rte_pktmbuf_pool_create(
594 test->name, /* mempool name */
595 opt->pool_sz, /* number of elements*/
597 0, opt->mbuf_sz, opt->socket_id); /* flags */
599 if (t->pool[0] == NULL) {
600 evt_err("failed to create mempool");
609 pipeline_mempool_destroy(struct evt_test *test, struct evt_options *opt)
611 struct test_pipeline *t = evt_test_priv(test);
615 if (opt->per_port_pool) {
616 RTE_ETH_FOREACH_DEV(i)
617 rte_mempool_free(t->pool[i]);
619 rte_mempool_free(t->pool[0]);
624 pipeline_test_setup(struct evt_test *test, struct evt_options *opt)
628 test_pipeline = rte_zmalloc_socket(test->name,
629 sizeof(struct test_pipeline), RTE_CACHE_LINE_SIZE,
631 if (test_pipeline == NULL) {
632 evt_err("failed to allocate test_pipeline memory");
635 test->test_priv = test_pipeline;
637 struct test_pipeline *t = evt_test_priv(test);
639 t->nb_workers = evt_nr_active_lcores(opt->wlcores);
640 t->outstand_pkts = opt->nb_pkts * evt_nr_active_lcores(opt->wlcores);
642 t->nb_flows = opt->nb_flows;
643 t->result = EVT_TEST_FAILED;
645 opt->prod_type = EVT_PROD_TYPE_ETH_RX_ADPTR;
646 memcpy(t->sched_type_list, opt->sched_type_list,
647 sizeof(opt->sched_type_list));
654 pipeline_test_destroy(struct evt_test *test, struct evt_options *opt)
658 rte_free(test->test_priv);