xref: /dpdk/lib/sched/rte_sched.h (revision 719834a6849e1daf4a70ff7742bbcc3ae7e25607)
199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson  * Copyright(c) 2010-2014 Intel Corporation
399a2dd95SBruce Richardson  */
499a2dd95SBruce Richardson 
599a2dd95SBruce Richardson #ifndef __INCLUDE_RTE_SCHED_H__
699a2dd95SBruce Richardson #define __INCLUDE_RTE_SCHED_H__
799a2dd95SBruce Richardson 
899a2dd95SBruce Richardson /**
999a2dd95SBruce Richardson  * @file
1099a2dd95SBruce Richardson  * RTE Hierarchical Scheduler
1199a2dd95SBruce Richardson  *
1299a2dd95SBruce Richardson  * The hierarchical scheduler prioritizes the transmission of packets
1399a2dd95SBruce Richardson  * from different users and traffic classes according to the Service
1499a2dd95SBruce Richardson  * Level Agreements (SLAs) defined for the current network node.
1599a2dd95SBruce Richardson  *
1699a2dd95SBruce Richardson  * The scheduler supports thousands of packet queues grouped under a
1799a2dd95SBruce Richardson  * 5-level hierarchy:
1899a2dd95SBruce Richardson  *     1. Port:
1999a2dd95SBruce Richardson  *           - Typical usage: output Ethernet port;
2099a2dd95SBruce Richardson  *           - Multiple ports are scheduled in round robin order with
2199a2dd95SBruce Richardson  *	    equal priority;
2299a2dd95SBruce Richardson  *     2. Subport:
2399a2dd95SBruce Richardson  *           - Typical usage: group of users;
2499a2dd95SBruce Richardson  *           - Traffic shaping using the token bucket algorithm
2599a2dd95SBruce Richardson  *	    (one bucket per subport);
2699a2dd95SBruce Richardson  *           - Upper limit enforced per traffic class at subport level;
2799a2dd95SBruce Richardson  *           - Lower priority traffic classes able to reuse subport
2899a2dd95SBruce Richardson  *	    bandwidth currently unused by higher priority traffic
2999a2dd95SBruce Richardson  *	    classes of the same subport;
3099a2dd95SBruce Richardson  *           - When any subport traffic class is oversubscribed
3199a2dd95SBruce Richardson  *	    (configuration time event), the usage of subport member
3299a2dd95SBruce Richardson  *	    pipes with high demand for that traffic class pipes is
3399a2dd95SBruce Richardson  *	    truncated to a dynamically adjusted value with no
3499a2dd95SBruce Richardson  *             impact to low demand pipes;
3599a2dd95SBruce Richardson  *     3. Pipe:
3699a2dd95SBruce Richardson  *           - Typical usage: individual user/subscriber;
3799a2dd95SBruce Richardson  *           - Traffic shaping using the token bucket algorithm
3899a2dd95SBruce Richardson  *	    (one bucket per pipe);
3999a2dd95SBruce Richardson  *     4. Traffic class:
4099a2dd95SBruce Richardson  *           - Traffic classes of the same pipe handled in strict
4199a2dd95SBruce Richardson  *	    priority order;
4299a2dd95SBruce Richardson  *           - Upper limit enforced per traffic class at the pipe level;
4399a2dd95SBruce Richardson  *           - Lower priority traffic classes able to reuse pipe
4499a2dd95SBruce Richardson  *	    bandwidth currently unused by higher priority traffic
4599a2dd95SBruce Richardson  *	    classes of the same pipe;
4699a2dd95SBruce Richardson  *     5. Queue:
4799a2dd95SBruce Richardson  *           - Typical usage: queue hosting packets from one or
4899a2dd95SBruce Richardson  *	    multiple connections of same traffic class belonging to
4999a2dd95SBruce Richardson  *	    the same user;
5099a2dd95SBruce Richardson  *           - Weighted Round Robin (WRR) is used to service the
5199a2dd95SBruce Richardson  *	    queues within same pipe lowest priority traffic class (best-effort).
5299a2dd95SBruce Richardson  */
5399a2dd95SBruce Richardson 
5499a2dd95SBruce Richardson #include <rte_mbuf.h>
5599a2dd95SBruce Richardson #include <rte_meter.h>
5699a2dd95SBruce Richardson 
5744c730b0SWojciech Liguzinski /** Congestion Management */
5899a2dd95SBruce Richardson #include "rte_red.h"
5944c730b0SWojciech Liguzinski #include "rte_pie.h"
6099a2dd95SBruce Richardson 
61*719834a6SMattias Rönnblom #ifdef __cplusplus
62*719834a6SMattias Rönnblom extern "C" {
63*719834a6SMattias Rönnblom #endif
64*719834a6SMattias Rönnblom 
6599a2dd95SBruce Richardson /** Maximum number of queues per pipe.
6699a2dd95SBruce Richardson  * Note that the multiple queues (power of 2) can only be assigned to
6799a2dd95SBruce Richardson  * lowest priority (best-effort) traffic class. Other higher priority traffic
6899a2dd95SBruce Richardson  * classes can only have one queue.
6999a2dd95SBruce Richardson  * Can not change.
7099a2dd95SBruce Richardson  *
7199a2dd95SBruce Richardson  * @see struct rte_sched_port_params
7299a2dd95SBruce Richardson  */
7399a2dd95SBruce Richardson #define RTE_SCHED_QUEUES_PER_PIPE    16
7499a2dd95SBruce Richardson 
7599a2dd95SBruce Richardson /** Number of WRR queues for best-effort traffic class per pipe.
7699a2dd95SBruce Richardson  *
7799a2dd95SBruce Richardson  * @see struct rte_sched_pipe_params
7899a2dd95SBruce Richardson  */
7999a2dd95SBruce Richardson #define RTE_SCHED_BE_QUEUES_PER_PIPE    4
8099a2dd95SBruce Richardson 
8199a2dd95SBruce Richardson /** Number of traffic classes per pipe (as well as subport).
8299a2dd95SBruce Richardson  * @see struct rte_sched_subport_params
8399a2dd95SBruce Richardson  * @see struct rte_sched_pipe_params
8499a2dd95SBruce Richardson  */
8599a2dd95SBruce Richardson #define RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE    \
8699a2dd95SBruce Richardson (RTE_SCHED_QUEUES_PER_PIPE - RTE_SCHED_BE_QUEUES_PER_PIPE + 1)
8799a2dd95SBruce Richardson 
8899a2dd95SBruce Richardson /** Best-effort traffic class ID
8999a2dd95SBruce Richardson  * Can not change.
9099a2dd95SBruce Richardson  */
9199a2dd95SBruce Richardson #define RTE_SCHED_TRAFFIC_CLASS_BE    (RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE - 1)
9299a2dd95SBruce Richardson 
9399a2dd95SBruce Richardson /*
9499a2dd95SBruce Richardson  * Ethernet framing overhead. Overhead fields per Ethernet frame:
9599a2dd95SBruce Richardson  * 1. Preamble:                             7 bytes;
9699a2dd95SBruce Richardson  * 2. Start of Frame Delimiter (SFD):       1 byte;
9799a2dd95SBruce Richardson  * 3. Frame Check Sequence (FCS):           4 bytes;
9899a2dd95SBruce Richardson  * 4. Inter Frame Gap (IFG):               12 bytes.
9999a2dd95SBruce Richardson  *
10099a2dd95SBruce Richardson  * The FCS is considered overhead only if not included in the packet
10199a2dd95SBruce Richardson  * length (field pkt_len of struct rte_mbuf).
10299a2dd95SBruce Richardson  *
10399a2dd95SBruce Richardson  * @see struct rte_sched_port_params
10499a2dd95SBruce Richardson  */
10599a2dd95SBruce Richardson #ifndef RTE_SCHED_FRAME_OVERHEAD_DEFAULT
10699a2dd95SBruce Richardson #define RTE_SCHED_FRAME_OVERHEAD_DEFAULT      24
10799a2dd95SBruce Richardson #endif
10899a2dd95SBruce Richardson 
10944c730b0SWojciech Liguzinski /**
11044c730b0SWojciech Liguzinski  * Congestion Management (CMAN) mode
11144c730b0SWojciech Liguzinski  *
11244c730b0SWojciech Liguzinski  * This is used for controlling the admission of packets into a packet queue or
11344c730b0SWojciech Liguzinski  * group of packet queues on congestion.
11444c730b0SWojciech Liguzinski  *
11544c730b0SWojciech Liguzinski  * The *Random Early Detection (RED)* algorithm works by proactively dropping
11644c730b0SWojciech Liguzinski  * more and more input packets as the queue occupancy builds up. When the queue
11744c730b0SWojciech Liguzinski  * is full or almost full, RED effectively works as *tail drop*. The *Weighted
11844c730b0SWojciech Liguzinski  * RED* algorithm uses a separate set of RED thresholds for each packet color.
11944c730b0SWojciech Liguzinski  *
12044c730b0SWojciech Liguzinski  * Similar to RED, Proportional Integral Controller Enhanced (PIE) randomly
12144c730b0SWojciech Liguzinski  * drops a packet at the onset of the congestion and tries to control the
12244c730b0SWojciech Liguzinski  * latency around the target value. The congestion detection, however, is based
12344c730b0SWojciech Liguzinski  * on the queueing latency instead of the queue length like RED. For more
12444c730b0SWojciech Liguzinski  * information, refer RFC8033.
12544c730b0SWojciech Liguzinski  */
12644c730b0SWojciech Liguzinski enum rte_sched_cman_mode {
12744c730b0SWojciech Liguzinski 	RTE_SCHED_CMAN_RED, /**< Random Early Detection (RED) */
12844c730b0SWojciech Liguzinski 	RTE_SCHED_CMAN_PIE, /**< Proportional Integral Controller Enhanced (PIE) */
12944c730b0SWojciech Liguzinski };
13044c730b0SWojciech Liguzinski 
13199a2dd95SBruce Richardson /*
13299a2dd95SBruce Richardson  * Pipe configuration parameters. The period and credits_per_period
13399a2dd95SBruce Richardson  * parameters are measured in bytes, with one byte meaning the time
13499a2dd95SBruce Richardson  * duration associated with the transmission of one byte on the
13599a2dd95SBruce Richardson  * physical medium of the output port, with pipe or pipe traffic class
13699a2dd95SBruce Richardson  * rate (measured as percentage of output port rate) determined as
13799a2dd95SBruce Richardson  * credits_per_period divided by period. One credit represents one
13899a2dd95SBruce Richardson  * byte.
13999a2dd95SBruce Richardson  */
14099a2dd95SBruce Richardson struct rte_sched_pipe_params {
14199a2dd95SBruce Richardson 	/** Token bucket rate (measured in bytes per second) */
14299a2dd95SBruce Richardson 	uint64_t tb_rate;
14399a2dd95SBruce Richardson 
14499a2dd95SBruce Richardson 	/** Token bucket size (measured in credits) */
14599a2dd95SBruce Richardson 	uint64_t tb_size;
14699a2dd95SBruce Richardson 
14799a2dd95SBruce Richardson 	/** Traffic class rates (measured in bytes per second) */
14899a2dd95SBruce Richardson 	uint64_t tc_rate[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
14999a2dd95SBruce Richardson 
15099a2dd95SBruce Richardson 	/** Enforcement period (measured in milliseconds) */
15199a2dd95SBruce Richardson 	uint64_t tc_period;
15299a2dd95SBruce Richardson 
15399a2dd95SBruce Richardson 	/** Best-effort traffic class oversubscription weight */
15499a2dd95SBruce Richardson 	uint8_t tc_ov_weight;
15599a2dd95SBruce Richardson 
15699a2dd95SBruce Richardson 	/** WRR weights of best-effort traffic class queues */
15799a2dd95SBruce Richardson 	uint8_t wrr_weights[RTE_SCHED_BE_QUEUES_PER_PIPE];
15899a2dd95SBruce Richardson };
15999a2dd95SBruce Richardson 
16099a2dd95SBruce Richardson /*
16144c730b0SWojciech Liguzinski  * Congestion Management configuration parameters.
16244c730b0SWojciech Liguzinski  */
16344c730b0SWojciech Liguzinski struct rte_sched_cman_params {
16444c730b0SWojciech Liguzinski 	/** Congestion Management mode */
16544c730b0SWojciech Liguzinski 	enum rte_sched_cman_mode cman_mode;
16644c730b0SWojciech Liguzinski 
16744c730b0SWojciech Liguzinski 	union {
16844c730b0SWojciech Liguzinski 		/** RED parameters */
16944c730b0SWojciech Liguzinski 		struct rte_red_params red_params[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE][RTE_COLORS];
17044c730b0SWojciech Liguzinski 
17144c730b0SWojciech Liguzinski 		/** PIE parameters */
17244c730b0SWojciech Liguzinski 		struct rte_pie_params pie_params[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
17344c730b0SWojciech Liguzinski 	};
17444c730b0SWojciech Liguzinski };
17544c730b0SWojciech Liguzinski 
17644c730b0SWojciech Liguzinski /*
17799a2dd95SBruce Richardson  * Subport configuration parameters. The period and credits_per_period
17899a2dd95SBruce Richardson  * parameters are measured in bytes, with one byte meaning the time
17999a2dd95SBruce Richardson  * duration associated with the transmission of one byte on the
18099a2dd95SBruce Richardson  * physical medium of the output port, with pipe or pipe traffic class
18199a2dd95SBruce Richardson  * rate (measured as percentage of output port rate) determined as
18299a2dd95SBruce Richardson  * credits_per_period divided by period. One credit represents one
18399a2dd95SBruce Richardson  * byte.
18499a2dd95SBruce Richardson  */
18599a2dd95SBruce Richardson struct rte_sched_subport_params {
18699a2dd95SBruce Richardson 	/** Number of subport pipes.
18799a2dd95SBruce Richardson 	 * The subport can enable/allocate fewer pipes than the maximum
18899a2dd95SBruce Richardson 	 * number set through struct port_params::n_max_pipes_per_subport,
18999a2dd95SBruce Richardson 	 * as needed, to avoid memory allocation for the queues of the
19099a2dd95SBruce Richardson 	 * pipes that are not really needed.
19199a2dd95SBruce Richardson 	 */
19299a2dd95SBruce Richardson 	uint32_t n_pipes_per_subport_enabled;
19399a2dd95SBruce Richardson 
19499a2dd95SBruce Richardson 	/** Packet queue size for each traffic class.
19599a2dd95SBruce Richardson 	 * All the pipes within the same subport share the similar
19699a2dd95SBruce Richardson 	 * configuration for the queues.
19799a2dd95SBruce Richardson 	 */
19899a2dd95SBruce Richardson 	uint16_t qsize[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
19999a2dd95SBruce Richardson 
20099a2dd95SBruce Richardson 	/** Pipe profile table.
20199a2dd95SBruce Richardson 	 * Every pipe is configured using one of the profiles from this table.
20299a2dd95SBruce Richardson 	 */
20399a2dd95SBruce Richardson 	struct rte_sched_pipe_params *pipe_profiles;
20499a2dd95SBruce Richardson 
20599a2dd95SBruce Richardson 	/** Profiles in the pipe profile table */
20699a2dd95SBruce Richardson 	uint32_t n_pipe_profiles;
20799a2dd95SBruce Richardson 
20899a2dd95SBruce Richardson 	/** Max allowed profiles in the pipe profile table */
20999a2dd95SBruce Richardson 	uint32_t n_max_pipe_profiles;
21099a2dd95SBruce Richardson 
21144c730b0SWojciech Liguzinski 	/** Congestion Management parameters
21244c730b0SWojciech Liguzinski 	 * If NULL the congestion management is disabled for the subport,
21344c730b0SWojciech Liguzinski 	 * otherwise proper parameters need to be provided.
21444c730b0SWojciech Liguzinski 	 */
21544c730b0SWojciech Liguzinski 	struct rte_sched_cman_params *cman_params;
21699a2dd95SBruce Richardson };
21799a2dd95SBruce Richardson 
21899a2dd95SBruce Richardson struct rte_sched_subport_profile_params {
21999a2dd95SBruce Richardson 	/** Token bucket rate (measured in bytes per second) */
22099a2dd95SBruce Richardson 	uint64_t tb_rate;
22199a2dd95SBruce Richardson 
22299a2dd95SBruce Richardson 	/** Token bucket size (measured in credits) */
22399a2dd95SBruce Richardson 	uint64_t tb_size;
22499a2dd95SBruce Richardson 
22599a2dd95SBruce Richardson 	/** Traffic class rates (measured in bytes per second) */
22699a2dd95SBruce Richardson 	uint64_t tc_rate[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
22799a2dd95SBruce Richardson 
22899a2dd95SBruce Richardson 	/** Enforcement period for rates (measured in milliseconds) */
22999a2dd95SBruce Richardson 	uint64_t tc_period;
23099a2dd95SBruce Richardson };
23199a2dd95SBruce Richardson 
23299a2dd95SBruce Richardson /** Subport statistics */
23399a2dd95SBruce Richardson struct rte_sched_subport_stats {
23499a2dd95SBruce Richardson 	/** Number of packets successfully written */
23599a2dd95SBruce Richardson 	uint64_t n_pkts_tc[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
23699a2dd95SBruce Richardson 
23799a2dd95SBruce Richardson 	/** Number of packets dropped */
23899a2dd95SBruce Richardson 	uint64_t n_pkts_tc_dropped[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
23999a2dd95SBruce Richardson 
24099a2dd95SBruce Richardson 	/** Number of bytes successfully written for each traffic class */
24199a2dd95SBruce Richardson 	uint64_t n_bytes_tc[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
24299a2dd95SBruce Richardson 
24399a2dd95SBruce Richardson 	/** Number of bytes dropped for each traffic class */
24499a2dd95SBruce Richardson 	uint64_t n_bytes_tc_dropped[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
24599a2dd95SBruce Richardson 
24644c730b0SWojciech Liguzinski 	/** Number of packets dropped by congestion management scheme */
24744c730b0SWojciech Liguzinski 	uint64_t n_pkts_cman_dropped[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
24899a2dd95SBruce Richardson };
24999a2dd95SBruce Richardson 
25099a2dd95SBruce Richardson /** Queue statistics */
25199a2dd95SBruce Richardson struct rte_sched_queue_stats {
25299a2dd95SBruce Richardson 	/** Packets successfully written */
25399a2dd95SBruce Richardson 	uint64_t n_pkts;
25499a2dd95SBruce Richardson 
25599a2dd95SBruce Richardson 	/** Packets dropped */
25699a2dd95SBruce Richardson 	uint64_t n_pkts_dropped;
25799a2dd95SBruce Richardson 
25844c730b0SWojciech Liguzinski 	/** Packets dropped by congestion management scheme */
25944c730b0SWojciech Liguzinski 	uint64_t n_pkts_cman_dropped;
26099a2dd95SBruce Richardson 
26199a2dd95SBruce Richardson 	/** Bytes successfully written */
26299a2dd95SBruce Richardson 	uint64_t n_bytes;
26399a2dd95SBruce Richardson 
26499a2dd95SBruce Richardson 	/** Bytes dropped */
26599a2dd95SBruce Richardson 	uint64_t n_bytes_dropped;
26699a2dd95SBruce Richardson };
26799a2dd95SBruce Richardson 
26899a2dd95SBruce Richardson /** Port configuration parameters. */
26999a2dd95SBruce Richardson struct rte_sched_port_params {
27099a2dd95SBruce Richardson 	/** Name of the port to be associated */
27199a2dd95SBruce Richardson 	const char *name;
27299a2dd95SBruce Richardson 
27399a2dd95SBruce Richardson 	/** CPU socket ID */
27499a2dd95SBruce Richardson 	int socket;
27599a2dd95SBruce Richardson 
27699a2dd95SBruce Richardson 	/** Output port rate (measured in bytes per second) */
27799a2dd95SBruce Richardson 	uint64_t rate;
27899a2dd95SBruce Richardson 
27999a2dd95SBruce Richardson 	/** Maximum Ethernet frame size (measured in bytes).
28099a2dd95SBruce Richardson 	 * Should not include the framing overhead.
28199a2dd95SBruce Richardson 	 */
28299a2dd95SBruce Richardson 	uint32_t mtu;
28399a2dd95SBruce Richardson 
28499a2dd95SBruce Richardson 	/** Framing overhead per packet (measured in bytes) */
28599a2dd95SBruce Richardson 	uint32_t frame_overhead;
28699a2dd95SBruce Richardson 
28799a2dd95SBruce Richardson 	/** Number of subports */
28899a2dd95SBruce Richardson 	uint32_t n_subports_per_port;
28999a2dd95SBruce Richardson 
29099a2dd95SBruce Richardson 	/** subport profile table.
29199a2dd95SBruce Richardson 	 * Every pipe is configured using one of the profiles from this table.
29299a2dd95SBruce Richardson 	 */
29399a2dd95SBruce Richardson 	struct rte_sched_subport_profile_params *subport_profiles;
29499a2dd95SBruce Richardson 
29599a2dd95SBruce Richardson 	/** Profiles in the pipe profile table */
29699a2dd95SBruce Richardson 	uint32_t n_subport_profiles;
29799a2dd95SBruce Richardson 
29899a2dd95SBruce Richardson 	/** Max allowed profiles in the pipe profile table */
29999a2dd95SBruce Richardson 	uint32_t n_max_subport_profiles;
30099a2dd95SBruce Richardson 
30199a2dd95SBruce Richardson 	/** Maximum number of subport pipes.
30299a2dd95SBruce Richardson 	 * This parameter is used to reserve a fixed number of bits
30399a2dd95SBruce Richardson 	 * in struct rte_mbuf::sched.queue_id for the pipe_id for all
30499a2dd95SBruce Richardson 	 * the subports of the same port.
30599a2dd95SBruce Richardson 	 */
30699a2dd95SBruce Richardson 	uint32_t n_pipes_per_subport;
30799a2dd95SBruce Richardson };
30899a2dd95SBruce Richardson 
30999a2dd95SBruce Richardson /*
31099a2dd95SBruce Richardson  * Configuration
3113e4c5be9SThomas Monjalon  */
31299a2dd95SBruce Richardson 
31399a2dd95SBruce Richardson /**
31499a2dd95SBruce Richardson  * Hierarchical scheduler port configuration
31599a2dd95SBruce Richardson  *
31699a2dd95SBruce Richardson  * @param params
31799a2dd95SBruce Richardson  *   Port scheduler configuration parameter structure
31899a2dd95SBruce Richardson  * @return
31999a2dd95SBruce Richardson  *   Handle to port scheduler instance upon success or NULL otherwise.
32099a2dd95SBruce Richardson  */
32199a2dd95SBruce Richardson struct rte_sched_port *
32299a2dd95SBruce Richardson rte_sched_port_config(struct rte_sched_port_params *params);
32399a2dd95SBruce Richardson 
32499a2dd95SBruce Richardson /**
32599a2dd95SBruce Richardson  * Hierarchical scheduler port free
32699a2dd95SBruce Richardson  *
32799a2dd95SBruce Richardson  * @param port
328448e01f1SStephen Hemminger  *   Handle to port scheduler instance.
329448e01f1SStephen Hemminger  *   If port is NULL, no operation is performed.
33099a2dd95SBruce Richardson  */
33199a2dd95SBruce Richardson void
33299a2dd95SBruce Richardson rte_sched_port_free(struct rte_sched_port *port);
33399a2dd95SBruce Richardson 
33499a2dd95SBruce Richardson /**
33599a2dd95SBruce Richardson  * Hierarchical scheduler pipe profile add
33699a2dd95SBruce Richardson  *
33799a2dd95SBruce Richardson  * @param port
33899a2dd95SBruce Richardson  *   Handle to port scheduler instance
33999a2dd95SBruce Richardson  * @param subport_id
34099a2dd95SBruce Richardson  *   Subport ID
34199a2dd95SBruce Richardson  * @param params
34299a2dd95SBruce Richardson  *   Pipe profile parameters
34399a2dd95SBruce Richardson  * @param pipe_profile_id
34499a2dd95SBruce Richardson  *   Set to valid profile id when profile is added successfully.
34599a2dd95SBruce Richardson  * @return
34699a2dd95SBruce Richardson  *   0 upon success, error code otherwise
34799a2dd95SBruce Richardson  */
34899a2dd95SBruce Richardson int
34999a2dd95SBruce Richardson rte_sched_subport_pipe_profile_add(struct rte_sched_port *port,
35099a2dd95SBruce Richardson 	uint32_t subport_id,
35199a2dd95SBruce Richardson 	struct rte_sched_pipe_params *params,
35299a2dd95SBruce Richardson 	uint32_t *pipe_profile_id);
35399a2dd95SBruce Richardson 
35499a2dd95SBruce Richardson /**
35599a2dd95SBruce Richardson  * Hierarchical scheduler subport bandwidth profile add
35699a2dd95SBruce Richardson  * Note that this function is safe to use in runtime for adding new
3577be78d02SJosh Soref  * subport bandwidth profile as it doesn't have any impact on hierarchical
35899a2dd95SBruce Richardson  * structure of the scheduler.
35999a2dd95SBruce Richardson  * @param port
36099a2dd95SBruce Richardson  *   Handle to port scheduler instance
36199a2dd95SBruce Richardson  * @param profile
36299a2dd95SBruce Richardson  *   Subport bandwidth profile
36399a2dd95SBruce Richardson  * @param subport_profile_id
36499a2dd95SBruce Richardson  *   Subport profile id
36599a2dd95SBruce Richardson  * @return
36699a2dd95SBruce Richardson  *   0 upon success, error code otherwise
36799a2dd95SBruce Richardson  */
36899a2dd95SBruce Richardson int
36999a2dd95SBruce Richardson rte_sched_port_subport_profile_add(struct rte_sched_port *port,
37099a2dd95SBruce Richardson 	struct rte_sched_subport_profile_params *profile,
37199a2dd95SBruce Richardson 	uint32_t *subport_profile_id);
37299a2dd95SBruce Richardson 
37399a2dd95SBruce Richardson /**
37499a2dd95SBruce Richardson  * Hierarchical scheduler subport configuration
37599a2dd95SBruce Richardson  * Note that this function is safe to use at runtime
37699a2dd95SBruce Richardson  * to configure subport bandwidth profile.
37799a2dd95SBruce Richardson  * @param port
37899a2dd95SBruce Richardson  *   Handle to port scheduler instance
37999a2dd95SBruce Richardson  * @param subport_id
38099a2dd95SBruce Richardson  *   Subport ID
38199a2dd95SBruce Richardson  * @param params
38299a2dd95SBruce Richardson  *   Subport configuration parameters. Must be non-NULL
38399a2dd95SBruce Richardson  *   for first invocation (i.e initialization) for a given
38499a2dd95SBruce Richardson  *   subport. Ignored (recommended value is NULL) for all
38599a2dd95SBruce Richardson  *   subsequent invocation on the same subport.
38699a2dd95SBruce Richardson  * @param subport_profile_id
38799a2dd95SBruce Richardson  *   ID of subport bandwidth profile
38899a2dd95SBruce Richardson  * @return
38999a2dd95SBruce Richardson  *   0 upon success, error code otherwise
39099a2dd95SBruce Richardson  */
39199a2dd95SBruce Richardson int
39299a2dd95SBruce Richardson rte_sched_subport_config(struct rte_sched_port *port,
39399a2dd95SBruce Richardson 	uint32_t subport_id,
39499a2dd95SBruce Richardson 	struct rte_sched_subport_params *params,
39599a2dd95SBruce Richardson 	uint32_t subport_profile_id);
39699a2dd95SBruce Richardson 
39799a2dd95SBruce Richardson /**
39899a2dd95SBruce Richardson  * Hierarchical scheduler pipe configuration
39999a2dd95SBruce Richardson  *
40099a2dd95SBruce Richardson  * @param port
40199a2dd95SBruce Richardson  *   Handle to port scheduler instance
40299a2dd95SBruce Richardson  * @param subport_id
40399a2dd95SBruce Richardson  *   Subport ID
40499a2dd95SBruce Richardson  * @param pipe_id
40599a2dd95SBruce Richardson  *   Pipe ID within subport
40699a2dd95SBruce Richardson  * @param pipe_profile
40799a2dd95SBruce Richardson  *   ID of subport-level pre-configured pipe profile
40899a2dd95SBruce Richardson  * @return
40999a2dd95SBruce Richardson  *   0 upon success, error code otherwise
41099a2dd95SBruce Richardson  */
41199a2dd95SBruce Richardson int
41299a2dd95SBruce Richardson rte_sched_pipe_config(struct rte_sched_port *port,
41399a2dd95SBruce Richardson 	uint32_t subport_id,
41499a2dd95SBruce Richardson 	uint32_t pipe_id,
41599a2dd95SBruce Richardson 	int32_t pipe_profile);
41699a2dd95SBruce Richardson 
41799a2dd95SBruce Richardson /**
41899a2dd95SBruce Richardson  * Hierarchical scheduler memory footprint size per port
41999a2dd95SBruce Richardson  *
42099a2dd95SBruce Richardson  * @param port_params
42199a2dd95SBruce Richardson  *   Port scheduler configuration parameter structure
42299a2dd95SBruce Richardson  * @param subport_params
42399a2dd95SBruce Richardson  *   Array of subport parameter structures
42499a2dd95SBruce Richardson  * @return
42599a2dd95SBruce Richardson  *   Memory footprint size in bytes upon success, 0 otherwise
42699a2dd95SBruce Richardson  */
42799a2dd95SBruce Richardson uint32_t
42899a2dd95SBruce Richardson rte_sched_port_get_memory_footprint(struct rte_sched_port_params *port_params,
42999a2dd95SBruce Richardson 	struct rte_sched_subport_params **subport_params);
4303e4c5be9SThomas Monjalon 
43199a2dd95SBruce Richardson /*
43299a2dd95SBruce Richardson  * Statistics
4333e4c5be9SThomas Monjalon  */
43499a2dd95SBruce Richardson 
43599a2dd95SBruce Richardson /**
43699a2dd95SBruce Richardson  * Hierarchical scheduler subport statistics read
43799a2dd95SBruce Richardson  *
43899a2dd95SBruce Richardson  * @param port
43999a2dd95SBruce Richardson  *   Handle to port scheduler instance
44099a2dd95SBruce Richardson  * @param subport_id
44199a2dd95SBruce Richardson  *   Subport ID
44299a2dd95SBruce Richardson  * @param stats
44399a2dd95SBruce Richardson  *   Pointer to pre-allocated subport statistics structure where the statistics
44499a2dd95SBruce Richardson  *   counters should be stored
44599a2dd95SBruce Richardson  * @param tc_ov
44699a2dd95SBruce Richardson  *   Pointer to pre-allocated RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE-entry array
44799a2dd95SBruce Richardson  *   where the oversubscription status for each of the subport traffic classes
44899a2dd95SBruce Richardson  *   should be stored.
44999a2dd95SBruce Richardson  * @return
45099a2dd95SBruce Richardson  *   0 upon success, error code otherwise
45199a2dd95SBruce Richardson  */
45299a2dd95SBruce Richardson int
45399a2dd95SBruce Richardson rte_sched_subport_read_stats(struct rte_sched_port *port,
45499a2dd95SBruce Richardson 	uint32_t subport_id,
45599a2dd95SBruce Richardson 	struct rte_sched_subport_stats *stats,
45699a2dd95SBruce Richardson 	uint32_t *tc_ov);
45799a2dd95SBruce Richardson 
45899a2dd95SBruce Richardson /**
45999a2dd95SBruce Richardson  * Hierarchical scheduler queue statistics read
46099a2dd95SBruce Richardson  *
46199a2dd95SBruce Richardson  * @param port
46299a2dd95SBruce Richardson  *   Handle to port scheduler instance
46399a2dd95SBruce Richardson  * @param queue_id
46499a2dd95SBruce Richardson  *   Queue ID within port scheduler
46599a2dd95SBruce Richardson  * @param stats
46699a2dd95SBruce Richardson  *   Pointer to pre-allocated subport statistics structure where the statistics
46799a2dd95SBruce Richardson  *   counters should be stored
46899a2dd95SBruce Richardson  * @param qlen
46999a2dd95SBruce Richardson  *   Pointer to pre-allocated variable where the current queue length
47099a2dd95SBruce Richardson  *   should be stored.
47199a2dd95SBruce Richardson  * @return
47299a2dd95SBruce Richardson  *   0 upon success, error code otherwise
47399a2dd95SBruce Richardson  */
47499a2dd95SBruce Richardson int
47599a2dd95SBruce Richardson rte_sched_queue_read_stats(struct rte_sched_port *port,
47699a2dd95SBruce Richardson 	uint32_t queue_id,
47799a2dd95SBruce Richardson 	struct rte_sched_queue_stats *stats,
47899a2dd95SBruce Richardson 	uint16_t *qlen);
47999a2dd95SBruce Richardson 
48099a2dd95SBruce Richardson /**
48199a2dd95SBruce Richardson  * Scheduler hierarchy path write to packet descriptor. Typically
48299a2dd95SBruce Richardson  * called by the packet classification stage.
48399a2dd95SBruce Richardson  *
48499a2dd95SBruce Richardson  * @param port
48599a2dd95SBruce Richardson  *   Handle to port scheduler instance
48699a2dd95SBruce Richardson  * @param pkt
48799a2dd95SBruce Richardson  *   Packet descriptor handle
48899a2dd95SBruce Richardson  * @param subport
48999a2dd95SBruce Richardson  *   Subport ID
49099a2dd95SBruce Richardson  * @param pipe
49199a2dd95SBruce Richardson  *   Pipe ID within subport
49299a2dd95SBruce Richardson  * @param traffic_class
49399a2dd95SBruce Richardson  *   Traffic class ID within pipe (0 .. RTE_SCHED_TRAFFIC_CLASS_BE)
49499a2dd95SBruce Richardson  * @param queue
49599a2dd95SBruce Richardson  *   Queue ID within pipe traffic class, 0 for high priority TCs, and
49699a2dd95SBruce Richardson  *   0 .. (RTE_SCHED_BE_QUEUES_PER_PIPE - 1) for best-effort TC
49799a2dd95SBruce Richardson  * @param color
49899a2dd95SBruce Richardson  *   Packet color set
49999a2dd95SBruce Richardson  */
50099a2dd95SBruce Richardson void
50199a2dd95SBruce Richardson rte_sched_port_pkt_write(struct rte_sched_port *port,
50299a2dd95SBruce Richardson 			 struct rte_mbuf *pkt,
50399a2dd95SBruce Richardson 			 uint32_t subport, uint32_t pipe, uint32_t traffic_class,
50499a2dd95SBruce Richardson 			 uint32_t queue, enum rte_color color);
50599a2dd95SBruce Richardson 
50699a2dd95SBruce Richardson /**
50799a2dd95SBruce Richardson  * Scheduler hierarchy path read from packet descriptor (struct
50899a2dd95SBruce Richardson  * rte_mbuf). Typically called as part of the hierarchical scheduler
50999a2dd95SBruce Richardson  * enqueue operation. The subport, pipe, traffic class and queue
51099a2dd95SBruce Richardson  * parameters need to be pre-allocated by the caller.
51199a2dd95SBruce Richardson  *
51299a2dd95SBruce Richardson  * @param port
51399a2dd95SBruce Richardson  *   Handle to port scheduler instance
51499a2dd95SBruce Richardson  * @param pkt
51599a2dd95SBruce Richardson  *   Packet descriptor handle
51699a2dd95SBruce Richardson  * @param subport
51799a2dd95SBruce Richardson  *   Subport ID
51899a2dd95SBruce Richardson  * @param pipe
51999a2dd95SBruce Richardson  *   Pipe ID within subport
52099a2dd95SBruce Richardson  * @param traffic_class
52199a2dd95SBruce Richardson  *   Traffic class ID within pipe (0 .. RTE_SCHED_TRAFFIC_CLASS_BE)
52299a2dd95SBruce Richardson  * @param queue
52399a2dd95SBruce Richardson  *   Queue ID within pipe traffic class, 0 for high priority TCs, and
52499a2dd95SBruce Richardson  *   0 .. (RTE_SCHED_BE_QUEUES_PER_PIPE - 1) for best-effort TC
52599a2dd95SBruce Richardson  */
52699a2dd95SBruce Richardson void
52799a2dd95SBruce Richardson rte_sched_port_pkt_read_tree_path(struct rte_sched_port *port,
52899a2dd95SBruce Richardson 				  const struct rte_mbuf *pkt,
52999a2dd95SBruce Richardson 				  uint32_t *subport, uint32_t *pipe,
53099a2dd95SBruce Richardson 				  uint32_t *traffic_class, uint32_t *queue);
53199a2dd95SBruce Richardson 
53299a2dd95SBruce Richardson enum rte_color
53399a2dd95SBruce Richardson rte_sched_port_pkt_read_color(const struct rte_mbuf *pkt);
53499a2dd95SBruce Richardson 
53599a2dd95SBruce Richardson /**
53699a2dd95SBruce Richardson  * Hierarchical scheduler port enqueue. Writes up to n_pkts to port
53799a2dd95SBruce Richardson  * scheduler and returns the number of packets actually written. For
53899a2dd95SBruce Richardson  * each packet, the port scheduler queue to write the packet to is
53999a2dd95SBruce Richardson  * identified by reading the hierarchy path from the packet
54099a2dd95SBruce Richardson  * descriptor; if the queue is full or congested and the packet is not
54199a2dd95SBruce Richardson  * written to the queue, then the packet is automatically dropped
54299a2dd95SBruce Richardson  * without any action required from the caller.
54399a2dd95SBruce Richardson  *
54499a2dd95SBruce Richardson  * @param port
54599a2dd95SBruce Richardson  *   Handle to port scheduler instance
54699a2dd95SBruce Richardson  * @param pkts
54799a2dd95SBruce Richardson  *   Array storing the packet descriptor handles
54899a2dd95SBruce Richardson  * @param n_pkts
54999a2dd95SBruce Richardson  *   Number of packets to enqueue from the pkts array into the port scheduler
55099a2dd95SBruce Richardson  * @return
55199a2dd95SBruce Richardson  *   Number of packets successfully enqueued
55299a2dd95SBruce Richardson  */
55399a2dd95SBruce Richardson int
55499a2dd95SBruce Richardson rte_sched_port_enqueue(struct rte_sched_port *port, struct rte_mbuf **pkts, uint32_t n_pkts);
55599a2dd95SBruce Richardson 
55699a2dd95SBruce Richardson /**
55799a2dd95SBruce Richardson  * Hierarchical scheduler port dequeue. Reads up to n_pkts from the
55899a2dd95SBruce Richardson  * port scheduler and stores them in the pkts array and returns the
55999a2dd95SBruce Richardson  * number of packets actually read.  The pkts array needs to be
56099a2dd95SBruce Richardson  * pre-allocated by the caller with at least n_pkts entries.
56199a2dd95SBruce Richardson  *
56299a2dd95SBruce Richardson  * @param port
56399a2dd95SBruce Richardson  *   Handle to port scheduler instance
56499a2dd95SBruce Richardson  * @param pkts
56599a2dd95SBruce Richardson  *   Pre-allocated packet descriptor array where the packets dequeued
56699a2dd95SBruce Richardson  *   from the port
56799a2dd95SBruce Richardson  *   scheduler should be stored
56899a2dd95SBruce Richardson  * @param n_pkts
56999a2dd95SBruce Richardson  *   Number of packets to dequeue from the port scheduler
57099a2dd95SBruce Richardson  * @return
57199a2dd95SBruce Richardson  *   Number of packets successfully dequeued and placed in the pkts array
57299a2dd95SBruce Richardson  */
57399a2dd95SBruce Richardson int
57499a2dd95SBruce Richardson rte_sched_port_dequeue(struct rte_sched_port *port, struct rte_mbuf **pkts, uint32_t n_pkts);
57599a2dd95SBruce Richardson 
576f5e60154SMarcin Danilewicz /**
577f5e60154SMarcin Danilewicz  * Hierarchical scheduler subport traffic class
578f5e60154SMarcin Danilewicz  * oversubscription enable/disable.
579f5e60154SMarcin Danilewicz  * This function should be called at the time of subport initialization.
580f5e60154SMarcin Danilewicz  *
581f5e60154SMarcin Danilewicz  * @param port
582f5e60154SMarcin Danilewicz  *   Handle to port scheduler instance
583f5e60154SMarcin Danilewicz  * @param subport_id
584f5e60154SMarcin Danilewicz  *   Subport ID
585f5e60154SMarcin Danilewicz  * @param tc_ov_enable
586f5e60154SMarcin Danilewicz  *  Boolean flag to enable/disable TC OV
587f5e60154SMarcin Danilewicz  * @return
588f5e60154SMarcin Danilewicz  *   0 upon success, error code otherwise
589f5e60154SMarcin Danilewicz  */
590f5e60154SMarcin Danilewicz int
591f5e60154SMarcin Danilewicz rte_sched_subport_tc_ov_config(struct rte_sched_port *port, uint32_t subport_id, bool tc_ov_enable);
592f5e60154SMarcin Danilewicz 
59399a2dd95SBruce Richardson #ifdef __cplusplus
59499a2dd95SBruce Richardson }
59599a2dd95SBruce Richardson #endif
59699a2dd95SBruce Richardson 
59799a2dd95SBruce Richardson #endif /* __INCLUDE_RTE_SCHED_H__ */
598