1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
8 #include <rte_common.h>
10 #include <rte_malloc.h>
11 #include <rte_cycles.h>
12 #include <rte_prefetch.h>
13 #include <rte_branch_prediction.h>
15 #include <rte_bitmap.h>
16 #include <rte_reciprocal.h>
18 #include "rte_sched.h"
19 #include "rte_sched_common.h"
20 #include "rte_approx.h"
22 #ifdef __INTEL_COMPILER
23 #pragma warning(disable:2259) /* conversion may lose significant bits */
26 #ifndef RTE_SCHED_PORT_N_GRINDERS
27 #define RTE_SCHED_PORT_N_GRINDERS 8
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
37 /* Scaling for cycles_per_byte calculation
38 * Chosen so that minimum rate is 480 bit/sec
40 #define RTE_SCHED_TIME_SHIFT 8
42 struct rte_sched_pipe_profile {
43 /* Token bucket (TB) */
45 uint64_t tb_credits_per_period;
48 /* Pipe traffic classes */
50 uint64_t tc_credits_per_period[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
53 /* Pipe best-effort traffic class queues */
54 uint8_t wrr_cost[RTE_SCHED_BE_QUEUES_PER_PIPE];
57 struct rte_sched_pipe {
58 /* Token bucket (TB) */
59 uint64_t tb_time; /* time of last update */
62 /* Pipe profile and flags */
65 /* Traffic classes (TCs) */
66 uint64_t tc_time; /* time of next update */
67 uint64_t tc_credits[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
69 /* Weighted Round Robin (WRR) */
70 uint8_t wrr_tokens[RTE_SCHED_BE_QUEUES_PER_PIPE];
72 /* TC oversubscription */
73 uint64_t tc_ov_credits;
74 uint8_t tc_ov_period_id;
75 } __rte_cache_aligned;
77 struct rte_sched_queue {
82 struct rte_sched_queue_extra {
83 struct rte_sched_queue_stats stats;
94 e_GRINDER_PREFETCH_PIPE = 0,
95 e_GRINDER_PREFETCH_TC_QUEUE_ARRAYS,
96 e_GRINDER_PREFETCH_MBUF,
100 struct rte_sched_subport_profile {
101 /* Token bucket (TB) */
103 uint64_t tb_credits_per_period;
106 uint64_t tc_credits_per_period[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
110 struct rte_sched_grinder {
112 uint16_t pcache_qmask[RTE_SCHED_GRINDER_PCACHE_SIZE];
113 uint32_t pcache_qindex[RTE_SCHED_GRINDER_PCACHE_SIZE];
118 enum grinder_state state;
121 struct rte_sched_subport *subport;
122 struct rte_sched_subport_profile *subport_params;
123 struct rte_sched_pipe *pipe;
124 struct rte_sched_pipe_profile *pipe_params;
127 uint8_t tccache_qmask[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
128 uint32_t tccache_qindex[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
134 struct rte_sched_queue *queue[RTE_SCHED_MAX_QUEUES_PER_TC];
135 struct rte_mbuf **qbase[RTE_SCHED_MAX_QUEUES_PER_TC];
136 uint32_t qindex[RTE_SCHED_MAX_QUEUES_PER_TC];
140 struct rte_mbuf *pkt;
143 uint16_t wrr_tokens[RTE_SCHED_BE_QUEUES_PER_PIPE];
144 uint16_t wrr_mask[RTE_SCHED_BE_QUEUES_PER_PIPE];
145 uint8_t wrr_cost[RTE_SCHED_BE_QUEUES_PER_PIPE];
148 struct rte_sched_subport {
149 /* Token bucket (TB) */
150 uint64_t tb_time; /* time of last update */
153 /* Traffic classes (TCs) */
154 uint64_t tc_time; /* time of next update */
155 uint64_t tc_credits[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
157 /* TC oversubscription */
159 uint64_t tc_ov_wm_min;
160 uint64_t tc_ov_wm_max;
161 uint8_t tc_ov_period_id;
167 struct rte_sched_subport_stats stats __rte_cache_aligned;
169 /* subport profile */
172 uint32_t n_pipes_per_subport_enabled;
173 uint32_t n_pipe_profiles;
174 uint32_t n_max_pipe_profiles;
176 /* Pipe best-effort TC rate */
177 uint64_t pipe_tc_be_rate_max;
179 /* Pipe queues size */
180 uint16_t qsize[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
182 #ifdef RTE_SCHED_CMAN
184 enum rte_sched_cman_mode cman;
188 struct rte_red_config red_config[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE][RTE_COLORS];
189 struct rte_pie_config pie_config[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
193 /* Scheduling loop detection */
195 uint32_t pipe_exhaustion;
198 struct rte_bitmap *bmp;
199 uint32_t grinder_base_bmp_pos[RTE_SCHED_PORT_N_GRINDERS] __rte_aligned_16;
202 struct rte_sched_grinder grinder[RTE_SCHED_PORT_N_GRINDERS];
203 uint32_t busy_grinders;
205 /* Queue base calculation */
206 uint32_t qsize_add[RTE_SCHED_QUEUES_PER_PIPE];
209 struct rte_sched_pipe *pipe;
210 struct rte_sched_queue *queue;
211 struct rte_sched_queue_extra *queue_extra;
212 struct rte_sched_pipe_profile *pipe_profiles;
214 struct rte_mbuf **queue_array;
215 uint8_t memory[0] __rte_cache_aligned;
216 } __rte_cache_aligned;
218 struct rte_sched_port {
219 /* User parameters */
220 uint32_t n_subports_per_port;
221 uint32_t n_pipes_per_subport;
222 uint32_t n_pipes_per_subport_log2;
223 uint16_t pipe_queue[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
224 uint8_t pipe_tc[RTE_SCHED_QUEUES_PER_PIPE];
225 uint8_t tc_queue[RTE_SCHED_QUEUES_PER_PIPE];
226 uint32_t n_subport_profiles;
227 uint32_t n_max_subport_profiles;
230 uint32_t frame_overhead;
234 uint64_t time_cpu_cycles; /* Current CPU time measured in CPU cycles */
235 uint64_t time_cpu_bytes; /* Current CPU time measured in bytes */
236 uint64_t time; /* Current NIC TX time measured in bytes */
237 struct rte_reciprocal inv_cycles_per_byte; /* CPU cycles per byte */
238 uint64_t cycles_per_byte;
241 struct rte_mbuf **pkts_out;
245 /* Large data structures */
246 struct rte_sched_subport_profile *subport_profiles;
247 struct rte_sched_subport *subports[0] __rte_cache_aligned;
248 } __rte_cache_aligned;
250 enum rte_sched_subport_array {
251 e_RTE_SCHED_SUBPORT_ARRAY_PIPE = 0,
252 e_RTE_SCHED_SUBPORT_ARRAY_QUEUE,
253 e_RTE_SCHED_SUBPORT_ARRAY_QUEUE_EXTRA,
254 e_RTE_SCHED_SUBPORT_ARRAY_PIPE_PROFILES,
255 e_RTE_SCHED_SUBPORT_ARRAY_BMP_ARRAY,
256 e_RTE_SCHED_SUBPORT_ARRAY_QUEUE_ARRAY,
257 e_RTE_SCHED_SUBPORT_ARRAY_TOTAL,
260 static inline uint32_t
261 rte_sched_subport_pipe_queues(struct rte_sched_subport *subport)
263 return RTE_SCHED_QUEUES_PER_PIPE * subport->n_pipes_per_subport_enabled;
266 static inline struct rte_mbuf **
267 rte_sched_subport_pipe_qbase(struct rte_sched_subport *subport, uint32_t qindex)
269 uint32_t pindex = qindex >> 4;
270 uint32_t qpos = qindex & (RTE_SCHED_QUEUES_PER_PIPE - 1);
272 return (subport->queue_array + pindex *
273 subport->qsize_sum + subport->qsize_add[qpos]);
276 static inline uint16_t
277 rte_sched_subport_pipe_qsize(struct rte_sched_port *port,
278 struct rte_sched_subport *subport, uint32_t qindex)
280 uint32_t tc = port->pipe_tc[qindex & (RTE_SCHED_QUEUES_PER_PIPE - 1)];
282 return subport->qsize[tc];
285 static inline uint32_t
286 rte_sched_port_queues_per_port(struct rte_sched_port *port)
288 uint32_t n_queues = 0, i;
290 for (i = 0; i < port->n_subports_per_port; i++)
291 n_queues += rte_sched_subport_pipe_queues(port->subports[i]);
296 static inline uint16_t
297 rte_sched_port_pipe_queue(struct rte_sched_port *port, uint32_t traffic_class)
299 uint16_t pipe_queue = port->pipe_queue[traffic_class];
304 static inline uint8_t
305 rte_sched_port_pipe_tc(struct rte_sched_port *port, uint32_t qindex)
307 uint8_t pipe_tc = port->pipe_tc[qindex & (RTE_SCHED_QUEUES_PER_PIPE - 1)];
312 static inline uint8_t
313 rte_sched_port_tc_queue(struct rte_sched_port *port, uint32_t qindex)
315 uint8_t tc_queue = port->tc_queue[qindex & (RTE_SCHED_QUEUES_PER_PIPE - 1)];
321 pipe_profile_check(struct rte_sched_pipe_params *params,
322 uint64_t rate, uint16_t *qsize)
326 /* Pipe parameters */
327 if (params == NULL) {
329 "%s: Incorrect value for parameter params\n", __func__);
333 /* TB rate: non-zero, not greater than port rate */
334 if (params->tb_rate == 0 ||
335 params->tb_rate > rate) {
337 "%s: Incorrect value for tb rate\n", __func__);
341 /* TB size: non-zero */
342 if (params->tb_size == 0) {
344 "%s: Incorrect value for tb size\n", __func__);
348 /* TC rate: non-zero if qsize non-zero, less than pipe rate */
349 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++) {
350 if ((qsize[i] == 0 && params->tc_rate[i] != 0) ||
351 (qsize[i] != 0 && (params->tc_rate[i] == 0 ||
352 params->tc_rate[i] > params->tb_rate))) {
354 "%s: Incorrect value for qsize or tc_rate\n", __func__);
359 if (params->tc_rate[RTE_SCHED_TRAFFIC_CLASS_BE] == 0 ||
360 qsize[RTE_SCHED_TRAFFIC_CLASS_BE] == 0) {
362 "%s: Incorrect value for be traffic class rate\n", __func__);
366 /* TC period: non-zero */
367 if (params->tc_period == 0) {
369 "%s: Incorrect value for tc period\n", __func__);
373 /* Best effort tc oversubscription weight: non-zero */
374 if (params->tc_ov_weight == 0) {
376 "%s: Incorrect value for tc ov weight\n", __func__);
380 /* Queue WRR weights: non-zero */
381 for (i = 0; i < RTE_SCHED_BE_QUEUES_PER_PIPE; i++) {
382 if (params->wrr_weights[i] == 0) {
384 "%s: Incorrect value for wrr weight\n", __func__);
393 subport_profile_check(struct rte_sched_subport_profile_params *params,
398 /* Check user parameters */
399 if (params == NULL) {
400 RTE_LOG(ERR, SCHED, "%s: "
401 "Incorrect value for parameter params\n", __func__);
405 if (params->tb_rate == 0 || params->tb_rate > rate) {
406 RTE_LOG(ERR, SCHED, "%s: "
407 "Incorrect value for tb rate\n", __func__);
411 if (params->tb_size == 0) {
412 RTE_LOG(ERR, SCHED, "%s: "
413 "Incorrect value for tb size\n", __func__);
417 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++) {
418 uint64_t tc_rate = params->tc_rate[i];
420 if (tc_rate == 0 || (tc_rate > params->tb_rate)) {
421 RTE_LOG(ERR, SCHED, "%s: "
422 "Incorrect value for tc rate\n", __func__);
427 if (params->tc_rate[RTE_SCHED_TRAFFIC_CLASS_BE] == 0) {
428 RTE_LOG(ERR, SCHED, "%s: "
429 "Incorrect tc rate(best effort)\n", __func__);
433 if (params->tc_period == 0) {
434 RTE_LOG(ERR, SCHED, "%s: "
435 "Incorrect value for tc period\n", __func__);
443 rte_sched_port_check_params(struct rte_sched_port_params *params)
447 if (params == NULL) {
449 "%s: Incorrect value for parameter params\n", __func__);
454 if (params->socket < 0) {
456 "%s: Incorrect value for socket id\n", __func__);
461 if (params->rate == 0) {
463 "%s: Incorrect value for rate\n", __func__);
468 if (params->mtu == 0) {
470 "%s: Incorrect value for mtu\n", __func__);
474 /* n_subports_per_port: non-zero, limited to 16 bits, power of 2 */
475 if (params->n_subports_per_port == 0 ||
476 params->n_subports_per_port > 1u << 16 ||
477 !rte_is_power_of_2(params->n_subports_per_port)) {
479 "%s: Incorrect value for number of subports\n", __func__);
483 if (params->subport_profiles == NULL ||
484 params->n_subport_profiles == 0 ||
485 params->n_max_subport_profiles == 0 ||
486 params->n_subport_profiles > params->n_max_subport_profiles) {
488 "%s: Incorrect value for subport profiles\n", __func__);
492 for (i = 0; i < params->n_subport_profiles; i++) {
493 struct rte_sched_subport_profile_params *p =
494 params->subport_profiles + i;
497 status = subport_profile_check(p, params->rate);
500 "%s: subport profile check failed(%d)\n",
506 /* n_pipes_per_subport: non-zero, power of 2 */
507 if (params->n_pipes_per_subport == 0 ||
508 !rte_is_power_of_2(params->n_pipes_per_subport)) {
510 "%s: Incorrect value for maximum pipes number\n", __func__);
518 rte_sched_subport_get_array_base(struct rte_sched_subport_params *params,
519 enum rte_sched_subport_array array)
521 uint32_t n_pipes_per_subport = params->n_pipes_per_subport_enabled;
522 uint32_t n_subport_pipe_queues =
523 RTE_SCHED_QUEUES_PER_PIPE * n_pipes_per_subport;
525 uint32_t size_pipe = n_pipes_per_subport * sizeof(struct rte_sched_pipe);
526 uint32_t size_queue =
527 n_subport_pipe_queues * sizeof(struct rte_sched_queue);
528 uint32_t size_queue_extra
529 = n_subport_pipe_queues * sizeof(struct rte_sched_queue_extra);
530 uint32_t size_pipe_profiles = params->n_max_pipe_profiles *
531 sizeof(struct rte_sched_pipe_profile);
532 uint32_t size_bmp_array =
533 rte_bitmap_get_memory_footprint(n_subport_pipe_queues);
534 uint32_t size_per_pipe_queue_array, size_queue_array;
538 size_per_pipe_queue_array = 0;
539 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++) {
540 if (i < RTE_SCHED_TRAFFIC_CLASS_BE)
541 size_per_pipe_queue_array +=
542 params->qsize[i] * sizeof(struct rte_mbuf *);
544 size_per_pipe_queue_array += RTE_SCHED_MAX_QUEUES_PER_TC *
545 params->qsize[i] * sizeof(struct rte_mbuf *);
547 size_queue_array = n_pipes_per_subport * size_per_pipe_queue_array;
551 if (array == e_RTE_SCHED_SUBPORT_ARRAY_PIPE)
553 base += RTE_CACHE_LINE_ROUNDUP(size_pipe);
555 if (array == e_RTE_SCHED_SUBPORT_ARRAY_QUEUE)
557 base += RTE_CACHE_LINE_ROUNDUP(size_queue);
559 if (array == e_RTE_SCHED_SUBPORT_ARRAY_QUEUE_EXTRA)
561 base += RTE_CACHE_LINE_ROUNDUP(size_queue_extra);
563 if (array == e_RTE_SCHED_SUBPORT_ARRAY_PIPE_PROFILES)
565 base += RTE_CACHE_LINE_ROUNDUP(size_pipe_profiles);
567 if (array == e_RTE_SCHED_SUBPORT_ARRAY_BMP_ARRAY)
569 base += RTE_CACHE_LINE_ROUNDUP(size_bmp_array);
571 if (array == e_RTE_SCHED_SUBPORT_ARRAY_QUEUE_ARRAY)
573 base += RTE_CACHE_LINE_ROUNDUP(size_queue_array);
579 rte_sched_subport_config_qsize(struct rte_sched_subport *subport)
583 subport->qsize_add[0] = 0;
585 /* Strict priority traffic class */
586 for (i = 1; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
587 subport->qsize_add[i] = subport->qsize_add[i-1] + subport->qsize[i-1];
589 /* Best-effort traffic class */
590 subport->qsize_add[RTE_SCHED_TRAFFIC_CLASS_BE + 1] =
591 subport->qsize_add[RTE_SCHED_TRAFFIC_CLASS_BE] +
592 subport->qsize[RTE_SCHED_TRAFFIC_CLASS_BE];
593 subport->qsize_add[RTE_SCHED_TRAFFIC_CLASS_BE + 2] =
594 subport->qsize_add[RTE_SCHED_TRAFFIC_CLASS_BE + 1] +
595 subport->qsize[RTE_SCHED_TRAFFIC_CLASS_BE];
596 subport->qsize_add[RTE_SCHED_TRAFFIC_CLASS_BE + 3] =
597 subport->qsize_add[RTE_SCHED_TRAFFIC_CLASS_BE + 2] +
598 subport->qsize[RTE_SCHED_TRAFFIC_CLASS_BE];
600 subport->qsize_sum = subport->qsize_add[RTE_SCHED_TRAFFIC_CLASS_BE + 3] +
601 subport->qsize[RTE_SCHED_TRAFFIC_CLASS_BE];
605 rte_sched_port_log_pipe_profile(struct rte_sched_subport *subport, uint32_t i)
607 struct rte_sched_pipe_profile *p = subport->pipe_profiles + i;
609 RTE_LOG(DEBUG, SCHED, "Low level config for pipe profile %u:\n"
610 " Token bucket: period = %"PRIu64", credits per period = %"PRIu64", size = %"PRIu64"\n"
611 " Traffic classes: period = %"PRIu64",\n"
612 " credits per period = [%"PRIu64", %"PRIu64", %"PRIu64", %"PRIu64
613 ", %"PRIu64", %"PRIu64", %"PRIu64", %"PRIu64", %"PRIu64", %"PRIu64
614 ", %"PRIu64", %"PRIu64", %"PRIu64"]\n"
615 " Best-effort traffic class oversubscription: weight = %hhu\n"
616 " WRR cost: [%hhu, %hhu, %hhu, %hhu]\n",
621 p->tb_credits_per_period,
624 /* Traffic classes */
626 p->tc_credits_per_period[0],
627 p->tc_credits_per_period[1],
628 p->tc_credits_per_period[2],
629 p->tc_credits_per_period[3],
630 p->tc_credits_per_period[4],
631 p->tc_credits_per_period[5],
632 p->tc_credits_per_period[6],
633 p->tc_credits_per_period[7],
634 p->tc_credits_per_period[8],
635 p->tc_credits_per_period[9],
636 p->tc_credits_per_period[10],
637 p->tc_credits_per_period[11],
638 p->tc_credits_per_period[12],
640 /* Best-effort traffic class oversubscription */
644 p->wrr_cost[0], p->wrr_cost[1], p->wrr_cost[2], p->wrr_cost[3]);
648 rte_sched_port_log_subport_profile(struct rte_sched_port *port, uint32_t i)
650 struct rte_sched_subport_profile *p = port->subport_profiles + i;
652 RTE_LOG(DEBUG, SCHED, "Low level config for subport profile %u:\n"
653 "Token bucket: period = %"PRIu64", credits per period = %"PRIu64","
655 "Traffic classes: period = %"PRIu64",\n"
656 "credits per period = [%"PRIu64", %"PRIu64", %"PRIu64", %"PRIu64
657 " %"PRIu64", %"PRIu64", %"PRIu64", %"PRIu64", %"PRIu64", %"PRIu64
658 " %"PRIu64", %"PRIu64", %"PRIu64"]\n",
663 p->tb_credits_per_period,
666 /* Traffic classes */
668 p->tc_credits_per_period[0],
669 p->tc_credits_per_period[1],
670 p->tc_credits_per_period[2],
671 p->tc_credits_per_period[3],
672 p->tc_credits_per_period[4],
673 p->tc_credits_per_period[5],
674 p->tc_credits_per_period[6],
675 p->tc_credits_per_period[7],
676 p->tc_credits_per_period[8],
677 p->tc_credits_per_period[9],
678 p->tc_credits_per_period[10],
679 p->tc_credits_per_period[11],
680 p->tc_credits_per_period[12]);
683 static inline uint64_t
684 rte_sched_time_ms_to_bytes(uint64_t time_ms, uint64_t rate)
686 uint64_t time = time_ms;
688 time = (time * rate) / 1000;
694 rte_sched_pipe_profile_convert(struct rte_sched_subport *subport,
695 struct rte_sched_pipe_params *src,
696 struct rte_sched_pipe_profile *dst,
699 uint32_t wrr_cost[RTE_SCHED_BE_QUEUES_PER_PIPE];
700 uint32_t lcd1, lcd2, lcd;
704 if (src->tb_rate == rate) {
705 dst->tb_credits_per_period = 1;
708 double tb_rate = (double) src->tb_rate
710 double d = RTE_SCHED_TB_RATE_CONFIG_ERR;
712 rte_approx_64(tb_rate, d, &dst->tb_credits_per_period,
716 dst->tb_size = src->tb_size;
718 /* Traffic Classes */
719 dst->tc_period = rte_sched_time_ms_to_bytes(src->tc_period,
722 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
723 if (subport->qsize[i])
724 dst->tc_credits_per_period[i]
725 = rte_sched_time_ms_to_bytes(src->tc_period,
728 dst->tc_ov_weight = src->tc_ov_weight;
731 wrr_cost[0] = src->wrr_weights[0];
732 wrr_cost[1] = src->wrr_weights[1];
733 wrr_cost[2] = src->wrr_weights[2];
734 wrr_cost[3] = src->wrr_weights[3];
736 lcd1 = rte_get_lcd(wrr_cost[0], wrr_cost[1]);
737 lcd2 = rte_get_lcd(wrr_cost[2], wrr_cost[3]);
738 lcd = rte_get_lcd(lcd1, lcd2);
740 wrr_cost[0] = lcd / wrr_cost[0];
741 wrr_cost[1] = lcd / wrr_cost[1];
742 wrr_cost[2] = lcd / wrr_cost[2];
743 wrr_cost[3] = lcd / wrr_cost[3];
745 dst->wrr_cost[0] = (uint8_t) wrr_cost[0];
746 dst->wrr_cost[1] = (uint8_t) wrr_cost[1];
747 dst->wrr_cost[2] = (uint8_t) wrr_cost[2];
748 dst->wrr_cost[3] = (uint8_t) wrr_cost[3];
752 rte_sched_subport_profile_convert(struct rte_sched_subport_profile_params *src,
753 struct rte_sched_subport_profile *dst,
759 if (src->tb_rate == rate) {
760 dst->tb_credits_per_period = 1;
763 double tb_rate = (double) src->tb_rate
765 double d = RTE_SCHED_TB_RATE_CONFIG_ERR;
767 rte_approx_64(tb_rate, d, &dst->tb_credits_per_period,
771 dst->tb_size = src->tb_size;
773 /* Traffic Classes */
774 dst->tc_period = rte_sched_time_ms_to_bytes(src->tc_period, rate);
776 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
777 dst->tc_credits_per_period[i]
778 = rte_sched_time_ms_to_bytes(src->tc_period,
783 rte_sched_subport_config_pipe_profile_table(struct rte_sched_subport *subport,
784 struct rte_sched_subport_params *params, uint64_t rate)
788 for (i = 0; i < subport->n_pipe_profiles; i++) {
789 struct rte_sched_pipe_params *src = params->pipe_profiles + i;
790 struct rte_sched_pipe_profile *dst = subport->pipe_profiles + i;
792 rte_sched_pipe_profile_convert(subport, src, dst, rate);
793 rte_sched_port_log_pipe_profile(subport, i);
796 subport->pipe_tc_be_rate_max = 0;
797 for (i = 0; i < subport->n_pipe_profiles; i++) {
798 struct rte_sched_pipe_params *src = params->pipe_profiles + i;
799 uint64_t pipe_tc_be_rate = src->tc_rate[RTE_SCHED_TRAFFIC_CLASS_BE];
801 if (subport->pipe_tc_be_rate_max < pipe_tc_be_rate)
802 subport->pipe_tc_be_rate_max = pipe_tc_be_rate;
807 rte_sched_port_config_subport_profile_table(struct rte_sched_port *port,
808 struct rte_sched_port_params *params,
813 for (i = 0; i < port->n_subport_profiles; i++) {
814 struct rte_sched_subport_profile_params *src
815 = params->subport_profiles + i;
816 struct rte_sched_subport_profile *dst
817 = port->subport_profiles + i;
819 rte_sched_subport_profile_convert(src, dst, rate);
820 rte_sched_port_log_subport_profile(port, i);
825 rte_sched_subport_check_params(struct rte_sched_subport_params *params,
826 uint32_t n_max_pipes_per_subport,
831 /* Check user parameters */
832 if (params == NULL) {
834 "%s: Incorrect value for parameter params\n", __func__);
838 /* qsize: if non-zero, power of 2,
839 * no bigger than 32K (due to 16-bit read/write pointers)
841 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++) {
842 uint16_t qsize = params->qsize[i];
844 if (qsize != 0 && !rte_is_power_of_2(qsize)) {
846 "%s: Incorrect value for qsize\n", __func__);
851 if (params->qsize[RTE_SCHED_TRAFFIC_CLASS_BE] == 0) {
852 RTE_LOG(ERR, SCHED, "%s: Incorrect qsize\n", __func__);
856 /* n_pipes_per_subport: non-zero, power of 2 */
857 if (params->n_pipes_per_subport_enabled == 0 ||
858 params->n_pipes_per_subport_enabled > n_max_pipes_per_subport ||
859 !rte_is_power_of_2(params->n_pipes_per_subport_enabled)) {
861 "%s: Incorrect value for pipes number\n", __func__);
865 /* pipe_profiles and n_pipe_profiles */
866 if (params->pipe_profiles == NULL ||
867 params->n_pipe_profiles == 0 ||
868 params->n_max_pipe_profiles == 0 ||
869 params->n_pipe_profiles > params->n_max_pipe_profiles) {
871 "%s: Incorrect value for pipe profiles\n", __func__);
875 for (i = 0; i < params->n_pipe_profiles; i++) {
876 struct rte_sched_pipe_params *p = params->pipe_profiles + i;
879 status = pipe_profile_check(p, rate, ¶ms->qsize[0]);
882 "%s: Pipe profile check failed(%d)\n", __func__, status);
891 rte_sched_port_get_memory_footprint(struct rte_sched_port_params *port_params,
892 struct rte_sched_subport_params **subport_params)
894 uint32_t size0 = 0, size1 = 0, i;
897 status = rte_sched_port_check_params(port_params);
900 "%s: Port scheduler port params check failed (%d)\n",
906 for (i = 0; i < port_params->n_subports_per_port; i++) {
907 struct rte_sched_subport_params *sp = subport_params[i];
909 status = rte_sched_subport_check_params(sp,
910 port_params->n_pipes_per_subport,
914 "%s: Port scheduler subport params check failed (%d)\n",
921 size0 = sizeof(struct rte_sched_port);
923 for (i = 0; i < port_params->n_subports_per_port; i++) {
924 struct rte_sched_subport_params *sp = subport_params[i];
926 size1 += rte_sched_subport_get_array_base(sp,
927 e_RTE_SCHED_SUBPORT_ARRAY_TOTAL);
930 return size0 + size1;
933 struct rte_sched_port *
934 rte_sched_port_config(struct rte_sched_port_params *params)
936 struct rte_sched_port *port = NULL;
937 uint32_t size0, size1, size2;
938 uint32_t cycles_per_byte;
942 status = rte_sched_port_check_params(params);
945 "%s: Port scheduler params check failed (%d)\n",
950 size0 = sizeof(struct rte_sched_port);
951 size1 = params->n_subports_per_port * sizeof(struct rte_sched_subport *);
952 size2 = params->n_max_subport_profiles *
953 sizeof(struct rte_sched_subport_profile);
955 /* Allocate memory to store the data structures */
956 port = rte_zmalloc_socket("qos_params", size0 + size1,
957 RTE_CACHE_LINE_SIZE, params->socket);
959 RTE_LOG(ERR, SCHED, "%s: Memory allocation fails\n", __func__);
964 /* Allocate memory to store the subport profile */
965 port->subport_profiles = rte_zmalloc_socket("subport_profile", size2,
966 RTE_CACHE_LINE_SIZE, params->socket);
967 if (port->subport_profiles == NULL) {
968 RTE_LOG(ERR, SCHED, "%s: Memory allocation fails\n", __func__);
973 /* User parameters */
974 port->n_subports_per_port = params->n_subports_per_port;
975 port->n_subport_profiles = params->n_subport_profiles;
976 port->n_max_subport_profiles = params->n_max_subport_profiles;
977 port->n_pipes_per_subport = params->n_pipes_per_subport;
978 port->n_pipes_per_subport_log2 =
979 __builtin_ctz(params->n_pipes_per_subport);
980 port->socket = params->socket;
982 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
983 port->pipe_queue[i] = i;
985 for (i = 0, j = 0; i < RTE_SCHED_QUEUES_PER_PIPE; i++) {
986 port->pipe_tc[i] = j;
988 if (j < RTE_SCHED_TRAFFIC_CLASS_BE)
992 for (i = 0, j = 0; i < RTE_SCHED_QUEUES_PER_PIPE; i++) {
993 port->tc_queue[i] = j;
995 if (i >= RTE_SCHED_TRAFFIC_CLASS_BE)
998 port->rate = params->rate;
999 port->mtu = params->mtu + params->frame_overhead;
1000 port->frame_overhead = params->frame_overhead;
1003 port->time_cpu_cycles = rte_get_tsc_cycles();
1004 port->time_cpu_bytes = 0;
1007 /* Subport profile table */
1008 rte_sched_port_config_subport_profile_table(port, params, port->rate);
1010 cycles_per_byte = (rte_get_tsc_hz() << RTE_SCHED_TIME_SHIFT)
1012 port->inv_cycles_per_byte = rte_reciprocal_value(cycles_per_byte);
1013 port->cycles_per_byte = cycles_per_byte;
1016 port->pkts_out = NULL;
1017 port->n_pkts_out = 0;
1018 port->subport_id = 0;
1024 rte_sched_subport_free(struct rte_sched_port *port,
1025 struct rte_sched_subport *subport)
1027 uint32_t n_subport_pipe_queues;
1030 if (subport == NULL)
1033 n_subport_pipe_queues = rte_sched_subport_pipe_queues(subport);
1035 /* Free enqueued mbufs */
1036 for (qindex = 0; qindex < n_subport_pipe_queues; qindex++) {
1037 struct rte_mbuf **mbufs =
1038 rte_sched_subport_pipe_qbase(subport, qindex);
1039 uint16_t qsize = rte_sched_subport_pipe_qsize(port, subport, qindex);
1041 struct rte_sched_queue *queue = subport->queue + qindex;
1042 uint16_t qr = queue->qr & (qsize - 1);
1043 uint16_t qw = queue->qw & (qsize - 1);
1045 for (; qr != qw; qr = (qr + 1) & (qsize - 1))
1046 rte_pktmbuf_free(mbufs[qr]);
1054 rte_sched_port_free(struct rte_sched_port *port)
1058 /* Check user parameters */
1062 for (i = 0; i < port->n_subports_per_port; i++)
1063 rte_sched_subport_free(port, port->subports[i]);
1065 rte_free(port->subport_profiles);
1070 rte_sched_free_memory(struct rte_sched_port *port, uint32_t n_subports)
1074 for (i = 0; i < n_subports; i++) {
1075 struct rte_sched_subport *subport = port->subports[i];
1077 rte_sched_subport_free(port, subport);
1080 rte_free(port->subport_profiles);
1084 #ifdef RTE_SCHED_CMAN
1086 rte_sched_red_config(struct rte_sched_port *port,
1087 struct rte_sched_subport *s,
1088 struct rte_sched_subport_params *params,
1089 uint32_t n_subports)
1093 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++) {
1097 for (j = 0; j < RTE_COLORS; j++) {
1098 /* if min/max are both zero, then RED is disabled */
1099 if ((params->cman_params->red_params[i][j].min_th |
1100 params->cman_params->red_params[i][j].max_th) == 0) {
1104 if (rte_red_config_init(&s->red_config[i][j],
1105 params->cman_params->red_params[i][j].wq_log2,
1106 params->cman_params->red_params[i][j].min_th,
1107 params->cman_params->red_params[i][j].max_th,
1108 params->cman_params->red_params[i][j].maxp_inv) != 0) {
1109 rte_sched_free_memory(port, n_subports);
1111 RTE_LOG(NOTICE, SCHED,
1112 "%s: RED configuration init fails\n", __func__);
1117 s->cman = RTE_SCHED_CMAN_RED;
1122 rte_sched_pie_config(struct rte_sched_port *port,
1123 struct rte_sched_subport *s,
1124 struct rte_sched_subport_params *params,
1125 uint32_t n_subports)
1129 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++) {
1130 if (params->cman_params->pie_params[i].tailq_th > params->qsize[i]) {
1131 RTE_LOG(NOTICE, SCHED,
1132 "%s: PIE tailq threshold incorrect\n", __func__);
1136 if (rte_pie_config_init(&s->pie_config[i],
1137 params->cman_params->pie_params[i].qdelay_ref,
1138 params->cman_params->pie_params[i].dp_update_interval,
1139 params->cman_params->pie_params[i].max_burst,
1140 params->cman_params->pie_params[i].tailq_th) != 0) {
1141 rte_sched_free_memory(port, n_subports);
1143 RTE_LOG(NOTICE, SCHED,
1144 "%s: PIE configuration init fails\n", __func__);
1148 s->cman = RTE_SCHED_CMAN_PIE;
1153 rte_sched_cman_config(struct rte_sched_port *port,
1154 struct rte_sched_subport *s,
1155 struct rte_sched_subport_params *params,
1156 uint32_t n_subports)
1158 if (params->cman_params->cman_mode == RTE_SCHED_CMAN_RED)
1159 return rte_sched_red_config(port, s, params, n_subports);
1161 else if (params->cman_params->cman_mode == RTE_SCHED_CMAN_PIE)
1162 return rte_sched_pie_config(port, s, params, n_subports);
1169 rte_sched_subport_config(struct rte_sched_port *port,
1170 uint32_t subport_id,
1171 struct rte_sched_subport_params *params,
1172 uint32_t subport_profile_id)
1174 struct rte_sched_subport *s = NULL;
1175 uint32_t n_subports = subport_id;
1176 struct rte_sched_subport_profile *profile;
1177 uint32_t n_subport_pipe_queues, i;
1178 uint32_t size0, size1, bmp_mem_size;
1182 /* Check user parameters */
1185 "%s: Incorrect value for parameter port\n", __func__);
1189 if (subport_id >= port->n_subports_per_port) {
1191 "%s: Incorrect value for subport id\n", __func__);
1196 if (subport_profile_id >= port->n_max_subport_profiles) {
1197 RTE_LOG(ERR, SCHED, "%s: "
1198 "Number of subport profile exceeds the max limit\n",
1204 /** Memory is allocated only on first invocation of the api for a
1205 * given subport. Subsequent invocation on same subport will just
1206 * update subport bandwidth parameter.
1208 if (port->subports[subport_id] == NULL) {
1210 status = rte_sched_subport_check_params(params,
1211 port->n_pipes_per_subport,
1214 RTE_LOG(NOTICE, SCHED,
1215 "%s: Port scheduler params check failed (%d)\n",
1221 /* Determine the amount of memory to allocate */
1222 size0 = sizeof(struct rte_sched_subport);
1223 size1 = rte_sched_subport_get_array_base(params,
1224 e_RTE_SCHED_SUBPORT_ARRAY_TOTAL);
1226 /* Allocate memory to store the data structures */
1227 s = rte_zmalloc_socket("subport_params", size0 + size1,
1228 RTE_CACHE_LINE_SIZE, port->socket);
1231 "%s: Memory allocation fails\n", __func__);
1238 subport_profile_id = 0;
1241 port->subports[subport_id] = s;
1243 s->tb_time = port->time;
1245 /* compile time checks */
1246 RTE_BUILD_BUG_ON(RTE_SCHED_PORT_N_GRINDERS == 0);
1247 RTE_BUILD_BUG_ON(RTE_SCHED_PORT_N_GRINDERS &
1248 (RTE_SCHED_PORT_N_GRINDERS - 1));
1250 /* User parameters */
1251 s->n_pipes_per_subport_enabled =
1252 params->n_pipes_per_subport_enabled;
1253 memcpy(s->qsize, params->qsize, sizeof(params->qsize));
1254 s->n_pipe_profiles = params->n_pipe_profiles;
1255 s->n_max_pipe_profiles = params->n_max_pipe_profiles;
1257 #ifdef RTE_SCHED_CMAN
1258 if (params->cman_params != NULL) {
1259 s->cman_enabled = true;
1260 status = rte_sched_cman_config(port, s, params, n_subports);
1262 RTE_LOG(NOTICE, SCHED,
1263 "%s: CMAN configuration fails\n", __func__);
1267 s->cman_enabled = false;
1271 /* Scheduling loop detection */
1272 s->pipe_loop = RTE_SCHED_PIPE_INVALID;
1273 s->pipe_exhaustion = 0;
1276 s->busy_grinders = 0;
1278 /* Queue base calculation */
1279 rte_sched_subport_config_qsize(s);
1281 /* Large data structures */
1282 s->pipe = (struct rte_sched_pipe *)
1283 (s->memory + rte_sched_subport_get_array_base(params,
1284 e_RTE_SCHED_SUBPORT_ARRAY_PIPE));
1285 s->queue = (struct rte_sched_queue *)
1286 (s->memory + rte_sched_subport_get_array_base(params,
1287 e_RTE_SCHED_SUBPORT_ARRAY_QUEUE));
1288 s->queue_extra = (struct rte_sched_queue_extra *)
1289 (s->memory + rte_sched_subport_get_array_base(params,
1290 e_RTE_SCHED_SUBPORT_ARRAY_QUEUE_EXTRA));
1291 s->pipe_profiles = (struct rte_sched_pipe_profile *)
1292 (s->memory + rte_sched_subport_get_array_base(params,
1293 e_RTE_SCHED_SUBPORT_ARRAY_PIPE_PROFILES));
1294 s->bmp_array = s->memory + rte_sched_subport_get_array_base(
1295 params, e_RTE_SCHED_SUBPORT_ARRAY_BMP_ARRAY);
1296 s->queue_array = (struct rte_mbuf **)
1297 (s->memory + rte_sched_subport_get_array_base(params,
1298 e_RTE_SCHED_SUBPORT_ARRAY_QUEUE_ARRAY));
1300 /* Pipe profile table */
1301 rte_sched_subport_config_pipe_profile_table(s, params,
1305 n_subport_pipe_queues = rte_sched_subport_pipe_queues(s);
1306 bmp_mem_size = rte_bitmap_get_memory_footprint(
1307 n_subport_pipe_queues);
1308 s->bmp = rte_bitmap_init(n_subport_pipe_queues, s->bmp_array,
1310 if (s->bmp == NULL) {
1312 "%s: Subport bitmap init error\n", __func__);
1317 for (i = 0; i < RTE_SCHED_PORT_N_GRINDERS; i++)
1318 s->grinder_base_bmp_pos[i] = RTE_SCHED_PIPE_INVALID;
1320 #ifdef RTE_SCHED_SUBPORT_TC_OV
1321 /* TC oversubscription */
1322 s->tc_ov_wm_min = port->mtu;
1323 s->tc_ov_period_id = 0;
1331 /* update subport parameters from subport profile table*/
1332 profile = port->subport_profiles + subport_profile_id;
1334 s = port->subports[subport_id];
1336 s->tb_credits = profile->tb_size / 2;
1338 s->tc_time = port->time + profile->tc_period;
1340 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
1343 profile->tc_credits_per_period[i];
1345 profile->tc_credits_per_period[i] = 0;
1347 #ifdef RTE_SCHED_SUBPORT_TC_OV
1348 s->tc_ov_wm_max = rte_sched_time_ms_to_bytes(profile->tc_period,
1349 s->pipe_tc_be_rate_max);
1350 s->tc_ov_wm = s->tc_ov_wm_max;
1352 s->profile = subport_profile_id;
1356 rte_sched_port_log_subport_profile(port, subport_profile_id);
1361 rte_sched_free_memory(port, n_subports);
1367 rte_sched_pipe_config(struct rte_sched_port *port,
1368 uint32_t subport_id,
1370 int32_t pipe_profile)
1372 struct rte_sched_subport *s;
1373 struct rte_sched_subport_profile *sp;
1374 struct rte_sched_pipe *p;
1375 struct rte_sched_pipe_profile *params;
1376 uint32_t n_subports = subport_id + 1;
1377 uint32_t deactivate, profile, i;
1380 /* Check user parameters */
1381 profile = (uint32_t) pipe_profile;
1382 deactivate = (pipe_profile < 0);
1386 "%s: Incorrect value for parameter port\n", __func__);
1390 if (subport_id >= port->n_subports_per_port) {
1392 "%s: Incorrect value for parameter subport id\n", __func__);
1397 s = port->subports[subport_id];
1398 if (pipe_id >= s->n_pipes_per_subport_enabled) {
1400 "%s: Incorrect value for parameter pipe id\n", __func__);
1405 if (!deactivate && profile >= s->n_pipe_profiles) {
1407 "%s: Incorrect value for parameter pipe profile\n", __func__);
1412 sp = port->subport_profiles + s->profile;
1413 /* Handle the case when pipe already has a valid configuration */
1414 p = s->pipe + pipe_id;
1416 params = s->pipe_profiles + p->profile;
1418 double subport_tc_be_rate =
1419 (double)sp->tc_credits_per_period[RTE_SCHED_TRAFFIC_CLASS_BE]
1420 / (double) sp->tc_period;
1421 double pipe_tc_be_rate =
1422 (double) params->tc_credits_per_period[RTE_SCHED_TRAFFIC_CLASS_BE]
1423 / (double) params->tc_period;
1424 uint32_t tc_be_ov = s->tc_ov;
1426 /* Unplug pipe from its subport */
1427 s->tc_ov_n -= params->tc_ov_weight;
1428 s->tc_ov_rate -= pipe_tc_be_rate;
1429 s->tc_ov = s->tc_ov_rate > subport_tc_be_rate;
1431 if (s->tc_ov != tc_be_ov) {
1432 RTE_LOG(DEBUG, SCHED,
1433 "Subport %u Best-effort TC oversubscription is OFF (%.4lf >= %.4lf)\n",
1434 subport_id, subport_tc_be_rate, s->tc_ov_rate);
1437 /* Reset the pipe */
1438 memset(p, 0, sizeof(struct rte_sched_pipe));
1444 /* Apply the new pipe configuration */
1445 p->profile = profile;
1446 params = s->pipe_profiles + p->profile;
1448 /* Token Bucket (TB) */
1449 p->tb_time = port->time;
1450 p->tb_credits = params->tb_size / 2;
1452 /* Traffic Classes (TCs) */
1453 p->tc_time = port->time + params->tc_period;
1455 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
1457 p->tc_credits[i] = params->tc_credits_per_period[i];
1460 /* Subport best effort tc oversubscription */
1461 double subport_tc_be_rate =
1462 (double)sp->tc_credits_per_period[RTE_SCHED_TRAFFIC_CLASS_BE]
1463 / (double) sp->tc_period;
1464 double pipe_tc_be_rate =
1465 (double) params->tc_credits_per_period[RTE_SCHED_TRAFFIC_CLASS_BE]
1466 / (double) params->tc_period;
1467 uint32_t tc_be_ov = s->tc_ov;
1469 s->tc_ov_n += params->tc_ov_weight;
1470 s->tc_ov_rate += pipe_tc_be_rate;
1471 s->tc_ov = s->tc_ov_rate > subport_tc_be_rate;
1473 if (s->tc_ov != tc_be_ov) {
1474 RTE_LOG(DEBUG, SCHED,
1475 "Subport %u Best effort TC oversubscription is ON (%.4lf < %.4lf)\n",
1476 subport_id, subport_tc_be_rate, s->tc_ov_rate);
1478 p->tc_ov_period_id = s->tc_ov_period_id;
1479 p->tc_ov_credits = s->tc_ov_wm;
1485 rte_sched_free_memory(port, n_subports);
1491 rte_sched_subport_pipe_profile_add(struct rte_sched_port *port,
1492 uint32_t subport_id,
1493 struct rte_sched_pipe_params *params,
1494 uint32_t *pipe_profile_id)
1496 struct rte_sched_subport *s;
1497 struct rte_sched_pipe_profile *pp;
1504 "%s: Incorrect value for parameter port\n", __func__);
1508 /* Subport id not exceeds the max limit */
1509 if (subport_id > port->n_subports_per_port) {
1511 "%s: Incorrect value for subport id\n", __func__);
1515 s = port->subports[subport_id];
1517 /* Pipe profiles exceeds the max limit */
1518 if (s->n_pipe_profiles >= s->n_max_pipe_profiles) {
1520 "%s: Number of pipe profiles exceeds the max limit\n", __func__);
1525 status = pipe_profile_check(params, port->rate, &s->qsize[0]);
1528 "%s: Pipe profile check failed(%d)\n", __func__, status);
1532 pp = &s->pipe_profiles[s->n_pipe_profiles];
1533 rte_sched_pipe_profile_convert(s, params, pp, port->rate);
1535 /* Pipe profile should not exists */
1536 for (i = 0; i < s->n_pipe_profiles; i++)
1537 if (memcmp(s->pipe_profiles + i, pp, sizeof(*pp)) == 0) {
1539 "%s: Pipe profile exists\n", __func__);
1543 /* Pipe profile commit */
1544 *pipe_profile_id = s->n_pipe_profiles;
1545 s->n_pipe_profiles++;
1547 if (s->pipe_tc_be_rate_max < params->tc_rate[RTE_SCHED_TRAFFIC_CLASS_BE])
1548 s->pipe_tc_be_rate_max = params->tc_rate[RTE_SCHED_TRAFFIC_CLASS_BE];
1550 rte_sched_port_log_pipe_profile(s, *pipe_profile_id);
1556 rte_sched_port_subport_profile_add(struct rte_sched_port *port,
1557 struct rte_sched_subport_profile_params *params,
1558 uint32_t *subport_profile_id)
1562 struct rte_sched_subport_profile *dst;
1566 RTE_LOG(ERR, SCHED, "%s: "
1567 "Incorrect value for parameter port\n", __func__);
1571 if (params == NULL) {
1572 RTE_LOG(ERR, SCHED, "%s: "
1573 "Incorrect value for parameter profile\n", __func__);
1577 if (subport_profile_id == NULL) {
1578 RTE_LOG(ERR, SCHED, "%s: "
1579 "Incorrect value for parameter subport_profile_id\n",
1584 dst = port->subport_profiles + port->n_subport_profiles;
1586 /* Subport profiles exceeds the max limit */
1587 if (port->n_subport_profiles >= port->n_max_subport_profiles) {
1588 RTE_LOG(ERR, SCHED, "%s: "
1589 "Number of subport profiles exceeds the max limit\n",
1594 status = subport_profile_check(params, port->rate);
1597 "%s: subport profile check failed(%d)\n", __func__, status);
1601 rte_sched_subport_profile_convert(params, dst, port->rate);
1603 /* Subport profile should not exists */
1604 for (i = 0; i < port->n_subport_profiles; i++)
1605 if (memcmp(port->subport_profiles + i,
1606 dst, sizeof(*dst)) == 0) {
1608 "%s: subport profile exists\n", __func__);
1612 /* Subport profile commit */
1613 *subport_profile_id = port->n_subport_profiles;
1614 port->n_subport_profiles++;
1616 rte_sched_port_log_subport_profile(port, *subport_profile_id);
1621 static inline uint32_t
1622 rte_sched_port_qindex(struct rte_sched_port *port,
1625 uint32_t traffic_class,
1628 return ((subport & (port->n_subports_per_port - 1)) <<
1629 (port->n_pipes_per_subport_log2 + 4)) |
1631 (port->subports[subport]->n_pipes_per_subport_enabled - 1)) << 4) |
1632 ((rte_sched_port_pipe_queue(port, traffic_class) + queue) &
1633 (RTE_SCHED_QUEUES_PER_PIPE - 1));
1637 rte_sched_port_pkt_write(struct rte_sched_port *port,
1638 struct rte_mbuf *pkt,
1639 uint32_t subport, uint32_t pipe,
1640 uint32_t traffic_class,
1641 uint32_t queue, enum rte_color color)
1644 rte_sched_port_qindex(port, subport, pipe, traffic_class, queue);
1646 rte_mbuf_sched_set(pkt, queue_id, traffic_class, (uint8_t)color);
1650 rte_sched_port_pkt_read_tree_path(struct rte_sched_port *port,
1651 const struct rte_mbuf *pkt,
1652 uint32_t *subport, uint32_t *pipe,
1653 uint32_t *traffic_class, uint32_t *queue)
1655 uint32_t queue_id = rte_mbuf_sched_queue_get(pkt);
1657 *subport = queue_id >> (port->n_pipes_per_subport_log2 + 4);
1658 *pipe = (queue_id >> 4) &
1659 (port->subports[*subport]->n_pipes_per_subport_enabled - 1);
1660 *traffic_class = rte_sched_port_pipe_tc(port, queue_id);
1661 *queue = rte_sched_port_tc_queue(port, queue_id);
1665 rte_sched_port_pkt_read_color(const struct rte_mbuf *pkt)
1667 return (enum rte_color)rte_mbuf_sched_color_get(pkt);
1671 rte_sched_subport_read_stats(struct rte_sched_port *port,
1672 uint32_t subport_id,
1673 struct rte_sched_subport_stats *stats,
1676 struct rte_sched_subport *s;
1678 /* Check user parameters */
1681 "%s: Incorrect value for parameter port\n", __func__);
1685 if (subport_id >= port->n_subports_per_port) {
1687 "%s: Incorrect value for subport id\n", __func__);
1691 if (stats == NULL) {
1693 "%s: Incorrect value for parameter stats\n", __func__);
1697 if (tc_ov == NULL) {
1699 "%s: Incorrect value for tc_ov\n", __func__);
1703 s = port->subports[subport_id];
1705 /* Copy subport stats and clear */
1706 memcpy(stats, &s->stats, sizeof(struct rte_sched_subport_stats));
1707 memset(&s->stats, 0, sizeof(struct rte_sched_subport_stats));
1709 /* Subport TC oversubscription status */
1716 rte_sched_queue_read_stats(struct rte_sched_port *port,
1718 struct rte_sched_queue_stats *stats,
1721 struct rte_sched_subport *s;
1722 struct rte_sched_queue *q;
1723 struct rte_sched_queue_extra *qe;
1724 uint32_t subport_id, subport_qmask, subport_qindex;
1726 /* Check user parameters */
1729 "%s: Incorrect value for parameter port\n", __func__);
1733 if (queue_id >= rte_sched_port_queues_per_port(port)) {
1735 "%s: Incorrect value for queue id\n", __func__);
1739 if (stats == NULL) {
1741 "%s: Incorrect value for parameter stats\n", __func__);
1747 "%s: Incorrect value for parameter qlen\n", __func__);
1750 subport_qmask = port->n_pipes_per_subport_log2 + 4;
1751 subport_id = (queue_id >> subport_qmask) & (port->n_subports_per_port - 1);
1753 s = port->subports[subport_id];
1754 subport_qindex = ((1 << subport_qmask) - 1) & queue_id;
1755 q = s->queue + subport_qindex;
1756 qe = s->queue_extra + subport_qindex;
1758 /* Copy queue stats and clear */
1759 memcpy(stats, &qe->stats, sizeof(struct rte_sched_queue_stats));
1760 memset(&qe->stats, 0, sizeof(struct rte_sched_queue_stats));
1763 *qlen = q->qw - q->qr;
1768 #ifdef RTE_SCHED_DEBUG
1771 rte_sched_port_queue_is_empty(struct rte_sched_subport *subport,
1774 struct rte_sched_queue *queue = subport->queue + qindex;
1776 return queue->qr == queue->qw;
1779 #endif /* RTE_SCHED_DEBUG */
1782 rte_sched_port_update_subport_stats(struct rte_sched_port *port,
1783 struct rte_sched_subport *subport,
1785 struct rte_mbuf *pkt)
1787 uint32_t tc_index = rte_sched_port_pipe_tc(port, qindex);
1788 uint32_t pkt_len = pkt->pkt_len;
1790 subport->stats.n_pkts_tc[tc_index] += 1;
1791 subport->stats.n_bytes_tc[tc_index] += pkt_len;
1795 rte_sched_port_update_subport_stats_on_drop(struct rte_sched_port *port,
1796 struct rte_sched_subport *subport,
1798 struct rte_mbuf *pkt,
1799 __rte_unused uint32_t n_pkts_cman_dropped)
1801 uint32_t tc_index = rte_sched_port_pipe_tc(port, qindex);
1802 uint32_t pkt_len = pkt->pkt_len;
1804 subport->stats.n_pkts_tc_dropped[tc_index] += 1;
1805 subport->stats.n_bytes_tc_dropped[tc_index] += pkt_len;
1806 subport->stats.n_pkts_cman_dropped[tc_index] += n_pkts_cman_dropped;
1810 rte_sched_port_update_queue_stats(struct rte_sched_subport *subport,
1812 struct rte_mbuf *pkt)
1814 struct rte_sched_queue_extra *qe = subport->queue_extra + qindex;
1815 uint32_t pkt_len = pkt->pkt_len;
1817 qe->stats.n_pkts += 1;
1818 qe->stats.n_bytes += pkt_len;
1822 rte_sched_port_update_queue_stats_on_drop(struct rte_sched_subport *subport,
1824 struct rte_mbuf *pkt,
1825 __rte_unused uint32_t n_pkts_cman_dropped)
1827 struct rte_sched_queue_extra *qe = subport->queue_extra + qindex;
1828 uint32_t pkt_len = pkt->pkt_len;
1830 qe->stats.n_pkts_dropped += 1;
1831 qe->stats.n_bytes_dropped += pkt_len;
1832 #ifdef RTE_SCHED_CMAN
1833 if (subport->cman_enabled)
1834 qe->stats.n_pkts_cman_dropped += n_pkts_cman_dropped;
1838 #ifdef RTE_SCHED_CMAN
1841 rte_sched_port_cman_drop(struct rte_sched_port *port,
1842 struct rte_sched_subport *subport,
1843 struct rte_mbuf *pkt,
1847 if (!subport->cman_enabled)
1850 struct rte_sched_queue_extra *qe;
1853 tc_index = rte_sched_port_pipe_tc(port, qindex);
1854 qe = subport->queue_extra + qindex;
1857 if (subport->cman == RTE_SCHED_CMAN_RED) {
1858 struct rte_red_config *red_cfg;
1859 struct rte_red *red;
1860 enum rte_color color;
1862 color = rte_sched_port_pkt_read_color(pkt);
1863 red_cfg = &subport->red_config[tc_index][color];
1865 if ((red_cfg->min_th | red_cfg->max_th) == 0)
1870 return rte_red_enqueue(red_cfg, red, qlen, port->time);
1874 struct rte_pie_config *pie_cfg = &subport->pie_config[tc_index];
1875 struct rte_pie *pie = &qe->pie;
1877 return rte_pie_enqueue(pie_cfg, pie, qlen, pkt->pkt_len, port->time_cpu_cycles);
1881 rte_sched_port_red_set_queue_empty_timestamp(struct rte_sched_port *port,
1882 struct rte_sched_subport *subport, uint32_t qindex)
1884 if (subport->cman_enabled) {
1885 struct rte_sched_queue_extra *qe = subport->queue_extra + qindex;
1886 if (subport->cman == RTE_SCHED_CMAN_RED) {
1887 struct rte_red *red = &qe->red;
1889 rte_red_mark_queue_empty(red, port->time);
1895 rte_sched_port_pie_dequeue(struct rte_sched_subport *subport,
1896 uint32_t qindex, uint32_t pkt_len, uint64_t time) {
1897 if (subport->cman_enabled && subport->cman == RTE_SCHED_CMAN_PIE) {
1898 struct rte_sched_queue_extra *qe = subport->queue_extra + qindex;
1899 struct rte_pie *pie = &qe->pie;
1901 /* Update queue length */
1903 pie->qlen_bytes -= pkt_len;
1905 rte_pie_dequeue(pie, pkt_len, time);
1911 static inline int rte_sched_port_cman_drop(struct rte_sched_port *port __rte_unused,
1912 struct rte_sched_subport *subport __rte_unused,
1913 struct rte_mbuf *pkt __rte_unused,
1914 uint32_t qindex __rte_unused,
1915 uint16_t qlen __rte_unused)
1920 #define rte_sched_port_red_set_queue_empty_timestamp(port, subport, qindex)
1923 rte_sched_port_pie_dequeue(struct rte_sched_subport *subport __rte_unused,
1924 uint32_t qindex __rte_unused,
1925 uint32_t pkt_len __rte_unused,
1926 uint64_t time __rte_unused) {
1927 /* do-nothing when RTE_SCHED_CMAN not defined */
1930 #endif /* RTE_SCHED_CMAN */
1932 #ifdef RTE_SCHED_DEBUG
1935 debug_check_queue_slab(struct rte_sched_subport *subport, uint32_t bmp_pos,
1942 rte_panic("Empty slab at position %u\n", bmp_pos);
1945 for (i = 0, mask = 1; i < 64; i++, mask <<= 1) {
1946 if (mask & bmp_slab) {
1947 if (rte_sched_port_queue_is_empty(subport, bmp_pos + i)) {
1948 printf("Queue %u (slab offset %u) is empty\n", bmp_pos + i, i);
1955 rte_panic("Empty queues in slab 0x%" PRIx64 "starting at position %u\n",
1959 #endif /* RTE_SCHED_DEBUG */
1961 static inline struct rte_sched_subport *
1962 rte_sched_port_subport(struct rte_sched_port *port,
1963 struct rte_mbuf *pkt)
1965 uint32_t queue_id = rte_mbuf_sched_queue_get(pkt);
1966 uint32_t subport_id = queue_id >> (port->n_pipes_per_subport_log2 + 4);
1968 return port->subports[subport_id];
1971 static inline uint32_t
1972 rte_sched_port_enqueue_qptrs_prefetch0(struct rte_sched_subport *subport,
1973 struct rte_mbuf *pkt, uint32_t subport_qmask)
1975 struct rte_sched_queue *q;
1976 struct rte_sched_queue_extra *qe;
1977 uint32_t qindex = rte_mbuf_sched_queue_get(pkt);
1978 uint32_t subport_queue_id = subport_qmask & qindex;
1980 q = subport->queue + subport_queue_id;
1982 qe = subport->queue_extra + subport_queue_id;
1985 return subport_queue_id;
1989 rte_sched_port_enqueue_qwa_prefetch0(struct rte_sched_port *port,
1990 struct rte_sched_subport *subport,
1992 struct rte_mbuf **qbase)
1994 struct rte_sched_queue *q;
1995 struct rte_mbuf **q_qw;
1998 q = subport->queue + qindex;
1999 qsize = rte_sched_subport_pipe_qsize(port, subport, qindex);
2000 q_qw = qbase + (q->qw & (qsize - 1));
2002 rte_prefetch0(q_qw);
2003 rte_bitmap_prefetch0(subport->bmp, qindex);
2007 rte_sched_port_enqueue_qwa(struct rte_sched_port *port,
2008 struct rte_sched_subport *subport,
2010 struct rte_mbuf **qbase,
2011 struct rte_mbuf *pkt)
2013 struct rte_sched_queue *q;
2017 q = subport->queue + qindex;
2018 qsize = rte_sched_subport_pipe_qsize(port, subport, qindex);
2019 qlen = q->qw - q->qr;
2021 /* Drop the packet (and update drop stats) when queue is full */
2022 if (unlikely(rte_sched_port_cman_drop(port, subport, pkt, qindex, qlen) ||
2024 rte_pktmbuf_free(pkt);
2025 rte_sched_port_update_subport_stats_on_drop(port, subport,
2026 qindex, pkt, qlen < qsize);
2027 rte_sched_port_update_queue_stats_on_drop(subport, qindex, pkt,
2032 /* Enqueue packet */
2033 qbase[q->qw & (qsize - 1)] = pkt;
2036 /* Activate queue in the subport bitmap */
2037 rte_bitmap_set(subport->bmp, qindex);
2040 rte_sched_port_update_subport_stats(port, subport, qindex, pkt);
2041 rte_sched_port_update_queue_stats(subport, qindex, pkt);
2048 * The enqueue function implements a 4-level pipeline with each stage
2049 * processing two different packets. The purpose of using a pipeline
2050 * is to hide the latency of prefetching the data structures. The
2051 * naming convention is presented in the diagram below:
2053 * p00 _______ p10 _______ p20 _______ p30 _______
2054 * ----->| |----->| |----->| |----->| |----->
2055 * | 0 | | 1 | | 2 | | 3 |
2056 * ----->|_______|----->|_______|----->|_______|----->|_______|----->
2061 rte_sched_port_enqueue(struct rte_sched_port *port, struct rte_mbuf **pkts,
2064 struct rte_mbuf *pkt00, *pkt01, *pkt10, *pkt11, *pkt20, *pkt21,
2065 *pkt30, *pkt31, *pkt_last;
2066 struct rte_mbuf **q00_base, **q01_base, **q10_base, **q11_base,
2067 **q20_base, **q21_base, **q30_base, **q31_base, **q_last_base;
2068 struct rte_sched_subport *subport00, *subport01, *subport10, *subport11,
2069 *subport20, *subport21, *subport30, *subport31, *subport_last;
2070 uint32_t q00, q01, q10, q11, q20, q21, q30, q31, q_last;
2071 uint32_t r00, r01, r10, r11, r20, r21, r30, r31, r_last;
2072 uint32_t subport_qmask;
2076 subport_qmask = (1 << (port->n_pipes_per_subport_log2 + 4)) - 1;
2079 * Less then 6 input packets available, which is not enough to
2082 if (unlikely(n_pkts < 6)) {
2083 struct rte_sched_subport *subports[5];
2084 struct rte_mbuf **q_base[5];
2087 /* Prefetch the mbuf structure of each packet */
2088 for (i = 0; i < n_pkts; i++)
2089 rte_prefetch0(pkts[i]);
2091 /* Prefetch the subport structure for each packet */
2092 for (i = 0; i < n_pkts; i++)
2093 subports[i] = rte_sched_port_subport(port, pkts[i]);
2095 /* Prefetch the queue structure for each queue */
2096 for (i = 0; i < n_pkts; i++)
2097 q[i] = rte_sched_port_enqueue_qptrs_prefetch0(subports[i],
2098 pkts[i], subport_qmask);
2100 /* Prefetch the write pointer location of each queue */
2101 for (i = 0; i < n_pkts; i++) {
2102 q_base[i] = rte_sched_subport_pipe_qbase(subports[i], q[i]);
2103 rte_sched_port_enqueue_qwa_prefetch0(port, subports[i],
2107 /* Write each packet to its queue */
2108 for (i = 0; i < n_pkts; i++)
2109 result += rte_sched_port_enqueue_qwa(port, subports[i],
2110 q[i], q_base[i], pkts[i]);
2115 /* Feed the first 3 stages of the pipeline (6 packets needed) */
2118 rte_prefetch0(pkt20);
2119 rte_prefetch0(pkt21);
2123 rte_prefetch0(pkt10);
2124 rte_prefetch0(pkt11);
2126 subport20 = rte_sched_port_subport(port, pkt20);
2127 subport21 = rte_sched_port_subport(port, pkt21);
2128 q20 = rte_sched_port_enqueue_qptrs_prefetch0(subport20,
2129 pkt20, subport_qmask);
2130 q21 = rte_sched_port_enqueue_qptrs_prefetch0(subport21,
2131 pkt21, subport_qmask);
2135 rte_prefetch0(pkt00);
2136 rte_prefetch0(pkt01);
2138 subport10 = rte_sched_port_subport(port, pkt10);
2139 subport11 = rte_sched_port_subport(port, pkt11);
2140 q10 = rte_sched_port_enqueue_qptrs_prefetch0(subport10,
2141 pkt10, subport_qmask);
2142 q11 = rte_sched_port_enqueue_qptrs_prefetch0(subport11,
2143 pkt11, subport_qmask);
2145 q20_base = rte_sched_subport_pipe_qbase(subport20, q20);
2146 q21_base = rte_sched_subport_pipe_qbase(subport21, q21);
2147 rte_sched_port_enqueue_qwa_prefetch0(port, subport20, q20, q20_base);
2148 rte_sched_port_enqueue_qwa_prefetch0(port, subport21, q21, q21_base);
2150 /* Run the pipeline */
2151 for (i = 6; i < (n_pkts & (~1)); i += 2) {
2152 /* Propagate stage inputs */
2163 subport30 = subport20;
2164 subport31 = subport21;
2165 subport20 = subport10;
2166 subport21 = subport11;
2167 q30_base = q20_base;
2168 q31_base = q21_base;
2170 /* Stage 0: Get packets in */
2172 pkt01 = pkts[i + 1];
2173 rte_prefetch0(pkt00);
2174 rte_prefetch0(pkt01);
2176 /* Stage 1: Prefetch subport and queue structure storing queue pointers */
2177 subport10 = rte_sched_port_subport(port, pkt10);
2178 subport11 = rte_sched_port_subport(port, pkt11);
2179 q10 = rte_sched_port_enqueue_qptrs_prefetch0(subport10,
2180 pkt10, subport_qmask);
2181 q11 = rte_sched_port_enqueue_qptrs_prefetch0(subport11,
2182 pkt11, subport_qmask);
2184 /* Stage 2: Prefetch queue write location */
2185 q20_base = rte_sched_subport_pipe_qbase(subport20, q20);
2186 q21_base = rte_sched_subport_pipe_qbase(subport21, q21);
2187 rte_sched_port_enqueue_qwa_prefetch0(port, subport20, q20, q20_base);
2188 rte_sched_port_enqueue_qwa_prefetch0(port, subport21, q21, q21_base);
2190 /* Stage 3: Write packet to queue and activate queue */
2191 r30 = rte_sched_port_enqueue_qwa(port, subport30,
2192 q30, q30_base, pkt30);
2193 r31 = rte_sched_port_enqueue_qwa(port, subport31,
2194 q31, q31_base, pkt31);
2195 result += r30 + r31;
2199 * Drain the pipeline (exactly 6 packets).
2200 * Handle the last packet in the case
2201 * of an odd number of input packets.
2203 pkt_last = pkts[n_pkts - 1];
2204 rte_prefetch0(pkt_last);
2206 subport00 = rte_sched_port_subport(port, pkt00);
2207 subport01 = rte_sched_port_subport(port, pkt01);
2208 q00 = rte_sched_port_enqueue_qptrs_prefetch0(subport00,
2209 pkt00, subport_qmask);
2210 q01 = rte_sched_port_enqueue_qptrs_prefetch0(subport01,
2211 pkt01, subport_qmask);
2213 q10_base = rte_sched_subport_pipe_qbase(subport10, q10);
2214 q11_base = rte_sched_subport_pipe_qbase(subport11, q11);
2215 rte_sched_port_enqueue_qwa_prefetch0(port, subport10, q10, q10_base);
2216 rte_sched_port_enqueue_qwa_prefetch0(port, subport11, q11, q11_base);
2218 r20 = rte_sched_port_enqueue_qwa(port, subport20,
2219 q20, q20_base, pkt20);
2220 r21 = rte_sched_port_enqueue_qwa(port, subport21,
2221 q21, q21_base, pkt21);
2222 result += r20 + r21;
2224 subport_last = rte_sched_port_subport(port, pkt_last);
2225 q_last = rte_sched_port_enqueue_qptrs_prefetch0(subport_last,
2226 pkt_last, subport_qmask);
2228 q00_base = rte_sched_subport_pipe_qbase(subport00, q00);
2229 q01_base = rte_sched_subport_pipe_qbase(subport01, q01);
2230 rte_sched_port_enqueue_qwa_prefetch0(port, subport00, q00, q00_base);
2231 rte_sched_port_enqueue_qwa_prefetch0(port, subport01, q01, q01_base);
2233 r10 = rte_sched_port_enqueue_qwa(port, subport10, q10,
2235 r11 = rte_sched_port_enqueue_qwa(port, subport11, q11,
2237 result += r10 + r11;
2239 q_last_base = rte_sched_subport_pipe_qbase(subport_last, q_last);
2240 rte_sched_port_enqueue_qwa_prefetch0(port, subport_last,
2241 q_last, q_last_base);
2243 r00 = rte_sched_port_enqueue_qwa(port, subport00, q00,
2245 r01 = rte_sched_port_enqueue_qwa(port, subport01, q01,
2247 result += r00 + r01;
2250 r_last = rte_sched_port_enqueue_qwa(port, subport_last,
2251 q_last, q_last_base, pkt_last);
2258 #ifndef RTE_SCHED_SUBPORT_TC_OV
2261 grinder_credits_update(struct rte_sched_port *port,
2262 struct rte_sched_subport *subport, uint32_t pos)
2264 struct rte_sched_grinder *grinder = subport->grinder + pos;
2265 struct rte_sched_pipe *pipe = grinder->pipe;
2266 struct rte_sched_pipe_profile *params = grinder->pipe_params;
2267 struct rte_sched_subport_profile *sp = grinder->subport_params;
2272 n_periods = (port->time - subport->tb_time) / sp->tb_period;
2273 subport->tb_credits += n_periods * sp->tb_credits_per_period;
2274 subport->tb_credits = RTE_MIN(subport->tb_credits, sp->tb_size);
2275 subport->tb_time += n_periods * sp->tb_period;
2278 n_periods = (port->time - pipe->tb_time) / params->tb_period;
2279 pipe->tb_credits += n_periods * params->tb_credits_per_period;
2280 pipe->tb_credits = RTE_MIN(pipe->tb_credits, params->tb_size);
2281 pipe->tb_time += n_periods * params->tb_period;
2284 if (unlikely(port->time >= subport->tc_time)) {
2285 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
2286 subport->tc_credits[i] = sp->tc_credits_per_period[i];
2288 subport->tc_time = port->time + sp->tc_period;
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];
2296 pipe->tc_time = port->time + params->tc_period;
2302 static inline uint64_t
2303 grinder_tc_ov_credits_update(struct rte_sched_port *port,
2304 struct rte_sched_subport *subport, uint32_t pos)
2306 struct rte_sched_grinder *grinder = subport->grinder + pos;
2307 struct rte_sched_subport_profile *sp = grinder->subport_params;
2308 uint64_t tc_ov_consumption[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
2309 uint64_t tc_consumption = 0, tc_ov_consumption_max;
2310 uint64_t tc_ov_wm = subport->tc_ov_wm;
2313 if (subport->tc_ov == 0)
2314 return subport->tc_ov_wm_max;
2316 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASS_BE; i++) {
2317 tc_ov_consumption[i] = sp->tc_credits_per_period[i]
2318 - subport->tc_credits[i];
2319 tc_consumption += tc_ov_consumption[i];
2322 tc_ov_consumption[RTE_SCHED_TRAFFIC_CLASS_BE] =
2323 sp->tc_credits_per_period[RTE_SCHED_TRAFFIC_CLASS_BE] -
2324 subport->tc_credits[RTE_SCHED_TRAFFIC_CLASS_BE];
2326 tc_ov_consumption_max =
2327 sp->tc_credits_per_period[RTE_SCHED_TRAFFIC_CLASS_BE] -
2330 if (tc_ov_consumption[RTE_SCHED_TRAFFIC_CLASS_BE] >
2331 (tc_ov_consumption_max - port->mtu)) {
2332 tc_ov_wm -= tc_ov_wm >> 7;
2333 if (tc_ov_wm < subport->tc_ov_wm_min)
2334 tc_ov_wm = subport->tc_ov_wm_min;
2339 tc_ov_wm += (tc_ov_wm >> 7) + 1;
2340 if (tc_ov_wm > subport->tc_ov_wm_max)
2341 tc_ov_wm = subport->tc_ov_wm_max;
2347 grinder_credits_update(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_sched_pipe_profile *params = grinder->pipe_params;
2353 struct rte_sched_subport_profile *sp = grinder->subport_params;
2358 n_periods = (port->time - subport->tb_time) / sp->tb_period;
2359 subport->tb_credits += n_periods * sp->tb_credits_per_period;
2360 subport->tb_credits = RTE_MIN(subport->tb_credits, sp->tb_size);
2361 subport->tb_time += n_periods * sp->tb_period;
2364 n_periods = (port->time - pipe->tb_time) / params->tb_period;
2365 pipe->tb_credits += n_periods * params->tb_credits_per_period;
2366 pipe->tb_credits = RTE_MIN(pipe->tb_credits, params->tb_size);
2367 pipe->tb_time += n_periods * params->tb_period;
2370 if (unlikely(port->time >= subport->tc_time)) {
2372 grinder_tc_ov_credits_update(port, subport, pos);
2374 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
2375 subport->tc_credits[i] = sp->tc_credits_per_period[i];
2377 subport->tc_time = port->time + sp->tc_period;
2378 subport->tc_ov_period_id++;
2382 if (unlikely(port->time >= pipe->tc_time)) {
2383 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
2384 pipe->tc_credits[i] = params->tc_credits_per_period[i];
2385 pipe->tc_time = port->time + params->tc_period;
2388 /* Pipe TCs - Oversubscription */
2389 if (unlikely(pipe->tc_ov_period_id != subport->tc_ov_period_id)) {
2390 pipe->tc_ov_credits = subport->tc_ov_wm * params->tc_ov_weight;
2392 pipe->tc_ov_period_id = subport->tc_ov_period_id;
2396 #endif /* RTE_SCHED_TS_CREDITS_UPDATE, RTE_SCHED_SUBPORT_TC_OV */
2399 #ifndef RTE_SCHED_SUBPORT_TC_OV
2402 grinder_credits_check(struct rte_sched_port *port,
2403 struct rte_sched_subport *subport, uint32_t pos)
2405 struct rte_sched_grinder *grinder = subport->grinder + pos;
2406 struct rte_sched_pipe *pipe = grinder->pipe;
2407 struct rte_mbuf *pkt = grinder->pkt;
2408 uint32_t tc_index = grinder->tc_index;
2409 uint64_t pkt_len = pkt->pkt_len + port->frame_overhead;
2410 uint64_t subport_tb_credits = subport->tb_credits;
2411 uint64_t subport_tc_credits = subport->tc_credits[tc_index];
2412 uint64_t pipe_tb_credits = pipe->tb_credits;
2413 uint64_t pipe_tc_credits = pipe->tc_credits[tc_index];
2416 /* Check queue credits */
2417 enough_credits = (pkt_len <= subport_tb_credits) &&
2418 (pkt_len <= subport_tc_credits) &&
2419 (pkt_len <= pipe_tb_credits) &&
2420 (pkt_len <= pipe_tc_credits);
2422 if (!enough_credits)
2425 /* Update port credits */
2426 subport->tb_credits -= pkt_len;
2427 subport->tc_credits[tc_index] -= pkt_len;
2428 pipe->tb_credits -= pkt_len;
2429 pipe->tc_credits[tc_index] -= pkt_len;
2437 grinder_credits_check(struct rte_sched_port *port,
2438 struct rte_sched_subport *subport, uint32_t pos)
2440 struct rte_sched_grinder *grinder = subport->grinder + pos;
2441 struct rte_sched_pipe *pipe = grinder->pipe;
2442 struct rte_mbuf *pkt = grinder->pkt;
2443 uint32_t tc_index = grinder->tc_index;
2444 uint64_t pkt_len = pkt->pkt_len + port->frame_overhead;
2445 uint64_t subport_tb_credits = subport->tb_credits;
2446 uint64_t subport_tc_credits = subport->tc_credits[tc_index];
2447 uint64_t pipe_tb_credits = pipe->tb_credits;
2448 uint64_t pipe_tc_credits = pipe->tc_credits[tc_index];
2449 uint64_t pipe_tc_ov_mask1[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
2450 uint64_t pipe_tc_ov_mask2[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE] = {0};
2451 uint64_t pipe_tc_ov_credits;
2455 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
2456 pipe_tc_ov_mask1[i] = ~0LLU;
2458 pipe_tc_ov_mask1[RTE_SCHED_TRAFFIC_CLASS_BE] = pipe->tc_ov_credits;
2459 pipe_tc_ov_mask2[RTE_SCHED_TRAFFIC_CLASS_BE] = ~0LLU;
2460 pipe_tc_ov_credits = pipe_tc_ov_mask1[tc_index];
2462 /* Check pipe and subport credits */
2463 enough_credits = (pkt_len <= subport_tb_credits) &&
2464 (pkt_len <= subport_tc_credits) &&
2465 (pkt_len <= pipe_tb_credits) &&
2466 (pkt_len <= pipe_tc_credits) &&
2467 (pkt_len <= pipe_tc_ov_credits);
2469 if (!enough_credits)
2472 /* Update pipe and subport credits */
2473 subport->tb_credits -= pkt_len;
2474 subport->tc_credits[tc_index] -= pkt_len;
2475 pipe->tb_credits -= pkt_len;
2476 pipe->tc_credits[tc_index] -= pkt_len;
2477 pipe->tc_ov_credits -= pipe_tc_ov_mask2[tc_index] & pkt_len;
2482 #endif /* RTE_SCHED_SUBPORT_TC_OV */
2486 grinder_schedule(struct rte_sched_port *port,
2487 struct rte_sched_subport *subport, uint32_t pos)
2489 struct rte_sched_grinder *grinder = subport->grinder + pos;
2490 struct rte_sched_queue *queue = grinder->queue[grinder->qpos];
2491 uint32_t qindex = grinder->qindex[grinder->qpos];
2492 struct rte_mbuf *pkt = grinder->pkt;
2493 uint32_t pkt_len = pkt->pkt_len + port->frame_overhead;
2494 uint32_t be_tc_active;
2496 if (!grinder_credits_check(port, subport, pos))
2499 /* Advance port time */
2500 port->time += pkt_len;
2503 port->pkts_out[port->n_pkts_out++] = pkt;
2506 be_tc_active = (grinder->tc_index == RTE_SCHED_TRAFFIC_CLASS_BE) ? ~0x0 : 0x0;
2507 grinder->wrr_tokens[grinder->qpos] +=
2508 (pkt_len * grinder->wrr_cost[grinder->qpos]) & be_tc_active;
2510 if (queue->qr == queue->qw) {
2511 rte_bitmap_clear(subport->bmp, qindex);
2512 grinder->qmask &= ~(1 << grinder->qpos);
2514 grinder->wrr_mask[grinder->qpos] = 0;
2516 rte_sched_port_red_set_queue_empty_timestamp(port, subport, qindex);
2519 rte_sched_port_pie_dequeue(subport, qindex, pkt_len, port->time_cpu_cycles);
2521 /* Reset pipe loop detection */
2522 subport->pipe_loop = RTE_SCHED_PIPE_INVALID;
2523 grinder->productive = 1;
2529 grinder_pipe_exists(struct rte_sched_subport *subport, uint32_t base_pipe)
2533 for (i = 0; i < RTE_SCHED_PORT_N_GRINDERS; i++) {
2534 if (subport->grinder_base_bmp_pos[i] == base_pipe)
2542 grinder_pcache_populate(struct rte_sched_subport *subport,
2543 uint32_t pos, uint32_t bmp_pos, uint64_t bmp_slab)
2545 struct rte_sched_grinder *grinder = subport->grinder + pos;
2548 grinder->pcache_w = 0;
2549 grinder->pcache_r = 0;
2551 w[0] = (uint16_t) bmp_slab;
2552 w[1] = (uint16_t) (bmp_slab >> 16);
2553 w[2] = (uint16_t) (bmp_slab >> 32);
2554 w[3] = (uint16_t) (bmp_slab >> 48);
2556 grinder->pcache_qmask[grinder->pcache_w] = w[0];
2557 grinder->pcache_qindex[grinder->pcache_w] = bmp_pos;
2558 grinder->pcache_w += (w[0] != 0);
2560 grinder->pcache_qmask[grinder->pcache_w] = w[1];
2561 grinder->pcache_qindex[grinder->pcache_w] = bmp_pos + 16;
2562 grinder->pcache_w += (w[1] != 0);
2564 grinder->pcache_qmask[grinder->pcache_w] = w[2];
2565 grinder->pcache_qindex[grinder->pcache_w] = bmp_pos + 32;
2566 grinder->pcache_w += (w[2] != 0);
2568 grinder->pcache_qmask[grinder->pcache_w] = w[3];
2569 grinder->pcache_qindex[grinder->pcache_w] = bmp_pos + 48;
2570 grinder->pcache_w += (w[3] != 0);
2574 grinder_tccache_populate(struct rte_sched_subport *subport,
2575 uint32_t pos, uint32_t qindex, uint16_t qmask)
2577 struct rte_sched_grinder *grinder = subport->grinder + pos;
2580 grinder->tccache_w = 0;
2581 grinder->tccache_r = 0;
2583 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASS_BE; i++) {
2584 b = (uint8_t) ((qmask >> i) & 0x1);
2585 grinder->tccache_qmask[grinder->tccache_w] = b;
2586 grinder->tccache_qindex[grinder->tccache_w] = qindex + i;
2587 grinder->tccache_w += (b != 0);
2590 b = (uint8_t) (qmask >> (RTE_SCHED_TRAFFIC_CLASS_BE));
2591 grinder->tccache_qmask[grinder->tccache_w] = b;
2592 grinder->tccache_qindex[grinder->tccache_w] = qindex +
2593 RTE_SCHED_TRAFFIC_CLASS_BE;
2594 grinder->tccache_w += (b != 0);
2598 grinder_next_tc(struct rte_sched_port *port,
2599 struct rte_sched_subport *subport, uint32_t pos)
2601 struct rte_sched_grinder *grinder = subport->grinder + pos;
2602 struct rte_mbuf **qbase;
2606 if (grinder->tccache_r == grinder->tccache_w)
2609 qindex = grinder->tccache_qindex[grinder->tccache_r];
2610 qbase = rte_sched_subport_pipe_qbase(subport, qindex);
2611 qsize = rte_sched_subport_pipe_qsize(port, subport, qindex);
2613 grinder->tc_index = rte_sched_port_pipe_tc(port, qindex);
2614 grinder->qmask = grinder->tccache_qmask[grinder->tccache_r];
2615 grinder->qsize = qsize;
2617 if (grinder->tc_index < RTE_SCHED_TRAFFIC_CLASS_BE) {
2618 grinder->queue[0] = subport->queue + qindex;
2619 grinder->qbase[0] = qbase;
2620 grinder->qindex[0] = qindex;
2621 grinder->tccache_r++;
2626 grinder->queue[0] = subport->queue + qindex;
2627 grinder->queue[1] = subport->queue + qindex + 1;
2628 grinder->queue[2] = subport->queue + qindex + 2;
2629 grinder->queue[3] = subport->queue + qindex + 3;
2631 grinder->qbase[0] = qbase;
2632 grinder->qbase[1] = qbase + qsize;
2633 grinder->qbase[2] = qbase + 2 * qsize;
2634 grinder->qbase[3] = qbase + 3 * qsize;
2636 grinder->qindex[0] = qindex;
2637 grinder->qindex[1] = qindex + 1;
2638 grinder->qindex[2] = qindex + 2;
2639 grinder->qindex[3] = qindex + 3;
2641 grinder->tccache_r++;
2646 grinder_next_pipe(struct rte_sched_port *port,
2647 struct rte_sched_subport *subport, uint32_t pos)
2649 struct rte_sched_grinder *grinder = subport->grinder + pos;
2650 uint32_t pipe_qindex;
2651 uint16_t pipe_qmask;
2653 if (grinder->pcache_r < grinder->pcache_w) {
2654 pipe_qmask = grinder->pcache_qmask[grinder->pcache_r];
2655 pipe_qindex = grinder->pcache_qindex[grinder->pcache_r];
2656 grinder->pcache_r++;
2658 uint64_t bmp_slab = 0;
2659 uint32_t bmp_pos = 0;
2661 /* Get another non-empty pipe group */
2662 if (unlikely(rte_bitmap_scan(subport->bmp, &bmp_pos, &bmp_slab) <= 0))
2665 #ifdef RTE_SCHED_DEBUG
2666 debug_check_queue_slab(subport, bmp_pos, bmp_slab);
2669 /* Return if pipe group already in one of the other grinders */
2670 subport->grinder_base_bmp_pos[pos] = RTE_SCHED_BMP_POS_INVALID;
2671 if (unlikely(grinder_pipe_exists(subport, bmp_pos)))
2674 subport->grinder_base_bmp_pos[pos] = bmp_pos;
2676 /* Install new pipe group into grinder's pipe cache */
2677 grinder_pcache_populate(subport, pos, bmp_pos, bmp_slab);
2679 pipe_qmask = grinder->pcache_qmask[0];
2680 pipe_qindex = grinder->pcache_qindex[0];
2681 grinder->pcache_r = 1;
2684 /* Install new pipe in the grinder */
2685 grinder->pindex = pipe_qindex >> 4;
2686 grinder->subport = subport;
2687 grinder->pipe = subport->pipe + grinder->pindex;
2688 grinder->pipe_params = NULL; /* to be set after the pipe structure is prefetched */
2689 grinder->productive = 0;
2691 grinder_tccache_populate(subport, pos, pipe_qindex, pipe_qmask);
2692 grinder_next_tc(port, subport, pos);
2694 /* Check for pipe exhaustion */
2695 if (grinder->pindex == subport->pipe_loop) {
2696 subport->pipe_exhaustion = 1;
2697 subport->pipe_loop = RTE_SCHED_PIPE_INVALID;
2705 grinder_wrr_load(struct rte_sched_subport *subport, uint32_t pos)
2707 struct rte_sched_grinder *grinder = subport->grinder + pos;
2708 struct rte_sched_pipe *pipe = grinder->pipe;
2709 struct rte_sched_pipe_profile *pipe_params = grinder->pipe_params;
2710 uint32_t qmask = grinder->qmask;
2712 grinder->wrr_tokens[0] =
2713 ((uint16_t) pipe->wrr_tokens[0]) << RTE_SCHED_WRR_SHIFT;
2714 grinder->wrr_tokens[1] =
2715 ((uint16_t) pipe->wrr_tokens[1]) << RTE_SCHED_WRR_SHIFT;
2716 grinder->wrr_tokens[2] =
2717 ((uint16_t) pipe->wrr_tokens[2]) << RTE_SCHED_WRR_SHIFT;
2718 grinder->wrr_tokens[3] =
2719 ((uint16_t) pipe->wrr_tokens[3]) << RTE_SCHED_WRR_SHIFT;
2721 grinder->wrr_mask[0] = (qmask & 0x1) * 0xFFFF;
2722 grinder->wrr_mask[1] = ((qmask >> 1) & 0x1) * 0xFFFF;
2723 grinder->wrr_mask[2] = ((qmask >> 2) & 0x1) * 0xFFFF;
2724 grinder->wrr_mask[3] = ((qmask >> 3) & 0x1) * 0xFFFF;
2726 grinder->wrr_cost[0] = pipe_params->wrr_cost[0];
2727 grinder->wrr_cost[1] = pipe_params->wrr_cost[1];
2728 grinder->wrr_cost[2] = pipe_params->wrr_cost[2];
2729 grinder->wrr_cost[3] = pipe_params->wrr_cost[3];
2733 grinder_wrr_store(struct rte_sched_subport *subport, uint32_t pos)
2735 struct rte_sched_grinder *grinder = subport->grinder + pos;
2736 struct rte_sched_pipe *pipe = grinder->pipe;
2738 pipe->wrr_tokens[0] =
2739 (grinder->wrr_tokens[0] & grinder->wrr_mask[0]) >>
2740 RTE_SCHED_WRR_SHIFT;
2741 pipe->wrr_tokens[1] =
2742 (grinder->wrr_tokens[1] & grinder->wrr_mask[1]) >>
2743 RTE_SCHED_WRR_SHIFT;
2744 pipe->wrr_tokens[2] =
2745 (grinder->wrr_tokens[2] & grinder->wrr_mask[2]) >>
2746 RTE_SCHED_WRR_SHIFT;
2747 pipe->wrr_tokens[3] =
2748 (grinder->wrr_tokens[3] & grinder->wrr_mask[3]) >>
2749 RTE_SCHED_WRR_SHIFT;
2753 grinder_wrr(struct rte_sched_subport *subport, uint32_t pos)
2755 struct rte_sched_grinder *grinder = subport->grinder + pos;
2756 uint16_t wrr_tokens_min;
2758 grinder->wrr_tokens[0] |= ~grinder->wrr_mask[0];
2759 grinder->wrr_tokens[1] |= ~grinder->wrr_mask[1];
2760 grinder->wrr_tokens[2] |= ~grinder->wrr_mask[2];
2761 grinder->wrr_tokens[3] |= ~grinder->wrr_mask[3];
2763 grinder->qpos = rte_min_pos_4_u16(grinder->wrr_tokens);
2764 wrr_tokens_min = grinder->wrr_tokens[grinder->qpos];
2766 grinder->wrr_tokens[0] -= wrr_tokens_min;
2767 grinder->wrr_tokens[1] -= wrr_tokens_min;
2768 grinder->wrr_tokens[2] -= wrr_tokens_min;
2769 grinder->wrr_tokens[3] -= wrr_tokens_min;
2773 #define grinder_evict(subport, pos)
2776 grinder_prefetch_pipe(struct rte_sched_subport *subport, uint32_t pos)
2778 struct rte_sched_grinder *grinder = subport->grinder + pos;
2780 rte_prefetch0(grinder->pipe);
2781 rte_prefetch0(grinder->queue[0]);
2785 grinder_prefetch_tc_queue_arrays(struct rte_sched_subport *subport, uint32_t pos)
2787 struct rte_sched_grinder *grinder = subport->grinder + pos;
2788 uint16_t qsize, qr[RTE_SCHED_MAX_QUEUES_PER_TC];
2790 qsize = grinder->qsize;
2793 if (grinder->tc_index < RTE_SCHED_TRAFFIC_CLASS_BE) {
2794 qr[0] = grinder->queue[0]->qr & (qsize - 1);
2796 rte_prefetch0(grinder->qbase[0] + qr[0]);
2800 qr[0] = grinder->queue[0]->qr & (qsize - 1);
2801 qr[1] = grinder->queue[1]->qr & (qsize - 1);
2802 qr[2] = grinder->queue[2]->qr & (qsize - 1);
2803 qr[3] = grinder->queue[3]->qr & (qsize - 1);
2805 rte_prefetch0(grinder->qbase[0] + qr[0]);
2806 rte_prefetch0(grinder->qbase[1] + qr[1]);
2808 grinder_wrr_load(subport, pos);
2809 grinder_wrr(subport, pos);
2811 rte_prefetch0(grinder->qbase[2] + qr[2]);
2812 rte_prefetch0(grinder->qbase[3] + qr[3]);
2816 grinder_prefetch_mbuf(struct rte_sched_subport *subport, uint32_t pos)
2818 struct rte_sched_grinder *grinder = subport->grinder + pos;
2819 uint32_t qpos = grinder->qpos;
2820 struct rte_mbuf **qbase = grinder->qbase[qpos];
2821 uint16_t qsize = grinder->qsize;
2822 uint16_t qr = grinder->queue[qpos]->qr & (qsize - 1);
2824 grinder->pkt = qbase[qr];
2825 rte_prefetch0(grinder->pkt);
2827 if (unlikely((qr & 0x7) == 7)) {
2828 uint16_t qr_next = (grinder->queue[qpos]->qr + 1) & (qsize - 1);
2830 rte_prefetch0(qbase + qr_next);
2834 static inline uint32_t
2835 grinder_handle(struct rte_sched_port *port,
2836 struct rte_sched_subport *subport, uint32_t pos)
2838 struct rte_sched_grinder *grinder = subport->grinder + pos;
2840 switch (grinder->state) {
2841 case e_GRINDER_PREFETCH_PIPE:
2843 if (grinder_next_pipe(port, subport, pos)) {
2844 grinder_prefetch_pipe(subport, pos);
2845 subport->busy_grinders++;
2847 grinder->state = e_GRINDER_PREFETCH_TC_QUEUE_ARRAYS;
2854 case e_GRINDER_PREFETCH_TC_QUEUE_ARRAYS:
2856 struct rte_sched_pipe *pipe = grinder->pipe;
2858 grinder->pipe_params = subport->pipe_profiles + pipe->profile;
2859 grinder->subport_params = port->subport_profiles +
2862 grinder_prefetch_tc_queue_arrays(subport, pos);
2863 grinder_credits_update(port, subport, pos);
2865 grinder->state = e_GRINDER_PREFETCH_MBUF;
2869 case e_GRINDER_PREFETCH_MBUF:
2871 grinder_prefetch_mbuf(subport, pos);
2873 grinder->state = e_GRINDER_READ_MBUF;
2877 case e_GRINDER_READ_MBUF:
2879 uint32_t wrr_active, result = 0;
2881 result = grinder_schedule(port, subport, pos);
2883 wrr_active = (grinder->tc_index == RTE_SCHED_TRAFFIC_CLASS_BE);
2885 /* Look for next packet within the same TC */
2886 if (result && grinder->qmask) {
2888 grinder_wrr(subport, pos);
2890 grinder_prefetch_mbuf(subport, pos);
2896 grinder_wrr_store(subport, pos);
2898 /* Look for another active TC within same pipe */
2899 if (grinder_next_tc(port, subport, pos)) {
2900 grinder_prefetch_tc_queue_arrays(subport, pos);
2902 grinder->state = e_GRINDER_PREFETCH_MBUF;
2906 if (grinder->productive == 0 &&
2907 subport->pipe_loop == RTE_SCHED_PIPE_INVALID)
2908 subport->pipe_loop = grinder->pindex;
2910 grinder_evict(subport, pos);
2912 /* Look for another active pipe */
2913 if (grinder_next_pipe(port, subport, pos)) {
2914 grinder_prefetch_pipe(subport, pos);
2916 grinder->state = e_GRINDER_PREFETCH_TC_QUEUE_ARRAYS;
2920 /* No active pipe found */
2921 subport->busy_grinders--;
2923 grinder->state = e_GRINDER_PREFETCH_PIPE;
2928 rte_panic("Algorithmic error (invalid state)\n");
2934 rte_sched_port_time_resync(struct rte_sched_port *port)
2936 uint64_t cycles = rte_get_tsc_cycles();
2937 uint64_t cycles_diff;
2938 uint64_t bytes_diff;
2941 if (cycles < port->time_cpu_cycles)
2942 port->time_cpu_cycles = 0;
2944 cycles_diff = cycles - port->time_cpu_cycles;
2945 /* Compute elapsed time in bytes */
2946 bytes_diff = rte_reciprocal_divide(cycles_diff << RTE_SCHED_TIME_SHIFT,
2947 port->inv_cycles_per_byte);
2949 /* Advance port time */
2950 port->time_cpu_cycles +=
2951 (bytes_diff * port->cycles_per_byte) >> RTE_SCHED_TIME_SHIFT;
2952 port->time_cpu_bytes += bytes_diff;
2953 if (port->time < port->time_cpu_bytes)
2954 port->time = port->time_cpu_bytes;
2956 /* Reset pipe loop detection */
2957 for (i = 0; i < port->n_subports_per_port; i++)
2958 port->subports[i]->pipe_loop = RTE_SCHED_PIPE_INVALID;
2962 rte_sched_port_exceptions(struct rte_sched_subport *subport, int second_pass)
2966 /* Check if any exception flag is set */
2967 exceptions = (second_pass && subport->busy_grinders == 0) ||
2968 (subport->pipe_exhaustion == 1);
2970 /* Clear exception flags */
2971 subport->pipe_exhaustion = 0;
2977 rte_sched_port_dequeue(struct rte_sched_port *port, struct rte_mbuf **pkts, uint32_t n_pkts)
2979 struct rte_sched_subport *subport;
2980 uint32_t subport_id = port->subport_id;
2981 uint32_t i, n_subports = 0, count;
2983 port->pkts_out = pkts;
2984 port->n_pkts_out = 0;
2986 rte_sched_port_time_resync(port);
2988 /* Take each queue in the grinder one step further */
2989 for (i = 0, count = 0; ; i++) {
2990 subport = port->subports[subport_id];
2992 count += grinder_handle(port, subport,
2993 i & (RTE_SCHED_PORT_N_GRINDERS - 1));
2995 if (count == n_pkts) {
2998 if (subport_id == port->n_subports_per_port)
3001 port->subport_id = subport_id;
3005 if (rte_sched_port_exceptions(subport, i >= RTE_SCHED_PORT_N_GRINDERS)) {
3011 if (subport_id == port->n_subports_per_port)
3014 if (n_subports == port->n_subports_per_port) {
3015 port->subport_id = subport_id;