xref: /dpdk/app/test-eventdev/test_perf_common.c (revision 52553263484a3ad3b24b9fa76b14aebbc4e8a526)
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);
116b1a14a8SPavan Nikhilesh 	int i;
126b1a14a8SPavan Nikhilesh 	uint64_t total = 0;
1341c219e6SJerin Jacob 	struct test_perf *t = evt_test_priv(test);
1441c219e6SJerin Jacob 
156b1a14a8SPavan Nikhilesh 	printf("Packet distribution across worker cores :\n");
166b1a14a8SPavan Nikhilesh 	for (i = 0; i < t->nb_workers; i++)
176b1a14a8SPavan Nikhilesh 		total += t->worker[i].processed_pkts;
186b1a14a8SPavan Nikhilesh 	for (i = 0; i < t->nb_workers; i++)
196b1a14a8SPavan Nikhilesh 		printf("Worker %d packets: "CLGRN"%"PRIx64" "CLNRM"percentage:"
206b1a14a8SPavan Nikhilesh 				CLGRN" %3.2f\n"CLNRM, i,
216b1a14a8SPavan Nikhilesh 				t->worker[i].processed_pkts,
226b1a14a8SPavan Nikhilesh 				(((double)t->worker[i].processed_pkts)/total)
236b1a14a8SPavan Nikhilesh 				* 100);
246b1a14a8SPavan Nikhilesh 
2541c219e6SJerin Jacob 	return t->result;
2641c219e6SJerin Jacob }
2741c219e6SJerin Jacob 
289d3aeb18SJerin Jacob static inline int
299d3aeb18SJerin Jacob perf_producer(void *arg)
309d3aeb18SJerin Jacob {
319d3aeb18SJerin Jacob 	struct prod_data *p  = arg;
329d3aeb18SJerin Jacob 	struct test_perf *t = p->t;
339d3aeb18SJerin Jacob 	struct evt_options *opt = t->opt;
349d3aeb18SJerin Jacob 	const uint8_t dev_id = p->dev_id;
359d3aeb18SJerin Jacob 	const uint8_t port = p->port_id;
369d3aeb18SJerin Jacob 	struct rte_mempool *pool = t->pool;
379d3aeb18SJerin Jacob 	const uint64_t nb_pkts = t->nb_pkts;
389d3aeb18SJerin Jacob 	const uint32_t nb_flows = t->nb_flows;
399d3aeb18SJerin Jacob 	uint32_t flow_counter = 0;
409d3aeb18SJerin Jacob 	uint64_t count = 0;
419d3aeb18SJerin Jacob 	struct perf_elt *m;
429d3aeb18SJerin Jacob 	struct rte_event ev;
439d3aeb18SJerin Jacob 
449d3aeb18SJerin Jacob 	if (opt->verbose_level > 1)
459d3aeb18SJerin Jacob 		printf("%s(): lcore %d dev_id %d port=%d queue %d\n", __func__,
469d3aeb18SJerin Jacob 				rte_lcore_id(), dev_id, port, p->queue_id);
479d3aeb18SJerin Jacob 
489d3aeb18SJerin Jacob 	ev.event = 0;
499d3aeb18SJerin Jacob 	ev.op = RTE_EVENT_OP_NEW;
509d3aeb18SJerin Jacob 	ev.queue_id = p->queue_id;
519d3aeb18SJerin Jacob 	ev.sched_type = t->opt->sched_type_list[0];
529d3aeb18SJerin Jacob 	ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL;
539d3aeb18SJerin Jacob 	ev.event_type =  RTE_EVENT_TYPE_CPU;
549d3aeb18SJerin Jacob 	ev.sub_event_type = 0; /* stage 0 */
559d3aeb18SJerin Jacob 
569d3aeb18SJerin Jacob 	while (count < nb_pkts && t->done == false) {
579d3aeb18SJerin Jacob 		if (rte_mempool_get(pool, (void **)&m) < 0)
589d3aeb18SJerin Jacob 			continue;
599d3aeb18SJerin Jacob 
609d3aeb18SJerin Jacob 		ev.flow_id = flow_counter++ % nb_flows;
619d3aeb18SJerin Jacob 		ev.event_ptr = m;
629d3aeb18SJerin Jacob 		m->timestamp = rte_get_timer_cycles();
639d3aeb18SJerin Jacob 		while (rte_event_enqueue_burst(dev_id, port, &ev, 1) != 1) {
649d3aeb18SJerin Jacob 			if (t->done)
659d3aeb18SJerin Jacob 				break;
669d3aeb18SJerin Jacob 			rte_pause();
679d3aeb18SJerin Jacob 			m->timestamp = rte_get_timer_cycles();
689d3aeb18SJerin Jacob 		}
699d3aeb18SJerin Jacob 		count++;
709d3aeb18SJerin Jacob 	}
719d3aeb18SJerin Jacob 
729d3aeb18SJerin Jacob 	return 0;
739d3aeb18SJerin Jacob }
749d3aeb18SJerin Jacob 
75d008f20bSPavan Nikhilesh static inline int
76d008f20bSPavan Nikhilesh perf_event_timer_producer(void *arg)
77d008f20bSPavan Nikhilesh {
78d008f20bSPavan Nikhilesh 	struct prod_data *p  = arg;
79d008f20bSPavan Nikhilesh 	struct test_perf *t = p->t;
80d008f20bSPavan Nikhilesh 	struct evt_options *opt = t->opt;
81d008f20bSPavan Nikhilesh 	uint32_t flow_counter = 0;
82d008f20bSPavan Nikhilesh 	uint64_t count = 0;
83d008f20bSPavan Nikhilesh 	uint64_t arm_latency = 0;
84d008f20bSPavan Nikhilesh 	const uint8_t nb_timer_adptrs = opt->nb_timer_adptrs;
85d008f20bSPavan Nikhilesh 	const uint32_t nb_flows = t->nb_flows;
86d008f20bSPavan Nikhilesh 	const uint64_t nb_timers = opt->nb_timers;
87d008f20bSPavan Nikhilesh 	struct rte_mempool *pool = t->pool;
88d008f20bSPavan Nikhilesh 	struct perf_elt *m;
89d008f20bSPavan Nikhilesh 	struct rte_event_timer_adapter **adptr = t->timer_adptr;
90*52553263SPavan Nikhilesh 	struct rte_event_timer tim;
91d008f20bSPavan Nikhilesh 	uint64_t timeout_ticks = opt->expiry_nsec / opt->timer_tick_nsec;
92d008f20bSPavan Nikhilesh 
93*52553263SPavan Nikhilesh 	memset(&tim, 0, sizeof(struct rte_event_timer));
94d008f20bSPavan Nikhilesh 	timeout_ticks = opt->optm_timer_tick_nsec ?
95d008f20bSPavan Nikhilesh 			(timeout_ticks * opt->timer_tick_nsec)
96d008f20bSPavan Nikhilesh 			/ opt->optm_timer_tick_nsec : timeout_ticks;
97d008f20bSPavan Nikhilesh 	timeout_ticks += timeout_ticks ? 0 : 1;
98*52553263SPavan Nikhilesh 	tim.ev.event_type =  RTE_EVENT_TYPE_TIMER;
99*52553263SPavan Nikhilesh 	tim.ev.op = RTE_EVENT_OP_NEW;
100*52553263SPavan Nikhilesh 	tim.ev.sched_type = t->opt->sched_type_list[0];
101*52553263SPavan Nikhilesh 	tim.ev.queue_id = p->queue_id;
102*52553263SPavan Nikhilesh 	tim.ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL;
103*52553263SPavan Nikhilesh 	tim.state = RTE_EVENT_TIMER_NOT_ARMED;
104*52553263SPavan Nikhilesh 	tim.timeout_ticks = timeout_ticks;
105d008f20bSPavan Nikhilesh 
106d008f20bSPavan Nikhilesh 	if (opt->verbose_level > 1)
107d008f20bSPavan Nikhilesh 		printf("%s(): lcore %d\n", __func__, rte_lcore_id());
108d008f20bSPavan Nikhilesh 
109d008f20bSPavan Nikhilesh 	while (count < nb_timers && t->done == false) {
110d008f20bSPavan Nikhilesh 		if (rte_mempool_get(pool, (void **)&m) < 0)
111d008f20bSPavan Nikhilesh 			continue;
112d008f20bSPavan Nikhilesh 
113d008f20bSPavan Nikhilesh 		m->tim = tim;
114d008f20bSPavan Nikhilesh 		m->tim.ev.flow_id = flow_counter++ % nb_flows;
115d008f20bSPavan Nikhilesh 		m->tim.ev.event_ptr = m;
116d008f20bSPavan Nikhilesh 		m->timestamp = rte_get_timer_cycles();
117d008f20bSPavan Nikhilesh 		while (rte_event_timer_arm_burst(
118d008f20bSPavan Nikhilesh 				adptr[flow_counter % nb_timer_adptrs],
119d008f20bSPavan Nikhilesh 				(struct rte_event_timer **)&m, 1) != 1) {
120d008f20bSPavan Nikhilesh 			if (t->done)
121d008f20bSPavan Nikhilesh 				break;
122d008f20bSPavan Nikhilesh 			rte_pause();
123d008f20bSPavan Nikhilesh 			m->timestamp = rte_get_timer_cycles();
124d008f20bSPavan Nikhilesh 		}
125d008f20bSPavan Nikhilesh 		arm_latency += rte_get_timer_cycles() - m->timestamp;
126d008f20bSPavan Nikhilesh 		count++;
127d008f20bSPavan Nikhilesh 	}
128d008f20bSPavan Nikhilesh 	fflush(stdout);
129d008f20bSPavan Nikhilesh 	rte_delay_ms(1000);
130d008f20bSPavan Nikhilesh 	printf("%s(): lcore %d Average event timer arm latency = %.3f us\n",
131d008f20bSPavan Nikhilesh 			__func__, rte_lcore_id(), (float)(arm_latency / count) /
132d008f20bSPavan Nikhilesh 			(rte_get_timer_hz() / 1000000));
133d008f20bSPavan Nikhilesh 	return 0;
134d008f20bSPavan Nikhilesh }
135d008f20bSPavan Nikhilesh 
13617b22d0bSPavan Nikhilesh static inline int
13717b22d0bSPavan Nikhilesh perf_event_timer_producer_burst(void *arg)
13817b22d0bSPavan Nikhilesh {
13917b22d0bSPavan Nikhilesh 	int i;
14017b22d0bSPavan Nikhilesh 	struct prod_data *p  = arg;
14117b22d0bSPavan Nikhilesh 	struct test_perf *t = p->t;
14217b22d0bSPavan Nikhilesh 	struct evt_options *opt = t->opt;
14317b22d0bSPavan Nikhilesh 	uint32_t flow_counter = 0;
14417b22d0bSPavan Nikhilesh 	uint64_t count = 0;
14517b22d0bSPavan Nikhilesh 	uint64_t arm_latency = 0;
14617b22d0bSPavan Nikhilesh 	const uint8_t nb_timer_adptrs = opt->nb_timer_adptrs;
14717b22d0bSPavan Nikhilesh 	const uint32_t nb_flows = t->nb_flows;
14817b22d0bSPavan Nikhilesh 	const uint64_t nb_timers = opt->nb_timers;
14917b22d0bSPavan Nikhilesh 	struct rte_mempool *pool = t->pool;
15017b22d0bSPavan Nikhilesh 	struct perf_elt *m[BURST_SIZE + 1] = {NULL};
15117b22d0bSPavan Nikhilesh 	struct rte_event_timer_adapter **adptr = t->timer_adptr;
152*52553263SPavan Nikhilesh 	struct rte_event_timer tim;
15317b22d0bSPavan Nikhilesh 	uint64_t timeout_ticks = opt->expiry_nsec / opt->timer_tick_nsec;
15417b22d0bSPavan Nikhilesh 
155*52553263SPavan Nikhilesh 	memset(&tim, 0, sizeof(struct rte_event_timer));
15617b22d0bSPavan Nikhilesh 	timeout_ticks = opt->optm_timer_tick_nsec ?
15717b22d0bSPavan Nikhilesh 			(timeout_ticks * opt->timer_tick_nsec)
15817b22d0bSPavan Nikhilesh 			/ opt->optm_timer_tick_nsec : timeout_ticks;
15917b22d0bSPavan Nikhilesh 	timeout_ticks += timeout_ticks ? 0 : 1;
160*52553263SPavan Nikhilesh 	tim.ev.event_type =  RTE_EVENT_TYPE_TIMER;
161*52553263SPavan Nikhilesh 	tim.ev.op = RTE_EVENT_OP_NEW;
162*52553263SPavan Nikhilesh 	tim.ev.sched_type = t->opt->sched_type_list[0];
163*52553263SPavan Nikhilesh 	tim.ev.queue_id = p->queue_id;
164*52553263SPavan Nikhilesh 	tim.ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL;
165*52553263SPavan Nikhilesh 	tim.state = RTE_EVENT_TIMER_NOT_ARMED;
166*52553263SPavan Nikhilesh 	tim.timeout_ticks = timeout_ticks;
16717b22d0bSPavan Nikhilesh 
16817b22d0bSPavan Nikhilesh 	if (opt->verbose_level > 1)
16917b22d0bSPavan Nikhilesh 		printf("%s(): lcore %d\n", __func__, rte_lcore_id());
17017b22d0bSPavan Nikhilesh 
17117b22d0bSPavan Nikhilesh 	while (count < nb_timers && t->done == false) {
17217b22d0bSPavan Nikhilesh 		if (rte_mempool_get_bulk(pool, (void **)m, BURST_SIZE) < 0)
17317b22d0bSPavan Nikhilesh 			continue;
17417b22d0bSPavan Nikhilesh 		for (i = 0; i < BURST_SIZE; i++) {
17517b22d0bSPavan Nikhilesh 			rte_prefetch0(m[i + 1]);
17617b22d0bSPavan Nikhilesh 			m[i]->tim = tim;
17717b22d0bSPavan Nikhilesh 			m[i]->tim.ev.flow_id = flow_counter++ % nb_flows;
17817b22d0bSPavan Nikhilesh 			m[i]->tim.ev.event_ptr = m[i];
17917b22d0bSPavan Nikhilesh 			m[i]->timestamp = rte_get_timer_cycles();
18017b22d0bSPavan Nikhilesh 		}
18117b22d0bSPavan Nikhilesh 		rte_event_timer_arm_tmo_tick_burst(
18217b22d0bSPavan Nikhilesh 				adptr[flow_counter % nb_timer_adptrs],
18317b22d0bSPavan Nikhilesh 				(struct rte_event_timer **)m,
18417b22d0bSPavan Nikhilesh 				tim.timeout_ticks,
18517b22d0bSPavan Nikhilesh 				BURST_SIZE);
18617b22d0bSPavan Nikhilesh 		arm_latency += rte_get_timer_cycles() - m[i - 1]->timestamp;
18717b22d0bSPavan Nikhilesh 		count += BURST_SIZE;
18817b22d0bSPavan Nikhilesh 	}
18917b22d0bSPavan Nikhilesh 	fflush(stdout);
19017b22d0bSPavan Nikhilesh 	rte_delay_ms(1000);
19117b22d0bSPavan Nikhilesh 	printf("%s(): lcore %d Average event timer arm latency = %.3f us\n",
19217b22d0bSPavan Nikhilesh 			__func__, rte_lcore_id(), (float)(arm_latency / count) /
19317b22d0bSPavan Nikhilesh 			(rte_get_timer_hz() / 1000000));
19417b22d0bSPavan Nikhilesh 	return 0;
19517b22d0bSPavan Nikhilesh }
19617b22d0bSPavan Nikhilesh 
19759f697e3SPavan Nikhilesh static int
19859f697e3SPavan Nikhilesh perf_producer_wrapper(void *arg)
19959f697e3SPavan Nikhilesh {
20059f697e3SPavan Nikhilesh 	struct prod_data *p  = arg;
20159f697e3SPavan Nikhilesh 	struct test_perf *t = p->t;
20259f697e3SPavan Nikhilesh 	/* Launch the producer function only in case of synthetic producer. */
20359f697e3SPavan Nikhilesh 	if (t->opt->prod_type == EVT_PROD_TYPE_SYNT)
20459f697e3SPavan Nikhilesh 		return perf_producer(arg);
20517b22d0bSPavan Nikhilesh 	else if (t->opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR &&
20617b22d0bSPavan Nikhilesh 			!t->opt->timdev_use_burst)
207d008f20bSPavan Nikhilesh 		return perf_event_timer_producer(arg);
20817b22d0bSPavan Nikhilesh 	else if (t->opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR &&
20917b22d0bSPavan Nikhilesh 			t->opt->timdev_use_burst)
21017b22d0bSPavan Nikhilesh 		return perf_event_timer_producer_burst(arg);
21159f697e3SPavan Nikhilesh 	return 0;
21259f697e3SPavan Nikhilesh }
21359f697e3SPavan Nikhilesh 
2149d3aeb18SJerin Jacob static inline uint64_t
2159d3aeb18SJerin Jacob processed_pkts(struct test_perf *t)
2169d3aeb18SJerin Jacob {
2179d3aeb18SJerin Jacob 	uint8_t i;
2189d3aeb18SJerin Jacob 	uint64_t total = 0;
2199d3aeb18SJerin Jacob 
2209d3aeb18SJerin Jacob 	rte_smp_rmb();
2219d3aeb18SJerin Jacob 	for (i = 0; i < t->nb_workers; i++)
2229d3aeb18SJerin Jacob 		total += t->worker[i].processed_pkts;
2239d3aeb18SJerin Jacob 
2249d3aeb18SJerin Jacob 	return total;
2259d3aeb18SJerin Jacob }
2269d3aeb18SJerin Jacob 
2279d3aeb18SJerin Jacob static inline uint64_t
2289d3aeb18SJerin Jacob total_latency(struct test_perf *t)
2299d3aeb18SJerin Jacob {
2309d3aeb18SJerin Jacob 	uint8_t i;
2319d3aeb18SJerin Jacob 	uint64_t total = 0;
2329d3aeb18SJerin Jacob 
2339d3aeb18SJerin Jacob 	rte_smp_rmb();
2349d3aeb18SJerin Jacob 	for (i = 0; i < t->nb_workers; i++)
2359d3aeb18SJerin Jacob 		total += t->worker[i].latency;
2369d3aeb18SJerin Jacob 
2379d3aeb18SJerin Jacob 	return total;
2389d3aeb18SJerin Jacob }
2399d3aeb18SJerin Jacob 
2409d3aeb18SJerin Jacob 
2419d3aeb18SJerin Jacob int
2429d3aeb18SJerin Jacob perf_launch_lcores(struct evt_test *test, struct evt_options *opt,
2439d3aeb18SJerin Jacob 		int (*worker)(void *))
2449d3aeb18SJerin Jacob {
2459d3aeb18SJerin Jacob 	int ret, lcore_id;
2469d3aeb18SJerin Jacob 	struct test_perf *t = evt_test_priv(test);
2479d3aeb18SJerin Jacob 
2489d3aeb18SJerin Jacob 	int port_idx = 0;
2499d3aeb18SJerin Jacob 	/* launch workers */
2509d3aeb18SJerin Jacob 	RTE_LCORE_FOREACH_SLAVE(lcore_id) {
2519d3aeb18SJerin Jacob 		if (!(opt->wlcores[lcore_id]))
2529d3aeb18SJerin Jacob 			continue;
2539d3aeb18SJerin Jacob 
2549d3aeb18SJerin Jacob 		ret = rte_eal_remote_launch(worker,
2559d3aeb18SJerin Jacob 				 &t->worker[port_idx], lcore_id);
2569d3aeb18SJerin Jacob 		if (ret) {
2579d3aeb18SJerin Jacob 			evt_err("failed to launch worker %d", lcore_id);
2589d3aeb18SJerin Jacob 			return ret;
2599d3aeb18SJerin Jacob 		}
2609d3aeb18SJerin Jacob 		port_idx++;
2619d3aeb18SJerin Jacob 	}
2629d3aeb18SJerin Jacob 
2639d3aeb18SJerin Jacob 	/* launch producers */
2649d3aeb18SJerin Jacob 	RTE_LCORE_FOREACH_SLAVE(lcore_id) {
2659d3aeb18SJerin Jacob 		if (!(opt->plcores[lcore_id]))
2669d3aeb18SJerin Jacob 			continue;
2679d3aeb18SJerin Jacob 
26859f697e3SPavan Nikhilesh 		ret = rte_eal_remote_launch(perf_producer_wrapper,
26959f697e3SPavan Nikhilesh 				&t->prod[port_idx], lcore_id);
2709d3aeb18SJerin Jacob 		if (ret) {
2719d3aeb18SJerin Jacob 			evt_err("failed to launch perf_producer %d", lcore_id);
2729d3aeb18SJerin Jacob 			return ret;
2739d3aeb18SJerin Jacob 		}
2749d3aeb18SJerin Jacob 		port_idx++;
2759d3aeb18SJerin Jacob 	}
2769d3aeb18SJerin Jacob 
277d008f20bSPavan Nikhilesh 	const uint64_t total_pkts = t->outstand_pkts;
2789d3aeb18SJerin Jacob 
2799d3aeb18SJerin Jacob 	uint64_t dead_lock_cycles = rte_get_timer_cycles();
2809d3aeb18SJerin Jacob 	int64_t dead_lock_remaining  =  total_pkts;
2819d3aeb18SJerin Jacob 	const uint64_t dead_lock_sample = rte_get_timer_hz() * 5;
2829d3aeb18SJerin Jacob 
2839d3aeb18SJerin Jacob 	uint64_t perf_cycles = rte_get_timer_cycles();
2849d3aeb18SJerin Jacob 	int64_t perf_remaining  = total_pkts;
2859d3aeb18SJerin Jacob 	const uint64_t perf_sample = rte_get_timer_hz();
2869d3aeb18SJerin Jacob 
2879d3aeb18SJerin Jacob 	static float total_mpps;
2889d3aeb18SJerin Jacob 	static uint64_t samples;
2899d3aeb18SJerin Jacob 
2909d3aeb18SJerin Jacob 	const uint64_t freq_mhz = rte_get_timer_hz() / 1000000;
2919d3aeb18SJerin Jacob 	int64_t remaining = t->outstand_pkts - processed_pkts(t);
2929d3aeb18SJerin Jacob 
2939d3aeb18SJerin Jacob 	while (t->done == false) {
2949d3aeb18SJerin Jacob 		const uint64_t new_cycles = rte_get_timer_cycles();
2959d3aeb18SJerin Jacob 
2969d3aeb18SJerin Jacob 		if ((new_cycles - perf_cycles) > perf_sample) {
2979d3aeb18SJerin Jacob 			const uint64_t latency = total_latency(t);
2989d3aeb18SJerin Jacob 			const uint64_t pkts = processed_pkts(t);
2999d3aeb18SJerin Jacob 
3009d3aeb18SJerin Jacob 			remaining = t->outstand_pkts - pkts;
3019d3aeb18SJerin Jacob 			float mpps = (float)(perf_remaining-remaining)/1000000;
3029d3aeb18SJerin Jacob 
3039d3aeb18SJerin Jacob 			perf_remaining = remaining;
3049d3aeb18SJerin Jacob 			perf_cycles = new_cycles;
3059d3aeb18SJerin Jacob 			total_mpps += mpps;
3069d3aeb18SJerin Jacob 			++samples;
30704716352SJerin Jacob 			if (opt->fwd_latency && pkts > 0) {
3089d3aeb18SJerin Jacob 				printf(CLGRN"\r%.3f mpps avg %.3f mpps [avg fwd latency %.3f us] "CLNRM,
3099d3aeb18SJerin Jacob 					mpps, total_mpps/samples,
3109d3aeb18SJerin Jacob 					(float)(latency/pkts)/freq_mhz);
3119d3aeb18SJerin Jacob 			} else {
3129d3aeb18SJerin Jacob 				printf(CLGRN"\r%.3f mpps avg %.3f mpps"CLNRM,
3139d3aeb18SJerin Jacob 					mpps, total_mpps/samples);
3149d3aeb18SJerin Jacob 			}
3159d3aeb18SJerin Jacob 			fflush(stdout);
3169d3aeb18SJerin Jacob 
3179d3aeb18SJerin Jacob 			if (remaining <= 0) {
3189d3aeb18SJerin Jacob 				t->result = EVT_TEST_SUCCESS;
319d008f20bSPavan Nikhilesh 				if (opt->prod_type == EVT_PROD_TYPE_SYNT ||
320d008f20bSPavan Nikhilesh 					opt->prod_type ==
321d008f20bSPavan Nikhilesh 					EVT_PROD_TYPE_EVENT_TIMER_ADPTR) {
32259f697e3SPavan Nikhilesh 					t->done = true;
3239d3aeb18SJerin Jacob 					rte_smp_wmb();
3249d3aeb18SJerin Jacob 					break;
3259d3aeb18SJerin Jacob 				}
3269d3aeb18SJerin Jacob 			}
32759f697e3SPavan Nikhilesh 		}
3289d3aeb18SJerin Jacob 
32959f697e3SPavan Nikhilesh 		if (new_cycles - dead_lock_cycles > dead_lock_sample &&
33059f697e3SPavan Nikhilesh 				opt->prod_type == EVT_PROD_TYPE_SYNT) {
3319d3aeb18SJerin Jacob 			remaining = t->outstand_pkts - processed_pkts(t);
3329d3aeb18SJerin Jacob 			if (dead_lock_remaining == remaining) {
3339d3aeb18SJerin Jacob 				rte_event_dev_dump(opt->dev_id, stdout);
3349d3aeb18SJerin Jacob 				evt_err("No schedules for seconds, deadlock");
3359d3aeb18SJerin Jacob 				t->done = true;
3369d3aeb18SJerin Jacob 				rte_smp_wmb();
3379d3aeb18SJerin Jacob 				break;
3389d3aeb18SJerin Jacob 			}
3399d3aeb18SJerin Jacob 			dead_lock_remaining = remaining;
3409d3aeb18SJerin Jacob 			dead_lock_cycles = new_cycles;
3419d3aeb18SJerin Jacob 		}
3429d3aeb18SJerin Jacob 	}
3439d3aeb18SJerin Jacob 	printf("\n");
3449d3aeb18SJerin Jacob 	return 0;
3459d3aeb18SJerin Jacob }
3469d3aeb18SJerin Jacob 
3473617aae5SPavan Nikhilesh static int
3483617aae5SPavan Nikhilesh perf_event_rx_adapter_setup(struct evt_options *opt, uint8_t stride,
3493617aae5SPavan Nikhilesh 		struct rte_event_port_conf prod_conf)
3503617aae5SPavan Nikhilesh {
3513617aae5SPavan Nikhilesh 	int ret = 0;
3523617aae5SPavan Nikhilesh 	uint16_t prod;
3533617aae5SPavan Nikhilesh 	struct rte_event_eth_rx_adapter_queue_conf queue_conf;
3543617aae5SPavan Nikhilesh 
3553617aae5SPavan Nikhilesh 	memset(&queue_conf, 0,
3563617aae5SPavan Nikhilesh 			sizeof(struct rte_event_eth_rx_adapter_queue_conf));
3573617aae5SPavan Nikhilesh 	queue_conf.ev.sched_type = opt->sched_type_list[0];
3583617aae5SPavan Nikhilesh 	for (prod = 0; prod < rte_eth_dev_count(); prod++) {
3593617aae5SPavan Nikhilesh 		uint32_t cap;
3603617aae5SPavan Nikhilesh 
3613617aae5SPavan Nikhilesh 		ret = rte_event_eth_rx_adapter_caps_get(opt->dev_id,
3623617aae5SPavan Nikhilesh 				prod, &cap);
3633617aae5SPavan Nikhilesh 		if (ret) {
3643617aae5SPavan Nikhilesh 			evt_err("failed to get event rx adapter[%d]"
3653617aae5SPavan Nikhilesh 					" capabilities",
3663617aae5SPavan Nikhilesh 					opt->dev_id);
3673617aae5SPavan Nikhilesh 			return ret;
3683617aae5SPavan Nikhilesh 		}
3693617aae5SPavan Nikhilesh 		queue_conf.ev.queue_id = prod * stride;
3703617aae5SPavan Nikhilesh 		ret = rte_event_eth_rx_adapter_create(prod, opt->dev_id,
3713617aae5SPavan Nikhilesh 				&prod_conf);
3723617aae5SPavan Nikhilesh 		if (ret) {
3733617aae5SPavan Nikhilesh 			evt_err("failed to create rx adapter[%d]", prod);
3743617aae5SPavan Nikhilesh 			return ret;
3753617aae5SPavan Nikhilesh 		}
3763617aae5SPavan Nikhilesh 		ret = rte_event_eth_rx_adapter_queue_add(prod, prod, -1,
3773617aae5SPavan Nikhilesh 				&queue_conf);
3783617aae5SPavan Nikhilesh 		if (ret) {
3793617aae5SPavan Nikhilesh 			evt_err("failed to add rx queues to adapter[%d]", prod);
3803617aae5SPavan Nikhilesh 			return ret;
3813617aae5SPavan Nikhilesh 		}
3823617aae5SPavan Nikhilesh 
383b0333c55SPavan Nikhilesh 		if (!(cap & RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT)) {
384b0333c55SPavan Nikhilesh 			uint32_t service_id;
385b0333c55SPavan Nikhilesh 
386b0333c55SPavan Nikhilesh 			rte_event_eth_rx_adapter_service_id_get(prod,
387b0333c55SPavan Nikhilesh 					&service_id);
388b0333c55SPavan Nikhilesh 			ret = evt_service_setup(service_id);
389b0333c55SPavan Nikhilesh 			if (ret) {
390b0333c55SPavan Nikhilesh 				evt_err("Failed to setup service core"
391b0333c55SPavan Nikhilesh 						" for Rx adapter\n");
392b0333c55SPavan Nikhilesh 				return ret;
393b0333c55SPavan Nikhilesh 			}
394b0333c55SPavan Nikhilesh 		}
395b0333c55SPavan Nikhilesh 
3963617aae5SPavan Nikhilesh 		ret = rte_eth_dev_start(prod);
3973617aae5SPavan Nikhilesh 		if (ret) {
3983617aae5SPavan Nikhilesh 			evt_err("Ethernet dev [%d] failed to start."
3993617aae5SPavan Nikhilesh 					" Using synthetic producer", prod);
4003617aae5SPavan Nikhilesh 			return ret;
4013617aae5SPavan Nikhilesh 		}
4023617aae5SPavan Nikhilesh 
4033617aae5SPavan Nikhilesh 		ret = rte_event_eth_rx_adapter_start(prod);
4043617aae5SPavan Nikhilesh 		if (ret) {
4053617aae5SPavan Nikhilesh 			evt_err("Rx adapter[%d] start failed", prod);
4063617aae5SPavan Nikhilesh 			return ret;
4073617aae5SPavan Nikhilesh 		}
4083617aae5SPavan Nikhilesh 		printf("%s: Port[%d] using Rx adapter[%d] started\n", __func__,
4093617aae5SPavan Nikhilesh 				prod, prod);
4103617aae5SPavan Nikhilesh 	}
4113617aae5SPavan Nikhilesh 
4123617aae5SPavan Nikhilesh 	return ret;
4133617aae5SPavan Nikhilesh }
4143617aae5SPavan Nikhilesh 
415d008f20bSPavan Nikhilesh static int
416d008f20bSPavan Nikhilesh perf_event_timer_adapter_setup(struct test_perf *t)
417d008f20bSPavan Nikhilesh {
418d008f20bSPavan Nikhilesh 	int i;
419d008f20bSPavan Nikhilesh 	int ret;
420d008f20bSPavan Nikhilesh 	struct rte_event_timer_adapter_info adapter_info;
421d008f20bSPavan Nikhilesh 	struct rte_event_timer_adapter *wl;
422d008f20bSPavan Nikhilesh 	uint8_t nb_producers = evt_nr_active_lcores(t->opt->plcores);
423d008f20bSPavan Nikhilesh 	uint8_t flags = RTE_EVENT_TIMER_ADAPTER_F_ADJUST_RES;
424d008f20bSPavan Nikhilesh 
425d008f20bSPavan Nikhilesh 	if (nb_producers == 1)
426d008f20bSPavan Nikhilesh 		flags |= RTE_EVENT_TIMER_ADAPTER_F_SP_PUT;
427d008f20bSPavan Nikhilesh 
428d008f20bSPavan Nikhilesh 	for (i = 0; i < t->opt->nb_timer_adptrs; i++) {
429d008f20bSPavan Nikhilesh 		struct rte_event_timer_adapter_conf config = {
430d008f20bSPavan Nikhilesh 			.event_dev_id = t->opt->dev_id,
431d008f20bSPavan Nikhilesh 			.timer_adapter_id = i,
432d008f20bSPavan Nikhilesh 			.timer_tick_ns = t->opt->timer_tick_nsec,
433d008f20bSPavan Nikhilesh 			.max_tmo_ns = t->opt->max_tmo_nsec,
434d008f20bSPavan Nikhilesh 			.nb_timers = 2 * 1024 * 1024,
435d008f20bSPavan Nikhilesh 			.flags = flags,
436d008f20bSPavan Nikhilesh 		};
437d008f20bSPavan Nikhilesh 
438d008f20bSPavan Nikhilesh 		wl = rte_event_timer_adapter_create(&config);
439d008f20bSPavan Nikhilesh 		if (wl == NULL) {
440d008f20bSPavan Nikhilesh 			evt_err("failed to create event timer ring %d", i);
441d008f20bSPavan Nikhilesh 			return rte_errno;
442d008f20bSPavan Nikhilesh 		}
443d008f20bSPavan Nikhilesh 
444d008f20bSPavan Nikhilesh 		memset(&adapter_info, 0,
445d008f20bSPavan Nikhilesh 				sizeof(struct rte_event_timer_adapter_info));
446d008f20bSPavan Nikhilesh 		rte_event_timer_adapter_get_info(wl, &adapter_info);
447d008f20bSPavan Nikhilesh 		t->opt->optm_timer_tick_nsec = adapter_info.min_resolution_ns;
448d008f20bSPavan Nikhilesh 
449d008f20bSPavan Nikhilesh 		if (!(adapter_info.caps &
450d008f20bSPavan Nikhilesh 				RTE_EVENT_TIMER_ADAPTER_CAP_INTERNAL_PORT)) {
451d008f20bSPavan Nikhilesh 			uint32_t service_id;
452d008f20bSPavan Nikhilesh 
453d008f20bSPavan Nikhilesh 			rte_event_timer_adapter_service_id_get(wl,
454d008f20bSPavan Nikhilesh 					&service_id);
455d008f20bSPavan Nikhilesh 			ret = evt_service_setup(service_id);
456d008f20bSPavan Nikhilesh 			if (ret) {
457d008f20bSPavan Nikhilesh 				evt_err("Failed to setup service core"
458d008f20bSPavan Nikhilesh 						" for timer adapter\n");
459d008f20bSPavan Nikhilesh 				return ret;
460d008f20bSPavan Nikhilesh 			}
461d008f20bSPavan Nikhilesh 			rte_service_runstate_set(service_id, 1);
462d008f20bSPavan Nikhilesh 		}
463d008f20bSPavan Nikhilesh 
464d008f20bSPavan Nikhilesh 		ret = rte_event_timer_adapter_start(wl);
465d008f20bSPavan Nikhilesh 		if (ret) {
466d008f20bSPavan Nikhilesh 			evt_err("failed to Start event timer adapter %d", i);
467d008f20bSPavan Nikhilesh 			return ret;
468d008f20bSPavan Nikhilesh 		}
469d008f20bSPavan Nikhilesh 		t->timer_adptr[i] = wl;
470d008f20bSPavan Nikhilesh 	}
471d008f20bSPavan Nikhilesh 	return 0;
472d008f20bSPavan Nikhilesh }
473d008f20bSPavan Nikhilesh 
474272de067SJerin Jacob int
47584a7513dSJerin Jacob perf_event_dev_port_setup(struct evt_test *test, struct evt_options *opt,
476535c630cSPavan Nikhilesh 				uint8_t stride, uint8_t nb_queues,
477535c630cSPavan Nikhilesh 				const struct rte_event_port_conf *port_conf)
47884a7513dSJerin Jacob {
47984a7513dSJerin Jacob 	struct test_perf *t = evt_test_priv(test);
4803617aae5SPavan Nikhilesh 	uint16_t port, prod;
48184a7513dSJerin Jacob 	int ret = -1;
48284a7513dSJerin Jacob 
48384a7513dSJerin Jacob 	/* setup one port per worker, linking to all queues */
48484a7513dSJerin Jacob 	for (port = 0; port < evt_nr_active_lcores(opt->wlcores);
48584a7513dSJerin Jacob 				port++) {
48684a7513dSJerin Jacob 		struct worker_data *w = &t->worker[port];
48784a7513dSJerin Jacob 
48884a7513dSJerin Jacob 		w->dev_id = opt->dev_id;
48984a7513dSJerin Jacob 		w->port_id = port;
49084a7513dSJerin Jacob 		w->t = t;
49184a7513dSJerin Jacob 		w->processed_pkts = 0;
49284a7513dSJerin Jacob 		w->latency = 0;
49384a7513dSJerin Jacob 
494535c630cSPavan Nikhilesh 		ret = rte_event_port_setup(opt->dev_id, port, port_conf);
49584a7513dSJerin Jacob 		if (ret) {
49684a7513dSJerin Jacob 			evt_err("failed to setup port %d", port);
49784a7513dSJerin Jacob 			return ret;
49884a7513dSJerin Jacob 		}
49984a7513dSJerin Jacob 
50084a7513dSJerin Jacob 		ret = rte_event_port_link(opt->dev_id, port, NULL, NULL, 0);
50184a7513dSJerin Jacob 		if (ret != nb_queues) {
50284a7513dSJerin Jacob 			evt_err("failed to link all queues to port %d", port);
50384a7513dSJerin Jacob 			return -EINVAL;
50484a7513dSJerin Jacob 		}
50584a7513dSJerin Jacob 	}
50684a7513dSJerin Jacob 
50784a7513dSJerin Jacob 	/* port for producers, no links */
5083617aae5SPavan Nikhilesh 	if (opt->prod_type == EVT_PROD_TYPE_ETH_RX_ADPTR) {
5093617aae5SPavan Nikhilesh 		for ( ; port < perf_nb_event_ports(opt); port++) {
5103617aae5SPavan Nikhilesh 			struct prod_data *p = &t->prod[port];
5113617aae5SPavan Nikhilesh 			p->t = t;
5123617aae5SPavan Nikhilesh 		}
5133617aae5SPavan Nikhilesh 
514535c630cSPavan Nikhilesh 		ret = perf_event_rx_adapter_setup(opt, stride, *port_conf);
5153617aae5SPavan Nikhilesh 		if (ret)
5163617aae5SPavan Nikhilesh 			return ret;
517d008f20bSPavan Nikhilesh 	} else if (opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR) {
518d008f20bSPavan Nikhilesh 		prod = 0;
519d008f20bSPavan Nikhilesh 		for ( ; port < perf_nb_event_ports(opt); port++) {
520d008f20bSPavan Nikhilesh 			struct prod_data *p = &t->prod[port];
521d008f20bSPavan Nikhilesh 			p->queue_id = prod * stride;
522d008f20bSPavan Nikhilesh 			p->t = t;
523d008f20bSPavan Nikhilesh 			prod++;
524d008f20bSPavan Nikhilesh 		}
525d008f20bSPavan Nikhilesh 
526d008f20bSPavan Nikhilesh 		ret = perf_event_timer_adapter_setup(t);
527d008f20bSPavan Nikhilesh 		if (ret)
528d008f20bSPavan Nikhilesh 			return ret;
5293617aae5SPavan Nikhilesh 	} else {
53084a7513dSJerin Jacob 		prod = 0;
53184a7513dSJerin Jacob 		for ( ; port < perf_nb_event_ports(opt); port++) {
53284a7513dSJerin Jacob 			struct prod_data *p = &t->prod[port];
53384a7513dSJerin Jacob 
53484a7513dSJerin Jacob 			p->dev_id = opt->dev_id;
53584a7513dSJerin Jacob 			p->port_id = port;
53684a7513dSJerin Jacob 			p->queue_id = prod * stride;
53784a7513dSJerin Jacob 			p->t = t;
53884a7513dSJerin Jacob 
5393617aae5SPavan Nikhilesh 			ret = rte_event_port_setup(opt->dev_id, port,
540535c630cSPavan Nikhilesh 					port_conf);
54184a7513dSJerin Jacob 			if (ret) {
54284a7513dSJerin Jacob 				evt_err("failed to setup port %d", port);
54384a7513dSJerin Jacob 				return ret;
54484a7513dSJerin Jacob 			}
54584a7513dSJerin Jacob 			prod++;
54684a7513dSJerin Jacob 		}
5473617aae5SPavan Nikhilesh 	}
54884a7513dSJerin Jacob 
54984a7513dSJerin Jacob 	return ret;
55084a7513dSJerin Jacob }
55184a7513dSJerin Jacob 
55284a7513dSJerin Jacob int
553272de067SJerin Jacob perf_opt_check(struct evt_options *opt, uint64_t nb_queues)
554272de067SJerin Jacob {
555272de067SJerin Jacob 	unsigned int lcores;
556272de067SJerin Jacob 
557b01974daSPavan Nikhilesh 	/* N producer + N worker + 1 master when producer cores are used
558b01974daSPavan Nikhilesh 	 * Else N worker + 1 master when Rx adapter is used
559b01974daSPavan Nikhilesh 	 */
560b01974daSPavan Nikhilesh 	lcores = opt->prod_type == EVT_PROD_TYPE_SYNT ? 3 : 2;
561272de067SJerin Jacob 
562272de067SJerin Jacob 	if (rte_lcore_count() < lcores) {
563272de067SJerin Jacob 		evt_err("test need minimum %d lcores", lcores);
564272de067SJerin Jacob 		return -1;
565272de067SJerin Jacob 	}
566272de067SJerin Jacob 
567272de067SJerin Jacob 	/* Validate worker lcores */
568272de067SJerin Jacob 	if (evt_lcores_has_overlap(opt->wlcores, rte_get_master_lcore())) {
569272de067SJerin Jacob 		evt_err("worker lcores overlaps with master lcore");
570272de067SJerin Jacob 		return -1;
571272de067SJerin Jacob 	}
572272de067SJerin Jacob 	if (evt_lcores_has_overlap_multi(opt->wlcores, opt->plcores)) {
573272de067SJerin Jacob 		evt_err("worker lcores overlaps producer lcores");
574272de067SJerin Jacob 		return -1;
575272de067SJerin Jacob 	}
576272de067SJerin Jacob 	if (evt_has_disabled_lcore(opt->wlcores)) {
577272de067SJerin Jacob 		evt_err("one or more workers lcores are not enabled");
578272de067SJerin Jacob 		return -1;
579272de067SJerin Jacob 	}
580272de067SJerin Jacob 	if (!evt_has_active_lcore(opt->wlcores)) {
581272de067SJerin Jacob 		evt_err("minimum one worker is required");
582272de067SJerin Jacob 		return -1;
583272de067SJerin Jacob 	}
584272de067SJerin Jacob 
585b01974daSPavan Nikhilesh 	if (opt->prod_type == EVT_PROD_TYPE_SYNT) {
586272de067SJerin Jacob 		/* Validate producer lcores */
587b01974daSPavan Nikhilesh 		if (evt_lcores_has_overlap(opt->plcores,
588b01974daSPavan Nikhilesh 					rte_get_master_lcore())) {
589272de067SJerin Jacob 			evt_err("producer lcores overlaps with master lcore");
590272de067SJerin Jacob 			return -1;
591272de067SJerin Jacob 		}
592272de067SJerin Jacob 		if (evt_has_disabled_lcore(opt->plcores)) {
593272de067SJerin Jacob 			evt_err("one or more producer lcores are not enabled");
594272de067SJerin Jacob 			return -1;
595272de067SJerin Jacob 		}
596272de067SJerin Jacob 		if (!evt_has_active_lcore(opt->plcores)) {
597272de067SJerin Jacob 			evt_err("minimum one producer is required");
598272de067SJerin Jacob 			return -1;
599272de067SJerin Jacob 		}
600b01974daSPavan Nikhilesh 	}
601272de067SJerin Jacob 
602272de067SJerin Jacob 	if (evt_has_invalid_stage(opt))
603272de067SJerin Jacob 		return -1;
604272de067SJerin Jacob 
605272de067SJerin Jacob 	if (evt_has_invalid_sched_type(opt))
606272de067SJerin Jacob 		return -1;
607272de067SJerin Jacob 
608272de067SJerin Jacob 	if (nb_queues > EVT_MAX_QUEUES) {
609272de067SJerin Jacob 		evt_err("number of queues exceeds %d", EVT_MAX_QUEUES);
610272de067SJerin Jacob 		return -1;
611272de067SJerin Jacob 	}
612272de067SJerin Jacob 	if (perf_nb_event_ports(opt) > EVT_MAX_PORTS) {
613272de067SJerin Jacob 		evt_err("number of ports exceeds %d", EVT_MAX_PORTS);
614272de067SJerin Jacob 		return -1;
615272de067SJerin Jacob 	}
616272de067SJerin Jacob 
617272de067SJerin Jacob 	/* Fixups */
618d008f20bSPavan Nikhilesh 	if ((opt->nb_stages == 1 &&
619d008f20bSPavan Nikhilesh 			opt->prod_type != EVT_PROD_TYPE_EVENT_TIMER_ADPTR) &&
620d008f20bSPavan Nikhilesh 			opt->fwd_latency) {
621272de067SJerin Jacob 		evt_info("fwd_latency is valid when nb_stages > 1, disabling");
622272de067SJerin Jacob 		opt->fwd_latency = 0;
623272de067SJerin Jacob 	}
624d008f20bSPavan Nikhilesh 
625272de067SJerin Jacob 	if (opt->fwd_latency && !opt->q_priority) {
626272de067SJerin Jacob 		evt_info("enabled queue priority for latency measurement");
627272de067SJerin Jacob 		opt->q_priority = 1;
628272de067SJerin Jacob 	}
6299d3aeb18SJerin Jacob 	if (opt->nb_pkts == 0)
6309d3aeb18SJerin Jacob 		opt->nb_pkts = INT64_MAX/evt_nr_active_lcores(opt->plcores);
631272de067SJerin Jacob 
632272de067SJerin Jacob 	return 0;
633272de067SJerin Jacob }
634272de067SJerin Jacob 
635272de067SJerin Jacob void
636272de067SJerin Jacob perf_opt_dump(struct evt_options *opt, uint8_t nb_queues)
637272de067SJerin Jacob {
638272de067SJerin Jacob 	evt_dump("nb_prod_lcores", "%d", evt_nr_active_lcores(opt->plcores));
639272de067SJerin Jacob 	evt_dump_producer_lcores(opt);
640272de067SJerin Jacob 	evt_dump("nb_worker_lcores", "%d", evt_nr_active_lcores(opt->wlcores));
641272de067SJerin Jacob 	evt_dump_worker_lcores(opt);
642272de067SJerin Jacob 	evt_dump_nb_stages(opt);
643272de067SJerin Jacob 	evt_dump("nb_evdev_ports", "%d", perf_nb_event_ports(opt));
644272de067SJerin Jacob 	evt_dump("nb_evdev_queues", "%d", nb_queues);
645272de067SJerin Jacob 	evt_dump_queue_priority(opt);
646272de067SJerin Jacob 	evt_dump_sched_type_list(opt);
647b01974daSPavan Nikhilesh 	evt_dump_producer_type(opt);
648272de067SJerin Jacob }
649272de067SJerin Jacob 
65041c219e6SJerin Jacob void
65141c219e6SJerin Jacob perf_eventdev_destroy(struct evt_test *test, struct evt_options *opt)
65241c219e6SJerin Jacob {
653d008f20bSPavan Nikhilesh 	int i;
654d008f20bSPavan Nikhilesh 	struct test_perf *t = evt_test_priv(test);
65541c219e6SJerin Jacob 
656d008f20bSPavan Nikhilesh 	if (opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR) {
657d008f20bSPavan Nikhilesh 		for (i = 0; i < opt->nb_timer_adptrs; i++)
658d008f20bSPavan Nikhilesh 			rte_event_timer_adapter_stop(t->timer_adptr[i]);
659d008f20bSPavan Nikhilesh 	}
66041c219e6SJerin Jacob 	rte_event_dev_stop(opt->dev_id);
66141c219e6SJerin Jacob 	rte_event_dev_close(opt->dev_id);
66241c219e6SJerin Jacob }
66341c219e6SJerin Jacob 
66441c219e6SJerin Jacob static inline void
66541c219e6SJerin Jacob perf_elt_init(struct rte_mempool *mp, void *arg __rte_unused,
66641c219e6SJerin Jacob 	    void *obj, unsigned i __rte_unused)
66741c219e6SJerin Jacob {
66841c219e6SJerin Jacob 	memset(obj, 0, mp->elt_size);
66941c219e6SJerin Jacob }
67041c219e6SJerin Jacob 
6713fc8de4fSPavan Nikhilesh #define NB_RX_DESC			128
6723fc8de4fSPavan Nikhilesh #define NB_TX_DESC			512
6733fc8de4fSPavan Nikhilesh int
6743fc8de4fSPavan Nikhilesh perf_ethdev_setup(struct evt_test *test, struct evt_options *opt)
6753fc8de4fSPavan Nikhilesh {
6763fc8de4fSPavan Nikhilesh 	int i;
6773fc8de4fSPavan Nikhilesh 	struct test_perf *t = evt_test_priv(test);
6783fc8de4fSPavan Nikhilesh 	struct rte_eth_conf port_conf = {
6793fc8de4fSPavan Nikhilesh 		.rxmode = {
6803fc8de4fSPavan Nikhilesh 			.mq_mode = ETH_MQ_RX_RSS,
6813fc8de4fSPavan Nikhilesh 			.max_rx_pkt_len = ETHER_MAX_LEN,
6823fc8de4fSPavan Nikhilesh 			.split_hdr_size = 0,
6833fc8de4fSPavan Nikhilesh 			.header_split   = 0,
6843fc8de4fSPavan Nikhilesh 			.hw_ip_checksum = 0,
6853fc8de4fSPavan Nikhilesh 			.hw_vlan_filter = 0,
6863fc8de4fSPavan Nikhilesh 			.hw_vlan_strip  = 0,
6873fc8de4fSPavan Nikhilesh 			.hw_vlan_extend = 0,
6883fc8de4fSPavan Nikhilesh 			.jumbo_frame    = 0,
6893fc8de4fSPavan Nikhilesh 			.hw_strip_crc   = 1,
6903fc8de4fSPavan Nikhilesh 		},
6913fc8de4fSPavan Nikhilesh 		.rx_adv_conf = {
6923fc8de4fSPavan Nikhilesh 			.rss_conf = {
6933fc8de4fSPavan Nikhilesh 				.rss_key = NULL,
6943fc8de4fSPavan Nikhilesh 				.rss_hf = ETH_RSS_IP,
6953fc8de4fSPavan Nikhilesh 			},
6963fc8de4fSPavan Nikhilesh 		},
6973fc8de4fSPavan Nikhilesh 	};
6983fc8de4fSPavan Nikhilesh 
699d008f20bSPavan Nikhilesh 	if (opt->prod_type == EVT_PROD_TYPE_SYNT ||
700d008f20bSPavan Nikhilesh 			opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR)
7013fc8de4fSPavan Nikhilesh 		return 0;
7023fc8de4fSPavan Nikhilesh 
7033fc8de4fSPavan Nikhilesh 	if (!rte_eth_dev_count()) {
7043fc8de4fSPavan Nikhilesh 		evt_err("No ethernet ports found.");
7053fc8de4fSPavan Nikhilesh 		return -ENODEV;
7063fc8de4fSPavan Nikhilesh 	}
7073fc8de4fSPavan Nikhilesh 
7083fc8de4fSPavan Nikhilesh 	for (i = 0; i < rte_eth_dev_count(); i++) {
7093fc8de4fSPavan Nikhilesh 
7103fc8de4fSPavan Nikhilesh 		if (rte_eth_dev_configure(i, 1, 1,
7113fc8de4fSPavan Nikhilesh 					&port_conf)
7123fc8de4fSPavan Nikhilesh 				< 0) {
7133fc8de4fSPavan Nikhilesh 			evt_err("Failed to configure eth port [%d]", i);
7143fc8de4fSPavan Nikhilesh 			return -EINVAL;
7153fc8de4fSPavan Nikhilesh 		}
7163fc8de4fSPavan Nikhilesh 
7173fc8de4fSPavan Nikhilesh 		if (rte_eth_rx_queue_setup(i, 0, NB_RX_DESC,
7183fc8de4fSPavan Nikhilesh 				rte_socket_id(), NULL, t->pool) < 0) {
7193fc8de4fSPavan Nikhilesh 			evt_err("Failed to setup eth port [%d] rx_queue: %d.",
7203fc8de4fSPavan Nikhilesh 					i, 0);
7213fc8de4fSPavan Nikhilesh 			return -EINVAL;
7223fc8de4fSPavan Nikhilesh 		}
7233fc8de4fSPavan Nikhilesh 
7243fc8de4fSPavan Nikhilesh 		if (rte_eth_tx_queue_setup(i, 0, NB_TX_DESC,
7253fc8de4fSPavan Nikhilesh 					rte_socket_id(), NULL) < 0) {
7263fc8de4fSPavan Nikhilesh 			evt_err("Failed to setup eth port [%d] tx_queue: %d.",
7273fc8de4fSPavan Nikhilesh 					i, 0);
7283fc8de4fSPavan Nikhilesh 			return -EINVAL;
7293fc8de4fSPavan Nikhilesh 		}
7303fc8de4fSPavan Nikhilesh 
7313fc8de4fSPavan Nikhilesh 		rte_eth_promiscuous_enable(i);
7323fc8de4fSPavan Nikhilesh 	}
7333fc8de4fSPavan Nikhilesh 
7343fc8de4fSPavan Nikhilesh 	return 0;
7353fc8de4fSPavan Nikhilesh }
7363fc8de4fSPavan Nikhilesh 
7377f3daf34SPavan Nikhilesh void perf_ethdev_destroy(struct evt_test *test, struct evt_options *opt)
7387f3daf34SPavan Nikhilesh {
7397f3daf34SPavan Nikhilesh 	int i;
7407f3daf34SPavan Nikhilesh 	RTE_SET_USED(test);
7417f3daf34SPavan Nikhilesh 
7427f3daf34SPavan Nikhilesh 	if (opt->prod_type == EVT_PROD_TYPE_ETH_RX_ADPTR) {
7437f3daf34SPavan Nikhilesh 		for (i = 0; i < rte_eth_dev_count(); i++) {
7443617aae5SPavan Nikhilesh 			rte_event_eth_rx_adapter_stop(i);
7457f3daf34SPavan Nikhilesh 			rte_eth_dev_stop(i);
7467f3daf34SPavan Nikhilesh 			rte_eth_dev_close(i);
7477f3daf34SPavan Nikhilesh 		}
7487f3daf34SPavan Nikhilesh 	}
7497f3daf34SPavan Nikhilesh }
7507f3daf34SPavan Nikhilesh 
75141c219e6SJerin Jacob int
75241c219e6SJerin Jacob perf_mempool_setup(struct evt_test *test, struct evt_options *opt)
75341c219e6SJerin Jacob {
75441c219e6SJerin Jacob 	struct test_perf *t = evt_test_priv(test);
75541c219e6SJerin Jacob 
756d008f20bSPavan Nikhilesh 	if (opt->prod_type == EVT_PROD_TYPE_SYNT ||
757d008f20bSPavan Nikhilesh 			opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR) {
75841c219e6SJerin Jacob 		t->pool = rte_mempool_create(test->name, /* mempool name */
75941c219e6SJerin Jacob 				opt->pool_sz, /* number of elements*/
76041c219e6SJerin Jacob 				sizeof(struct perf_elt), /* element size*/
76141c219e6SJerin Jacob 				512, /* cache size*/
76241c219e6SJerin Jacob 				0, NULL, NULL,
76341c219e6SJerin Jacob 				perf_elt_init, /* obj constructor */
76441c219e6SJerin Jacob 				NULL, opt->socket_id, 0); /* flags */
7658577cc1aSPavan Nikhilesh 	} else {
7668577cc1aSPavan Nikhilesh 		t->pool = rte_pktmbuf_pool_create(test->name, /* mempool name */
7678577cc1aSPavan Nikhilesh 				opt->pool_sz, /* number of elements*/
7688577cc1aSPavan Nikhilesh 				512, /* cache size*/
7698577cc1aSPavan Nikhilesh 				0,
7708577cc1aSPavan Nikhilesh 				RTE_MBUF_DEFAULT_BUF_SIZE,
7718577cc1aSPavan Nikhilesh 				opt->socket_id); /* flags */
7728577cc1aSPavan Nikhilesh 
7738577cc1aSPavan Nikhilesh 	}
7748577cc1aSPavan Nikhilesh 
77541c219e6SJerin Jacob 	if (t->pool == NULL) {
77641c219e6SJerin Jacob 		evt_err("failed to create mempool");
77741c219e6SJerin Jacob 		return -ENOMEM;
77841c219e6SJerin Jacob 	}
77941c219e6SJerin Jacob 
78041c219e6SJerin Jacob 	return 0;
78141c219e6SJerin Jacob }
78241c219e6SJerin Jacob 
78341c219e6SJerin Jacob void
78441c219e6SJerin Jacob perf_mempool_destroy(struct evt_test *test, struct evt_options *opt)
78541c219e6SJerin Jacob {
78641c219e6SJerin Jacob 	RTE_SET_USED(opt);
78741c219e6SJerin Jacob 	struct test_perf *t = evt_test_priv(test);
78841c219e6SJerin Jacob 
78941c219e6SJerin Jacob 	rte_mempool_free(t->pool);
79041c219e6SJerin Jacob }
791ffbae86fSJerin Jacob 
792ffbae86fSJerin Jacob int
793ffbae86fSJerin Jacob perf_test_setup(struct evt_test *test, struct evt_options *opt)
794ffbae86fSJerin Jacob {
795ffbae86fSJerin Jacob 	void *test_perf;
796ffbae86fSJerin Jacob 
797ffbae86fSJerin Jacob 	test_perf = rte_zmalloc_socket(test->name, sizeof(struct test_perf),
798ffbae86fSJerin Jacob 				RTE_CACHE_LINE_SIZE, opt->socket_id);
799ffbae86fSJerin Jacob 	if (test_perf  == NULL) {
800ffbae86fSJerin Jacob 		evt_err("failed to allocate test_perf memory");
801ffbae86fSJerin Jacob 		goto nomem;
802ffbae86fSJerin Jacob 	}
803ffbae86fSJerin Jacob 	test->test_priv = test_perf;
804ffbae86fSJerin Jacob 
805ffbae86fSJerin Jacob 	struct test_perf *t = evt_test_priv(test);
806ffbae86fSJerin Jacob 
807d008f20bSPavan Nikhilesh 	if (opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR) {
808d008f20bSPavan Nikhilesh 		t->outstand_pkts = opt->nb_timers *
809d008f20bSPavan Nikhilesh 			evt_nr_active_lcores(opt->plcores);
810d008f20bSPavan Nikhilesh 		t->nb_pkts = opt->nb_timers;
811d008f20bSPavan Nikhilesh 	} else {
812d008f20bSPavan Nikhilesh 		t->outstand_pkts = opt->nb_pkts *
813d008f20bSPavan Nikhilesh 			evt_nr_active_lcores(opt->plcores);
814d008f20bSPavan Nikhilesh 		t->nb_pkts = opt->nb_pkts;
815d008f20bSPavan Nikhilesh 	}
816d008f20bSPavan Nikhilesh 
817ffbae86fSJerin Jacob 	t->nb_workers = evt_nr_active_lcores(opt->wlcores);
818ffbae86fSJerin Jacob 	t->done = false;
819ffbae86fSJerin Jacob 	t->nb_flows = opt->nb_flows;
820ffbae86fSJerin Jacob 	t->result = EVT_TEST_FAILED;
821ffbae86fSJerin Jacob 	t->opt = opt;
822ffbae86fSJerin Jacob 	memcpy(t->sched_type_list, opt->sched_type_list,
823ffbae86fSJerin Jacob 			sizeof(opt->sched_type_list));
824ffbae86fSJerin Jacob 	return 0;
825ffbae86fSJerin Jacob nomem:
826ffbae86fSJerin Jacob 	return -ENOMEM;
827ffbae86fSJerin Jacob }
828ffbae86fSJerin Jacob 
829ffbae86fSJerin Jacob void
830ffbae86fSJerin Jacob perf_test_destroy(struct evt_test *test, struct evt_options *opt)
831ffbae86fSJerin Jacob {
832ffbae86fSJerin Jacob 	RTE_SET_USED(opt);
833ffbae86fSJerin Jacob 
834ffbae86fSJerin Jacob 	rte_free(test->test_priv);
835ffbae86fSJerin Jacob }
836