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)
47 for (i = 0; i < t->nb_workers; i++)
48 total += t->worker[i].processed_pkts;
54 pipeline_launch_lcores(struct evt_test *test, struct evt_options *opt,
55 int (*worker)(void *))
58 struct test_pipeline *t = evt_test_priv(test);
62 RTE_LCORE_FOREACH_WORKER(lcore_id) {
63 if (!(opt->wlcores[lcore_id]))
66 ret = rte_eal_remote_launch(worker,
67 &t->worker[port_idx], lcore_id);
69 evt_err("failed to launch worker %d", lcore_id);
75 uint64_t perf_cycles = rte_get_timer_cycles();
76 const uint64_t perf_sample = rte_get_timer_hz();
78 static float total_mpps;
79 static uint64_t samples;
81 uint64_t prev_pkts = 0;
83 while (t->done == false) {
84 const uint64_t new_cycles = rte_get_timer_cycles();
86 if ((new_cycles - perf_cycles) > perf_sample) {
87 const uint64_t curr_pkts = processed_pkts(t);
89 float mpps = (float)(curr_pkts - prev_pkts)/1000000;
91 prev_pkts = curr_pkts;
92 perf_cycles = new_cycles;
95 printf(CLGRN"\r%.3f mpps avg %.3f mpps"CLNRM,
96 mpps, total_mpps/samples);
105 pipeline_opt_check(struct evt_options *opt, uint64_t nb_queues)
109 /* N worker + main */
112 if (opt->prod_type != EVT_PROD_TYPE_ETH_RX_ADPTR) {
113 evt_err("Invalid producer type '%s' valid producer '%s'",
114 evt_prod_id_to_name(opt->prod_type),
115 evt_prod_id_to_name(EVT_PROD_TYPE_ETH_RX_ADPTR));
119 if (!rte_eth_dev_count_avail()) {
120 evt_err("test needs minimum 1 ethernet dev");
124 if (rte_lcore_count() < lcores) {
125 evt_err("test need minimum %d lcores", lcores);
129 /* Validate worker lcores */
130 if (evt_lcores_has_overlap(opt->wlcores, rte_get_main_lcore())) {
131 evt_err("worker lcores overlaps with main lcore");
134 if (evt_has_disabled_lcore(opt->wlcores)) {
135 evt_err("one or more workers lcores are not enabled");
138 if (!evt_has_active_lcore(opt->wlcores)) {
139 evt_err("minimum one worker is required");
143 if (nb_queues > EVT_MAX_QUEUES) {
144 evt_err("number of queues exceeds %d", EVT_MAX_QUEUES);
147 if (pipeline_nb_event_ports(opt) > EVT_MAX_PORTS) {
148 evt_err("number of ports exceeds %d", EVT_MAX_PORTS);
152 if (evt_has_invalid_stage(opt))
155 if (evt_has_invalid_sched_type(opt))
161 #define NB_RX_DESC 128
162 #define NB_TX_DESC 512
164 pipeline_ethdev_setup(struct evt_test *test, struct evt_options *opt)
168 uint8_t nb_queues = 1;
169 struct test_pipeline *t = evt_test_priv(test);
170 struct rte_eth_rxconf rx_conf;
171 struct rte_eth_conf port_conf = {
173 .mq_mode = ETH_MQ_RX_RSS,
178 .rss_hf = ETH_RSS_IP,
183 if (!rte_eth_dev_count_avail()) {
184 evt_err("No ethernet ports found.");
188 if (opt->max_pkt_sz < RTE_ETHER_MIN_LEN) {
189 evt_err("max_pkt_sz can not be less than %d",
194 port_conf.rxmode.max_rx_pkt_len = opt->max_pkt_sz;
195 if (opt->max_pkt_sz > RTE_ETHER_MAX_LEN)
196 port_conf.rxmode.offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
198 t->internal_port = 1;
199 RTE_ETH_FOREACH_DEV(i) {
200 struct rte_eth_dev_info dev_info;
201 struct rte_eth_conf local_port_conf = port_conf;
204 ret = rte_event_eth_tx_adapter_caps_get(opt->dev_id, i, &caps);
206 evt_err("failed to get event tx adapter[%d] caps", i);
210 if (!(caps & RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT))
211 t->internal_port = 0;
213 ret = rte_eth_dev_info_get(i, &dev_info);
215 evt_err("Error during getting device (port %u) info: %s\n",
220 /* Enable mbuf fast free if PMD has the capability. */
221 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
222 local_port_conf.txmode.offloads |=
223 DEV_TX_OFFLOAD_MBUF_FAST_FREE;
225 rx_conf = dev_info.default_rxconf;
226 rx_conf.offloads = port_conf.rxmode.offloads;
228 local_port_conf.rx_adv_conf.rss_conf.rss_hf &=
229 dev_info.flow_type_rss_offloads;
230 if (local_port_conf.rx_adv_conf.rss_conf.rss_hf !=
231 port_conf.rx_adv_conf.rss_conf.rss_hf) {
232 evt_info("Port %u modified RSS hash function based on hardware support,"
233 "requested:%#"PRIx64" configured:%#"PRIx64"",
235 port_conf.rx_adv_conf.rss_conf.rss_hf,
236 local_port_conf.rx_adv_conf.rss_conf.rss_hf);
239 if (rte_eth_dev_configure(i, nb_queues, nb_queues,
242 evt_err("Failed to configure eth port [%d]", i);
246 if (rte_eth_rx_queue_setup(i, 0, NB_RX_DESC,
247 rte_socket_id(), &rx_conf, t->pool) < 0) {
248 evt_err("Failed to setup eth port [%d] rx_queue: %d.",
252 if (rte_eth_tx_queue_setup(i, 0, NB_TX_DESC,
253 rte_socket_id(), NULL) < 0) {
254 evt_err("Failed to setup eth port [%d] tx_queue: %d.",
259 ret = rte_eth_promiscuous_enable(i);
261 evt_err("Failed to enable promiscuous mode for eth port [%d]: %s",
262 i, rte_strerror(-ret));
271 pipeline_event_port_setup(struct evt_test *test, struct evt_options *opt,
272 uint8_t *queue_arr, uint8_t nb_queues,
273 const struct rte_event_port_conf p_conf)
277 struct test_pipeline *t = evt_test_priv(test);
280 /* setup one port per worker, linking to all queues */
281 for (port = 0; port < evt_nr_active_lcores(opt->wlcores); port++) {
282 struct worker_data *w = &t->worker[port];
284 w->dev_id = opt->dev_id;
287 w->processed_pkts = 0;
289 ret = rte_event_port_setup(opt->dev_id, port, &p_conf);
291 evt_err("failed to setup port %d", port);
295 if (rte_event_port_link(opt->dev_id, port, queue_arr, NULL,
296 nb_queues) != nb_queues)
303 evt_err("failed to link queues to port %d", port);
308 pipeline_event_rx_adapter_setup(struct evt_options *opt, uint8_t stride,
309 struct rte_event_port_conf prod_conf)
313 struct rte_event_eth_rx_adapter_queue_conf queue_conf;
315 memset(&queue_conf, 0,
316 sizeof(struct rte_event_eth_rx_adapter_queue_conf));
317 queue_conf.ev.sched_type = opt->sched_type_list[0];
318 RTE_ETH_FOREACH_DEV(prod) {
321 ret = rte_event_eth_rx_adapter_caps_get(opt->dev_id,
324 evt_err("failed to get event rx adapter[%d]"
329 queue_conf.ev.queue_id = prod * stride;
330 ret = rte_event_eth_rx_adapter_create(prod, opt->dev_id,
333 evt_err("failed to create rx adapter[%d]", prod);
336 ret = rte_event_eth_rx_adapter_queue_add(prod, prod, -1,
339 evt_err("failed to add rx queues to adapter[%d]", prod);
343 if (!(cap & RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT)) {
344 uint32_t service_id = -1U;
346 rte_event_eth_rx_adapter_service_id_get(prod,
348 ret = evt_service_setup(service_id);
350 evt_err("Failed to setup service core"
356 evt_info("Port[%d] using Rx adapter[%d] configured", prod,
364 pipeline_event_tx_adapter_setup(struct evt_options *opt,
365 struct rte_event_port_conf port_conf)
370 RTE_ETH_FOREACH_DEV(consm) {
373 ret = rte_event_eth_tx_adapter_caps_get(opt->dev_id,
376 evt_err("failed to get event tx adapter[%d] caps",
381 ret = rte_event_eth_tx_adapter_create(consm, opt->dev_id,
384 evt_err("failed to create tx adapter[%d]", consm);
388 ret = rte_event_eth_tx_adapter_queue_add(consm, consm, -1);
390 evt_err("failed to add tx queues to adapter[%d]",
395 if (!(cap & RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT)) {
396 uint32_t service_id = -1U;
398 ret = rte_event_eth_tx_adapter_service_id_get(consm,
400 if (ret != -ESRCH && ret != 0) {
401 evt_err("Failed to get Tx adptr service ID");
404 ret = evt_service_setup(service_id);
406 evt_err("Failed to setup service core"
412 evt_info("Port[%d] using Tx adapter[%d] Configured", consm,
420 pipeline_ethdev_destroy(struct evt_test *test, struct evt_options *opt)
426 RTE_ETH_FOREACH_DEV(i) {
427 rte_event_eth_rx_adapter_stop(i);
428 rte_event_eth_tx_adapter_stop(i);
434 pipeline_eventdev_destroy(struct evt_test *test, struct evt_options *opt)
438 rte_event_dev_stop(opt->dev_id);
439 rte_event_dev_close(opt->dev_id);
443 pipeline_mempool_setup(struct evt_test *test, struct evt_options *opt)
445 struct test_pipeline *t = evt_test_priv(test);
449 opt->mbuf_sz = RTE_MBUF_DEFAULT_BUF_SIZE;
451 if (!opt->max_pkt_sz)
452 opt->max_pkt_sz = RTE_ETHER_MAX_LEN;
454 RTE_ETH_FOREACH_DEV(i) {
455 struct rte_eth_dev_info dev_info;
456 uint16_t data_size = 0;
458 memset(&dev_info, 0, sizeof(dev_info));
459 ret = rte_eth_dev_info_get(i, &dev_info);
461 evt_err("Error during getting device (port %u) info: %s\n",
466 if (dev_info.rx_desc_lim.nb_mtu_seg_max != UINT16_MAX &&
467 dev_info.rx_desc_lim.nb_mtu_seg_max != 0) {
468 data_size = opt->max_pkt_sz /
469 dev_info.rx_desc_lim.nb_mtu_seg_max;
470 data_size += RTE_PKTMBUF_HEADROOM;
472 if (data_size > opt->mbuf_sz)
473 opt->mbuf_sz = data_size;
477 t->pool = rte_pktmbuf_pool_create(test->name, /* mempool name */
478 opt->pool_sz, /* number of elements*/
482 opt->socket_id); /* flags */
484 if (t->pool == NULL) {
485 evt_err("failed to create mempool");
493 pipeline_mempool_destroy(struct evt_test *test, struct evt_options *opt)
496 struct test_pipeline *t = evt_test_priv(test);
498 rte_mempool_free(t->pool);
502 pipeline_test_setup(struct evt_test *test, struct evt_options *opt)
506 test_pipeline = rte_zmalloc_socket(test->name,
507 sizeof(struct test_pipeline), RTE_CACHE_LINE_SIZE,
509 if (test_pipeline == NULL) {
510 evt_err("failed to allocate test_pipeline memory");
513 test->test_priv = test_pipeline;
515 struct test_pipeline *t = evt_test_priv(test);
517 t->nb_workers = evt_nr_active_lcores(opt->wlcores);
518 t->outstand_pkts = opt->nb_pkts * evt_nr_active_lcores(opt->wlcores);
520 t->nb_flows = opt->nb_flows;
521 t->result = EVT_TEST_FAILED;
523 opt->prod_type = EVT_PROD_TYPE_ETH_RX_ADPTR;
524 memcpy(t->sched_type_list, opt->sched_type_list,
525 sizeof(opt->sched_type_list));
532 pipeline_test_destroy(struct evt_test *test, struct evt_options *opt)
536 rte_free(test->test_priv);