xref: /dpdk/drivers/event/sw/sw_evdev.h (revision ba9de463)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2016-2017 Intel Corporation
3  */
4 
5 #ifndef _SW_EVDEV_H_
6 #define _SW_EVDEV_H_
7 
8 #include <rte_eventdev.h>
9 #include <rte_eventdev_pmd_vdev.h>
10 #include <rte_atomic.h>
11 
12 #define SW_DEFAULT_CREDIT_QUANTA 32
13 #define SW_DEFAULT_SCHED_QUANTA 128
14 #define SW_QID_NUM_FIDS 16384
15 #define SW_IQS_MAX 4
16 #define SW_Q_PRIORITY_MAX 255
17 #define SW_PORTS_MAX 64
18 #define MAX_SW_CONS_Q_DEPTH 128
19 #define SW_INFLIGHT_EVENTS_TOTAL 4096
20 /* allow for lots of over-provisioning */
21 #define MAX_SW_PROD_Q_DEPTH 4096
22 #define SW_FRAGMENTS_MAX 16
23 
24 /* Should be power-of-two minus one, to leave room for the next pointer */
25 #define SW_EVS_PER_Q_CHUNK 255
26 #define SW_Q_CHUNK_SIZE ((SW_EVS_PER_Q_CHUNK + 1) * sizeof(struct rte_event))
27 
28 /* report dequeue burst sizes in buckets */
29 #define SW_DEQ_STAT_BUCKET_SHIFT 2
30 /* how many packets pulled from port by sched */
31 #define SCHED_DEQUEUE_BURST_SIZE 32
32 
33 #define SW_PORT_HIST_LIST (MAX_SW_PROD_Q_DEPTH) /* size of our history list */
34 #define NUM_SAMPLES 64 /* how many data points use for average stats */
35 
36 #define EVENTDEV_NAME_SW_PMD event_sw
37 #define SW_PMD_NAME RTE_STR(event_sw)
38 #define SW_PMD_NAME_MAX 64
39 
40 #define SW_SCHED_TYPE_DIRECT (RTE_SCHED_TYPE_PARALLEL + 1)
41 
42 #define SW_NUM_POLL_BUCKETS (MAX_SW_CONS_Q_DEPTH >> SW_DEQ_STAT_BUCKET_SHIFT)
43 
44 enum {
45 	QE_FLAG_VALID_SHIFT = 0,
46 	QE_FLAG_COMPLETE_SHIFT,
47 	QE_FLAG_NOT_EOP_SHIFT,
48 	_QE_FLAG_COUNT
49 };
50 
51 #define QE_FLAG_VALID    (1 << QE_FLAG_VALID_SHIFT)    /* for NEW FWD, FRAG */
52 #define QE_FLAG_COMPLETE (1 << QE_FLAG_COMPLETE_SHIFT) /* set for FWD, DROP  */
53 #define QE_FLAG_NOT_EOP  (1 << QE_FLAG_NOT_EOP_SHIFT)  /* set for FRAG only  */
54 
55 static const uint8_t sw_qe_flag_map[] = {
56 		QE_FLAG_VALID /* NEW Event */,
57 		QE_FLAG_VALID | QE_FLAG_COMPLETE /* FWD Event */,
58 		QE_FLAG_COMPLETE /* RELEASE Event */,
59 
60 		/* Values which can be used for future support for partial
61 		 * events, i.e. where one event comes back to the scheduler
62 		 * as multiple which need to be tracked together
63 		 */
64 		QE_FLAG_VALID | QE_FLAG_COMPLETE | QE_FLAG_NOT_EOP,
65 };
66 
67 #ifdef RTE_LIBRTE_PMD_EVDEV_SW_DEBUG
68 #define SW_LOG_INFO(fmt, args...) \
69 	RTE_LOG(INFO, EVENTDEV, "[%s] %s() line %u: " fmt "\n", \
70 			SW_PMD_NAME, \
71 			__func__, __LINE__, ## args)
72 
73 #define SW_LOG_DBG(fmt, args...) \
74 	RTE_LOG(DEBUG, EVENTDEV, "[%s] %s() line %u: " fmt "\n", \
75 			SW_PMD_NAME, \
76 			__func__, __LINE__, ## args)
77 #else
78 #define SW_LOG_INFO(fmt, args...)
79 #define SW_LOG_DBG(fmt, args...)
80 #endif
81 
82 #define SW_LOG_ERR(fmt, args...) \
83 	RTE_LOG(ERR, EVENTDEV, "[%s] %s() line %u: " fmt "\n", \
84 			SW_PMD_NAME, \
85 			__func__, __LINE__, ## args)
86 
87 /* Records basic event stats at a given point. Used in port and qid structs */
88 struct sw_point_stats {
89 	uint64_t rx_pkts;
90 	uint64_t rx_dropped;
91 	uint64_t tx_pkts;
92 };
93 
94 /* structure used to track what port a flow (FID) is pinned to */
95 struct sw_fid_t {
96 	/* which CQ this FID is currently pinned to */
97 	int32_t cq;
98 	/* number of packets gone to the CQ with this FID */
99 	uint32_t pcount;
100 };
101 
102 struct reorder_buffer_entry {
103 	uint16_t num_fragments;		/**< Number of packet fragments */
104 	uint16_t fragment_index;	/**< Points to the oldest valid frag */
105 	uint8_t ready;			/**< Entry is ready to be reordered */
106 	struct rte_event fragments[SW_FRAGMENTS_MAX];
107 };
108 
109 struct sw_iq {
110 	struct sw_queue_chunk *head;
111 	struct sw_queue_chunk *tail;
112 	uint16_t head_idx;
113 	uint16_t tail_idx;
114 	uint16_t count;
115 };
116 
117 struct sw_qid {
118 	/* set when the QID has been initialized */
119 	uint8_t initialized;
120 	/* The type of this QID */
121 	int8_t type;
122 	/* Integer ID representing the queue. This is used in history lists,
123 	 * to identify the stage of processing.
124 	 */
125 	uint32_t id;
126 	struct sw_point_stats stats;
127 
128 	/* Internal priority rings for packets */
129 	struct sw_iq iq[SW_IQS_MAX];
130 	uint32_t iq_pkt_mask; /* A mask to indicate packets in an IQ */
131 	uint64_t iq_pkt_count[SW_IQS_MAX];
132 
133 	/* Information on what CQs are polling this IQ */
134 	uint32_t cq_num_mapped_cqs;
135 	uint32_t cq_next_tx; /* cq to write next (non-atomic) packet */
136 	uint32_t cq_map[SW_PORTS_MAX];
137 	uint64_t to_port[SW_PORTS_MAX];
138 
139 	/* Track flow ids for atomic load balancing */
140 	struct sw_fid_t fids[SW_QID_NUM_FIDS];
141 
142 	/* Track packet order for reordering when needed */
143 	struct reorder_buffer_entry *reorder_buffer; /*< pkts await reorder */
144 	struct rte_ring *reorder_buffer_freelist; /* available reorder slots */
145 	uint32_t reorder_buffer_index; /* oldest valid reorder buffer entry */
146 	uint32_t window_size;          /* Used to wrap reorder_buffer_index */
147 
148 	uint8_t priority;
149 };
150 
151 struct sw_hist_list_entry {
152 	int32_t qid;
153 	int32_t fid;
154 	struct reorder_buffer_entry *rob_entry;
155 };
156 
157 struct sw_evdev;
158 
159 struct sw_port {
160 	/* new enqueue / dequeue API doesn't have an instance pointer, only the
161 	 * pointer to the port being enqueue/dequeued from
162 	 */
163 	struct sw_evdev *sw;
164 
165 	/* set when the port is initialized */
166 	uint8_t initialized;
167 	/* A numeric ID for the port */
168 	uint8_t id;
169 
170 	int16_t is_directed; /** Takes from a single directed QID */
171 	/**
172 	 * For loadbalanced we can optimise pulling packets from
173 	 * producers if there is no reordering involved
174 	 */
175 	int16_t num_ordered_qids;
176 
177 	/** Ring and buffer for pulling events from workers for scheduling */
178 	struct rte_event_ring *rx_worker_ring __rte_cache_aligned;
179 	/** Ring and buffer for pushing packets to workers after scheduling */
180 	struct rte_event_ring *cq_worker_ring;
181 
182 	/* hole */
183 
184 	/* num releases yet to be completed on this port */
185 	uint16_t outstanding_releases __rte_cache_aligned;
186 	uint16_t inflight_max; /* app requested max inflights for this port */
187 	uint16_t inflight_credits; /* num credits this port has right now */
188 	uint8_t implicit_release; /* release events before dequeueing */
189 
190 	uint16_t last_dequeue_burst_sz; /* how big the burst was */
191 	uint64_t last_dequeue_ticks; /* used to track burst processing time */
192 	uint64_t avg_pkt_ticks;      /* tracks average over NUM_SAMPLES burst */
193 	uint64_t total_polls;        /* how many polls were counted in stats */
194 	uint64_t zero_polls;         /* tracks polls returning nothing */
195 	uint32_t poll_buckets[SW_NUM_POLL_BUCKETS];
196 		/* bucket values in 4s for shorter reporting */
197 
198 	/* History list structs, containing info on pkts egressed to worker */
199 	uint16_t hist_head __rte_cache_aligned;
200 	uint16_t hist_tail;
201 	uint16_t inflights;
202 	struct sw_hist_list_entry hist_list[SW_PORT_HIST_LIST];
203 
204 	/* track packets in and out of this port */
205 	struct sw_point_stats stats;
206 
207 
208 	uint32_t pp_buf_start;
209 	uint32_t pp_buf_count;
210 	uint16_t cq_buf_count;
211 	struct rte_event pp_buf[SCHED_DEQUEUE_BURST_SIZE];
212 	struct rte_event cq_buf[MAX_SW_CONS_Q_DEPTH];
213 
214 	uint8_t num_qids_mapped;
215 };
216 
217 struct sw_evdev {
218 	struct rte_eventdev_data *data;
219 
220 	uint32_t port_count;
221 	uint32_t qid_count;
222 	uint32_t xstats_count;
223 	struct sw_xstats_entry *xstats;
224 	uint32_t xstats_count_mode_dev;
225 	uint32_t xstats_count_mode_port;
226 	uint32_t xstats_count_mode_queue;
227 
228 	/* Contains all ports - load balanced and directed */
229 	struct sw_port ports[SW_PORTS_MAX] __rte_cache_aligned;
230 
231 	rte_atomic32_t inflights __rte_cache_aligned;
232 
233 	/*
234 	 * max events in this instance. Cached here for performance.
235 	 * (also available in data->conf.nb_events_limit)
236 	 */
237 	uint32_t nb_events_limit;
238 
239 	/* Internal queues - one per logical queue */
240 	struct sw_qid qids[RTE_EVENT_MAX_QUEUES_PER_DEV] __rte_cache_aligned;
241 	struct sw_queue_chunk *chunk_list_head;
242 	struct sw_queue_chunk *chunks;
243 
244 	/* Cache how many packets are in each cq */
245 	uint16_t cq_ring_space[SW_PORTS_MAX] __rte_cache_aligned;
246 
247 	/* Array of pointers to load-balanced QIDs sorted by priority level */
248 	struct sw_qid *qids_prioritized[RTE_EVENT_MAX_QUEUES_PER_DEV];
249 
250 	/* Stats */
251 	struct sw_point_stats stats __rte_cache_aligned;
252 	uint64_t sched_called;
253 	int32_t sched_quanta;
254 	uint64_t sched_no_iq_enqueues;
255 	uint64_t sched_no_cq_enqueues;
256 	uint64_t sched_cq_qid_called;
257 
258 	uint8_t started;
259 	uint32_t credit_update_quanta;
260 
261 	/* store num stats and offset of the stats for each port */
262 	uint16_t xstats_count_per_port[SW_PORTS_MAX];
263 	uint16_t xstats_offset_for_port[SW_PORTS_MAX];
264 	/* store num stats and offset of the stats for each queue */
265 	uint16_t xstats_count_per_qid[RTE_EVENT_MAX_QUEUES_PER_DEV];
266 	uint16_t xstats_offset_for_qid[RTE_EVENT_MAX_QUEUES_PER_DEV];
267 
268 	uint32_t service_id;
269 	char service_name[SW_PMD_NAME_MAX];
270 };
271 
272 static inline struct sw_evdev *
273 sw_pmd_priv(const struct rte_eventdev *eventdev)
274 {
275 	return eventdev->data->dev_private;
276 }
277 
278 static inline const struct sw_evdev *
279 sw_pmd_priv_const(const struct rte_eventdev *eventdev)
280 {
281 	return eventdev->data->dev_private;
282 }
283 
284 uint16_t sw_event_enqueue(void *port, const struct rte_event *ev);
285 uint16_t sw_event_enqueue_burst(void *port, const struct rte_event ev[],
286 		uint16_t num);
287 
288 uint16_t sw_event_dequeue(void *port, struct rte_event *ev, uint64_t wait);
289 uint16_t sw_event_dequeue_burst(void *port, struct rte_event *ev, uint16_t num,
290 			uint64_t wait);
291 void sw_event_schedule(struct rte_eventdev *dev);
292 int sw_xstats_init(struct sw_evdev *dev);
293 int sw_xstats_uninit(struct sw_evdev *dev);
294 int sw_xstats_get_names(const struct rte_eventdev *dev,
295 	enum rte_event_dev_xstats_mode mode, uint8_t queue_port_id,
296 	struct rte_event_dev_xstats_name *xstats_names,
297 	unsigned int *ids, unsigned int size);
298 int sw_xstats_get(const struct rte_eventdev *dev,
299 		enum rte_event_dev_xstats_mode mode, uint8_t queue_port_id,
300 		const unsigned int ids[], uint64_t values[], unsigned int n);
301 uint64_t sw_xstats_get_by_name(const struct rte_eventdev *dev,
302 		const char *name, unsigned int *id);
303 int sw_xstats_reset(struct rte_eventdev *dev,
304 		enum rte_event_dev_xstats_mode mode,
305 		int16_t queue_port_id,
306 		const uint32_t ids[],
307 		uint32_t nb_ids);
308 
309 int test_sw_eventdev(void);
310 
311 #endif /* _SW_EVDEV_H_ */
312