xref: /dpdk/app/test-eventdev/test_perf_common.c (revision b0333c55dfa55ce31e67aaad220b074c435af24f)
153a3b7e8SJerin Jacob /* SPDX-License-Identifier: BSD-3-Clause
253a3b7e8SJerin Jacob  * Copyright(c) 2017 Cavium, Inc
3ffbae86fSJerin Jacob  */
4ffbae86fSJerin Jacob 
5ffbae86fSJerin Jacob #include "test_perf_common.h"
6ffbae86fSJerin Jacob 
741c219e6SJerin Jacob int
841c219e6SJerin Jacob perf_test_result(struct evt_test *test, struct evt_options *opt)
941c219e6SJerin Jacob {
1041c219e6SJerin Jacob 	RTE_SET_USED(opt);
1141c219e6SJerin Jacob 	struct test_perf *t = evt_test_priv(test);
1241c219e6SJerin Jacob 
1341c219e6SJerin Jacob 	return t->result;
1441c219e6SJerin Jacob }
1541c219e6SJerin Jacob 
169d3aeb18SJerin Jacob static inline int
179d3aeb18SJerin Jacob perf_producer(void *arg)
189d3aeb18SJerin Jacob {
199d3aeb18SJerin Jacob 	struct prod_data *p  = arg;
209d3aeb18SJerin Jacob 	struct test_perf *t = p->t;
219d3aeb18SJerin Jacob 	struct evt_options *opt = t->opt;
229d3aeb18SJerin Jacob 	const uint8_t dev_id = p->dev_id;
239d3aeb18SJerin Jacob 	const uint8_t port = p->port_id;
249d3aeb18SJerin Jacob 	struct rte_mempool *pool = t->pool;
259d3aeb18SJerin Jacob 	const uint64_t nb_pkts = t->nb_pkts;
269d3aeb18SJerin Jacob 	const uint32_t nb_flows = t->nb_flows;
279d3aeb18SJerin Jacob 	uint32_t flow_counter = 0;
289d3aeb18SJerin Jacob 	uint64_t count = 0;
299d3aeb18SJerin Jacob 	struct perf_elt *m;
309d3aeb18SJerin Jacob 	struct rte_event ev;
319d3aeb18SJerin Jacob 
329d3aeb18SJerin Jacob 	if (opt->verbose_level > 1)
339d3aeb18SJerin Jacob 		printf("%s(): lcore %d dev_id %d port=%d queue %d\n", __func__,
349d3aeb18SJerin Jacob 				rte_lcore_id(), dev_id, port, p->queue_id);
359d3aeb18SJerin Jacob 
369d3aeb18SJerin Jacob 	ev.event = 0;
379d3aeb18SJerin Jacob 	ev.op = RTE_EVENT_OP_NEW;
389d3aeb18SJerin Jacob 	ev.queue_id = p->queue_id;
399d3aeb18SJerin Jacob 	ev.sched_type = t->opt->sched_type_list[0];
409d3aeb18SJerin Jacob 	ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL;
419d3aeb18SJerin Jacob 	ev.event_type =  RTE_EVENT_TYPE_CPU;
429d3aeb18SJerin Jacob 	ev.sub_event_type = 0; /* stage 0 */
439d3aeb18SJerin Jacob 
449d3aeb18SJerin Jacob 	while (count < nb_pkts && t->done == false) {
459d3aeb18SJerin Jacob 		if (rte_mempool_get(pool, (void **)&m) < 0)
469d3aeb18SJerin Jacob 			continue;
479d3aeb18SJerin Jacob 
489d3aeb18SJerin Jacob 		ev.flow_id = flow_counter++ % nb_flows;
499d3aeb18SJerin Jacob 		ev.event_ptr = m;
509d3aeb18SJerin Jacob 		m->timestamp = rte_get_timer_cycles();
519d3aeb18SJerin Jacob 		while (rte_event_enqueue_burst(dev_id, port, &ev, 1) != 1) {
529d3aeb18SJerin Jacob 			if (t->done)
539d3aeb18SJerin Jacob 				break;
549d3aeb18SJerin Jacob 			rte_pause();
559d3aeb18SJerin Jacob 			m->timestamp = rte_get_timer_cycles();
569d3aeb18SJerin Jacob 		}
579d3aeb18SJerin Jacob 		count++;
589d3aeb18SJerin Jacob 	}
599d3aeb18SJerin Jacob 
609d3aeb18SJerin Jacob 	return 0;
619d3aeb18SJerin Jacob }
629d3aeb18SJerin Jacob 
6359f697e3SPavan Nikhilesh static int
6459f697e3SPavan Nikhilesh perf_producer_wrapper(void *arg)
6559f697e3SPavan Nikhilesh {
6659f697e3SPavan Nikhilesh 	struct prod_data *p  = arg;
6759f697e3SPavan Nikhilesh 	struct test_perf *t = p->t;
6859f697e3SPavan Nikhilesh 	/* Launch the producer function only in case of synthetic producer. */
6959f697e3SPavan Nikhilesh 	if (t->opt->prod_type == EVT_PROD_TYPE_SYNT)
7059f697e3SPavan Nikhilesh 		return perf_producer(arg);
7159f697e3SPavan Nikhilesh 	return 0;
7259f697e3SPavan Nikhilesh }
7359f697e3SPavan Nikhilesh 
749d3aeb18SJerin Jacob static inline uint64_t
759d3aeb18SJerin Jacob processed_pkts(struct test_perf *t)
769d3aeb18SJerin Jacob {
779d3aeb18SJerin Jacob 	uint8_t i;
789d3aeb18SJerin Jacob 	uint64_t total = 0;
799d3aeb18SJerin Jacob 
809d3aeb18SJerin Jacob 	rte_smp_rmb();
819d3aeb18SJerin Jacob 	for (i = 0; i < t->nb_workers; i++)
829d3aeb18SJerin Jacob 		total += t->worker[i].processed_pkts;
839d3aeb18SJerin Jacob 
849d3aeb18SJerin Jacob 	return total;
859d3aeb18SJerin Jacob }
869d3aeb18SJerin Jacob 
879d3aeb18SJerin Jacob static inline uint64_t
889d3aeb18SJerin Jacob total_latency(struct test_perf *t)
899d3aeb18SJerin Jacob {
909d3aeb18SJerin Jacob 	uint8_t i;
919d3aeb18SJerin Jacob 	uint64_t total = 0;
929d3aeb18SJerin Jacob 
939d3aeb18SJerin Jacob 	rte_smp_rmb();
949d3aeb18SJerin Jacob 	for (i = 0; i < t->nb_workers; i++)
959d3aeb18SJerin Jacob 		total += t->worker[i].latency;
969d3aeb18SJerin Jacob 
979d3aeb18SJerin Jacob 	return total;
989d3aeb18SJerin Jacob }
999d3aeb18SJerin Jacob 
1009d3aeb18SJerin Jacob 
1019d3aeb18SJerin Jacob int
1029d3aeb18SJerin Jacob perf_launch_lcores(struct evt_test *test, struct evt_options *opt,
1039d3aeb18SJerin Jacob 		int (*worker)(void *))
1049d3aeb18SJerin Jacob {
1059d3aeb18SJerin Jacob 	int ret, lcore_id;
1069d3aeb18SJerin Jacob 	struct test_perf *t = evt_test_priv(test);
1079d3aeb18SJerin Jacob 
1089d3aeb18SJerin Jacob 	int port_idx = 0;
1099d3aeb18SJerin Jacob 	/* launch workers */
1109d3aeb18SJerin Jacob 	RTE_LCORE_FOREACH_SLAVE(lcore_id) {
1119d3aeb18SJerin Jacob 		if (!(opt->wlcores[lcore_id]))
1129d3aeb18SJerin Jacob 			continue;
1139d3aeb18SJerin Jacob 
1149d3aeb18SJerin Jacob 		ret = rte_eal_remote_launch(worker,
1159d3aeb18SJerin Jacob 				 &t->worker[port_idx], lcore_id);
1169d3aeb18SJerin Jacob 		if (ret) {
1179d3aeb18SJerin Jacob 			evt_err("failed to launch worker %d", lcore_id);
1189d3aeb18SJerin Jacob 			return ret;
1199d3aeb18SJerin Jacob 		}
1209d3aeb18SJerin Jacob 		port_idx++;
1219d3aeb18SJerin Jacob 	}
1229d3aeb18SJerin Jacob 
1239d3aeb18SJerin Jacob 	/* launch producers */
1249d3aeb18SJerin Jacob 	RTE_LCORE_FOREACH_SLAVE(lcore_id) {
1259d3aeb18SJerin Jacob 		if (!(opt->plcores[lcore_id]))
1269d3aeb18SJerin Jacob 			continue;
1279d3aeb18SJerin Jacob 
12859f697e3SPavan Nikhilesh 		ret = rte_eal_remote_launch(perf_producer_wrapper,
12959f697e3SPavan Nikhilesh 				&t->prod[port_idx], lcore_id);
1309d3aeb18SJerin Jacob 		if (ret) {
1319d3aeb18SJerin Jacob 			evt_err("failed to launch perf_producer %d", lcore_id);
1329d3aeb18SJerin Jacob 			return ret;
1339d3aeb18SJerin Jacob 		}
1349d3aeb18SJerin Jacob 		port_idx++;
1359d3aeb18SJerin Jacob 	}
1369d3aeb18SJerin Jacob 
1379d3aeb18SJerin Jacob 	const uint64_t total_pkts = opt->nb_pkts *
1389d3aeb18SJerin Jacob 			evt_nr_active_lcores(opt->plcores);
1399d3aeb18SJerin Jacob 
1409d3aeb18SJerin Jacob 	uint64_t dead_lock_cycles = rte_get_timer_cycles();
1419d3aeb18SJerin Jacob 	int64_t dead_lock_remaining  =  total_pkts;
1429d3aeb18SJerin Jacob 	const uint64_t dead_lock_sample = rte_get_timer_hz() * 5;
1439d3aeb18SJerin Jacob 
1449d3aeb18SJerin Jacob 	uint64_t perf_cycles = rte_get_timer_cycles();
1459d3aeb18SJerin Jacob 	int64_t perf_remaining  = total_pkts;
1469d3aeb18SJerin Jacob 	const uint64_t perf_sample = rte_get_timer_hz();
1479d3aeb18SJerin Jacob 
1489d3aeb18SJerin Jacob 	static float total_mpps;
1499d3aeb18SJerin Jacob 	static uint64_t samples;
1509d3aeb18SJerin Jacob 
1519d3aeb18SJerin Jacob 	const uint64_t freq_mhz = rte_get_timer_hz() / 1000000;
1529d3aeb18SJerin Jacob 	int64_t remaining = t->outstand_pkts - processed_pkts(t);
1539d3aeb18SJerin Jacob 
1549d3aeb18SJerin Jacob 	while (t->done == false) {
1559d3aeb18SJerin Jacob 		const uint64_t new_cycles = rte_get_timer_cycles();
1569d3aeb18SJerin Jacob 
1579d3aeb18SJerin Jacob 		if ((new_cycles - perf_cycles) > perf_sample) {
1589d3aeb18SJerin Jacob 			const uint64_t latency = total_latency(t);
1599d3aeb18SJerin Jacob 			const uint64_t pkts = processed_pkts(t);
1609d3aeb18SJerin Jacob 
1619d3aeb18SJerin Jacob 			remaining = t->outstand_pkts - pkts;
1629d3aeb18SJerin Jacob 			float mpps = (float)(perf_remaining-remaining)/1000000;
1639d3aeb18SJerin Jacob 
1649d3aeb18SJerin Jacob 			perf_remaining = remaining;
1659d3aeb18SJerin Jacob 			perf_cycles = new_cycles;
1669d3aeb18SJerin Jacob 			total_mpps += mpps;
1679d3aeb18SJerin Jacob 			++samples;
16804716352SJerin Jacob 			if (opt->fwd_latency && pkts > 0) {
1699d3aeb18SJerin Jacob 				printf(CLGRN"\r%.3f mpps avg %.3f mpps [avg fwd latency %.3f us] "CLNRM,
1709d3aeb18SJerin Jacob 					mpps, total_mpps/samples,
1719d3aeb18SJerin Jacob 					(float)(latency/pkts)/freq_mhz);
1729d3aeb18SJerin Jacob 			} else {
1739d3aeb18SJerin Jacob 				printf(CLGRN"\r%.3f mpps avg %.3f mpps"CLNRM,
1749d3aeb18SJerin Jacob 					mpps, total_mpps/samples);
1759d3aeb18SJerin Jacob 			}
1769d3aeb18SJerin Jacob 			fflush(stdout);
1779d3aeb18SJerin Jacob 
1789d3aeb18SJerin Jacob 			if (remaining <= 0) {
1799d3aeb18SJerin Jacob 				t->result = EVT_TEST_SUCCESS;
18059f697e3SPavan Nikhilesh 				if (opt->prod_type == EVT_PROD_TYPE_SYNT) {
18159f697e3SPavan Nikhilesh 					t->done = true;
1829d3aeb18SJerin Jacob 					rte_smp_wmb();
1839d3aeb18SJerin Jacob 					break;
1849d3aeb18SJerin Jacob 				}
1859d3aeb18SJerin Jacob 			}
18659f697e3SPavan Nikhilesh 		}
1879d3aeb18SJerin Jacob 
18859f697e3SPavan Nikhilesh 		if (new_cycles - dead_lock_cycles > dead_lock_sample &&
18959f697e3SPavan Nikhilesh 				opt->prod_type == EVT_PROD_TYPE_SYNT) {
1909d3aeb18SJerin Jacob 			remaining = t->outstand_pkts - processed_pkts(t);
1919d3aeb18SJerin Jacob 			if (dead_lock_remaining == remaining) {
1929d3aeb18SJerin Jacob 				rte_event_dev_dump(opt->dev_id, stdout);
1939d3aeb18SJerin Jacob 				evt_err("No schedules for seconds, deadlock");
1949d3aeb18SJerin Jacob 				t->done = true;
1959d3aeb18SJerin Jacob 				rte_smp_wmb();
1969d3aeb18SJerin Jacob 				break;
1979d3aeb18SJerin Jacob 			}
1989d3aeb18SJerin Jacob 			dead_lock_remaining = remaining;
1999d3aeb18SJerin Jacob 			dead_lock_cycles = new_cycles;
2009d3aeb18SJerin Jacob 		}
2019d3aeb18SJerin Jacob 	}
2029d3aeb18SJerin Jacob 	printf("\n");
2039d3aeb18SJerin Jacob 	return 0;
2049d3aeb18SJerin Jacob }
2059d3aeb18SJerin Jacob 
2063617aae5SPavan Nikhilesh static int
2073617aae5SPavan Nikhilesh perf_event_rx_adapter_setup(struct evt_options *opt, uint8_t stride,
2083617aae5SPavan Nikhilesh 		struct rte_event_port_conf prod_conf)
2093617aae5SPavan Nikhilesh {
2103617aae5SPavan Nikhilesh 	int ret = 0;
2113617aae5SPavan Nikhilesh 	uint16_t prod;
2123617aae5SPavan Nikhilesh 	struct rte_event_eth_rx_adapter_queue_conf queue_conf;
2133617aae5SPavan Nikhilesh 
2143617aae5SPavan Nikhilesh 	memset(&queue_conf, 0,
2153617aae5SPavan Nikhilesh 			sizeof(struct rte_event_eth_rx_adapter_queue_conf));
2163617aae5SPavan Nikhilesh 	queue_conf.ev.sched_type = opt->sched_type_list[0];
2173617aae5SPavan Nikhilesh 	for (prod = 0; prod < rte_eth_dev_count(); prod++) {
2183617aae5SPavan Nikhilesh 		uint32_t cap;
2193617aae5SPavan Nikhilesh 
2203617aae5SPavan Nikhilesh 		ret = rte_event_eth_rx_adapter_caps_get(opt->dev_id,
2213617aae5SPavan Nikhilesh 				prod, &cap);
2223617aae5SPavan Nikhilesh 		if (ret) {
2233617aae5SPavan Nikhilesh 			evt_err("failed to get event rx adapter[%d]"
2243617aae5SPavan Nikhilesh 					" capabilities",
2253617aae5SPavan Nikhilesh 					opt->dev_id);
2263617aae5SPavan Nikhilesh 			return ret;
2273617aae5SPavan Nikhilesh 		}
2283617aae5SPavan Nikhilesh 		queue_conf.ev.queue_id = prod * stride;
2293617aae5SPavan Nikhilesh 		ret = rte_event_eth_rx_adapter_create(prod, opt->dev_id,
2303617aae5SPavan Nikhilesh 				&prod_conf);
2313617aae5SPavan Nikhilesh 		if (ret) {
2323617aae5SPavan Nikhilesh 			evt_err("failed to create rx adapter[%d]", prod);
2333617aae5SPavan Nikhilesh 			return ret;
2343617aae5SPavan Nikhilesh 		}
2353617aae5SPavan Nikhilesh 		ret = rte_event_eth_rx_adapter_queue_add(prod, prod, -1,
2363617aae5SPavan Nikhilesh 				&queue_conf);
2373617aae5SPavan Nikhilesh 		if (ret) {
2383617aae5SPavan Nikhilesh 			evt_err("failed to add rx queues to adapter[%d]", prod);
2393617aae5SPavan Nikhilesh 			return ret;
2403617aae5SPavan Nikhilesh 		}
2413617aae5SPavan Nikhilesh 
242*b0333c55SPavan Nikhilesh 		if (!(cap & RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT)) {
243*b0333c55SPavan Nikhilesh 			uint32_t service_id;
244*b0333c55SPavan Nikhilesh 
245*b0333c55SPavan Nikhilesh 			rte_event_eth_rx_adapter_service_id_get(prod,
246*b0333c55SPavan Nikhilesh 					&service_id);
247*b0333c55SPavan Nikhilesh 			ret = evt_service_setup(service_id);
248*b0333c55SPavan Nikhilesh 			if (ret) {
249*b0333c55SPavan Nikhilesh 				evt_err("Failed to setup service core"
250*b0333c55SPavan Nikhilesh 						" for Rx adapter\n");
251*b0333c55SPavan Nikhilesh 				return ret;
252*b0333c55SPavan Nikhilesh 			}
253*b0333c55SPavan Nikhilesh 		}
254*b0333c55SPavan Nikhilesh 
2553617aae5SPavan Nikhilesh 		ret = rte_eth_dev_start(prod);
2563617aae5SPavan Nikhilesh 		if (ret) {
2573617aae5SPavan Nikhilesh 			evt_err("Ethernet dev [%d] failed to start."
2583617aae5SPavan Nikhilesh 					" Using synthetic producer", prod);
2593617aae5SPavan Nikhilesh 			return ret;
2603617aae5SPavan Nikhilesh 		}
2613617aae5SPavan Nikhilesh 
2623617aae5SPavan Nikhilesh 		ret = rte_event_eth_rx_adapter_start(prod);
2633617aae5SPavan Nikhilesh 		if (ret) {
2643617aae5SPavan Nikhilesh 			evt_err("Rx adapter[%d] start failed", prod);
2653617aae5SPavan Nikhilesh 			return ret;
2663617aae5SPavan Nikhilesh 		}
2673617aae5SPavan Nikhilesh 		printf("%s: Port[%d] using Rx adapter[%d] started\n", __func__,
2683617aae5SPavan Nikhilesh 				prod, prod);
2693617aae5SPavan Nikhilesh 	}
2703617aae5SPavan Nikhilesh 
2713617aae5SPavan Nikhilesh 	return ret;
2723617aae5SPavan Nikhilesh }
2733617aae5SPavan Nikhilesh 
274272de067SJerin Jacob int
27584a7513dSJerin Jacob perf_event_dev_port_setup(struct evt_test *test, struct evt_options *opt,
27684a7513dSJerin Jacob 				uint8_t stride, uint8_t nb_queues)
27784a7513dSJerin Jacob {
27884a7513dSJerin Jacob 	struct test_perf *t = evt_test_priv(test);
2793617aae5SPavan Nikhilesh 	uint16_t port, prod;
28084a7513dSJerin Jacob 	int ret = -1;
2813617aae5SPavan Nikhilesh 	struct rte_event_port_conf port_conf;
2823617aae5SPavan Nikhilesh 
2833617aae5SPavan Nikhilesh 	memset(&port_conf, 0, sizeof(struct rte_event_port_conf));
2843617aae5SPavan Nikhilesh 	rte_event_port_default_conf_get(opt->dev_id, 0, &port_conf);
28584a7513dSJerin Jacob 
28684a7513dSJerin Jacob 	/* port configuration */
28784a7513dSJerin Jacob 	const struct rte_event_port_conf wkr_p_conf = {
28884a7513dSJerin Jacob 			.dequeue_depth = opt->wkr_deq_dep,
2893617aae5SPavan Nikhilesh 			.enqueue_depth = port_conf.enqueue_depth,
2903617aae5SPavan Nikhilesh 			.new_event_threshold = port_conf.new_event_threshold,
29184a7513dSJerin Jacob 	};
29284a7513dSJerin Jacob 
29384a7513dSJerin Jacob 	/* setup one port per worker, linking to all queues */
29484a7513dSJerin Jacob 	for (port = 0; port < evt_nr_active_lcores(opt->wlcores);
29584a7513dSJerin Jacob 				port++) {
29684a7513dSJerin Jacob 		struct worker_data *w = &t->worker[port];
29784a7513dSJerin Jacob 
29884a7513dSJerin Jacob 		w->dev_id = opt->dev_id;
29984a7513dSJerin Jacob 		w->port_id = port;
30084a7513dSJerin Jacob 		w->t = t;
30184a7513dSJerin Jacob 		w->processed_pkts = 0;
30284a7513dSJerin Jacob 		w->latency = 0;
30384a7513dSJerin Jacob 
30484a7513dSJerin Jacob 		ret = rte_event_port_setup(opt->dev_id, port, &wkr_p_conf);
30584a7513dSJerin Jacob 		if (ret) {
30684a7513dSJerin Jacob 			evt_err("failed to setup port %d", port);
30784a7513dSJerin Jacob 			return ret;
30884a7513dSJerin Jacob 		}
30984a7513dSJerin Jacob 
31084a7513dSJerin Jacob 		ret = rte_event_port_link(opt->dev_id, port, NULL, NULL, 0);
31184a7513dSJerin Jacob 		if (ret != nb_queues) {
31284a7513dSJerin Jacob 			evt_err("failed to link all queues to port %d", port);
31384a7513dSJerin Jacob 			return -EINVAL;
31484a7513dSJerin Jacob 		}
31584a7513dSJerin Jacob 	}
31684a7513dSJerin Jacob 
31784a7513dSJerin Jacob 	/* port for producers, no links */
3183617aae5SPavan Nikhilesh 	struct rte_event_port_conf prod_conf = {
3193617aae5SPavan Nikhilesh 			.dequeue_depth = port_conf.dequeue_depth,
3203617aae5SPavan Nikhilesh 			.enqueue_depth = port_conf.enqueue_depth,
3213617aae5SPavan Nikhilesh 			.new_event_threshold = port_conf.new_event_threshold,
32284a7513dSJerin Jacob 	};
3233617aae5SPavan Nikhilesh 	if (opt->prod_type == EVT_PROD_TYPE_ETH_RX_ADPTR) {
3243617aae5SPavan Nikhilesh 		for ( ; port < perf_nb_event_ports(opt); port++) {
3253617aae5SPavan Nikhilesh 			struct prod_data *p = &t->prod[port];
3263617aae5SPavan Nikhilesh 			p->t = t;
3273617aae5SPavan Nikhilesh 		}
3283617aae5SPavan Nikhilesh 
3293617aae5SPavan Nikhilesh 		ret = perf_event_rx_adapter_setup(opt, stride, prod_conf);
3303617aae5SPavan Nikhilesh 		if (ret)
3313617aae5SPavan Nikhilesh 			return ret;
3323617aae5SPavan Nikhilesh 	} else {
33384a7513dSJerin Jacob 		prod = 0;
33484a7513dSJerin Jacob 		for ( ; port < perf_nb_event_ports(opt); port++) {
33584a7513dSJerin Jacob 			struct prod_data *p = &t->prod[port];
33684a7513dSJerin Jacob 
33784a7513dSJerin Jacob 			p->dev_id = opt->dev_id;
33884a7513dSJerin Jacob 			p->port_id = port;
33984a7513dSJerin Jacob 			p->queue_id = prod * stride;
34084a7513dSJerin Jacob 			p->t = t;
34184a7513dSJerin Jacob 
3423617aae5SPavan Nikhilesh 			ret = rte_event_port_setup(opt->dev_id, port,
3433617aae5SPavan Nikhilesh 					&prod_conf);
34484a7513dSJerin Jacob 			if (ret) {
34584a7513dSJerin Jacob 				evt_err("failed to setup port %d", port);
34684a7513dSJerin Jacob 				return ret;
34784a7513dSJerin Jacob 			}
34884a7513dSJerin Jacob 			prod++;
34984a7513dSJerin Jacob 		}
3503617aae5SPavan Nikhilesh 	}
35184a7513dSJerin Jacob 
35284a7513dSJerin Jacob 	return ret;
35384a7513dSJerin Jacob }
35484a7513dSJerin Jacob 
35584a7513dSJerin Jacob int
356272de067SJerin Jacob perf_opt_check(struct evt_options *opt, uint64_t nb_queues)
357272de067SJerin Jacob {
358272de067SJerin Jacob 	unsigned int lcores;
359272de067SJerin Jacob 
360b01974daSPavan Nikhilesh 	/* N producer + N worker + 1 master when producer cores are used
361b01974daSPavan Nikhilesh 	 * Else N worker + 1 master when Rx adapter is used
362b01974daSPavan Nikhilesh 	 */
363b01974daSPavan Nikhilesh 	lcores = opt->prod_type == EVT_PROD_TYPE_SYNT ? 3 : 2;
364272de067SJerin Jacob 
365272de067SJerin Jacob 	if (rte_lcore_count() < lcores) {
366272de067SJerin Jacob 		evt_err("test need minimum %d lcores", lcores);
367272de067SJerin Jacob 		return -1;
368272de067SJerin Jacob 	}
369272de067SJerin Jacob 
370272de067SJerin Jacob 	/* Validate worker lcores */
371272de067SJerin Jacob 	if (evt_lcores_has_overlap(opt->wlcores, rte_get_master_lcore())) {
372272de067SJerin Jacob 		evt_err("worker lcores overlaps with master lcore");
373272de067SJerin Jacob 		return -1;
374272de067SJerin Jacob 	}
375272de067SJerin Jacob 	if (evt_lcores_has_overlap_multi(opt->wlcores, opt->plcores)) {
376272de067SJerin Jacob 		evt_err("worker lcores overlaps producer lcores");
377272de067SJerin Jacob 		return -1;
378272de067SJerin Jacob 	}
379272de067SJerin Jacob 	if (evt_has_disabled_lcore(opt->wlcores)) {
380272de067SJerin Jacob 		evt_err("one or more workers lcores are not enabled");
381272de067SJerin Jacob 		return -1;
382272de067SJerin Jacob 	}
383272de067SJerin Jacob 	if (!evt_has_active_lcore(opt->wlcores)) {
384272de067SJerin Jacob 		evt_err("minimum one worker is required");
385272de067SJerin Jacob 		return -1;
386272de067SJerin Jacob 	}
387272de067SJerin Jacob 
388b01974daSPavan Nikhilesh 	if (opt->prod_type == EVT_PROD_TYPE_SYNT) {
389272de067SJerin Jacob 		/* Validate producer lcores */
390b01974daSPavan Nikhilesh 		if (evt_lcores_has_overlap(opt->plcores,
391b01974daSPavan Nikhilesh 					rte_get_master_lcore())) {
392272de067SJerin Jacob 			evt_err("producer lcores overlaps with master lcore");
393272de067SJerin Jacob 			return -1;
394272de067SJerin Jacob 		}
395272de067SJerin Jacob 		if (evt_has_disabled_lcore(opt->plcores)) {
396272de067SJerin Jacob 			evt_err("one or more producer lcores are not enabled");
397272de067SJerin Jacob 			return -1;
398272de067SJerin Jacob 		}
399272de067SJerin Jacob 		if (!evt_has_active_lcore(opt->plcores)) {
400272de067SJerin Jacob 			evt_err("minimum one producer is required");
401272de067SJerin Jacob 			return -1;
402272de067SJerin Jacob 		}
403b01974daSPavan Nikhilesh 	}
404272de067SJerin Jacob 
405272de067SJerin Jacob 	if (evt_has_invalid_stage(opt))
406272de067SJerin Jacob 		return -1;
407272de067SJerin Jacob 
408272de067SJerin Jacob 	if (evt_has_invalid_sched_type(opt))
409272de067SJerin Jacob 		return -1;
410272de067SJerin Jacob 
411272de067SJerin Jacob 	if (nb_queues > EVT_MAX_QUEUES) {
412272de067SJerin Jacob 		evt_err("number of queues exceeds %d", EVT_MAX_QUEUES);
413272de067SJerin Jacob 		return -1;
414272de067SJerin Jacob 	}
415272de067SJerin Jacob 	if (perf_nb_event_ports(opt) > EVT_MAX_PORTS) {
416272de067SJerin Jacob 		evt_err("number of ports exceeds %d", EVT_MAX_PORTS);
417272de067SJerin Jacob 		return -1;
418272de067SJerin Jacob 	}
419272de067SJerin Jacob 
420272de067SJerin Jacob 	/* Fixups */
421272de067SJerin Jacob 	if (opt->nb_stages == 1 && opt->fwd_latency) {
422272de067SJerin Jacob 		evt_info("fwd_latency is valid when nb_stages > 1, disabling");
423272de067SJerin Jacob 		opt->fwd_latency = 0;
424272de067SJerin Jacob 	}
425272de067SJerin Jacob 	if (opt->fwd_latency && !opt->q_priority) {
426272de067SJerin Jacob 		evt_info("enabled queue priority for latency measurement");
427272de067SJerin Jacob 		opt->q_priority = 1;
428272de067SJerin Jacob 	}
4299d3aeb18SJerin Jacob 	if (opt->nb_pkts == 0)
4309d3aeb18SJerin Jacob 		opt->nb_pkts = INT64_MAX/evt_nr_active_lcores(opt->plcores);
431272de067SJerin Jacob 
432272de067SJerin Jacob 	return 0;
433272de067SJerin Jacob }
434272de067SJerin Jacob 
435272de067SJerin Jacob void
436272de067SJerin Jacob perf_opt_dump(struct evt_options *opt, uint8_t nb_queues)
437272de067SJerin Jacob {
438272de067SJerin Jacob 	evt_dump("nb_prod_lcores", "%d", evt_nr_active_lcores(opt->plcores));
439272de067SJerin Jacob 	evt_dump_producer_lcores(opt);
440272de067SJerin Jacob 	evt_dump("nb_worker_lcores", "%d", evt_nr_active_lcores(opt->wlcores));
441272de067SJerin Jacob 	evt_dump_worker_lcores(opt);
442272de067SJerin Jacob 	evt_dump_nb_stages(opt);
443272de067SJerin Jacob 	evt_dump("nb_evdev_ports", "%d", perf_nb_event_ports(opt));
444272de067SJerin Jacob 	evt_dump("nb_evdev_queues", "%d", nb_queues);
445272de067SJerin Jacob 	evt_dump_queue_priority(opt);
446272de067SJerin Jacob 	evt_dump_sched_type_list(opt);
447b01974daSPavan Nikhilesh 	evt_dump_producer_type(opt);
448272de067SJerin Jacob }
449272de067SJerin Jacob 
45041c219e6SJerin Jacob void
45141c219e6SJerin Jacob perf_eventdev_destroy(struct evt_test *test, struct evt_options *opt)
45241c219e6SJerin Jacob {
45341c219e6SJerin Jacob 	RTE_SET_USED(test);
45441c219e6SJerin Jacob 
45541c219e6SJerin Jacob 	rte_event_dev_stop(opt->dev_id);
45641c219e6SJerin Jacob 	rte_event_dev_close(opt->dev_id);
45741c219e6SJerin Jacob }
45841c219e6SJerin Jacob 
45941c219e6SJerin Jacob static inline void
46041c219e6SJerin Jacob perf_elt_init(struct rte_mempool *mp, void *arg __rte_unused,
46141c219e6SJerin Jacob 	    void *obj, unsigned i __rte_unused)
46241c219e6SJerin Jacob {
46341c219e6SJerin Jacob 	memset(obj, 0, mp->elt_size);
46441c219e6SJerin Jacob }
46541c219e6SJerin Jacob 
4663fc8de4fSPavan Nikhilesh #define NB_RX_DESC			128
4673fc8de4fSPavan Nikhilesh #define NB_TX_DESC			512
4683fc8de4fSPavan Nikhilesh int
4693fc8de4fSPavan Nikhilesh perf_ethdev_setup(struct evt_test *test, struct evt_options *opt)
4703fc8de4fSPavan Nikhilesh {
4713fc8de4fSPavan Nikhilesh 	int i;
4723fc8de4fSPavan Nikhilesh 	struct test_perf *t = evt_test_priv(test);
4733fc8de4fSPavan Nikhilesh 	struct rte_eth_conf port_conf = {
4743fc8de4fSPavan Nikhilesh 		.rxmode = {
4753fc8de4fSPavan Nikhilesh 			.mq_mode = ETH_MQ_RX_RSS,
4763fc8de4fSPavan Nikhilesh 			.max_rx_pkt_len = ETHER_MAX_LEN,
4773fc8de4fSPavan Nikhilesh 			.split_hdr_size = 0,
4783fc8de4fSPavan Nikhilesh 			.header_split   = 0,
4793fc8de4fSPavan Nikhilesh 			.hw_ip_checksum = 0,
4803fc8de4fSPavan Nikhilesh 			.hw_vlan_filter = 0,
4813fc8de4fSPavan Nikhilesh 			.hw_vlan_strip  = 0,
4823fc8de4fSPavan Nikhilesh 			.hw_vlan_extend = 0,
4833fc8de4fSPavan Nikhilesh 			.jumbo_frame    = 0,
4843fc8de4fSPavan Nikhilesh 			.hw_strip_crc   = 1,
4853fc8de4fSPavan Nikhilesh 		},
4863fc8de4fSPavan Nikhilesh 		.rx_adv_conf = {
4873fc8de4fSPavan Nikhilesh 			.rss_conf = {
4883fc8de4fSPavan Nikhilesh 				.rss_key = NULL,
4893fc8de4fSPavan Nikhilesh 				.rss_hf = ETH_RSS_IP,
4903fc8de4fSPavan Nikhilesh 			},
4913fc8de4fSPavan Nikhilesh 		},
4923fc8de4fSPavan Nikhilesh 	};
4933fc8de4fSPavan Nikhilesh 
4943fc8de4fSPavan Nikhilesh 	if (opt->prod_type == EVT_PROD_TYPE_SYNT)
4953fc8de4fSPavan Nikhilesh 		return 0;
4963fc8de4fSPavan Nikhilesh 
4973fc8de4fSPavan Nikhilesh 	if (!rte_eth_dev_count()) {
4983fc8de4fSPavan Nikhilesh 		evt_err("No ethernet ports found.");
4993fc8de4fSPavan Nikhilesh 		return -ENODEV;
5003fc8de4fSPavan Nikhilesh 	}
5013fc8de4fSPavan Nikhilesh 
5023fc8de4fSPavan Nikhilesh 	for (i = 0; i < rte_eth_dev_count(); i++) {
5033fc8de4fSPavan Nikhilesh 
5043fc8de4fSPavan Nikhilesh 		if (rte_eth_dev_configure(i, 1, 1,
5053fc8de4fSPavan Nikhilesh 					&port_conf)
5063fc8de4fSPavan Nikhilesh 				< 0) {
5073fc8de4fSPavan Nikhilesh 			evt_err("Failed to configure eth port [%d]", i);
5083fc8de4fSPavan Nikhilesh 			return -EINVAL;
5093fc8de4fSPavan Nikhilesh 		}
5103fc8de4fSPavan Nikhilesh 
5113fc8de4fSPavan Nikhilesh 		if (rte_eth_rx_queue_setup(i, 0, NB_RX_DESC,
5123fc8de4fSPavan Nikhilesh 				rte_socket_id(), NULL, t->pool) < 0) {
5133fc8de4fSPavan Nikhilesh 			evt_err("Failed to setup eth port [%d] rx_queue: %d.",
5143fc8de4fSPavan Nikhilesh 					i, 0);
5153fc8de4fSPavan Nikhilesh 			return -EINVAL;
5163fc8de4fSPavan Nikhilesh 		}
5173fc8de4fSPavan Nikhilesh 
5183fc8de4fSPavan Nikhilesh 		if (rte_eth_tx_queue_setup(i, 0, NB_TX_DESC,
5193fc8de4fSPavan Nikhilesh 					rte_socket_id(), NULL) < 0) {
5203fc8de4fSPavan Nikhilesh 			evt_err("Failed to setup eth port [%d] tx_queue: %d.",
5213fc8de4fSPavan Nikhilesh 					i, 0);
5223fc8de4fSPavan Nikhilesh 			return -EINVAL;
5233fc8de4fSPavan Nikhilesh 		}
5243fc8de4fSPavan Nikhilesh 
5253fc8de4fSPavan Nikhilesh 		rte_eth_promiscuous_enable(i);
5263fc8de4fSPavan Nikhilesh 	}
5273fc8de4fSPavan Nikhilesh 
5283fc8de4fSPavan Nikhilesh 	return 0;
5293fc8de4fSPavan Nikhilesh }
5303fc8de4fSPavan Nikhilesh 
5317f3daf34SPavan Nikhilesh void perf_ethdev_destroy(struct evt_test *test, struct evt_options *opt)
5327f3daf34SPavan Nikhilesh {
5337f3daf34SPavan Nikhilesh 	int i;
5347f3daf34SPavan Nikhilesh 	RTE_SET_USED(test);
5357f3daf34SPavan Nikhilesh 
5367f3daf34SPavan Nikhilesh 	if (opt->prod_type == EVT_PROD_TYPE_ETH_RX_ADPTR) {
5377f3daf34SPavan Nikhilesh 		for (i = 0; i < rte_eth_dev_count(); i++) {
5383617aae5SPavan Nikhilesh 			rte_event_eth_rx_adapter_stop(i);
5397f3daf34SPavan Nikhilesh 			rte_eth_dev_stop(i);
5407f3daf34SPavan Nikhilesh 			rte_eth_dev_close(i);
5417f3daf34SPavan Nikhilesh 		}
5427f3daf34SPavan Nikhilesh 	}
5437f3daf34SPavan Nikhilesh }
5447f3daf34SPavan Nikhilesh 
54541c219e6SJerin Jacob int
54641c219e6SJerin Jacob perf_mempool_setup(struct evt_test *test, struct evt_options *opt)
54741c219e6SJerin Jacob {
54841c219e6SJerin Jacob 	struct test_perf *t = evt_test_priv(test);
54941c219e6SJerin Jacob 
5508577cc1aSPavan Nikhilesh 	if (opt->prod_type == EVT_PROD_TYPE_SYNT) {
55141c219e6SJerin Jacob 		t->pool = rte_mempool_create(test->name, /* mempool name */
55241c219e6SJerin Jacob 				opt->pool_sz, /* number of elements*/
55341c219e6SJerin Jacob 				sizeof(struct perf_elt), /* element size*/
55441c219e6SJerin Jacob 				512, /* cache size*/
55541c219e6SJerin Jacob 				0, NULL, NULL,
55641c219e6SJerin Jacob 				perf_elt_init, /* obj constructor */
55741c219e6SJerin Jacob 				NULL, opt->socket_id, 0); /* flags */
5588577cc1aSPavan Nikhilesh 	} else {
5598577cc1aSPavan Nikhilesh 		t->pool = rte_pktmbuf_pool_create(test->name, /* mempool name */
5608577cc1aSPavan Nikhilesh 				opt->pool_sz, /* number of elements*/
5618577cc1aSPavan Nikhilesh 				512, /* cache size*/
5628577cc1aSPavan Nikhilesh 				0,
5638577cc1aSPavan Nikhilesh 				RTE_MBUF_DEFAULT_BUF_SIZE,
5648577cc1aSPavan Nikhilesh 				opt->socket_id); /* flags */
5658577cc1aSPavan Nikhilesh 
5668577cc1aSPavan Nikhilesh 	}
5678577cc1aSPavan Nikhilesh 
56841c219e6SJerin Jacob 	if (t->pool == NULL) {
56941c219e6SJerin Jacob 		evt_err("failed to create mempool");
57041c219e6SJerin Jacob 		return -ENOMEM;
57141c219e6SJerin Jacob 	}
57241c219e6SJerin Jacob 
57341c219e6SJerin Jacob 	return 0;
57441c219e6SJerin Jacob }
57541c219e6SJerin Jacob 
57641c219e6SJerin Jacob void
57741c219e6SJerin Jacob perf_mempool_destroy(struct evt_test *test, struct evt_options *opt)
57841c219e6SJerin Jacob {
57941c219e6SJerin Jacob 	RTE_SET_USED(opt);
58041c219e6SJerin Jacob 	struct test_perf *t = evt_test_priv(test);
58141c219e6SJerin Jacob 
58241c219e6SJerin Jacob 	rte_mempool_free(t->pool);
58341c219e6SJerin Jacob }
584ffbae86fSJerin Jacob 
585ffbae86fSJerin Jacob int
586ffbae86fSJerin Jacob perf_test_setup(struct evt_test *test, struct evt_options *opt)
587ffbae86fSJerin Jacob {
588ffbae86fSJerin Jacob 	void *test_perf;
589ffbae86fSJerin Jacob 
590ffbae86fSJerin Jacob 	test_perf = rte_zmalloc_socket(test->name, sizeof(struct test_perf),
591ffbae86fSJerin Jacob 				RTE_CACHE_LINE_SIZE, opt->socket_id);
592ffbae86fSJerin Jacob 	if (test_perf  == NULL) {
593ffbae86fSJerin Jacob 		evt_err("failed to allocate test_perf memory");
594ffbae86fSJerin Jacob 		goto nomem;
595ffbae86fSJerin Jacob 	}
596ffbae86fSJerin Jacob 	test->test_priv = test_perf;
597ffbae86fSJerin Jacob 
598ffbae86fSJerin Jacob 	struct test_perf *t = evt_test_priv(test);
599ffbae86fSJerin Jacob 
600ffbae86fSJerin Jacob 	t->outstand_pkts = opt->nb_pkts * evt_nr_active_lcores(opt->plcores);
601ffbae86fSJerin Jacob 	t->nb_workers = evt_nr_active_lcores(opt->wlcores);
602ffbae86fSJerin Jacob 	t->done = false;
603ffbae86fSJerin Jacob 	t->nb_pkts = opt->nb_pkts;
604ffbae86fSJerin Jacob 	t->nb_flows = opt->nb_flows;
605ffbae86fSJerin Jacob 	t->result = EVT_TEST_FAILED;
606ffbae86fSJerin Jacob 	t->opt = opt;
607ffbae86fSJerin Jacob 	memcpy(t->sched_type_list, opt->sched_type_list,
608ffbae86fSJerin Jacob 			sizeof(opt->sched_type_list));
609ffbae86fSJerin Jacob 	return 0;
610ffbae86fSJerin Jacob nomem:
611ffbae86fSJerin Jacob 	return -ENOMEM;
612ffbae86fSJerin Jacob }
613ffbae86fSJerin Jacob 
614ffbae86fSJerin Jacob void
615ffbae86fSJerin Jacob perf_test_destroy(struct evt_test *test, struct evt_options *opt)
616ffbae86fSJerin Jacob {
617ffbae86fSJerin Jacob 	RTE_SET_USED(opt);
618ffbae86fSJerin Jacob 
619ffbae86fSJerin Jacob 	rte_free(test->test_priv);
620ffbae86fSJerin Jacob }
621