4 * Copyright(c) 2016-2017 Intel Corporation. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of Intel Corporation nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #include <rte_eventdev.h>
37 #include <rte_eventdev_pmd.h>
38 #include <rte_atomic.h>
40 #define SW_DEFAULT_CREDIT_QUANTA 32
41 #define SW_DEFAULT_SCHED_QUANTA 128
42 #define SW_QID_NUM_FIDS 16384
44 #define SW_Q_PRIORITY_MAX 255
45 #define SW_PORTS_MAX 64
46 #define MAX_SW_CONS_Q_DEPTH 128
47 #define SW_INFLIGHT_EVENTS_TOTAL 4096
48 /* allow for lots of over-provisioning */
49 #define MAX_SW_PROD_Q_DEPTH 4096
50 #define SW_FRAGMENTS_MAX 16
52 /* report dequeue burst sizes in buckets */
53 #define SW_DEQ_STAT_BUCKET_SHIFT 2
54 /* how many packets pulled from port by sched */
55 #define SCHED_DEQUEUE_BURST_SIZE 32
57 #define SW_PORT_HIST_LIST (MAX_SW_PROD_Q_DEPTH) /* size of our history list */
58 #define NUM_SAMPLES 64 /* how many data points use for average stats */
60 #define EVENTDEV_NAME_SW_PMD event_sw
61 #define SW_PMD_NAME RTE_STR(event_sw)
63 #define SW_SCHED_TYPE_DIRECT (RTE_SCHED_TYPE_PARALLEL + 1)
66 QE_FLAG_VALID_SHIFT = 0,
67 QE_FLAG_COMPLETE_SHIFT,
68 QE_FLAG_NOT_EOP_SHIFT,
72 #define QE_FLAG_VALID (1 << QE_FLAG_VALID_SHIFT) /* for NEW FWD, FRAG */
73 #define QE_FLAG_COMPLETE (1 << QE_FLAG_COMPLETE_SHIFT) /* set for FWD, DROP */
74 #define QE_FLAG_NOT_EOP (1 << QE_FLAG_NOT_EOP_SHIFT) /* set for FRAG only */
76 static const uint8_t sw_qe_flag_map[] = {
77 QE_FLAG_VALID /* NEW Event */,
78 QE_FLAG_VALID | QE_FLAG_COMPLETE /* FWD Event */,
79 QE_FLAG_COMPLETE /* RELEASE Event */,
81 /* Values which can be used for future support for partial
82 * events, i.e. where one event comes back to the scheduler
83 * as multiple which need to be tracked together
85 QE_FLAG_VALID | QE_FLAG_COMPLETE | QE_FLAG_NOT_EOP,
88 #ifdef RTE_LIBRTE_PMD_EVDEV_SW_DEBUG
89 #define SW_LOG_INFO(fmt, args...) \
90 RTE_LOG(INFO, EVENTDEV, "[%s] %s() line %u: " fmt "\n", \
92 __func__, __LINE__, ## args)
94 #define SW_LOG_DBG(fmt, args...) \
95 RTE_LOG(DEBUG, EVENTDEV, "[%s] %s() line %u: " fmt "\n", \
97 __func__, __LINE__, ## args)
99 #define SW_LOG_INFO(fmt, args...)
100 #define SW_LOG_DBG(fmt, args...)
103 #define SW_LOG_ERR(fmt, args...) \
104 RTE_LOG(ERR, EVENTDEV, "[%s] %s() line %u: " fmt "\n", \
106 __func__, __LINE__, ## args)
108 /* Records basic event stats at a given point. Used in port and qid structs */
109 struct sw_point_stats {
115 /* structure used to track what port a flow (FID) is pinned to */
117 /* which CQ this FID is currently pinned to */
119 /* number of packets gone to the CQ with this FID */
123 struct reorder_buffer_entry {
124 uint16_t num_fragments; /**< Number of packet fragments */
125 uint16_t fragment_index; /**< Points to the oldest valid frag */
126 uint8_t ready; /**< Entry is ready to be reordered */
127 struct rte_event fragments[SW_FRAGMENTS_MAX];
131 /* set when the QID has been initialized */
133 /* The type of this QID */
135 /* Integer ID representing the queue. This is used in history lists,
136 * to identify the stage of processing.
139 struct sw_point_stats stats;
141 /* Internal priority rings for packets */
142 struct iq_ring *iq[SW_IQS_MAX];
143 uint32_t iq_pkt_mask; /* A mask to indicate packets in an IQ */
144 uint64_t iq_pkt_count[SW_IQS_MAX];
146 /* Information on what CQs are polling this IQ */
147 uint32_t cq_num_mapped_cqs;
148 uint32_t cq_next_tx; /* cq to write next (non-atomic) packet */
149 uint32_t cq_map[SW_PORTS_MAX];
151 /* Track flow ids for atomic load balancing */
152 struct sw_fid_t fids[SW_QID_NUM_FIDS];
154 /* Track packet order for reordering when needed */
155 struct reorder_buffer_entry *reorder_buffer; /*< pkts await reorder */
156 struct rte_ring *reorder_buffer_freelist; /* available reorder slots */
157 uint32_t reorder_buffer_index; /* oldest valid reorder buffer entry */
158 uint32_t window_size; /* Used to wrap reorder_buffer_index */
163 struct sw_hist_list_entry {
166 struct reorder_buffer_entry *rob_entry;
172 /* new enqueue / dequeue API doesn't have an instance pointer, only the
173 * pointer to the port being enqueue/dequeued from
177 /* set when the port is initialized */
179 /* A numeric ID for the port */
182 int16_t is_directed; /** Takes from a single directed QID */
184 * For loadbalanced we can optimise pulling packets from
185 * producers if there is no reordering involved
187 int16_t num_ordered_qids;
189 /** Ring and buffer for pulling events from workers for scheduling */
190 struct qe_ring *rx_worker_ring __rte_cache_aligned;
191 /** Ring and buffer for pushing packets to workers after scheduling */
192 struct qe_ring *cq_worker_ring;
196 /* num releases yet to be completed on this port */
197 uint16_t outstanding_releases __rte_cache_aligned;
198 uint16_t inflight_max; /* app requested max inflights for this port */
199 uint16_t inflight_credits; /* num credits this port has right now */
201 uint16_t last_dequeue_burst_sz; /* how big the burst was */
202 uint64_t last_dequeue_ticks; /* used to track burst processing time */
203 uint64_t avg_pkt_ticks; /* tracks average over NUM_SAMPLES burst */
204 uint64_t total_polls; /* how many polls were counted in stats */
205 uint64_t zero_polls; /* tracks polls returning nothing */
206 uint32_t poll_buckets[MAX_SW_CONS_Q_DEPTH >> SW_DEQ_STAT_BUCKET_SHIFT];
207 /* bucket values in 4s for shorter reporting */
209 /* History list structs, containing info on pkts egressed to worker */
210 uint16_t hist_head __rte_cache_aligned;
213 struct sw_hist_list_entry hist_list[SW_PORT_HIST_LIST];
215 /* track packets in and out of this port */
216 struct sw_point_stats stats;
219 uint32_t pp_buf_start;
220 uint32_t pp_buf_count;
221 uint16_t cq_buf_count;
222 struct rte_event pp_buf[SCHED_DEQUEUE_BURST_SIZE];
223 struct rte_event cq_buf[MAX_SW_CONS_Q_DEPTH];
225 uint8_t num_qids_mapped;
229 struct rte_eventdev_data *data;
234 /* Contains all ports - load balanced and directed */
235 struct sw_port ports[SW_PORTS_MAX] __rte_cache_aligned;
237 rte_atomic32_t inflights __rte_cache_aligned;
240 * max events in this instance. Cached here for performance.
241 * (also available in data->conf.nb_events_limit)
243 uint32_t nb_events_limit;
245 /* Internal queues - one per logical queue */
246 struct sw_qid qids[RTE_EVENT_MAX_QUEUES_PER_DEV] __rte_cache_aligned;
248 /* Cache how many packets are in each cq */
249 uint16_t cq_ring_space[SW_PORTS_MAX] __rte_cache_aligned;
251 /* Array of pointers to load-balanced QIDs sorted by priority level */
252 struct sw_qid *qids_prioritized[RTE_EVENT_MAX_QUEUES_PER_DEV];
255 struct sw_point_stats stats __rte_cache_aligned;
256 uint64_t sched_called;
257 int32_t sched_quanta;
258 uint64_t sched_no_iq_enqueues;
259 uint64_t sched_no_cq_enqueues;
260 uint64_t sched_cq_qid_called;
263 uint32_t credit_update_quanta;
266 static inline struct sw_evdev *
267 sw_pmd_priv(const struct rte_eventdev *eventdev)
269 return eventdev->data->dev_private;
272 static inline const struct sw_evdev *
273 sw_pmd_priv_const(const struct rte_eventdev *eventdev)
275 return eventdev->data->dev_private;
278 uint16_t sw_event_enqueue(void *port, const struct rte_event *ev);
279 uint16_t sw_event_enqueue_burst(void *port, const struct rte_event ev[],
282 uint16_t sw_event_dequeue(void *port, struct rte_event *ev, uint64_t wait);
283 uint16_t sw_event_dequeue_burst(void *port, struct rte_event *ev, uint16_t num,
285 void sw_event_schedule(struct rte_eventdev *dev);
287 #endif /* _SW_EVDEV_H_ */