DPDK  2.2.0
rte_sched.h
Go to the documentation of this file.
1 /*-
2  * BSD LICENSE
3  *
4  * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  * * Neither the name of Intel Corporation nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #ifndef __INCLUDE_RTE_SCHED_H__
35 #define __INCLUDE_RTE_SCHED_H__
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
88 #include <sys/types.h>
89 #include <rte_mbuf.h>
90 #include <rte_meter.h>
91 
93 #ifdef RTE_SCHED_RED
94 #include "rte_red.h"
95 #endif
96 
100 #define RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE 4
101 
103 #define RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS 4
104 
106 #define RTE_SCHED_QUEUES_PER_PIPE \
107  (RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE * \
108  RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS)
109 
113 #ifndef RTE_SCHED_PIPE_PROFILES_PER_PORT
114 #define RTE_SCHED_PIPE_PROFILES_PER_PORT 256
115 #endif
116 
117 /*
118  * Ethernet framing overhead. Overhead fields per Ethernet frame:
119  * 1. Preamble: 7 bytes;
120  * 2. Start of Frame Delimiter (SFD): 1 byte;
121  * 3. Frame Check Sequence (FCS): 4 bytes;
122  * 4. Inter Frame Gap (IFG): 12 bytes.
123  *
124  * The FCS is considered overhead only if not included in the packet
125  * length (field pkt_len of struct rte_mbuf).
126  */
127 #ifndef RTE_SCHED_FRAME_OVERHEAD_DEFAULT
128 #define RTE_SCHED_FRAME_OVERHEAD_DEFAULT 24
129 #endif
130 
131 /*
132  * Subport configuration parameters. The period and credits_per_period
133  * parameters are measured in bytes, with one byte meaning the time
134  * duration associated with the transmission of one byte on the
135  * physical medium of the output port, with pipe or pipe traffic class
136  * rate (measured as percentage of output port rate) determined as
137  * credits_per_period divided by period. One credit represents one
138  * byte.
139  */
140 struct rte_sched_subport_params {
141  /* Subport token bucket */
142  uint32_t tb_rate;
143  uint32_t tb_size;
145  /* Subport traffic classes */
146  uint32_t tc_rate[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
148  uint32_t tc_period;
150 };
151 
154  /* Packets */
160  /* Bytes */
165 };
166 
167 /*
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
174  * byte.
175  */
176 struct rte_sched_pipe_params {
177  /* Pipe token bucket */
178  uint32_t tb_rate;
179  uint32_t tb_size;
181  /* Pipe traffic classes */
182  uint32_t tc_rate[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
184  uint32_t tc_period;
186 #ifdef RTE_SCHED_SUBPORT_TC_OV
187  uint8_t tc_ov_weight;
188 #endif
189 
190  /* Pipe queues */
191  uint8_t wrr_weights[RTE_SCHED_QUEUES_PER_PIPE];
192 };
193 
196  /* Packets */
197  uint32_t n_pkts;
198  uint32_t n_pkts_dropped;
200  /* Bytes */
201  uint32_t n_bytes;
202  uint32_t n_bytes_dropped;
203 };
204 
207  const char *name;
208  int socket;
209  uint32_t rate;
211  uint32_t mtu;
214  uint32_t frame_overhead;
223  struct rte_sched_pipe_params *pipe_profiles;
226  uint32_t n_pipe_profiles;
227 #ifdef RTE_SCHED_RED
229 #endif
230 };
231 
232 /*
233  * Configuration
234  *
235  ***/
236 
245 struct rte_sched_port *
247 
254 void
255 rte_sched_port_free(struct rte_sched_port *port);
256 
269 int
270 rte_sched_subport_config(struct rte_sched_port *port,
271  uint32_t subport_id,
272  struct rte_sched_subport_params *params);
273 
288 int
289 rte_sched_pipe_config(struct rte_sched_port *port,
290  uint32_t subport_id,
291  uint32_t pipe_id,
292  int32_t pipe_profile);
293 
302 uint32_t
304 
305 /*
306  * Statistics
307  *
308  ***/
309 
326 int
327 rte_sched_subport_read_stats(struct rte_sched_port *port,
328  uint32_t subport_id,
329  struct rte_sched_subport_stats *stats,
330  uint32_t *tc_ov);
331 
348 int
349 rte_sched_queue_read_stats(struct rte_sched_port *port,
350  uint32_t queue_id,
351  struct rte_sched_queue_stats *stats,
352  uint16_t *qlen);
353 
371 void
373  uint32_t subport, uint32_t pipe, uint32_t traffic_class,
374  uint32_t queue, enum rte_meter_color color);
375 
394 void
396  uint32_t *subport, uint32_t *pipe,
397  uint32_t *traffic_class, uint32_t *queue);
398 
399 enum rte_meter_color
400 rte_sched_port_pkt_read_color(const struct rte_mbuf *pkt);
401 
420 int
421 rte_sched_port_enqueue(struct rte_sched_port *port, struct rte_mbuf **pkts, uint32_t n_pkts);
422 
440 int
441 rte_sched_port_dequeue(struct rte_sched_port *port, struct rte_mbuf **pkts, uint32_t n_pkts);
442 
443 #ifdef __cplusplus
444 }
445 #endif
446 
447 #endif /* __INCLUDE_RTE_SCHED_H__ */