Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2010-2014 Intel Corporation
3 : : */
4 : :
5 : : #include <stdalign.h>
6 : : #include <stdio.h>
7 : : #include <string.h>
8 : :
9 : : #include <eal_export.h>
10 : : #include <rte_common.h>
11 : : #include <rte_log.h>
12 : : #include <rte_malloc.h>
13 : : #include <rte_cycles.h>
14 : : #include <rte_prefetch.h>
15 : : #include <rte_branch_prediction.h>
16 : : #include <rte_mbuf.h>
17 : : #include <rte_bitmap.h>
18 : : #include <rte_reciprocal.h>
19 : :
20 : : #include "rte_sched.h"
21 : : #include "rte_sched_log.h"
22 : : #include "rte_sched_common.h"
23 : :
24 : : #include "rte_approx.h"
25 : :
26 : : #ifndef RTE_SCHED_PORT_N_GRINDERS
27 : : #define RTE_SCHED_PORT_N_GRINDERS 8
28 : : #endif
29 : :
30 : : #define RTE_SCHED_TB_RATE_CONFIG_ERR (1e-7)
31 : : #define RTE_SCHED_WRR_SHIFT 3
32 : : #define RTE_SCHED_MAX_QUEUES_PER_TC RTE_SCHED_BE_QUEUES_PER_PIPE
33 : : #define RTE_SCHED_GRINDER_PCACHE_SIZE (64 / RTE_SCHED_QUEUES_PER_PIPE)
34 : : #define RTE_SCHED_PIPE_INVALID UINT32_MAX
35 : : #define RTE_SCHED_BMP_POS_INVALID UINT32_MAX
36 : :
37 : : /* Scaling for cycles_per_byte calculation
38 : : * Chosen so that minimum rate is 480 bit/sec
39 : : */
40 : : #define RTE_SCHED_TIME_SHIFT 8
41 : :
42 : : struct rte_sched_pipe_profile {
43 : : /* Token bucket (TB) */
44 : : uint64_t tb_period;
45 : : uint64_t tb_credits_per_period;
46 : : uint64_t tb_size;
47 : :
48 : : /* Pipe traffic classes */
49 : : uint64_t tc_period;
50 : : uint64_t tc_credits_per_period[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
51 : : uint8_t tc_ov_weight;
52 : :
53 : : /* Pipe best-effort traffic class queues */
54 : : uint8_t wrr_cost[RTE_SCHED_BE_QUEUES_PER_PIPE];
55 : : };
56 : :
57 : : struct __rte_cache_aligned rte_sched_pipe {
58 : : /* Token bucket (TB) */
59 : : uint64_t tb_time; /* time of last update */
60 : : uint64_t tb_credits;
61 : :
62 : : /* Pipe profile and flags */
63 : : uint32_t profile;
64 : :
65 : : /* Traffic classes (TCs) */
66 : : uint64_t tc_time; /* time of next update */
67 : : uint64_t tc_credits[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
68 : :
69 : : /* Weighted Round Robin (WRR) */
70 : : uint8_t wrr_tokens[RTE_SCHED_BE_QUEUES_PER_PIPE];
71 : :
72 : : /* TC oversubscription */
73 : : uint64_t tc_ov_credits;
74 : : uint8_t tc_ov_period_id;
75 : : };
76 : :
77 : : struct rte_sched_queue {
78 : : uint16_t qw;
79 : : uint16_t qr;
80 : : };
81 : :
82 : : struct rte_sched_queue_extra {
83 : : struct rte_sched_queue_stats stats;
84 : : union {
85 : : struct rte_red red;
86 : : struct rte_pie pie;
87 : : };
88 : : };
89 : :
90 : : enum grinder_state {
91 : : e_GRINDER_PREFETCH_PIPE = 0,
92 : : e_GRINDER_PREFETCH_TC_QUEUE_ARRAYS,
93 : : e_GRINDER_PREFETCH_MBUF,
94 : : e_GRINDER_READ_MBUF
95 : : };
96 : :
97 : : struct rte_sched_subport_profile {
98 : : /* Token bucket (TB) */
99 : : uint64_t tb_period;
100 : : uint64_t tb_credits_per_period;
101 : : uint64_t tb_size;
102 : :
103 : : uint64_t tc_credits_per_period[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
104 : : uint64_t tc_period;
105 : : };
106 : :
107 : : struct rte_sched_grinder {
108 : : /* Pipe cache */
109 : : uint16_t pcache_qmask[RTE_SCHED_GRINDER_PCACHE_SIZE];
110 : : uint32_t pcache_qindex[RTE_SCHED_GRINDER_PCACHE_SIZE];
111 : : uint32_t pcache_w;
112 : : uint32_t pcache_r;
113 : :
114 : : /* Current pipe */
115 : : enum grinder_state state;
116 : : uint32_t productive;
117 : : uint32_t pindex;
118 : : struct rte_sched_subport *subport;
119 : : struct rte_sched_subport_profile *subport_params;
120 : : struct rte_sched_pipe *pipe;
121 : : struct rte_sched_pipe_profile *pipe_params;
122 : :
123 : : /* TC cache */
124 : : uint8_t tccache_qmask[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
125 : : uint32_t tccache_qindex[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
126 : : uint32_t tccache_w;
127 : : uint32_t tccache_r;
128 : :
129 : : /* Current TC */
130 : : uint32_t tc_index;
131 : : struct rte_sched_queue *queue[RTE_SCHED_MAX_QUEUES_PER_TC];
132 : : struct rte_mbuf **qbase[RTE_SCHED_MAX_QUEUES_PER_TC];
133 : : uint32_t qindex[RTE_SCHED_MAX_QUEUES_PER_TC];
134 : : uint16_t qsize;
135 : : uint32_t qmask;
136 : : uint32_t qpos;
137 : : struct rte_mbuf *pkt;
138 : :
139 : : /* WRR */
140 : : uint16_t wrr_tokens[RTE_SCHED_BE_QUEUES_PER_PIPE];
141 : : uint16_t wrr_mask[RTE_SCHED_BE_QUEUES_PER_PIPE];
142 : : uint8_t wrr_cost[RTE_SCHED_BE_QUEUES_PER_PIPE];
143 : : };
144 : :
145 : : struct __rte_cache_aligned rte_sched_subport {
146 : : /* Token bucket (TB) */
147 : : uint64_t tb_time; /* time of last update */
148 : : uint64_t tb_credits;
149 : :
150 : : /* Traffic classes (TCs) */
151 : : uint64_t tc_time; /* time of next update */
152 : : uint64_t tc_credits[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
153 : :
154 : : /* TC oversubscription */
155 : : uint64_t tc_ov_wm;
156 : : uint64_t tc_ov_wm_min;
157 : : uint64_t tc_ov_wm_max;
158 : : uint8_t tc_ov_period_id;
159 : : uint8_t tc_ov;
160 : : uint32_t tc_ov_n;
161 : : double tc_ov_rate;
162 : :
163 : : /* Statistics */
164 : : alignas(RTE_CACHE_LINE_SIZE) struct rte_sched_subport_stats stats;
165 : :
166 : : /* subport profile */
167 : : uint32_t profile;
168 : : /* Subport pipes */
169 : : uint32_t n_pipes_per_subport_enabled;
170 : : uint32_t n_pipe_profiles;
171 : : uint32_t n_max_pipe_profiles;
172 : :
173 : : /* Pipe best-effort TC rate */
174 : : uint64_t pipe_tc_be_rate_max;
175 : :
176 : : /* Pipe queues size */
177 : : uint16_t qsize[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
178 : :
179 : : bool cman_enabled;
180 : : enum rte_sched_cman_mode cman;
181 : :
182 : : union {
183 : : struct rte_red_config red_config[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE][RTE_COLORS];
184 : : struct rte_pie_config pie_config[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
185 : : };
186 : :
187 : : /* Scheduling loop detection */
188 : : uint32_t pipe_loop;
189 : : uint32_t pipe_exhaustion;
190 : :
191 : : /* Bitmap */
192 : : struct rte_bitmap *bmp;
193 : : alignas(16) uint32_t grinder_base_bmp_pos[RTE_SCHED_PORT_N_GRINDERS];
194 : :
195 : : /* Grinders */
196 : : struct rte_sched_grinder grinder[RTE_SCHED_PORT_N_GRINDERS];
197 : : uint32_t busy_grinders;
198 : :
199 : : /* Queue base calculation */
200 : : uint32_t qsize_add[RTE_SCHED_QUEUES_PER_PIPE];
201 : : uint32_t qsize_sum;
202 : :
203 : : /* TC oversubscription activation */
204 : : int tc_ov_enabled;
205 : :
206 : : struct rte_sched_pipe *pipe;
207 : : struct rte_sched_queue *queue;
208 : : struct rte_sched_queue_extra *queue_extra;
209 : : struct rte_sched_pipe_profile *pipe_profiles;
210 : : uint8_t *bmp_array;
211 : : struct rte_mbuf **queue_array;
212 : : alignas(RTE_CACHE_LINE_SIZE) uint8_t memory[0];
213 : : };
214 : :
215 : : struct __rte_cache_aligned rte_sched_port {
216 : : /* User parameters */
217 : : uint32_t n_subports_per_port;
218 : : uint32_t n_pipes_per_subport;
219 : : uint32_t n_pipes_per_subport_log2;
220 : : uint16_t pipe_queue[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
221 : : uint8_t pipe_tc[RTE_SCHED_QUEUES_PER_PIPE];
222 : : uint8_t tc_queue[RTE_SCHED_QUEUES_PER_PIPE];
223 : : uint32_t n_subport_profiles;
224 : : uint32_t n_max_subport_profiles;
225 : : uint64_t rate;
226 : : uint32_t mtu;
227 : : uint32_t frame_overhead;
228 : : int socket;
229 : :
230 : : /* Timing */
231 : : uint64_t time_cpu_cycles; /* Current CPU time measured in CPU cycles */
232 : : uint64_t time_cpu_bytes; /* Current CPU time measured in bytes */
233 : : uint64_t time; /* Current NIC TX time measured in bytes */
234 : : struct rte_reciprocal inv_cycles_per_byte; /* CPU cycles per byte */
235 : : uint64_t cycles_per_byte;
236 : :
237 : : /* Grinders */
238 : : struct rte_mbuf **pkts_out;
239 : : uint32_t n_pkts_out;
240 : : uint32_t subport_id;
241 : :
242 : : /* Large data structures */
243 : : struct rte_sched_subport_profile *subport_profiles;
244 : : alignas(RTE_CACHE_LINE_SIZE) struct rte_sched_subport *subports[0];
245 : : };
246 : :
247 : : enum rte_sched_subport_array {
248 : : e_RTE_SCHED_SUBPORT_ARRAY_PIPE = 0,
249 : : e_RTE_SCHED_SUBPORT_ARRAY_QUEUE,
250 : : e_RTE_SCHED_SUBPORT_ARRAY_QUEUE_EXTRA,
251 : : e_RTE_SCHED_SUBPORT_ARRAY_PIPE_PROFILES,
252 : : e_RTE_SCHED_SUBPORT_ARRAY_BMP_ARRAY,
253 : : e_RTE_SCHED_SUBPORT_ARRAY_QUEUE_ARRAY,
254 : : e_RTE_SCHED_SUBPORT_ARRAY_TOTAL,
255 : : };
256 : :
257 : : static inline uint32_t
258 : : rte_sched_subport_pipe_queues(struct rte_sched_subport *subport)
259 : : {
260 : 3 : return RTE_SCHED_QUEUES_PER_PIPE * subport->n_pipes_per_subport_enabled;
261 : : }
262 : :
263 : : static inline struct rte_mbuf **
264 : : rte_sched_subport_pipe_qbase(struct rte_sched_subport *subport, uint32_t qindex)
265 : : {
266 : 16391 : uint32_t pindex = qindex >> 4;
267 : 16391 : uint32_t qpos = qindex & (RTE_SCHED_QUEUES_PER_PIPE - 1);
268 : :
269 : 16391 : return (subport->queue_array + pindex *
270 : 16391 : subport->qsize_sum + subport->qsize_add[qpos]);
271 : : }
272 : :
273 : : static inline uint16_t
274 : : rte_sched_subport_pipe_qsize(struct rte_sched_port *port,
275 : : struct rte_sched_subport *subport, uint32_t qindex)
276 : : {
277 : 16406 : uint32_t tc = port->pipe_tc[qindex & (RTE_SCHED_QUEUES_PER_PIPE - 1)];
278 : :
279 : 16406 : return subport->qsize[tc];
280 : : }
281 : :
282 : : static inline uint32_t
283 : : rte_sched_port_queues_per_port(struct rte_sched_port *port)
284 : : {
285 : : uint32_t n_queues = 0, i;
286 : :
287 [ + + ]: 2 : for (i = 0; i < port->n_subports_per_port; i++)
288 : 1 : n_queues += rte_sched_subport_pipe_queues(port->subports[i]);
289 : :
290 : : return n_queues;
291 : : }
292 : :
293 : : static inline uint16_t
294 : : rte_sched_port_pipe_queue(struct rte_sched_port *port, uint32_t traffic_class)
295 : : {
296 : 10 : uint16_t pipe_queue = port->pipe_queue[traffic_class];
297 : :
298 : : return pipe_queue;
299 : : }
300 : :
301 : : static inline uint8_t
302 : : rte_sched_port_pipe_tc(struct rte_sched_port *port, uint32_t qindex)
303 : : {
304 : 20 : uint8_t pipe_tc = port->pipe_tc[qindex & (RTE_SCHED_QUEUES_PER_PIPE - 1)];
305 : :
306 : : return pipe_tc;
307 : : }
308 : :
309 : : static inline uint8_t
310 : : rte_sched_port_tc_queue(struct rte_sched_port *port, uint32_t qindex)
311 : : {
312 : 10 : uint8_t tc_queue = port->tc_queue[qindex & (RTE_SCHED_QUEUES_PER_PIPE - 1)];
313 : :
314 : : return tc_queue;
315 : : }
316 : :
317 : : static int
318 : 1 : pipe_profile_check(struct rte_sched_pipe_params *params,
319 : : uint64_t rate, uint16_t *qsize)
320 : : {
321 : : uint32_t i;
322 : :
323 : : /* Pipe parameters */
324 [ - + ]: 1 : if (params == NULL) {
325 : 0 : SCHED_LOG(ERR,
326 : : "%s: Incorrect value for parameter params", __func__);
327 : 0 : return -EINVAL;
328 : : }
329 : :
330 : : /* TB rate: non-zero, not greater than port rate */
331 [ + - - + ]: 1 : if (params->tb_rate == 0 ||
332 : : params->tb_rate > rate) {
333 : 0 : SCHED_LOG(ERR,
334 : : "%s: Incorrect value for tb rate", __func__);
335 : 0 : return -EINVAL;
336 : : }
337 : :
338 : : /* TB size: non-zero */
339 [ - + ]: 1 : if (params->tb_size == 0) {
340 : 0 : SCHED_LOG(ERR,
341 : : "%s: Incorrect value for tb size", __func__);
342 : 0 : return -EINVAL;
343 : : }
344 : :
345 : : /* TC rate: non-zero if qsize non-zero, less than pipe rate */
346 [ + + ]: 14 : for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++) {
347 [ - + - - : 13 : if ((qsize[i] == 0 && params->tc_rate[i] != 0) ||
+ - ]
348 [ + - - + ]: 13 : (qsize[i] != 0 && (params->tc_rate[i] == 0 ||
349 : : params->tc_rate[i] > params->tb_rate))) {
350 : 0 : SCHED_LOG(ERR,
351 : : "%s: Incorrect value for qsize or tc_rate", __func__);
352 : 0 : return -EINVAL;
353 : : }
354 : : }
355 : :
356 [ + - ]: 1 : if (params->tc_rate[RTE_SCHED_TRAFFIC_CLASS_BE] == 0 ||
357 [ - + ]: 1 : qsize[RTE_SCHED_TRAFFIC_CLASS_BE] == 0) {
358 : 0 : SCHED_LOG(ERR,
359 : : "%s: Incorrect value for be traffic class rate", __func__);
360 : 0 : return -EINVAL;
361 : : }
362 : :
363 : : /* TC period: non-zero */
364 [ - + ]: 1 : if (params->tc_period == 0) {
365 : 0 : SCHED_LOG(ERR,
366 : : "%s: Incorrect value for tc period", __func__);
367 : 0 : return -EINVAL;
368 : : }
369 : :
370 : : /* Best effort tc oversubscription weight: non-zero */
371 [ - + ]: 1 : if (params->tc_ov_weight == 0) {
372 : 0 : SCHED_LOG(ERR,
373 : : "%s: Incorrect value for tc ov weight", __func__);
374 : 0 : return -EINVAL;
375 : : }
376 : :
377 : : /* Queue WRR weights: non-zero */
378 [ + + ]: 5 : for (i = 0; i < RTE_SCHED_BE_QUEUES_PER_PIPE; i++) {
379 [ - + ]: 4 : if (params->wrr_weights[i] == 0) {
380 : 0 : SCHED_LOG(ERR,
381 : : "%s: Incorrect value for wrr weight", __func__);
382 : 0 : return -EINVAL;
383 : : }
384 : : }
385 : :
386 : : return 0;
387 : : }
388 : :
389 : : static int
390 : 1 : subport_profile_check(struct rte_sched_subport_profile_params *params,
391 : : uint64_t rate)
392 : : {
393 : : uint32_t i;
394 : :
395 : : /* Check user parameters */
396 [ - + ]: 1 : if (params == NULL) {
397 : 0 : SCHED_LOG(ERR, "%s: "
398 : : "Incorrect value for parameter params", __func__);
399 : 0 : return -EINVAL;
400 : : }
401 : :
402 [ + - - + ]: 1 : if (params->tb_rate == 0 || params->tb_rate > rate) {
403 : 0 : SCHED_LOG(ERR, "%s: "
404 : : "Incorrect value for tb rate", __func__);
405 : 0 : return -EINVAL;
406 : : }
407 : :
408 [ - + ]: 1 : if (params->tb_size == 0) {
409 : 0 : SCHED_LOG(ERR, "%s: "
410 : : "Incorrect value for tb size", __func__);
411 : 0 : return -EINVAL;
412 : : }
413 : :
414 [ + + ]: 14 : for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++) {
415 : 13 : uint64_t tc_rate = params->tc_rate[i];
416 : :
417 [ + - - + ]: 13 : if (tc_rate == 0 || (tc_rate > params->tb_rate)) {
418 : 0 : SCHED_LOG(ERR, "%s: "
419 : : "Incorrect value for tc rate", __func__);
420 : 0 : return -EINVAL;
421 : : }
422 : : }
423 : :
424 [ - + ]: 1 : if (params->tc_rate[RTE_SCHED_TRAFFIC_CLASS_BE] == 0) {
425 : 0 : SCHED_LOG(ERR, "%s: "
426 : : "Incorrect tc rate(best effort)", __func__);
427 : 0 : return -EINVAL;
428 : : }
429 : :
430 [ - + ]: 1 : if (params->tc_period == 0) {
431 : 0 : SCHED_LOG(ERR, "%s: "
432 : : "Incorrect value for tc period", __func__);
433 : 0 : return -EINVAL;
434 : : }
435 : :
436 : : return 0;
437 : : }
438 : :
439 : : static int
440 : 1 : rte_sched_port_check_params(struct rte_sched_port_params *params)
441 : : {
442 : : uint32_t i;
443 : :
444 [ - + ]: 1 : if (params == NULL) {
445 : 0 : SCHED_LOG(ERR,
446 : : "%s: Incorrect value for parameter params", __func__);
447 : 0 : return -EINVAL;
448 : : }
449 : :
450 : : /* socket */
451 [ - + ]: 1 : if (params->socket < 0) {
452 : 0 : SCHED_LOG(ERR,
453 : : "%s: Incorrect value for socket id", __func__);
454 : 0 : return -EINVAL;
455 : : }
456 : :
457 : : /* rate */
458 [ - + ]: 1 : if (params->rate == 0) {
459 : 0 : SCHED_LOG(ERR,
460 : : "%s: Incorrect value for rate", __func__);
461 : 0 : return -EINVAL;
462 : : }
463 : :
464 : : /* mtu */
465 [ - + ]: 1 : if (params->mtu == 0) {
466 : 0 : SCHED_LOG(ERR,
467 : : "%s: Incorrect value for mtu", __func__);
468 : 0 : return -EINVAL;
469 : : }
470 : :
471 : : /* n_subports_per_port: non-zero, limited to 16 bits, power of 2 */
472 [ + - ]: 1 : if (params->n_subports_per_port == 0 ||
473 : : params->n_subports_per_port > 1u << 16 ||
474 : : !rte_is_power_of_2(params->n_subports_per_port)) {
475 : 0 : SCHED_LOG(ERR,
476 : : "%s: Incorrect value for number of subports", __func__);
477 : 0 : return -EINVAL;
478 : : }
479 : :
480 [ + - ]: 1 : if (params->subport_profiles == NULL ||
481 [ + - ]: 1 : params->n_subport_profiles == 0 ||
482 [ + - - + ]: 1 : params->n_max_subport_profiles == 0 ||
483 : : params->n_subport_profiles > params->n_max_subport_profiles) {
484 : 0 : SCHED_LOG(ERR,
485 : : "%s: Incorrect value for subport profiles", __func__);
486 : 0 : return -EINVAL;
487 : : }
488 : :
489 [ + + ]: 2 : for (i = 0; i < params->n_subport_profiles; i++) {
490 : 1 : struct rte_sched_subport_profile_params *p =
491 : 1 : params->subport_profiles + i;
492 : : int status;
493 : :
494 : 1 : status = subport_profile_check(p, params->rate);
495 [ - + ]: 1 : if (status != 0) {
496 : 0 : SCHED_LOG(ERR,
497 : : "%s: subport profile check failed(%d)",
498 : : __func__, status);
499 : 0 : return -EINVAL;
500 : : }
501 : : }
502 : :
503 : : /* n_pipes_per_subport: non-zero, power of 2 */
504 [ + - ]: 1 : if (params->n_pipes_per_subport == 0 ||
505 : : !rte_is_power_of_2(params->n_pipes_per_subport)) {
506 : 0 : SCHED_LOG(ERR,
507 : : "%s: Incorrect value for maximum pipes number", __func__);
508 : 0 : return -EINVAL;
509 : : }
510 : :
511 : : return 0;
512 : : }
513 : :
514 : : static uint32_t
515 : 7 : rte_sched_subport_get_array_base(struct rte_sched_subport_params *params,
516 : : enum rte_sched_subport_array array)
517 : : {
518 : 7 : uint32_t n_pipes_per_subport = params->n_pipes_per_subport_enabled;
519 : 7 : uint32_t n_subport_pipe_queues =
520 : : RTE_SCHED_QUEUES_PER_PIPE * n_pipes_per_subport;
521 : :
522 : 7 : uint32_t size_pipe = n_pipes_per_subport * sizeof(struct rte_sched_pipe);
523 : 7 : uint32_t size_queue =
524 : : n_subport_pipe_queues * sizeof(struct rte_sched_queue);
525 : 7 : uint32_t size_queue_extra
526 : : = n_subport_pipe_queues * sizeof(struct rte_sched_queue_extra);
527 : 7 : uint32_t size_pipe_profiles = params->n_max_pipe_profiles *
528 : : sizeof(struct rte_sched_pipe_profile);
529 : : uint32_t size_bmp_array =
530 : 7 : rte_bitmap_get_memory_footprint(n_subport_pipe_queues);
531 : : uint32_t size_per_pipe_queue_array, size_queue_array;
532 : :
533 : : uint32_t base, i;
534 : :
535 : : size_per_pipe_queue_array = 0;
536 [ + + ]: 98 : for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++) {
537 [ + + ]: 91 : if (i < RTE_SCHED_TRAFFIC_CLASS_BE)
538 : 84 : size_per_pipe_queue_array +=
539 : 84 : params->qsize[i] * sizeof(struct rte_mbuf *);
540 : : else
541 : 7 : size_per_pipe_queue_array += RTE_SCHED_MAX_QUEUES_PER_TC *
542 : 7 : params->qsize[i] * sizeof(struct rte_mbuf *);
543 : : }
544 : 7 : size_queue_array = n_pipes_per_subport * size_per_pipe_queue_array;
545 : :
546 : : base = 0;
547 : :
548 [ + + ]: 7 : if (array == e_RTE_SCHED_SUBPORT_ARRAY_PIPE)
549 : : return base;
550 : 6 : base += RTE_CACHE_LINE_ROUNDUP(size_pipe);
551 : :
552 [ + + ]: 6 : if (array == e_RTE_SCHED_SUBPORT_ARRAY_QUEUE)
553 : : return base;
554 : 5 : base += RTE_CACHE_LINE_ROUNDUP(size_queue);
555 : :
556 [ + + ]: 5 : if (array == e_RTE_SCHED_SUBPORT_ARRAY_QUEUE_EXTRA)
557 : : return base;
558 : 4 : base += RTE_CACHE_LINE_ROUNDUP(size_queue_extra);
559 : :
560 [ + + ]: 4 : if (array == e_RTE_SCHED_SUBPORT_ARRAY_PIPE_PROFILES)
561 : : return base;
562 : 3 : base += RTE_CACHE_LINE_ROUNDUP(size_pipe_profiles);
563 : :
564 [ + + ]: 3 : if (array == e_RTE_SCHED_SUBPORT_ARRAY_BMP_ARRAY)
565 : : return base;
566 : 2 : base += RTE_CACHE_LINE_ROUNDUP(size_bmp_array);
567 : :
568 [ + + ]: 2 : if (array == e_RTE_SCHED_SUBPORT_ARRAY_QUEUE_ARRAY)
569 : : return base;
570 : 1 : base += RTE_CACHE_LINE_ROUNDUP(size_queue_array);
571 : :
572 : 1 : return base;
573 : : }
574 : :
575 : : static void
576 : 1 : rte_sched_subport_config_qsize(struct rte_sched_subport *subport)
577 : : {
578 : : uint32_t i;
579 : :
580 : 1 : subport->qsize_add[0] = 0;
581 : :
582 : : /* Strict priority traffic class */
583 [ + + ]: 13 : for (i = 1; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
584 : 12 : subport->qsize_add[i] = subport->qsize_add[i-1] + subport->qsize[i-1];
585 : :
586 : : /* Best-effort traffic class */
587 : 1 : subport->qsize_add[RTE_SCHED_TRAFFIC_CLASS_BE + 1] =
588 : 1 : subport->qsize_add[RTE_SCHED_TRAFFIC_CLASS_BE] +
589 : 1 : subport->qsize[RTE_SCHED_TRAFFIC_CLASS_BE];
590 : 1 : subport->qsize_add[RTE_SCHED_TRAFFIC_CLASS_BE + 2] =
591 : 1 : subport->qsize_add[RTE_SCHED_TRAFFIC_CLASS_BE + 1] +
592 : : subport->qsize[RTE_SCHED_TRAFFIC_CLASS_BE];
593 : 1 : subport->qsize_add[RTE_SCHED_TRAFFIC_CLASS_BE + 3] =
594 : 1 : subport->qsize_add[RTE_SCHED_TRAFFIC_CLASS_BE + 2] +
595 : : subport->qsize[RTE_SCHED_TRAFFIC_CLASS_BE];
596 : :
597 : 1 : subport->qsize_sum = subport->qsize_add[RTE_SCHED_TRAFFIC_CLASS_BE + 3] +
598 : : subport->qsize[RTE_SCHED_TRAFFIC_CLASS_BE];
599 : 1 : }
600 : :
601 : : static void
602 : 1 : rte_sched_port_log_pipe_profile(struct rte_sched_subport *subport, uint32_t i)
603 : : {
604 : 1 : struct rte_sched_pipe_profile *p = subport->pipe_profiles + i;
605 : :
606 : 1 : RTE_LOG(DEBUG, SCHED, "Low level config for pipe profile %u:\n"
607 : : " Token bucket: period = %"PRIu64", credits per period = %"PRIu64", size = %"PRIu64"\n"
608 : : " Traffic classes: period = %"PRIu64",\n"
609 : : " credits per period = [%"PRIu64", %"PRIu64", %"PRIu64", %"PRIu64
610 : : ", %"PRIu64", %"PRIu64", %"PRIu64", %"PRIu64", %"PRIu64", %"PRIu64
611 : : ", %"PRIu64", %"PRIu64", %"PRIu64"]\n"
612 : : " Best-effort traffic class oversubscription: weight = %hhu\n"
613 : : " WRR cost: [%hhu, %hhu, %hhu, %hhu]\n",
614 : : i,
615 : :
616 : : /* Token bucket */
617 : : p->tb_period,
618 : : p->tb_credits_per_period,
619 : : p->tb_size,
620 : :
621 : : /* Traffic classes */
622 : : p->tc_period,
623 : : p->tc_credits_per_period[0],
624 : : p->tc_credits_per_period[1],
625 : : p->tc_credits_per_period[2],
626 : : p->tc_credits_per_period[3],
627 : : p->tc_credits_per_period[4],
628 : : p->tc_credits_per_period[5],
629 : : p->tc_credits_per_period[6],
630 : : p->tc_credits_per_period[7],
631 : : p->tc_credits_per_period[8],
632 : : p->tc_credits_per_period[9],
633 : : p->tc_credits_per_period[10],
634 : : p->tc_credits_per_period[11],
635 : : p->tc_credits_per_period[12],
636 : :
637 : : /* Best-effort traffic class oversubscription */
638 : : p->tc_ov_weight,
639 : :
640 : : /* WRR */
641 : : p->wrr_cost[0], p->wrr_cost[1], p->wrr_cost[2], p->wrr_cost[3]);
642 : 1 : }
643 : :
644 : : static void
645 : 2 : rte_sched_port_log_subport_profile(struct rte_sched_port *port, uint32_t i)
646 : : {
647 : 2 : struct rte_sched_subport_profile *p = port->subport_profiles + i;
648 : :
649 : 2 : RTE_LOG(DEBUG, SCHED, "Low level config for subport profile %u:\n"
650 : : "Token bucket: period = %"PRIu64", credits per period = %"PRIu64","
651 : : "size = %"PRIu64"\n"
652 : : "Traffic classes: period = %"PRIu64",\n"
653 : : "credits per period = [%"PRIu64", %"PRIu64", %"PRIu64", %"PRIu64
654 : : " %"PRIu64", %"PRIu64", %"PRIu64", %"PRIu64", %"PRIu64", %"PRIu64
655 : : " %"PRIu64", %"PRIu64", %"PRIu64"]\n",
656 : : i,
657 : :
658 : : /* Token bucket */
659 : : p->tb_period,
660 : : p->tb_credits_per_period,
661 : : p->tb_size,
662 : :
663 : : /* Traffic classes */
664 : : p->tc_period,
665 : : p->tc_credits_per_period[0],
666 : : p->tc_credits_per_period[1],
667 : : p->tc_credits_per_period[2],
668 : : p->tc_credits_per_period[3],
669 : : p->tc_credits_per_period[4],
670 : : p->tc_credits_per_period[5],
671 : : p->tc_credits_per_period[6],
672 : : p->tc_credits_per_period[7],
673 : : p->tc_credits_per_period[8],
674 : : p->tc_credits_per_period[9],
675 : : p->tc_credits_per_period[10],
676 : : p->tc_credits_per_period[11],
677 : : p->tc_credits_per_period[12]);
678 : 2 : }
679 : :
680 : : static inline uint64_t
681 : : rte_sched_time_ms_to_bytes(uint64_t time_ms, uint64_t rate)
682 : : {
683 : : uint64_t time = time_ms;
684 : :
685 : 29 : time = (time * rate) / 1000;
686 : :
687 : : return time;
688 : : }
689 : :
690 : : static void
691 : 1 : rte_sched_pipe_profile_convert(struct rte_sched_subport *subport,
692 : : struct rte_sched_pipe_params *src,
693 : : struct rte_sched_pipe_profile *dst,
694 : : uint64_t rate)
695 : : {
696 : : uint32_t wrr_cost[RTE_SCHED_BE_QUEUES_PER_PIPE];
697 : : uint32_t lcd1, lcd2, lcd;
698 : : uint32_t i;
699 : :
700 : : /* Token Bucket */
701 [ - + ]: 1 : if (src->tb_rate == rate) {
702 : 0 : dst->tb_credits_per_period = 1;
703 : 0 : dst->tb_period = 1;
704 : : } else {
705 : 1 : double tb_rate = (double) src->tb_rate
706 : 1 : / (double) rate;
707 : : double d = RTE_SCHED_TB_RATE_CONFIG_ERR;
708 : :
709 : 1 : rte_approx_64(tb_rate, d, &dst->tb_credits_per_period,
710 : : &dst->tb_period);
711 : : }
712 : :
713 : 1 : dst->tb_size = src->tb_size;
714 : :
715 : : /* Traffic Classes */
716 : 1 : dst->tc_period = rte_sched_time_ms_to_bytes(src->tc_period,
717 : : rate);
718 : :
719 [ + + ]: 14 : for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
720 [ + - ]: 13 : if (subport->qsize[i])
721 : : dst->tc_credits_per_period[i]
722 : 13 : = rte_sched_time_ms_to_bytes(src->tc_period,
723 : : src->tc_rate[i]);
724 : :
725 : 1 : dst->tc_ov_weight = src->tc_ov_weight;
726 : :
727 : : /* WRR queues */
728 : 1 : wrr_cost[0] = src->wrr_weights[0];
729 : 1 : wrr_cost[1] = src->wrr_weights[1];
730 : 1 : wrr_cost[2] = src->wrr_weights[2];
731 [ + - ]: 1 : wrr_cost[3] = src->wrr_weights[3];
732 : :
733 : : lcd1 = rte_get_lcd(wrr_cost[0], wrr_cost[1]);
734 : : lcd2 = rte_get_lcd(wrr_cost[2], wrr_cost[3]);
735 : : lcd = rte_get_lcd(lcd1, lcd2);
736 : :
737 : 1 : wrr_cost[0] = lcd / wrr_cost[0];
738 : 1 : wrr_cost[1] = lcd / wrr_cost[1];
739 : 1 : wrr_cost[2] = lcd / wrr_cost[2];
740 : 1 : wrr_cost[3] = lcd / wrr_cost[3];
741 : :
742 : 1 : dst->wrr_cost[0] = (uint8_t) wrr_cost[0];
743 : 1 : dst->wrr_cost[1] = (uint8_t) wrr_cost[1];
744 : 1 : dst->wrr_cost[2] = (uint8_t) wrr_cost[2];
745 : 1 : dst->wrr_cost[3] = (uint8_t) wrr_cost[3];
746 : 1 : }
747 : :
748 : : static void
749 : 1 : rte_sched_subport_profile_convert(struct rte_sched_subport_profile_params *src,
750 : : struct rte_sched_subport_profile *dst,
751 : : uint64_t rate)
752 : : {
753 : : uint32_t i;
754 : :
755 : : /* Token Bucket */
756 [ + - ]: 1 : if (src->tb_rate == rate) {
757 : 1 : dst->tb_credits_per_period = 1;
758 : 1 : dst->tb_period = 1;
759 : : } else {
760 : 0 : double tb_rate = (double) src->tb_rate
761 : 0 : / (double) rate;
762 : : double d = RTE_SCHED_TB_RATE_CONFIG_ERR;
763 : :
764 : 0 : rte_approx_64(tb_rate, d, &dst->tb_credits_per_period,
765 : : &dst->tb_period);
766 : : }
767 : :
768 : 1 : dst->tb_size = src->tb_size;
769 : :
770 : : /* Traffic Classes */
771 : 1 : dst->tc_period = rte_sched_time_ms_to_bytes(src->tc_period, rate);
772 : :
773 [ + + ]: 14 : for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
774 : : dst->tc_credits_per_period[i]
775 : 13 : = rte_sched_time_ms_to_bytes(src->tc_period,
776 : : src->tc_rate[i]);
777 : 1 : }
778 : :
779 : : static void
780 : 1 : rte_sched_subport_config_pipe_profile_table(struct rte_sched_subport *subport,
781 : : struct rte_sched_subport_params *params, uint64_t rate)
782 : : {
783 : : uint32_t i;
784 : :
785 [ + + ]: 2 : for (i = 0; i < subport->n_pipe_profiles; i++) {
786 : 1 : struct rte_sched_pipe_params *src = params->pipe_profiles + i;
787 : 1 : struct rte_sched_pipe_profile *dst = subport->pipe_profiles + i;
788 : :
789 : 1 : rte_sched_pipe_profile_convert(subport, src, dst, rate);
790 : 1 : rte_sched_port_log_pipe_profile(subport, i);
791 : : }
792 : :
793 : 1 : subport->pipe_tc_be_rate_max = 0;
794 [ + + ]: 2 : for (i = 0; i < subport->n_pipe_profiles; i++) {
795 : 1 : struct rte_sched_pipe_params *src = params->pipe_profiles + i;
796 : 1 : uint64_t pipe_tc_be_rate = src->tc_rate[RTE_SCHED_TRAFFIC_CLASS_BE];
797 : :
798 [ + - ]: 1 : if (subport->pipe_tc_be_rate_max < pipe_tc_be_rate)
799 : 1 : subport->pipe_tc_be_rate_max = pipe_tc_be_rate;
800 : : }
801 : 1 : }
802 : :
803 : : static void
804 : 1 : rte_sched_port_config_subport_profile_table(struct rte_sched_port *port,
805 : : struct rte_sched_port_params *params,
806 : : uint64_t rate)
807 : : {
808 : : uint32_t i;
809 : :
810 [ + + ]: 2 : for (i = 0; i < port->n_subport_profiles; i++) {
811 : 1 : struct rte_sched_subport_profile_params *src
812 : 1 : = params->subport_profiles + i;
813 : 1 : struct rte_sched_subport_profile *dst
814 : 1 : = port->subport_profiles + i;
815 : :
816 : 1 : rte_sched_subport_profile_convert(src, dst, rate);
817 : 1 : rte_sched_port_log_subport_profile(port, i);
818 : : }
819 : 1 : }
820 : :
821 : : static int
822 : 1 : rte_sched_subport_check_params(struct rte_sched_subport_params *params,
823 : : uint32_t n_max_pipes_per_subport,
824 : : uint64_t rate)
825 : : {
826 : : uint32_t i;
827 : :
828 : : /* Check user parameters */
829 [ - + ]: 1 : if (params == NULL) {
830 : 0 : SCHED_LOG(ERR,
831 : : "%s: Incorrect value for parameter params", __func__);
832 : 0 : return -EINVAL;
833 : : }
834 : :
835 : : /* qsize: if non-zero, power of 2,
836 : : * no bigger than 32K (due to 16-bit read/write pointers)
837 : : */
838 [ + + ]: 14 : for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++) {
839 : 13 : uint16_t qsize = params->qsize[i];
840 : :
841 [ + - - + ]: 13 : if (qsize != 0 && !rte_is_power_of_2(qsize)) {
842 : 0 : SCHED_LOG(ERR,
843 : : "%s: Incorrect value for qsize", __func__);
844 : 0 : return -EINVAL;
845 : : }
846 : : }
847 : :
848 [ - + ]: 1 : if (params->qsize[RTE_SCHED_TRAFFIC_CLASS_BE] == 0) {
849 : 0 : SCHED_LOG(ERR, "%s: Incorrect qsize", __func__);
850 : 0 : return -EINVAL;
851 : : }
852 : :
853 : : /* n_pipes_per_subport: non-zero, power of 2 */
854 [ + - + - ]: 1 : if (params->n_pipes_per_subport_enabled == 0 ||
855 : : params->n_pipes_per_subport_enabled > n_max_pipes_per_subport ||
856 : : !rte_is_power_of_2(params->n_pipes_per_subport_enabled)) {
857 : 0 : SCHED_LOG(ERR,
858 : : "%s: Incorrect value for pipes number", __func__);
859 : 0 : return -EINVAL;
860 : : }
861 : :
862 : : /* pipe_profiles and n_pipe_profiles */
863 [ + - ]: 1 : if (params->pipe_profiles == NULL ||
864 [ + - ]: 1 : params->n_pipe_profiles == 0 ||
865 [ + - - + ]: 1 : params->n_max_pipe_profiles == 0 ||
866 : : params->n_pipe_profiles > params->n_max_pipe_profiles) {
867 : 0 : SCHED_LOG(ERR,
868 : : "%s: Incorrect value for pipe profiles", __func__);
869 : 0 : return -EINVAL;
870 : : }
871 : :
872 [ + + ]: 2 : for (i = 0; i < params->n_pipe_profiles; i++) {
873 : 1 : struct rte_sched_pipe_params *p = params->pipe_profiles + i;
874 : : int status;
875 : :
876 : 1 : status = pipe_profile_check(p, rate, ¶ms->qsize[0]);
877 [ - + ]: 1 : if (status != 0) {
878 : 0 : SCHED_LOG(ERR,
879 : : "%s: Pipe profile check failed(%d)", __func__, status);
880 : 0 : return -EINVAL;
881 : : }
882 : : }
883 : :
884 : : return 0;
885 : : }
886 : :
887 : : RTE_EXPORT_SYMBOL(rte_sched_port_get_memory_footprint)
888 : : uint32_t
889 : 0 : rte_sched_port_get_memory_footprint(struct rte_sched_port_params *port_params,
890 : : struct rte_sched_subport_params **subport_params)
891 : : {
892 : : uint32_t size0 = 0, size1 = 0, i;
893 : : int status;
894 : :
895 : 0 : status = rte_sched_port_check_params(port_params);
896 [ # # ]: 0 : if (status != 0) {
897 : 0 : SCHED_LOG(ERR,
898 : : "%s: Port scheduler port params check failed (%d)",
899 : : __func__, status);
900 : :
901 : 0 : return 0;
902 : : }
903 : :
904 [ # # ]: 0 : for (i = 0; i < port_params->n_subports_per_port; i++) {
905 : 0 : struct rte_sched_subport_params *sp = subport_params[i];
906 : :
907 : 0 : status = rte_sched_subport_check_params(sp,
908 : : port_params->n_pipes_per_subport,
909 : : port_params->rate);
910 [ # # ]: 0 : if (status != 0) {
911 : 0 : SCHED_LOG(ERR,
912 : : "%s: Port scheduler subport params check failed (%d)",
913 : : __func__, status);
914 : :
915 : 0 : return 0;
916 : : }
917 : : }
918 : :
919 : : size0 = sizeof(struct rte_sched_port);
920 : :
921 [ # # ]: 0 : for (i = 0; i < port_params->n_subports_per_port; i++) {
922 : 0 : struct rte_sched_subport_params *sp = subport_params[i];
923 : :
924 : 0 : size1 += rte_sched_subport_get_array_base(sp,
925 : : e_RTE_SCHED_SUBPORT_ARRAY_TOTAL);
926 : : }
927 : :
928 : 0 : return size0 + size1;
929 : : }
930 : :
931 : : RTE_EXPORT_SYMBOL(rte_sched_port_config)
932 : : struct rte_sched_port *
933 : 1 : rte_sched_port_config(struct rte_sched_port_params *params)
934 : : {
935 : : struct rte_sched_port *port = NULL;
936 : : uint32_t size0, size1, size2;
937 : : uint32_t cycles_per_byte;
938 : : uint32_t i, j;
939 : : int status;
940 : :
941 : 1 : status = rte_sched_port_check_params(params);
942 [ - + ]: 1 : if (status != 0) {
943 : 0 : SCHED_LOG(ERR,
944 : : "%s: Port scheduler params check failed (%d)",
945 : : __func__, status);
946 : 0 : return NULL;
947 : : }
948 : :
949 : : size0 = sizeof(struct rte_sched_port);
950 : 1 : size1 = params->n_subports_per_port * sizeof(struct rte_sched_subport *);
951 : 1 : size2 = params->n_max_subport_profiles *
952 : : sizeof(struct rte_sched_subport_profile);
953 : :
954 : : /* Allocate memory to store the data structures */
955 : 1 : port = rte_zmalloc_socket("qos_params", size0 + size1,
956 : : RTE_CACHE_LINE_SIZE, params->socket);
957 [ - + ]: 1 : if (port == NULL) {
958 : 0 : SCHED_LOG(ERR, "%s: Memory allocation fails", __func__);
959 : :
960 : 0 : return NULL;
961 : : }
962 : :
963 : : /* Allocate memory to store the subport profile */
964 : 1 : port->subport_profiles = rte_zmalloc_socket("subport_profile", size2,
965 : : RTE_CACHE_LINE_SIZE, params->socket);
966 [ - + ]: 1 : if (port->subport_profiles == NULL) {
967 : 0 : SCHED_LOG(ERR, "%s: Memory allocation fails", __func__);
968 : 0 : rte_free(port);
969 : 0 : return NULL;
970 : : }
971 : :
972 : : /* User parameters */
973 : 1 : port->n_subports_per_port = params->n_subports_per_port;
974 : 1 : port->n_subport_profiles = params->n_subport_profiles;
975 : 1 : port->n_max_subport_profiles = params->n_max_subport_profiles;
976 : 1 : port->n_pipes_per_subport = params->n_pipes_per_subport;
977 : 1 : port->n_pipes_per_subport_log2 =
978 : : rte_ctz32(params->n_pipes_per_subport);
979 : 1 : port->socket = params->socket;
980 : :
981 [ + + ]: 14 : for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
982 : 13 : port->pipe_queue[i] = i;
983 : :
984 [ + + ]: 17 : for (i = 0, j = 0; i < RTE_SCHED_QUEUES_PER_PIPE; i++) {
985 : 16 : port->pipe_tc[i] = j;
986 : :
987 [ + + ]: 16 : if (j < RTE_SCHED_TRAFFIC_CLASS_BE)
988 : 12 : j++;
989 : : }
990 : :
991 [ + + ]: 17 : for (i = 0, j = 0; i < RTE_SCHED_QUEUES_PER_PIPE; i++) {
992 : 16 : port->tc_queue[i] = j;
993 : :
994 [ + + ]: 16 : if (i >= RTE_SCHED_TRAFFIC_CLASS_BE)
995 : 4 : j++;
996 : : }
997 : 1 : port->rate = params->rate;
998 : 1 : port->mtu = params->mtu + params->frame_overhead;
999 : 1 : port->frame_overhead = params->frame_overhead;
1000 : :
1001 : : /* Timing */
1002 : 1 : port->time_cpu_cycles = rte_get_tsc_cycles();
1003 : 1 : port->time_cpu_bytes = 0;
1004 : 1 : port->time = 0;
1005 : :
1006 : : /* Subport profile table */
1007 : 1 : rte_sched_port_config_subport_profile_table(port, params, port->rate);
1008 : :
1009 : 1 : cycles_per_byte = (rte_get_tsc_hz() << RTE_SCHED_TIME_SHIFT)
1010 : 1 : / params->rate;
1011 : 1 : port->inv_cycles_per_byte = rte_reciprocal_value(cycles_per_byte);
1012 : 1 : port->cycles_per_byte = cycles_per_byte;
1013 : :
1014 : : /* Grinders */
1015 : 1 : port->pkts_out = NULL;
1016 : 1 : port->n_pkts_out = 0;
1017 : 1 : port->subport_id = 0;
1018 : :
1019 : 1 : return port;
1020 : : }
1021 : :
1022 : : static inline void
1023 : 1 : rte_sched_subport_free(struct rte_sched_port *port,
1024 : : struct rte_sched_subport *subport)
1025 : : {
1026 : : uint32_t n_subport_pipe_queues;
1027 : : uint32_t qindex;
1028 : :
1029 [ + - ]: 1 : if (subport == NULL)
1030 : : return;
1031 : :
1032 : : n_subport_pipe_queues = rte_sched_subport_pipe_queues(subport);
1033 : :
1034 : : /* Free enqueued mbufs */
1035 [ + + ]: 16385 : for (qindex = 0; qindex < n_subport_pipe_queues; qindex++) {
1036 : : struct rte_mbuf **mbufs =
1037 : : rte_sched_subport_pipe_qbase(subport, qindex);
1038 : : uint16_t qsize = rte_sched_subport_pipe_qsize(port, subport, qindex);
1039 [ + - ]: 16384 : if (qsize != 0) {
1040 : 16384 : struct rte_sched_queue *queue = subport->queue + qindex;
1041 : 16384 : uint16_t qr = queue->qr & (qsize - 1);
1042 : 16384 : uint16_t qw = queue->qw & (qsize - 1);
1043 : :
1044 [ - + ]: 16384 : for (; qr != qw; qr = (qr + 1) & (qsize - 1))
1045 : 0 : rte_pktmbuf_free(mbufs[qr]);
1046 : : }
1047 : : }
1048 : :
1049 : 1 : rte_free(subport);
1050 : : }
1051 : :
1052 : : RTE_EXPORT_SYMBOL(rte_sched_port_free)
1053 : : void
1054 : 1 : rte_sched_port_free(struct rte_sched_port *port)
1055 : : {
1056 : : uint32_t i;
1057 : :
1058 : : /* Check user parameters */
1059 [ + - ]: 1 : if (port == NULL)
1060 : : return;
1061 : :
1062 [ + + ]: 2 : for (i = 0; i < port->n_subports_per_port; i++)
1063 : 1 : rte_sched_subport_free(port, port->subports[i]);
1064 : :
1065 : 1 : rte_free(port->subport_profiles);
1066 : 1 : rte_free(port);
1067 : : }
1068 : :
1069 : : static void
1070 : 0 : rte_sched_free_memory(struct rte_sched_port *port, uint32_t n_subports)
1071 : : {
1072 : : uint32_t i;
1073 : :
1074 [ # # ]: 0 : for (i = 0; i < n_subports; i++) {
1075 : 0 : struct rte_sched_subport *subport = port->subports[i];
1076 : :
1077 : 0 : rte_sched_subport_free(port, subport);
1078 : : }
1079 : :
1080 : 0 : rte_free(port->subport_profiles);
1081 : 0 : rte_free(port);
1082 : 0 : }
1083 : :
1084 : : static int
1085 : 0 : rte_sched_red_config(struct rte_sched_port *port,
1086 : : struct rte_sched_subport *s,
1087 : : struct rte_sched_subport_params *params,
1088 : : uint32_t n_subports)
1089 : : {
1090 : : uint32_t i;
1091 : :
1092 [ # # ]: 0 : for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++) {
1093 : :
1094 : : uint32_t j;
1095 : :
1096 [ # # ]: 0 : for (j = 0; j < RTE_COLORS; j++) {
1097 : : /* if min/max are both zero, then RED is disabled */
1098 : 0 : if ((params->cman_params->red_params[i][j].min_th |
1099 [ # # ]: 0 : params->cman_params->red_params[i][j].max_th) == 0) {
1100 : 0 : continue;
1101 : : }
1102 : :
1103 [ # # ]: 0 : if (rte_red_config_init(&s->red_config[i][j],
1104 : 0 : params->cman_params->red_params[i][j].wq_log2,
1105 : : params->cman_params->red_params[i][j].min_th,
1106 : : params->cman_params->red_params[i][j].max_th,
1107 : 0 : params->cman_params->red_params[i][j].maxp_inv) != 0) {
1108 : 0 : rte_sched_free_memory(port, n_subports);
1109 : :
1110 : 0 : SCHED_LOG(NOTICE,
1111 : : "%s: RED configuration init fails", __func__);
1112 : 0 : return -EINVAL;
1113 : : }
1114 : : }
1115 : : }
1116 : 0 : s->cman = RTE_SCHED_CMAN_RED;
1117 : 0 : return 0;
1118 : : }
1119 : :
1120 : : static int
1121 : 0 : rte_sched_pie_config(struct rte_sched_port *port,
1122 : : struct rte_sched_subport *s,
1123 : : struct rte_sched_subport_params *params,
1124 : : uint32_t n_subports)
1125 : : {
1126 : : uint32_t i;
1127 : :
1128 [ # # ]: 0 : for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++) {
1129 [ # # ]: 0 : if (params->cman_params->pie_params[i].tailq_th > params->qsize[i]) {
1130 : 0 : SCHED_LOG(NOTICE,
1131 : : "%s: PIE tailq threshold incorrect", __func__);
1132 : 0 : return -EINVAL;
1133 : : }
1134 : :
1135 [ # # ]: 0 : if (rte_pie_config_init(&s->pie_config[i],
1136 : 0 : params->cman_params->pie_params[i].qdelay_ref,
1137 : 0 : params->cman_params->pie_params[i].dp_update_interval,
1138 : 0 : params->cman_params->pie_params[i].max_burst,
1139 : : params->cman_params->pie_params[i].tailq_th) != 0) {
1140 : 0 : rte_sched_free_memory(port, n_subports);
1141 : :
1142 : 0 : SCHED_LOG(NOTICE,
1143 : : "%s: PIE configuration init fails", __func__);
1144 : 0 : return -EINVAL;
1145 : : }
1146 : : }
1147 : 0 : s->cman = RTE_SCHED_CMAN_PIE;
1148 : 0 : return 0;
1149 : : }
1150 : :
1151 : : static int
1152 : 0 : rte_sched_cman_config(struct rte_sched_port *port,
1153 : : struct rte_sched_subport *s,
1154 : : struct rte_sched_subport_params *params,
1155 : : uint32_t n_subports)
1156 : : {
1157 [ # # ]: 0 : if (params->cman_params->cman_mode == RTE_SCHED_CMAN_RED)
1158 : 0 : return rte_sched_red_config(port, s, params, n_subports);
1159 : :
1160 [ # # ]: 0 : else if (params->cman_params->cman_mode == RTE_SCHED_CMAN_PIE)
1161 : 0 : return rte_sched_pie_config(port, s, params, n_subports);
1162 : :
1163 : : return -EINVAL;
1164 : : }
1165 : :
1166 : : RTE_EXPORT_SYMBOL(rte_sched_subport_tc_ov_config)
1167 : : int
1168 : 0 : rte_sched_subport_tc_ov_config(struct rte_sched_port *port,
1169 : : uint32_t subport_id,
1170 : : bool tc_ov_enable)
1171 : : {
1172 : : struct rte_sched_subport *s;
1173 : :
1174 [ # # ]: 0 : if (port == NULL) {
1175 : 0 : SCHED_LOG(ERR,
1176 : : "%s: Incorrect value for parameter port", __func__);
1177 : 0 : return -EINVAL;
1178 : : }
1179 : :
1180 [ # # ]: 0 : if (subport_id >= port->n_subports_per_port) {
1181 : 0 : SCHED_LOG(ERR,
1182 : : "%s: Incorrect value for parameter subport id", __func__);
1183 : 0 : return -EINVAL;
1184 : : }
1185 : :
1186 : 0 : s = port->subports[subport_id];
1187 : 0 : s->tc_ov_enabled = tc_ov_enable ? 1 : 0;
1188 : :
1189 : 0 : return 0;
1190 : : }
1191 : :
1192 : : RTE_EXPORT_SYMBOL(rte_sched_subport_config)
1193 : : int
1194 : 1 : rte_sched_subport_config(struct rte_sched_port *port,
1195 : : uint32_t subport_id,
1196 : : struct rte_sched_subport_params *params,
1197 : : uint32_t subport_profile_id)
1198 : : {
1199 : : struct rte_sched_subport *s = NULL;
1200 : : uint32_t n_subports = subport_id;
1201 : : struct rte_sched_subport_profile *profile;
1202 : : uint32_t n_subport_pipe_queues, i;
1203 : : uint32_t size0, size1, bmp_mem_size;
1204 : : int status;
1205 : : int ret;
1206 : :
1207 : : /* Check user parameters */
1208 [ - + ]: 1 : if (port == NULL) {
1209 : 0 : SCHED_LOG(ERR,
1210 : : "%s: Incorrect value for parameter port", __func__);
1211 : 0 : return 0;
1212 : : }
1213 : :
1214 [ - + ]: 1 : if (subport_id >= port->n_subports_per_port) {
1215 : 0 : SCHED_LOG(ERR,
1216 : : "%s: Incorrect value for subport id", __func__);
1217 : : ret = -EINVAL;
1218 : 0 : goto out;
1219 : : }
1220 : :
1221 [ - + ]: 1 : if (subport_profile_id >= port->n_max_subport_profiles) {
1222 : 0 : SCHED_LOG(ERR, "%s: "
1223 : : "Number of subport profile exceeds the max limit",
1224 : : __func__);
1225 : : ret = -EINVAL;
1226 : 0 : goto out;
1227 : : }
1228 : :
1229 : : /** Memory is allocated only on first invocation of the api for a
1230 : : * given subport. Subsequent invocation on same subport will just
1231 : : * update subport bandwidth parameter.
1232 : : */
1233 [ + - ]: 1 : if (port->subports[subport_id] == NULL) {
1234 : :
1235 : 1 : status = rte_sched_subport_check_params(params,
1236 : : port->n_pipes_per_subport,
1237 : : port->rate);
1238 [ - + ]: 1 : if (status != 0) {
1239 : 0 : SCHED_LOG(NOTICE,
1240 : : "%s: Port scheduler params check failed (%d)",
1241 : : __func__, status);
1242 : : ret = -EINVAL;
1243 : 0 : goto out;
1244 : : }
1245 : :
1246 : : /* Determine the amount of memory to allocate */
1247 : : size0 = sizeof(struct rte_sched_subport);
1248 : 1 : size1 = rte_sched_subport_get_array_base(params,
1249 : : e_RTE_SCHED_SUBPORT_ARRAY_TOTAL);
1250 : :
1251 : : /* Allocate memory to store the data structures */
1252 : 1 : s = rte_zmalloc_socket("subport_params", size0 + size1,
1253 : : RTE_CACHE_LINE_SIZE, port->socket);
1254 [ - + ]: 1 : if (s == NULL) {
1255 : 0 : SCHED_LOG(ERR,
1256 : : "%s: Memory allocation fails", __func__);
1257 : : ret = -ENOMEM;
1258 : 0 : goto out;
1259 : : }
1260 : :
1261 : 1 : n_subports++;
1262 : :
1263 : : /* Port */
1264 : 1 : port->subports[subport_id] = s;
1265 : :
1266 : 1 : s->tb_time = port->time;
1267 : :
1268 : : /* compile time checks */
1269 : : RTE_BUILD_BUG_ON(RTE_SCHED_PORT_N_GRINDERS == 0);
1270 : : RTE_BUILD_BUG_ON(RTE_SCHED_PORT_N_GRINDERS &
1271 : : (RTE_SCHED_PORT_N_GRINDERS - 1));
1272 : :
1273 : : /* User parameters */
1274 : 1 : s->n_pipes_per_subport_enabled =
1275 : 1 : params->n_pipes_per_subport_enabled;
1276 [ - + ]: 1 : memcpy(s->qsize, params->qsize, sizeof(params->qsize));
1277 : 1 : s->n_pipe_profiles = params->n_pipe_profiles;
1278 : 1 : s->n_max_pipe_profiles = params->n_max_pipe_profiles;
1279 : :
1280 : : /* TC oversubscription is enabled by default */
1281 : 1 : s->tc_ov_enabled = 1;
1282 : :
1283 [ - + ]: 1 : if (params->cman_params != NULL) {
1284 : 0 : s->cman_enabled = true;
1285 : 0 : status = rte_sched_cman_config(port, s, params, n_subports);
1286 [ # # ]: 0 : if (status) {
1287 : 0 : SCHED_LOG(NOTICE,
1288 : : "%s: CMAN configuration fails", __func__);
1289 : 0 : return status;
1290 : : }
1291 : : } else {
1292 : 1 : s->cman_enabled = false;
1293 : : }
1294 : :
1295 : : /* Scheduling loop detection */
1296 : 1 : s->pipe_loop = RTE_SCHED_PIPE_INVALID;
1297 : 1 : s->pipe_exhaustion = 0;
1298 : :
1299 : : /* Grinders */
1300 : 1 : s->busy_grinders = 0;
1301 : :
1302 : : /* Queue base calculation */
1303 : 1 : rte_sched_subport_config_qsize(s);
1304 : :
1305 : : /* Large data structures */
1306 : 1 : s->pipe = (struct rte_sched_pipe *)
1307 : 1 : (s->memory + rte_sched_subport_get_array_base(params,
1308 : : e_RTE_SCHED_SUBPORT_ARRAY_PIPE));
1309 : 1 : s->queue = (struct rte_sched_queue *)
1310 : 1 : (s->memory + rte_sched_subport_get_array_base(params,
1311 : : e_RTE_SCHED_SUBPORT_ARRAY_QUEUE));
1312 : 1 : s->queue_extra = (struct rte_sched_queue_extra *)
1313 : 1 : (s->memory + rte_sched_subport_get_array_base(params,
1314 : : e_RTE_SCHED_SUBPORT_ARRAY_QUEUE_EXTRA));
1315 : 1 : s->pipe_profiles = (struct rte_sched_pipe_profile *)
1316 : 1 : (s->memory + rte_sched_subport_get_array_base(params,
1317 : : e_RTE_SCHED_SUBPORT_ARRAY_PIPE_PROFILES));
1318 : 1 : s->bmp_array = s->memory + rte_sched_subport_get_array_base(
1319 : : params, e_RTE_SCHED_SUBPORT_ARRAY_BMP_ARRAY);
1320 : 1 : s->queue_array = (struct rte_mbuf **)
1321 : 1 : (s->memory + rte_sched_subport_get_array_base(params,
1322 : : e_RTE_SCHED_SUBPORT_ARRAY_QUEUE_ARRAY));
1323 : :
1324 : : /* Pipe profile table */
1325 : 1 : rte_sched_subport_config_pipe_profile_table(s, params,
1326 : : port->rate);
1327 : :
1328 : : /* Bitmap */
1329 : : n_subport_pipe_queues = rte_sched_subport_pipe_queues(s);
1330 : 1 : bmp_mem_size = rte_bitmap_get_memory_footprint(
1331 : : n_subport_pipe_queues);
1332 : 1 : s->bmp = rte_bitmap_init(n_subport_pipe_queues, s->bmp_array,
1333 : : bmp_mem_size);
1334 [ - + ]: 1 : if (s->bmp == NULL) {
1335 : 0 : SCHED_LOG(ERR,
1336 : : "%s: Subport bitmap init error", __func__);
1337 : : ret = -EINVAL;
1338 : 0 : goto out;
1339 : : }
1340 : :
1341 [ + + ]: 9 : for (i = 0; i < RTE_SCHED_PORT_N_GRINDERS; i++)
1342 : 8 : s->grinder_base_bmp_pos[i] = RTE_SCHED_PIPE_INVALID;
1343 : :
1344 : : /* TC oversubscription */
1345 : 1 : s->tc_ov_wm_min = port->mtu;
1346 : 1 : s->tc_ov_period_id = 0;
1347 : 1 : s->tc_ov = 0;
1348 : 1 : s->tc_ov_n = 0;
1349 : 1 : s->tc_ov_rate = 0;
1350 : : }
1351 : :
1352 : : {
1353 : : /* update subport parameters from subport profile table*/
1354 : 1 : profile = port->subport_profiles + subport_profile_id;
1355 : :
1356 : 1 : s = port->subports[subport_id];
1357 : :
1358 : 1 : s->tb_credits = profile->tb_size / 2;
1359 : :
1360 : 1 : s->tc_time = port->time + profile->tc_period;
1361 : :
1362 [ + + ]: 14 : for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
1363 [ + - ]: 13 : if (s->qsize[i])
1364 : 13 : s->tc_credits[i] =
1365 : 13 : profile->tc_credits_per_period[i];
1366 : : else
1367 : 0 : profile->tc_credits_per_period[i] = 0;
1368 : :
1369 : 1 : s->tc_ov_wm_max = rte_sched_time_ms_to_bytes(profile->tc_period,
1370 : : s->pipe_tc_be_rate_max);
1371 : 1 : s->tc_ov_wm = s->tc_ov_wm_max;
1372 : 1 : s->profile = subport_profile_id;
1373 : :
1374 : : }
1375 : :
1376 : 1 : rte_sched_port_log_subport_profile(port, subport_profile_id);
1377 : :
1378 : 1 : return 0;
1379 : :
1380 : 0 : out:
1381 : 0 : rte_sched_free_memory(port, n_subports);
1382 : :
1383 : 0 : return ret;
1384 : : }
1385 : :
1386 : : RTE_EXPORT_SYMBOL(rte_sched_pipe_config)
1387 : : int
1388 : 1024 : rte_sched_pipe_config(struct rte_sched_port *port,
1389 : : uint32_t subport_id,
1390 : : uint32_t pipe_id,
1391 : : int32_t pipe_profile)
1392 : : {
1393 : : struct rte_sched_subport *s;
1394 : : struct rte_sched_subport_profile *sp;
1395 : : struct rte_sched_pipe *p;
1396 : : struct rte_sched_pipe_profile *params;
1397 : 1024 : uint32_t n_subports = subport_id + 1;
1398 : : uint32_t deactivate, profile, i;
1399 : : int ret;
1400 : :
1401 : : /* Check user parameters */
1402 : 1024 : profile = (uint32_t) pipe_profile;
1403 : : deactivate = (pipe_profile < 0);
1404 : :
1405 [ - + ]: 1024 : if (port == NULL) {
1406 : 0 : SCHED_LOG(ERR,
1407 : : "%s: Incorrect value for parameter port", __func__);
1408 : 0 : return -EINVAL;
1409 : : }
1410 : :
1411 [ - + ]: 1024 : if (subport_id >= port->n_subports_per_port) {
1412 : 0 : SCHED_LOG(ERR,
1413 : : "%s: Incorrect value for parameter subport id", __func__);
1414 : : ret = -EINVAL;
1415 : 0 : goto out;
1416 : : }
1417 : :
1418 : 1024 : s = port->subports[subport_id];
1419 [ - + ]: 1024 : if (pipe_id >= s->n_pipes_per_subport_enabled) {
1420 : 0 : SCHED_LOG(ERR,
1421 : : "%s: Incorrect value for parameter pipe id", __func__);
1422 : : ret = -EINVAL;
1423 : 0 : goto out;
1424 : : }
1425 : :
1426 [ + - - + ]: 1024 : if (!deactivate && profile >= s->n_pipe_profiles) {
1427 : 0 : SCHED_LOG(ERR,
1428 : : "%s: Incorrect value for parameter pipe profile", __func__);
1429 : : ret = -EINVAL;
1430 : 0 : goto out;
1431 : : }
1432 : :
1433 : 1024 : sp = port->subport_profiles + s->profile;
1434 : : /* Handle the case when pipe already has a valid configuration */
1435 : 1024 : p = s->pipe + pipe_id;
1436 [ - + ]: 1024 : if (p->tb_time) {
1437 : 0 : params = s->pipe_profiles + p->profile;
1438 : :
1439 : 0 : double subport_tc_be_rate =
1440 : 0 : (double)sp->tc_credits_per_period[RTE_SCHED_TRAFFIC_CLASS_BE]
1441 : 0 : / (double) sp->tc_period;
1442 : 0 : double pipe_tc_be_rate =
1443 : 0 : (double) params->tc_credits_per_period[RTE_SCHED_TRAFFIC_CLASS_BE]
1444 : 0 : / (double) params->tc_period;
1445 : 0 : uint32_t tc_be_ov = s->tc_ov;
1446 : :
1447 : : /* Unplug pipe from its subport */
1448 : 0 : s->tc_ov_n -= params->tc_ov_weight;
1449 : 0 : s->tc_ov_rate -= pipe_tc_be_rate;
1450 : 0 : s->tc_ov = s->tc_ov_rate > subport_tc_be_rate;
1451 : :
1452 [ # # ]: 0 : if (s->tc_ov != tc_be_ov) {
1453 : 0 : SCHED_LOG(DEBUG,
1454 : : "Subport %u Best-effort TC oversubscription is OFF (%.4lf >= %.4lf)",
1455 : : subport_id, subport_tc_be_rate, s->tc_ov_rate);
1456 : : }
1457 : :
1458 : : /* Reset the pipe */
1459 : : memset(p, 0, sizeof(struct rte_sched_pipe));
1460 : : }
1461 : :
1462 [ + - ]: 1024 : if (deactivate)
1463 : : return 0;
1464 : :
1465 : : /* Apply the new pipe configuration */
1466 : 1024 : p->profile = profile;
1467 : 1024 : params = s->pipe_profiles + p->profile;
1468 : :
1469 : : /* Token Bucket (TB) */
1470 : 1024 : p->tb_time = port->time;
1471 : 1024 : p->tb_credits = params->tb_size / 2;
1472 : :
1473 : : /* Traffic Classes (TCs) */
1474 : 1024 : p->tc_time = port->time + params->tc_period;
1475 : :
1476 [ + + ]: 14336 : for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
1477 [ + - ]: 13312 : if (s->qsize[i])
1478 : 13312 : p->tc_credits[i] = params->tc_credits_per_period[i];
1479 : :
1480 : : {
1481 : : /* Subport best effort tc oversubscription */
1482 : 1024 : double subport_tc_be_rate =
1483 : 1024 : (double)sp->tc_credits_per_period[RTE_SCHED_TRAFFIC_CLASS_BE]
1484 : 1024 : / (double) sp->tc_period;
1485 : 1024 : double pipe_tc_be_rate =
1486 : 1024 : (double) params->tc_credits_per_period[RTE_SCHED_TRAFFIC_CLASS_BE]
1487 : 1024 : / (double) params->tc_period;
1488 : 1024 : uint32_t tc_be_ov = s->tc_ov;
1489 : :
1490 : 1024 : s->tc_ov_n += params->tc_ov_weight;
1491 : 1024 : s->tc_ov_rate += pipe_tc_be_rate;
1492 : 1024 : s->tc_ov = s->tc_ov_rate > subport_tc_be_rate;
1493 : :
1494 [ - + ]: 1024 : if (s->tc_ov != tc_be_ov) {
1495 : 0 : SCHED_LOG(DEBUG,
1496 : : "Subport %u Best effort TC oversubscription is ON (%.4lf < %.4lf)",
1497 : : subport_id, subport_tc_be_rate, s->tc_ov_rate);
1498 : : }
1499 : 1024 : p->tc_ov_period_id = s->tc_ov_period_id;
1500 : 1024 : p->tc_ov_credits = s->tc_ov_wm;
1501 : : }
1502 : :
1503 : 1024 : return 0;
1504 : :
1505 : 0 : out:
1506 : 0 : rte_sched_free_memory(port, n_subports);
1507 : :
1508 : 0 : return ret;
1509 : : }
1510 : :
1511 : : RTE_EXPORT_SYMBOL(rte_sched_subport_pipe_profile_add)
1512 : : int
1513 : 0 : rte_sched_subport_pipe_profile_add(struct rte_sched_port *port,
1514 : : uint32_t subport_id,
1515 : : struct rte_sched_pipe_params *params,
1516 : : uint32_t *pipe_profile_id)
1517 : : {
1518 : : struct rte_sched_subport *s;
1519 : : struct rte_sched_pipe_profile *pp;
1520 : : uint32_t i;
1521 : : int status;
1522 : :
1523 : : /* Port */
1524 [ # # ]: 0 : if (port == NULL) {
1525 : 0 : SCHED_LOG(ERR,
1526 : : "%s: Incorrect value for parameter port", __func__);
1527 : 0 : return -EINVAL;
1528 : : }
1529 : :
1530 : : /* Subport id not exceeds the max limit */
1531 [ # # ]: 0 : if (subport_id > port->n_subports_per_port) {
1532 : 0 : SCHED_LOG(ERR,
1533 : : "%s: Incorrect value for subport id", __func__);
1534 : 0 : return -EINVAL;
1535 : : }
1536 : :
1537 : 0 : s = port->subports[subport_id];
1538 : :
1539 : : /* Pipe profiles exceeds the max limit */
1540 [ # # ]: 0 : if (s->n_pipe_profiles >= s->n_max_pipe_profiles) {
1541 : 0 : SCHED_LOG(ERR,
1542 : : "%s: Number of pipe profiles exceeds the max limit", __func__);
1543 : 0 : return -EINVAL;
1544 : : }
1545 : :
1546 : : /* Pipe params */
1547 : 0 : status = pipe_profile_check(params, port->rate, &s->qsize[0]);
1548 [ # # ]: 0 : if (status != 0) {
1549 : 0 : SCHED_LOG(ERR,
1550 : : "%s: Pipe profile check failed(%d)", __func__, status);
1551 : 0 : return -EINVAL;
1552 : : }
1553 : :
1554 : 0 : pp = &s->pipe_profiles[s->n_pipe_profiles];
1555 : 0 : rte_sched_pipe_profile_convert(s, params, pp, port->rate);
1556 : :
1557 : : /* Pipe profile should not exists */
1558 [ # # ]: 0 : for (i = 0; i < s->n_pipe_profiles; i++)
1559 [ # # ]: 0 : if (memcmp(s->pipe_profiles + i, pp, sizeof(*pp)) == 0) {
1560 : 0 : SCHED_LOG(ERR,
1561 : : "%s: Pipe profile exists", __func__);
1562 : 0 : return -EINVAL;
1563 : : }
1564 : :
1565 : : /* Pipe profile commit */
1566 : 0 : *pipe_profile_id = s->n_pipe_profiles;
1567 : 0 : s->n_pipe_profiles++;
1568 : :
1569 [ # # ]: 0 : if (s->pipe_tc_be_rate_max < params->tc_rate[RTE_SCHED_TRAFFIC_CLASS_BE])
1570 : 0 : s->pipe_tc_be_rate_max = params->tc_rate[RTE_SCHED_TRAFFIC_CLASS_BE];
1571 : :
1572 : 0 : rte_sched_port_log_pipe_profile(s, *pipe_profile_id);
1573 : :
1574 : 0 : return 0;
1575 : : }
1576 : :
1577 : : RTE_EXPORT_SYMBOL(rte_sched_port_subport_profile_add)
1578 : : int
1579 : 0 : rte_sched_port_subport_profile_add(struct rte_sched_port *port,
1580 : : struct rte_sched_subport_profile_params *params,
1581 : : uint32_t *subport_profile_id)
1582 : : {
1583 : : int status;
1584 : : uint32_t i;
1585 : : struct rte_sched_subport_profile *dst;
1586 : :
1587 : : /* Port */
1588 [ # # ]: 0 : if (port == NULL) {
1589 : 0 : SCHED_LOG(ERR, "%s: "
1590 : : "Incorrect value for parameter port", __func__);
1591 : 0 : return -EINVAL;
1592 : : }
1593 : :
1594 [ # # ]: 0 : if (params == NULL) {
1595 : 0 : SCHED_LOG(ERR, "%s: "
1596 : : "Incorrect value for parameter profile", __func__);
1597 : 0 : return -EINVAL;
1598 : : }
1599 : :
1600 [ # # ]: 0 : if (subport_profile_id == NULL) {
1601 : 0 : SCHED_LOG(ERR, "%s: "
1602 : : "Incorrect value for parameter subport_profile_id",
1603 : : __func__);
1604 : 0 : return -EINVAL;
1605 : : }
1606 : :
1607 : 0 : dst = port->subport_profiles + port->n_subport_profiles;
1608 : :
1609 : : /* Subport profiles exceeds the max limit */
1610 [ # # ]: 0 : if (port->n_subport_profiles >= port->n_max_subport_profiles) {
1611 : 0 : SCHED_LOG(ERR, "%s: "
1612 : : "Number of subport profiles exceeds the max limit",
1613 : : __func__);
1614 : 0 : return -EINVAL;
1615 : : }
1616 : :
1617 : 0 : status = subport_profile_check(params, port->rate);
1618 [ # # ]: 0 : if (status != 0) {
1619 : 0 : SCHED_LOG(ERR,
1620 : : "%s: subport profile check failed(%d)", __func__, status);
1621 : 0 : return -EINVAL;
1622 : : }
1623 : :
1624 : 0 : rte_sched_subport_profile_convert(params, dst, port->rate);
1625 : :
1626 : : /* Subport profile should not exists */
1627 [ # # ]: 0 : for (i = 0; i < port->n_subport_profiles; i++)
1628 [ # # ]: 0 : if (memcmp(port->subport_profiles + i,
1629 : : dst, sizeof(*dst)) == 0) {
1630 : 0 : SCHED_LOG(ERR,
1631 : : "%s: subport profile exists", __func__);
1632 : 0 : return -EINVAL;
1633 : : }
1634 : :
1635 : : /* Subport profile commit */
1636 : 0 : *subport_profile_id = port->n_subport_profiles;
1637 : 0 : port->n_subport_profiles++;
1638 : :
1639 : 0 : rte_sched_port_log_subport_profile(port, *subport_profile_id);
1640 : :
1641 : 0 : return 0;
1642 : : }
1643 : :
1644 : : static inline uint32_t
1645 : : rte_sched_port_qindex(struct rte_sched_port *port,
1646 : : uint32_t subport,
1647 : : uint32_t pipe,
1648 : : uint32_t traffic_class,
1649 : : uint32_t queue)
1650 : : {
1651 : 10 : return ((subport & (port->n_subports_per_port - 1)) <<
1652 : 10 : (port->n_pipes_per_subport_log2 + 4)) |
1653 : 10 : ((pipe &
1654 : 10 : (port->subports[subport]->n_pipes_per_subport_enabled - 1)) << 4) |
1655 : 10 : ((rte_sched_port_pipe_queue(port, traffic_class) + queue) &
1656 : : (RTE_SCHED_QUEUES_PER_PIPE - 1));
1657 : : }
1658 : :
1659 : : RTE_EXPORT_SYMBOL(rte_sched_port_pkt_write)
1660 : : void
1661 : 10 : rte_sched_port_pkt_write(struct rte_sched_port *port,
1662 : : struct rte_mbuf *pkt,
1663 : : uint32_t subport, uint32_t pipe,
1664 : : uint32_t traffic_class,
1665 : : uint32_t queue, enum rte_color color)
1666 : : {
1667 : : uint32_t queue_id =
1668 : : rte_sched_port_qindex(port, subport, pipe, traffic_class, queue);
1669 : :
1670 : 10 : rte_mbuf_sched_set(pkt, queue_id, traffic_class, (uint8_t)color);
1671 : 10 : }
1672 : :
1673 : : RTE_EXPORT_SYMBOL(rte_sched_port_pkt_read_tree_path)
1674 : : void
1675 : 10 : rte_sched_port_pkt_read_tree_path(struct rte_sched_port *port,
1676 : : const struct rte_mbuf *pkt,
1677 : : uint32_t *subport, uint32_t *pipe,
1678 : : uint32_t *traffic_class, uint32_t *queue)
1679 : : {
1680 : : uint32_t queue_id = rte_mbuf_sched_queue_get(pkt);
1681 : :
1682 : 10 : *subport = queue_id >> (port->n_pipes_per_subport_log2 + 4);
1683 : 10 : *pipe = (queue_id >> 4) &
1684 : 10 : (port->subports[*subport]->n_pipes_per_subport_enabled - 1);
1685 : 10 : *traffic_class = rte_sched_port_pipe_tc(port, queue_id);
1686 : 10 : *queue = rte_sched_port_tc_queue(port, queue_id);
1687 : 10 : }
1688 : :
1689 : : RTE_EXPORT_SYMBOL(rte_sched_port_pkt_read_color)
1690 : : enum rte_color
1691 : 10 : rte_sched_port_pkt_read_color(const struct rte_mbuf *pkt)
1692 : : {
1693 : 10 : return (enum rte_color)rte_mbuf_sched_color_get(pkt);
1694 : : }
1695 : :
1696 : : RTE_EXPORT_SYMBOL(rte_sched_subport_read_stats)
1697 : : int
1698 : 1 : rte_sched_subport_read_stats(struct rte_sched_port *port,
1699 : : uint32_t subport_id,
1700 : : struct rte_sched_subport_stats *stats,
1701 : : uint32_t *tc_ov)
1702 : : {
1703 : : struct rte_sched_subport *s;
1704 : :
1705 : : /* Check user parameters */
1706 [ - + ]: 1 : if (port == NULL) {
1707 : 0 : SCHED_LOG(ERR,
1708 : : "%s: Incorrect value for parameter port", __func__);
1709 : 0 : return -EINVAL;
1710 : : }
1711 : :
1712 [ - + ]: 1 : if (subport_id >= port->n_subports_per_port) {
1713 : 0 : SCHED_LOG(ERR,
1714 : : "%s: Incorrect value for subport id", __func__);
1715 : 0 : return -EINVAL;
1716 : : }
1717 : :
1718 [ - + ]: 1 : if (stats == NULL) {
1719 : 0 : SCHED_LOG(ERR,
1720 : : "%s: Incorrect value for parameter stats", __func__);
1721 : 0 : return -EINVAL;
1722 : : }
1723 : :
1724 [ - + ]: 1 : if (tc_ov == NULL) {
1725 : 0 : SCHED_LOG(ERR,
1726 : : "%s: Incorrect value for tc_ov", __func__);
1727 : 0 : return -EINVAL;
1728 : : }
1729 : :
1730 : 1 : s = port->subports[subport_id];
1731 : :
1732 : : /* Copy subport stats and clear */
1733 : 1 : memcpy(stats, &s->stats, sizeof(struct rte_sched_subport_stats));
1734 : : memset(&s->stats, 0, sizeof(struct rte_sched_subport_stats));
1735 : :
1736 : : /* Subport TC oversubscription status */
1737 : 1 : *tc_ov = s->tc_ov;
1738 : :
1739 : 1 : return 0;
1740 : : }
1741 : :
1742 : : RTE_EXPORT_SYMBOL(rte_sched_queue_read_stats)
1743 : : int
1744 : 1 : rte_sched_queue_read_stats(struct rte_sched_port *port,
1745 : : uint32_t queue_id,
1746 : : struct rte_sched_queue_stats *stats,
1747 : : uint16_t *qlen)
1748 : : {
1749 : : struct rte_sched_subport *s;
1750 : : struct rte_sched_queue *q;
1751 : : struct rte_sched_queue_extra *qe;
1752 : : uint32_t subport_id, subport_qmask, subport_qindex;
1753 : :
1754 : : /* Check user parameters */
1755 [ - + ]: 1 : if (port == NULL) {
1756 : 0 : SCHED_LOG(ERR,
1757 : : "%s: Incorrect value for parameter port", __func__);
1758 : 0 : return -EINVAL;
1759 : : }
1760 : :
1761 [ - + ]: 1 : if (queue_id >= rte_sched_port_queues_per_port(port)) {
1762 : 0 : SCHED_LOG(ERR,
1763 : : "%s: Incorrect value for queue id", __func__);
1764 : 0 : return -EINVAL;
1765 : : }
1766 : :
1767 [ - + ]: 1 : if (stats == NULL) {
1768 : 0 : SCHED_LOG(ERR,
1769 : : "%s: Incorrect value for parameter stats", __func__);
1770 : 0 : return -EINVAL;
1771 : : }
1772 : :
1773 [ - + ]: 1 : if (qlen == NULL) {
1774 : 0 : SCHED_LOG(ERR,
1775 : : "%s: Incorrect value for parameter qlen", __func__);
1776 : 0 : return -EINVAL;
1777 : : }
1778 : 1 : subport_qmask = port->n_pipes_per_subport_log2 + 4;
1779 : 1 : subport_id = (queue_id >> subport_qmask) & (port->n_subports_per_port - 1);
1780 : :
1781 : 1 : s = port->subports[subport_id];
1782 : 1 : subport_qindex = ((1 << subport_qmask) - 1) & queue_id;
1783 : 1 : q = s->queue + subport_qindex;
1784 : 1 : qe = s->queue_extra + subport_qindex;
1785 : :
1786 : : /* Copy queue stats and clear */
1787 : 1 : memcpy(stats, &qe->stats, sizeof(struct rte_sched_queue_stats));
1788 : : memset(&qe->stats, 0, sizeof(struct rte_sched_queue_stats));
1789 : :
1790 : : /* Queue length */
1791 : 1 : *qlen = q->qw - q->qr;
1792 : :
1793 : 1 : return 0;
1794 : : }
1795 : :
1796 : : #ifdef RTE_SCHED_DEBUG
1797 : :
1798 : : static inline int
1799 : : rte_sched_port_queue_is_empty(struct rte_sched_subport *subport,
1800 : : uint32_t qindex)
1801 : : {
1802 : : struct rte_sched_queue *queue = subport->queue + qindex;
1803 : :
1804 : : return queue->qr == queue->qw;
1805 : : }
1806 : :
1807 : : #endif /* RTE_SCHED_DEBUG */
1808 : :
1809 : : static inline void
1810 : : rte_sched_port_update_subport_stats(struct rte_sched_port *port,
1811 : : struct rte_sched_subport *subport,
1812 : : uint32_t qindex,
1813 : : struct rte_mbuf *pkt)
1814 : : {
1815 : 10 : uint32_t tc_index = rte_sched_port_pipe_tc(port, qindex);
1816 : 10 : uint32_t pkt_len = pkt->pkt_len;
1817 : :
1818 : 10 : subport->stats.n_pkts_tc[tc_index] += 1;
1819 : 10 : subport->stats.n_bytes_tc[tc_index] += pkt_len;
1820 : : }
1821 : :
1822 : : static inline void
1823 : : rte_sched_port_update_subport_stats_on_drop(struct rte_sched_port *port,
1824 : : struct rte_sched_subport *subport,
1825 : : uint32_t qindex,
1826 : : struct rte_mbuf *pkt,
1827 : : uint32_t n_pkts_cman_dropped)
1828 : : {
1829 : 0 : uint32_t tc_index = rte_sched_port_pipe_tc(port, qindex);
1830 : 0 : uint32_t pkt_len = pkt->pkt_len;
1831 : :
1832 : 0 : subport->stats.n_pkts_tc_dropped[tc_index] += 1;
1833 : 0 : subport->stats.n_bytes_tc_dropped[tc_index] += pkt_len;
1834 : 0 : subport->stats.n_pkts_cman_dropped[tc_index] += n_pkts_cman_dropped;
1835 : : }
1836 : :
1837 : : static inline void
1838 : : rte_sched_port_update_queue_stats(struct rte_sched_subport *subport,
1839 : : uint32_t qindex,
1840 : : struct rte_mbuf *pkt)
1841 : : {
1842 : 10 : struct rte_sched_queue_extra *qe = subport->queue_extra + qindex;
1843 : : uint32_t pkt_len = pkt->pkt_len;
1844 : :
1845 : 10 : qe->stats.n_pkts += 1;
1846 : 10 : qe->stats.n_bytes += pkt_len;
1847 : : }
1848 : :
1849 : : static inline void
1850 : : rte_sched_port_update_queue_stats_on_drop(struct rte_sched_subport *subport,
1851 : : uint32_t qindex,
1852 : : struct rte_mbuf *pkt,
1853 : : uint32_t n_pkts_cman_dropped)
1854 : : {
1855 : 0 : struct rte_sched_queue_extra *qe = subport->queue_extra + qindex;
1856 : : uint32_t pkt_len = pkt->pkt_len;
1857 : :
1858 : 0 : qe->stats.n_pkts_dropped += 1;
1859 : 0 : qe->stats.n_bytes_dropped += pkt_len;
1860 : 0 : if (subport->cman_enabled)
1861 : 0 : qe->stats.n_pkts_cman_dropped += n_pkts_cman_dropped;
1862 : : }
1863 : :
1864 : : static inline int
1865 : 10 : rte_sched_port_cman_drop(struct rte_sched_port *port,
1866 : : struct rte_sched_subport *subport,
1867 : : struct rte_mbuf *pkt,
1868 : : uint32_t qindex,
1869 : : uint16_t qlen)
1870 : : {
1871 [ - + ]: 10 : if (!subport->cman_enabled)
1872 : : return 0;
1873 : :
1874 : : struct rte_sched_queue_extra *qe;
1875 : : uint32_t tc_index;
1876 : :
1877 : 0 : tc_index = rte_sched_port_pipe_tc(port, qindex);
1878 : 0 : qe = subport->queue_extra + qindex;
1879 : :
1880 : : /* RED */
1881 [ # # ]: 0 : if (subport->cman == RTE_SCHED_CMAN_RED) {
1882 : : struct rte_red_config *red_cfg;
1883 : : struct rte_red *red;
1884 : : enum rte_color color;
1885 : :
1886 : 0 : color = rte_sched_port_pkt_read_color(pkt);
1887 : 0 : red_cfg = &subport->red_config[tc_index][color];
1888 : :
1889 [ # # ]: 0 : if ((red_cfg->min_th | red_cfg->max_th) == 0)
1890 : : return 0;
1891 : :
1892 : 0 : red = &qe->red;
1893 : :
1894 : 0 : return rte_red_enqueue(red_cfg, red, qlen, port->time);
1895 : : }
1896 : :
1897 : : /* PIE */
1898 : 0 : struct rte_pie_config *pie_cfg = &subport->pie_config[tc_index];
1899 : 0 : struct rte_pie *pie = &qe->pie;
1900 : :
1901 : 0 : return rte_pie_enqueue(pie_cfg, pie, qlen, pkt->pkt_len, port->time_cpu_cycles);
1902 : : }
1903 : :
1904 : : static inline void
1905 : : rte_sched_port_red_set_queue_empty_timestamp(struct rte_sched_port *port,
1906 : : struct rte_sched_subport *subport, uint32_t qindex)
1907 : : {
1908 [ - + - - ]: 1 : if (subport->cman_enabled && subport->cman == RTE_SCHED_CMAN_RED) {
1909 : 0 : struct rte_sched_queue_extra *qe = subport->queue_extra + qindex;
1910 : : struct rte_red *red = &qe->red;
1911 : :
1912 : 0 : rte_red_mark_queue_empty(red, port->time);
1913 : : }
1914 : : }
1915 : :
1916 : : static inline void
1917 : 10 : rte_sched_port_pie_dequeue(struct rte_sched_subport *subport,
1918 : : uint32_t qindex, uint32_t pkt_len, uint64_t time) {
1919 [ - + - - ]: 10 : if (subport->cman_enabled && subport->cman == RTE_SCHED_CMAN_PIE) {
1920 : 0 : struct rte_sched_queue_extra *qe = subport->queue_extra + qindex;
1921 : 0 : struct rte_pie *pie = &qe->pie;
1922 : :
1923 : : /* Update queue length */
1924 : 0 : pie->qlen -= 1;
1925 : 0 : pie->qlen_bytes -= pkt_len;
1926 : :
1927 : 0 : rte_pie_dequeue(pie, pkt_len, time);
1928 : : }
1929 : 10 : }
1930 : :
1931 : : #ifdef RTE_SCHED_DEBUG
1932 : :
1933 : : static inline void
1934 : : debug_check_queue_slab(struct rte_sched_subport *subport, uint32_t bmp_pos,
1935 : : uint64_t bmp_slab)
1936 : : {
1937 : : uint64_t mask;
1938 : : uint32_t i, panic;
1939 : :
1940 : : if (bmp_slab == 0)
1941 : : rte_panic("Empty slab at position %u\n", bmp_pos);
1942 : :
1943 : : panic = 0;
1944 : : for (i = 0, mask = 1; i < 64; i++, mask <<= 1) {
1945 : : if (mask & bmp_slab) {
1946 : : if (rte_sched_port_queue_is_empty(subport, bmp_pos + i)) {
1947 : : printf("Queue %u (slab offset %u) is empty\n", bmp_pos + i, i);
1948 : : panic = 1;
1949 : : }
1950 : : }
1951 : : }
1952 : :
1953 : : if (panic)
1954 : : rte_panic("Empty queues in slab 0x%" PRIx64 "starting at position %u\n",
1955 : : bmp_slab, bmp_pos);
1956 : : }
1957 : :
1958 : : #endif /* RTE_SCHED_DEBUG */
1959 : :
1960 : : static inline struct rte_sched_subport *
1961 : : rte_sched_port_subport(struct rte_sched_port *port,
1962 : : struct rte_mbuf *pkt)
1963 : : {
1964 : : uint32_t queue_id = rte_mbuf_sched_queue_get(pkt);
1965 : 6 : uint32_t subport_id = queue_id >> (port->n_pipes_per_subport_log2 + 4);
1966 : :
1967 : 6 : return port->subports[subport_id];
1968 : : }
1969 : :
1970 : : static inline uint32_t
1971 : : rte_sched_port_enqueue_qptrs_prefetch0(struct rte_sched_subport *subport,
1972 : : struct rte_mbuf *pkt, uint32_t subport_qmask)
1973 : : {
1974 : : struct rte_sched_queue *q;
1975 : : struct rte_sched_queue_extra *qe;
1976 : : uint32_t qindex = rte_mbuf_sched_queue_get(pkt);
1977 : 11 : uint32_t subport_queue_id = subport_qmask & qindex;
1978 : :
1979 : 11 : q = subport->queue + subport_queue_id;
1980 : : rte_prefetch0(q);
1981 : 11 : qe = subport->queue_extra + subport_queue_id;
1982 : : rte_prefetch0(qe);
1983 : :
1984 : : return subport_queue_id;
1985 : : }
1986 : :
1987 : : static inline void
1988 : : rte_sched_port_enqueue_qwa_prefetch0(struct rte_sched_port *port,
1989 : : struct rte_sched_subport *subport,
1990 : : uint32_t qindex,
1991 : : struct rte_mbuf **qbase)
1992 : : {
1993 : : struct rte_sched_queue *q;
1994 : : struct rte_mbuf **q_qw;
1995 : : uint16_t qsize;
1996 : :
1997 : 9 : q = subport->queue + qindex;
1998 : : qsize = rte_sched_subport_pipe_qsize(port, subport, qindex);
1999 : 10 : q_qw = qbase + (q->qw & (qsize - 1));
2000 : :
2001 : : rte_prefetch0(q_qw);
2002 : 11 : rte_bitmap_prefetch0(subport->bmp, qindex);
2003 : : }
2004 : :
2005 : : static inline int
2006 : 10 : rte_sched_port_enqueue_qwa(struct rte_sched_port *port,
2007 : : struct rte_sched_subport *subport,
2008 : : uint32_t qindex,
2009 : : struct rte_mbuf **qbase,
2010 : : struct rte_mbuf *pkt)
2011 : : {
2012 : : struct rte_sched_queue *q;
2013 : : uint16_t qsize;
2014 : : uint16_t qlen;
2015 : :
2016 : 10 : q = subport->queue + qindex;
2017 : : qsize = rte_sched_subport_pipe_qsize(port, subport, qindex);
2018 : 10 : qlen = q->qw - q->qr;
2019 : :
2020 : : /* Drop the packet (and update drop stats) when queue is full */
2021 [ + - - + ]: 10 : if (unlikely(rte_sched_port_cman_drop(port, subport, pkt, qindex, qlen) ||
2022 : : (qlen >= qsize))) {
2023 : 0 : rte_pktmbuf_free(pkt);
2024 [ # # ]: 0 : rte_sched_port_update_subport_stats_on_drop(port, subport,
2025 : : qindex, pkt, qlen < qsize);
2026 : : rte_sched_port_update_queue_stats_on_drop(subport, qindex, pkt,
2027 : : qlen < qsize);
2028 : 0 : return 0;
2029 : : }
2030 : :
2031 : : /* Enqueue packet */
2032 : 10 : qbase[q->qw & (qsize - 1)] = pkt;
2033 : 10 : q->qw++;
2034 : :
2035 : : /* Activate queue in the subport bitmap */
2036 : 10 : rte_bitmap_set(subport->bmp, qindex);
2037 : :
2038 : : /* Statistics */
2039 : : rte_sched_port_update_subport_stats(port, subport, qindex, pkt);
2040 : : rte_sched_port_update_queue_stats(subport, qindex, pkt);
2041 : :
2042 : 10 : return 1;
2043 : : }
2044 : :
2045 : :
2046 : : /*
2047 : : * The enqueue function implements a 4-level pipeline with each stage
2048 : : * processing two different packets. The purpose of using a pipeline
2049 : : * is to hide the latency of prefetching the data structures. The
2050 : : * naming convention is presented in the diagram below:
2051 : : *
2052 : : * p00 _______ p10 _______ p20 _______ p30 _______
2053 : : * ----->| |----->| |----->| |----->| |----->
2054 : : * | 0 | | 1 | | 2 | | 3 |
2055 : : * ----->|_______|----->|_______|----->|_______|----->|_______|----->
2056 : : * p01 p11 p21 p31
2057 : : */
2058 : : RTE_EXPORT_SYMBOL(rte_sched_port_enqueue)
2059 : : int
2060 : 1 : rte_sched_port_enqueue(struct rte_sched_port *port, struct rte_mbuf **pkts,
2061 : : uint32_t n_pkts)
2062 : : {
2063 : : struct rte_mbuf *pkt00, *pkt01, *pkt10, *pkt11, *pkt20, *pkt21,
2064 : : *pkt30, *pkt31, *pkt_last;
2065 : : struct rte_mbuf **q00_base, **q01_base, **q10_base, **q11_base,
2066 : : **q20_base, **q21_base, **q30_base, **q31_base, **q_last_base;
2067 : : struct rte_sched_subport *subport00, *subport01, *subport10, *subport11,
2068 : : *subport20, *subport21, *subport30, *subport31, *subport_last;
2069 : : uint32_t q00, q01, q10, q11, q20, q21, q30, q31, q_last;
2070 : : uint32_t r00, r01, r10, r11, r20, r21, r30, r31, r_last;
2071 : : uint32_t subport_qmask;
2072 : : uint32_t result, i;
2073 : :
2074 : : result = 0;
2075 : 1 : subport_qmask = (1 << (port->n_pipes_per_subport_log2 + 4)) - 1;
2076 : :
2077 : : /*
2078 : : * Less then 6 input packets available, which is not enough to
2079 : : * feed the pipeline
2080 : : */
2081 [ - + ]: 1 : if (unlikely(n_pkts < 6)) {
2082 : : struct rte_sched_subport *subports[5];
2083 : : struct rte_mbuf **q_base[5];
2084 : : uint32_t q[5];
2085 : :
2086 : : /* Prefetch the mbuf structure of each packet */
2087 [ # # ]: 0 : for (i = 0; i < n_pkts; i++)
2088 : 0 : rte_prefetch0(pkts[i]);
2089 : :
2090 : : /* Prefetch the subport structure for each packet */
2091 [ # # ]: 0 : for (i = 0; i < n_pkts; i++)
2092 : 0 : subports[i] = rte_sched_port_subport(port, pkts[i]);
2093 : :
2094 : : /* Prefetch the queue structure for each queue */
2095 [ # # ]: 0 : for (i = 0; i < n_pkts; i++)
2096 : 0 : q[i] = rte_sched_port_enqueue_qptrs_prefetch0(subports[i],
2097 : 0 : pkts[i], subport_qmask);
2098 : :
2099 : : /* Prefetch the write pointer location of each queue */
2100 [ # # ]: 0 : for (i = 0; i < n_pkts; i++) {
2101 : 0 : q_base[i] = rte_sched_subport_pipe_qbase(subports[i], q[i]);
2102 : : rte_sched_port_enqueue_qwa_prefetch0(port, subports[i],
2103 : : q[i], q_base[i]);
2104 : : }
2105 : :
2106 : : /* Write each packet to its queue */
2107 [ # # ]: 0 : for (i = 0; i < n_pkts; i++)
2108 : 0 : result += rte_sched_port_enqueue_qwa(port, subports[i],
2109 : 0 : q[i], q_base[i], pkts[i]);
2110 : :
2111 : 0 : return result;
2112 : : }
2113 : :
2114 : : /* Feed the first 3 stages of the pipeline (6 packets needed) */
2115 : 1 : pkt20 = pkts[0];
2116 : 1 : pkt21 = pkts[1];
2117 : : rte_prefetch0(pkt20);
2118 : : rte_prefetch0(pkt21);
2119 : :
2120 : 1 : pkt10 = pkts[2];
2121 : 1 : pkt11 = pkts[3];
2122 : : rte_prefetch0(pkt10);
2123 : : rte_prefetch0(pkt11);
2124 : :
2125 : : subport20 = rte_sched_port_subport(port, pkt20);
2126 : : subport21 = rte_sched_port_subport(port, pkt21);
2127 : : q20 = rte_sched_port_enqueue_qptrs_prefetch0(subport20,
2128 : : pkt20, subport_qmask);
2129 : : q21 = rte_sched_port_enqueue_qptrs_prefetch0(subport21,
2130 : : pkt21, subport_qmask);
2131 : :
2132 : 1 : pkt00 = pkts[4];
2133 : 1 : pkt01 = pkts[5];
2134 : : rte_prefetch0(pkt00);
2135 : : rte_prefetch0(pkt01);
2136 : :
2137 : : subport10 = rte_sched_port_subport(port, pkt10);
2138 : : subport11 = rte_sched_port_subport(port, pkt11);
2139 : : q10 = rte_sched_port_enqueue_qptrs_prefetch0(subport10,
2140 : : pkt10, subport_qmask);
2141 : : q11 = rte_sched_port_enqueue_qptrs_prefetch0(subport11,
2142 : : pkt11, subport_qmask);
2143 : :
2144 : : q20_base = rte_sched_subport_pipe_qbase(subport20, q20);
2145 : : q21_base = rte_sched_subport_pipe_qbase(subport21, q21);
2146 : : rte_sched_port_enqueue_qwa_prefetch0(port, subport20, q20, q20_base);
2147 : : rte_sched_port_enqueue_qwa_prefetch0(port, subport21, q21, q21_base);
2148 : :
2149 : : /* Run the pipeline */
2150 [ + + ]: 3 : for (i = 6; i < (n_pkts & (~1)); i += 2) {
2151 : : /* Propagate stage inputs */
2152 : : pkt30 = pkt20;
2153 : : pkt31 = pkt21;
2154 : : pkt20 = pkt10;
2155 : : pkt21 = pkt11;
2156 : : pkt10 = pkt00;
2157 : : pkt11 = pkt01;
2158 : : q30 = q20;
2159 : : q31 = q21;
2160 : : q20 = q10;
2161 : : q21 = q11;
2162 : : subport30 = subport20;
2163 : : subport31 = subport21;
2164 : : subport20 = subport10;
2165 : : subport21 = subport11;
2166 : : q30_base = q20_base;
2167 : : q31_base = q21_base;
2168 : :
2169 : : /* Stage 0: Get packets in */
2170 : 2 : pkt00 = pkts[i];
2171 : 2 : pkt01 = pkts[i + 1];
2172 : : rte_prefetch0(pkt00);
2173 : : rte_prefetch0(pkt01);
2174 : :
2175 : : /* Stage 1: Prefetch subport and queue structure storing queue pointers */
2176 : : subport10 = rte_sched_port_subport(port, pkt10);
2177 : : subport11 = rte_sched_port_subport(port, pkt11);
2178 : : q10 = rte_sched_port_enqueue_qptrs_prefetch0(subport10,
2179 : : pkt10, subport_qmask);
2180 : : q11 = rte_sched_port_enqueue_qptrs_prefetch0(subport11,
2181 : : pkt11, subport_qmask);
2182 : :
2183 : : /* Stage 2: Prefetch queue write location */
2184 : : q20_base = rte_sched_subport_pipe_qbase(subport20, q20);
2185 : : q21_base = rte_sched_subport_pipe_qbase(subport21, q21);
2186 : : rte_sched_port_enqueue_qwa_prefetch0(port, subport20, q20, q20_base);
2187 : : rte_sched_port_enqueue_qwa_prefetch0(port, subport21, q21, q21_base);
2188 : :
2189 : : /* Stage 3: Write packet to queue and activate queue */
2190 : 2 : r30 = rte_sched_port_enqueue_qwa(port, subport30,
2191 : : q30, q30_base, pkt30);
2192 : 2 : r31 = rte_sched_port_enqueue_qwa(port, subport31,
2193 : : q31, q31_base, pkt31);
2194 : 2 : result += r30 + r31;
2195 : : }
2196 : :
2197 : : /*
2198 : : * Drain the pipeline (exactly 6 packets).
2199 : : * Handle the last packet in the case
2200 : : * of an odd number of input packets.
2201 : : */
2202 : 1 : pkt_last = pkts[n_pkts - 1];
2203 : : rte_prefetch0(pkt_last);
2204 : :
2205 : : subport00 = rte_sched_port_subport(port, pkt00);
2206 : : subport01 = rte_sched_port_subport(port, pkt01);
2207 : : q00 = rte_sched_port_enqueue_qptrs_prefetch0(subport00,
2208 : : pkt00, subport_qmask);
2209 : : q01 = rte_sched_port_enqueue_qptrs_prefetch0(subport01,
2210 : : pkt01, subport_qmask);
2211 : :
2212 : : q10_base = rte_sched_subport_pipe_qbase(subport10, q10);
2213 : : q11_base = rte_sched_subport_pipe_qbase(subport11, q11);
2214 : : rte_sched_port_enqueue_qwa_prefetch0(port, subport10, q10, q10_base);
2215 : : rte_sched_port_enqueue_qwa_prefetch0(port, subport11, q11, q11_base);
2216 : :
2217 : 1 : r20 = rte_sched_port_enqueue_qwa(port, subport20,
2218 : : q20, q20_base, pkt20);
2219 : 1 : r21 = rte_sched_port_enqueue_qwa(port, subport21,
2220 : : q21, q21_base, pkt21);
2221 : 1 : result += r20 + r21;
2222 : :
2223 : : subport_last = rte_sched_port_subport(port, pkt_last);
2224 : : q_last = rte_sched_port_enqueue_qptrs_prefetch0(subport_last,
2225 : : pkt_last, subport_qmask);
2226 : :
2227 : : q00_base = rte_sched_subport_pipe_qbase(subport00, q00);
2228 : : q01_base = rte_sched_subport_pipe_qbase(subport01, q01);
2229 : : rte_sched_port_enqueue_qwa_prefetch0(port, subport00, q00, q00_base);
2230 : : rte_sched_port_enqueue_qwa_prefetch0(port, subport01, q01, q01_base);
2231 : :
2232 : 1 : r10 = rte_sched_port_enqueue_qwa(port, subport10, q10,
2233 : : q10_base, pkt10);
2234 : 1 : r11 = rte_sched_port_enqueue_qwa(port, subport11, q11,
2235 : : q11_base, pkt11);
2236 : 1 : result += r10 + r11;
2237 : :
2238 : : q_last_base = rte_sched_subport_pipe_qbase(subport_last, q_last);
2239 : : rte_sched_port_enqueue_qwa_prefetch0(port, subport_last,
2240 : : q_last, q_last_base);
2241 : :
2242 : 1 : r00 = rte_sched_port_enqueue_qwa(port, subport00, q00,
2243 : : q00_base, pkt00);
2244 : 1 : r01 = rte_sched_port_enqueue_qwa(port, subport01, q01,
2245 : : q01_base, pkt01);
2246 : 1 : result += r00 + r01;
2247 : :
2248 [ - + ]: 1 : if (n_pkts & 1) {
2249 : 0 : r_last = rte_sched_port_enqueue_qwa(port, subport_last,
2250 : : q_last, q_last_base, pkt_last);
2251 : 0 : result += r_last;
2252 : : }
2253 : :
2254 : 1 : return result;
2255 : : }
2256 : :
2257 : : static inline uint64_t
2258 : 0 : grinder_tc_ov_credits_update(struct rte_sched_port *port,
2259 : : struct rte_sched_subport *subport, uint32_t pos)
2260 : : {
2261 : 0 : struct rte_sched_grinder *grinder = subport->grinder + pos;
2262 : 0 : struct rte_sched_subport_profile *sp = grinder->subport_params;
2263 : : uint64_t tc_ov_consumption[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
2264 : : uint64_t tc_consumption = 0, tc_ov_consumption_max;
2265 : 0 : uint64_t tc_ov_wm = subport->tc_ov_wm;
2266 : : uint32_t i;
2267 : :
2268 [ # # ]: 0 : if (subport->tc_ov == 0)
2269 : 0 : return subport->tc_ov_wm_max;
2270 : :
2271 [ # # ]: 0 : for (i = 0; i < RTE_SCHED_TRAFFIC_CLASS_BE; i++) {
2272 : 0 : tc_ov_consumption[i] = sp->tc_credits_per_period[i]
2273 : 0 : - subport->tc_credits[i];
2274 : 0 : tc_consumption += tc_ov_consumption[i];
2275 : : }
2276 : :
2277 : : tc_ov_consumption[RTE_SCHED_TRAFFIC_CLASS_BE] =
2278 : 0 : sp->tc_credits_per_period[RTE_SCHED_TRAFFIC_CLASS_BE] -
2279 : 0 : subport->tc_credits[RTE_SCHED_TRAFFIC_CLASS_BE];
2280 : :
2281 : 0 : tc_ov_consumption_max =
2282 : : sp->tc_credits_per_period[RTE_SCHED_TRAFFIC_CLASS_BE] -
2283 : : tc_consumption;
2284 : :
2285 : 0 : if (tc_ov_consumption[RTE_SCHED_TRAFFIC_CLASS_BE] >
2286 [ # # ]: 0 : (tc_ov_consumption_max - port->mtu)) {
2287 : 0 : tc_ov_wm -= tc_ov_wm >> 7;
2288 : 0 : if (tc_ov_wm < subport->tc_ov_wm_min)
2289 : : tc_ov_wm = subport->tc_ov_wm_min;
2290 : :
2291 : 0 : return tc_ov_wm;
2292 : : }
2293 : :
2294 : 0 : tc_ov_wm += (tc_ov_wm >> 7) + 1;
2295 : 0 : if (tc_ov_wm > subport->tc_ov_wm_max)
2296 : : tc_ov_wm = subport->tc_ov_wm_max;
2297 : :
2298 : : return tc_ov_wm;
2299 : : }
2300 : :
2301 : : static inline void
2302 : 0 : grinder_credits_update(struct rte_sched_port *port,
2303 : : struct rte_sched_subport *subport, uint32_t pos)
2304 : : {
2305 : 0 : struct rte_sched_grinder *grinder = subport->grinder + pos;
2306 : 0 : struct rte_sched_pipe *pipe = grinder->pipe;
2307 : 0 : struct rte_sched_pipe_profile *params = grinder->pipe_params;
2308 : 0 : struct rte_sched_subport_profile *sp = grinder->subport_params;
2309 : : uint64_t n_periods;
2310 : : uint32_t i;
2311 : :
2312 : : /* Subport TB */
2313 : 0 : n_periods = (port->time - subport->tb_time) / sp->tb_period;
2314 : 0 : subport->tb_credits += n_periods * sp->tb_credits_per_period;
2315 : 0 : subport->tb_credits = RTE_MIN(subport->tb_credits, sp->tb_size);
2316 : 0 : subport->tb_time += n_periods * sp->tb_period;
2317 : :
2318 : : /* Pipe TB */
2319 : 0 : n_periods = (port->time - pipe->tb_time) / params->tb_period;
2320 : 0 : pipe->tb_credits += n_periods * params->tb_credits_per_period;
2321 : 0 : pipe->tb_credits = RTE_MIN(pipe->tb_credits, params->tb_size);
2322 : 0 : pipe->tb_time += n_periods * params->tb_period;
2323 : :
2324 : : /* Subport TCs */
2325 [ # # ]: 0 : if (unlikely(port->time >= subport->tc_time)) {
2326 [ # # ]: 0 : for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
2327 : 0 : subport->tc_credits[i] = sp->tc_credits_per_period[i];
2328 : :
2329 : 0 : subport->tc_time = port->time + sp->tc_period;
2330 : : }
2331 : :
2332 : : /* Pipe TCs */
2333 [ # # ]: 0 : if (unlikely(port->time >= pipe->tc_time)) {
2334 [ # # ]: 0 : for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
2335 : 0 : pipe->tc_credits[i] = params->tc_credits_per_period[i];
2336 : 0 : pipe->tc_time = port->time + params->tc_period;
2337 : : }
2338 : 0 : }
2339 : :
2340 : : static inline void
2341 : 1 : grinder_credits_update_with_tc_ov(struct rte_sched_port *port,
2342 : : struct rte_sched_subport *subport, uint32_t pos)
2343 : : {
2344 : 1 : struct rte_sched_grinder *grinder = subport->grinder + pos;
2345 : 1 : struct rte_sched_pipe *pipe = grinder->pipe;
2346 : 1 : struct rte_sched_pipe_profile *params = grinder->pipe_params;
2347 : 1 : struct rte_sched_subport_profile *sp = grinder->subport_params;
2348 : : uint64_t n_periods;
2349 : : uint32_t i;
2350 : :
2351 : : /* Subport TB */
2352 : 1 : n_periods = (port->time - subport->tb_time) / sp->tb_period;
2353 : 1 : subport->tb_credits += n_periods * sp->tb_credits_per_period;
2354 : 1 : subport->tb_credits = RTE_MIN(subport->tb_credits, sp->tb_size);
2355 : 1 : subport->tb_time += n_periods * sp->tb_period;
2356 : :
2357 : : /* Pipe TB */
2358 : 1 : n_periods = (port->time - pipe->tb_time) / params->tb_period;
2359 : 1 : pipe->tb_credits += n_periods * params->tb_credits_per_period;
2360 : 1 : pipe->tb_credits = RTE_MIN(pipe->tb_credits, params->tb_size);
2361 : 1 : pipe->tb_time += n_periods * params->tb_period;
2362 : :
2363 : : /* Subport TCs */
2364 [ - + ]: 1 : if (unlikely(port->time >= subport->tc_time)) {
2365 : 0 : subport->tc_ov_wm =
2366 : 0 : grinder_tc_ov_credits_update(port, subport, pos);
2367 : :
2368 [ # # ]: 0 : for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
2369 : 0 : subport->tc_credits[i] = sp->tc_credits_per_period[i];
2370 : :
2371 : 0 : subport->tc_time = port->time + sp->tc_period;
2372 : 0 : subport->tc_ov_period_id++;
2373 : : }
2374 : :
2375 : : /* Pipe TCs */
2376 [ - + ]: 1 : if (unlikely(port->time >= pipe->tc_time)) {
2377 [ # # ]: 0 : for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
2378 : 0 : pipe->tc_credits[i] = params->tc_credits_per_period[i];
2379 : 0 : pipe->tc_time = port->time + params->tc_period;
2380 : : }
2381 : :
2382 : : /* Pipe TCs - Oversubscription */
2383 [ - + ]: 1 : if (unlikely(pipe->tc_ov_period_id != subport->tc_ov_period_id)) {
2384 : 0 : pipe->tc_ov_credits = subport->tc_ov_wm * params->tc_ov_weight;
2385 : :
2386 : 0 : pipe->tc_ov_period_id = subport->tc_ov_period_id;
2387 : : }
2388 : 1 : }
2389 : :
2390 : : static inline int
2391 : 0 : grinder_credits_check(struct rte_sched_port *port,
2392 : : struct rte_sched_subport *subport, uint32_t pos)
2393 : : {
2394 : 0 : struct rte_sched_grinder *grinder = subport->grinder + pos;
2395 : 0 : struct rte_sched_pipe *pipe = grinder->pipe;
2396 : 0 : struct rte_mbuf *pkt = grinder->pkt;
2397 : 0 : uint32_t tc_index = grinder->tc_index;
2398 : 0 : uint64_t pkt_len = pkt->pkt_len + port->frame_overhead;
2399 : 0 : uint64_t subport_tb_credits = subport->tb_credits;
2400 : 0 : uint64_t subport_tc_credits = subport->tc_credits[tc_index];
2401 : 0 : uint64_t pipe_tb_credits = pipe->tb_credits;
2402 : 0 : uint64_t pipe_tc_credits = pipe->tc_credits[tc_index];
2403 : : int enough_credits;
2404 : :
2405 : : /* Check pipe and subport credits */
2406 : : enough_credits = (pkt_len <= subport_tb_credits) &&
2407 : : (pkt_len <= subport_tc_credits) &&
2408 [ # # # # ]: 0 : (pkt_len <= pipe_tb_credits) &&
2409 : : (pkt_len <= pipe_tc_credits);
2410 : :
2411 : : if (!enough_credits)
2412 : : return 0;
2413 : :
2414 : : /* Update pipe and subport credits */
2415 : 0 : subport->tb_credits -= pkt_len;
2416 : 0 : subport->tc_credits[tc_index] -= pkt_len;
2417 : 0 : pipe->tb_credits -= pkt_len;
2418 : 0 : pipe->tc_credits[tc_index] -= pkt_len;
2419 : :
2420 : 0 : return 1;
2421 : : }
2422 : :
2423 : : static inline int
2424 : 10 : grinder_credits_check_with_tc_ov(struct rte_sched_port *port,
2425 : : struct rte_sched_subport *subport, uint32_t pos)
2426 : : {
2427 : 10 : struct rte_sched_grinder *grinder = subport->grinder + pos;
2428 : 10 : struct rte_sched_pipe *pipe = grinder->pipe;
2429 : 10 : struct rte_mbuf *pkt = grinder->pkt;
2430 : 10 : uint32_t tc_index = grinder->tc_index;
2431 : 10 : uint64_t pkt_len = pkt->pkt_len + port->frame_overhead;
2432 : 10 : uint64_t subport_tb_credits = subport->tb_credits;
2433 : 10 : uint64_t subport_tc_credits = subport->tc_credits[tc_index];
2434 : 10 : uint64_t pipe_tb_credits = pipe->tb_credits;
2435 : 10 : uint64_t pipe_tc_credits = pipe->tc_credits[tc_index];
2436 : : uint64_t pipe_tc_ov_mask1[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
2437 : 10 : uint64_t pipe_tc_ov_mask2[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE] = {0};
2438 : : uint64_t pipe_tc_ov_credits;
2439 : : uint32_t i;
2440 : : int enough_credits;
2441 : :
2442 [ + + ]: 140 : for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
2443 : 130 : pipe_tc_ov_mask1[i] = ~0LLU;
2444 : :
2445 : 10 : pipe_tc_ov_mask1[RTE_SCHED_TRAFFIC_CLASS_BE] = pipe->tc_ov_credits;
2446 : 10 : pipe_tc_ov_mask2[RTE_SCHED_TRAFFIC_CLASS_BE] = ~0LLU;
2447 : 10 : pipe_tc_ov_credits = pipe_tc_ov_mask1[tc_index];
2448 : :
2449 : : /* Check pipe and subport credits */
2450 : : enough_credits = (pkt_len <= subport_tb_credits) &&
2451 : : (pkt_len <= subport_tc_credits) &&
2452 [ + - ]: 10 : (pkt_len <= pipe_tb_credits) &&
2453 [ + - + - ]: 20 : (pkt_len <= pipe_tc_credits) &&
2454 : : (pkt_len <= pipe_tc_ov_credits);
2455 : :
2456 : : if (!enough_credits)
2457 : : return 0;
2458 : :
2459 : : /* Update pipe and subport credits */
2460 : 10 : subport->tb_credits -= pkt_len;
2461 : 10 : subport->tc_credits[tc_index] -= pkt_len;
2462 : 10 : pipe->tb_credits -= pkt_len;
2463 : 10 : pipe->tc_credits[tc_index] -= pkt_len;
2464 : 10 : pipe->tc_ov_credits -= pipe_tc_ov_mask2[tc_index] & pkt_len;
2465 : :
2466 : 10 : return 1;
2467 : : }
2468 : :
2469 : :
2470 : : static inline int
2471 : 10 : grinder_schedule(struct rte_sched_port *port,
2472 : : struct rte_sched_subport *subport, uint32_t pos)
2473 : : {
2474 : 10 : struct rte_sched_grinder *grinder = subport->grinder + pos;
2475 : 10 : struct rte_sched_queue *queue = grinder->queue[grinder->qpos];
2476 : 10 : uint32_t qindex = grinder->qindex[grinder->qpos];
2477 : 10 : struct rte_mbuf *pkt = grinder->pkt;
2478 : 10 : uint32_t pkt_len = pkt->pkt_len + port->frame_overhead;
2479 : : uint32_t be_tc_active;
2480 : :
2481 [ + - ]: 10 : if (subport->tc_ov_enabled) {
2482 [ + - ]: 10 : if (!grinder_credits_check_with_tc_ov(port, subport, pos))
2483 : : return 0;
2484 : : } else {
2485 [ # # ]: 0 : if (!grinder_credits_check(port, subport, pos))
2486 : : return 0;
2487 : : }
2488 : :
2489 : : /* Advance port time */
2490 : 10 : port->time += pkt_len;
2491 : :
2492 : : /* Send packet */
2493 : 10 : port->pkts_out[port->n_pkts_out++] = pkt;
2494 : 10 : queue->qr++;
2495 : :
2496 [ + - ]: 10 : be_tc_active = (grinder->tc_index == RTE_SCHED_TRAFFIC_CLASS_BE) ? ~0x0 : 0x0;
2497 : 10 : grinder->wrr_tokens[grinder->qpos] +=
2498 : 10 : (pkt_len * grinder->wrr_cost[grinder->qpos]) & be_tc_active;
2499 : :
2500 [ + + ]: 10 : if (queue->qr == queue->qw) {
2501 : 1 : rte_bitmap_clear(subport->bmp, qindex);
2502 : 1 : grinder->qmask &= ~(1 << grinder->qpos);
2503 [ - + ]: 1 : if (be_tc_active)
2504 : 0 : grinder->wrr_mask[grinder->qpos] = 0;
2505 : :
2506 : : rte_sched_port_red_set_queue_empty_timestamp(port, subport, qindex);
2507 : : }
2508 : :
2509 : 10 : rte_sched_port_pie_dequeue(subport, qindex, pkt_len, port->time_cpu_cycles);
2510 : :
2511 : : /* Reset pipe loop detection */
2512 : 10 : subport->pipe_loop = RTE_SCHED_PIPE_INVALID;
2513 : 10 : grinder->productive = 1;
2514 : :
2515 : 10 : return 1;
2516 : : }
2517 : :
2518 : : static inline int
2519 : : grinder_pipe_exists(struct rte_sched_subport *subport, uint32_t base_pipe)
2520 : : {
2521 : : uint32_t i;
2522 : :
2523 [ + + ]: 93 : for (i = 0; i < RTE_SCHED_PORT_N_GRINDERS; i++) {
2524 [ + + ]: 92 : if (subport->grinder_base_bmp_pos[i] == base_pipe)
2525 : : return 1;
2526 : : }
2527 : :
2528 : : return 0;
2529 : : }
2530 : :
2531 : : static inline void
2532 : 1 : grinder_pcache_populate(struct rte_sched_subport *subport,
2533 : : uint32_t pos, uint32_t bmp_pos, uint64_t bmp_slab)
2534 : : {
2535 : 1 : struct rte_sched_grinder *grinder = subport->grinder + pos;
2536 : : uint16_t w[4];
2537 : :
2538 : : grinder->pcache_w = 0;
2539 : 1 : grinder->pcache_r = 0;
2540 : :
2541 : 1 : w[0] = (uint16_t) bmp_slab;
2542 : 1 : w[1] = (uint16_t) (bmp_slab >> 16);
2543 : 1 : w[2] = (uint16_t) (bmp_slab >> 32);
2544 : 1 : w[3] = (uint16_t) (bmp_slab >> 48);
2545 : :
2546 : 1 : grinder->pcache_qmask[grinder->pcache_w] = w[0];
2547 : 1 : grinder->pcache_qindex[grinder->pcache_w] = bmp_pos;
2548 : 1 : grinder->pcache_w += (w[0] != 0);
2549 : :
2550 : 1 : grinder->pcache_qmask[grinder->pcache_w] = w[1];
2551 : 1 : grinder->pcache_qindex[grinder->pcache_w] = bmp_pos + 16;
2552 : 1 : grinder->pcache_w += (w[1] != 0);
2553 : :
2554 : 1 : grinder->pcache_qmask[grinder->pcache_w] = w[2];
2555 : 1 : grinder->pcache_qindex[grinder->pcache_w] = bmp_pos + 32;
2556 : 1 : grinder->pcache_w += (w[2] != 0);
2557 : :
2558 : 1 : grinder->pcache_qmask[grinder->pcache_w] = w[3];
2559 : 1 : grinder->pcache_qindex[grinder->pcache_w] = bmp_pos + 48;
2560 : 1 : grinder->pcache_w += (w[3] != 0);
2561 : 1 : }
2562 : :
2563 : : static inline void
2564 : 1 : grinder_tccache_populate(struct rte_sched_subport *subport,
2565 : : uint32_t pos, uint32_t qindex, uint16_t qmask)
2566 : : {
2567 : 1 : struct rte_sched_grinder *grinder = subport->grinder + pos;
2568 : : uint8_t b, i;
2569 : :
2570 : 1 : grinder->tccache_w = 0;
2571 : 1 : grinder->tccache_r = 0;
2572 : :
2573 [ + + ]: 13 : for (i = 0; i < RTE_SCHED_TRAFFIC_CLASS_BE; i++) {
2574 : 12 : b = (uint8_t) ((qmask >> i) & 0x1);
2575 : 12 : grinder->tccache_qmask[grinder->tccache_w] = b;
2576 : 12 : grinder->tccache_qindex[grinder->tccache_w] = qindex + i;
2577 : 12 : grinder->tccache_w += (b != 0);
2578 : : }
2579 : :
2580 : 1 : b = (uint8_t) (qmask >> (RTE_SCHED_TRAFFIC_CLASS_BE));
2581 : 1 : grinder->tccache_qmask[grinder->tccache_w] = b;
2582 : 1 : grinder->tccache_qindex[grinder->tccache_w] = qindex +
2583 : : RTE_SCHED_TRAFFIC_CLASS_BE;
2584 : 1 : grinder->tccache_w += (b != 0);
2585 : 1 : }
2586 : :
2587 : : static inline int
2588 : 2 : grinder_next_tc(struct rte_sched_port *port,
2589 : : struct rte_sched_subport *subport, uint32_t pos)
2590 : : {
2591 : 2 : struct rte_sched_grinder *grinder = subport->grinder + pos;
2592 : : struct rte_mbuf **qbase;
2593 : : uint32_t qindex;
2594 : : uint16_t qsize;
2595 : :
2596 [ + + ]: 2 : if (grinder->tccache_r == grinder->tccache_w)
2597 : : return 0;
2598 : :
2599 : 1 : qindex = grinder->tccache_qindex[grinder->tccache_r];
2600 : : qbase = rte_sched_subport_pipe_qbase(subport, qindex);
2601 : : qsize = rte_sched_subport_pipe_qsize(port, subport, qindex);
2602 : :
2603 : 1 : grinder->tc_index = rte_sched_port_pipe_tc(port, qindex);
2604 : 1 : grinder->qmask = grinder->tccache_qmask[grinder->tccache_r];
2605 : 1 : grinder->qsize = qsize;
2606 : :
2607 [ + - ]: 1 : if (grinder->tc_index < RTE_SCHED_TRAFFIC_CLASS_BE) {
2608 : 1 : grinder->queue[0] = subport->queue + qindex;
2609 : 1 : grinder->qbase[0] = qbase;
2610 : 1 : grinder->qindex[0] = qindex;
2611 : 1 : grinder->tccache_r++;
2612 : :
2613 : 1 : return 1;
2614 : : }
2615 : :
2616 : 0 : grinder->queue[0] = subport->queue + qindex;
2617 : 0 : grinder->queue[1] = subport->queue + qindex + 1;
2618 : 0 : grinder->queue[2] = subport->queue + qindex + 2;
2619 : 0 : grinder->queue[3] = subport->queue + qindex + 3;
2620 : :
2621 : 0 : grinder->qbase[0] = qbase;
2622 : 0 : grinder->qbase[1] = qbase + qsize;
2623 : 0 : grinder->qbase[2] = qbase + 2 * qsize;
2624 : 0 : grinder->qbase[3] = qbase + 3 * qsize;
2625 : :
2626 : 0 : grinder->qindex[0] = qindex;
2627 : 0 : grinder->qindex[1] = qindex + 1;
2628 : 0 : grinder->qindex[2] = qindex + 2;
2629 : 0 : grinder->qindex[3] = qindex + 3;
2630 : :
2631 : 0 : grinder->tccache_r++;
2632 : 0 : return 1;
2633 : : }
2634 : :
2635 : : static inline int
2636 : 86 : grinder_next_pipe(struct rte_sched_port *port,
2637 : : struct rte_sched_subport *subport, uint32_t pos)
2638 : : {
2639 : 86 : struct rte_sched_grinder *grinder = subport->grinder + pos;
2640 : : uint32_t pipe_qindex;
2641 : : uint16_t pipe_qmask;
2642 : :
2643 [ - + ]: 86 : if (grinder->pcache_r < grinder->pcache_w) {
2644 : 0 : pipe_qmask = grinder->pcache_qmask[grinder->pcache_r];
2645 : 0 : pipe_qindex = grinder->pcache_qindex[grinder->pcache_r];
2646 : 0 : grinder->pcache_r++;
2647 : : } else {
2648 : 86 : uint64_t bmp_slab = 0;
2649 : 86 : uint32_t bmp_pos = 0;
2650 : :
2651 : : /* Get another non-empty pipe group */
2652 [ + + ]: 86 : if (unlikely(rte_bitmap_scan(subport->bmp, &bmp_pos, &bmp_slab) <= 0))
2653 : 85 : return 0;
2654 : :
2655 : : #ifdef RTE_SCHED_DEBUG
2656 : : debug_check_queue_slab(subport, bmp_pos, bmp_slab);
2657 : : #endif
2658 : :
2659 : : /* Return if pipe group already in one of the other grinders */
2660 : 85 : subport->grinder_base_bmp_pos[pos] = RTE_SCHED_BMP_POS_INVALID;
2661 [ + + ]: 170 : if (unlikely(grinder_pipe_exists(subport, bmp_pos)))
2662 : : return 0;
2663 : :
2664 : 1 : subport->grinder_base_bmp_pos[pos] = bmp_pos;
2665 : :
2666 : : /* Install new pipe group into grinder's pipe cache */
2667 : 1 : grinder_pcache_populate(subport, pos, bmp_pos, bmp_slab);
2668 : :
2669 : 1 : pipe_qmask = grinder->pcache_qmask[0];
2670 : 1 : pipe_qindex = grinder->pcache_qindex[0];
2671 : 1 : grinder->pcache_r = 1;
2672 : : }
2673 : :
2674 : : /* Install new pipe in the grinder */
2675 : 1 : grinder->pindex = pipe_qindex >> 4;
2676 : 1 : grinder->subport = subport;
2677 : 1 : grinder->pipe = subport->pipe + grinder->pindex;
2678 : 1 : grinder->pipe_params = NULL; /* to be set after the pipe structure is prefetched */
2679 : 1 : grinder->productive = 0;
2680 : :
2681 : 1 : grinder_tccache_populate(subport, pos, pipe_qindex, pipe_qmask);
2682 : 1 : grinder_next_tc(port, subport, pos);
2683 : :
2684 : : /* Check for pipe exhaustion */
2685 [ - + ]: 1 : if (grinder->pindex == subport->pipe_loop) {
2686 : 0 : subport->pipe_exhaustion = 1;
2687 : 0 : subport->pipe_loop = RTE_SCHED_PIPE_INVALID;
2688 : : }
2689 : :
2690 : : return 1;
2691 : : }
2692 : :
2693 : :
2694 : : static inline void
2695 : 0 : grinder_wrr_load(struct rte_sched_subport *subport, uint32_t pos)
2696 : : {
2697 : 0 : struct rte_sched_grinder *grinder = subport->grinder + pos;
2698 : 0 : struct rte_sched_pipe *pipe = grinder->pipe;
2699 : 0 : struct rte_sched_pipe_profile *pipe_params = grinder->pipe_params;
2700 : 0 : uint32_t qmask = grinder->qmask;
2701 : :
2702 : 0 : grinder->wrr_tokens[0] =
2703 : 0 : ((uint16_t) pipe->wrr_tokens[0]) << RTE_SCHED_WRR_SHIFT;
2704 : 0 : grinder->wrr_tokens[1] =
2705 : 0 : ((uint16_t) pipe->wrr_tokens[1]) << RTE_SCHED_WRR_SHIFT;
2706 : 0 : grinder->wrr_tokens[2] =
2707 : 0 : ((uint16_t) pipe->wrr_tokens[2]) << RTE_SCHED_WRR_SHIFT;
2708 : 0 : grinder->wrr_tokens[3] =
2709 : 0 : ((uint16_t) pipe->wrr_tokens[3]) << RTE_SCHED_WRR_SHIFT;
2710 : :
2711 : 0 : grinder->wrr_mask[0] = (qmask & 0x1) * 0xFFFF;
2712 : 0 : grinder->wrr_mask[1] = ((qmask >> 1) & 0x1) * 0xFFFF;
2713 : 0 : grinder->wrr_mask[2] = ((qmask >> 2) & 0x1) * 0xFFFF;
2714 : 0 : grinder->wrr_mask[3] = ((qmask >> 3) & 0x1) * 0xFFFF;
2715 : :
2716 : 0 : grinder->wrr_cost[0] = pipe_params->wrr_cost[0];
2717 : 0 : grinder->wrr_cost[1] = pipe_params->wrr_cost[1];
2718 : 0 : grinder->wrr_cost[2] = pipe_params->wrr_cost[2];
2719 : 0 : grinder->wrr_cost[3] = pipe_params->wrr_cost[3];
2720 : 0 : }
2721 : :
2722 : : static inline void
2723 : 0 : grinder_wrr_store(struct rte_sched_subport *subport, uint32_t pos)
2724 : : {
2725 : 0 : struct rte_sched_grinder *grinder = subport->grinder + pos;
2726 : 0 : struct rte_sched_pipe *pipe = grinder->pipe;
2727 : :
2728 : 0 : pipe->wrr_tokens[0] =
2729 : 0 : (grinder->wrr_tokens[0] & grinder->wrr_mask[0]) >>
2730 : : RTE_SCHED_WRR_SHIFT;
2731 : 0 : pipe->wrr_tokens[1] =
2732 : 0 : (grinder->wrr_tokens[1] & grinder->wrr_mask[1]) >>
2733 : : RTE_SCHED_WRR_SHIFT;
2734 : 0 : pipe->wrr_tokens[2] =
2735 : 0 : (grinder->wrr_tokens[2] & grinder->wrr_mask[2]) >>
2736 : : RTE_SCHED_WRR_SHIFT;
2737 : 0 : pipe->wrr_tokens[3] =
2738 : 0 : (grinder->wrr_tokens[3] & grinder->wrr_mask[3]) >>
2739 : : RTE_SCHED_WRR_SHIFT;
2740 : 0 : }
2741 : :
2742 : : static inline void
2743 : 0 : grinder_wrr(struct rte_sched_subport *subport, uint32_t pos)
2744 : : {
2745 : 0 : struct rte_sched_grinder *grinder = subport->grinder + pos;
2746 : : uint16_t wrr_tokens_min;
2747 : :
2748 : 0 : grinder->wrr_tokens[0] |= ~grinder->wrr_mask[0];
2749 : 0 : grinder->wrr_tokens[1] |= ~grinder->wrr_mask[1];
2750 : 0 : grinder->wrr_tokens[2] |= ~grinder->wrr_mask[2];
2751 : 0 : grinder->wrr_tokens[3] |= ~grinder->wrr_mask[3];
2752 : :
2753 [ # # ]: 0 : grinder->qpos = rte_min_pos_4_u16(grinder->wrr_tokens);
2754 : 0 : wrr_tokens_min = grinder->wrr_tokens[grinder->qpos];
2755 : :
2756 : 0 : grinder->wrr_tokens[0] -= wrr_tokens_min;
2757 : 0 : grinder->wrr_tokens[1] -= wrr_tokens_min;
2758 : 0 : grinder->wrr_tokens[2] -= wrr_tokens_min;
2759 : 0 : grinder->wrr_tokens[3] -= wrr_tokens_min;
2760 : 0 : }
2761 : :
2762 : :
2763 : : #define grinder_evict(subport, pos)
2764 : :
2765 : : static inline void
2766 : : grinder_prefetch_pipe(struct rte_sched_subport *subport, uint32_t pos)
2767 : : {
2768 : : struct rte_sched_grinder *grinder = subport->grinder + pos;
2769 : :
2770 : 1 : rte_prefetch0(grinder->pipe);
2771 : 1 : rte_prefetch0(grinder->queue[0]);
2772 : : }
2773 : :
2774 : : static inline void
2775 : 1 : grinder_prefetch_tc_queue_arrays(struct rte_sched_subport *subport, uint32_t pos)
2776 : : {
2777 : 1 : struct rte_sched_grinder *grinder = subport->grinder + pos;
2778 : : uint16_t qsize, qr[RTE_SCHED_MAX_QUEUES_PER_TC];
2779 : :
2780 : 1 : qsize = grinder->qsize;
2781 : 1 : grinder->qpos = 0;
2782 : :
2783 [ + - ]: 1 : if (grinder->tc_index < RTE_SCHED_TRAFFIC_CLASS_BE) {
2784 : 1 : qr[0] = grinder->queue[0]->qr & (qsize - 1);
2785 : :
2786 : 1 : rte_prefetch0(grinder->qbase[0] + qr[0]);
2787 : : return;
2788 : : }
2789 : :
2790 : 0 : qr[0] = grinder->queue[0]->qr & (qsize - 1);
2791 : 0 : qr[1] = grinder->queue[1]->qr & (qsize - 1);
2792 : 0 : qr[2] = grinder->queue[2]->qr & (qsize - 1);
2793 : 0 : qr[3] = grinder->queue[3]->qr & (qsize - 1);
2794 : :
2795 : 0 : rte_prefetch0(grinder->qbase[0] + qr[0]);
2796 : 0 : rte_prefetch0(grinder->qbase[1] + qr[1]);
2797 : :
2798 : 0 : grinder_wrr_load(subport, pos);
2799 : 0 : grinder_wrr(subport, pos);
2800 : :
2801 : 0 : rte_prefetch0(grinder->qbase[2] + qr[2]);
2802 : 0 : rte_prefetch0(grinder->qbase[3] + qr[3]);
2803 : : }
2804 : :
2805 : : static inline void
2806 : 10 : grinder_prefetch_mbuf(struct rte_sched_subport *subport, uint32_t pos)
2807 : : {
2808 : 10 : struct rte_sched_grinder *grinder = subport->grinder + pos;
2809 : 10 : uint32_t qpos = grinder->qpos;
2810 : 10 : struct rte_mbuf **qbase = grinder->qbase[qpos];
2811 : 10 : uint16_t qsize = grinder->qsize;
2812 : 10 : uint16_t qr = grinder->queue[qpos]->qr & (qsize - 1);
2813 : :
2814 : 10 : grinder->pkt = qbase[qr];
2815 : : rte_prefetch0(grinder->pkt);
2816 : :
2817 [ + + ]: 10 : if (unlikely((qr & 0x7) == 7)) {
2818 : 1 : uint16_t qr_next = (grinder->queue[qpos]->qr + 1) & (qsize - 1);
2819 : :
2820 : 1 : rte_prefetch0(qbase + qr_next);
2821 : : }
2822 : 10 : }
2823 : :
2824 : : static inline uint32_t
2825 : 97 : grinder_handle(struct rte_sched_port *port,
2826 : : struct rte_sched_subport *subport, uint32_t pos)
2827 : : {
2828 : 97 : struct rte_sched_grinder *grinder = subport->grinder + pos;
2829 : :
2830 [ + + + + : 97 : switch (grinder->state) {
- ]
2831 : 85 : case e_GRINDER_PREFETCH_PIPE:
2832 : : {
2833 [ + + ]: 85 : if (grinder_next_pipe(port, subport, pos)) {
2834 : : grinder_prefetch_pipe(subport, pos);
2835 : 1 : subport->busy_grinders++;
2836 : :
2837 : 1 : grinder->state = e_GRINDER_PREFETCH_TC_QUEUE_ARRAYS;
2838 : 1 : return 0;
2839 : : }
2840 : :
2841 : : return 0;
2842 : : }
2843 : :
2844 : 1 : case e_GRINDER_PREFETCH_TC_QUEUE_ARRAYS:
2845 : : {
2846 : 1 : struct rte_sched_pipe *pipe = grinder->pipe;
2847 : :
2848 : 1 : grinder->pipe_params = subport->pipe_profiles + pipe->profile;
2849 : 1 : grinder->subport_params = port->subport_profiles +
2850 : 1 : subport->profile;
2851 : :
2852 : 1 : grinder_prefetch_tc_queue_arrays(subport, pos);
2853 : :
2854 [ + - ]: 1 : if (subport->tc_ov_enabled)
2855 : 1 : grinder_credits_update_with_tc_ov(port, subport, pos);
2856 : : else
2857 : 0 : grinder_credits_update(port, subport, pos);
2858 : :
2859 : 1 : grinder->state = e_GRINDER_PREFETCH_MBUF;
2860 : 1 : return 0;
2861 : : }
2862 : :
2863 : 1 : case e_GRINDER_PREFETCH_MBUF:
2864 : : {
2865 : 1 : grinder_prefetch_mbuf(subport, pos);
2866 : :
2867 : 1 : grinder->state = e_GRINDER_READ_MBUF;
2868 : 1 : return 0;
2869 : : }
2870 : :
2871 : 10 : case e_GRINDER_READ_MBUF:
2872 : : {
2873 : : uint32_t wrr_active, result = 0;
2874 : :
2875 : 10 : result = grinder_schedule(port, subport, pos);
2876 : :
2877 : 10 : wrr_active = (grinder->tc_index == RTE_SCHED_TRAFFIC_CLASS_BE);
2878 : :
2879 : : /* Look for next packet within the same TC */
2880 [ + - + + ]: 10 : if (result && grinder->qmask) {
2881 [ - + ]: 9 : if (wrr_active)
2882 : 0 : grinder_wrr(subport, pos);
2883 : :
2884 : 9 : grinder_prefetch_mbuf(subport, pos);
2885 : :
2886 : 9 : return 1;
2887 : : }
2888 : :
2889 [ - + ]: 1 : if (wrr_active)
2890 : 0 : grinder_wrr_store(subport, pos);
2891 : :
2892 : : /* Look for another active TC within same pipe */
2893 [ - + ]: 1 : if (grinder_next_tc(port, subport, pos)) {
2894 : 0 : grinder_prefetch_tc_queue_arrays(subport, pos);
2895 : :
2896 : 0 : grinder->state = e_GRINDER_PREFETCH_MBUF;
2897 : 0 : return result;
2898 : : }
2899 : :
2900 [ - + ]: 1 : if (grinder->productive == 0 &&
2901 [ # # ]: 0 : subport->pipe_loop == RTE_SCHED_PIPE_INVALID)
2902 : 0 : subport->pipe_loop = grinder->pindex;
2903 : :
2904 : : grinder_evict(subport, pos);
2905 : :
2906 : : /* Look for another active pipe */
2907 [ - + ]: 1 : if (grinder_next_pipe(port, subport, pos)) {
2908 : : grinder_prefetch_pipe(subport, pos);
2909 : :
2910 : 0 : grinder->state = e_GRINDER_PREFETCH_TC_QUEUE_ARRAYS;
2911 : 0 : return result;
2912 : : }
2913 : :
2914 : : /* No active pipe found */
2915 : 1 : subport->busy_grinders--;
2916 : :
2917 : 1 : grinder->state = e_GRINDER_PREFETCH_PIPE;
2918 : 1 : return result;
2919 : : }
2920 : :
2921 : 0 : default:
2922 : 0 : rte_panic("Algorithmic error (invalid state)\n");
2923 : : return 0;
2924 : : }
2925 : : }
2926 : :
2927 : : static inline void
2928 : 1 : rte_sched_port_time_resync(struct rte_sched_port *port)
2929 : : {
2930 : : uint64_t cycles = rte_get_tsc_cycles();
2931 : : uint64_t cycles_diff;
2932 : : uint64_t bytes_diff;
2933 : : uint32_t i;
2934 : :
2935 [ - + ]: 1 : if (cycles < port->time_cpu_cycles)
2936 : 0 : port->time_cpu_cycles = 0;
2937 : :
2938 : 1 : cycles_diff = cycles - port->time_cpu_cycles;
2939 : : /* Compute elapsed time in bytes */
2940 [ + - ]: 1 : bytes_diff = rte_reciprocal_divide(cycles_diff << RTE_SCHED_TIME_SHIFT,
2941 : : port->inv_cycles_per_byte);
2942 : :
2943 : : /* Advance port time */
2944 : 1 : port->time_cpu_cycles +=
2945 : 1 : (bytes_diff * port->cycles_per_byte) >> RTE_SCHED_TIME_SHIFT;
2946 : 1 : port->time_cpu_bytes += bytes_diff;
2947 [ + - ]: 1 : if (port->time < port->time_cpu_bytes)
2948 : 1 : port->time = port->time_cpu_bytes;
2949 : :
2950 : : /* Reset pipe loop detection */
2951 [ + + ]: 2 : for (i = 0; i < port->n_subports_per_port; i++)
2952 : 1 : port->subports[i]->pipe_loop = RTE_SCHED_PIPE_INVALID;
2953 : 1 : }
2954 : :
2955 : : static inline int
2956 : : rte_sched_port_exceptions(struct rte_sched_subport *subport, int second_pass)
2957 : : {
2958 : : int exceptions;
2959 : :
2960 : : /* Check if any exception flag is set */
2961 [ + + - + ]: 96 : exceptions = (second_pass && subport->busy_grinders == 0) ||
2962 [ + - ]: 96 : (subport->pipe_exhaustion == 1);
2963 : :
2964 : : /* Clear exception flags */
2965 : 96 : subport->pipe_exhaustion = 0;
2966 : :
2967 : : return exceptions;
2968 : : }
2969 : :
2970 : : RTE_EXPORT_SYMBOL(rte_sched_port_dequeue)
2971 : : int
2972 : 1 : rte_sched_port_dequeue(struct rte_sched_port *port, struct rte_mbuf **pkts, uint32_t n_pkts)
2973 : : {
2974 : : struct rte_sched_subport *subport;
2975 : 1 : uint32_t subport_id = port->subport_id;
2976 : : uint32_t i, n_subports = 0, count;
2977 : :
2978 : 1 : port->pkts_out = pkts;
2979 : 1 : port->n_pkts_out = 0;
2980 : :
2981 : 1 : rte_sched_port_time_resync(port);
2982 : :
2983 : : /* Take each queue in the grinder one step further */
2984 : 96 : for (i = 0, count = 0; ; i++) {
2985 : 97 : subport = port->subports[subport_id];
2986 : :
2987 : 97 : count += grinder_handle(port, subport,
2988 : : i & (RTE_SCHED_PORT_N_GRINDERS - 1));
2989 : :
2990 [ + + ]: 97 : if (count == n_pkts) {
2991 : 1 : subport_id++;
2992 : :
2993 [ + - ]: 1 : if (subport_id == port->n_subports_per_port)
2994 : : subport_id = 0;
2995 : :
2996 : 1 : port->subport_id = subport_id;
2997 : 1 : break;
2998 : : }
2999 : :
3000 : : if (rte_sched_port_exceptions(subport, i >= RTE_SCHED_PORT_N_GRINDERS)) {
3001 : : i = 0;
3002 : 0 : subport_id++;
3003 : 0 : n_subports++;
3004 : : }
3005 : :
3006 [ - + ]: 96 : if (subport_id == port->n_subports_per_port)
3007 : : subport_id = 0;
3008 : :
3009 [ - + ]: 96 : if (n_subports == port->n_subports_per_port) {
3010 : 0 : port->subport_id = subport_id;
3011 : 0 : break;
3012 : : }
3013 : : }
3014 : :
3015 : 1 : return count;
3016 : : }
3017 : :
3018 [ - + ]: 252 : RTE_LOG_REGISTER_DEFAULT(sched_logtype, INFO);
|