event/sw: support event ports
[dpdk.git] / drivers / event / sw / sw_evdev.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2016-2017 Intel Corporation. All rights reserved.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
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
15  *       distribution.
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.
19  *
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.
31  */
32
33 #ifndef _SW_EVDEV_H_
34 #define _SW_EVDEV_H_
35
36 #include <rte_eventdev.h>
37 #include <rte_eventdev_pmd.h>
38 #include <rte_atomic.h>
39
40 #define SW_DEFAULT_CREDIT_QUANTA 32
41 #define SW_DEFAULT_SCHED_QUANTA 128
42 #define SW_QID_NUM_FIDS 16384
43 #define SW_IQS_MAX 4
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
51
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
56
57 #define SW_PORT_HIST_LIST (MAX_SW_PROD_Q_DEPTH) /* size of our history list */
58
59 #define EVENTDEV_NAME_SW_PMD event_sw
60 #define SW_PMD_NAME RTE_STR(event_sw)
61
62 #define SW_SCHED_TYPE_DIRECT (RTE_SCHED_TYPE_PARALLEL + 1)
63
64 #ifdef RTE_LIBRTE_PMD_EVDEV_SW_DEBUG
65 #define SW_LOG_INFO(fmt, args...) \
66         RTE_LOG(INFO, EVENTDEV, "[%s] %s() line %u: " fmt "\n", \
67                         SW_PMD_NAME, \
68                         __func__, __LINE__, ## args)
69
70 #define SW_LOG_DBG(fmt, args...) \
71         RTE_LOG(DEBUG, EVENTDEV, "[%s] %s() line %u: " fmt "\n", \
72                         SW_PMD_NAME, \
73                         __func__, __LINE__, ## args)
74 #else
75 #define SW_LOG_INFO(fmt, args...)
76 #define SW_LOG_DBG(fmt, args...)
77 #endif
78
79 #define SW_LOG_ERR(fmt, args...) \
80         RTE_LOG(ERR, EVENTDEV, "[%s] %s() line %u: " fmt "\n", \
81                         SW_PMD_NAME, \
82                         __func__, __LINE__, ## args)
83
84 /* Records basic event stats at a given point. Used in port and qid structs */
85 struct sw_point_stats {
86         uint64_t rx_pkts;
87         uint64_t rx_dropped;
88         uint64_t tx_pkts;
89 };
90
91 /* structure used to track what port a flow (FID) is pinned to */
92 struct sw_fid_t {
93         /* which CQ this FID is currently pinned to */
94         int32_t cq;
95         /* number of packets gone to the CQ with this FID */
96         uint32_t pcount;
97 };
98
99 struct reorder_buffer_entry {
100         uint16_t num_fragments;         /**< Number of packet fragments */
101         uint16_t fragment_index;        /**< Points to the oldest valid frag */
102         uint8_t ready;                  /**< Entry is ready to be reordered */
103         struct rte_event fragments[SW_FRAGMENTS_MAX];
104 };
105
106 struct sw_qid {
107         /* set when the QID has been initialized */
108         uint8_t initialized;
109         /* The type of this QID */
110         int8_t type;
111         /* Integer ID representing the queue. This is used in history lists,
112          * to identify the stage of processing.
113          */
114         uint32_t id;
115         struct sw_point_stats stats;
116
117         /* Internal priority rings for packets */
118         struct iq_ring *iq[SW_IQS_MAX];
119         uint32_t iq_pkt_mask; /* A mask to indicate packets in an IQ */
120         uint64_t iq_pkt_count[SW_IQS_MAX];
121
122         /* Information on what CQs are polling this IQ */
123         uint32_t cq_num_mapped_cqs;
124         uint32_t cq_next_tx; /* cq to write next (non-atomic) packet */
125         uint32_t cq_map[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 qe_ring *rx_worker_ring __rte_cache_aligned;
167         /** Ring and buffer for pushing packets to workers after scheduling */
168         struct qe_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[MAX_SW_CONS_Q_DEPTH >> SW_DEQ_STAT_BUCKET_SHIFT];
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
210         /* Contains all ports - load balanced and directed */
211         struct sw_port ports[SW_PORTS_MAX] __rte_cache_aligned;
212
213         rte_atomic32_t inflights __rte_cache_aligned;
214
215         /*
216          * max events in this instance. Cached here for performance.
217          * (also available in data->conf.nb_events_limit)
218          */
219         uint32_t nb_events_limit;
220
221         /* Internal queues - one per logical queue */
222         struct sw_qid qids[RTE_EVENT_MAX_QUEUES_PER_DEV] __rte_cache_aligned;
223
224         /* Cache how many packets are in each cq */
225         uint16_t cq_ring_space[SW_PORTS_MAX] __rte_cache_aligned;
226
227         int32_t sched_quanta;
228
229         uint32_t credit_update_quanta;
230 };
231
232 static inline struct sw_evdev *
233 sw_pmd_priv(const struct rte_eventdev *eventdev)
234 {
235         return eventdev->data->dev_private;
236 }
237
238 static inline const struct sw_evdev *
239 sw_pmd_priv_const(const struct rte_eventdev *eventdev)
240 {
241         return eventdev->data->dev_private;
242 }
243
244 #endif /* _SW_EVDEV_H_ */