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