DPDK  16.04.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 */
166 #ifdef RTE_SCHED_RED
167  uint32_t n_pkts_red_dropped[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
169 #endif
170 };
171 
172 /*
173  * Pipe configuration parameters. The period and credits_per_period
174  * parameters are measured in bytes, with one byte meaning the time
175  * duration associated with the transmission of one byte on the
176  * physical medium of the output port, with pipe or pipe traffic class
177  * rate (measured as percentage of output port rate) determined as
178  * credits_per_period divided by period. One credit represents one
179  * byte.
180  */
181 struct rte_sched_pipe_params {
182  /* Pipe token bucket */
183  uint32_t tb_rate;
184  uint32_t tb_size;
186  /* Pipe traffic classes */
187  uint32_t tc_rate[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
189  uint32_t tc_period;
191 #ifdef RTE_SCHED_SUBPORT_TC_OV
192  uint8_t tc_ov_weight;
193 #endif
194 
195  /* Pipe queues */
196  uint8_t wrr_weights[RTE_SCHED_QUEUES_PER_PIPE];
197 };
198 
201  /* Packets */
202  uint32_t n_pkts;
203  uint32_t n_pkts_dropped;
204 #ifdef RTE_SCHED_RED
205  uint32_t n_pkts_red_dropped;
206 #endif
207 
208  /* Bytes */
209  uint32_t n_bytes;
210  uint32_t n_bytes_dropped;
211 };
212 
215  const char *name;
216  int socket;
217  uint32_t rate;
219  uint32_t mtu;
222  uint32_t frame_overhead;
231  struct rte_sched_pipe_params *pipe_profiles;
234  uint32_t n_pipe_profiles;
235 #ifdef RTE_SCHED_RED
237 #endif
238 };
239 
240 /*
241  * Configuration
242  *
243  ***/
244 
253 struct rte_sched_port *
255 
262 void
263 rte_sched_port_free(struct rte_sched_port *port);
264 
277 int
278 rte_sched_subport_config(struct rte_sched_port *port,
279  uint32_t subport_id,
280  struct rte_sched_subport_params *params);
281 
296 int
297 rte_sched_pipe_config(struct rte_sched_port *port,
298  uint32_t subport_id,
299  uint32_t pipe_id,
300  int32_t pipe_profile);
301 
310 uint32_t
312 
313 /*
314  * Statistics
315  *
316  ***/
317 
334 int
335 rte_sched_subport_read_stats(struct rte_sched_port *port,
336  uint32_t subport_id,
337  struct rte_sched_subport_stats *stats,
338  uint32_t *tc_ov);
339 
356 int
357 rte_sched_queue_read_stats(struct rte_sched_port *port,
358  uint32_t queue_id,
359  struct rte_sched_queue_stats *stats,
360  uint16_t *qlen);
361 
379 void
381  uint32_t subport, uint32_t pipe, uint32_t traffic_class,
382  uint32_t queue, enum rte_meter_color color);
383 
402 void
404  uint32_t *subport, uint32_t *pipe,
405  uint32_t *traffic_class, uint32_t *queue);
406 
407 enum rte_meter_color
408 rte_sched_port_pkt_read_color(const struct rte_mbuf *pkt);
409 
428 int
429 rte_sched_port_enqueue(struct rte_sched_port *port, struct rte_mbuf **pkts, uint32_t n_pkts);
430 
448 int
449 rte_sched_port_dequeue(struct rte_sched_port *port, struct rte_mbuf **pkts, uint32_t n_pkts);
450 
451 #ifdef __cplusplus
452 }
453 #endif
454 
455 #endif /* __INCLUDE_RTE_SCHED_H__ */