xref: /dpdk/app/test-eventdev/evt_common.h (revision f7c9651c830e4a54c81b0357fca768787d3d6402)
153a3b7e8SJerin Jacob /* SPDX-License-Identifier: BSD-3-Clause
253a3b7e8SJerin Jacob  * Copyright(c) 2017 Cavium, Inc
368cdc3dfSJerin Jacob  */
468cdc3dfSJerin Jacob 
568cdc3dfSJerin Jacob #ifndef _EVT_COMMON_
668cdc3dfSJerin Jacob #define _EVT_COMMON_
768cdc3dfSJerin Jacob 
868cdc3dfSJerin Jacob #include <rte_common.h>
98f5b5495SAkhil Goyal #include <rte_crypto.h>
1068cdc3dfSJerin Jacob #include <rte_debug.h>
11de2bc16eSShijith Thotton #include <rte_event_crypto_adapter.h>
12b25a66c4SAmit Prakash Shukla #include <rte_event_dma_adapter.h>
1368cdc3dfSJerin Jacob #include <rte_eventdev.h>
1457305d79SPavan Nikhilesh #include <rte_service.h>
1568cdc3dfSJerin Jacob 
1668cdc3dfSJerin Jacob #define CLNRM  "\x1b[0m"
1768cdc3dfSJerin Jacob #define CLRED  "\x1b[31m"
1868cdc3dfSJerin Jacob #define CLGRN  "\x1b[32m"
1968cdc3dfSJerin Jacob #define CLYEL  "\x1b[33m"
2068cdc3dfSJerin Jacob 
21*f7c9651cSAndre Muezerie #define evt_err(fmt, ...) \
22*f7c9651cSAndre Muezerie 	fprintf(stderr, CLRED"error: %s() "fmt CLNRM "\n", __func__, ## __VA_ARGS__)
2368cdc3dfSJerin Jacob 
24*f7c9651cSAndre Muezerie #define evt_info(fmt, ...) \
25*f7c9651cSAndre Muezerie 	fprintf(stdout, CLYEL""fmt CLNRM "\n", ## __VA_ARGS__)
2668cdc3dfSJerin Jacob 
2768cdc3dfSJerin Jacob #define EVT_STR_FMT 20
2868cdc3dfSJerin Jacob 
29*f7c9651cSAndre Muezerie #define evt_dump(str, fmt, ...) \
30*f7c9651cSAndre Muezerie 	printf("\t%-*s : "fmt"\n", EVT_STR_FMT, str, ## __VA_ARGS__)
3168cdc3dfSJerin Jacob 
3268cdc3dfSJerin Jacob #define evt_dump_begin(str) printf("\t%-*s : {", EVT_STR_FMT, str)
3368cdc3dfSJerin Jacob 
3468cdc3dfSJerin Jacob #define evt_dump_end printf("\b}\n")
3568cdc3dfSJerin Jacob 
3668cdc3dfSJerin Jacob #define EVT_MAX_STAGES           64
3768cdc3dfSJerin Jacob #define EVT_MAX_PORTS            256
3868cdc3dfSJerin Jacob #define EVT_MAX_QUEUES           256
3968cdc3dfSJerin Jacob 
40f0959283SPavan Nikhilesh enum evt_prod_type {
41f0959283SPavan Nikhilesh 	EVT_PROD_TYPE_NONE,
42f0959283SPavan Nikhilesh 	EVT_PROD_TYPE_SYNT,          /* Producer type Synthetic i.e. CPU. */
43f0959283SPavan Nikhilesh 	EVT_PROD_TYPE_ETH_RX_ADPTR,  /* Producer type Eth Rx Adapter. */
44f0959283SPavan Nikhilesh 	EVT_PROD_TYPE_EVENT_TIMER_ADPTR,  /* Producer type Timer Adapter. */
45de2bc16eSShijith Thotton 	EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR,  /* Producer type Crypto Adapter. */
46b25a66c4SAmit Prakash Shukla 	EVT_PROD_TYPE_EVENT_DMA_ADPTR,  /* Producer type DMA Adapter. */
47f0959283SPavan Nikhilesh 	EVT_PROD_TYPE_MAX,
48f0959283SPavan Nikhilesh };
49f0959283SPavan Nikhilesh 
50f0959283SPavan Nikhilesh struct evt_options {
51f0959283SPavan Nikhilesh #define EVT_TEST_NAME_MAX_LEN     32
52750ab9d5SAakash Sasidharan #define EVT_CRYPTO_MAX_KEY_SIZE   256
53750ab9d5SAakash Sasidharan #define EVT_CRYPTO_MAX_IV_SIZE    16
54f0959283SPavan Nikhilesh 	char test_name[EVT_TEST_NAME_MAX_LEN];
55f0959283SPavan Nikhilesh 	bool plcores[RTE_MAX_LCORE];
56f0959283SPavan Nikhilesh 	bool wlcores[RTE_MAX_LCORE];
57750ab9d5SAakash Sasidharan 	bool crypto_cipher_bit_mode;
58f0959283SPavan Nikhilesh 	int pool_sz;
59fc8b96fbSPavan Nikhilesh 	int socket_id;
60f0959283SPavan Nikhilesh 	int nb_stages;
61f0959283SPavan Nikhilesh 	int verbose_level;
62fc8b96fbSPavan Nikhilesh 	uint8_t dev_id;
63fc8b96fbSPavan Nikhilesh 	uint8_t timdev_cnt;
64f0959283SPavan Nikhilesh 	uint8_t nb_timer_adptrs;
65fc8b96fbSPavan Nikhilesh 	uint8_t timdev_use_burst;
66dbd4defeSPavan Nikhilesh 	uint8_t per_port_pool;
677a7a04d3SPavan Nikhilesh 	uint8_t preschedule;
687a7a04d3SPavan Nikhilesh 	uint8_t preschedule_opted;
69fc8b96fbSPavan Nikhilesh 	uint8_t sched_type_list[EVT_MAX_STAGES];
70fc8b96fbSPavan Nikhilesh 	uint16_t mbuf_sz;
71fc8b96fbSPavan Nikhilesh 	uint16_t wkr_deq_dep;
722eaa37b8SPavan Nikhilesh 	uint16_t vector_size;
732eaa37b8SPavan Nikhilesh 	uint16_t eth_queues;
74750ab9d5SAakash Sasidharan 	uint16_t crypto_cipher_iv_sz;
75fc8b96fbSPavan Nikhilesh 	uint32_t nb_flows;
76fc8b96fbSPavan Nikhilesh 	uint32_t tx_first;
77c9043624SPavan Nikhilesh 	uint16_t tx_pkt_sz;
78fc8b96fbSPavan Nikhilesh 	uint32_t max_pkt_sz;
7920841a25SRashmi Shetty 	uint32_t prod_enq_burst_sz;
80fc8b96fbSPavan Nikhilesh 	uint32_t deq_tmo_nsec;
81750ab9d5SAakash Sasidharan 	uint32_t crypto_cipher_key_sz;
82fc8b96fbSPavan Nikhilesh 	uint32_t q_priority:1;
83fc8b96fbSPavan Nikhilesh 	uint32_t fwd_latency:1;
842eaa37b8SPavan Nikhilesh 	uint32_t ena_vector : 1;
85fc8b96fbSPavan Nikhilesh 	uint64_t nb_pkts;
86f0959283SPavan Nikhilesh 	uint64_t nb_timers;
87fc8b96fbSPavan Nikhilesh 	uint64_t expiry_nsec;
88fc8b96fbSPavan Nikhilesh 	uint64_t max_tmo_nsec;
892eaa37b8SPavan Nikhilesh 	uint64_t vector_tmo_nsec;
90f0959283SPavan Nikhilesh 	uint64_t timer_tick_nsec;
91f0959283SPavan Nikhilesh 	uint64_t optm_timer_tick_nsec;
92f0959283SPavan Nikhilesh 	enum evt_prod_type prod_type;
93b25a66c4SAmit Prakash Shukla 	enum rte_event_dma_adapter_mode dma_adptr_mode;
94de2bc16eSShijith Thotton 	enum rte_event_crypto_adapter_mode crypto_adptr_mode;
958f5b5495SAkhil Goyal 	enum rte_crypto_op_type crypto_op_type;
96750ab9d5SAakash Sasidharan 	enum rte_crypto_cipher_algorithm crypto_cipher_alg;
97750ab9d5SAakash Sasidharan 	uint8_t crypto_cipher_key[EVT_CRYPTO_MAX_KEY_SIZE];
98f0959283SPavan Nikhilesh };
99f0959283SPavan Nikhilesh 
10068cdc3dfSJerin Jacob static inline bool
10168cdc3dfSJerin Jacob evt_has_distributed_sched(uint8_t dev_id)
10268cdc3dfSJerin Jacob {
10368cdc3dfSJerin Jacob 	struct rte_event_dev_info dev_info;
10468cdc3dfSJerin Jacob 
10568cdc3dfSJerin Jacob 	rte_event_dev_info_get(dev_id, &dev_info);
10668cdc3dfSJerin Jacob 	return (dev_info.event_dev_cap & RTE_EVENT_DEV_CAP_DISTRIBUTED_SCHED) ?
10768cdc3dfSJerin Jacob 			true : false;
10868cdc3dfSJerin Jacob }
10968cdc3dfSJerin Jacob 
11068cdc3dfSJerin Jacob static inline bool
11168cdc3dfSJerin Jacob evt_has_burst_mode(uint8_t dev_id)
11268cdc3dfSJerin Jacob {
11368cdc3dfSJerin Jacob 	struct rte_event_dev_info dev_info;
11468cdc3dfSJerin Jacob 
11568cdc3dfSJerin Jacob 	rte_event_dev_info_get(dev_id, &dev_info);
11668cdc3dfSJerin Jacob 	return (dev_info.event_dev_cap & RTE_EVENT_DEV_CAP_BURST_MODE) ?
11768cdc3dfSJerin Jacob 			true : false;
11868cdc3dfSJerin Jacob }
11968cdc3dfSJerin Jacob 
12068cdc3dfSJerin Jacob 
12168cdc3dfSJerin Jacob static inline bool
12268cdc3dfSJerin Jacob evt_has_all_types_queue(uint8_t dev_id)
12368cdc3dfSJerin Jacob {
12468cdc3dfSJerin Jacob 	struct rte_event_dev_info dev_info;
12568cdc3dfSJerin Jacob 
12668cdc3dfSJerin Jacob 	rte_event_dev_info_get(dev_id, &dev_info);
12768cdc3dfSJerin Jacob 	return (dev_info.event_dev_cap & RTE_EVENT_DEV_CAP_QUEUE_ALL_TYPES) ?
12868cdc3dfSJerin Jacob 			true : false;
12968cdc3dfSJerin Jacob }
13068cdc3dfSJerin Jacob 
13175d11313STimothy McDaniel static inline bool
13275d11313STimothy McDaniel evt_has_flow_id(uint8_t dev_id)
13375d11313STimothy McDaniel {
13475d11313STimothy McDaniel 	struct rte_event_dev_info dev_info;
13575d11313STimothy McDaniel 
13675d11313STimothy McDaniel 	rte_event_dev_info_get(dev_id, &dev_info);
13775d11313STimothy McDaniel 	return (dev_info.event_dev_cap & RTE_EVENT_DEV_CAP_CARRY_FLOW_ID) ?
13875d11313STimothy McDaniel 			true : false;
13975d11313STimothy McDaniel }
14075d11313STimothy McDaniel 
14157305d79SPavan Nikhilesh static inline int
142b0333c55SPavan Nikhilesh evt_service_setup(uint32_t service_id)
14357305d79SPavan Nikhilesh {
14457305d79SPavan Nikhilesh 	int32_t core_cnt;
14557305d79SPavan Nikhilesh 	unsigned int lcore = 0;
14657305d79SPavan Nikhilesh 	uint32_t core_array[RTE_MAX_LCORE];
14757305d79SPavan Nikhilesh 	uint8_t cnt;
14857305d79SPavan Nikhilesh 	uint8_t min_cnt = UINT8_MAX;
14957305d79SPavan Nikhilesh 
15057305d79SPavan Nikhilesh 	if (!rte_service_lcore_count())
15157305d79SPavan Nikhilesh 		return -ENOENT;
15257305d79SPavan Nikhilesh 
15357305d79SPavan Nikhilesh 	core_cnt = rte_service_lcore_list(core_array,
15457305d79SPavan Nikhilesh 			RTE_MAX_LCORE);
15557305d79SPavan Nikhilesh 	if (core_cnt < 0)
15657305d79SPavan Nikhilesh 		return -ENOENT;
15757305d79SPavan Nikhilesh 	/* Get the core which has least number of services running. */
15857305d79SPavan Nikhilesh 	while (core_cnt--) {
15957305d79SPavan Nikhilesh 		/* Reset default mapping */
16057305d79SPavan Nikhilesh 		rte_service_map_lcore_set(service_id,
16157305d79SPavan Nikhilesh 				core_array[core_cnt], 0);
16257305d79SPavan Nikhilesh 		cnt = rte_service_lcore_count_services(
16357305d79SPavan Nikhilesh 				core_array[core_cnt]);
16457305d79SPavan Nikhilesh 		if (cnt < min_cnt) {
16557305d79SPavan Nikhilesh 			lcore = core_array[core_cnt];
16657305d79SPavan Nikhilesh 			min_cnt = cnt;
16757305d79SPavan Nikhilesh 		}
16857305d79SPavan Nikhilesh 	}
16957305d79SPavan Nikhilesh 	if (rte_service_map_lcore_set(service_id, lcore, 1))
17057305d79SPavan Nikhilesh 		return -ENOENT;
171b0333c55SPavan Nikhilesh 
17257305d79SPavan Nikhilesh 	return 0;
17357305d79SPavan Nikhilesh }
17457305d79SPavan Nikhilesh 
175f0959283SPavan Nikhilesh static inline int
176f0959283SPavan Nikhilesh evt_configure_eventdev(struct evt_options *opt, uint8_t nb_queues,
177f0959283SPavan Nikhilesh 		uint8_t nb_ports)
178f0959283SPavan Nikhilesh {
179f0959283SPavan Nikhilesh 	struct rte_event_dev_info info;
180f0959283SPavan Nikhilesh 	int ret;
181f0959283SPavan Nikhilesh 
182f0959283SPavan Nikhilesh 	memset(&info, 0, sizeof(struct rte_event_dev_info));
183f0959283SPavan Nikhilesh 	ret = rte_event_dev_info_get(opt->dev_id, &info);
184f0959283SPavan Nikhilesh 	if (ret) {
185f0959283SPavan Nikhilesh 		evt_err("failed to get eventdev info %d", opt->dev_id);
186f0959283SPavan Nikhilesh 		return ret;
187f0959283SPavan Nikhilesh 	}
188f0959283SPavan Nikhilesh 
1897a7a04d3SPavan Nikhilesh 	if (opt->preschedule_opted && opt->preschedule) {
1907a7a04d3SPavan Nikhilesh 		switch (opt->preschedule) {
1917a7a04d3SPavan Nikhilesh 		case RTE_EVENT_PRESCHEDULE_ADAPTIVE:
1927a7a04d3SPavan Nikhilesh 			if (!(info.event_dev_cap & RTE_EVENT_DEV_CAP_EVENT_PRESCHEDULE_ADAPTIVE)) {
1937a7a04d3SPavan Nikhilesh 				evt_err("Preschedule type %d not supported", opt->preschedule);
1947a7a04d3SPavan Nikhilesh 				return -EINVAL;
1957a7a04d3SPavan Nikhilesh 			}
1967a7a04d3SPavan Nikhilesh 			break;
1977a7a04d3SPavan Nikhilesh 		case RTE_EVENT_PRESCHEDULE:
1987a7a04d3SPavan Nikhilesh 			if (!(info.event_dev_cap & RTE_EVENT_DEV_CAP_EVENT_PRESCHEDULE)) {
1997a7a04d3SPavan Nikhilesh 				evt_err("Preschedule type %d not supported", opt->preschedule);
2007a7a04d3SPavan Nikhilesh 				return -EINVAL;
2017a7a04d3SPavan Nikhilesh 			}
2027a7a04d3SPavan Nikhilesh 			break;
2037a7a04d3SPavan Nikhilesh 		default:
2047a7a04d3SPavan Nikhilesh 			break;
2057a7a04d3SPavan Nikhilesh 		}
2067a7a04d3SPavan Nikhilesh 	}
2077a7a04d3SPavan Nikhilesh 
2087a7a04d3SPavan Nikhilesh 	if (!opt->preschedule_opted) {
2097a7a04d3SPavan Nikhilesh 		if (info.event_dev_cap & RTE_EVENT_DEV_CAP_EVENT_PRESCHEDULE_ADAPTIVE)
2107a7a04d3SPavan Nikhilesh 			opt->preschedule = RTE_EVENT_PRESCHEDULE_ADAPTIVE;
2117a7a04d3SPavan Nikhilesh 	}
2127a7a04d3SPavan Nikhilesh 
213f0959283SPavan Nikhilesh 	if (opt->deq_tmo_nsec) {
214f0959283SPavan Nikhilesh 		if (opt->deq_tmo_nsec < info.min_dequeue_timeout_ns) {
215f0959283SPavan Nikhilesh 			opt->deq_tmo_nsec = info.min_dequeue_timeout_ns;
216f0959283SPavan Nikhilesh 			evt_info("dequeue_timeout_ns too low, using %d",
217f0959283SPavan Nikhilesh 					opt->deq_tmo_nsec);
218f0959283SPavan Nikhilesh 		}
219f0959283SPavan Nikhilesh 		if (opt->deq_tmo_nsec > info.max_dequeue_timeout_ns) {
220f0959283SPavan Nikhilesh 			opt->deq_tmo_nsec = info.max_dequeue_timeout_ns;
221f0959283SPavan Nikhilesh 			evt_info("dequeue_timeout_ns too high, using %d",
222f0959283SPavan Nikhilesh 					opt->deq_tmo_nsec);
223f0959283SPavan Nikhilesh 		}
224f0959283SPavan Nikhilesh 	}
225f0959283SPavan Nikhilesh 
226f0959283SPavan Nikhilesh 	const struct rte_event_dev_config config = {
227f0959283SPavan Nikhilesh 		.dequeue_timeout_ns = opt->deq_tmo_nsec,
228f0959283SPavan Nikhilesh 		.nb_event_queues = nb_queues,
229f0959283SPavan Nikhilesh 		.nb_event_ports = nb_ports,
23075d11313STimothy McDaniel 		.nb_single_link_event_port_queues = 0,
231f0959283SPavan Nikhilesh 		.nb_events_limit = info.max_num_events,
232f0959283SPavan Nikhilesh 		.nb_event_queue_flows = opt->nb_flows,
2337a7a04d3SPavan Nikhilesh 		.nb_event_port_dequeue_depth = info.max_event_port_dequeue_depth,
2347a7a04d3SPavan Nikhilesh 		.nb_event_port_enqueue_depth = info.max_event_port_enqueue_depth,
2357a7a04d3SPavan Nikhilesh 		.preschedule_type = opt->preschedule,
236f0959283SPavan Nikhilesh 	};
237f0959283SPavan Nikhilesh 
238f0959283SPavan Nikhilesh 	return rte_event_dev_configure(opt->dev_id, &config);
239f0959283SPavan Nikhilesh }
240f0959283SPavan Nikhilesh 
24168cdc3dfSJerin Jacob #endif /*  _EVT_COMMON_*/
242