1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
5 #ifndef __INCLUDE_RTE_SCHED_H__
6 #define __INCLUDE_RTE_SCHED_H__
14 * RTE Hierarchical Scheduler
16 * The hierarchical scheduler prioritizes the transmission of packets
17 * from different users and traffic classes according to the Service
18 * Level Agreements (SLAs) defined for the current network node.
20 * The scheduler supports thousands of packet queues grouped under a
23 * - Typical usage: output Ethernet port;
24 * - Multiple ports are scheduled in round robin order with
27 * - Typical usage: group of users;
28 * - Traffic shaping using the token bucket algorithm
29 * (one bucket per subport);
30 * - Upper limit enforced per traffic class at subport level;
31 * - Lower priority traffic classes able to reuse subport
32 * bandwidth currently unused by higher priority traffic
33 * classes of the same subport;
34 * - When any subport traffic class is oversubscribed
35 * (configuration time event), the usage of subport member
36 * pipes with high demand for that traffic class pipes is
37 * truncated to a dynamically adjusted value with no
38 * impact to low demand pipes;
40 * - Typical usage: individual user/subscriber;
41 * - Traffic shaping using the token bucket algorithm
42 * (one bucket per pipe);
44 * - Traffic classes of the same pipe handled in strict
46 * - Upper limit enforced per traffic class at the pipe level;
47 * - Lower priority traffic classes able to reuse pipe
48 * bandwidth currently unused by higher priority traffic
49 * classes of the same pipe;
51 * - Typical usage: queue hosting packets from one or
52 * multiple connections of same traffic class belonging to
54 * - Weighted Round Robin (WRR) is used to service the
55 * queues within same pipe traffic class.
59 #include <sys/types.h>
60 #include <rte_compat.h>
62 #include <rte_meter.h>
64 /** Random Early Detection (RED) */
69 /** Maximum number of queues per pipe.
70 * Note that the multiple queues (power of 2) can only be assigned to
71 * lowest priority (best-effort) traffic class. Other higher priority traffic
72 * classes can only have one queue.
75 * @see struct rte_sched_port_params
77 #define RTE_SCHED_QUEUES_PER_PIPE 16
79 /** Number of WRR queues for best-effort traffic class per pipe.
81 * @see struct rte_sched_pipe_params
83 #define RTE_SCHED_BE_QUEUES_PER_PIPE 4
85 /** Number of traffic classes per pipe (as well as subport).
88 #define RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE \
89 (RTE_SCHED_QUEUES_PER_PIPE - RTE_SCHED_BE_QUEUES_PER_PIPE + 1)
91 /** Best-effort traffic class ID
94 #define RTE_SCHED_TRAFFIC_CLASS_BE (RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE - 1)
96 /** Number of queues per pipe traffic class. Cannot be changed. */
97 #define RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS 4
100 /** Maximum number of pipe profiles that can be defined per port.
101 * Compile-time configurable.
103 #ifndef RTE_SCHED_PIPE_PROFILES_PER_PORT
104 #define RTE_SCHED_PIPE_PROFILES_PER_PORT 256
108 * Ethernet framing overhead. Overhead fields per Ethernet frame:
109 * 1. Preamble: 7 bytes;
110 * 2. Start of Frame Delimiter (SFD): 1 byte;
111 * 3. Frame Check Sequence (FCS): 4 bytes;
112 * 4. Inter Frame Gap (IFG): 12 bytes.
114 * The FCS is considered overhead only if not included in the packet
115 * length (field pkt_len of struct rte_mbuf).
117 #ifndef RTE_SCHED_FRAME_OVERHEAD_DEFAULT
118 #define RTE_SCHED_FRAME_OVERHEAD_DEFAULT 24
122 * Subport configuration parameters. The period and credits_per_period
123 * parameters are measured in bytes, with one byte meaning the time
124 * duration associated with the transmission of one byte on the
125 * physical medium of the output port, with pipe or pipe traffic class
126 * rate (measured as percentage of output port rate) determined as
127 * credits_per_period divided by period. One credit represents one
130 struct rte_sched_subport_params {
131 /* Subport token bucket */
132 uint32_t tb_rate; /**< Rate (measured in bytes per second) */
133 uint32_t tb_size; /**< Size (measured in credits) */
135 /* Subport traffic classes */
136 uint32_t tc_rate[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
137 /**< Traffic class rates (measured in bytes per second) */
139 /**< Enforcement period for rates (measured in milliseconds) */
142 /** Subport statistics */
143 struct rte_sched_subport_stats {
145 uint32_t n_pkts_tc[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
146 /**< Number of packets successfully written */
147 uint32_t n_pkts_tc_dropped[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
148 /**< Number of packets dropped */
151 uint32_t n_bytes_tc[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
152 /**< Number of bytes successfully written for each traffic class */
153 uint32_t n_bytes_tc_dropped[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
154 /**< Number of bytes dropped for each traffic class */
157 uint32_t n_pkts_red_dropped[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
158 /**< Number of packets dropped by red */
163 * Pipe configuration parameters. The period and credits_per_period
164 * parameters are measured in bytes, with one byte meaning the time
165 * duration associated with the transmission of one byte on the
166 * physical medium of the output port, with pipe or pipe traffic class
167 * rate (measured as percentage of output port rate) determined as
168 * credits_per_period divided by period. One credit represents one
171 struct rte_sched_pipe_params {
172 /* Pipe token bucket */
173 uint32_t tb_rate; /**< Rate (measured in bytes per second) */
174 uint32_t tb_size; /**< Size (measured in credits) */
176 /* Pipe traffic classes */
177 uint32_t tc_rate[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
178 /**< Traffic class rates (measured in bytes per second) */
180 /**< Enforcement period (measured in milliseconds) */
181 uint8_t tc_ov_weight; /**< Weight Traffic class 3 oversubscription */
184 uint8_t wrr_weights[RTE_SCHED_BE_QUEUES_PER_PIPE]; /**< WRR weights */
187 /** Queue statistics */
188 struct rte_sched_queue_stats {
190 uint32_t n_pkts; /**< Packets successfully written */
191 uint32_t n_pkts_dropped; /**< Packets dropped */
193 uint32_t n_pkts_red_dropped; /**< Packets dropped by RED */
197 uint32_t n_bytes; /**< Bytes successfully written */
198 uint32_t n_bytes_dropped; /**< Bytes dropped */
201 /** Port configuration parameters. */
202 struct rte_sched_port_params {
203 const char *name; /**< String to be associated */
204 int socket; /**< CPU socket ID */
205 uint32_t rate; /**< Output port rate
206 * (measured in bytes per second) */
207 uint32_t mtu; /**< Maximum Ethernet frame size
208 * (measured in bytes).
209 * Should not include the framing overhead. */
210 uint32_t frame_overhead; /**< Framing overhead per packet
211 * (measured in bytes) */
212 uint32_t n_subports_per_port; /**< Number of subports */
213 uint32_t n_pipes_per_subport; /**< Number of pipes per subport */
214 uint16_t qsize[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
215 /**< Packet queue size for each traffic class.
216 * All queues within the same pipe traffic class have the same
217 * size. Queues from different pipes serving the same traffic
218 * class have the same size. */
219 struct rte_sched_pipe_params *pipe_profiles;
220 /**< Pipe profile table.
221 * Every pipe is configured using one of the profiles from this table. */
222 uint32_t n_pipe_profiles; /**< Profiles in the pipe profile table */
223 uint32_t n_max_pipe_profiles;
224 /**< Max profiles allowed in the pipe profile table */
226 struct rte_red_params red_params[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE][RTE_COLORS]; /**< RED parameters */
236 * Hierarchical scheduler port configuration
239 * Port scheduler configuration parameter structure
241 * Handle to port scheduler instance upon success or NULL otherwise.
243 struct rte_sched_port *
244 rte_sched_port_config(struct rte_sched_port_params *params);
247 * Hierarchical scheduler port free
250 * Handle to port scheduler instance
253 rte_sched_port_free(struct rte_sched_port *port);
257 * @b EXPERIMENTAL: this API may change without prior notice.
259 * Hierarchical scheduler pipe profile add
262 * Handle to port scheduler instance
264 * Pipe profile parameters
265 * @param pipe_profile_id
266 * Set to valid profile id when profile is added successfully.
268 * 0 upon success, error code otherwise
272 rte_sched_port_pipe_profile_add(struct rte_sched_port *port,
273 struct rte_sched_pipe_params *params,
274 uint32_t *pipe_profile_id);
277 * Hierarchical scheduler subport configuration
280 * Handle to port scheduler instance
284 * Subport configuration parameters
286 * 0 upon success, error code otherwise
289 rte_sched_subport_config(struct rte_sched_port *port,
291 struct rte_sched_subport_params *params);
294 * Hierarchical scheduler pipe configuration
297 * Handle to port scheduler instance
301 * Pipe ID within subport
302 * @param pipe_profile
303 * ID of port-level pre-configured pipe profile
305 * 0 upon success, error code otherwise
308 rte_sched_pipe_config(struct rte_sched_port *port,
311 int32_t pipe_profile);
314 * Hierarchical scheduler memory footprint size per port
317 * Port scheduler configuration parameter structure
319 * Memory footprint size in bytes upon success, 0 otherwise
322 rte_sched_port_get_memory_footprint(struct rte_sched_port_params *params);
330 * Hierarchical scheduler subport statistics read
333 * Handle to port scheduler instance
337 * Pointer to pre-allocated subport statistics structure where the statistics
338 * counters should be stored
340 * Pointer to pre-allocated 4-entry array where the oversubscription status for
341 * each of the 4 subport traffic classes should be stored.
343 * 0 upon success, error code otherwise
346 rte_sched_subport_read_stats(struct rte_sched_port *port,
348 struct rte_sched_subport_stats *stats,
352 * Hierarchical scheduler queue statistics read
355 * Handle to port scheduler instance
357 * Queue ID within port scheduler
359 * Pointer to pre-allocated subport statistics structure where the statistics
360 * counters should be stored
362 * Pointer to pre-allocated variable where the current queue length
365 * 0 upon success, error code otherwise
368 rte_sched_queue_read_stats(struct rte_sched_port *port,
370 struct rte_sched_queue_stats *stats,
374 * Scheduler hierarchy path write to packet descriptor. Typically
375 * called by the packet classification stage.
378 * Handle to port scheduler instance
380 * Packet descriptor handle
384 * Pipe ID within subport
385 * @param traffic_class
386 * Traffic class ID within pipe (0 .. 3)
388 * Queue ID within pipe traffic class (0 .. 3)
393 rte_sched_port_pkt_write(struct rte_sched_port *port,
394 struct rte_mbuf *pkt,
395 uint32_t subport, uint32_t pipe, uint32_t traffic_class,
396 uint32_t queue, enum rte_color color);
399 * Scheduler hierarchy path read from packet descriptor (struct
400 * rte_mbuf). Typically called as part of the hierarchical scheduler
401 * enqueue operation. The subport, pipe, traffic class and queue
402 * parameters need to be pre-allocated by the caller.
405 * Handle to port scheduler instance
407 * Packet descriptor handle
411 * Pipe ID within subport
412 * @param traffic_class
413 * Traffic class ID within pipe (0 .. 3)
415 * Queue ID within pipe traffic class (0 .. 3)
419 rte_sched_port_pkt_read_tree_path(struct rte_sched_port *port,
420 const struct rte_mbuf *pkt,
421 uint32_t *subport, uint32_t *pipe,
422 uint32_t *traffic_class, uint32_t *queue);
425 rte_sched_port_pkt_read_color(const struct rte_mbuf *pkt);
428 * Hierarchical scheduler port enqueue. Writes up to n_pkts to port
429 * scheduler and returns the number of packets actually written. For
430 * each packet, the port scheduler queue to write the packet to is
431 * identified by reading the hierarchy path from the packet
432 * descriptor; if the queue is full or congested and the packet is not
433 * written to the queue, then the packet is automatically dropped
434 * without any action required from the caller.
437 * Handle to port scheduler instance
439 * Array storing the packet descriptor handles
441 * Number of packets to enqueue from the pkts array into the port scheduler
443 * Number of packets successfully enqueued
446 rte_sched_port_enqueue(struct rte_sched_port *port, struct rte_mbuf **pkts, uint32_t n_pkts);
449 * Hierarchical scheduler port dequeue. Reads up to n_pkts from the
450 * port scheduler and stores them in the pkts array and returns the
451 * number of packets actually read. The pkts array needs to be
452 * pre-allocated by the caller with at least n_pkts entries.
455 * Handle to port scheduler instance
457 * Pre-allocated packet descriptor array where the packets dequeued
459 * scheduler should be stored
461 * Number of packets to dequeue from the port scheduler
463 * Number of packets successfully dequeued and placed in the pkts array
466 rte_sched_port_dequeue(struct rte_sched_port *port, struct rte_mbuf **pkts, uint32_t n_pkts);
472 #endif /* __INCLUDE_RTE_SCHED_H__ */