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