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 printf("Packet distribution across worker cores :\n");
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 printf("Worker %d packets: "CLGRN"%"PRIx64" "CLNRM"percentage:"
21 CLGRN" %3.2f\n"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);
42 pipeline_opt_check(struct evt_options *opt, uint64_t nb_queues)
50 if (!rte_eth_dev_count()) {
51 evt_err("test needs minimum 1 ethernet dev");
55 if (rte_lcore_count() < lcores) {
56 evt_err("test need minimum %d lcores", lcores);
60 /* Validate worker lcores */
61 if (evt_lcores_has_overlap(opt->wlcores, rte_get_master_lcore())) {
62 evt_err("worker lcores overlaps with master lcore");
65 if (evt_has_disabled_lcore(opt->wlcores)) {
66 evt_err("one or more workers lcores are not enabled");
69 if (!evt_has_active_lcore(opt->wlcores)) {
70 evt_err("minimum one worker is required");
74 if (nb_queues > EVT_MAX_QUEUES) {
75 evt_err("number of queues exceeds %d", EVT_MAX_QUEUES);
78 if (pipeline_nb_event_ports(opt) > EVT_MAX_PORTS) {
79 evt_err("number of ports exceeds %d", EVT_MAX_PORTS);
83 if (evt_has_invalid_stage(opt))
86 if (evt_has_invalid_sched_type(opt))
92 #define NB_RX_DESC 128
93 #define NB_TX_DESC 512
95 pipeline_ethdev_setup(struct evt_test *test, struct evt_options *opt)
98 uint8_t nb_queues = 1;
100 struct test_pipeline *t = evt_test_priv(test);
101 struct rte_eth_rxconf rx_conf;
102 struct rte_eth_conf port_conf = {
104 .mq_mode = ETH_MQ_RX_RSS,
105 .max_rx_pkt_len = ETHER_MAX_LEN,
106 .offloads = DEV_RX_OFFLOAD_CRC_STRIP,
107 .ignore_offload_bitfield = 1,
112 .rss_hf = ETH_RSS_IP,
118 if (!rte_eth_dev_count()) {
119 evt_err("No ethernet ports found.\n");
123 for (i = 0; i < rte_eth_dev_count(); i++) {
124 struct rte_eth_dev_info dev_info;
126 memset(&dev_info, 0, sizeof(struct rte_eth_dev_info));
127 rte_eth_dev_info_get(i, &dev_info);
128 mt_state = !(dev_info.tx_offload_capa &
129 DEV_TX_OFFLOAD_MT_LOCKFREE);
130 rx_conf = dev_info.default_rxconf;
131 rx_conf.offloads = port_conf.rxmode.offloads;
133 if (rte_eth_dev_configure(i, nb_queues, nb_queues,
136 evt_err("Failed to configure eth port [%d]\n", i);
140 if (rte_eth_rx_queue_setup(i, 0, NB_RX_DESC,
141 rte_socket_id(), &rx_conf, t->pool) < 0) {
142 evt_err("Failed to setup eth port [%d] rx_queue: %d.\n",
146 if (rte_eth_tx_queue_setup(i, 0, NB_TX_DESC,
147 rte_socket_id(), NULL) < 0) {
148 evt_err("Failed to setup eth port [%d] tx_queue: %d.\n",
153 t->mt_unsafe |= mt_state;
154 rte_eth_promiscuous_enable(i);
161 pipeline_event_port_setup(struct evt_test *test, struct evt_options *opt,
162 uint8_t *queue_arr, uint8_t nb_queues,
163 const struct rte_event_port_conf p_conf)
168 struct test_pipeline *t = evt_test_priv(test);
171 /* setup one port per worker, linking to all queues */
172 for (port = 0; port < evt_nr_active_lcores(opt->wlcores); port++) {
173 struct worker_data *w = &t->worker[port];
175 w->dev_id = opt->dev_id;
178 w->processed_pkts = 0;
180 ret = rte_event_port_setup(opt->dev_id, port, &p_conf);
182 evt_err("failed to setup port %d", port);
186 if (queue_arr == NULL) {
187 if (rte_event_port_link(opt->dev_id, port, NULL, NULL,
191 for (i = 0; i < nb_queues; i++) {
192 if (rte_event_port_link(opt->dev_id, port,
193 &queue_arr[i], NULL, 1) != 1)
202 evt_err("failed to link all queues to port %d", port);
207 pipeline_event_rx_adapter_setup(struct evt_options *opt, uint8_t stride,
208 struct rte_event_port_conf prod_conf)
212 struct rte_event_eth_rx_adapter_queue_conf queue_conf;
214 memset(&queue_conf, 0,
215 sizeof(struct rte_event_eth_rx_adapter_queue_conf));
216 queue_conf.ev.sched_type = opt->sched_type_list[0];
217 for (prod = 0; prod < rte_eth_dev_count(); prod++) {
220 ret = rte_event_eth_rx_adapter_caps_get(opt->dev_id,
223 evt_err("failed to get event rx adapter[%d]"
228 queue_conf.ev.queue_id = prod * stride;
229 ret = rte_event_eth_rx_adapter_create(prod, opt->dev_id,
232 evt_err("failed to create rx adapter[%d]", prod);
235 ret = rte_event_eth_rx_adapter_queue_add(prod, prod, -1,
238 evt_err("failed to add rx queues to adapter[%d]", prod);
242 if (!(cap & RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT)) {
245 rte_event_eth_rx_adapter_service_id_get(prod,
247 ret = evt_service_setup(service_id);
249 evt_err("Failed to setup service core"
250 " for Rx adapter\n");
255 ret = rte_eth_dev_start(prod);
257 evt_err("Ethernet dev [%d] failed to start."
258 " Using synthetic producer", prod);
262 ret = rte_event_eth_rx_adapter_start(prod);
264 evt_err("Rx adapter[%d] start failed", prod);
267 printf("%s: Port[%d] using Rx adapter[%d] started\n", __func__,
275 pipeline_ethdev_destroy(struct evt_test *test, struct evt_options *opt)
281 for (i = 0; i < rte_eth_dev_count(); i++) {
282 rte_event_eth_rx_adapter_stop(i);
284 rte_eth_dev_close(i);
289 pipeline_eventdev_destroy(struct evt_test *test, struct evt_options *opt)
293 rte_event_dev_stop(opt->dev_id);
294 rte_event_dev_close(opt->dev_id);
298 pipeline_mempool_setup(struct evt_test *test, struct evt_options *opt)
300 struct test_pipeline *t = evt_test_priv(test);
302 t->pool = rte_pktmbuf_pool_create(test->name, /* mempool name */
303 opt->pool_sz, /* number of elements*/
306 RTE_MBUF_DEFAULT_BUF_SIZE,
307 opt->socket_id); /* flags */
309 if (t->pool == NULL) {
310 evt_err("failed to create mempool");
318 pipeline_mempool_destroy(struct evt_test *test, struct evt_options *opt)
321 struct test_pipeline *t = evt_test_priv(test);
323 rte_mempool_free(t->pool);
327 pipeline_test_setup(struct evt_test *test, struct evt_options *opt)
331 test_pipeline = rte_zmalloc_socket(test->name,
332 sizeof(struct test_pipeline), RTE_CACHE_LINE_SIZE,
334 if (test_pipeline == NULL) {
335 evt_err("failed to allocate test_pipeline memory");
338 test->test_priv = test_pipeline;
340 struct test_pipeline *t = evt_test_priv(test);
342 t->nb_workers = evt_nr_active_lcores(opt->wlcores);
343 t->outstand_pkts = opt->nb_pkts * evt_nr_active_lcores(opt->wlcores);
345 t->nb_flows = opt->nb_flows;
346 t->result = EVT_TEST_FAILED;
348 opt->prod_type = EVT_PROD_TYPE_ETH_RX_ADPTR;
349 memcpy(t->sched_type_list, opt->sched_type_list,
350 sizeof(opt->sched_type_list));
357 pipeline_test_destroy(struct evt_test *test, struct evt_options *opt)
361 rte_free(test->test_priv);