cregit-Linux how code gets into the kernel

Release 4.8 net/sched/sch_htb.c

Directory: net/sched
/*
 * net/sched/sch_htb.c  Hierarchical token bucket, feed tree version
 *
 *              This program is free software; you can redistribute it and/or
 *              modify it under the terms of the GNU General Public License
 *              as published by the Free Software Foundation; either version
 *              2 of the License, or (at your option) any later version.
 *
 * Authors:     Martin Devera, <devik@cdi.cz>
 *
 * Credits (in time order) for older HTB versions:
 *              Stef Coene <stef.coene@docum.org>
 *                      HTB support at LARTC mailing list
 *              Ondrej Kraus, <krauso@barr.cz>
 *                      found missing INIT_QDISC(htb)
 *              Vladimir Smelhaus, Aamer Akhter, Bert Hubert
 *                      helped a lot to locate nasty class stall bug
 *              Andi Kleen, Jamal Hadi, Bert Hubert
 *                      code review and helpful comments on shaping
 *              Tomasz Wrona, <tw@eter.tym.pl>
 *                      created test case so that I was able to fix nasty bug
 *              Wilfried Weissmann
 *                      spotted bug in dequeue code and helped with fix
 *              Jiri Fojtasek
 *                      fixed requeue routine
 *              and many others. thanks.
 */
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/errno.h>
#include <linux/skbuff.h>
#include <linux/list.h>
#include <linux/compiler.h>
#include <linux/rbtree.h>
#include <linux/workqueue.h>
#include <linux/slab.h>
#include <net/netlink.h>
#include <net/sch_generic.h>
#include <net/pkt_sched.h>

/* HTB algorithm.
    Author: devik@cdi.cz
    ========================================================================
    HTB is like TBF with multiple classes. It is also similar to CBQ because
    it allows to assign priority to each class in hierarchy.
    In fact it is another implementation of Floyd's formal sharing.

    Levels:
    Each class is assigned level. Leaf has ALWAYS level 0 and root
    classes have level TC_HTB_MAXDEPTH-1. Interior nodes has level
    one less than their parent.
*/


static int htb_hysteresis __read_mostly = 0; 
/* whether to use mode hysteresis for speedup */

#define HTB_VER 0x30011		
/* major must be matched with number suplied by TC as version */

#if HTB_VER >> 16 != TC_HTB_PROTOVER
#error "Mismatched sch_htb.c and pkt_sch.h"
#endif

/* Module parameter and sysfs export */
module_param    (htb_hysteresis, int, 0640);
MODULE_PARM_DESC(htb_hysteresis, "Hysteresis mode, less CPU load, less accurate");


static int htb_rate_est = 0; 
/* htb classes have a default rate estimator */
module_param(htb_rate_est, int, 0640);
MODULE_PARM_DESC(htb_rate_est, "setup a default rate estimator (4sec 16sec) for htb classes");

/* used internaly to keep status of single class */

enum htb_cmode {
	
HTB_CANT_SEND,		/* class can't send and can't borrow */
	
HTB_MAY_BORROW,		/* class can't send but may borrow */
	
HTB_CAN_SEND		/* class can send */
};


struct htb_prio {
	union {
		
struct rb_root	row;
		
struct rb_root	feed;
	};
	
struct rb_node	*ptr;
	/* When class changes from state 1->2 and disconnects from
         * parent's feed then we lost ptr value and start from the
         * first child again. Here we store classid of the
         * last valid ptr (used when ptr is NULL).
         */
	
u32		last_ptr_id;
};

/* interior & leaf nodes; props specific to leaves are marked L:
 * To reduce false sharing, place mostly read fields at beginning,
 * and mostly written ones at the end.
 */

struct htb_class {
	
struct Qdisc_class_common common;
	
struct psched_ratecfg	rate;
	
struct psched_ratecfg	ceil;
	

s64			buffer, cbuffer;/* token bucket depth/rate */
	
s64			mbuffer;	/* max wait time */
	
u32			prio;		/* these two are used only by leaves... */
	
int			quantum;	/* but stored for parent-to-leaf return */

	
struct tcf_proto __rcu	*filter_list;	/* class attached filters */
	
int			filter_cnt;
	
int			refcnt;		/* usage count of this class */

	
int			level;		/* our level (see above) */
	
unsigned int		children;
	
struct htb_class	*parent;	/* parent class */

	
struct gnet_stats_rate_est64 rate_est;

	/*
         * Written often fields
         */
	
struct gnet_stats_basic_packed bstats;
	
struct tc_htb_xstats	xstats;	/* our special stats */

	/* token bucket parameters */
	

s64			tokens, ctokens;/* current number of tokens */
	
s64			t_c;		/* checkpoint time */

	union {
		
struct htb_class_leaf {
			
struct list_head drop_list;
			
int		deficit[TC_HTB_MAXDEPTH];
			
struct Qdisc	*q;
		} 
leaf;
		
struct htb_class_inner {
			
struct htb_prio clprio[TC_HTB_NUMPRIO];
		} 
inner;
	} 
un;
	
s64			pq_key;

	
int			prio_activity;	/* for which prios are we active */
	
enum htb_cmode		cmode;		/* current mode of the class */
	
struct rb_node		pq_node;	/* node for event queue */
	
struct rb_node		node[TC_HTB_NUMPRIO];	/* node for self or feed tree */

	
unsigned int drops ____cacheline_aligned_in_smp;
};


struct htb_level {
	
struct rb_root	wait_pq;
	
struct htb_prio hprio[TC_HTB_NUMPRIO];
};


struct htb_sched {
	
struct Qdisc_class_hash clhash;
	
int			defcls;		/* class where unclassified flows go to */
	
int			rate2quantum;	/* quant = rate / rate2quantum */

	/* filters for qdisc itself */
	
struct tcf_proto __rcu	*filter_list;


#define HTB_WARN_TOOMANYEVENTS	0x1
	
unsigned int		warned;	/* only one warning */
	
int			direct_qlen;
	
struct work_struct	work;

	/* non shaped skbs; let them go directly thru */
	
struct sk_buff_head	direct_queue;
	
long			direct_pkts;

	
struct qdisc_watchdog	watchdog;

	
s64			now;	/* cached dequeue time */
	
struct list_head	drops[TC_HTB_NUMPRIO];/* active leaves (for drops) */

	/* time of nearest event per level (row) */
	
s64			near_ev_cache[TC_HTB_MAXDEPTH];

	
int			row_mask[TC_HTB_MAXDEPTH];

	
struct htb_level	hlevel[TC_HTB_MAXDEPTH];
};

/* find class in global hash table using given handle */

static inline struct htb_class *htb_find(u32 handle, struct Qdisc *sch) { struct htb_sched *q = qdisc_priv(sch); struct Qdisc_class_common *clc; clc = qdisc_class_find(&q->clhash, handle); if (clc == NULL) return NULL; return container_of(clc, struct htb_class, common); }

Contributors

PersonTokensPropCommitsCommitProp
stephen hemmingerstephen hemminger2539.06%360.00%
patrick mchardypatrick mchardy2234.38%120.00%
david s. millerdavid s. miller1726.56%120.00%
Total64100.00%5100.00%

/** * htb_classify - classify a packet into class * * It returns NULL if the packet should be dropped or -1 if the packet * should be passed directly thru. In all other cases leaf class is returned. * We allow direct class selection by classid in priority. The we examine * filters in qdisc and in inner nodes (if higher filter points to the inner * node). If we end up with classid MAJOR:0 we enqueue the skb into special * internal fifo (direct). These packets then go directly thru. If we still * have no valid leaf we try to use MAJOR:default leaf. It still unsuccessful * then finish and return direct queue. */ #define HTB_DIRECT ((struct htb_class *)-1L)
static struct htb_class *htb_classify(struct sk_buff *skb, struct Qdisc *sch, int *qerr) { struct htb_sched *q = qdisc_priv(sch); struct htb_class *cl; struct tcf_result res; struct tcf_proto *tcf; int result; /* allow to select class by setting skb->priority to valid classid; * note that nfmark can be used too by attaching filter fw with no * rules in it */ if (skb->priority == sch->handle) return HTB_DIRECT; /* X:0 (direct flow) selected */ cl = htb_find(skb->priority, sch); if (cl) { if (cl->level == 0) return cl; /* Start with inner filter chain if a non-leaf class is selected */ tcf = rcu_dereference_bh(cl->filter_list); } else { tcf = rcu_dereference_bh(q->filter_list); } *qerr = NET_XMIT_SUCCESS | __NET_XMIT_BYPASS; while (tcf && (result = tc_classify(skb, tcf, &res, false)) >= 0) { #ifdef CONFIG_NET_CLS_ACT switch (result) { case TC_ACT_QUEUED: case TC_ACT_STOLEN: *qerr = NET_XMIT_SUCCESS | __NET_XMIT_STOLEN; case TC_ACT_SHOT: return NULL; } #endif cl = (void *)res.class; if (!cl) { if (res.classid == sch->handle) return HTB_DIRECT; /* X:0 (direct flow) */ cl = htb_find(res.classid, sch); if (!cl) break; /* filter selected invalid classid */ } if (!cl->level) return cl; /* we hit leaf; return it */ /* we have got inner class; apply inner filter chain */ tcf = rcu_dereference_bh(cl->filter_list); } /* classification failed; try to use default class */ cl = htb_find(TC_H_MAKE(TC_H_MAJ(sch->handle), q->defcls), sch); if (!cl || cl->level) return HTB_DIRECT; /* bad default .. this is safe bet */ return cl; }

Contributors

PersonTokensPropCommitsCommitProp
david s. millerdavid s. miller19769.61%218.18%
jamal hadi salimjamal hadi salim238.13%19.09%
harry masonharry mason207.07%19.09%
eric dumazeteric dumazet155.30%19.09%
john fastabendjohn fastabend93.18%19.09%
patrick mchardypatrick mchardy72.47%19.09%
martin deveramartin devera51.77%19.09%
stephen hemmingerstephen hemminger31.06%19.09%
jarek poplawskijarek poplawski20.71%19.09%
daniel borkmanndaniel borkmann20.71%19.09%
Total283100.00%11100.00%

/** * htb_add_to_id_tree - adds class to the round robin list * * Routine adds class to the list (actually tree) sorted by classid. * Make sure that class is not already on such list for given prio. */
static void htb_add_to_id_tree(struct rb_root *root, struct htb_class *cl, int prio) { struct rb_node **p = &root->rb_node, *parent = NULL; while (*p) { struct htb_class *c; parent = *p; c = rb_entry(parent, struct htb_class, node[prio]); if (cl->common.classid > c->common.classid) p = &parent->rb_right; else p = &parent->rb_left; } rb_link_node(&cl->node[prio], parent, p); rb_insert_color(&cl->node[prio], root); }

Contributors

PersonTokensPropCommitsCommitProp
david s. millerdavid s. miller7157.26%125.00%
stephen hemmingerstephen hemminger4838.71%125.00%
patrick mchardypatrick mchardy43.23%125.00%
david woodhousedavid woodhouse10.81%125.00%
Total124100.00%4100.00%

/** * htb_add_to_wait_tree - adds class to the event queue with delay * * The class is added to priority event queue to indicate that class will * change its mode in cl->pq_key microseconds. Make sure that class is not * already in the queue. */
static void htb_add_to_wait_tree(struct htb_sched *q, struct htb_class *cl, s64 delay) { struct rb_node **p = &q->hlevel[cl->level].wait_pq.rb_node, *parent = NULL; cl->pq_key = q->now + delay; if (cl->pq_key == q->now) cl->pq_key++; /* update the nearest event cache */ if (q->near_ev_cache[cl->level] > cl->pq_key) q->near_ev_cache[cl->level] = cl->pq_key; while (*p) { struct htb_class *c; parent = *p; c = rb_entry(parent, struct htb_class, pq_node); if (cl->pq_key >= c->pq_key) p = &parent->rb_right; else p = &parent->rb_left; } rb_link_node(&cl->pq_node, parent, p); rb_insert_color(&cl->pq_node, &q->hlevel[cl->level].wait_pq); }

Contributors

PersonTokensPropCommitsCommitProp
david s. millerdavid s. miller16790.76%116.67%
eric dumazeteric dumazet63.26%116.67%
patrick mchardypatrick mchardy42.17%116.67%
martin deveramartin devera42.17%116.67%
david woodhousedavid woodhouse21.09%116.67%
vimalkumarvimalkumar10.54%116.67%
Total184100.00%6100.00%

/** * htb_next_rb_node - finds next node in binary tree * * When we are past last key we return NULL. * Average complexity is 2 steps per call. */
static inline void htb_next_rb_node(struct rb_node **n) { *n = rb_next(*n); }

Contributors

PersonTokensPropCommitsCommitProp
david s. millerdavid s. miller1672.73%133.33%
david woodhousedavid woodhouse522.73%133.33%
stephen hemmingerstephen hemminger14.55%133.33%
Total22100.00%3100.00%

/** * htb_add_class_to_row - add class to its row * * The class is added to row at priorities marked in mask. * It does nothing if mask == 0. */
static inline void htb_add_class_to_row(struct htb_sched *q, struct htb_class *cl, int mask) { q->row_mask[cl->level] |= mask; while (mask) { int prio = ffz(~mask); mask &= ~(1 << prio); htb_add_to_id_tree(&q->hlevel[cl->level].hprio[prio].row, cl, prio); } }

Contributors

PersonTokensPropCommitsCommitProp
david s. millerdavid s. miller6075.95%133.33%
stephen hemmingerstephen hemminger1113.92%133.33%
eric dumazeteric dumazet810.13%133.33%
Total79100.00%3100.00%

/* If this triggers, it is a bug in this code, but it need not be fatal */
static void htb_safe_rb_erase(struct rb_node *rb, struct rb_root *root) { if (RB_EMPTY_NODE(rb)) { WARN_ON(1); } else { rb_erase(rb, root); RB_CLEAR_NODE(rb); } }

Contributors

PersonTokensPropCommitsCommitProp
stephen hemmingerstephen hemminger45100.00%1100.00%
Total45100.00%1100.00%

/** * htb_remove_class_from_row - removes class from its row * * The class is removed from row at priorities marked in mask. * It does nothing if mask == 0. */
static inline void htb_remove_class_from_row(struct htb_sched *q, struct htb_class *cl, int mask) { int m = 0; struct htb_level *hlevel = &q->hlevel[cl->level]; while (mask) { int prio = ffz(~mask); struct htb_prio *hprio = &hlevel->hprio[prio]; mask &= ~(1 << prio); if (hprio->ptr == cl->node + prio) htb_next_rb_node(&hprio->ptr); htb_safe_rb_erase(cl->node + prio, &hprio->row); if (!hprio->row.rb_node) m |= 1 << prio; } q->row_mask[cl->level] &= ~m; }

Contributors

PersonTokensPropCommitsCommitProp
david s. millerdavid s. miller10273.91%125.00%
eric dumazeteric dumazet3424.64%125.00%
stephen hemmingerstephen hemminger21.45%250.00%
Total138100.00%4100.00%

/** * htb_activate_prios - creates active classe's feed chain * * The class is connected to ancestors and/or appropriate rows * for priorities it is participating on. cl->cmode must be new * (activated) mode. It does nothing if cl->prio_activity == 0. */
static void htb_activate_prios(struct htb_sched *q, struct htb_class *cl) { struct htb_class *p = cl->parent; long m, mask = cl->prio_activity; while (cl->cmode == HTB_MAY_BORROW && p && mask) { m = mask; while (m) { int prio = ffz(~m); m &= ~(1 << prio); if (p->un.inner.clprio[prio].feed.rb_node) /* parent already has its feed in use so that * reset bit in mask as parent is already ok */ mask &= ~(1 << prio); htb_add_to_id_tree(&p->un.inner.clprio[prio].feed, cl, prio); } p->prio_activity |= mask; cl = p; p = cl->parent; } if (cl->cmode == HTB_CAN_SEND && mask) htb_add_class_to_row(q, cl, mask); }

Contributors

PersonTokensPropCommitsCommitProp
david s. millerdavid s. miller13786.16%125.00%
stephen hemmingerstephen hemminger127.55%125.00%
eric dumazeteric dumazet106.29%250.00%
Total159100.00%4100.00%

/** * htb_deactivate_prios - remove class from feed chain * * cl->cmode must represent old mode (before deactivation). It does * nothing if cl->prio_activity == 0. Class is removed from all feed * chains and rows. */
static void htb_deactivate_prios(struct htb_sched *q, struct htb_class *cl) { struct htb_class *p = cl->parent; long m, mask = cl->prio_activity; while (cl->cmode == HTB_MAY_BORROW && p && mask) { m = mask; mask = 0; while (m) { int prio = ffz(~m); m &= ~(1 << prio); if (p->un.inner.clprio[prio].ptr == cl->node + prio) { /* we are removing child which is pointed to from * parent feed - forget the pointer but remember * classid */ p->un.inner.clprio[prio].last_ptr_id = cl->common.classid; p->un.inner.clprio[prio].ptr = NULL; } htb_safe_rb_erase(cl->node + prio, &p->un.inner.clprio[prio].feed); if (!p->un.inner.clprio[prio].feed.rb_node) mask |= 1 << prio; } p->prio_activity &= ~mask; cl = p; p = cl->parent; } if (cl->cmode == HTB_CAN_SEND && mask) htb_remove_class_from_row(q, cl, mask); }

Contributors

PersonTokensPropCommitsCommitProp
david s. millerdavid s. miller17981.00%116.67%
martin deveramartin devera209.05%116.67%
eric dumazeteric dumazet198.60%233.33%
patrick mchardypatrick mchardy20.90%116.67%
stephen hemmingerstephen hemminger10.45%116.67%
Total221100.00%6100.00%


static inline s64 htb_lowater(const struct htb_class *cl) { if (htb_hysteresis) return cl->cmode != HTB_CANT_SEND ? -cl->cbuffer : 0; else return 0; }

Contributors

PersonTokensPropCommitsCommitProp
stephen hemmingerstephen hemminger2674.29%133.33%
jesper dangaard brouerjesper dangaard brouer822.86%133.33%
vimalkumarvimalkumar12.86%133.33%
Total35100.00%3100.00%


static inline s64 htb_hiwater(const struct htb_class *cl) { if (htb_hysteresis) return cl->cmode == HTB_CAN_SEND ? -cl->buffer : 0; else return 0; }

Contributors

PersonTokensPropCommitsCommitProp
stephen hemmingerstephen hemminger2674.29%133.33%
jesper dangaard brouerjesper dangaard brouer822.86%133.33%
vimalkumarvimalkumar12.86%133.33%
Total35100.00%3100.00%

/** * htb_class_mode - computes and returns current class mode * * It computes cl's mode at time cl->t_c+diff and returns it. If mode * is not HTB_CAN_SEND then cl->pq_key is updated to time difference * from now to time when cl will change its state. * Also it is worth to note that class mode doesn't change simply * at cl->{c,}tokens == 0 but there can rather be hysteresis of * 0 .. -cl->{c,}buffer range. It is meant to limit number of * mode transitions per time unit. The speed gain is about 1/6. */
static inline enum htb_cmode htb_class_mode(struct htb_class *cl, s64 *diff) { s64 toks; if ((toks = (cl->ctokens + *diff)) < htb_lowater(cl)) { *diff = -toks; return HTB_CANT_SEND; } if ((toks = (cl->tokens + *diff)) >= htb_hiwater(cl)) return HTB_CAN_SEND; *diff = -toks; return HTB_MAY_BORROW; }

Contributors

PersonTokensPropCommitsCommitProp
david s. millerdavid s. miller7489.16%125.00%
stephen hemmingerstephen hemminger78.43%250.00%
vimalkumarvimalkumar22.41%125.00%
Total83100.00%4100.00%

/** * htb_change_class_mode - changes classe's mode * * This should be the only way how to change classe's mode under normal * cirsumstances. Routine will update feed lists linkage, change mode * and add class to the wait event queue if appropriate. New mode should * be different from old one and cl->pq_key has to be valid if changing * to mode other than HTB_CAN_SEND (see htb_add_to_wait_tree). */
static void htb_change_class_mode(struct htb_sched *q, struct htb_class *cl, s64 *diff) { enum htb_cmode new_mode = htb_class_mode(cl, diff); if (new_mode == cl->cmode) return; if (cl->prio_activity) { /* not necessary: speed optimization */ if (cl->cmode != HTB_CANT_SEND) htb_deactivate_prios(q, cl); cl->cmode = new_mode; if (new_mode != HTB_CANT_SEND) htb_activate_prios(q, cl); } else cl->cmode = new_mode; }

Contributors

PersonTokensPropCommitsCommitProp
david s. millerdavid s. miller8897.78%133.33%
vimalkumarvimalkumar11.11%133.33%
michael hayesmichael hayes11.11%133.33%
Total90100.00%3100.00%

/** * htb_activate - inserts leaf cl into appropriate active feeds * * Routine learns (new) priority of leaf and activates feed chain * for the prio. It can be called on already active leaf safely. * It also adds leaf into droplist. */
static inline void htb_activate(struct htb_sched *q, struct htb_class *cl) { WARN_ON(cl->level || !cl->un.leaf.q || !cl->un.leaf.q->q.qlen); if (!cl->prio_activity) { cl->prio_activity = 1 << cl->prio; htb_activate_prios(q, cl); list_add_tail(&cl->un.leaf.drop_list, q->drops + cl->prio); } }

Contributors

PersonTokensPropCommitsCommitProp
david s. millerdavid s. miller8592.39%125.00%
ilpo jarvinenilpo jarvinen55.43%125.00%
jarek poplawskijarek poplawski11.09%125.00%
stephen hemmingerstephen hemminger11.09%125.00%
Total92100.00%4100.00%

/** * htb_deactivate - remove leaf cl from active feeds * * Make sure that leaf is active. In the other words it can't be called * with non-active leaf. It also removes class from the drop list. */
static inline void htb_deactivate(struct htb_sched *q, struct htb_class *cl) { WARN_ON(!cl->prio_activity); htb_deactivate_prios(q, cl); cl->prio_activity = 0; list_del_init(&cl->un.leaf.drop_list); }

Contributors

PersonTokensPropCommitsCommitProp
david s. millerdavid s. miller4794.00%133.33%
ilpo jarvinenilpo jarvinen24.00%133.33%
stephen hemmingerstephen hemminger12.00%133.33%
Total50100.00%3100.00%


static int htb_enqueue(struct sk_buff *skb, struct Qdisc *sch, struct sk_buff **to_free) { int uninitialized_var(ret); struct htb_sched *q = qdisc_priv(sch); struct htb_class *cl = htb_classify(skb, sch, &ret); if (cl == HTB_DIRECT) { /* enqueue to helper queue */ if (q->direct_queue.qlen < q->direct_qlen) { __skb_queue_tail(&q->direct_queue, skb); q->direct_pkts++; } else { return qdisc_drop(skb, sch, to_free); } #ifdef CONFIG_NET_CLS_ACT } else if (!cl) { if (ret & __NET_XMIT_BYPASS) qdisc_qstats_drop(sch); __qdisc_drop(skb, to_free); return ret; #endif } else if ((ret = qdisc_enqueue(skb, cl->un.leaf.q, to_free)) != NET_XMIT_SUCCESS) { if (net_xmit_drop_count(ret)) { qdisc_qstats_drop(sch); cl->drops++; } return ret; } else { htb_activate(q, cl); } qdisc_qstats_backlog_inc(sch, skb); sch->q.qlen++; return NET_XMIT_SUCCESS; }

Contributors

PersonTokensPropCommitsCommitProp
david s. millerdavid s. miller9042.25%214.29%
jamal hadi salimjamal hadi salim5827.23%17.14%
jarek poplawskijarek poplawski188.45%321.43%
eric dumazeteric dumazet177.98%214.29%
americo wangamerico wang73.29%17.14%
asim shankarasim shankar73.29%17.14%
patrick mchardypatrick mchardy62.82%17.14%
john fastabendjohn fastabend62.82%17.14%
stephen hemmingerstephen hemminger31.41%17.14%
jussi kivilinnajussi kivilinna10.47%17.14%
Total213100.00%14100.00%


static inline void htb_accnt_tokens(struct htb_class *cl, int bytes, s64 diff) { s64 toks = diff + cl->tokens; if (toks > cl->buffer) toks = cl->buffer; toks -= (s64) psched_l2t_ns(&cl->rate, bytes); if (toks <= -cl->mbuffer) toks = 1 - cl->mbuffer; cl->tokens = toks; }

Contributors

PersonTokensPropCommitsCommitProp
jarek poplawskijarek poplawski7493.67%133.33%
vimalkumarvimalkumar45.06%133.33%
jiri pirkojiri pirko11.27%133.33%
Total79100.00%3100.00%


static inline void htb_accnt_ctokens(struct htb_class *cl, int bytes, s64 diff) { s64 toks = diff + cl->ctokens; if (toks > cl->cbuffer) toks = cl->cbuffer; toks -= (s64) psched_l2t_ns(&cl->ceil, bytes); if (toks <= -cl->mbuffer) toks = 1 - cl->mbuffer; cl->ctokens = toks; }

Contributors

PersonTokensPropCommitsCommitProp
jarek poplawskijarek poplawski7493.67%133.33%
vimalkumarvimalkumar45.06%133.33%
jiri pirkojiri pirko11.27%133.33%
Total79100.00%3100.00%

/** * htb_charge_class - charges amount "bytes" to leaf and ancestors * * Routine assumes that packet "bytes" long was dequeued from leaf cl * borrowing from "level". It accounts bytes to ceil leaky bucket for * leaf and all ancestors and to rate bucket for ancestors at levels * "level" and higher. It also handles possible change of mode resulting * from the update. Note that mode can also increase here (MAY_BORROW to * CAN_SEND) because we can use more precise clock that event queue here. * In such case we remove class from event queue first. */
static void htb_charge_class(struct htb_sched *q, struct htb_class *cl, int level, struct sk_buff *skb) { int bytes = qdisc_pkt_len(skb); enum htb_cmode old_mode; s64 diff; while (cl) { diff = min_t(s64, q->now - cl->t_c, cl->mbuffer); if (cl->level >= level) { if (cl->level == level) cl->xstats.lends++; htb_accnt_tokens(cl, bytes, diff); } else { cl->xstats.borrows++; cl->tokens += diff; /* we moved t_c; update tokens */ } htb_accnt_ctokens(cl, bytes, diff); cl->t_c = q->now; old_mode = cl->cmode; diff = 0; htb_change_class_mode(q, cl, &diff); if (old_mode != cl->cmode) { if (old_mode != HTB_CAN_SEND) htb_safe_rb_erase(&cl->pq_node, &q->hlevel[cl->level].wait_pq); if (cl->cmode != HTB_CAN_SEND) htb_add_to_wait_tree(q, cl, diff); } /* update basic stats except for leaves which are already updated */ if (cl->level) bstats_update(&cl->bstats, skb); cl = cl->parent; } }

Contributors

PersonTokensPropCommitsCommitProp
david s. millerdavid s. miller17576.75%19.09%
ranjit manomohanranjit manomohan114.82%19.09%
eric dumazeteric dumazet114.82%218.18%
jarek poplawskijarek poplawski104.39%19.09%
stephen hemmingerstephen hemminger62.63%218.18%
patrick mchardypatrick mchardy62.63%19.09%
vimalkumarvimalkumar52.19%19.09%
jussi kivilinnajussi kivilinna31.32%19.09%
thomas grafthomas graf10.44%19.09%
Total228100.00%11100.00%

/** * htb_do_events - make mode changes to classes at the level * * Scans event queue for pending events and applies them. Returns time of * next pending event (0 for no event in pq, q->now for too many events). * Note: Applied are events whose have cl->pq_key <= q->now. */
static s64 htb_do_events(struct htb_sched *q, const int level, unsigned long start) { /* don't run for longer than 2 jiffies; 2 is used instead of * 1 to simplify things when jiffy is going to be incremented * too soon */ unsigned long stop_at = start + 2; struct rb_root *wait_pq = &q->hlevel[level].wait_pq; while (time_before(jiffies, stop_at)) { struct htb_class *cl; s64 diff; struct rb_node *p = rb_first(wait_pq); if (!p) return 0; cl = rb_entry(p, struct htb_class, pq_node); if (cl->pq_key > q->now) return cl->pq_key; htb_safe_rb_erase(p, wait_pq); diff = min_t(s64, q->now - cl->t_c, cl->mbuffer); htb_change_class_mode(q, cl, &diff