cregit-Linux how code gets into the kernel

Release 4.11 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>
#include <net/pkt_cls.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 net_rate_estimator __rcu *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 qdisc_skb_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 Hemminger2539.06%360.00%
Patrick McHardy2234.38%120.00%
David 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. Miller19769.61%218.18%
Jamal Hadi Salim238.13%19.09%
Harry Mason207.07%19.09%
Eric Dumazet155.30%19.09%
John Fastabend93.18%19.09%
Patrick McHardy72.47%19.09%
Martin Devera51.77%19.09%
Stephen Hemminger31.06%19.09%
Jarek Poplawski20.71%19.09%
Daniel 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. Miller7157.26%125.00%
Stephen Hemminger4838.71%125.00%
Patrick McHardy43.23%125.00%
David 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. Miller16790.76%116.67%
Eric Dumazet63.26%116.67%
Patrick McHardy42.17%116.67%
Martin Devera42.17%116.67%
David Woodhouse21.09%116.67%
Vimalkumar10.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. Miller1672.73%133.33%
David Woodhouse522.73%133.33%
Stephen 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. Miller6075.95%133.33%
Stephen Hemminger1113.92%133.33%
Eric 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 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. Miller10273.91%125.00%
Eric Dumazet3424.64%125.00%
Stephen 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. Miller13786.16%125.00%
Stephen Hemminger127.55%125.00%
Eric 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. Miller17981.00%116.67%
Martin Devera209.05%116.67%
Eric Dumazet198.60%233.33%
Patrick McHardy20.90%116.67%
Stephen 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 Hemminger2674.29%133.33%
Jesper Dangaard Brouer822.86%133.33%
Vimalkumar12.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 Hemminger2674.29%133.33%
Jesper Dangaard Brouer822.86%133.33%
Vimalkumar12.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. Miller7489.16%125.00%
Stephen Hemminger78.43%250.00%
Vimalkumar22.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. Miller8897.78%133.33%
Michael Hayes11.11%133.33%
Vimalkumar11.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. Miller8592.39%125.00%
Ilpo Järvinen55.43%125.00%
Stephen Hemminger11.09%125.00%
Jarek Poplawski11.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. Miller4794.00%133.33%
Ilpo Järvinen24.00%133.33%
Stephen Hemminger12.00%133.33%
Total50100.00%3100.00%


static void htb_enqueue_tail(struct sk_buff *skb, struct Qdisc *sch, struct qdisc_skb_head *qh) { struct sk_buff *last = qh->tail; if (last) { skb->next = NULL; last->next = skb; qh->tail = skb; } else { qh->tail = skb; qh->head = skb; } qh->qlen++; }

Contributors

PersonTokensPropCommitsCommitProp
Florian Westphal74100.00%1100.00%
Total74100.00%1100.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) { htb_enqueue_tail(skb, sch, &q->direct_queue); 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. Miller9041.86%213.33%
Jamal Hadi Salim5525.58%16.67%
Jarek Poplawski188.37%320.00%
Eric Dumazet177.91%213.33%
Asim Shankar73.26%16.67%
Américo Wang73.26%16.67%
John Fastabend62.79%16.67%
Patrick McHardy62.79%16.67%
Florian Westphal52.33%16.67%
Stephen Hemminger31.40%16.67%
Jussi Kivilinna10.47%16.67%
Total215100.00%15100.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 Poplawski7493.67%133.33%
Vimalkumar45.06%133.33%
Jiri 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 Poplawski7493.67%133.33%
Vimalkumar45.06%133.33%
Jiri 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. Miller17576.75%19.09%
Ranjit Manomohan114.82%19.09%
Eric Dumazet114.82%218.18%
Jarek Poplawski104.39%19.09%
Patrick McHardy62.63%19.09%
Stephen Hemminger62.63%218.18%
Vimalkumar52.19%19.09%
Jussi Kivilinna31.32%19.09%
Thomas 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); if (cl->cmode != HTB_CAN_SEND) htb_add_to_wait_tree(q, cl