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 lowest priority traffic class (best-effort).
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).
86 * @see struct rte_sched_subport_params
87 * @see struct rte_sched_pipe_params
89 #define RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE \
90 (RTE_SCHED_QUEUES_PER_PIPE - RTE_SCHED_BE_QUEUES_PER_PIPE + 1)
92 /** Best-effort traffic class ID
95 #define RTE_SCHED_TRAFFIC_CLASS_BE (RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE - 1)
97 /** Number of queues per pipe traffic class. Cannot be changed. */
98 #define RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS 4
101 /** Maximum number of pipe profiles that can be defined per port.
102 * Compile-time configurable.
104 #ifndef RTE_SCHED_PIPE_PROFILES_PER_PORT
105 #define RTE_SCHED_PIPE_PROFILES_PER_PORT 256
109 * Ethernet framing overhead. Overhead fields per Ethernet frame:
110 * 1. Preamble: 7 bytes;
111 * 2. Start of Frame Delimiter (SFD): 1 byte;
112 * 3. Frame Check Sequence (FCS): 4 bytes;
113 * 4. Inter Frame Gap (IFG): 12 bytes.
115 * The FCS is considered overhead only if not included in the packet
116 * length (field pkt_len of struct rte_mbuf).
118 * @see struct rte_sched_port_params
120 #ifndef RTE_SCHED_FRAME_OVERHEAD_DEFAULT
121 #define RTE_SCHED_FRAME_OVERHEAD_DEFAULT 24
125 * Subport configuration parameters. The period and credits_per_period
126 * parameters are measured in bytes, with one byte meaning the time
127 * duration associated with the transmission of one byte on the
128 * physical medium of the output port, with pipe or pipe traffic class
129 * rate (measured as percentage of output port rate) determined as
130 * credits_per_period divided by period. One credit represents one
133 struct rte_sched_subport_params {
134 /** Token bucket rate (measured in bytes per second) */
137 /** Token bucket size (measured in credits) */
140 /** Traffic class rates (measured in bytes per second) */
141 uint32_t tc_rate[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
143 /** Enforcement period for rates (measured in milliseconds) */
147 /** Subport statistics */
148 struct rte_sched_subport_stats {
149 /** Number of packets successfully written */
150 uint32_t n_pkts_tc[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
152 /** Number of packets dropped */
153 uint32_t n_pkts_tc_dropped[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
155 /** Number of bytes successfully written for each traffic class */
156 uint32_t n_bytes_tc[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
158 /** Number of bytes dropped for each traffic class */
159 uint32_t n_bytes_tc_dropped[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
162 /** Number of packets dropped by red */
163 uint32_t n_pkts_red_dropped[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
168 * Pipe configuration parameters. The period and credits_per_period
169 * parameters are measured in bytes, with one byte meaning the time
170 * duration associated with the transmission of one byte on the
171 * physical medium of the output port, with pipe or pipe traffic class
172 * rate (measured as percentage of output port rate) determined as
173 * credits_per_period divided by period. One credit represents one
176 struct rte_sched_pipe_params {
177 /** Token bucket rate (measured in bytes per second) */
180 /** Token bucket size (measured in credits) */
183 /** Traffic class rates (measured in bytes per second) */
184 uint32_t tc_rate[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
186 /** Enforcement period (measured in milliseconds) */
189 /** Best-effort traffic class oversubscription weight */
190 uint8_t tc_ov_weight;
192 /** WRR weights of best-effort traffic class queues */
193 uint8_t wrr_weights[RTE_SCHED_BE_QUEUES_PER_PIPE];
196 /** Queue statistics */
197 struct rte_sched_queue_stats {
198 /** Packets successfully written */
201 /** Packets dropped */
202 uint32_t n_pkts_dropped;
205 /** Packets dropped by RED */
206 uint32_t n_pkts_red_dropped;
209 /** Bytes successfully written */
213 uint32_t n_bytes_dropped;
216 /** Port configuration parameters. */
217 struct rte_sched_port_params {
218 /** Name of the port to be associated */
224 /** Output port rate (measured in bytes per second) */
227 /** Maximum Ethernet frame size (measured in bytes).
228 * Should not include the framing overhead.
232 /** Framing overhead per packet (measured in bytes) */
233 uint32_t frame_overhead;
235 /** Number of subports */
236 uint32_t n_subports_per_port;
238 /** Number of subport_pipes */
239 uint32_t n_pipes_per_subport;
241 /** Packet queue size for each traffic class.
242 * All the pipes within the same subport share the similar
243 * configuration for the queues.
245 uint16_t qsize[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
247 /** Pipe profile table.
248 * Every pipe is configured using one of the profiles from this table.
250 struct rte_sched_pipe_params *pipe_profiles;
252 /** Profiles in the pipe profile table */
253 uint32_t n_pipe_profiles;
255 /** Max profiles allowed in the pipe profile table */
256 uint32_t n_max_pipe_profiles;
259 /** RED parameters */
260 struct rte_red_params red_params[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE][RTE_COLORS];
270 * Hierarchical scheduler port configuration
273 * Port scheduler configuration parameter structure
275 * Handle to port scheduler instance upon success or NULL otherwise.
277 struct rte_sched_port *
278 rte_sched_port_config(struct rte_sched_port_params *params);
281 * Hierarchical scheduler port free
284 * Handle to port scheduler instance
287 rte_sched_port_free(struct rte_sched_port *port);
291 * @b EXPERIMENTAL: this API may change without prior notice.
293 * Hierarchical scheduler pipe profile add
296 * Handle to port scheduler instance
298 * Pipe profile parameters
299 * @param pipe_profile_id
300 * Set to valid profile id when profile is added successfully.
302 * 0 upon success, error code otherwise
306 rte_sched_port_pipe_profile_add(struct rte_sched_port *port,
307 struct rte_sched_pipe_params *params,
308 uint32_t *pipe_profile_id);
311 * Hierarchical scheduler subport configuration
314 * Handle to port scheduler instance
318 * Subport configuration parameters
320 * 0 upon success, error code otherwise
323 rte_sched_subport_config(struct rte_sched_port *port,
325 struct rte_sched_subport_params *params);
328 * Hierarchical scheduler pipe configuration
331 * Handle to port scheduler instance
335 * Pipe ID within subport
336 * @param pipe_profile
337 * ID of port-level pre-configured pipe profile
339 * 0 upon success, error code otherwise
342 rte_sched_pipe_config(struct rte_sched_port *port,
345 int32_t pipe_profile);
348 * Hierarchical scheduler memory footprint size per port
351 * Port scheduler configuration parameter structure
353 * Memory footprint size in bytes upon success, 0 otherwise
356 rte_sched_port_get_memory_footprint(struct rte_sched_port_params *params);
364 * Hierarchical scheduler subport statistics read
367 * Handle to port scheduler instance
371 * Pointer to pre-allocated subport statistics structure where the statistics
372 * counters should be stored
374 * Pointer to pre-allocated RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE-entry array
375 * where the oversubscription status for each of the subport traffic classes
378 * 0 upon success, error code otherwise
381 rte_sched_subport_read_stats(struct rte_sched_port *port,
383 struct rte_sched_subport_stats *stats,
387 * Hierarchical scheduler queue statistics read
390 * Handle to port scheduler instance
392 * Queue ID within port scheduler
394 * Pointer to pre-allocated subport statistics structure where the statistics
395 * counters should be stored
397 * Pointer to pre-allocated variable where the current queue length
400 * 0 upon success, error code otherwise
403 rte_sched_queue_read_stats(struct rte_sched_port *port,
405 struct rte_sched_queue_stats *stats,
409 * Scheduler hierarchy path write to packet descriptor. Typically
410 * called by the packet classification stage.
413 * Handle to port scheduler instance
415 * Packet descriptor handle
419 * Pipe ID within subport
420 * @param traffic_class
421 * Traffic class ID within pipe (0 .. RTE_SCHED_TRAFFIC_CLASS_BE)
423 * Queue ID within pipe traffic class, 0 for high priority TCs, and
424 * 0 .. (RTE_SCHED_BE_QUEUES_PER_PIPE - 1) for best-effort TC
429 rte_sched_port_pkt_write(struct rte_sched_port *port,
430 struct rte_mbuf *pkt,
431 uint32_t subport, uint32_t pipe, uint32_t traffic_class,
432 uint32_t queue, enum rte_color color);
435 * Scheduler hierarchy path read from packet descriptor (struct
436 * rte_mbuf). Typically called as part of the hierarchical scheduler
437 * enqueue operation. The subport, pipe, traffic class and queue
438 * parameters need to be pre-allocated by the caller.
441 * Handle to port scheduler instance
443 * Packet descriptor handle
447 * Pipe ID within subport
448 * @param traffic_class
449 * Traffic class ID within pipe (0 .. RTE_SCHED_TRAFFIC_CLASS_BE)
451 * Queue ID within pipe traffic class, 0 for high priority TCs, and
452 * 0 .. (RTE_SCHED_BE_QUEUES_PER_PIPE - 1) for best-effort TC
455 rte_sched_port_pkt_read_tree_path(struct rte_sched_port *port,
456 const struct rte_mbuf *pkt,
457 uint32_t *subport, uint32_t *pipe,
458 uint32_t *traffic_class, uint32_t *queue);
461 rte_sched_port_pkt_read_color(const struct rte_mbuf *pkt);
464 * Hierarchical scheduler port enqueue. Writes up to n_pkts to port
465 * scheduler and returns the number of packets actually written. For
466 * each packet, the port scheduler queue to write the packet to is
467 * identified by reading the hierarchy path from the packet
468 * descriptor; if the queue is full or congested and the packet is not
469 * written to the queue, then the packet is automatically dropped
470 * without any action required from the caller.
473 * Handle to port scheduler instance
475 * Array storing the packet descriptor handles
477 * Number of packets to enqueue from the pkts array into the port scheduler
479 * Number of packets successfully enqueued
482 rte_sched_port_enqueue(struct rte_sched_port *port, struct rte_mbuf **pkts, uint32_t n_pkts);
485 * Hierarchical scheduler port dequeue. Reads up to n_pkts from the
486 * port scheduler and stores them in the pkts array and returns the
487 * number of packets actually read. The pkts array needs to be
488 * pre-allocated by the caller with at least n_pkts entries.
491 * Handle to port scheduler instance
493 * Pre-allocated packet descriptor array where the packets dequeued
495 * scheduler should be stored
497 * Number of packets to dequeue from the port scheduler
499 * Number of packets successfully dequeued and placed in the pkts array
502 rte_sched_port_dequeue(struct rte_sched_port *port, struct rte_mbuf **pkts, uint32_t n_pkts);
508 #endif /* __INCLUDE_RTE_SCHED_H__ */