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);
41 static inline uint64_t
42 processed_pkts(struct test_pipeline *t)
48 for (i = 0; i < t->nb_workers; i++)
49 total += t->worker[i].processed_pkts;
55 pipeline_launch_lcores(struct evt_test *test, struct evt_options *opt,
56 int (*worker)(void *))
59 struct test_pipeline *t = evt_test_priv(test);
63 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
64 if (!(opt->wlcores[lcore_id]))
67 ret = rte_eal_remote_launch(worker,
68 &t->worker[port_idx], lcore_id);
70 evt_err("failed to launch worker %d", lcore_id);
76 uint64_t perf_cycles = rte_get_timer_cycles();
77 const uint64_t perf_sample = rte_get_timer_hz();
79 static float total_mpps;
80 static uint64_t samples;
82 uint64_t prev_pkts = 0;
84 while (t->done == false) {
85 const uint64_t new_cycles = rte_get_timer_cycles();
87 if ((new_cycles - perf_cycles) > perf_sample) {
88 const uint64_t curr_pkts = processed_pkts(t);
90 float mpps = (float)(curr_pkts - prev_pkts)/1000000;
92 prev_pkts = curr_pkts;
93 perf_cycles = new_cycles;
96 printf(CLGRN"\r%.3f mpps avg %.3f mpps"CLNRM,
97 mpps, total_mpps/samples);
106 pipeline_opt_check(struct evt_options *opt, uint64_t nb_queues)
110 * N worker + 1 master
114 if (opt->prod_type != EVT_PROD_TYPE_ETH_RX_ADPTR) {
115 evt_err("Invalid producer type '%s' valid producer '%s'",
116 evt_prod_id_to_name(opt->prod_type),
117 evt_prod_id_to_name(EVT_PROD_TYPE_ETH_RX_ADPTR));
121 if (!rte_eth_dev_count_avail()) {
122 evt_err("test needs minimum 1 ethernet dev");
126 if (rte_lcore_count() < lcores) {
127 evt_err("test need minimum %d lcores", lcores);
131 /* Validate worker lcores */
132 if (evt_lcores_has_overlap(opt->wlcores, rte_get_master_lcore())) {
133 evt_err("worker lcores overlaps with master lcore");
136 if (evt_has_disabled_lcore(opt->wlcores)) {
137 evt_err("one or more workers lcores are not enabled");
140 if (!evt_has_active_lcore(opt->wlcores)) {
141 evt_err("minimum one worker is required");
145 if (nb_queues > EVT_MAX_QUEUES) {
146 evt_err("number of queues exceeds %d", EVT_MAX_QUEUES);
149 if (pipeline_nb_event_ports(opt) > EVT_MAX_PORTS) {
150 evt_err("number of ports exceeds %d", EVT_MAX_PORTS);
154 if (evt_has_invalid_stage(opt))
157 if (evt_has_invalid_sched_type(opt))
163 #define NB_RX_DESC 128
164 #define NB_TX_DESC 512
166 pipeline_ethdev_setup(struct evt_test *test, struct evt_options *opt)
170 uint8_t nb_queues = 1;
171 struct test_pipeline *t = evt_test_priv(test);
172 struct rte_eth_rxconf rx_conf;
173 struct rte_eth_conf port_conf = {
175 .mq_mode = ETH_MQ_RX_RSS,
180 .rss_hf = ETH_RSS_IP,
185 if (!rte_eth_dev_count_avail()) {
186 evt_err("No ethernet ports found.");
190 if (opt->max_pkt_sz < RTE_ETHER_MIN_LEN) {
191 evt_err("max_pkt_sz can not be less than %d",
196 port_conf.rxmode.max_rx_pkt_len = opt->max_pkt_sz;
197 if (opt->max_pkt_sz > RTE_ETHER_MAX_LEN)
198 port_conf.rxmode.offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
200 t->internal_port = 1;
201 RTE_ETH_FOREACH_DEV(i) {
202 struct rte_eth_dev_info dev_info;
203 struct rte_eth_conf local_port_conf = port_conf;
206 ret = rte_event_eth_tx_adapter_caps_get(opt->dev_id, i, &caps);
208 evt_err("failed to get event tx adapter[%d] caps", i);
212 if (!(caps & RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT))
213 t->internal_port = 0;
215 ret = rte_eth_dev_info_get(i, &dev_info);
217 evt_err("Error during getting device (port %u) info: %s\n",
222 /* Enable mbuf fast free if PMD has the capability. */
223 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
224 local_port_conf.txmode.offloads |=
225 DEV_TX_OFFLOAD_MBUF_FAST_FREE;
227 rx_conf = dev_info.default_rxconf;
228 rx_conf.offloads = port_conf.rxmode.offloads;
230 local_port_conf.rx_adv_conf.rss_conf.rss_hf &=
231 dev_info.flow_type_rss_offloads;
232 if (local_port_conf.rx_adv_conf.rss_conf.rss_hf !=
233 port_conf.rx_adv_conf.rss_conf.rss_hf) {
234 evt_info("Port %u modified RSS hash function based on hardware support,"
235 "requested:%#"PRIx64" configured:%#"PRIx64"",
237 port_conf.rx_adv_conf.rss_conf.rss_hf,
238 local_port_conf.rx_adv_conf.rss_conf.rss_hf);
241 if (rte_eth_dev_configure(i, nb_queues, nb_queues,
244 evt_err("Failed to configure eth port [%d]", i);
248 if (rte_eth_rx_queue_setup(i, 0, NB_RX_DESC,
249 rte_socket_id(), &rx_conf, t->pool) < 0) {
250 evt_err("Failed to setup eth port [%d] rx_queue: %d.",
254 if (rte_eth_tx_queue_setup(i, 0, NB_TX_DESC,
255 rte_socket_id(), NULL) < 0) {
256 evt_err("Failed to setup eth port [%d] tx_queue: %d.",
261 ret = rte_eth_promiscuous_enable(i);
263 evt_err("Failed to enable promiscuous mode for eth port [%d]: %s",
264 i, rte_strerror(-ret));
273 pipeline_event_port_setup(struct evt_test *test, struct evt_options *opt,
274 uint8_t *queue_arr, uint8_t nb_queues,
275 const struct rte_event_port_conf p_conf)
279 struct test_pipeline *t = evt_test_priv(test);
282 /* setup one port per worker, linking to all queues */
283 for (port = 0; port < evt_nr_active_lcores(opt->wlcores); port++) {
284 struct worker_data *w = &t->worker[port];
286 w->dev_id = opt->dev_id;
289 w->processed_pkts = 0;
291 ret = rte_event_port_setup(opt->dev_id, port, &p_conf);
293 evt_err("failed to setup port %d", port);
297 if (rte_event_port_link(opt->dev_id, port, queue_arr, NULL,
298 nb_queues) != nb_queues)
305 evt_err("failed to link queues to port %d", port);
310 pipeline_event_rx_adapter_setup(struct evt_options *opt, uint8_t stride,
311 struct rte_event_port_conf prod_conf)
315 struct rte_event_eth_rx_adapter_queue_conf queue_conf;
317 memset(&queue_conf, 0,
318 sizeof(struct rte_event_eth_rx_adapter_queue_conf));
319 queue_conf.ev.sched_type = opt->sched_type_list[0];
320 RTE_ETH_FOREACH_DEV(prod) {
323 ret = rte_event_eth_rx_adapter_caps_get(opt->dev_id,
326 evt_err("failed to get event rx adapter[%d]"
331 queue_conf.ev.queue_id = prod * stride;
332 ret = rte_event_eth_rx_adapter_create(prod, opt->dev_id,
335 evt_err("failed to create rx adapter[%d]", prod);
338 ret = rte_event_eth_rx_adapter_queue_add(prod, prod, -1,
341 evt_err("failed to add rx queues to adapter[%d]", prod);
345 if (!(cap & RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT)) {
346 uint32_t service_id = -1U;
348 rte_event_eth_rx_adapter_service_id_get(prod,
350 ret = evt_service_setup(service_id);
352 evt_err("Failed to setup service core"
358 evt_info("Port[%d] using Rx adapter[%d] configured", prod,
366 pipeline_event_tx_adapter_setup(struct evt_options *opt,
367 struct rte_event_port_conf port_conf)
372 RTE_ETH_FOREACH_DEV(consm) {
375 ret = rte_event_eth_tx_adapter_caps_get(opt->dev_id,
378 evt_err("failed to get event tx adapter[%d] caps",
383 ret = rte_event_eth_tx_adapter_create(consm, opt->dev_id,
386 evt_err("failed to create tx adapter[%d]", consm);
390 ret = rte_event_eth_tx_adapter_queue_add(consm, consm, -1);
392 evt_err("failed to add tx queues to adapter[%d]",
397 if (!(cap & RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT)) {
398 uint32_t service_id = -1U;
400 ret = rte_event_eth_tx_adapter_service_id_get(consm,
402 if (ret != -ESRCH && ret != 0) {
403 evt_err("Failed to get Tx adptr service ID");
406 ret = evt_service_setup(service_id);
408 evt_err("Failed to setup service core"
414 evt_info("Port[%d] using Tx adapter[%d] Configured", consm,
422 pipeline_ethdev_destroy(struct evt_test *test, struct evt_options *opt)
428 RTE_ETH_FOREACH_DEV(i) {
429 rte_event_eth_rx_adapter_stop(i);
430 rte_event_eth_tx_adapter_stop(i);
436 pipeline_eventdev_destroy(struct evt_test *test, struct evt_options *opt)
440 rte_event_dev_stop(opt->dev_id);
441 rte_event_dev_close(opt->dev_id);
445 pipeline_mempool_setup(struct evt_test *test, struct evt_options *opt)
447 struct test_pipeline *t = evt_test_priv(test);
451 opt->mbuf_sz = RTE_MBUF_DEFAULT_BUF_SIZE;
453 if (!opt->max_pkt_sz)
454 opt->max_pkt_sz = RTE_ETHER_MAX_LEN;
456 RTE_ETH_FOREACH_DEV(i) {
457 struct rte_eth_dev_info dev_info;
458 uint16_t data_size = 0;
460 memset(&dev_info, 0, sizeof(dev_info));
461 ret = rte_eth_dev_info_get(i, &dev_info);
463 evt_err("Error during getting device (port %u) info: %s\n",
468 if (dev_info.rx_desc_lim.nb_mtu_seg_max != UINT16_MAX &&
469 dev_info.rx_desc_lim.nb_mtu_seg_max != 0) {
470 data_size = opt->max_pkt_sz /
471 dev_info.rx_desc_lim.nb_mtu_seg_max;
472 data_size += RTE_PKTMBUF_HEADROOM;
474 if (data_size > opt->mbuf_sz)
475 opt->mbuf_sz = data_size;
479 t->pool = rte_pktmbuf_pool_create(test->name, /* mempool name */
480 opt->pool_sz, /* number of elements*/
484 opt->socket_id); /* flags */
486 if (t->pool == NULL) {
487 evt_err("failed to create mempool");
495 pipeline_mempool_destroy(struct evt_test *test, struct evt_options *opt)
498 struct test_pipeline *t = evt_test_priv(test);
500 rte_mempool_free(t->pool);
504 pipeline_test_setup(struct evt_test *test, struct evt_options *opt)
508 test_pipeline = rte_zmalloc_socket(test->name,
509 sizeof(struct test_pipeline), RTE_CACHE_LINE_SIZE,
511 if (test_pipeline == NULL) {
512 evt_err("failed to allocate test_pipeline memory");
515 test->test_priv = test_pipeline;
517 struct test_pipeline *t = evt_test_priv(test);
519 t->nb_workers = evt_nr_active_lcores(opt->wlcores);
520 t->outstand_pkts = opt->nb_pkts * evt_nr_active_lcores(opt->wlcores);
522 t->nb_flows = opt->nb_flows;
523 t->result = EVT_TEST_FAILED;
525 opt->prod_type = EVT_PROD_TYPE_ETH_RX_ADPTR;
526 memcpy(t->sched_type_list, opt->sched_type_list,
527 sizeof(opt->sched_type_list));
534 pipeline_test_destroy(struct evt_test *test, struct evt_options *opt)
538 rte_free(test->test_priv);