xref: /dpdk/app/test-eventdev/test_perf_common.h (revision 7f3daf34269e42ec31bf330fa6f869b05a9fec2f)
153a3b7e8SJerin Jacob /* SPDX-License-Identifier: BSD-3-Clause
253a3b7e8SJerin Jacob  * Copyright(c) 2017 Cavium, Inc
3ffbae86fSJerin Jacob  */
4ffbae86fSJerin Jacob 
5ffbae86fSJerin Jacob #ifndef _TEST_PERF_COMMON_
6ffbae86fSJerin Jacob #define _TEST_PERF_COMMON_
7ffbae86fSJerin Jacob 
8ffbae86fSJerin Jacob #include <stdio.h>
9ffbae86fSJerin Jacob #include <stdbool.h>
10ffbae86fSJerin Jacob #include <unistd.h>
11ffbae86fSJerin Jacob 
12ffbae86fSJerin Jacob #include <rte_cycles.h>
1359f697e3SPavan Nikhilesh #include <rte_ethdev.h>
14ffbae86fSJerin Jacob #include <rte_eventdev.h>
15ffbae86fSJerin Jacob #include <rte_lcore.h>
16ffbae86fSJerin Jacob #include <rte_malloc.h>
17ffbae86fSJerin Jacob #include <rte_mempool.h>
18ffbae86fSJerin Jacob #include <rte_prefetch.h>
19ffbae86fSJerin Jacob 
20ffbae86fSJerin Jacob #include "evt_common.h"
21ffbae86fSJerin Jacob #include "evt_options.h"
22ffbae86fSJerin Jacob #include "evt_test.h"
23ffbae86fSJerin Jacob 
24ffbae86fSJerin Jacob struct test_perf;
25ffbae86fSJerin Jacob 
26ffbae86fSJerin Jacob struct worker_data {
27ffbae86fSJerin Jacob 	uint64_t processed_pkts;
28ffbae86fSJerin Jacob 	uint64_t latency;
29ffbae86fSJerin Jacob 	uint8_t dev_id;
30ffbae86fSJerin Jacob 	uint8_t port_id;
31ffbae86fSJerin Jacob 	struct test_perf *t;
32ffbae86fSJerin Jacob } __rte_cache_aligned;
33ffbae86fSJerin Jacob 
34ffbae86fSJerin Jacob struct prod_data {
35ffbae86fSJerin Jacob 	uint8_t dev_id;
36ffbae86fSJerin Jacob 	uint8_t port_id;
37ffbae86fSJerin Jacob 	uint8_t queue_id;
38ffbae86fSJerin Jacob 	struct test_perf *t;
39ffbae86fSJerin Jacob } __rte_cache_aligned;
40ffbae86fSJerin Jacob 
41ffbae86fSJerin Jacob struct test_perf {
42ffbae86fSJerin Jacob 	/* Don't change the offset of "done". Signal handler use this memory
43ffbae86fSJerin Jacob 	 * to terminate all lcores work.
44ffbae86fSJerin Jacob 	 */
45ffbae86fSJerin Jacob 	int done;
46ffbae86fSJerin Jacob 	uint64_t outstand_pkts;
47ffbae86fSJerin Jacob 	uint8_t nb_workers;
48ffbae86fSJerin Jacob 	enum evt_test_result result;
49ffbae86fSJerin Jacob 	uint32_t nb_flows;
50ffbae86fSJerin Jacob 	uint64_t nb_pkts;
51ffbae86fSJerin Jacob 	struct rte_mempool *pool;
52ffbae86fSJerin Jacob 	struct prod_data prod[EVT_MAX_PORTS];
53ffbae86fSJerin Jacob 	struct worker_data worker[EVT_MAX_PORTS];
54ffbae86fSJerin Jacob 	struct evt_options *opt;
55ffbae86fSJerin Jacob 	uint8_t sched_type_list[EVT_MAX_STAGES] __rte_cache_aligned;
56ffbae86fSJerin Jacob } __rte_cache_aligned;
57ffbae86fSJerin Jacob 
5841c219e6SJerin Jacob struct perf_elt {
5941c219e6SJerin Jacob 	uint64_t timestamp;
6041c219e6SJerin Jacob } __rte_cache_aligned;
6141c219e6SJerin Jacob 
622369f733SJerin Jacob #define BURST_SIZE 16
632369f733SJerin Jacob 
642369f733SJerin Jacob #define PERF_WORKER_INIT\
652369f733SJerin Jacob 	struct worker_data *w  = arg;\
662369f733SJerin Jacob 	struct test_perf *t = w->t;\
672369f733SJerin Jacob 	struct evt_options *opt = t->opt;\
682369f733SJerin Jacob 	const uint8_t dev = w->dev_id;\
692369f733SJerin Jacob 	const uint8_t port = w->port_id;\
702369f733SJerin Jacob 	uint8_t *const sched_type_list = &t->sched_type_list[0];\
712369f733SJerin Jacob 	struct rte_mempool *const pool = t->pool;\
722369f733SJerin Jacob 	const uint8_t nb_stages = t->opt->nb_stages;\
732369f733SJerin Jacob 	const uint8_t laststage = nb_stages - 1;\
742369f733SJerin Jacob 	uint8_t cnt = 0;\
752369f733SJerin Jacob 	void *bufs[16] __rte_cache_aligned;\
762369f733SJerin Jacob 	int const sz = RTE_DIM(bufs);\
772369f733SJerin Jacob 	if (opt->verbose_level > 1)\
782369f733SJerin Jacob 		printf("%s(): lcore %d dev_id %d port=%d\n", __func__,\
792369f733SJerin Jacob 				rte_lcore_id(), dev, port)
802369f733SJerin Jacob 
812369f733SJerin Jacob static inline __attribute__((always_inline)) int
822369f733SJerin Jacob perf_process_last_stage(struct rte_mempool *const pool,
832369f733SJerin Jacob 		struct rte_event *const ev, struct worker_data *const w,
842369f733SJerin Jacob 		void *bufs[], int const buf_sz, uint8_t count)
852369f733SJerin Jacob {
862369f733SJerin Jacob 	bufs[count++] = ev->event_ptr;
872369f733SJerin Jacob 	w->processed_pkts++;
882369f733SJerin Jacob 	rte_smp_wmb();
892369f733SJerin Jacob 
902369f733SJerin Jacob 	if (unlikely(count == buf_sz)) {
912369f733SJerin Jacob 		count = 0;
922369f733SJerin Jacob 		rte_mempool_put_bulk(pool, bufs, buf_sz);
932369f733SJerin Jacob 	}
942369f733SJerin Jacob 	return count;
952369f733SJerin Jacob }
962369f733SJerin Jacob 
972369f733SJerin Jacob static inline __attribute__((always_inline)) uint8_t
982369f733SJerin Jacob perf_process_last_stage_latency(struct rte_mempool *const pool,
992369f733SJerin Jacob 		struct rte_event *const ev, struct worker_data *const w,
1002369f733SJerin Jacob 		void *bufs[], int const buf_sz, uint8_t count)
1012369f733SJerin Jacob {
1022369f733SJerin Jacob 	uint64_t latency;
1032369f733SJerin Jacob 	struct perf_elt *const m = ev->event_ptr;
1042369f733SJerin Jacob 
1052369f733SJerin Jacob 	bufs[count++] = ev->event_ptr;
1062369f733SJerin Jacob 	w->processed_pkts++;
1072369f733SJerin Jacob 
1082369f733SJerin Jacob 	if (unlikely(count == buf_sz)) {
1092369f733SJerin Jacob 		count = 0;
1102369f733SJerin Jacob 		latency = rte_get_timer_cycles() - m->timestamp;
1112369f733SJerin Jacob 		rte_mempool_put_bulk(pool, bufs, buf_sz);
1122369f733SJerin Jacob 	} else {
1132369f733SJerin Jacob 		latency = rte_get_timer_cycles() - m->timestamp;
1142369f733SJerin Jacob 	}
1152369f733SJerin Jacob 
1162369f733SJerin Jacob 	w->latency += latency;
1172369f733SJerin Jacob 	rte_smp_wmb();
1182369f733SJerin Jacob 	return count;
1192369f733SJerin Jacob }
1202369f733SJerin Jacob 
1212369f733SJerin Jacob 
122272de067SJerin Jacob static inline int
123272de067SJerin Jacob perf_nb_event_ports(struct evt_options *opt)
124272de067SJerin Jacob {
125272de067SJerin Jacob 	return evt_nr_active_lcores(opt->wlcores) +
126272de067SJerin Jacob 			evt_nr_active_lcores(opt->plcores);
127272de067SJerin Jacob }
128272de067SJerin Jacob 
12941c219e6SJerin Jacob int perf_test_result(struct evt_test *test, struct evt_options *opt);
130272de067SJerin Jacob int perf_opt_check(struct evt_options *opt, uint64_t nb_queues);
131ffbae86fSJerin Jacob int perf_test_setup(struct evt_test *test, struct evt_options *opt);
1323fc8de4fSPavan Nikhilesh int perf_ethdev_setup(struct evt_test *test, struct evt_options *opt);
13341c219e6SJerin Jacob int perf_mempool_setup(struct evt_test *test, struct evt_options *opt);
13484a7513dSJerin Jacob int perf_event_dev_port_setup(struct evt_test *test, struct evt_options *opt,
13584a7513dSJerin Jacob 				uint8_t stride, uint8_t nb_queues);
13657305d79SPavan Nikhilesh int perf_event_dev_service_setup(uint8_t dev_id);
1379d3aeb18SJerin Jacob int perf_launch_lcores(struct evt_test *test, struct evt_options *opt,
1389d3aeb18SJerin Jacob 		int (*worker)(void *));
139272de067SJerin Jacob void perf_opt_dump(struct evt_options *opt, uint8_t nb_queues);
140ffbae86fSJerin Jacob void perf_test_destroy(struct evt_test *test, struct evt_options *opt);
14141c219e6SJerin Jacob void perf_eventdev_destroy(struct evt_test *test, struct evt_options *opt);
142*7f3daf34SPavan Nikhilesh void perf_ethdev_destroy(struct evt_test *test, struct evt_options *opt);
14341c219e6SJerin Jacob void perf_mempool_destroy(struct evt_test *test, struct evt_options *opt);
144ffbae86fSJerin Jacob 
145ffbae86fSJerin Jacob #endif /* _TEST_PERF_COMMON_ */
146