1d30ea906Sjfb8856606 /* SPDX-License-Identifier: BSD-3-Clause
2d30ea906Sjfb8856606 * Copyright(c) 2016-2017 Intel Corporation
32bfe3f2eSlogwang */
42bfe3f2eSlogwang
52bfe3f2eSlogwang #ifndef _SW_EVDEV_H_
62bfe3f2eSlogwang #define _SW_EVDEV_H_
72bfe3f2eSlogwang
8d30ea906Sjfb8856606 #include "sw_evdev_log.h"
92bfe3f2eSlogwang #include <rte_eventdev.h>
102bfe3f2eSlogwang #include <rte_eventdev_pmd_vdev.h>
112bfe3f2eSlogwang #include <rte_atomic.h>
122bfe3f2eSlogwang
132bfe3f2eSlogwang #define SW_DEFAULT_CREDIT_QUANTA 32
142bfe3f2eSlogwang #define SW_DEFAULT_SCHED_QUANTA 128
152bfe3f2eSlogwang #define SW_QID_NUM_FIDS 16384
162bfe3f2eSlogwang #define SW_IQS_MAX 4
172bfe3f2eSlogwang #define SW_Q_PRIORITY_MAX 255
182bfe3f2eSlogwang #define SW_PORTS_MAX 64
192bfe3f2eSlogwang #define MAX_SW_CONS_Q_DEPTH 128
202bfe3f2eSlogwang #define SW_INFLIGHT_EVENTS_TOTAL 4096
212bfe3f2eSlogwang /* allow for lots of over-provisioning */
222bfe3f2eSlogwang #define MAX_SW_PROD_Q_DEPTH 4096
232bfe3f2eSlogwang #define SW_FRAGMENTS_MAX 16
242bfe3f2eSlogwang
25d30ea906Sjfb8856606 /* Should be power-of-two minus one, to leave room for the next pointer */
26d30ea906Sjfb8856606 #define SW_EVS_PER_Q_CHUNK 255
27d30ea906Sjfb8856606 #define SW_Q_CHUNK_SIZE ((SW_EVS_PER_Q_CHUNK + 1) * sizeof(struct rte_event))
28d30ea906Sjfb8856606
292bfe3f2eSlogwang /* report dequeue burst sizes in buckets */
302bfe3f2eSlogwang #define SW_DEQ_STAT_BUCKET_SHIFT 2
312bfe3f2eSlogwang /* how many packets pulled from port by sched */
32*2d9fd380Sjfb8856606 #define SCHED_DEQUEUE_DEFAULT_BURST_SIZE 32
33*2d9fd380Sjfb8856606 /* max buffer size */
34*2d9fd380Sjfb8856606 #define SCHED_DEQUEUE_MAX_BURST_SIZE 256
35*2d9fd380Sjfb8856606
36*2d9fd380Sjfb8856606 /* Flush the pipeline after this many no enq to cq */
37*2d9fd380Sjfb8856606 #define SCHED_NO_ENQ_CYCLE_FLUSH 256
38*2d9fd380Sjfb8856606
392bfe3f2eSlogwang
402bfe3f2eSlogwang #define SW_PORT_HIST_LIST (MAX_SW_PROD_Q_DEPTH) /* size of our history list */
412bfe3f2eSlogwang #define NUM_SAMPLES 64 /* how many data points use for average stats */
422bfe3f2eSlogwang
432bfe3f2eSlogwang #define EVENTDEV_NAME_SW_PMD event_sw
442bfe3f2eSlogwang #define SW_PMD_NAME RTE_STR(event_sw)
452bfe3f2eSlogwang #define SW_PMD_NAME_MAX 64
462bfe3f2eSlogwang
472bfe3f2eSlogwang #define SW_SCHED_TYPE_DIRECT (RTE_SCHED_TYPE_PARALLEL + 1)
482bfe3f2eSlogwang
492bfe3f2eSlogwang #define SW_NUM_POLL_BUCKETS (MAX_SW_CONS_Q_DEPTH >> SW_DEQ_STAT_BUCKET_SHIFT)
502bfe3f2eSlogwang
512bfe3f2eSlogwang enum {
522bfe3f2eSlogwang QE_FLAG_VALID_SHIFT = 0,
532bfe3f2eSlogwang QE_FLAG_COMPLETE_SHIFT,
542bfe3f2eSlogwang QE_FLAG_NOT_EOP_SHIFT,
552bfe3f2eSlogwang _QE_FLAG_COUNT
562bfe3f2eSlogwang };
572bfe3f2eSlogwang
582bfe3f2eSlogwang #define QE_FLAG_VALID (1 << QE_FLAG_VALID_SHIFT) /* for NEW FWD, FRAG */
592bfe3f2eSlogwang #define QE_FLAG_COMPLETE (1 << QE_FLAG_COMPLETE_SHIFT) /* set for FWD, DROP */
602bfe3f2eSlogwang #define QE_FLAG_NOT_EOP (1 << QE_FLAG_NOT_EOP_SHIFT) /* set for FRAG only */
612bfe3f2eSlogwang
622bfe3f2eSlogwang static const uint8_t sw_qe_flag_map[] = {
632bfe3f2eSlogwang QE_FLAG_VALID /* NEW Event */,
642bfe3f2eSlogwang QE_FLAG_VALID | QE_FLAG_COMPLETE /* FWD Event */,
652bfe3f2eSlogwang QE_FLAG_COMPLETE /* RELEASE Event */,
662bfe3f2eSlogwang
672bfe3f2eSlogwang /* Values which can be used for future support for partial
682bfe3f2eSlogwang * events, i.e. where one event comes back to the scheduler
692bfe3f2eSlogwang * as multiple which need to be tracked together
702bfe3f2eSlogwang */
712bfe3f2eSlogwang QE_FLAG_VALID | QE_FLAG_COMPLETE | QE_FLAG_NOT_EOP,
722bfe3f2eSlogwang };
732bfe3f2eSlogwang
742bfe3f2eSlogwang /* Records basic event stats at a given point. Used in port and qid structs */
752bfe3f2eSlogwang struct sw_point_stats {
762bfe3f2eSlogwang uint64_t rx_pkts;
772bfe3f2eSlogwang uint64_t rx_dropped;
782bfe3f2eSlogwang uint64_t tx_pkts;
792bfe3f2eSlogwang };
802bfe3f2eSlogwang
812bfe3f2eSlogwang /* structure used to track what port a flow (FID) is pinned to */
822bfe3f2eSlogwang struct sw_fid_t {
832bfe3f2eSlogwang /* which CQ this FID is currently pinned to */
842bfe3f2eSlogwang int32_t cq;
852bfe3f2eSlogwang /* number of packets gone to the CQ with this FID */
862bfe3f2eSlogwang uint32_t pcount;
872bfe3f2eSlogwang };
882bfe3f2eSlogwang
892bfe3f2eSlogwang struct reorder_buffer_entry {
902bfe3f2eSlogwang uint16_t num_fragments; /**< Number of packet fragments */
912bfe3f2eSlogwang uint16_t fragment_index; /**< Points to the oldest valid frag */
922bfe3f2eSlogwang uint8_t ready; /**< Entry is ready to be reordered */
932bfe3f2eSlogwang struct rte_event fragments[SW_FRAGMENTS_MAX];
942bfe3f2eSlogwang };
952bfe3f2eSlogwang
96d30ea906Sjfb8856606 struct sw_iq {
97d30ea906Sjfb8856606 struct sw_queue_chunk *head;
98d30ea906Sjfb8856606 struct sw_queue_chunk *tail;
99d30ea906Sjfb8856606 uint16_t head_idx;
100d30ea906Sjfb8856606 uint16_t tail_idx;
101d30ea906Sjfb8856606 uint16_t count;
102d30ea906Sjfb8856606 };
103d30ea906Sjfb8856606
1042bfe3f2eSlogwang struct sw_qid {
1052bfe3f2eSlogwang /* set when the QID has been initialized */
1062bfe3f2eSlogwang uint8_t initialized;
1072bfe3f2eSlogwang /* The type of this QID */
1082bfe3f2eSlogwang int8_t type;
1092bfe3f2eSlogwang /* Integer ID representing the queue. This is used in history lists,
1102bfe3f2eSlogwang * to identify the stage of processing.
1112bfe3f2eSlogwang */
1122bfe3f2eSlogwang uint32_t id;
1132bfe3f2eSlogwang struct sw_point_stats stats;
1142bfe3f2eSlogwang
1152bfe3f2eSlogwang /* Internal priority rings for packets */
116d30ea906Sjfb8856606 struct sw_iq iq[SW_IQS_MAX];
1172bfe3f2eSlogwang uint32_t iq_pkt_mask; /* A mask to indicate packets in an IQ */
1182bfe3f2eSlogwang uint64_t iq_pkt_count[SW_IQS_MAX];
1192bfe3f2eSlogwang
1202bfe3f2eSlogwang /* Information on what CQs are polling this IQ */
1212bfe3f2eSlogwang uint32_t cq_num_mapped_cqs;
1222bfe3f2eSlogwang uint32_t cq_next_tx; /* cq to write next (non-atomic) packet */
1232bfe3f2eSlogwang uint32_t cq_map[SW_PORTS_MAX];
1242bfe3f2eSlogwang uint64_t to_port[SW_PORTS_MAX];
1252bfe3f2eSlogwang
1262bfe3f2eSlogwang /* Track flow ids for atomic load balancing */
1272bfe3f2eSlogwang struct sw_fid_t fids[SW_QID_NUM_FIDS];
1282bfe3f2eSlogwang
1292bfe3f2eSlogwang /* Track packet order for reordering when needed */
1302bfe3f2eSlogwang struct reorder_buffer_entry *reorder_buffer; /*< pkts await reorder */
131*2d9fd380Sjfb8856606 struct rob_ring *reorder_buffer_freelist; /* available reorder slots */
1322bfe3f2eSlogwang uint32_t reorder_buffer_index; /* oldest valid reorder buffer entry */
1332bfe3f2eSlogwang uint32_t window_size; /* Used to wrap reorder_buffer_index */
1342bfe3f2eSlogwang
1352bfe3f2eSlogwang uint8_t priority;
1362bfe3f2eSlogwang };
1372bfe3f2eSlogwang
1382bfe3f2eSlogwang struct sw_hist_list_entry {
1392bfe3f2eSlogwang int32_t qid;
1402bfe3f2eSlogwang int32_t fid;
1412bfe3f2eSlogwang struct reorder_buffer_entry *rob_entry;
1422bfe3f2eSlogwang };
1432bfe3f2eSlogwang
1442bfe3f2eSlogwang struct sw_evdev;
1452bfe3f2eSlogwang
1462bfe3f2eSlogwang struct sw_port {
1472bfe3f2eSlogwang /* new enqueue / dequeue API doesn't have an instance pointer, only the
1482bfe3f2eSlogwang * pointer to the port being enqueue/dequeued from
1492bfe3f2eSlogwang */
1502bfe3f2eSlogwang struct sw_evdev *sw;
1512bfe3f2eSlogwang
1522bfe3f2eSlogwang /* set when the port is initialized */
1532bfe3f2eSlogwang uint8_t initialized;
1542bfe3f2eSlogwang /* A numeric ID for the port */
1552bfe3f2eSlogwang uint8_t id;
1562bfe3f2eSlogwang
157d30ea906Sjfb8856606 /* An atomic counter for when the port has been unlinked, and the
158d30ea906Sjfb8856606 * scheduler has not yet acked this unlink - hence there may still be
159d30ea906Sjfb8856606 * events in the buffers going to the port. When the unlinks in
160d30ea906Sjfb8856606 * progress is read by the scheduler, no more events will be pushed to
161d30ea906Sjfb8856606 * the port - hence the scheduler core can just assign zero.
162d30ea906Sjfb8856606 */
163d30ea906Sjfb8856606 uint8_t unlinks_in_progress;
164d30ea906Sjfb8856606
1652bfe3f2eSlogwang int16_t is_directed; /** Takes from a single directed QID */
1662bfe3f2eSlogwang /**
1672bfe3f2eSlogwang * For loadbalanced we can optimise pulling packets from
1682bfe3f2eSlogwang * producers if there is no reordering involved
1692bfe3f2eSlogwang */
1702bfe3f2eSlogwang int16_t num_ordered_qids;
1712bfe3f2eSlogwang
1722bfe3f2eSlogwang /** Ring and buffer for pulling events from workers for scheduling */
1732bfe3f2eSlogwang struct rte_event_ring *rx_worker_ring __rte_cache_aligned;
1742bfe3f2eSlogwang /** Ring and buffer for pushing packets to workers after scheduling */
1752bfe3f2eSlogwang struct rte_event_ring *cq_worker_ring;
1762bfe3f2eSlogwang
1772bfe3f2eSlogwang /* hole */
1782bfe3f2eSlogwang
1792bfe3f2eSlogwang /* num releases yet to be completed on this port */
1802bfe3f2eSlogwang uint16_t outstanding_releases __rte_cache_aligned;
1812bfe3f2eSlogwang uint16_t inflight_max; /* app requested max inflights for this port */
1822bfe3f2eSlogwang uint16_t inflight_credits; /* num credits this port has right now */
183d30ea906Sjfb8856606 uint8_t implicit_release; /* release events before dequeueing */
1842bfe3f2eSlogwang
1852bfe3f2eSlogwang uint16_t last_dequeue_burst_sz; /* how big the burst was */
1862bfe3f2eSlogwang uint64_t last_dequeue_ticks; /* used to track burst processing time */
1872bfe3f2eSlogwang uint64_t avg_pkt_ticks; /* tracks average over NUM_SAMPLES burst */
1882bfe3f2eSlogwang uint64_t total_polls; /* how many polls were counted in stats */
1892bfe3f2eSlogwang uint64_t zero_polls; /* tracks polls returning nothing */
1902bfe3f2eSlogwang uint32_t poll_buckets[SW_NUM_POLL_BUCKETS];
1912bfe3f2eSlogwang /* bucket values in 4s for shorter reporting */
1922bfe3f2eSlogwang
1932bfe3f2eSlogwang /* History list structs, containing info on pkts egressed to worker */
1942bfe3f2eSlogwang uint16_t hist_head __rte_cache_aligned;
1952bfe3f2eSlogwang uint16_t hist_tail;
1962bfe3f2eSlogwang uint16_t inflights;
1972bfe3f2eSlogwang struct sw_hist_list_entry hist_list[SW_PORT_HIST_LIST];
1982bfe3f2eSlogwang
1992bfe3f2eSlogwang /* track packets in and out of this port */
2002bfe3f2eSlogwang struct sw_point_stats stats;
2012bfe3f2eSlogwang
2022bfe3f2eSlogwang
2032bfe3f2eSlogwang uint32_t pp_buf_start;
2042bfe3f2eSlogwang uint32_t pp_buf_count;
2052bfe3f2eSlogwang uint16_t cq_buf_count;
206*2d9fd380Sjfb8856606 struct rte_event pp_buf[SCHED_DEQUEUE_MAX_BURST_SIZE];
2072bfe3f2eSlogwang struct rte_event cq_buf[MAX_SW_CONS_Q_DEPTH];
2082bfe3f2eSlogwang
2092bfe3f2eSlogwang uint8_t num_qids_mapped;
2102bfe3f2eSlogwang };
2112bfe3f2eSlogwang
2122bfe3f2eSlogwang struct sw_evdev {
2132bfe3f2eSlogwang struct rte_eventdev_data *data;
2142bfe3f2eSlogwang
2152bfe3f2eSlogwang uint32_t port_count;
2162bfe3f2eSlogwang uint32_t qid_count;
2172bfe3f2eSlogwang uint32_t xstats_count;
2182bfe3f2eSlogwang struct sw_xstats_entry *xstats;
2192bfe3f2eSlogwang uint32_t xstats_count_mode_dev;
2202bfe3f2eSlogwang uint32_t xstats_count_mode_port;
2212bfe3f2eSlogwang uint32_t xstats_count_mode_queue;
2222bfe3f2eSlogwang
223*2d9fd380Sjfb8856606 /* Minimum burst size*/
224*2d9fd380Sjfb8856606 uint32_t sched_min_burst_size __rte_cache_aligned;
225*2d9fd380Sjfb8856606 /* Port dequeue burst size*/
226*2d9fd380Sjfb8856606 uint32_t sched_deq_burst_size;
227*2d9fd380Sjfb8856606 /* Refill pp buffers only once per scheduler call*/
228*2d9fd380Sjfb8856606 uint32_t refill_once_per_iter;
229*2d9fd380Sjfb8856606 /* Current values */
230*2d9fd380Sjfb8856606 uint32_t sched_flush_count;
231*2d9fd380Sjfb8856606 uint32_t sched_min_burst;
232*2d9fd380Sjfb8856606
2332bfe3f2eSlogwang /* Contains all ports - load balanced and directed */
2342bfe3f2eSlogwang struct sw_port ports[SW_PORTS_MAX] __rte_cache_aligned;
2352bfe3f2eSlogwang
2362bfe3f2eSlogwang rte_atomic32_t inflights __rte_cache_aligned;
2372bfe3f2eSlogwang
2382bfe3f2eSlogwang /*
2392bfe3f2eSlogwang * max events in this instance. Cached here for performance.
2402bfe3f2eSlogwang * (also available in data->conf.nb_events_limit)
2412bfe3f2eSlogwang */
2422bfe3f2eSlogwang uint32_t nb_events_limit;
2432bfe3f2eSlogwang
2442bfe3f2eSlogwang /* Internal queues - one per logical queue */
2452bfe3f2eSlogwang struct sw_qid qids[RTE_EVENT_MAX_QUEUES_PER_DEV] __rte_cache_aligned;
246d30ea906Sjfb8856606 struct sw_queue_chunk *chunk_list_head;
247d30ea906Sjfb8856606 struct sw_queue_chunk *chunks;
2482bfe3f2eSlogwang
2492bfe3f2eSlogwang /* Cache how many packets are in each cq */
2502bfe3f2eSlogwang uint16_t cq_ring_space[SW_PORTS_MAX] __rte_cache_aligned;
2512bfe3f2eSlogwang
2522bfe3f2eSlogwang /* Array of pointers to load-balanced QIDs sorted by priority level */
2532bfe3f2eSlogwang struct sw_qid *qids_prioritized[RTE_EVENT_MAX_QUEUES_PER_DEV];
2542bfe3f2eSlogwang
2552bfe3f2eSlogwang /* Stats */
2562bfe3f2eSlogwang struct sw_point_stats stats __rte_cache_aligned;
2572bfe3f2eSlogwang uint64_t sched_called;
2582bfe3f2eSlogwang int32_t sched_quanta;
2592bfe3f2eSlogwang uint64_t sched_no_iq_enqueues;
2602bfe3f2eSlogwang uint64_t sched_no_cq_enqueues;
2612bfe3f2eSlogwang uint64_t sched_cq_qid_called;
2622bfe3f2eSlogwang
2632bfe3f2eSlogwang uint8_t started;
2642bfe3f2eSlogwang uint32_t credit_update_quanta;
2652bfe3f2eSlogwang
2662bfe3f2eSlogwang /* store num stats and offset of the stats for each port */
2672bfe3f2eSlogwang uint16_t xstats_count_per_port[SW_PORTS_MAX];
2682bfe3f2eSlogwang uint16_t xstats_offset_for_port[SW_PORTS_MAX];
2692bfe3f2eSlogwang /* store num stats and offset of the stats for each queue */
2702bfe3f2eSlogwang uint16_t xstats_count_per_qid[RTE_EVENT_MAX_QUEUES_PER_DEV];
2712bfe3f2eSlogwang uint16_t xstats_offset_for_qid[RTE_EVENT_MAX_QUEUES_PER_DEV];
2722bfe3f2eSlogwang
2732bfe3f2eSlogwang uint32_t service_id;
2742bfe3f2eSlogwang char service_name[SW_PMD_NAME_MAX];
2752bfe3f2eSlogwang };
2762bfe3f2eSlogwang
2772bfe3f2eSlogwang static inline struct sw_evdev *
sw_pmd_priv(const struct rte_eventdev * eventdev)2782bfe3f2eSlogwang sw_pmd_priv(const struct rte_eventdev *eventdev)
2792bfe3f2eSlogwang {
2802bfe3f2eSlogwang return eventdev->data->dev_private;
2812bfe3f2eSlogwang }
2822bfe3f2eSlogwang
2832bfe3f2eSlogwang static inline const struct sw_evdev *
sw_pmd_priv_const(const struct rte_eventdev * eventdev)2842bfe3f2eSlogwang sw_pmd_priv_const(const struct rte_eventdev *eventdev)
2852bfe3f2eSlogwang {
2862bfe3f2eSlogwang return eventdev->data->dev_private;
2872bfe3f2eSlogwang }
2882bfe3f2eSlogwang
2892bfe3f2eSlogwang uint16_t sw_event_enqueue(void *port, const struct rte_event *ev);
2902bfe3f2eSlogwang uint16_t sw_event_enqueue_burst(void *port, const struct rte_event ev[],
2912bfe3f2eSlogwang uint16_t num);
2922bfe3f2eSlogwang
2932bfe3f2eSlogwang uint16_t sw_event_dequeue(void *port, struct rte_event *ev, uint64_t wait);
2942bfe3f2eSlogwang uint16_t sw_event_dequeue_burst(void *port, struct rte_event *ev, uint16_t num,
2952bfe3f2eSlogwang uint64_t wait);
2962bfe3f2eSlogwang void sw_event_schedule(struct rte_eventdev *dev);
2972bfe3f2eSlogwang int sw_xstats_init(struct sw_evdev *dev);
2982bfe3f2eSlogwang int sw_xstats_uninit(struct sw_evdev *dev);
2992bfe3f2eSlogwang int sw_xstats_get_names(const struct rte_eventdev *dev,
3002bfe3f2eSlogwang enum rte_event_dev_xstats_mode mode, uint8_t queue_port_id,
3012bfe3f2eSlogwang struct rte_event_dev_xstats_name *xstats_names,
3022bfe3f2eSlogwang unsigned int *ids, unsigned int size);
3032bfe3f2eSlogwang int sw_xstats_get(const struct rte_eventdev *dev,
3042bfe3f2eSlogwang enum rte_event_dev_xstats_mode mode, uint8_t queue_port_id,
3052bfe3f2eSlogwang const unsigned int ids[], uint64_t values[], unsigned int n);
3062bfe3f2eSlogwang uint64_t sw_xstats_get_by_name(const struct rte_eventdev *dev,
3072bfe3f2eSlogwang const char *name, unsigned int *id);
3082bfe3f2eSlogwang int sw_xstats_reset(struct rte_eventdev *dev,
3092bfe3f2eSlogwang enum rte_event_dev_xstats_mode mode,
3102bfe3f2eSlogwang int16_t queue_port_id,
3112bfe3f2eSlogwang const uint32_t ids[],
3122bfe3f2eSlogwang uint32_t nb_ids);
3132bfe3f2eSlogwang
314d30ea906Sjfb8856606 int test_sw_eventdev(void);
3152bfe3f2eSlogwang
3162bfe3f2eSlogwang #endif /* _SW_EVDEV_H_ */
317