^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Copyright (c) 2003 Patrick McHardy, <kaber@trash.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * This program is free software; you can redistribute it and/or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * modify it under the terms of the GNU General Public License
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * as published by the Free Software Foundation; either version 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * of the License, or (at your option) any later version.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * 2003-10-17 - Ported from altq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Copyright (c) 1997-1999 Carnegie Mellon University. All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Permission to use, copy, modify, and distribute this software and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * its documentation is hereby granted (including for commercial or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * for-profit use), provided that both the copyright notice and this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * permission notice appear in all copies of the software, derivative
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * works, or modified versions, and any portions thereof.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * THIS SOFTWARE IS EXPERIMENTAL AND IS KNOWN TO HAVE BUGS, SOME OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON PROVIDES THIS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * SOFTWARE IN ITS ``AS IS'' CONDITION, AND ANY EXPRESS OR IMPLIED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * DAMAGE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * Carnegie Mellon encourages (but does not require) users of this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * software to return any improvements or extensions that they make,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * and to grant Carnegie Mellon the rights to redistribute these
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * changes without encumbrance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * H-FSC is described in Proceedings of SIGCOMM'97,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * "A Hierarchical Fair Service Curve Algorithm for Link-Sharing,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * Real-Time and Priority Service"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * by Ion Stoica, Hui Zhang, and T. S. Eugene Ng.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * Oleg Cherevko <olwi@aq.ml.com.ua> added the upperlimit for link-sharing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * when a class has an upperlimit, the fit-time is computed from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * upperlimit service curve. the link-sharing scheduler does not schedule
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * a class whose fit-time exceeds the current time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #include <linux/compiler.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #include <linux/rbtree.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #include <linux/rtnetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #include <linux/pkt_sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #include <net/netlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #include <net/pkt_sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #include <net/pkt_cls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) #include <asm/div64.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * kernel internal service curve representation:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * coordinates are given by 64 bit unsigned integers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * x-axis: unit is clock count.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * y-axis: unit is byte.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * The service curve parameters are converted to the internal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * representation. The slope values are scaled to avoid overflow.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * the inverse slope values as well as the y-projection of the 1st
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * segment are kept in order to avoid 64-bit divide operations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * that are expensive on 32-bit architectures.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) struct internal_sc {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) u64 sm1; /* scaled slope of the 1st segment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) u64 ism1; /* scaled inverse-slope of the 1st segment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) u64 dx; /* the x-projection of the 1st segment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) u64 dy; /* the y-projection of the 1st segment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) u64 sm2; /* scaled slope of the 2nd segment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) u64 ism2; /* scaled inverse-slope of the 2nd segment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) /* runtime service curve */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct runtime_sc {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) u64 x; /* current starting position on x-axis */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) u64 y; /* current starting position on y-axis */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) u64 sm1; /* scaled slope of the 1st segment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) u64 ism1; /* scaled inverse-slope of the 1st segment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) u64 dx; /* the x-projection of the 1st segment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) u64 dy; /* the y-projection of the 1st segment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) u64 sm2; /* scaled slope of the 2nd segment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) u64 ism2; /* scaled inverse-slope of the 2nd segment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) enum hfsc_class_flags {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) HFSC_RSC = 0x1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) HFSC_FSC = 0x2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) HFSC_USC = 0x4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct hfsc_class {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct Qdisc_class_common cl_common;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) struct gnet_stats_basic_packed bstats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct gnet_stats_queue qstats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) struct net_rate_estimator __rcu *rate_est;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) struct tcf_proto __rcu *filter_list; /* filter list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct tcf_block *block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) unsigned int filter_cnt; /* filter count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) unsigned int level; /* class level in hierarchy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) struct hfsc_sched *sched; /* scheduler data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) struct hfsc_class *cl_parent; /* parent class */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) struct list_head siblings; /* sibling classes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct list_head children; /* child classes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) struct Qdisc *qdisc; /* leaf qdisc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct rb_node el_node; /* qdisc's eligible tree member */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) struct rb_root vt_tree; /* active children sorted by cl_vt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) struct rb_node vt_node; /* parent's vt_tree member */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) struct rb_root cf_tree; /* active children sorted by cl_f */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) struct rb_node cf_node; /* parent's cf_heap member */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) u64 cl_total; /* total work in bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) u64 cl_cumul; /* cumulative work in bytes done by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) real-time criteria */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) u64 cl_d; /* deadline*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) u64 cl_e; /* eligible time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) u64 cl_vt; /* virtual time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) u64 cl_f; /* time when this class will fit for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) link-sharing, max(myf, cfmin) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) u64 cl_myf; /* my fit-time (calculated from this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) class's own upperlimit curve) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) u64 cl_cfmin; /* earliest children's fit-time (used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) with cl_myf to obtain cl_f) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) u64 cl_cvtmin; /* minimal virtual time among the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) children fit for link-sharing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) (monotonic within a period) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) u64 cl_vtadj; /* intra-period cumulative vt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) adjustment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) u64 cl_cvtoff; /* largest virtual time seen among
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) the children */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) struct internal_sc cl_rsc; /* internal real-time service curve */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) struct internal_sc cl_fsc; /* internal fair service curve */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) struct internal_sc cl_usc; /* internal upperlimit service curve */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) struct runtime_sc cl_deadline; /* deadline curve */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) struct runtime_sc cl_eligible; /* eligible curve */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) struct runtime_sc cl_virtual; /* virtual curve */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) struct runtime_sc cl_ulimit; /* upperlimit curve */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) u8 cl_flags; /* which curves are valid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) u32 cl_vtperiod; /* vt period sequence number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) u32 cl_parentperiod;/* parent's vt period sequence number*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) u32 cl_nactive; /* number of active children */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) struct hfsc_sched {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) u16 defcls; /* default class id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) struct hfsc_class root; /* root class */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) struct Qdisc_class_hash clhash; /* class hash */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) struct rb_root eligible; /* eligible tree */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) struct qdisc_watchdog watchdog; /* watchdog timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) #define HT_INFINITY 0xffffffffffffffffULL /* infinite time value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) * eligible tree holds backlogged classes being sorted by their eligible times.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) * there is one eligible tree per hfsc instance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) eltree_insert(struct hfsc_class *cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) struct rb_node **p = &cl->sched->eligible.rb_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) struct rb_node *parent = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) struct hfsc_class *cl1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) while (*p != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) parent = *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) cl1 = rb_entry(parent, struct hfsc_class, el_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) if (cl->cl_e >= cl1->cl_e)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) p = &parent->rb_right;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) p = &parent->rb_left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) rb_link_node(&cl->el_node, parent, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) rb_insert_color(&cl->el_node, &cl->sched->eligible);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) eltree_remove(struct hfsc_class *cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) rb_erase(&cl->el_node, &cl->sched->eligible);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) eltree_update(struct hfsc_class *cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) eltree_remove(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) eltree_insert(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) /* find the class with the minimum deadline among the eligible classes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) static inline struct hfsc_class *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) eltree_get_mindl(struct hfsc_sched *q, u64 cur_time)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) struct hfsc_class *p, *cl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) struct rb_node *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) for (n = rb_first(&q->eligible); n != NULL; n = rb_next(n)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) p = rb_entry(n, struct hfsc_class, el_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) if (p->cl_e > cur_time)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) if (cl == NULL || p->cl_d < cl->cl_d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) cl = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) return cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) /* find the class with minimum eligible time among the eligible classes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) static inline struct hfsc_class *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) eltree_get_minel(struct hfsc_sched *q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) struct rb_node *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) n = rb_first(&q->eligible);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) if (n == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) return rb_entry(n, struct hfsc_class, el_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) * vttree holds holds backlogged child classes being sorted by their virtual
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) * time. each intermediate class has one vttree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) vttree_insert(struct hfsc_class *cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) struct rb_node **p = &cl->cl_parent->vt_tree.rb_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) struct rb_node *parent = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) struct hfsc_class *cl1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) while (*p != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) parent = *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) cl1 = rb_entry(parent, struct hfsc_class, vt_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) if (cl->cl_vt >= cl1->cl_vt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) p = &parent->rb_right;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) p = &parent->rb_left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) rb_link_node(&cl->vt_node, parent, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) rb_insert_color(&cl->vt_node, &cl->cl_parent->vt_tree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) vttree_remove(struct hfsc_class *cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) rb_erase(&cl->vt_node, &cl->cl_parent->vt_tree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) vttree_update(struct hfsc_class *cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) vttree_remove(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) vttree_insert(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) static inline struct hfsc_class *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) vttree_firstfit(struct hfsc_class *cl, u64 cur_time)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) struct hfsc_class *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) struct rb_node *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) for (n = rb_first(&cl->vt_tree); n != NULL; n = rb_next(n)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) p = rb_entry(n, struct hfsc_class, vt_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) if (p->cl_f <= cur_time)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) return p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) * get the leaf class with the minimum vt in the hierarchy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) static struct hfsc_class *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) vttree_get_minvt(struct hfsc_class *cl, u64 cur_time)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) /* if root-class's cfmin is bigger than cur_time nothing to do */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) if (cl->cl_cfmin > cur_time)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) while (cl->level > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) cl = vttree_firstfit(cl, cur_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) if (cl == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) * update parent's cl_cvtmin.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) if (cl->cl_parent->cl_cvtmin < cl->cl_vt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) cl->cl_parent->cl_cvtmin = cl->cl_vt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) return cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) cftree_insert(struct hfsc_class *cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) struct rb_node **p = &cl->cl_parent->cf_tree.rb_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) struct rb_node *parent = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) struct hfsc_class *cl1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) while (*p != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) parent = *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) cl1 = rb_entry(parent, struct hfsc_class, cf_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) if (cl->cl_f >= cl1->cl_f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) p = &parent->rb_right;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) p = &parent->rb_left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) rb_link_node(&cl->cf_node, parent, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) rb_insert_color(&cl->cf_node, &cl->cl_parent->cf_tree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) cftree_remove(struct hfsc_class *cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) rb_erase(&cl->cf_node, &cl->cl_parent->cf_tree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) cftree_update(struct hfsc_class *cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) cftree_remove(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) cftree_insert(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) * service curve support functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) * external service curve parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) * m: bps
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) * d: us
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) * internal service curve parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) * sm: (bytes/psched_us) << SM_SHIFT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) * ism: (psched_us/byte) << ISM_SHIFT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) * dx: psched_us
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) * The clock source resolution with ktime and PSCHED_SHIFT 10 is 1.024us.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) * sm and ism are scaled in order to keep effective digits.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) * SM_SHIFT and ISM_SHIFT are selected to keep at least 4 effective
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) * digits in decimal using the following table.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) * bits/sec 100Kbps 1Mbps 10Mbps 100Mbps 1Gbps
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) * ------------+-------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) * bytes/1.024us 12.8e-3 128e-3 1280e-3 12800e-3 128000e-3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) * 1.024us/byte 78.125 7.8125 0.78125 0.078125 0.0078125
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) * So, for PSCHED_SHIFT 10 we need: SM_SHIFT 20, ISM_SHIFT 18.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) #define SM_SHIFT (30 - PSCHED_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) #define ISM_SHIFT (8 + PSCHED_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) #define SM_MASK ((1ULL << SM_SHIFT) - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) #define ISM_MASK ((1ULL << ISM_SHIFT) - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) static inline u64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) seg_x2y(u64 x, u64 sm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) u64 y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) * compute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) * y = x * sm >> SM_SHIFT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) * but divide it for the upper and lower bits to avoid overflow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) y = (x >> SM_SHIFT) * sm + (((x & SM_MASK) * sm) >> SM_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) return y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) static inline u64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) seg_y2x(u64 y, u64 ism)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) u64 x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) if (y == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) x = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) else if (ism == HT_INFINITY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) x = HT_INFINITY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) x = (y >> ISM_SHIFT) * ism
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) + (((y & ISM_MASK) * ism) >> ISM_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) return x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) /* Convert m (bps) into sm (bytes/psched us) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) static u64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) m2sm(u32 m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) u64 sm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) sm = ((u64)m << SM_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) sm += PSCHED_TICKS_PER_SEC - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) do_div(sm, PSCHED_TICKS_PER_SEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) return sm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) /* convert m (bps) into ism (psched us/byte) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) static u64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) m2ism(u32 m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) u64 ism;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) if (m == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) ism = HT_INFINITY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) ism = ((u64)PSCHED_TICKS_PER_SEC << ISM_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) ism += m - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) do_div(ism, m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) return ism;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) /* convert d (us) into dx (psched us) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) static u64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) d2dx(u32 d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) u64 dx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) dx = ((u64)d * PSCHED_TICKS_PER_SEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) dx += USEC_PER_SEC - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) do_div(dx, USEC_PER_SEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) return dx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) /* convert sm (bytes/psched us) into m (bps) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) static u32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) sm2m(u64 sm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) u64 m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) m = (sm * PSCHED_TICKS_PER_SEC) >> SM_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) return (u32)m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) /* convert dx (psched us) into d (us) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) static u32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) dx2d(u64 dx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) u64 d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) d = dx * USEC_PER_SEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) do_div(d, PSCHED_TICKS_PER_SEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) return (u32)d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) sc2isc(struct tc_service_curve *sc, struct internal_sc *isc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) isc->sm1 = m2sm(sc->m1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) isc->ism1 = m2ism(sc->m1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) isc->dx = d2dx(sc->d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) isc->dy = seg_x2y(isc->dx, isc->sm1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) isc->sm2 = m2sm(sc->m2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) isc->ism2 = m2ism(sc->m2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) * initialize the runtime service curve with the given internal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) * service curve starting at (x, y).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) rtsc_init(struct runtime_sc *rtsc, struct internal_sc *isc, u64 x, u64 y)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) rtsc->x = x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) rtsc->y = y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) rtsc->sm1 = isc->sm1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) rtsc->ism1 = isc->ism1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) rtsc->dx = isc->dx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) rtsc->dy = isc->dy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) rtsc->sm2 = isc->sm2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) rtsc->ism2 = isc->ism2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) * calculate the y-projection of the runtime service curve by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) * given x-projection value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) static u64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) rtsc_y2x(struct runtime_sc *rtsc, u64 y)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) u64 x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) if (y < rtsc->y)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) x = rtsc->x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) else if (y <= rtsc->y + rtsc->dy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) /* x belongs to the 1st segment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) if (rtsc->dy == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) x = rtsc->x + rtsc->dx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) x = rtsc->x + seg_y2x(y - rtsc->y, rtsc->ism1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) /* x belongs to the 2nd segment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) x = rtsc->x + rtsc->dx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) + seg_y2x(y - rtsc->y - rtsc->dy, rtsc->ism2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) return x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) static u64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) rtsc_x2y(struct runtime_sc *rtsc, u64 x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) u64 y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) if (x <= rtsc->x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) y = rtsc->y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) else if (x <= rtsc->x + rtsc->dx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) /* y belongs to the 1st segment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) y = rtsc->y + seg_x2y(x - rtsc->x, rtsc->sm1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) /* y belongs to the 2nd segment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) y = rtsc->y + rtsc->dy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) + seg_x2y(x - rtsc->x - rtsc->dx, rtsc->sm2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) return y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) * update the runtime service curve by taking the minimum of the current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) * runtime service curve and the service curve starting at (x, y).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) rtsc_min(struct runtime_sc *rtsc, struct internal_sc *isc, u64 x, u64 y)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) u64 y1, y2, dx, dy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) u32 dsm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) if (isc->sm1 <= isc->sm2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) /* service curve is convex */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) y1 = rtsc_x2y(rtsc, x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) if (y1 < y)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) /* the current rtsc is smaller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) rtsc->x = x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) rtsc->y = y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) * service curve is concave
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) * compute the two y values of the current rtsc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) * y1: at x
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) * y2: at (x + dx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) y1 = rtsc_x2y(rtsc, x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) if (y1 <= y) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) /* rtsc is below isc, no change to rtsc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) y2 = rtsc_x2y(rtsc, x + isc->dx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) if (y2 >= y + isc->dy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) /* rtsc is above isc, replace rtsc by isc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) rtsc->x = x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) rtsc->y = y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) rtsc->dx = isc->dx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) rtsc->dy = isc->dy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) * the two curves intersect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) * compute the offsets (dx, dy) using the reverse
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) * function of seg_x2y()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) * seg_x2y(dx, sm1) == seg_x2y(dx, sm2) + (y1 - y)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) dx = (y1 - y) << SM_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) dsm = isc->sm1 - isc->sm2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) do_div(dx, dsm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) * check if (x, y1) belongs to the 1st segment of rtsc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) * if so, add the offset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) if (rtsc->x + rtsc->dx > x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) dx += rtsc->x + rtsc->dx - x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) dy = seg_x2y(dx, isc->sm1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) rtsc->x = x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) rtsc->y = y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) rtsc->dx = dx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) rtsc->dy = dy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) init_ed(struct hfsc_class *cl, unsigned int next_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) u64 cur_time = psched_get_time();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) /* update the deadline curve */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) rtsc_min(&cl->cl_deadline, &cl->cl_rsc, cur_time, cl->cl_cumul);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) * update the eligible curve.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) * for concave, it is equal to the deadline curve.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) * for convex, it is a linear curve with slope m2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) cl->cl_eligible = cl->cl_deadline;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) if (cl->cl_rsc.sm1 <= cl->cl_rsc.sm2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) cl->cl_eligible.dx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) cl->cl_eligible.dy = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) /* compute e and d */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) cl->cl_e = rtsc_y2x(&cl->cl_eligible, cl->cl_cumul);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) cl->cl_d = rtsc_y2x(&cl->cl_deadline, cl->cl_cumul + next_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) eltree_insert(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) update_ed(struct hfsc_class *cl, unsigned int next_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) cl->cl_e = rtsc_y2x(&cl->cl_eligible, cl->cl_cumul);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) cl->cl_d = rtsc_y2x(&cl->cl_deadline, cl->cl_cumul + next_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) eltree_update(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) update_d(struct hfsc_class *cl, unsigned int next_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) cl->cl_d = rtsc_y2x(&cl->cl_deadline, cl->cl_cumul + next_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) update_cfmin(struct hfsc_class *cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) struct rb_node *n = rb_first(&cl->cf_tree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) struct hfsc_class *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) if (n == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) cl->cl_cfmin = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) p = rb_entry(n, struct hfsc_class, cf_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) cl->cl_cfmin = p->cl_f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) init_vf(struct hfsc_class *cl, unsigned int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) struct hfsc_class *max_cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) struct rb_node *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) u64 vt, f, cur_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) int go_active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) cur_time = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) go_active = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) for (; cl->cl_parent != NULL; cl = cl->cl_parent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) if (go_active && cl->cl_nactive++ == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) go_active = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) go_active = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) if (go_active) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) n = rb_last(&cl->cl_parent->vt_tree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) if (n != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) max_cl = rb_entry(n, struct hfsc_class, vt_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) * set vt to the average of the min and max
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) * classes. if the parent's period didn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) * change, don't decrease vt of the class.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) vt = max_cl->cl_vt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) if (cl->cl_parent->cl_cvtmin != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) vt = (cl->cl_parent->cl_cvtmin + vt)/2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) if (cl->cl_parent->cl_vtperiod !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) cl->cl_parentperiod || vt > cl->cl_vt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) cl->cl_vt = vt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) * first child for a new parent backlog period.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) * initialize cl_vt to the highest value seen
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) * among the siblings. this is analogous to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) * what cur_time would provide in realtime case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) cl->cl_vt = cl->cl_parent->cl_cvtoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) cl->cl_parent->cl_cvtmin = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) /* update the virtual curve */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) rtsc_min(&cl->cl_virtual, &cl->cl_fsc, cl->cl_vt, cl->cl_total);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) cl->cl_vtadj = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) cl->cl_vtperiod++; /* increment vt period */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) cl->cl_parentperiod = cl->cl_parent->cl_vtperiod;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) if (cl->cl_parent->cl_nactive == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) cl->cl_parentperiod++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) cl->cl_f = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) vttree_insert(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) cftree_insert(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) if (cl->cl_flags & HFSC_USC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) /* class has upper limit curve */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) if (cur_time == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) cur_time = psched_get_time();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) /* update the ulimit curve */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) rtsc_min(&cl->cl_ulimit, &cl->cl_usc, cur_time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) cl->cl_total);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) /* compute myf */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) cl->cl_myf = rtsc_y2x(&cl->cl_ulimit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) cl->cl_total);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) f = max(cl->cl_myf, cl->cl_cfmin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) if (f != cl->cl_f) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) cl->cl_f = f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) cftree_update(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) update_cfmin(cl->cl_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) update_vf(struct hfsc_class *cl, unsigned int len, u64 cur_time)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) u64 f; /* , myf_bound, delta; */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) int go_passive = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) if (cl->qdisc->q.qlen == 0 && cl->cl_flags & HFSC_FSC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) go_passive = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) for (; cl->cl_parent != NULL; cl = cl->cl_parent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) cl->cl_total += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) if (!(cl->cl_flags & HFSC_FSC) || cl->cl_nactive == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) if (go_passive && --cl->cl_nactive == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) go_passive = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) go_passive = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) /* update vt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) cl->cl_vt = rtsc_y2x(&cl->cl_virtual, cl->cl_total) + cl->cl_vtadj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) * if vt of the class is smaller than cvtmin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) * the class was skipped in the past due to non-fit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) * if so, we need to adjust vtadj.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) if (cl->cl_vt < cl->cl_parent->cl_cvtmin) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) cl->cl_vtadj += cl->cl_parent->cl_cvtmin - cl->cl_vt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) cl->cl_vt = cl->cl_parent->cl_cvtmin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) if (go_passive) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) /* no more active child, going passive */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) /* update cvtoff of the parent class */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) if (cl->cl_vt > cl->cl_parent->cl_cvtoff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) cl->cl_parent->cl_cvtoff = cl->cl_vt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) /* remove this class from the vt tree */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) vttree_remove(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) cftree_remove(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) update_cfmin(cl->cl_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) /* update the vt tree */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) vttree_update(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) /* update f */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) if (cl->cl_flags & HFSC_USC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) cl->cl_myf = rtsc_y2x(&cl->cl_ulimit, cl->cl_total);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) cl->cl_myf = cl->cl_myfadj + rtsc_y2x(&cl->cl_ulimit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) cl->cl_total);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) * This code causes classes to stay way under their
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) * limit when multiple classes are used at gigabit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) * speed. needs investigation. -kaber
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) * if myf lags behind by more than one clock tick
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) * from the current time, adjust myfadj to prevent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) * a rate-limited class from going greedy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) * in a steady state under rate-limiting, myf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) * fluctuates within one clock tick.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) myf_bound = cur_time - PSCHED_JIFFIE2US(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) if (cl->cl_myf < myf_bound) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) delta = cur_time - cl->cl_myf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) cl->cl_myfadj += delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) cl->cl_myf += delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) f = max(cl->cl_myf, cl->cl_cfmin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) if (f != cl->cl_f) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) cl->cl_f = f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) cftree_update(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) update_cfmin(cl->cl_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) static unsigned int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) qdisc_peek_len(struct Qdisc *sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) unsigned int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) skb = sch->ops->peek(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) if (unlikely(skb == NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) qdisc_warn_nonwc("qdisc_peek_len", sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) len = qdisc_pkt_len(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) hfsc_adjust_levels(struct hfsc_class *cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) struct hfsc_class *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) unsigned int level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) level = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) list_for_each_entry(p, &cl->children, siblings) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) if (p->level >= level)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) level = p->level + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) cl->level = level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) } while ((cl = cl->cl_parent) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) static inline struct hfsc_class *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) hfsc_find_class(u32 classid, struct Qdisc *sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) struct hfsc_sched *q = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) struct Qdisc_class_common *clc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) clc = qdisc_class_find(&q->clhash, classid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) if (clc == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) return container_of(clc, struct hfsc_class, cl_common);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) hfsc_change_rsc(struct hfsc_class *cl, struct tc_service_curve *rsc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) u64 cur_time)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) sc2isc(rsc, &cl->cl_rsc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) rtsc_init(&cl->cl_deadline, &cl->cl_rsc, cur_time, cl->cl_cumul);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) cl->cl_eligible = cl->cl_deadline;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) if (cl->cl_rsc.sm1 <= cl->cl_rsc.sm2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) cl->cl_eligible.dx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) cl->cl_eligible.dy = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) cl->cl_flags |= HFSC_RSC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) hfsc_change_fsc(struct hfsc_class *cl, struct tc_service_curve *fsc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) sc2isc(fsc, &cl->cl_fsc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) rtsc_init(&cl->cl_virtual, &cl->cl_fsc, cl->cl_vt, cl->cl_total);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) cl->cl_flags |= HFSC_FSC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) hfsc_change_usc(struct hfsc_class *cl, struct tc_service_curve *usc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) u64 cur_time)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) sc2isc(usc, &cl->cl_usc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) rtsc_init(&cl->cl_ulimit, &cl->cl_usc, cur_time, cl->cl_total);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) cl->cl_flags |= HFSC_USC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) static const struct nla_policy hfsc_policy[TCA_HFSC_MAX + 1] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) [TCA_HFSC_RSC] = { .len = sizeof(struct tc_service_curve) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) [TCA_HFSC_FSC] = { .len = sizeof(struct tc_service_curve) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) [TCA_HFSC_USC] = { .len = sizeof(struct tc_service_curve) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) hfsc_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) struct nlattr **tca, unsigned long *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) struct hfsc_sched *q = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) struct hfsc_class *cl = (struct hfsc_class *)*arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) struct hfsc_class *parent = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) struct nlattr *opt = tca[TCA_OPTIONS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) struct nlattr *tb[TCA_HFSC_MAX + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) struct tc_service_curve *rsc = NULL, *fsc = NULL, *usc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) u64 cur_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) if (opt == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) err = nla_parse_nested_deprecated(tb, TCA_HFSC_MAX, opt, hfsc_policy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) if (tb[TCA_HFSC_RSC]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) rsc = nla_data(tb[TCA_HFSC_RSC]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) if (rsc->m1 == 0 && rsc->m2 == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) rsc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) if (tb[TCA_HFSC_FSC]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) fsc = nla_data(tb[TCA_HFSC_FSC]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) if (fsc->m1 == 0 && fsc->m2 == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) fsc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) if (tb[TCA_HFSC_USC]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) usc = nla_data(tb[TCA_HFSC_USC]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) if (usc->m1 == 0 && usc->m2 == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) usc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) if (cl != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) int old_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) if (parentid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) if (cl->cl_parent &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) cl->cl_parent->cl_common.classid != parentid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) if (cl->cl_parent == NULL && parentid != TC_H_ROOT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) cur_time = psched_get_time();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) if (tca[TCA_RATE]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) err = gen_replace_estimator(&cl->bstats, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) &cl->rate_est,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) qdisc_root_sleeping_running(sch),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) tca[TCA_RATE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) sch_tree_lock(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) old_flags = cl->cl_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) if (rsc != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) hfsc_change_rsc(cl, rsc, cur_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) if (fsc != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) hfsc_change_fsc(cl, fsc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) if (usc != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) hfsc_change_usc(cl, usc, cur_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) if (cl->qdisc->q.qlen != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) int len = qdisc_peek_len(cl->qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) if (cl->cl_flags & HFSC_RSC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) if (old_flags & HFSC_RSC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) update_ed(cl, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) init_ed(cl, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) if (cl->cl_flags & HFSC_FSC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) if (old_flags & HFSC_FSC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) update_vf(cl, 0, cur_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) init_vf(cl, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) sch_tree_unlock(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) if (parentid == TC_H_ROOT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) return -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) parent = &q->root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) if (parentid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) parent = hfsc_find_class(parentid, sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) if (parent == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) if (classid == 0 || TC_H_MAJ(classid ^ sch->handle) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) if (hfsc_find_class(classid, sch))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) return -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) if (rsc == NULL && fsc == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) cl = kzalloc(sizeof(struct hfsc_class), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) if (cl == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) return -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) err = tcf_block_get(&cl->block, &cl->filter_list, sch, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) kfree(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) if (tca[TCA_RATE]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) err = gen_new_estimator(&cl->bstats, NULL, &cl->rate_est,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) qdisc_root_sleeping_running(sch),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) tca[TCA_RATE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) tcf_block_put(cl->block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) kfree(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) if (rsc != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) hfsc_change_rsc(cl, rsc, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) if (fsc != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) hfsc_change_fsc(cl, fsc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) if (usc != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) hfsc_change_usc(cl, usc, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) cl->cl_common.classid = classid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) cl->sched = q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) cl->cl_parent = parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) cl->qdisc = qdisc_create_dflt(sch->dev_queue, &pfifo_qdisc_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) classid, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) if (cl->qdisc == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) cl->qdisc = &noop_qdisc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) qdisc_hash_add(cl->qdisc, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) INIT_LIST_HEAD(&cl->children);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) cl->vt_tree = RB_ROOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) cl->cf_tree = RB_ROOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) sch_tree_lock(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) qdisc_class_hash_insert(&q->clhash, &cl->cl_common);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) list_add_tail(&cl->siblings, &parent->children);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) if (parent->level == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) qdisc_purge_queue(parent->qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) hfsc_adjust_levels(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) sch_tree_unlock(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) qdisc_class_hash_grow(sch, &q->clhash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) *arg = (unsigned long)cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) hfsc_destroy_class(struct Qdisc *sch, struct hfsc_class *cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) struct hfsc_sched *q = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) tcf_block_put(cl->block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) qdisc_put(cl->qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) gen_kill_estimator(&cl->rate_est);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) if (cl != &q->root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) kfree(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) hfsc_delete_class(struct Qdisc *sch, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) struct hfsc_sched *q = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) struct hfsc_class *cl = (struct hfsc_class *)arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) if (cl->level > 0 || cl->filter_cnt > 0 || cl == &q->root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) sch_tree_lock(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) list_del(&cl->siblings);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) hfsc_adjust_levels(cl->cl_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) qdisc_purge_queue(cl->qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) qdisc_class_hash_remove(&q->clhash, &cl->cl_common);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) sch_tree_unlock(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) hfsc_destroy_class(sch, cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) static struct hfsc_class *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) hfsc_classify(struct sk_buff *skb, struct Qdisc *sch, int *qerr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) struct hfsc_sched *q = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) struct hfsc_class *head, *cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) struct tcf_result res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) struct tcf_proto *tcf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) if (TC_H_MAJ(skb->priority ^ sch->handle) == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) (cl = hfsc_find_class(skb->priority, sch)) != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) if (cl->level == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) return cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) *qerr = NET_XMIT_SUCCESS | __NET_XMIT_BYPASS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) head = &q->root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) tcf = rcu_dereference_bh(q->root.filter_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) while (tcf && (result = tcf_classify(skb, tcf, &res, false)) >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) #ifdef CONFIG_NET_CLS_ACT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) switch (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) case TC_ACT_QUEUED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) case TC_ACT_STOLEN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) case TC_ACT_TRAP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) *qerr = NET_XMIT_SUCCESS | __NET_XMIT_STOLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) case TC_ACT_SHOT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) cl = (struct hfsc_class *)res.class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) if (!cl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) cl = hfsc_find_class(res.classid, sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) if (!cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) break; /* filter selected invalid classid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) if (cl->level >= head->level)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) break; /* filter may only point downwards */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) if (cl->level == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) return cl; /* hit leaf class */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) /* apply inner filter chain */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) tcf = rcu_dereference_bh(cl->filter_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) head = cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) /* classification failed, try default class */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) cl = hfsc_find_class(TC_H_MAKE(TC_H_MAJ(sch->handle), q->defcls), sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) if (cl == NULL || cl->level > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) return cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) hfsc_graft_class(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) struct Qdisc **old, struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) struct hfsc_class *cl = (struct hfsc_class *)arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) if (cl->level > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) if (new == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) new = qdisc_create_dflt(sch->dev_queue, &pfifo_qdisc_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) cl->cl_common.classid, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) if (new == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) new = &noop_qdisc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) *old = qdisc_replace(sch, new, &cl->qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) static struct Qdisc *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) hfsc_class_leaf(struct Qdisc *sch, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) struct hfsc_class *cl = (struct hfsc_class *)arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) if (cl->level == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) return cl->qdisc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) hfsc_qlen_notify(struct Qdisc *sch, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) struct hfsc_class *cl = (struct hfsc_class *)arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) /* vttree is now handled in update_vf() so that update_vf(cl, 0, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) * needs to be called explicitly to remove a class from vttree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) update_vf(cl, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) if (cl->cl_flags & HFSC_RSC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) eltree_remove(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) static unsigned long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) hfsc_search_class(struct Qdisc *sch, u32 classid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) return (unsigned long)hfsc_find_class(classid, sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) static unsigned long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) hfsc_bind_tcf(struct Qdisc *sch, unsigned long parent, u32 classid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) struct hfsc_class *p = (struct hfsc_class *)parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) struct hfsc_class *cl = hfsc_find_class(classid, sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) if (cl != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) if (p != NULL && p->level <= cl->level)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) cl->filter_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) return (unsigned long)cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) hfsc_unbind_tcf(struct Qdisc *sch, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) struct hfsc_class *cl = (struct hfsc_class *)arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) cl->filter_cnt--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) static struct tcf_block *hfsc_tcf_block(struct Qdisc *sch, unsigned long arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) struct hfsc_sched *q = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) struct hfsc_class *cl = (struct hfsc_class *)arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) if (cl == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) cl = &q->root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) return cl->block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) hfsc_dump_sc(struct sk_buff *skb, int attr, struct internal_sc *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) struct tc_service_curve tsc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) tsc.m1 = sm2m(sc->sm1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) tsc.d = dx2d(sc->dx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) tsc.m2 = sm2m(sc->sm2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) if (nla_put(skb, attr, sizeof(tsc), &tsc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) return skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) nla_put_failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) hfsc_dump_curves(struct sk_buff *skb, struct hfsc_class *cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) if ((cl->cl_flags & HFSC_RSC) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) (hfsc_dump_sc(skb, TCA_HFSC_RSC, &cl->cl_rsc) < 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) if ((cl->cl_flags & HFSC_FSC) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) (hfsc_dump_sc(skb, TCA_HFSC_FSC, &cl->cl_fsc) < 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) if ((cl->cl_flags & HFSC_USC) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) (hfsc_dump_sc(skb, TCA_HFSC_USC, &cl->cl_usc) < 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) return skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) nla_put_failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) hfsc_dump_class(struct Qdisc *sch, unsigned long arg, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) struct tcmsg *tcm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) struct hfsc_class *cl = (struct hfsc_class *)arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) struct nlattr *nest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) tcm->tcm_parent = cl->cl_parent ? cl->cl_parent->cl_common.classid :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) TC_H_ROOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) tcm->tcm_handle = cl->cl_common.classid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) if (cl->level == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) tcm->tcm_info = cl->qdisc->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) if (nest == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) if (hfsc_dump_curves(skb, cl) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) return nla_nest_end(skb, nest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) nla_put_failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) nla_nest_cancel(skb, nest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) hfsc_dump_class_stats(struct Qdisc *sch, unsigned long arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) struct gnet_dump *d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) struct hfsc_class *cl = (struct hfsc_class *)arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) struct tc_hfsc_stats xstats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) __u32 qlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) qdisc_qstats_qlen_backlog(cl->qdisc, &qlen, &cl->qstats.backlog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) xstats.level = cl->level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) xstats.period = cl->cl_vtperiod;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) xstats.work = cl->cl_total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) xstats.rtwork = cl->cl_cumul;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) if (gnet_stats_copy_basic(qdisc_root_sleeping_running(sch), d, NULL, &cl->bstats) < 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) gnet_stats_copy_rate_est(d, &cl->rate_est) < 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) gnet_stats_copy_queue(d, NULL, &cl->qstats, qlen) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) return gnet_stats_copy_app(d, &xstats, sizeof(xstats));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) hfsc_walk(struct Qdisc *sch, struct qdisc_walker *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) struct hfsc_sched *q = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) struct hfsc_class *cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) if (arg->stop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) for (i = 0; i < q->clhash.hashsize; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) hlist_for_each_entry(cl, &q->clhash.hash[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) cl_common.hnode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) if (arg->count < arg->skip) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) arg->count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) if (arg->fn(sch, (unsigned long)cl, arg) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) arg->stop = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) arg->count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) hfsc_schedule_watchdog(struct Qdisc *sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) struct hfsc_sched *q = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) struct hfsc_class *cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) u64 next_time = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) cl = eltree_get_minel(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) if (cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) next_time = cl->cl_e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) if (q->root.cl_cfmin != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) if (next_time == 0 || next_time > q->root.cl_cfmin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) next_time = q->root.cl_cfmin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) if (next_time)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) qdisc_watchdog_schedule(&q->watchdog, next_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) hfsc_init_qdisc(struct Qdisc *sch, struct nlattr *opt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) struct hfsc_sched *q = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) struct tc_hfsc_qopt *qopt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) qdisc_watchdog_init(&q->watchdog, sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) if (!opt || nla_len(opt) < sizeof(*qopt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) qopt = nla_data(opt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) q->defcls = qopt->defcls;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) err = qdisc_class_hash_init(&q->clhash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) q->eligible = RB_ROOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) err = tcf_block_get(&q->root.block, &q->root.filter_list, sch, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) q->root.cl_common.classid = sch->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) q->root.sched = q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) q->root.qdisc = qdisc_create_dflt(sch->dev_queue, &pfifo_qdisc_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) sch->handle, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) if (q->root.qdisc == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) q->root.qdisc = &noop_qdisc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) qdisc_hash_add(q->root.qdisc, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) INIT_LIST_HEAD(&q->root.children);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) q->root.vt_tree = RB_ROOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) q->root.cf_tree = RB_ROOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) qdisc_class_hash_insert(&q->clhash, &q->root.cl_common);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) qdisc_class_hash_grow(sch, &q->clhash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) hfsc_change_qdisc(struct Qdisc *sch, struct nlattr *opt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) struct hfsc_sched *q = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) struct tc_hfsc_qopt *qopt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) if (opt == NULL || nla_len(opt) < sizeof(*qopt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) qopt = nla_data(opt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) sch_tree_lock(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) q->defcls = qopt->defcls;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) sch_tree_unlock(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) hfsc_reset_class(struct hfsc_class *cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) cl->cl_total = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) cl->cl_cumul = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) cl->cl_d = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) cl->cl_e = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) cl->cl_vt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) cl->cl_vtadj = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) cl->cl_cvtmin = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) cl->cl_cvtoff = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) cl->cl_vtperiod = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) cl->cl_parentperiod = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) cl->cl_f = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) cl->cl_myf = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) cl->cl_cfmin = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) cl->cl_nactive = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) cl->vt_tree = RB_ROOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) cl->cf_tree = RB_ROOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) qdisc_reset(cl->qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) if (cl->cl_flags & HFSC_RSC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) rtsc_init(&cl->cl_deadline, &cl->cl_rsc, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) if (cl->cl_flags & HFSC_FSC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) rtsc_init(&cl->cl_virtual, &cl->cl_fsc, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) if (cl->cl_flags & HFSC_USC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) rtsc_init(&cl->cl_ulimit, &cl->cl_usc, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) hfsc_reset_qdisc(struct Qdisc *sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) struct hfsc_sched *q = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) struct hfsc_class *cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) for (i = 0; i < q->clhash.hashsize; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) hlist_for_each_entry(cl, &q->clhash.hash[i], cl_common.hnode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) hfsc_reset_class(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) q->eligible = RB_ROOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) qdisc_watchdog_cancel(&q->watchdog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) sch->qstats.backlog = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) sch->q.qlen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) hfsc_destroy_qdisc(struct Qdisc *sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) struct hfsc_sched *q = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) struct hlist_node *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) struct hfsc_class *cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) for (i = 0; i < q->clhash.hashsize; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) hlist_for_each_entry(cl, &q->clhash.hash[i], cl_common.hnode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) tcf_block_put(cl->block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) cl->block = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) for (i = 0; i < q->clhash.hashsize; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) hlist_for_each_entry_safe(cl, next, &q->clhash.hash[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) cl_common.hnode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) hfsc_destroy_class(sch, cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) qdisc_class_hash_destroy(&q->clhash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) qdisc_watchdog_cancel(&q->watchdog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) hfsc_dump_qdisc(struct Qdisc *sch, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) struct hfsc_sched *q = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) unsigned char *b = skb_tail_pointer(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) struct tc_hfsc_qopt qopt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) qopt.defcls = q->defcls;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) if (nla_put(skb, TCA_OPTIONS, sizeof(qopt), &qopt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) return skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) nla_put_failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) nlmsg_trim(skb, b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) hfsc_enqueue(struct sk_buff *skb, struct Qdisc *sch, struct sk_buff **to_free)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) unsigned int len = qdisc_pkt_len(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) struct hfsc_class *cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) bool first;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) cl = hfsc_classify(skb, sch, &err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) if (cl == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) if (err & __NET_XMIT_BYPASS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) qdisc_qstats_drop(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) __qdisc_drop(skb, to_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) first = !cl->qdisc->q.qlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) err = qdisc_enqueue(skb, cl->qdisc, to_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) if (unlikely(err != NET_XMIT_SUCCESS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) if (net_xmit_drop_count(err)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) cl->qstats.drops++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) qdisc_qstats_drop(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) if (first) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) if (cl->cl_flags & HFSC_RSC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) init_ed(cl, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) if (cl->cl_flags & HFSC_FSC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) init_vf(cl, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) * If this is the first packet, isolate the head so an eventual
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) * head drop before the first dequeue operation has no chance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) * to invalidate the deadline.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) if (cl->cl_flags & HFSC_RSC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) cl->qdisc->ops->peek(cl->qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) sch->qstats.backlog += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) sch->q.qlen++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) return NET_XMIT_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) static struct sk_buff *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) hfsc_dequeue(struct Qdisc *sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) struct hfsc_sched *q = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) struct hfsc_class *cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) u64 cur_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) unsigned int next_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) int realtime = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) if (sch->q.qlen == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) cur_time = psched_get_time();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) * if there are eligible classes, use real-time criteria.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) * find the class with the minimum deadline among
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) * the eligible classes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) cl = eltree_get_mindl(q, cur_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) if (cl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) realtime = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) * use link-sharing criteria
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) * get the class with the minimum vt in the hierarchy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) cl = vttree_get_minvt(&q->root, cur_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) if (cl == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) qdisc_qstats_overlimit(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) hfsc_schedule_watchdog(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) skb = qdisc_dequeue_peeked(cl->qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) if (skb == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) qdisc_warn_nonwc("HFSC", cl->qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) bstats_update(&cl->bstats, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) update_vf(cl, qdisc_pkt_len(skb), cur_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) if (realtime)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) cl->cl_cumul += qdisc_pkt_len(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) if (cl->cl_flags & HFSC_RSC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) if (cl->qdisc->q.qlen != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) /* update ed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) next_len = qdisc_peek_len(cl->qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) if (realtime)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) update_ed(cl, next_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) update_d(cl, next_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) /* the class becomes passive */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) eltree_remove(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) qdisc_bstats_update(sch, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) qdisc_qstats_backlog_dec(sch, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) sch->q.qlen--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) return skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) static const struct Qdisc_class_ops hfsc_class_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) .change = hfsc_change_class,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) .delete = hfsc_delete_class,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) .graft = hfsc_graft_class,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) .leaf = hfsc_class_leaf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) .qlen_notify = hfsc_qlen_notify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) .find = hfsc_search_class,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) .bind_tcf = hfsc_bind_tcf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) .unbind_tcf = hfsc_unbind_tcf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) .tcf_block = hfsc_tcf_block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) .dump = hfsc_dump_class,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) .dump_stats = hfsc_dump_class_stats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) .walk = hfsc_walk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) static struct Qdisc_ops hfsc_qdisc_ops __read_mostly = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) .id = "hfsc",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) .init = hfsc_init_qdisc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) .change = hfsc_change_qdisc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) .reset = hfsc_reset_qdisc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) .destroy = hfsc_destroy_qdisc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) .dump = hfsc_dump_qdisc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) .enqueue = hfsc_enqueue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) .dequeue = hfsc_dequeue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) .peek = qdisc_peek_dequeued,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) .cl_ops = &hfsc_class_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) .priv_size = sizeof(struct hfsc_sched),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) .owner = THIS_MODULE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) static int __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) hfsc_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) return register_qdisc(&hfsc_qdisc_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) static void __exit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) hfsc_cleanup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) unregister_qdisc(&hfsc_qdisc_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) module_init(hfsc_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) module_exit(hfsc_cleanup);