2 * Copyright (c) 2010 Fabio Checconi, Luigi Rizzo, Paolo Valente
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * $Id: dn_sched_qfq.c 5621 2010-03-04 16:51:27Z luigi $
32 #include <sys/malloc.h>
33 #include <sys/socket.h>
34 #include <sys/socketvar.h>
35 #include <sys/kernel.h>
37 #include <sys/module.h>
38 #include <net/if.h> /* IFNAMSIZ */
39 #include <netinet/in.h>
40 #include <netinet/ip_var.h> /* ipfw_rule_ref */
41 #include <netinet/ip_fw.h> /* flow_id */
42 #include <netinet/ip_dummynet.h>
43 #include <netinet/ipfw/dn_heap.h>
44 #include <netinet/ipfw/ip_dn_private.h>
45 #include <netinet/ipfw/dn_sched.h>
52 static void dump_sched(struct qfq_sched *q, const char *msg);
57 #define DN_SCHED_QFQ 4 // XXX Where?
58 typedef unsigned long bitmap;
61 * bitmaps ops are critical. Some linux versions have __fls
62 * and the bitmap ops. Some machines have ffs
65 int fls(unsigned int n)
68 for (i = 0; n > 0; n >>= 1, i++)
74 #if !defined(_KERNEL) || defined( __FreeBSD__ ) || defined(_WIN32)
75 static inline unsigned long __fls(unsigned long word)
81 #if !defined(_KERNEL) || !defined(__linux__)
83 int test_bit(int ix, bitmap *p)
85 if (ix < 0 || ix > 31)
86 D("bad index %d", ix);
89 void __set_bit(int ix, bitmap *p)
91 if (ix < 0 || ix > 31)
92 D("bad index %d", ix);
95 void __clear_bit(int ix, bitmap *p)
97 if (ix < 0 || ix > 31)
98 D("bad index %d", ix);
101 #else /* !QFQ_DEBUG */
102 /* XXX do we have fast version, or leave it to the compiler ? */
103 #define test_bit(ix, pData) ((*pData) & (1<<(ix)))
104 #define __set_bit(ix, pData) (*pData) |= (1<<(ix))
105 #define __clear_bit(ix, pData) (*pData) &= ~(1<<(ix))
106 #endif /* !QFQ_DEBUG */
107 #endif /* !__linux__ */
110 #define __clear_bit(ix, pData) (*pData) &= ~(1<<(ix))
113 /*-------------------------------------------*/
116 Virtual time computations.
118 S, F and V are all computed in fixed point arithmetic with
119 FRAC_BITS decimal bits.
121 QFQ_MAX_INDEX is the maximum index allowed for a group. We need
123 QFQ_MAX_WSHIFT is the maximum power of two supported as a weight.
124 The layout of the bits is as below:
126 [ MTU_SHIFT ][ FRAC_BITS ]
127 [ MAX_INDEX ][ MIN_SLOT_SHIFT ]
131 where MIN_SLOT_SHIFT is derived by difference from the others.
133 The max group index corresponds to Lmax/w_min, where
134 Lmax=1<<MTU_SHIFT, w_min = 1 .
135 From this, and knowing how many groups (MAX_INDEX) we want,
136 we can derive the shift corresponding to each group.
138 Because we often need to compute
139 F = S + len/w_i and V = V + len/wsum
140 instead of storing w_i store the value
141 inv_w = (1<<FRAC_BITS)/w_i
142 so we can do F = S + len * inv_w * wsum.
143 We use W_TOT in the formulas so we can easily move between
144 static and adaptive weight sum.
146 The per-scheduler-instance data contain all the data structures
147 for the scheduler: bitmaps and bucket lists.
151 * Maximum number of consecutive slots occupied by backlogged classes
152 * inside a group. This is approx lmax/lmin + 5.
153 * XXX check because it poses constraints on MAX_INDEX
155 #define QFQ_MAX_SLOTS 32
157 * Shifts used for class<->group mapping. Class weights are
158 * in the range [1, QFQ_MAX_WEIGHT], we to map each class i to the
159 * group with the smallest index that can support the L_i / r_i
160 * configured for the class.
162 * grp->index is the index of the group; and grp->slot_shift
163 * is the shift for the corresponding (scaled) sigma_i.
165 * When computing the group index, we do (len<<FP_SHIFT)/weight,
166 * then compute an FLS (which is like a log2()), and if the result
167 * is below the MAX_INDEX region we use 0 (which is the same as
168 * using a larger len).
170 #define QFQ_MAX_INDEX 19
171 #define QFQ_MAX_WSHIFT 16 /* log2(max_weight) */
173 #define QFQ_MAX_WEIGHT (1<<QFQ_MAX_WSHIFT)
174 #define QFQ_MAX_WSUM (2*QFQ_MAX_WEIGHT)
175 //#define IWSUM (q->i_wsum)
176 #define IWSUM ((1<<FRAC_BITS)/QFQ_MAX_WSUM)
178 #define FRAC_BITS 30 /* fixed point arithmetic */
179 #define ONE_FP (1UL << FRAC_BITS)
181 #define QFQ_MTU_SHIFT 11 /* log2(max_len) */
182 #define QFQ_MIN_SLOT_SHIFT (FRAC_BITS + QFQ_MTU_SHIFT - QFQ_MAX_INDEX)
185 * Possible group states, also indexes for the bitmaps array in
186 * struct qfq_queue. We rely on ER, IR, EB, IB being numbered 0..3
188 enum qfq_state { ER, IR, EB, IB, QFQ_MAX_STATE };
192 * additional queue info. Some of this info should come from
193 * the flowset, we copy them here for faster processing.
194 * This is an overlay of the struct dn_queue
198 uint64_t S, F; /* flow timestamps (exact) */
199 struct qfq_class *next; /* Link for the slot list. */
201 /* group we belong to. In principle we would need the index,
202 * which is log_2(lmax/weight), but we never reference it
203 * directly, only the group.
205 struct qfq_group *grp;
207 /* these are copied from the flowset. */
208 uint32_t inv_w; /* ONE_FP/weight */
209 uint32_t lmax; /* Max packet size for this flow. */
212 /* Group descriptor, see the paper for details.
213 * Basically this contains the bucket lists
216 uint64_t S, F; /* group timestamps (approx). */
217 unsigned int slot_shift; /* Slot shift. */
218 unsigned int index; /* Group index. */
219 unsigned int front; /* Index of the front slot. */
220 bitmap full_slots; /* non-empty slots */
222 /* Array of lists of active classes. */
223 struct qfq_class *slots[QFQ_MAX_SLOTS];
226 /* scheduler instance descriptor. */
228 uint64_t V; /* Precise virtual time. */
229 uint32_t wsum; /* weight sum */
230 NO(uint32_t i_wsum; /* ONE_FP/w_sum */
231 uint32_t _queued; /* debugging */
232 uint32_t loops; /* debugging */)
233 bitmap bitmaps[QFQ_MAX_STATE]; /* Group bitmaps. */
234 struct qfq_group groups[QFQ_MAX_INDEX + 1]; /* The groups. */
237 /*---- support functions ----------------------------*/
239 /* Generic comparison function, handling wraparound. */
240 static inline int qfq_gt(uint64_t a, uint64_t b)
242 return (int64_t)(a - b) > 0;
245 /* Round a precise timestamp to its slotted value. */
246 static inline uint64_t qfq_round_down(uint64_t ts, unsigned int shift)
248 return ts & ~((1ULL << shift) - 1);
251 /* return the pointer to the group with lowest index in the bitmap */
252 static inline struct qfq_group *qfq_ffs(struct qfq_sched *q,
253 unsigned long bitmap)
255 int index = ffs(bitmap) - 1; // zero-based
256 return &q->groups[index];
260 * Calculate a flow index, given its weight and maximum packet length.
261 * index = log_2(maxlen/weight) but we need to apply the scaling.
262 * This is used only once at flow creation.
264 static int qfq_calc_index(uint32_t inv_w, unsigned int maxlen)
266 uint64_t slot_size = (uint64_t)maxlen *inv_w;
267 unsigned long size_map;
270 size_map = (unsigned long)(slot_size >> QFQ_MIN_SLOT_SHIFT);
274 index = __fls(size_map) + 1; // basically a log_2()
275 index -= !(slot_size - (1ULL << (index + QFQ_MIN_SLOT_SHIFT - 1)));
281 ND("W = %d, L = %d, I = %d\n", ONE_FP/inv_w, maxlen, index);
284 /*---- end support functions ----*/
286 /*-------- API calls --------------------------------*/
288 * Validate and copy parameters from flowset.
291 qfq_new_queue(struct dn_queue *_q)
293 struct qfq_sched *q = (struct qfq_sched *)(_q->_si + 1);
294 struct qfq_class *cl = (struct qfq_class *)_q;
296 uint32_t w; /* approximated weight */
298 /* import parameters from the flowset. They should be correct
301 w = _q->fs->fs.par[0];
302 cl->lmax = _q->fs->fs.par[1];
303 if (!w || w > QFQ_MAX_WEIGHT) {
305 D("rounding weight to 1");
307 cl->inv_w = ONE_FP/w;
308 w = ONE_FP/cl->inv_w;
309 if (q->wsum + w > QFQ_MAX_WSUM)
312 i = qfq_calc_index(cl->inv_w, cl->lmax);
313 cl->grp = &q->groups[i];
315 // XXX cl->S = q->V; ?
316 // XXX compute q->i_wsum
320 /* remove an empty queue */
322 qfq_free_queue(struct dn_queue *_q)
324 struct qfq_sched *q = (struct qfq_sched *)(_q->_si + 1);
325 struct qfq_class *cl = (struct qfq_class *)_q;
327 q->wsum -= ONE_FP/cl->inv_w;
328 cl->inv_w = 0; /* reset weight to avoid run twice */
333 /* Calculate a mask to mimic what would be ffs_from(). */
334 static inline unsigned long
335 mask_from(unsigned long bitmap, int from)
337 return bitmap & ~((1UL << from) - 1);
341 * The state computation relies on ER=0, IR=1, EB=2, IB=3
342 * First compute eligibility comparing grp->S, q->V,
343 * then check if someone is blocking us and possibly add EB
345 static inline unsigned int
346 qfq_calc_state(struct qfq_sched *q, struct qfq_group *grp)
348 /* if S > V we are not eligible */
349 unsigned int state = qfq_gt(grp->S, q->V);
350 unsigned long mask = mask_from(q->bitmaps[ER], grp->index);
351 struct qfq_group *next;
354 next = qfq_ffs(q, mask);
355 if (qfq_gt(grp->F, next->F))
364 * q->bitmaps[dst] |= q->bitmaps[src] & mask;
365 * q->bitmaps[src] &= ~mask;
366 * but we should make sure that src != dst
369 qfq_move_groups(struct qfq_sched *q, unsigned long mask, int src, int dst)
371 q->bitmaps[dst] |= q->bitmaps[src] & mask;
372 q->bitmaps[src] &= ~mask;
376 qfq_unblock_groups(struct qfq_sched *q, int index, uint64_t old_finish)
378 unsigned long mask = mask_from(q->bitmaps[ER], index + 1);
379 struct qfq_group *next;
382 next = qfq_ffs(q, mask);
383 if (!qfq_gt(next->F, old_finish))
387 mask = (1UL << index) - 1;
388 qfq_move_groups(q, mask, EB, ER);
389 qfq_move_groups(q, mask, IB, IR);
396 old_V >>= QFQ_MIN_SLOT_SHIFT;
403 qfq_make_eligible(struct qfq_sched *q, uint64_t old_V)
405 unsigned long mask, vslot, old_vslot;
407 vslot = q->V >> QFQ_MIN_SLOT_SHIFT;
408 old_vslot = old_V >> QFQ_MIN_SLOT_SHIFT;
410 if (vslot != old_vslot) {
411 mask = (2UL << (__fls(vslot ^ old_vslot))) - 1;
412 qfq_move_groups(q, mask, IR, ER);
413 qfq_move_groups(q, mask, IB, EB);
418 * XXX we should make sure that slot becomes less than 32.
419 * This is guaranteed by the input values.
420 * roundedS is always cl->S rounded on grp->slot_shift bits.
423 qfq_slot_insert(struct qfq_group *grp, struct qfq_class *cl, uint64_t roundedS)
425 uint64_t slot = (roundedS - grp->S) >> grp->slot_shift;
426 unsigned int i = (grp->front + slot) % QFQ_MAX_SLOTS;
428 cl->next = grp->slots[i];
430 __set_bit(slot, &grp->full_slots);
434 * remove the entry from the slot
437 qfq_front_slot_remove(struct qfq_group *grp)
439 struct qfq_class **h = &grp->slots[grp->front];
443 __clear_bit(0, &grp->full_slots);
447 * Returns the first full queue in a group. As a side effect,
448 * adjust the bucket list so the first non-empty bucket is at
449 * position 0 in full_slots.
451 static inline struct qfq_class *
452 qfq_slot_scan(struct qfq_group *grp)
456 ND("grp %d full %x", grp->index, grp->full_slots);
457 if (!grp->full_slots)
460 i = ffs(grp->full_slots) - 1; // zero-based
462 grp->front = (grp->front + i) % QFQ_MAX_SLOTS;
463 grp->full_slots >>= i;
466 return grp->slots[grp->front];
470 * adjust the bucket list. When the start time of a group decreases,
471 * we move the index down (modulo QFQ_MAX_SLOTS) so we don't need to
472 * move the objects. The mask of occupied slots must be shifted
473 * because we use ffs() to find the first non-empty slot.
474 * This covers decreases in the group's start time, but what about
475 * increases of the start time ?
476 * Here too we should make sure that i is less than 32
479 qfq_slot_rotate(struct qfq_sched *q, struct qfq_group *grp, uint64_t roundedS)
481 unsigned int i = (grp->S - roundedS) >> grp->slot_shift;
483 grp->full_slots <<= i;
484 grp->front = (grp->front - i) % QFQ_MAX_SLOTS;
489 qfq_update_eligible(struct qfq_sched *q, uint64_t old_V)
493 ineligible = q->bitmaps[IR] | q->bitmaps[IB];
495 if (!q->bitmaps[ER]) {
496 struct qfq_group *grp;
497 grp = qfq_ffs(q, ineligible);
498 if (qfq_gt(grp->S, q->V))
501 qfq_make_eligible(q, old_V);
506 * Updates the class, returns true if also the group needs to be updated.
509 qfq_update_class(struct qfq_sched *q, struct qfq_group *grp,
510 struct qfq_class *cl)
514 if (cl->_q.mq.head == NULL) {
515 qfq_front_slot_remove(grp);
520 len = cl->_q.mq.head->m_pkthdr.len;
521 cl->F = cl->S + (uint64_t)len * cl->inv_w;
522 roundedS = qfq_round_down(cl->S, grp->slot_shift);
523 if (roundedS == grp->S)
526 qfq_front_slot_remove(grp);
527 qfq_slot_insert(grp, cl, roundedS);
533 qfq_dequeue(struct dn_sch_inst *si)
535 struct qfq_sched *q = (struct qfq_sched *)(si + 1);
536 struct qfq_group *grp;
537 struct qfq_class *cl;
542 if (!q->bitmaps[ER]) {
544 dump_sched(q, "start dequeue");)
548 grp = qfq_ffs(q, q->bitmaps[ER]);
550 cl = grp->slots[grp->front];
551 /* extract from the first bucket in the bucket list */
552 m = dn_dequeue(&cl->_q);
555 D("BUG/* non-workconserving leaf */");
560 q->V += (uint64_t)m->m_pkthdr.len * IWSUM;
561 ND("m is %p F 0x%llx V now 0x%llx", m, cl->F, q->V);
563 if (qfq_update_class(q, grp, cl)) {
564 uint64_t old_F = grp->F;
565 cl = qfq_slot_scan(grp);
566 if (!cl) { /* group gone, remove from ER */
567 __clear_bit(grp->index, &q->bitmaps[ER]);
568 // grp->S = grp->F + 1; // XXX debugging only
570 uint64_t roundedS = qfq_round_down(cl->S, grp->slot_shift);
573 if (grp->S == roundedS)
576 grp->F = roundedS + (2ULL << grp->slot_shift);
577 /* remove from ER and put in the new set */
578 __clear_bit(grp->index, &q->bitmaps[ER]);
579 s = qfq_calc_state(q, grp);
580 __set_bit(grp->index, &q->bitmaps[s]);
582 /* we need to unblock even if the group has gone away */
583 qfq_unblock_groups(q, grp->index, old_F);
587 qfq_update_eligible(q, old_V);
588 NO(if (!q->bitmaps[ER] && q->queued)
589 dump_sched(q, "end dequeue");)
595 * Assign a reasonable start time for a new flow k in group i.
596 * Admissible values for \hat(F) are multiples of \sigma_i
597 * no greater than V+\sigma_i . Larger values mean that
598 * we had a wraparound so we consider the timestamp to be stale.
600 * If F is not stale and F >= V then we set S = F.
601 * Otherwise we should assign S = V, but this may violate
602 * the ordering in ER. So, if we have groups in ER, set S to
603 * the F_j of the first group j which would be blocking us.
604 * We are guaranteed not to move S backward because
605 * otherwise our group i would still be blocked.
608 qfq_update_start(struct qfq_sched *q, struct qfq_class *cl)
611 uint32_t limit, roundedF;
612 int slot_shift = cl->grp->slot_shift;
614 roundedF = qfq_round_down(cl->F, slot_shift);
615 limit = qfq_round_down(q->V, slot_shift) + (1UL << slot_shift);
617 if (!qfq_gt(cl->F, q->V) || qfq_gt(roundedF, limit)) {
618 /* timestamp was stale */
619 mask = mask_from(q->bitmaps[ER], cl->grp->index);
621 struct qfq_group *next = qfq_ffs(q, mask);
622 if (qfq_gt(roundedF, next->F)) {
628 } else { /* timestamp is not stale */
634 qfq_enqueue(struct dn_sch_inst *si, struct dn_queue *_q, struct mbuf *m)
636 struct qfq_sched *q = (struct qfq_sched *)(si + 1);
637 struct qfq_group *grp;
638 struct qfq_class *cl = (struct qfq_class *)_q;
643 DX(4, "len %d flow %p inv_w 0x%x grp %d", m->m_pkthdr.len,
644 _q, cl->inv_w, cl->grp->index);
645 /* XXX verify that the packet obeys the parameters */
646 if (m != _q->mq.head) {
647 if (dn_enqueue(_q, m, 0)) /* packet was dropped */
650 if (m != _q->mq.head)
653 /* If reach this point, queue q was idle */
655 qfq_update_start(q, cl); /* adjust start time */
656 /* compute new finish time and rounded start. */
657 cl->F = cl->S + (uint64_t)(m->m_pkthdr.len) * cl->inv_w;
658 roundedS = qfq_round_down(cl->S, grp->slot_shift);
661 * insert cl in the correct bucket.
662 * If cl->S >= grp->S we don't need to adjust the
663 * bucket list and simply go to the insertion phase.
664 * Otherwise grp->S is decreasing, we must make room
665 * in the bucket list, and also recompute the group state.
666 * Finally, if there were no flows in this group and nobody
667 * was in ER make sure to adjust V.
669 if (grp->full_slots) {
670 if (!qfq_gt(grp->S, cl->S))
672 /* create a slot for this cl->S */
673 qfq_slot_rotate(q, grp, roundedS);
674 /* group was surely ineligible, remove */
675 __clear_bit(grp->index, &q->bitmaps[IR]);
676 __clear_bit(grp->index, &q->bitmaps[IB]);
677 } else if (!q->bitmaps[ER] && qfq_gt(roundedS, q->V))
681 grp->F = roundedS + (2ULL << grp->slot_shift); // i.e. 2\sigma_i
682 s = qfq_calc_state(q, grp);
683 __set_bit(grp->index, &q->bitmaps[s]);
684 ND("new state %d 0x%x", s, q->bitmaps[s]);
685 ND("S %llx F %llx V %llx", cl->S, cl->F, q->V);
687 qfq_slot_insert(grp, cl, roundedS);
695 qfq_slot_remove(struct qfq_sched *q, struct qfq_group *grp,
696 struct qfq_class *cl, struct qfq_class **pprev)
698 unsigned int i, offset;
701 roundedS = qfq_round_down(cl->S, grp->slot_shift);
702 offset = (roundedS - grp->S) >> grp->slot_shift;
703 i = (grp->front + offset) % QFQ_MAX_SLOTS;
707 pprev = &grp->slots[i];
708 while (*pprev && *pprev != cl)
709 pprev = &(*pprev)->next;
715 __clear_bit(offset, &grp->full_slots);
719 * called to forcibly destroy a queue.
720 * If the queue is not in the front bucket, or if it has
721 * other queues in the front bucket, we can simply remove
722 * the queue with no other side effects.
723 * Otherwise we must propagate the event up.
724 * XXX description to be completed.
727 qfq_deactivate_class(struct qfq_sched *q, struct qfq_class *cl,
728 struct qfq_class **pprev)
730 struct qfq_group *grp = &q->groups[cl->index];
735 cl->F = cl->S; // not needed if the class goes away.
736 qfq_slot_remove(q, grp, cl, pprev);
738 if (!grp->full_slots) {
739 /* nothing left in the group, remove from all sets.
740 * Do ER last because if we were blocking other groups
741 * we must unblock them.
743 __clear_bit(grp->index, &q->bitmaps[IR]);
744 __clear_bit(grp->index, &q->bitmaps[EB]);
745 __clear_bit(grp->index, &q->bitmaps[IB]);
747 if (test_bit(grp->index, &q->bitmaps[ER]) &&
748 !(q->bitmaps[ER] & ~((1UL << grp->index) - 1))) {
749 mask = q->bitmaps[ER] & ((1UL << grp->index) - 1);
751 mask = ~((1UL << __fls(mask)) - 1);
754 qfq_move_groups(q, mask, EB, ER);
755 qfq_move_groups(q, mask, IB, IR);
757 __clear_bit(grp->index, &q->bitmaps[ER]);
758 } else if (!grp->slots[grp->front]) {
759 cl = qfq_slot_scan(grp);
760 roundedS = qfq_round_down(cl->S, grp->slot_shift);
761 if (grp->S != roundedS) {
762 __clear_bit(grp->index, &q->bitmaps[ER]);
763 __clear_bit(grp->index, &q->bitmaps[IR]);
764 __clear_bit(grp->index, &q->bitmaps[EB]);
765 __clear_bit(grp->index, &q->bitmaps[IB]);
767 grp->F = roundedS + (2ULL << grp->slot_shift);
768 s = qfq_calc_state(q, grp);
769 __set_bit(grp->index, &q->bitmaps[s]);
772 qfq_update_eligible(q, q->V);
777 qfq_new_fsk(struct dn_fsk *f)
779 ipdn_bound_var(&f->fs.par[0], 1, 1, QFQ_MAX_WEIGHT, "qfq weight");
780 ipdn_bound_var(&f->fs.par[1], 1500, 1, 2000, "qfq maxlen");
781 ND("weight %d len %d\n", f->fs.par[0], f->fs.par[1]);
786 * initialize a new scheduler instance
789 qfq_new_sched(struct dn_sch_inst *si)
791 struct qfq_sched *q = (struct qfq_sched *)(si + 1);
792 struct qfq_group *grp;
795 for (i = 0; i <= QFQ_MAX_INDEX; i++) {
798 grp->slot_shift = QFQ_MTU_SHIFT + FRAC_BITS -
805 * QFQ scheduler descriptor
807 static struct dn_alg qfq_desc = {
808 _SI( .type = ) DN_SCHED_QFQ,
809 _SI( .name = ) "QFQ",
810 _SI( .flags = ) DN_MULTIQUEUE,
812 _SI( .schk_datalen = ) 0,
813 _SI( .si_datalen = ) sizeof(struct qfq_sched),
814 _SI( .q_datalen = ) sizeof(struct qfq_class) - sizeof(struct dn_queue),
816 _SI( .enqueue = ) qfq_enqueue,
817 _SI( .dequeue = ) qfq_dequeue,
819 _SI( .config = ) NULL,
820 _SI( .destroy = ) NULL,
821 _SI( .new_sched = ) qfq_new_sched,
822 _SI( .free_sched = ) NULL,
823 _SI( .new_fsk = ) qfq_new_fsk,
824 _SI( .free_fsk = ) NULL,
825 _SI( .new_queue = ) qfq_new_queue,
826 _SI( .free_queue = ) qfq_free_queue,
829 DECLARE_DNSCHED_MODULE(dn_qfq, &qfq_desc);
833 dump_groups(struct qfq_sched *q, uint32_t mask)
837 for (i = 0; i < QFQ_MAX_INDEX + 1; i++) {
838 struct qfq_group *g = &q->groups[i];
840 if (0 == (mask & (1<<i)))
842 for (j = 0; j < QFQ_MAX_SLOTS; j++) {
844 D(" bucket %d %p", j, g->slots[j]);
846 D("full_slots 0x%x", g->full_slots);
847 D(" %2d S 0x%20llx F 0x%llx %c", i,
849 mask & (1<<i) ? '1' : '0');
854 dump_sched(struct qfq_sched *q, const char *msg)
856 D("--- in %s: ---", msg);
857 ND("loops %d queued %d V 0x%llx", q->loops, q->queued, q->V);
858 D(" ER 0x%08x", q->bitmaps[ER]);
859 D(" EB 0x%08x", q->bitmaps[EB]);
860 D(" IR 0x%08x", q->bitmaps[IR]);
861 D(" IB 0x%08x", q->bitmaps[IB]);
862 dump_groups(q, 0xffffffff);
864 #endif /* QFQ_DEBUG */