1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
8 #include <rte_common.h>
10 #include <rte_memory.h>
11 #include <rte_malloc.h>
12 #include <rte_cycles.h>
13 #include <rte_prefetch.h>
14 #include <rte_branch_prediction.h>
16 #include <rte_bitmap.h>
17 #include <rte_reciprocal.h>
19 #include "rte_sched.h"
20 #include "rte_sched_common.h"
21 #include "rte_approx.h"
23 #ifdef __INTEL_COMPILER
24 #pragma warning(disable:2259) /* conversion may lose significant bits */
27 #ifdef RTE_SCHED_VECTOR
31 #define SCHED_VECTOR_SSE4
32 #elif defined(__ARM_NEON)
33 #define SCHED_VECTOR_NEON
38 #define RTE_SCHED_TB_RATE_CONFIG_ERR (1e-7)
39 #define RTE_SCHED_WRR_SHIFT 3
40 #define RTE_SCHED_MAX_QUEUES_PER_TC RTE_SCHED_BE_QUEUES_PER_PIPE
41 #define RTE_SCHED_GRINDER_PCACHE_SIZE (64 / RTE_SCHED_QUEUES_PER_PIPE)
42 #define RTE_SCHED_PIPE_INVALID UINT32_MAX
43 #define RTE_SCHED_BMP_POS_INVALID UINT32_MAX
45 /* Scaling for cycles_per_byte calculation
46 * Chosen so that minimum rate is 480 bit/sec
48 #define RTE_SCHED_TIME_SHIFT 8
50 struct rte_sched_pipe_profile {
51 /* Token bucket (TB) */
53 uint64_t tb_credits_per_period;
56 /* Pipe traffic classes */
58 uint64_t tc_credits_per_period[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
61 /* Pipe best-effort traffic class queues */
62 uint8_t wrr_cost[RTE_SCHED_BE_QUEUES_PER_PIPE];
65 struct rte_sched_pipe {
66 /* Token bucket (TB) */
67 uint64_t tb_time; /* time of last update */
70 /* Pipe profile and flags */
73 /* Traffic classes (TCs) */
74 uint64_t tc_time; /* time of next update */
75 uint64_t tc_credits[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
77 /* Weighted Round Robin (WRR) */
78 uint8_t wrr_tokens[RTE_SCHED_BE_QUEUES_PER_PIPE];
80 /* TC oversubscription */
81 uint64_t tc_ov_credits;
82 uint8_t tc_ov_period_id;
83 } __rte_cache_aligned;
85 struct rte_sched_queue {
90 struct rte_sched_queue_extra {
91 struct rte_sched_queue_stats stats;
98 e_GRINDER_PREFETCH_PIPE = 0,
99 e_GRINDER_PREFETCH_TC_QUEUE_ARRAYS,
100 e_GRINDER_PREFETCH_MBUF,
104 struct rte_sched_subport_profile {
105 /* Token bucket (TB) */
107 uint64_t tb_credits_per_period;
110 uint64_t tc_credits_per_period[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
114 struct rte_sched_grinder {
116 uint16_t pcache_qmask[RTE_SCHED_GRINDER_PCACHE_SIZE];
117 uint32_t pcache_qindex[RTE_SCHED_GRINDER_PCACHE_SIZE];
122 enum grinder_state state;
125 struct rte_sched_subport *subport;
126 struct rte_sched_subport_profile *subport_params;
127 struct rte_sched_pipe *pipe;
128 struct rte_sched_pipe_profile *pipe_params;
131 uint8_t tccache_qmask[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
132 uint32_t tccache_qindex[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
138 struct rte_sched_queue *queue[RTE_SCHED_MAX_QUEUES_PER_TC];
139 struct rte_mbuf **qbase[RTE_SCHED_MAX_QUEUES_PER_TC];
140 uint32_t qindex[RTE_SCHED_MAX_QUEUES_PER_TC];
144 struct rte_mbuf *pkt;
147 uint16_t wrr_tokens[RTE_SCHED_BE_QUEUES_PER_PIPE];
148 uint16_t wrr_mask[RTE_SCHED_BE_QUEUES_PER_PIPE];
149 uint8_t wrr_cost[RTE_SCHED_BE_QUEUES_PER_PIPE];
152 struct rte_sched_subport {
153 /* Token bucket (TB) */
154 uint64_t tb_time; /* time of last update */
157 /* Traffic classes (TCs) */
158 uint64_t tc_time; /* time of next update */
159 uint64_t tc_credits[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
161 /* TC oversubscription */
163 uint64_t tc_ov_wm_min;
164 uint64_t tc_ov_wm_max;
165 uint8_t tc_ov_period_id;
171 struct rte_sched_subport_stats stats __rte_cache_aligned;
173 /* subport profile */
176 uint32_t n_pipes_per_subport_enabled;
177 uint32_t n_pipe_profiles;
178 uint32_t n_max_pipe_profiles;
180 /* Pipe best-effort TC rate */
181 uint64_t pipe_tc_be_rate_max;
183 /* Pipe queues size */
184 uint16_t qsize[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
187 struct rte_red_config red_config[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE][RTE_COLORS];
190 /* Scheduling loop detection */
192 uint32_t pipe_exhaustion;
195 struct rte_bitmap *bmp;
196 uint32_t grinder_base_bmp_pos[RTE_SCHED_PORT_N_GRINDERS] __rte_aligned_16;
199 struct rte_sched_grinder grinder[RTE_SCHED_PORT_N_GRINDERS];
200 uint32_t busy_grinders;
202 /* Queue base calculation */
203 uint32_t qsize_add[RTE_SCHED_QUEUES_PER_PIPE];
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;
211 struct rte_mbuf **queue_array;
212 uint8_t memory[0] __rte_cache_aligned;
213 } __rte_cache_aligned;
215 struct 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;
227 uint32_t frame_overhead;
231 uint64_t time_cpu_cycles; /* Current CPU time measured in CPU cyles */
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;
238 struct rte_mbuf **pkts_out;
242 /* Large data structures */
243 struct rte_sched_subport_profile *subport_profiles;
244 struct rte_sched_subport *subports[0] __rte_cache_aligned;
245 } __rte_cache_aligned;
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,
257 static inline uint32_t
258 rte_sched_subport_pipe_queues(struct rte_sched_subport *subport)
260 return RTE_SCHED_QUEUES_PER_PIPE * subport->n_pipes_per_subport_enabled;
263 static inline struct rte_mbuf **
264 rte_sched_subport_pipe_qbase(struct rte_sched_subport *subport, uint32_t qindex)
266 uint32_t pindex = qindex >> 4;
267 uint32_t qpos = qindex & (RTE_SCHED_QUEUES_PER_PIPE - 1);
269 return (subport->queue_array + pindex *
270 subport->qsize_sum + subport->qsize_add[qpos]);
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)
277 uint32_t tc = port->pipe_tc[qindex & (RTE_SCHED_QUEUES_PER_PIPE - 1)];
279 return subport->qsize[tc];
282 static inline uint32_t
283 rte_sched_port_queues_per_port(struct rte_sched_port *port)
285 uint32_t n_queues = 0, i;
287 for (i = 0; i < port->n_subports_per_port; i++)
288 n_queues += rte_sched_subport_pipe_queues(port->subports[i]);
293 static inline uint16_t
294 rte_sched_port_pipe_queue(struct rte_sched_port *port, uint32_t traffic_class)
296 uint16_t pipe_queue = port->pipe_queue[traffic_class];
301 static inline uint8_t
302 rte_sched_port_pipe_tc(struct rte_sched_port *port, uint32_t qindex)
304 uint8_t pipe_tc = port->pipe_tc[qindex & (RTE_SCHED_QUEUES_PER_PIPE - 1)];
309 static inline uint8_t
310 rte_sched_port_tc_queue(struct rte_sched_port *port, uint32_t qindex)
312 uint8_t tc_queue = port->tc_queue[qindex & (RTE_SCHED_QUEUES_PER_PIPE - 1)];
318 pipe_profile_check(struct rte_sched_pipe_params *params,
319 uint64_t rate, uint16_t *qsize)
323 /* Pipe parameters */
324 if (params == NULL) {
326 "%s: Incorrect value for parameter params\n", __func__);
330 /* TB rate: non-zero, not greater than port rate */
331 if (params->tb_rate == 0 ||
332 params->tb_rate > rate) {
334 "%s: Incorrect value for tb rate\n", __func__);
338 /* TB size: non-zero */
339 if (params->tb_size == 0) {
341 "%s: Incorrect value for tb size\n", __func__);
345 /* TC rate: non-zero if qsize non-zero, less than pipe rate */
346 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++) {
347 if ((qsize[i] == 0 && params->tc_rate[i] != 0) ||
348 (qsize[i] != 0 && (params->tc_rate[i] == 0 ||
349 params->tc_rate[i] > params->tb_rate))) {
351 "%s: Incorrect value for qsize or tc_rate\n", __func__);
356 if (params->tc_rate[RTE_SCHED_TRAFFIC_CLASS_BE] == 0 ||
357 qsize[RTE_SCHED_TRAFFIC_CLASS_BE] == 0) {
359 "%s: Incorrect value for be traffic class rate\n", __func__);
363 /* TC period: non-zero */
364 if (params->tc_period == 0) {
366 "%s: Incorrect value for tc period\n", __func__);
370 /* Best effort tc oversubscription weight: non-zero */
371 if (params->tc_ov_weight == 0) {
373 "%s: Incorrect value for tc ov weight\n", __func__);
377 /* Queue WRR weights: non-zero */
378 for (i = 0; i < RTE_SCHED_BE_QUEUES_PER_PIPE; i++) {
379 if (params->wrr_weights[i] == 0) {
381 "%s: Incorrect value for wrr weight\n", __func__);
390 subport_profile_check(struct rte_sched_subport_profile_params *params,
395 /* Check user parameters */
396 if (params == NULL) {
397 RTE_LOG(ERR, SCHED, "%s: "
398 "Incorrect value for parameter params\n", __func__);
402 if (params->tb_rate == 0 || params->tb_rate > rate) {
403 RTE_LOG(ERR, SCHED, "%s: "
404 "Incorrect value for tb rate\n", __func__);
408 if (params->tb_size == 0) {
409 RTE_LOG(ERR, SCHED, "%s: "
410 "Incorrect value for tb size\n", __func__);
414 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++) {
415 uint64_t tc_rate = params->tc_rate[i];
417 if (tc_rate == 0 || (tc_rate > params->tb_rate)) {
418 RTE_LOG(ERR, SCHED, "%s: "
419 "Incorrect value for tc rate\n", __func__);
424 if (params->tc_rate[RTE_SCHED_TRAFFIC_CLASS_BE] == 0) {
425 RTE_LOG(ERR, SCHED, "%s: "
426 "Incorrect tc rate(best effort)\n", __func__);
430 if (params->tc_period == 0) {
431 RTE_LOG(ERR, SCHED, "%s: "
432 "Incorrect value for tc period\n", __func__);
440 rte_sched_port_check_params(struct rte_sched_port_params *params)
444 if (params == NULL) {
446 "%s: Incorrect value for parameter params\n", __func__);
451 if (params->socket < 0) {
453 "%s: Incorrect value for socket id\n", __func__);
458 if (params->rate == 0) {
460 "%s: Incorrect value for rate\n", __func__);
465 if (params->mtu == 0) {
467 "%s: Incorrect value for mtu\n", __func__);
471 /* n_subports_per_port: non-zero, limited to 16 bits, power of 2 */
472 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)) {
476 "%s: Incorrect value for number of subports\n", __func__);
480 if (params->subport_profiles == NULL ||
481 params->n_subport_profiles == 0 ||
482 params->n_max_subport_profiles == 0 ||
483 params->n_subport_profiles > params->n_max_subport_profiles) {
485 "%s: Incorrect value for subport profiles\n", __func__);
489 for (i = 0; i < params->n_subport_profiles; i++) {
490 struct rte_sched_subport_profile_params *p =
491 params->subport_profiles + i;
494 status = subport_profile_check(p, params->rate);
497 "%s: subport profile check failed(%d)\n",
503 /* n_pipes_per_subport: non-zero, power of 2 */
504 if (params->n_pipes_per_subport == 0 ||
505 !rte_is_power_of_2(params->n_pipes_per_subport)) {
507 "%s: Incorrect value for maximum pipes number\n", __func__);
515 rte_sched_subport_get_array_base(struct rte_sched_subport_params *params,
516 enum rte_sched_subport_array array)
518 uint32_t n_pipes_per_subport = params->n_pipes_per_subport_enabled;
519 uint32_t n_subport_pipe_queues =
520 RTE_SCHED_QUEUES_PER_PIPE * n_pipes_per_subport;
522 uint32_t size_pipe = n_pipes_per_subport * sizeof(struct rte_sched_pipe);
523 uint32_t size_queue =
524 n_subport_pipe_queues * sizeof(struct rte_sched_queue);
525 uint32_t size_queue_extra
526 = n_subport_pipe_queues * sizeof(struct rte_sched_queue_extra);
527 uint32_t size_pipe_profiles = params->n_max_pipe_profiles *
528 sizeof(struct rte_sched_pipe_profile);
529 uint32_t size_bmp_array =
530 rte_bitmap_get_memory_footprint(n_subport_pipe_queues);
531 uint32_t size_per_pipe_queue_array, size_queue_array;
535 size_per_pipe_queue_array = 0;
536 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++) {
537 if (i < RTE_SCHED_TRAFFIC_CLASS_BE)
538 size_per_pipe_queue_array +=
539 params->qsize[i] * sizeof(struct rte_mbuf *);
541 size_per_pipe_queue_array += RTE_SCHED_MAX_QUEUES_PER_TC *
542 params->qsize[i] * sizeof(struct rte_mbuf *);
544 size_queue_array = n_pipes_per_subport * size_per_pipe_queue_array;
548 if (array == e_RTE_SCHED_SUBPORT_ARRAY_PIPE)
550 base += RTE_CACHE_LINE_ROUNDUP(size_pipe);
552 if (array == e_RTE_SCHED_SUBPORT_ARRAY_QUEUE)
554 base += RTE_CACHE_LINE_ROUNDUP(size_queue);
556 if (array == e_RTE_SCHED_SUBPORT_ARRAY_QUEUE_EXTRA)
558 base += RTE_CACHE_LINE_ROUNDUP(size_queue_extra);
560 if (array == e_RTE_SCHED_SUBPORT_ARRAY_PIPE_PROFILES)
562 base += RTE_CACHE_LINE_ROUNDUP(size_pipe_profiles);
564 if (array == e_RTE_SCHED_SUBPORT_ARRAY_BMP_ARRAY)
566 base += RTE_CACHE_LINE_ROUNDUP(size_bmp_array);
568 if (array == e_RTE_SCHED_SUBPORT_ARRAY_QUEUE_ARRAY)
570 base += RTE_CACHE_LINE_ROUNDUP(size_queue_array);
576 rte_sched_subport_config_qsize(struct rte_sched_subport *subport)
580 subport->qsize_add[0] = 0;
582 /* Strict prority traffic class */
583 for (i = 1; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
584 subport->qsize_add[i] = subport->qsize_add[i-1] + subport->qsize[i-1];
586 /* Best-effort traffic class */
587 subport->qsize_add[RTE_SCHED_TRAFFIC_CLASS_BE + 1] =
588 subport->qsize_add[RTE_SCHED_TRAFFIC_CLASS_BE] +
589 subport->qsize[RTE_SCHED_TRAFFIC_CLASS_BE];
590 subport->qsize_add[RTE_SCHED_TRAFFIC_CLASS_BE + 2] =
591 subport->qsize_add[RTE_SCHED_TRAFFIC_CLASS_BE + 1] +
592 subport->qsize[RTE_SCHED_TRAFFIC_CLASS_BE];
593 subport->qsize_add[RTE_SCHED_TRAFFIC_CLASS_BE + 3] =
594 subport->qsize_add[RTE_SCHED_TRAFFIC_CLASS_BE + 2] +
595 subport->qsize[RTE_SCHED_TRAFFIC_CLASS_BE];
597 subport->qsize_sum = subport->qsize_add[RTE_SCHED_TRAFFIC_CLASS_BE + 3] +
598 subport->qsize[RTE_SCHED_TRAFFIC_CLASS_BE];
602 rte_sched_port_log_pipe_profile(struct rte_sched_subport *subport, uint32_t i)
604 struct rte_sched_pipe_profile *p = subport->pipe_profiles + i;
606 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",
618 p->tb_credits_per_period,
621 /* Traffic classes */
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],
637 /* Best-effort traffic class oversubscription */
641 p->wrr_cost[0], p->wrr_cost[1], p->wrr_cost[2], p->wrr_cost[3]);
645 rte_sched_port_log_subport_profile(struct rte_sched_port *port, uint32_t i)
647 struct rte_sched_subport_profile *p = port->subport_profiles + i;
649 RTE_LOG(DEBUG, SCHED, "Low level config for subport profile %u:\n"
650 "Token bucket: period = %"PRIu64", credits per period = %"PRIu64","
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",
660 p->tb_credits_per_period,
663 /* Traffic classes */
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]);
680 static inline uint64_t
681 rte_sched_time_ms_to_bytes(uint64_t time_ms, uint64_t rate)
683 uint64_t time = time_ms;
685 time = (time * rate) / 1000;
691 rte_sched_pipe_profile_convert(struct rte_sched_subport *subport,
692 struct rte_sched_pipe_params *src,
693 struct rte_sched_pipe_profile *dst,
696 uint32_t wrr_cost[RTE_SCHED_BE_QUEUES_PER_PIPE];
697 uint32_t lcd1, lcd2, lcd;
701 if (src->tb_rate == rate) {
702 dst->tb_credits_per_period = 1;
705 double tb_rate = (double) src->tb_rate
707 double d = RTE_SCHED_TB_RATE_CONFIG_ERR;
709 rte_approx_64(tb_rate, d, &dst->tb_credits_per_period,
713 dst->tb_size = src->tb_size;
715 /* Traffic Classes */
716 dst->tc_period = rte_sched_time_ms_to_bytes(src->tc_period,
719 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
720 if (subport->qsize[i])
721 dst->tc_credits_per_period[i]
722 = rte_sched_time_ms_to_bytes(src->tc_period,
725 dst->tc_ov_weight = src->tc_ov_weight;
728 wrr_cost[0] = src->wrr_weights[0];
729 wrr_cost[1] = src->wrr_weights[1];
730 wrr_cost[2] = src->wrr_weights[2];
731 wrr_cost[3] = src->wrr_weights[3];
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);
737 wrr_cost[0] = lcd / wrr_cost[0];
738 wrr_cost[1] = lcd / wrr_cost[1];
739 wrr_cost[2] = lcd / wrr_cost[2];
740 wrr_cost[3] = lcd / wrr_cost[3];
742 dst->wrr_cost[0] = (uint8_t) wrr_cost[0];
743 dst->wrr_cost[1] = (uint8_t) wrr_cost[1];
744 dst->wrr_cost[2] = (uint8_t) wrr_cost[2];
745 dst->wrr_cost[3] = (uint8_t) wrr_cost[3];
749 rte_sched_subport_profile_convert(struct rte_sched_subport_profile_params *src,
750 struct rte_sched_subport_profile *dst,
756 if (src->tb_rate == rate) {
757 dst->tb_credits_per_period = 1;
760 double tb_rate = (double) src->tb_rate
762 double d = RTE_SCHED_TB_RATE_CONFIG_ERR;
764 rte_approx_64(tb_rate, d, &dst->tb_credits_per_period,
768 dst->tb_size = src->tb_size;
770 /* Traffic Classes */
771 dst->tc_period = rte_sched_time_ms_to_bytes(src->tc_period, rate);
773 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
774 dst->tc_credits_per_period[i]
775 = rte_sched_time_ms_to_bytes(src->tc_period,
780 rte_sched_subport_config_pipe_profile_table(struct rte_sched_subport *subport,
781 struct rte_sched_subport_params *params, uint64_t rate)
785 for (i = 0; i < subport->n_pipe_profiles; i++) {
786 struct rte_sched_pipe_params *src = params->pipe_profiles + i;
787 struct rte_sched_pipe_profile *dst = subport->pipe_profiles + i;
789 rte_sched_pipe_profile_convert(subport, src, dst, rate);
790 rte_sched_port_log_pipe_profile(subport, i);
793 subport->pipe_tc_be_rate_max = 0;
794 for (i = 0; i < subport->n_pipe_profiles; i++) {
795 struct rte_sched_pipe_params *src = params->pipe_profiles + i;
796 uint64_t pipe_tc_be_rate = src->tc_rate[RTE_SCHED_TRAFFIC_CLASS_BE];
798 if (subport->pipe_tc_be_rate_max < pipe_tc_be_rate)
799 subport->pipe_tc_be_rate_max = pipe_tc_be_rate;
804 rte_sched_port_config_subport_profile_table(struct rte_sched_port *port,
805 struct rte_sched_port_params *params,
810 for (i = 0; i < port->n_subport_profiles; i++) {
811 struct rte_sched_subport_profile_params *src
812 = params->subport_profiles + i;
813 struct rte_sched_subport_profile *dst
814 = port->subport_profiles + i;
816 rte_sched_subport_profile_convert(src, dst, rate);
817 rte_sched_port_log_subport_profile(port, i);
822 rte_sched_subport_check_params(struct rte_sched_subport_params *params,
823 uint32_t n_max_pipes_per_subport,
828 /* Check user parameters */
829 if (params == NULL) {
831 "%s: Incorrect value for parameter params\n", __func__);
835 /* qsize: if non-zero, power of 2,
836 * no bigger than 32K (due to 16-bit read/write pointers)
838 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++) {
839 uint16_t qsize = params->qsize[i];
841 if (qsize != 0 && !rte_is_power_of_2(qsize)) {
843 "%s: Incorrect value for qsize\n", __func__);
848 if (params->qsize[RTE_SCHED_TRAFFIC_CLASS_BE] == 0) {
849 RTE_LOG(ERR, SCHED, "%s: Incorrect qsize\n", __func__);
853 /* n_pipes_per_subport: non-zero, power of 2 */
854 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)) {
858 "%s: Incorrect value for pipes number\n", __func__);
862 /* pipe_profiles and n_pipe_profiles */
863 if (params->pipe_profiles == NULL ||
864 params->n_pipe_profiles == 0 ||
865 params->n_max_pipe_profiles == 0 ||
866 params->n_pipe_profiles > params->n_max_pipe_profiles) {
868 "%s: Incorrect value for pipe profiles\n", __func__);
872 for (i = 0; i < params->n_pipe_profiles; i++) {
873 struct rte_sched_pipe_params *p = params->pipe_profiles + i;
876 status = pipe_profile_check(p, rate, ¶ms->qsize[0]);
879 "%s: Pipe profile check failed(%d)\n", __func__, status);
888 rte_sched_port_get_memory_footprint(struct rte_sched_port_params *port_params,
889 struct rte_sched_subport_params **subport_params)
891 uint32_t size0 = 0, size1 = 0, i;
894 status = rte_sched_port_check_params(port_params);
897 "%s: Port scheduler port params check failed (%d)\n",
903 for (i = 0; i < port_params->n_subports_per_port; i++) {
904 struct rte_sched_subport_params *sp = subport_params[i];
906 status = rte_sched_subport_check_params(sp,
907 port_params->n_pipes_per_subport,
911 "%s: Port scheduler subport params check failed (%d)\n",
918 size0 = sizeof(struct rte_sched_port);
920 for (i = 0; i < port_params->n_subports_per_port; i++) {
921 struct rte_sched_subport_params *sp = subport_params[i];
923 size1 += rte_sched_subport_get_array_base(sp,
924 e_RTE_SCHED_SUBPORT_ARRAY_TOTAL);
927 return size0 + size1;
930 struct rte_sched_port *
931 rte_sched_port_config(struct rte_sched_port_params *params)
933 struct rte_sched_port *port = NULL;
934 uint32_t size0, size1, size2;
935 uint32_t cycles_per_byte;
939 status = rte_sched_port_check_params(params);
942 "%s: Port scheduler params check failed (%d)\n",
947 size0 = sizeof(struct rte_sched_port);
948 size1 = params->n_subports_per_port * sizeof(struct rte_sched_subport *);
949 size2 = params->n_max_subport_profiles *
950 sizeof(struct rte_sched_subport_profile);
952 /* Allocate memory to store the data structures */
953 port = rte_zmalloc_socket("qos_params", size0 + size1,
954 RTE_CACHE_LINE_SIZE, params->socket);
956 RTE_LOG(ERR, SCHED, "%s: Memory allocation fails\n", __func__);
961 /* Allocate memory to store the subport profile */
962 port->subport_profiles = rte_zmalloc_socket("subport_profile", size2,
963 RTE_CACHE_LINE_SIZE, params->socket);
965 RTE_LOG(ERR, SCHED, "%s: Memory allocation fails\n", __func__);
970 /* User parameters */
971 port->n_subports_per_port = params->n_subports_per_port;
972 port->n_subport_profiles = params->n_subport_profiles;
973 port->n_max_subport_profiles = params->n_max_subport_profiles;
974 port->n_pipes_per_subport = params->n_pipes_per_subport;
975 port->n_pipes_per_subport_log2 =
976 __builtin_ctz(params->n_pipes_per_subport);
977 port->socket = params->socket;
979 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
980 port->pipe_queue[i] = i;
982 for (i = 0, j = 0; i < RTE_SCHED_QUEUES_PER_PIPE; i++) {
983 port->pipe_tc[i] = j;
985 if (j < RTE_SCHED_TRAFFIC_CLASS_BE)
989 for (i = 0, j = 0; i < RTE_SCHED_QUEUES_PER_PIPE; i++) {
990 port->tc_queue[i] = j;
992 if (i >= RTE_SCHED_TRAFFIC_CLASS_BE)
995 port->rate = params->rate;
996 port->mtu = params->mtu + params->frame_overhead;
997 port->frame_overhead = params->frame_overhead;
1000 port->time_cpu_cycles = rte_get_tsc_cycles();
1001 port->time_cpu_bytes = 0;
1004 /* Subport profile table */
1005 rte_sched_port_config_subport_profile_table(port, params, port->rate);
1007 cycles_per_byte = (rte_get_tsc_hz() << RTE_SCHED_TIME_SHIFT)
1009 port->inv_cycles_per_byte = rte_reciprocal_value(cycles_per_byte);
1010 port->cycles_per_byte = cycles_per_byte;
1013 port->pkts_out = NULL;
1014 port->n_pkts_out = 0;
1015 port->subport_id = 0;
1021 rte_sched_subport_free(struct rte_sched_port *port,
1022 struct rte_sched_subport *subport)
1024 uint32_t n_subport_pipe_queues;
1027 if (subport == NULL)
1030 n_subport_pipe_queues = rte_sched_subport_pipe_queues(subport);
1032 /* Free enqueued mbufs */
1033 for (qindex = 0; qindex < n_subport_pipe_queues; qindex++) {
1034 struct rte_mbuf **mbufs =
1035 rte_sched_subport_pipe_qbase(subport, qindex);
1036 uint16_t qsize = rte_sched_subport_pipe_qsize(port, subport, qindex);
1038 struct rte_sched_queue *queue = subport->queue + qindex;
1039 uint16_t qr = queue->qr & (qsize - 1);
1040 uint16_t qw = queue->qw & (qsize - 1);
1042 for (; qr != qw; qr = (qr + 1) & (qsize - 1))
1043 rte_pktmbuf_free(mbufs[qr]);
1051 rte_sched_port_free(struct rte_sched_port *port)
1055 /* Check user parameters */
1059 for (i = 0; i < port->n_subports_per_port; i++)
1060 rte_sched_subport_free(port, port->subports[i]);
1062 rte_free(port->subport_profiles);
1067 rte_sched_free_memory(struct rte_sched_port *port, uint32_t n_subports)
1071 for (i = 0; i < n_subports; i++) {
1072 struct rte_sched_subport *subport = port->subports[i];
1074 rte_sched_subport_free(port, subport);
1077 rte_free(port->subport_profiles);
1082 rte_sched_subport_config(struct rte_sched_port *port,
1083 uint32_t subport_id,
1084 struct rte_sched_subport_params *params,
1085 uint32_t subport_profile_id)
1087 struct rte_sched_subport *s = NULL;
1088 uint32_t n_subports = subport_id;
1089 struct rte_sched_subport_profile *profile;
1090 uint32_t n_subport_pipe_queues, i;
1091 uint32_t size0, size1, bmp_mem_size;
1094 /* Check user parameters */
1097 "%s: Incorrect value for parameter port\n", __func__);
1101 if (subport_id >= port->n_subports_per_port) {
1103 "%s: Incorrect value for subport id\n", __func__);
1105 rte_sched_free_memory(port, n_subports);
1109 if (subport_profile_id >= port->n_max_subport_profiles) {
1110 RTE_LOG(ERR, SCHED, "%s: "
1111 "Number of subport profile exceeds the max limit\n",
1113 rte_sched_free_memory(port, n_subports);
1117 /** Memory is allocated only on first invocation of the api for a
1118 * given subport. Subsequent invocation on same subport will just
1119 * update subport bandwidth parameter.
1121 if (port->subports[subport_id] == NULL) {
1123 status = rte_sched_subport_check_params(params,
1124 port->n_pipes_per_subport,
1127 RTE_LOG(NOTICE, SCHED,
1128 "%s: Port scheduler params check failed (%d)\n",
1131 rte_sched_free_memory(port, n_subports);
1135 /* Determine the amount of memory to allocate */
1136 size0 = sizeof(struct rte_sched_subport);
1137 size1 = rte_sched_subport_get_array_base(params,
1138 e_RTE_SCHED_SUBPORT_ARRAY_TOTAL);
1140 /* Allocate memory to store the data structures */
1141 s = rte_zmalloc_socket("subport_params", size0 + size1,
1142 RTE_CACHE_LINE_SIZE, port->socket);
1145 "%s: Memory allocation fails\n", __func__);
1147 rte_sched_free_memory(port, n_subports);
1153 subport_profile_id = 0;
1156 port->subports[subport_id] = s;
1158 s->tb_time = port->time;
1160 /* compile time checks */
1161 RTE_BUILD_BUG_ON(RTE_SCHED_PORT_N_GRINDERS == 0);
1162 RTE_BUILD_BUG_ON(RTE_SCHED_PORT_N_GRINDERS &
1163 (RTE_SCHED_PORT_N_GRINDERS - 1));
1165 /* User parameters */
1166 s->n_pipes_per_subport_enabled =
1167 params->n_pipes_per_subport_enabled;
1168 memcpy(s->qsize, params->qsize, sizeof(params->qsize));
1169 s->n_pipe_profiles = params->n_pipe_profiles;
1170 s->n_max_pipe_profiles = params->n_max_pipe_profiles;
1172 #ifdef RTE_SCHED_RED
1173 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++) {
1176 for (j = 0; j < RTE_COLORS; j++) {
1177 /* if min/max are both zero, then RED is disabled */
1178 if ((params->red_params[i][j].min_th |
1179 params->red_params[i][j].max_th) == 0) {
1183 if (rte_red_config_init(&s->red_config[i][j],
1184 params->red_params[i][j].wq_log2,
1185 params->red_params[i][j].min_th,
1186 params->red_params[i][j].max_th,
1187 params->red_params[i][j].maxp_inv) != 0) {
1188 rte_sched_free_memory(port, n_subports);
1190 RTE_LOG(NOTICE, SCHED,
1191 "%s: RED configuration init fails\n",
1199 /* Scheduling loop detection */
1200 s->pipe_loop = RTE_SCHED_PIPE_INVALID;
1201 s->pipe_exhaustion = 0;
1204 s->busy_grinders = 0;
1206 /* Queue base calculation */
1207 rte_sched_subport_config_qsize(s);
1209 /* Large data structures */
1210 s->pipe = (struct rte_sched_pipe *)
1211 (s->memory + rte_sched_subport_get_array_base(params,
1212 e_RTE_SCHED_SUBPORT_ARRAY_PIPE));
1213 s->queue = (struct rte_sched_queue *)
1214 (s->memory + rte_sched_subport_get_array_base(params,
1215 e_RTE_SCHED_SUBPORT_ARRAY_QUEUE));
1216 s->queue_extra = (struct rte_sched_queue_extra *)
1217 (s->memory + rte_sched_subport_get_array_base(params,
1218 e_RTE_SCHED_SUBPORT_ARRAY_QUEUE_EXTRA));
1219 s->pipe_profiles = (struct rte_sched_pipe_profile *)
1220 (s->memory + rte_sched_subport_get_array_base(params,
1221 e_RTE_SCHED_SUBPORT_ARRAY_PIPE_PROFILES));
1222 s->bmp_array = s->memory + rte_sched_subport_get_array_base(
1223 params, e_RTE_SCHED_SUBPORT_ARRAY_BMP_ARRAY);
1224 s->queue_array = (struct rte_mbuf **)
1225 (s->memory + rte_sched_subport_get_array_base(params,
1226 e_RTE_SCHED_SUBPORT_ARRAY_QUEUE_ARRAY));
1228 /* Pipe profile table */
1229 rte_sched_subport_config_pipe_profile_table(s, params,
1233 n_subport_pipe_queues = rte_sched_subport_pipe_queues(s);
1234 bmp_mem_size = rte_bitmap_get_memory_footprint(
1235 n_subport_pipe_queues);
1236 s->bmp = rte_bitmap_init(n_subport_pipe_queues, s->bmp_array,
1238 if (s->bmp == NULL) {
1240 "%s: Subport bitmap init error\n", __func__);
1242 rte_sched_free_memory(port, n_subports);
1246 for (i = 0; i < RTE_SCHED_PORT_N_GRINDERS; i++)
1247 s->grinder_base_bmp_pos[i] = RTE_SCHED_PIPE_INVALID;
1249 #ifdef RTE_SCHED_SUBPORT_TC_OV
1250 /* TC oversubscription */
1251 s->tc_ov_wm_min = port->mtu;
1252 s->tc_ov_wm = s->tc_ov_wm_max;
1253 s->tc_ov_period_id = 0;
1261 /* update subport parameters from subport profile table*/
1262 profile = port->subport_profiles + subport_profile_id;
1264 s = port->subports[subport_id];
1266 s->tb_credits = profile->tb_size / 2;
1268 s->tc_time = port->time + profile->tc_period;
1270 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
1273 profile->tc_credits_per_period[i];
1275 profile->tc_credits_per_period[i] = 0;
1277 #ifdef RTE_SCHED_SUBPORT_TC_OV
1278 s->tc_ov_wm_max = rte_sched_time_ms_to_bytes(profile->tc_period,
1279 s->pipe_tc_be_rate_max);
1281 s->profile = subport_profile_id;
1285 rte_sched_port_log_subport_profile(port, subport_profile_id);
1291 rte_sched_pipe_config(struct rte_sched_port *port,
1292 uint32_t subport_id,
1294 int32_t pipe_profile)
1296 struct rte_sched_subport *s;
1297 struct rte_sched_subport_profile *sp;
1298 struct rte_sched_pipe *p;
1299 struct rte_sched_pipe_profile *params;
1300 uint32_t n_subports = subport_id + 1;
1301 uint32_t deactivate, profile, i;
1303 /* Check user parameters */
1304 profile = (uint32_t) pipe_profile;
1305 deactivate = (pipe_profile < 0);
1309 "%s: Incorrect value for parameter port\n", __func__);
1313 if (subport_id >= port->n_subports_per_port) {
1315 "%s: Incorrect value for parameter subport id\n", __func__);
1317 rte_sched_free_memory(port, n_subports);
1321 s = port->subports[subport_id];
1322 if (pipe_id >= s->n_pipes_per_subport_enabled) {
1324 "%s: Incorrect value for parameter pipe id\n", __func__);
1326 rte_sched_free_memory(port, n_subports);
1330 if (!deactivate && profile >= s->n_pipe_profiles) {
1332 "%s: Incorrect value for parameter pipe profile\n", __func__);
1334 rte_sched_free_memory(port, n_subports);
1338 sp = port->subport_profiles + s->profile;
1339 /* Handle the case when pipe already has a valid configuration */
1340 p = s->pipe + pipe_id;
1342 params = s->pipe_profiles + p->profile;
1344 double subport_tc_be_rate =
1345 (double)sp->tc_credits_per_period[RTE_SCHED_TRAFFIC_CLASS_BE]
1346 / (double) sp->tc_period;
1347 double pipe_tc_be_rate =
1348 (double) params->tc_credits_per_period[RTE_SCHED_TRAFFIC_CLASS_BE]
1349 / (double) params->tc_period;
1350 uint32_t tc_be_ov = s->tc_ov;
1352 /* Unplug pipe from its subport */
1353 s->tc_ov_n -= params->tc_ov_weight;
1354 s->tc_ov_rate -= pipe_tc_be_rate;
1355 s->tc_ov = s->tc_ov_rate > subport_tc_be_rate;
1357 if (s->tc_ov != tc_be_ov) {
1358 RTE_LOG(DEBUG, SCHED,
1359 "Subport %u Best-effort TC oversubscription is OFF (%.4lf >= %.4lf)\n",
1360 subport_id, subport_tc_be_rate, s->tc_ov_rate);
1363 /* Reset the pipe */
1364 memset(p, 0, sizeof(struct rte_sched_pipe));
1370 /* Apply the new pipe configuration */
1371 p->profile = profile;
1372 params = s->pipe_profiles + p->profile;
1374 /* Token Bucket (TB) */
1375 p->tb_time = port->time;
1376 p->tb_credits = params->tb_size / 2;
1378 /* Traffic Classes (TCs) */
1379 p->tc_time = port->time + params->tc_period;
1381 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
1383 p->tc_credits[i] = params->tc_credits_per_period[i];
1386 /* Subport best effort tc oversubscription */
1387 double subport_tc_be_rate =
1388 (double)sp->tc_credits_per_period[RTE_SCHED_TRAFFIC_CLASS_BE]
1389 / (double) sp->tc_period;
1390 double pipe_tc_be_rate =
1391 (double) params->tc_credits_per_period[RTE_SCHED_TRAFFIC_CLASS_BE]
1392 / (double) params->tc_period;
1393 uint32_t tc_be_ov = s->tc_ov;
1395 s->tc_ov_n += params->tc_ov_weight;
1396 s->tc_ov_rate += pipe_tc_be_rate;
1397 s->tc_ov = s->tc_ov_rate > subport_tc_be_rate;
1399 if (s->tc_ov != tc_be_ov) {
1400 RTE_LOG(DEBUG, SCHED,
1401 "Subport %u Best effort TC oversubscription is ON (%.4lf < %.4lf)\n",
1402 subport_id, subport_tc_be_rate, s->tc_ov_rate);
1404 p->tc_ov_period_id = s->tc_ov_period_id;
1405 p->tc_ov_credits = s->tc_ov_wm;
1412 rte_sched_subport_pipe_profile_add(struct rte_sched_port *port,
1413 uint32_t subport_id,
1414 struct rte_sched_pipe_params *params,
1415 uint32_t *pipe_profile_id)
1417 struct rte_sched_subport *s;
1418 struct rte_sched_pipe_profile *pp;
1425 "%s: Incorrect value for parameter port\n", __func__);
1429 /* Subport id not exceeds the max limit */
1430 if (subport_id > port->n_subports_per_port) {
1432 "%s: Incorrect value for subport id\n", __func__);
1436 s = port->subports[subport_id];
1438 /* Pipe profiles exceeds the max limit */
1439 if (s->n_pipe_profiles >= s->n_max_pipe_profiles) {
1441 "%s: Number of pipe profiles exceeds the max limit\n", __func__);
1446 status = pipe_profile_check(params, port->rate, &s->qsize[0]);
1449 "%s: Pipe profile check failed(%d)\n", __func__, status);
1453 pp = &s->pipe_profiles[s->n_pipe_profiles];
1454 rte_sched_pipe_profile_convert(s, params, pp, port->rate);
1456 /* Pipe profile should not exists */
1457 for (i = 0; i < s->n_pipe_profiles; i++)
1458 if (memcmp(s->pipe_profiles + i, pp, sizeof(*pp)) == 0) {
1460 "%s: Pipe profile exists\n", __func__);
1464 /* Pipe profile commit */
1465 *pipe_profile_id = s->n_pipe_profiles;
1466 s->n_pipe_profiles++;
1468 if (s->pipe_tc_be_rate_max < params->tc_rate[RTE_SCHED_TRAFFIC_CLASS_BE])
1469 s->pipe_tc_be_rate_max = params->tc_rate[RTE_SCHED_TRAFFIC_CLASS_BE];
1471 rte_sched_port_log_pipe_profile(s, *pipe_profile_id);
1477 rte_sched_port_subport_profile_add(struct rte_sched_port *port,
1478 struct rte_sched_subport_profile_params *params,
1479 uint32_t *subport_profile_id)
1483 struct rte_sched_subport_profile *dst;
1487 RTE_LOG(ERR, SCHED, "%s: "
1488 "Incorrect value for parameter port\n", __func__);
1492 if (params == NULL) {
1493 RTE_LOG(ERR, SCHED, "%s: "
1494 "Incorrect value for parameter profile\n", __func__);
1498 if (subport_profile_id == NULL) {
1499 RTE_LOG(ERR, SCHED, "%s: "
1500 "Incorrect value for parameter subport_profile_id\n",
1505 dst = port->subport_profiles + port->n_subport_profiles;
1507 /* Subport profiles exceeds the max limit */
1508 if (port->n_subport_profiles >= port->n_max_subport_profiles) {
1509 RTE_LOG(ERR, SCHED, "%s: "
1510 "Number of subport profiles exceeds the max limit\n",
1515 status = subport_profile_check(params, port->rate);
1518 "%s: subport profile check failed(%d)\n", __func__, status);
1522 rte_sched_subport_profile_convert(params, dst, port->rate);
1524 /* Subport profile should not exists */
1525 for (i = 0; i < port->n_subport_profiles; i++)
1526 if (memcmp(port->subport_profiles + i,
1527 dst, sizeof(*dst)) == 0) {
1529 "%s: subport profile exists\n", __func__);
1533 /* Subport profile commit */
1534 *subport_profile_id = port->n_subport_profiles;
1535 port->n_subport_profiles++;
1537 rte_sched_port_log_subport_profile(port, *subport_profile_id);
1542 static inline uint32_t
1543 rte_sched_port_qindex(struct rte_sched_port *port,
1546 uint32_t traffic_class,
1549 return ((subport & (port->n_subports_per_port - 1)) <<
1550 (port->n_pipes_per_subport_log2 + 4)) |
1552 (port->subports[subport]->n_pipes_per_subport_enabled - 1)) << 4) |
1553 ((rte_sched_port_pipe_queue(port, traffic_class) + queue) &
1554 (RTE_SCHED_QUEUES_PER_PIPE - 1));
1558 rte_sched_port_pkt_write(struct rte_sched_port *port,
1559 struct rte_mbuf *pkt,
1560 uint32_t subport, uint32_t pipe,
1561 uint32_t traffic_class,
1562 uint32_t queue, enum rte_color color)
1565 rte_sched_port_qindex(port, subport, pipe, traffic_class, queue);
1567 rte_mbuf_sched_set(pkt, queue_id, traffic_class, (uint8_t)color);
1571 rte_sched_port_pkt_read_tree_path(struct rte_sched_port *port,
1572 const struct rte_mbuf *pkt,
1573 uint32_t *subport, uint32_t *pipe,
1574 uint32_t *traffic_class, uint32_t *queue)
1576 uint32_t queue_id = rte_mbuf_sched_queue_get(pkt);
1578 *subport = queue_id >> (port->n_pipes_per_subport_log2 + 4);
1579 *pipe = (queue_id >> 4) &
1580 (port->subports[*subport]->n_pipes_per_subport_enabled - 1);
1581 *traffic_class = rte_sched_port_pipe_tc(port, queue_id);
1582 *queue = rte_sched_port_tc_queue(port, queue_id);
1586 rte_sched_port_pkt_read_color(const struct rte_mbuf *pkt)
1588 return (enum rte_color)rte_mbuf_sched_color_get(pkt);
1592 rte_sched_subport_read_stats(struct rte_sched_port *port,
1593 uint32_t subport_id,
1594 struct rte_sched_subport_stats *stats,
1597 struct rte_sched_subport *s;
1599 /* Check user parameters */
1602 "%s: Incorrect value for parameter port\n", __func__);
1606 if (subport_id >= port->n_subports_per_port) {
1608 "%s: Incorrect value for subport id\n", __func__);
1612 if (stats == NULL) {
1614 "%s: Incorrect value for parameter stats\n", __func__);
1618 if (tc_ov == NULL) {
1620 "%s: Incorrect value for tc_ov\n", __func__);
1624 s = port->subports[subport_id];
1626 /* Copy subport stats and clear */
1627 memcpy(stats, &s->stats, sizeof(struct rte_sched_subport_stats));
1628 memset(&s->stats, 0, sizeof(struct rte_sched_subport_stats));
1630 /* Subport TC oversubscription status */
1637 rte_sched_queue_read_stats(struct rte_sched_port *port,
1639 struct rte_sched_queue_stats *stats,
1642 struct rte_sched_subport *s;
1643 struct rte_sched_queue *q;
1644 struct rte_sched_queue_extra *qe;
1645 uint32_t subport_id, subport_qmask, subport_qindex;
1647 /* Check user parameters */
1650 "%s: Incorrect value for parameter port\n", __func__);
1654 if (queue_id >= rte_sched_port_queues_per_port(port)) {
1656 "%s: Incorrect value for queue id\n", __func__);
1660 if (stats == NULL) {
1662 "%s: Incorrect value for parameter stats\n", __func__);
1668 "%s: Incorrect value for parameter qlen\n", __func__);
1671 subport_qmask = port->n_pipes_per_subport_log2 + 4;
1672 subport_id = (queue_id >> subport_qmask) & (port->n_subports_per_port - 1);
1674 s = port->subports[subport_id];
1675 subport_qindex = ((1 << subport_qmask) - 1) & queue_id;
1676 q = s->queue + subport_qindex;
1677 qe = s->queue_extra + subport_qindex;
1679 /* Copy queue stats and clear */
1680 memcpy(stats, &qe->stats, sizeof(struct rte_sched_queue_stats));
1681 memset(&qe->stats, 0, sizeof(struct rte_sched_queue_stats));
1684 *qlen = q->qw - q->qr;
1689 #ifdef RTE_SCHED_DEBUG
1692 rte_sched_port_queue_is_empty(struct rte_sched_subport *subport,
1695 struct rte_sched_queue *queue = subport->queue + qindex;
1697 return queue->qr == queue->qw;
1700 #endif /* RTE_SCHED_DEBUG */
1702 #ifdef RTE_SCHED_COLLECT_STATS
1705 rte_sched_port_update_subport_stats(struct rte_sched_port *port,
1706 struct rte_sched_subport *subport,
1708 struct rte_mbuf *pkt)
1710 uint32_t tc_index = rte_sched_port_pipe_tc(port, qindex);
1711 uint32_t pkt_len = pkt->pkt_len;
1713 subport->stats.n_pkts_tc[tc_index] += 1;
1714 subport->stats.n_bytes_tc[tc_index] += pkt_len;
1717 #ifdef RTE_SCHED_RED
1719 rte_sched_port_update_subport_stats_on_drop(struct rte_sched_port *port,
1720 struct rte_sched_subport *subport,
1722 struct rte_mbuf *pkt,
1726 rte_sched_port_update_subport_stats_on_drop(struct rte_sched_port *port,
1727 struct rte_sched_subport *subport,
1729 struct rte_mbuf *pkt,
1730 __rte_unused uint32_t red)
1733 uint32_t tc_index = rte_sched_port_pipe_tc(port, qindex);
1734 uint32_t pkt_len = pkt->pkt_len;
1736 subport->stats.n_pkts_tc_dropped[tc_index] += 1;
1737 subport->stats.n_bytes_tc_dropped[tc_index] += pkt_len;
1738 #ifdef RTE_SCHED_RED
1739 subport->stats.n_pkts_red_dropped[tc_index] += red;
1744 rte_sched_port_update_queue_stats(struct rte_sched_subport *subport,
1746 struct rte_mbuf *pkt)
1748 struct rte_sched_queue_extra *qe = subport->queue_extra + qindex;
1749 uint32_t pkt_len = pkt->pkt_len;
1751 qe->stats.n_pkts += 1;
1752 qe->stats.n_bytes += pkt_len;
1755 #ifdef RTE_SCHED_RED
1757 rte_sched_port_update_queue_stats_on_drop(struct rte_sched_subport *subport,
1759 struct rte_mbuf *pkt,
1763 rte_sched_port_update_queue_stats_on_drop(struct rte_sched_subport *subport,
1765 struct rte_mbuf *pkt,
1766 __rte_unused uint32_t red)
1769 struct rte_sched_queue_extra *qe = subport->queue_extra + qindex;
1770 uint32_t pkt_len = pkt->pkt_len;
1772 qe->stats.n_pkts_dropped += 1;
1773 qe->stats.n_bytes_dropped += pkt_len;
1774 #ifdef RTE_SCHED_RED
1775 qe->stats.n_pkts_red_dropped += red;
1779 #endif /* RTE_SCHED_COLLECT_STATS */
1781 #ifdef RTE_SCHED_RED
1784 rte_sched_port_red_drop(struct rte_sched_port *port,
1785 struct rte_sched_subport *subport,
1786 struct rte_mbuf *pkt,
1790 struct rte_sched_queue_extra *qe;
1791 struct rte_red_config *red_cfg;
1792 struct rte_red *red;
1794 enum rte_color color;
1796 tc_index = rte_sched_port_pipe_tc(port, qindex);
1797 color = rte_sched_port_pkt_read_color(pkt);
1798 red_cfg = &subport->red_config[tc_index][color];
1800 if ((red_cfg->min_th | red_cfg->max_th) == 0)
1803 qe = subport->queue_extra + qindex;
1806 return rte_red_enqueue(red_cfg, red, qlen, port->time);
1810 rte_sched_port_set_queue_empty_timestamp(struct rte_sched_port *port,
1811 struct rte_sched_subport *subport, uint32_t qindex)
1813 struct rte_sched_queue_extra *qe = subport->queue_extra + qindex;
1814 struct rte_red *red = &qe->red;
1816 rte_red_mark_queue_empty(red, port->time);
1821 static inline int rte_sched_port_red_drop(struct rte_sched_port *port __rte_unused,
1822 struct rte_sched_subport *subport __rte_unused,
1823 struct rte_mbuf *pkt __rte_unused,
1824 uint32_t qindex __rte_unused,
1825 uint16_t qlen __rte_unused)
1830 #define rte_sched_port_set_queue_empty_timestamp(port, subport, qindex)
1832 #endif /* RTE_SCHED_RED */
1834 #ifdef RTE_SCHED_DEBUG
1837 debug_check_queue_slab(struct rte_sched_subport *subport, uint32_t bmp_pos,
1844 rte_panic("Empty slab at position %u\n", bmp_pos);
1847 for (i = 0, mask = 1; i < 64; i++, mask <<= 1) {
1848 if (mask & bmp_slab) {
1849 if (rte_sched_port_queue_is_empty(subport, bmp_pos + i)) {
1850 printf("Queue %u (slab offset %u) is empty\n", bmp_pos + i, i);
1857 rte_panic("Empty queues in slab 0x%" PRIx64 "starting at position %u\n",
1861 #endif /* RTE_SCHED_DEBUG */
1863 static inline struct rte_sched_subport *
1864 rte_sched_port_subport(struct rte_sched_port *port,
1865 struct rte_mbuf *pkt)
1867 uint32_t queue_id = rte_mbuf_sched_queue_get(pkt);
1868 uint32_t subport_id = queue_id >> (port->n_pipes_per_subport_log2 + 4);
1870 return port->subports[subport_id];
1873 static inline uint32_t
1874 rte_sched_port_enqueue_qptrs_prefetch0(struct rte_sched_subport *subport,
1875 struct rte_mbuf *pkt, uint32_t subport_qmask)
1877 struct rte_sched_queue *q;
1878 #ifdef RTE_SCHED_COLLECT_STATS
1879 struct rte_sched_queue_extra *qe;
1881 uint32_t qindex = rte_mbuf_sched_queue_get(pkt);
1882 uint32_t subport_queue_id = subport_qmask & qindex;
1884 q = subport->queue + subport_queue_id;
1886 #ifdef RTE_SCHED_COLLECT_STATS
1887 qe = subport->queue_extra + subport_queue_id;
1891 return subport_queue_id;
1895 rte_sched_port_enqueue_qwa_prefetch0(struct rte_sched_port *port,
1896 struct rte_sched_subport *subport,
1898 struct rte_mbuf **qbase)
1900 struct rte_sched_queue *q;
1901 struct rte_mbuf **q_qw;
1904 q = subport->queue + qindex;
1905 qsize = rte_sched_subport_pipe_qsize(port, subport, qindex);
1906 q_qw = qbase + (q->qw & (qsize - 1));
1908 rte_prefetch0(q_qw);
1909 rte_bitmap_prefetch0(subport->bmp, qindex);
1913 rte_sched_port_enqueue_qwa(struct rte_sched_port *port,
1914 struct rte_sched_subport *subport,
1916 struct rte_mbuf **qbase,
1917 struct rte_mbuf *pkt)
1919 struct rte_sched_queue *q;
1923 q = subport->queue + qindex;
1924 qsize = rte_sched_subport_pipe_qsize(port, subport, qindex);
1925 qlen = q->qw - q->qr;
1927 /* Drop the packet (and update drop stats) when queue is full */
1928 if (unlikely(rte_sched_port_red_drop(port, subport, pkt, qindex, qlen) ||
1930 rte_pktmbuf_free(pkt);
1931 #ifdef RTE_SCHED_COLLECT_STATS
1932 rte_sched_port_update_subport_stats_on_drop(port, subport,
1933 qindex, pkt, qlen < qsize);
1934 rte_sched_port_update_queue_stats_on_drop(subport, qindex, pkt,
1940 /* Enqueue packet */
1941 qbase[q->qw & (qsize - 1)] = pkt;
1944 /* Activate queue in the subport bitmap */
1945 rte_bitmap_set(subport->bmp, qindex);
1948 #ifdef RTE_SCHED_COLLECT_STATS
1949 rte_sched_port_update_subport_stats(port, subport, qindex, pkt);
1950 rte_sched_port_update_queue_stats(subport, qindex, pkt);
1958 * The enqueue function implements a 4-level pipeline with each stage
1959 * processing two different packets. The purpose of using a pipeline
1960 * is to hide the latency of prefetching the data structures. The
1961 * naming convention is presented in the diagram below:
1963 * p00 _______ p10 _______ p20 _______ p30 _______
1964 * ----->| |----->| |----->| |----->| |----->
1965 * | 0 | | 1 | | 2 | | 3 |
1966 * ----->|_______|----->|_______|----->|_______|----->|_______|----->
1971 rte_sched_port_enqueue(struct rte_sched_port *port, struct rte_mbuf **pkts,
1974 struct rte_mbuf *pkt00, *pkt01, *pkt10, *pkt11, *pkt20, *pkt21,
1975 *pkt30, *pkt31, *pkt_last;
1976 struct rte_mbuf **q00_base, **q01_base, **q10_base, **q11_base,
1977 **q20_base, **q21_base, **q30_base, **q31_base, **q_last_base;
1978 struct rte_sched_subport *subport00, *subport01, *subport10, *subport11,
1979 *subport20, *subport21, *subport30, *subport31, *subport_last;
1980 uint32_t q00, q01, q10, q11, q20, q21, q30, q31, q_last;
1981 uint32_t r00, r01, r10, r11, r20, r21, r30, r31, r_last;
1982 uint32_t subport_qmask;
1986 subport_qmask = (1 << (port->n_pipes_per_subport_log2 + 4)) - 1;
1989 * Less then 6 input packets available, which is not enough to
1992 if (unlikely(n_pkts < 6)) {
1993 struct rte_sched_subport *subports[5];
1994 struct rte_mbuf **q_base[5];
1997 /* Prefetch the mbuf structure of each packet */
1998 for (i = 0; i < n_pkts; i++)
1999 rte_prefetch0(pkts[i]);
2001 /* Prefetch the subport structure for each packet */
2002 for (i = 0; i < n_pkts; i++)
2003 subports[i] = rte_sched_port_subport(port, pkts[i]);
2005 /* Prefetch the queue structure for each queue */
2006 for (i = 0; i < n_pkts; i++)
2007 q[i] = rte_sched_port_enqueue_qptrs_prefetch0(subports[i],
2008 pkts[i], subport_qmask);
2010 /* Prefetch the write pointer location of each queue */
2011 for (i = 0; i < n_pkts; i++) {
2012 q_base[i] = rte_sched_subport_pipe_qbase(subports[i], q[i]);
2013 rte_sched_port_enqueue_qwa_prefetch0(port, subports[i],
2017 /* Write each packet to its queue */
2018 for (i = 0; i < n_pkts; i++)
2019 result += rte_sched_port_enqueue_qwa(port, subports[i],
2020 q[i], q_base[i], pkts[i]);
2025 /* Feed the first 3 stages of the pipeline (6 packets needed) */
2028 rte_prefetch0(pkt20);
2029 rte_prefetch0(pkt21);
2033 rte_prefetch0(pkt10);
2034 rte_prefetch0(pkt11);
2036 subport20 = rte_sched_port_subport(port, pkt20);
2037 subport21 = rte_sched_port_subport(port, pkt21);
2038 q20 = rte_sched_port_enqueue_qptrs_prefetch0(subport20,
2039 pkt20, subport_qmask);
2040 q21 = rte_sched_port_enqueue_qptrs_prefetch0(subport21,
2041 pkt21, subport_qmask);
2045 rte_prefetch0(pkt00);
2046 rte_prefetch0(pkt01);
2048 subport10 = rte_sched_port_subport(port, pkt10);
2049 subport11 = rte_sched_port_subport(port, pkt11);
2050 q10 = rte_sched_port_enqueue_qptrs_prefetch0(subport10,
2051 pkt10, subport_qmask);
2052 q11 = rte_sched_port_enqueue_qptrs_prefetch0(subport11,
2053 pkt11, subport_qmask);
2055 q20_base = rte_sched_subport_pipe_qbase(subport20, q20);
2056 q21_base = rte_sched_subport_pipe_qbase(subport21, q21);
2057 rte_sched_port_enqueue_qwa_prefetch0(port, subport20, q20, q20_base);
2058 rte_sched_port_enqueue_qwa_prefetch0(port, subport21, q21, q21_base);
2060 /* Run the pipeline */
2061 for (i = 6; i < (n_pkts & (~1)); i += 2) {
2062 /* Propagate stage inputs */
2073 subport30 = subport20;
2074 subport31 = subport21;
2075 subport20 = subport10;
2076 subport21 = subport11;
2077 q30_base = q20_base;
2078 q31_base = q21_base;
2080 /* Stage 0: Get packets in */
2082 pkt01 = pkts[i + 1];
2083 rte_prefetch0(pkt00);
2084 rte_prefetch0(pkt01);
2086 /* Stage 1: Prefetch subport and queue structure storing queue pointers */
2087 subport10 = rte_sched_port_subport(port, pkt10);
2088 subport11 = rte_sched_port_subport(port, pkt11);
2089 q10 = rte_sched_port_enqueue_qptrs_prefetch0(subport10,
2090 pkt10, subport_qmask);
2091 q11 = rte_sched_port_enqueue_qptrs_prefetch0(subport11,
2092 pkt11, subport_qmask);
2094 /* Stage 2: Prefetch queue write location */
2095 q20_base = rte_sched_subport_pipe_qbase(subport20, q20);
2096 q21_base = rte_sched_subport_pipe_qbase(subport21, q21);
2097 rte_sched_port_enqueue_qwa_prefetch0(port, subport20, q20, q20_base);
2098 rte_sched_port_enqueue_qwa_prefetch0(port, subport21, q21, q21_base);
2100 /* Stage 3: Write packet to queue and activate queue */
2101 r30 = rte_sched_port_enqueue_qwa(port, subport30,
2102 q30, q30_base, pkt30);
2103 r31 = rte_sched_port_enqueue_qwa(port, subport31,
2104 q31, q31_base, pkt31);
2105 result += r30 + r31;
2109 * Drain the pipeline (exactly 6 packets).
2110 * Handle the last packet in the case
2111 * of an odd number of input packets.
2113 pkt_last = pkts[n_pkts - 1];
2114 rte_prefetch0(pkt_last);
2116 subport00 = rte_sched_port_subport(port, pkt00);
2117 subport01 = rte_sched_port_subport(port, pkt01);
2118 q00 = rte_sched_port_enqueue_qptrs_prefetch0(subport00,
2119 pkt00, subport_qmask);
2120 q01 = rte_sched_port_enqueue_qptrs_prefetch0(subport01,
2121 pkt01, subport_qmask);
2123 q10_base = rte_sched_subport_pipe_qbase(subport10, q10);
2124 q11_base = rte_sched_subport_pipe_qbase(subport11, q11);
2125 rte_sched_port_enqueue_qwa_prefetch0(port, subport10, q10, q10_base);
2126 rte_sched_port_enqueue_qwa_prefetch0(port, subport11, q11, q11_base);
2128 r20 = rte_sched_port_enqueue_qwa(port, subport20,
2129 q20, q20_base, pkt20);
2130 r21 = rte_sched_port_enqueue_qwa(port, subport21,
2131 q21, q21_base, pkt21);
2132 result += r20 + r21;
2134 subport_last = rte_sched_port_subport(port, pkt_last);
2135 q_last = rte_sched_port_enqueue_qptrs_prefetch0(subport_last,
2136 pkt_last, subport_qmask);
2138 q00_base = rte_sched_subport_pipe_qbase(subport00, q00);
2139 q01_base = rte_sched_subport_pipe_qbase(subport01, q01);
2140 rte_sched_port_enqueue_qwa_prefetch0(port, subport00, q00, q00_base);
2141 rte_sched_port_enqueue_qwa_prefetch0(port, subport01, q01, q01_base);
2143 r10 = rte_sched_port_enqueue_qwa(port, subport10, q10,
2145 r11 = rte_sched_port_enqueue_qwa(port, subport11, q11,
2147 result += r10 + r11;
2149 q_last_base = rte_sched_subport_pipe_qbase(subport_last, q_last);
2150 rte_sched_port_enqueue_qwa_prefetch0(port, subport_last,
2151 q_last, q_last_base);
2153 r00 = rte_sched_port_enqueue_qwa(port, subport00, q00,
2155 r01 = rte_sched_port_enqueue_qwa(port, subport01, q01,
2157 result += r00 + r01;
2160 r_last = rte_sched_port_enqueue_qwa(port, subport_last,
2161 q_last, q_last_base, pkt_last);
2168 #ifndef RTE_SCHED_SUBPORT_TC_OV
2171 grinder_credits_update(struct rte_sched_port *port,
2172 struct rte_sched_subport *subport, uint32_t pos)
2174 struct rte_sched_grinder *grinder = subport->grinder + pos;
2175 struct rte_sched_pipe *pipe = grinder->pipe;
2176 struct rte_sched_pipe_profile *params = grinder->pipe_params;
2177 struct rte_sched_subport_profile *sp = grinder->subport_params;
2182 n_periods = (port->time - subport->tb_time) / sp->tb_period;
2183 subport->tb_credits += n_periods * sp->tb_credits_per_period;
2184 subport->tb_credits = RTE_MIN(subport->tb_credits, sp->tb_size);
2185 subport->tb_time += n_periods * sp->tb_period;
2188 n_periods = (port->time - pipe->tb_time) / params->tb_period;
2189 pipe->tb_credits += n_periods * params->tb_credits_per_period;
2190 pipe->tb_credits = RTE_MIN(pipe->tb_credits, params->tb_size);
2191 pipe->tb_time += n_periods * params->tb_period;
2194 if (unlikely(port->time >= subport->tc_time)) {
2195 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
2196 subport->tc_credits[i] = sp->tc_credits_per_period[i];
2198 subport->tc_time = port->time + sp->tc_period;
2202 if (unlikely(port->time >= pipe->tc_time)) {
2203 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
2204 pipe->tc_credits[i] = params->tc_credits_per_period[i];
2206 pipe->tc_time = port->time + params->tc_period;
2212 static inline uint64_t
2213 grinder_tc_ov_credits_update(struct rte_sched_port *port,
2214 struct rte_sched_subport *subport, uint32_t pos)
2216 struct rte_sched_grinder *grinder = subport->grinder + pos;
2217 struct rte_sched_subport_profile *sp = grinder->subport_params;
2218 uint64_t tc_ov_consumption[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
2219 uint64_t tc_consumption = 0, tc_ov_consumption_max;
2220 uint64_t tc_ov_wm = subport->tc_ov_wm;
2223 if (subport->tc_ov == 0)
2224 return subport->tc_ov_wm_max;
2226 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASS_BE; i++) {
2227 tc_ov_consumption[i] = sp->tc_credits_per_period[i]
2228 - subport->tc_credits[i];
2229 tc_consumption += tc_ov_consumption[i];
2232 tc_ov_consumption[RTE_SCHED_TRAFFIC_CLASS_BE] =
2233 sp->tc_credits_per_period[RTE_SCHED_TRAFFIC_CLASS_BE] -
2234 subport->tc_credits[RTE_SCHED_TRAFFIC_CLASS_BE];
2236 tc_ov_consumption_max =
2237 sp->tc_credits_per_period[RTE_SCHED_TRAFFIC_CLASS_BE] -
2240 if (tc_ov_consumption[RTE_SCHED_TRAFFIC_CLASS_BE] >
2241 (tc_ov_consumption_max - port->mtu)) {
2242 tc_ov_wm -= tc_ov_wm >> 7;
2243 if (tc_ov_wm < subport->tc_ov_wm_min)
2244 tc_ov_wm = subport->tc_ov_wm_min;
2249 tc_ov_wm += (tc_ov_wm >> 7) + 1;
2250 if (tc_ov_wm > subport->tc_ov_wm_max)
2251 tc_ov_wm = subport->tc_ov_wm_max;
2257 grinder_credits_update(struct rte_sched_port *port,
2258 struct rte_sched_subport *subport, uint32_t pos)
2260 struct rte_sched_grinder *grinder = subport->grinder + pos;
2261 struct rte_sched_pipe *pipe = grinder->pipe;
2262 struct rte_sched_pipe_profile *params = grinder->pipe_params;
2263 struct rte_sched_subport_profile *sp = grinder->subport_params;
2268 n_periods = (port->time - subport->tb_time) / sp->tb_period;
2269 subport->tb_credits += n_periods * sp->tb_credits_per_period;
2270 subport->tb_credits = RTE_MIN(subport->tb_credits, sp->tb_size);
2271 subport->tb_time += n_periods * sp->tb_period;
2274 n_periods = (port->time - pipe->tb_time) / params->tb_period;
2275 pipe->tb_credits += n_periods * params->tb_credits_per_period;
2276 pipe->tb_credits = RTE_MIN(pipe->tb_credits, params->tb_size);
2277 pipe->tb_time += n_periods * params->tb_period;
2280 if (unlikely(port->time >= subport->tc_time)) {
2282 grinder_tc_ov_credits_update(port, subport, pos);
2284 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
2285 subport->tc_credits[i] = sp->tc_credits_per_period[i];
2287 subport->tc_time = port->time + sp->tc_period;
2288 subport->tc_ov_period_id++;
2292 if (unlikely(port->time >= pipe->tc_time)) {
2293 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
2294 pipe->tc_credits[i] = params->tc_credits_per_period[i];
2295 pipe->tc_time = port->time + params->tc_period;
2298 /* Pipe TCs - Oversubscription */
2299 if (unlikely(pipe->tc_ov_period_id != subport->tc_ov_period_id)) {
2300 pipe->tc_ov_credits = subport->tc_ov_wm * params->tc_ov_weight;
2302 pipe->tc_ov_period_id = subport->tc_ov_period_id;
2306 #endif /* RTE_SCHED_TS_CREDITS_UPDATE, RTE_SCHED_SUBPORT_TC_OV */
2309 #ifndef RTE_SCHED_SUBPORT_TC_OV
2312 grinder_credits_check(struct rte_sched_port *port,
2313 struct rte_sched_subport *subport, uint32_t pos)
2315 struct rte_sched_grinder *grinder = subport->grinder + pos;
2316 struct rte_sched_pipe *pipe = grinder->pipe;
2317 struct rte_mbuf *pkt = grinder->pkt;
2318 uint32_t tc_index = grinder->tc_index;
2319 uint64_t pkt_len = pkt->pkt_len + port->frame_overhead;
2320 uint64_t subport_tb_credits = subport->tb_credits;
2321 uint64_t subport_tc_credits = subport->tc_credits[tc_index];
2322 uint64_t pipe_tb_credits = pipe->tb_credits;
2323 uint64_t pipe_tc_credits = pipe->tc_credits[tc_index];
2326 /* Check queue credits */
2327 enough_credits = (pkt_len <= subport_tb_credits) &&
2328 (pkt_len <= subport_tc_credits) &&
2329 (pkt_len <= pipe_tb_credits) &&
2330 (pkt_len <= pipe_tc_credits);
2332 if (!enough_credits)
2335 /* Update port credits */
2336 subport->tb_credits -= pkt_len;
2337 subport->tc_credits[tc_index] -= pkt_len;
2338 pipe->tb_credits -= pkt_len;
2339 pipe->tc_credits[tc_index] -= pkt_len;
2347 grinder_credits_check(struct rte_sched_port *port,
2348 struct rte_sched_subport *subport, uint32_t pos)
2350 struct rte_sched_grinder *grinder = subport->grinder + pos;
2351 struct rte_sched_pipe *pipe = grinder->pipe;
2352 struct rte_mbuf *pkt = grinder->pkt;
2353 uint32_t tc_index = grinder->tc_index;
2354 uint64_t pkt_len = pkt->pkt_len + port->frame_overhead;
2355 uint64_t subport_tb_credits = subport->tb_credits;
2356 uint64_t subport_tc_credits = subport->tc_credits[tc_index];
2357 uint64_t pipe_tb_credits = pipe->tb_credits;
2358 uint64_t pipe_tc_credits = pipe->tc_credits[tc_index];
2359 uint64_t pipe_tc_ov_mask1[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
2360 uint64_t pipe_tc_ov_mask2[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE] = {0};
2361 uint64_t pipe_tc_ov_credits;
2365 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
2366 pipe_tc_ov_mask1[i] = ~0LLU;
2368 pipe_tc_ov_mask1[RTE_SCHED_TRAFFIC_CLASS_BE] = pipe->tc_ov_credits;
2369 pipe_tc_ov_mask2[RTE_SCHED_TRAFFIC_CLASS_BE] = ~0LLU;
2370 pipe_tc_ov_credits = pipe_tc_ov_mask1[tc_index];
2372 /* Check pipe and subport credits */
2373 enough_credits = (pkt_len <= subport_tb_credits) &&
2374 (pkt_len <= subport_tc_credits) &&
2375 (pkt_len <= pipe_tb_credits) &&
2376 (pkt_len <= pipe_tc_credits) &&
2377 (pkt_len <= pipe_tc_ov_credits);
2379 if (!enough_credits)
2382 /* Update pipe and subport credits */
2383 subport->tb_credits -= pkt_len;
2384 subport->tc_credits[tc_index] -= pkt_len;
2385 pipe->tb_credits -= pkt_len;
2386 pipe->tc_credits[tc_index] -= pkt_len;
2387 pipe->tc_ov_credits -= pipe_tc_ov_mask2[tc_index] & pkt_len;
2392 #endif /* RTE_SCHED_SUBPORT_TC_OV */
2396 grinder_schedule(struct rte_sched_port *port,
2397 struct rte_sched_subport *subport, uint32_t pos)
2399 struct rte_sched_grinder *grinder = subport->grinder + pos;
2400 struct rte_sched_queue *queue = grinder->queue[grinder->qpos];
2401 struct rte_mbuf *pkt = grinder->pkt;
2402 uint32_t pkt_len = pkt->pkt_len + port->frame_overhead;
2403 uint32_t be_tc_active;
2405 if (!grinder_credits_check(port, subport, pos))
2408 /* Advance port time */
2409 port->time += pkt_len;
2412 port->pkts_out[port->n_pkts_out++] = pkt;
2415 be_tc_active = (grinder->tc_index == RTE_SCHED_TRAFFIC_CLASS_BE) ? ~0x0 : 0x0;
2416 grinder->wrr_tokens[grinder->qpos] +=
2417 (pkt_len * grinder->wrr_cost[grinder->qpos]) & be_tc_active;
2419 if (queue->qr == queue->qw) {
2420 uint32_t qindex = grinder->qindex[grinder->qpos];
2422 rte_bitmap_clear(subport->bmp, qindex);
2423 grinder->qmask &= ~(1 << grinder->qpos);
2425 grinder->wrr_mask[grinder->qpos] = 0;
2426 rte_sched_port_set_queue_empty_timestamp(port, subport, qindex);
2429 /* Reset pipe loop detection */
2430 subport->pipe_loop = RTE_SCHED_PIPE_INVALID;
2431 grinder->productive = 1;
2436 #ifdef SCHED_VECTOR_SSE4
2439 grinder_pipe_exists(struct rte_sched_subport *subport, uint32_t base_pipe)
2441 __m128i index = _mm_set1_epi32(base_pipe);
2442 __m128i pipes = _mm_load_si128((__m128i *)subport->grinder_base_bmp_pos);
2443 __m128i res = _mm_cmpeq_epi32(pipes, index);
2445 pipes = _mm_load_si128((__m128i *)(subport->grinder_base_bmp_pos + 4));
2446 pipes = _mm_cmpeq_epi32(pipes, index);
2447 res = _mm_or_si128(res, pipes);
2449 if (_mm_testz_si128(res, res))
2455 #elif defined(SCHED_VECTOR_NEON)
2458 grinder_pipe_exists(struct rte_sched_subport *subport, uint32_t base_pipe)
2460 uint32x4_t index, pipes;
2461 uint32_t *pos = (uint32_t *)subport->grinder_base_bmp_pos;
2463 index = vmovq_n_u32(base_pipe);
2464 pipes = vld1q_u32(pos);
2465 if (!vminvq_u32(veorq_u32(pipes, index)))
2468 pipes = vld1q_u32(pos + 4);
2469 if (!vminvq_u32(veorq_u32(pipes, index)))
2478 grinder_pipe_exists(struct rte_sched_subport *subport, uint32_t base_pipe)
2482 for (i = 0; i < RTE_SCHED_PORT_N_GRINDERS; i++) {
2483 if (subport->grinder_base_bmp_pos[i] == base_pipe)
2490 #endif /* RTE_SCHED_OPTIMIZATIONS */
2493 grinder_pcache_populate(struct rte_sched_subport *subport,
2494 uint32_t pos, uint32_t bmp_pos, uint64_t bmp_slab)
2496 struct rte_sched_grinder *grinder = subport->grinder + pos;
2499 grinder->pcache_w = 0;
2500 grinder->pcache_r = 0;
2502 w[0] = (uint16_t) bmp_slab;
2503 w[1] = (uint16_t) (bmp_slab >> 16);
2504 w[2] = (uint16_t) (bmp_slab >> 32);
2505 w[3] = (uint16_t) (bmp_slab >> 48);
2507 grinder->pcache_qmask[grinder->pcache_w] = w[0];
2508 grinder->pcache_qindex[grinder->pcache_w] = bmp_pos;
2509 grinder->pcache_w += (w[0] != 0);
2511 grinder->pcache_qmask[grinder->pcache_w] = w[1];
2512 grinder->pcache_qindex[grinder->pcache_w] = bmp_pos + 16;
2513 grinder->pcache_w += (w[1] != 0);
2515 grinder->pcache_qmask[grinder->pcache_w] = w[2];
2516 grinder->pcache_qindex[grinder->pcache_w] = bmp_pos + 32;
2517 grinder->pcache_w += (w[2] != 0);
2519 grinder->pcache_qmask[grinder->pcache_w] = w[3];
2520 grinder->pcache_qindex[grinder->pcache_w] = bmp_pos + 48;
2521 grinder->pcache_w += (w[3] != 0);
2525 grinder_tccache_populate(struct rte_sched_subport *subport,
2526 uint32_t pos, uint32_t qindex, uint16_t qmask)
2528 struct rte_sched_grinder *grinder = subport->grinder + pos;
2531 grinder->tccache_w = 0;
2532 grinder->tccache_r = 0;
2534 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASS_BE; i++) {
2535 b = (uint8_t) ((qmask >> i) & 0x1);
2536 grinder->tccache_qmask[grinder->tccache_w] = b;
2537 grinder->tccache_qindex[grinder->tccache_w] = qindex + i;
2538 grinder->tccache_w += (b != 0);
2541 b = (uint8_t) (qmask >> (RTE_SCHED_TRAFFIC_CLASS_BE));
2542 grinder->tccache_qmask[grinder->tccache_w] = b;
2543 grinder->tccache_qindex[grinder->tccache_w] = qindex +
2544 RTE_SCHED_TRAFFIC_CLASS_BE;
2545 grinder->tccache_w += (b != 0);
2549 grinder_next_tc(struct rte_sched_port *port,
2550 struct rte_sched_subport *subport, uint32_t pos)
2552 struct rte_sched_grinder *grinder = subport->grinder + pos;
2553 struct rte_mbuf **qbase;
2557 if (grinder->tccache_r == grinder->tccache_w)
2560 qindex = grinder->tccache_qindex[grinder->tccache_r];
2561 qbase = rte_sched_subport_pipe_qbase(subport, qindex);
2562 qsize = rte_sched_subport_pipe_qsize(port, subport, qindex);
2564 grinder->tc_index = rte_sched_port_pipe_tc(port, qindex);
2565 grinder->qmask = grinder->tccache_qmask[grinder->tccache_r];
2566 grinder->qsize = qsize;
2568 if (grinder->tc_index < RTE_SCHED_TRAFFIC_CLASS_BE) {
2569 grinder->queue[0] = subport->queue + qindex;
2570 grinder->qbase[0] = qbase;
2571 grinder->qindex[0] = qindex;
2572 grinder->tccache_r++;
2577 grinder->queue[0] = subport->queue + qindex;
2578 grinder->queue[1] = subport->queue + qindex + 1;
2579 grinder->queue[2] = subport->queue + qindex + 2;
2580 grinder->queue[3] = subport->queue + qindex + 3;
2582 grinder->qbase[0] = qbase;
2583 grinder->qbase[1] = qbase + qsize;
2584 grinder->qbase[2] = qbase + 2 * qsize;
2585 grinder->qbase[3] = qbase + 3 * qsize;
2587 grinder->qindex[0] = qindex;
2588 grinder->qindex[1] = qindex + 1;
2589 grinder->qindex[2] = qindex + 2;
2590 grinder->qindex[3] = qindex + 3;
2592 grinder->tccache_r++;
2597 grinder_next_pipe(struct rte_sched_port *port,
2598 struct rte_sched_subport *subport, uint32_t pos)
2600 struct rte_sched_grinder *grinder = subport->grinder + pos;
2601 uint32_t pipe_qindex;
2602 uint16_t pipe_qmask;
2604 if (grinder->pcache_r < grinder->pcache_w) {
2605 pipe_qmask = grinder->pcache_qmask[grinder->pcache_r];
2606 pipe_qindex = grinder->pcache_qindex[grinder->pcache_r];
2607 grinder->pcache_r++;
2609 uint64_t bmp_slab = 0;
2610 uint32_t bmp_pos = 0;
2612 /* Get another non-empty pipe group */
2613 if (unlikely(rte_bitmap_scan(subport->bmp, &bmp_pos, &bmp_slab) <= 0))
2616 #ifdef RTE_SCHED_DEBUG
2617 debug_check_queue_slab(subport, bmp_pos, bmp_slab);
2620 /* Return if pipe group already in one of the other grinders */
2621 subport->grinder_base_bmp_pos[pos] = RTE_SCHED_BMP_POS_INVALID;
2622 if (unlikely(grinder_pipe_exists(subport, bmp_pos)))
2625 subport->grinder_base_bmp_pos[pos] = bmp_pos;
2627 /* Install new pipe group into grinder's pipe cache */
2628 grinder_pcache_populate(subport, pos, bmp_pos, bmp_slab);
2630 pipe_qmask = grinder->pcache_qmask[0];
2631 pipe_qindex = grinder->pcache_qindex[0];
2632 grinder->pcache_r = 1;
2635 /* Install new pipe in the grinder */
2636 grinder->pindex = pipe_qindex >> 4;
2637 grinder->subport = subport;
2638 grinder->pipe = subport->pipe + grinder->pindex;
2639 grinder->pipe_params = NULL; /* to be set after the pipe structure is prefetched */
2640 grinder->productive = 0;
2642 grinder_tccache_populate(subport, pos, pipe_qindex, pipe_qmask);
2643 grinder_next_tc(port, subport, pos);
2645 /* Check for pipe exhaustion */
2646 if (grinder->pindex == subport->pipe_loop) {
2647 subport->pipe_exhaustion = 1;
2648 subport->pipe_loop = RTE_SCHED_PIPE_INVALID;
2656 grinder_wrr_load(struct rte_sched_subport *subport, uint32_t pos)
2658 struct rte_sched_grinder *grinder = subport->grinder + pos;
2659 struct rte_sched_pipe *pipe = grinder->pipe;
2660 struct rte_sched_pipe_profile *pipe_params = grinder->pipe_params;
2661 uint32_t qmask = grinder->qmask;
2663 grinder->wrr_tokens[0] =
2664 ((uint16_t) pipe->wrr_tokens[0]) << RTE_SCHED_WRR_SHIFT;
2665 grinder->wrr_tokens[1] =
2666 ((uint16_t) pipe->wrr_tokens[1]) << RTE_SCHED_WRR_SHIFT;
2667 grinder->wrr_tokens[2] =
2668 ((uint16_t) pipe->wrr_tokens[2]) << RTE_SCHED_WRR_SHIFT;
2669 grinder->wrr_tokens[3] =
2670 ((uint16_t) pipe->wrr_tokens[3]) << RTE_SCHED_WRR_SHIFT;
2672 grinder->wrr_mask[0] = (qmask & 0x1) * 0xFFFF;
2673 grinder->wrr_mask[1] = ((qmask >> 1) & 0x1) * 0xFFFF;
2674 grinder->wrr_mask[2] = ((qmask >> 2) & 0x1) * 0xFFFF;
2675 grinder->wrr_mask[3] = ((qmask >> 3) & 0x1) * 0xFFFF;
2677 grinder->wrr_cost[0] = pipe_params->wrr_cost[0];
2678 grinder->wrr_cost[1] = pipe_params->wrr_cost[1];
2679 grinder->wrr_cost[2] = pipe_params->wrr_cost[2];
2680 grinder->wrr_cost[3] = pipe_params->wrr_cost[3];
2684 grinder_wrr_store(struct rte_sched_subport *subport, uint32_t pos)
2686 struct rte_sched_grinder *grinder = subport->grinder + pos;
2687 struct rte_sched_pipe *pipe = grinder->pipe;
2689 pipe->wrr_tokens[0] =
2690 (grinder->wrr_tokens[0] & grinder->wrr_mask[0]) >>
2691 RTE_SCHED_WRR_SHIFT;
2692 pipe->wrr_tokens[1] =
2693 (grinder->wrr_tokens[1] & grinder->wrr_mask[1]) >>
2694 RTE_SCHED_WRR_SHIFT;
2695 pipe->wrr_tokens[2] =
2696 (grinder->wrr_tokens[2] & grinder->wrr_mask[2]) >>
2697 RTE_SCHED_WRR_SHIFT;
2698 pipe->wrr_tokens[3] =
2699 (grinder->wrr_tokens[3] & grinder->wrr_mask[3]) >>
2700 RTE_SCHED_WRR_SHIFT;
2704 grinder_wrr(struct rte_sched_subport *subport, uint32_t pos)
2706 struct rte_sched_grinder *grinder = subport->grinder + pos;
2707 uint16_t wrr_tokens_min;
2709 grinder->wrr_tokens[0] |= ~grinder->wrr_mask[0];
2710 grinder->wrr_tokens[1] |= ~grinder->wrr_mask[1];
2711 grinder->wrr_tokens[2] |= ~grinder->wrr_mask[2];
2712 grinder->wrr_tokens[3] |= ~grinder->wrr_mask[3];
2714 grinder->qpos = rte_min_pos_4_u16(grinder->wrr_tokens);
2715 wrr_tokens_min = grinder->wrr_tokens[grinder->qpos];
2717 grinder->wrr_tokens[0] -= wrr_tokens_min;
2718 grinder->wrr_tokens[1] -= wrr_tokens_min;
2719 grinder->wrr_tokens[2] -= wrr_tokens_min;
2720 grinder->wrr_tokens[3] -= wrr_tokens_min;
2724 #define grinder_evict(subport, pos)
2727 grinder_prefetch_pipe(struct rte_sched_subport *subport, uint32_t pos)
2729 struct rte_sched_grinder *grinder = subport->grinder + pos;
2731 rte_prefetch0(grinder->pipe);
2732 rte_prefetch0(grinder->queue[0]);
2736 grinder_prefetch_tc_queue_arrays(struct rte_sched_subport *subport, uint32_t pos)
2738 struct rte_sched_grinder *grinder = subport->grinder + pos;
2739 uint16_t qsize, qr[RTE_SCHED_MAX_QUEUES_PER_TC];
2741 qsize = grinder->qsize;
2744 if (grinder->tc_index < RTE_SCHED_TRAFFIC_CLASS_BE) {
2745 qr[0] = grinder->queue[0]->qr & (qsize - 1);
2747 rte_prefetch0(grinder->qbase[0] + qr[0]);
2751 qr[0] = grinder->queue[0]->qr & (qsize - 1);
2752 qr[1] = grinder->queue[1]->qr & (qsize - 1);
2753 qr[2] = grinder->queue[2]->qr & (qsize - 1);
2754 qr[3] = grinder->queue[3]->qr & (qsize - 1);
2756 rte_prefetch0(grinder->qbase[0] + qr[0]);
2757 rte_prefetch0(grinder->qbase[1] + qr[1]);
2759 grinder_wrr_load(subport, pos);
2760 grinder_wrr(subport, pos);
2762 rte_prefetch0(grinder->qbase[2] + qr[2]);
2763 rte_prefetch0(grinder->qbase[3] + qr[3]);
2767 grinder_prefetch_mbuf(struct rte_sched_subport *subport, uint32_t pos)
2769 struct rte_sched_grinder *grinder = subport->grinder + pos;
2770 uint32_t qpos = grinder->qpos;
2771 struct rte_mbuf **qbase = grinder->qbase[qpos];
2772 uint16_t qsize = grinder->qsize;
2773 uint16_t qr = grinder->queue[qpos]->qr & (qsize - 1);
2775 grinder->pkt = qbase[qr];
2776 rte_prefetch0(grinder->pkt);
2778 if (unlikely((qr & 0x7) == 7)) {
2779 uint16_t qr_next = (grinder->queue[qpos]->qr + 1) & (qsize - 1);
2781 rte_prefetch0(qbase + qr_next);
2785 static inline uint32_t
2786 grinder_handle(struct rte_sched_port *port,
2787 struct rte_sched_subport *subport, uint32_t pos)
2789 struct rte_sched_grinder *grinder = subport->grinder + pos;
2791 switch (grinder->state) {
2792 case e_GRINDER_PREFETCH_PIPE:
2794 if (grinder_next_pipe(port, subport, pos)) {
2795 grinder_prefetch_pipe(subport, pos);
2796 subport->busy_grinders++;
2798 grinder->state = e_GRINDER_PREFETCH_TC_QUEUE_ARRAYS;
2805 case e_GRINDER_PREFETCH_TC_QUEUE_ARRAYS:
2807 struct rte_sched_pipe *pipe = grinder->pipe;
2809 grinder->pipe_params = subport->pipe_profiles + pipe->profile;
2810 grinder->subport_params = port->subport_profiles +
2813 grinder_prefetch_tc_queue_arrays(subport, pos);
2814 grinder_credits_update(port, subport, pos);
2816 grinder->state = e_GRINDER_PREFETCH_MBUF;
2820 case e_GRINDER_PREFETCH_MBUF:
2822 grinder_prefetch_mbuf(subport, pos);
2824 grinder->state = e_GRINDER_READ_MBUF;
2828 case e_GRINDER_READ_MBUF:
2830 uint32_t wrr_active, result = 0;
2832 result = grinder_schedule(port, subport, pos);
2834 wrr_active = (grinder->tc_index == RTE_SCHED_TRAFFIC_CLASS_BE);
2836 /* Look for next packet within the same TC */
2837 if (result && grinder->qmask) {
2839 grinder_wrr(subport, pos);
2841 grinder_prefetch_mbuf(subport, pos);
2847 grinder_wrr_store(subport, pos);
2849 /* Look for another active TC within same pipe */
2850 if (grinder_next_tc(port, subport, pos)) {
2851 grinder_prefetch_tc_queue_arrays(subport, pos);
2853 grinder->state = e_GRINDER_PREFETCH_MBUF;
2857 if (grinder->productive == 0 &&
2858 subport->pipe_loop == RTE_SCHED_PIPE_INVALID)
2859 subport->pipe_loop = grinder->pindex;
2861 grinder_evict(subport, pos);
2863 /* Look for another active pipe */
2864 if (grinder_next_pipe(port, subport, pos)) {
2865 grinder_prefetch_pipe(subport, pos);
2867 grinder->state = e_GRINDER_PREFETCH_TC_QUEUE_ARRAYS;
2871 /* No active pipe found */
2872 subport->busy_grinders--;
2874 grinder->state = e_GRINDER_PREFETCH_PIPE;
2879 rte_panic("Algorithmic error (invalid state)\n");
2885 rte_sched_port_time_resync(struct rte_sched_port *port)
2887 uint64_t cycles = rte_get_tsc_cycles();
2888 uint64_t cycles_diff;
2889 uint64_t bytes_diff;
2892 if (cycles < port->time_cpu_cycles)
2893 port->time_cpu_cycles = 0;
2895 cycles_diff = cycles - port->time_cpu_cycles;
2896 /* Compute elapsed time in bytes */
2897 bytes_diff = rte_reciprocal_divide(cycles_diff << RTE_SCHED_TIME_SHIFT,
2898 port->inv_cycles_per_byte);
2900 /* Advance port time */
2901 port->time_cpu_cycles +=
2902 (bytes_diff * port->cycles_per_byte) >> RTE_SCHED_TIME_SHIFT;
2903 port->time_cpu_bytes += bytes_diff;
2904 if (port->time < port->time_cpu_bytes)
2905 port->time = port->time_cpu_bytes;
2907 /* Reset pipe loop detection */
2908 for (i = 0; i < port->n_subports_per_port; i++)
2909 port->subports[i]->pipe_loop = RTE_SCHED_PIPE_INVALID;
2913 rte_sched_port_exceptions(struct rte_sched_subport *subport, int second_pass)
2917 /* Check if any exception flag is set */
2918 exceptions = (second_pass && subport->busy_grinders == 0) ||
2919 (subport->pipe_exhaustion == 1);
2921 /* Clear exception flags */
2922 subport->pipe_exhaustion = 0;
2928 rte_sched_port_dequeue(struct rte_sched_port *port, struct rte_mbuf **pkts, uint32_t n_pkts)
2930 struct rte_sched_subport *subport;
2931 uint32_t subport_id = port->subport_id;
2932 uint32_t i, n_subports = 0, count;
2934 port->pkts_out = pkts;
2935 port->n_pkts_out = 0;
2937 rte_sched_port_time_resync(port);
2939 /* Take each queue in the grinder one step further */
2940 for (i = 0, count = 0; ; i++) {
2941 subport = port->subports[subport_id];
2943 count += grinder_handle(port, subport,
2944 i & (RTE_SCHED_PORT_N_GRINDERS - 1));
2946 if (count == n_pkts) {
2949 if (subport_id == port->n_subports_per_port)
2952 port->subport_id = subport_id;
2956 if (rte_sched_port_exceptions(subport, i >= RTE_SCHED_PORT_N_GRINDERS)) {
2962 if (subport_id == port->n_subports_per_port)
2965 if (n_subports == port->n_subports_per_port) {
2966 port->subport_id = subport_id;