Release 4.11 net/sched/sch_htb.c
/*
* 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
Person | Tokens | Prop | Commits | CommitProp |
Stephen Hemminger | 25 | 39.06% | 3 | 60.00% |
Patrick McHardy | 22 | 34.38% | 1 | 20.00% |
David S. Miller | 17 | 26.56% | 1 | 20.00% |
Total | 64 | 100.00% | 5 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
David S. Miller | 197 | 69.61% | 2 | 18.18% |
Jamal Hadi Salim | 23 | 8.13% | 1 | 9.09% |
Harry Mason | 20 | 7.07% | 1 | 9.09% |
Eric Dumazet | 15 | 5.30% | 1 | 9.09% |
John Fastabend | 9 | 3.18% | 1 | 9.09% |
Patrick McHardy | 7 | 2.47% | 1 | 9.09% |
Martin Devera | 5 | 1.77% | 1 | 9.09% |
Stephen Hemminger | 3 | 1.06% | 1 | 9.09% |
Jarek Poplawski | 2 | 0.71% | 1 | 9.09% |
Daniel Borkmann | 2 | 0.71% | 1 | 9.09% |
Total | 283 | 100.00% | 11 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
David S. Miller | 71 | 57.26% | 1 | 25.00% |
Stephen Hemminger | 48 | 38.71% | 1 | 25.00% |
Patrick McHardy | 4 | 3.23% | 1 | 25.00% |
David Woodhouse | 1 | 0.81% | 1 | 25.00% |
Total | 124 | 100.00% | 4 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
David S. Miller | 167 | 90.76% | 1 | 16.67% |
Eric Dumazet | 6 | 3.26% | 1 | 16.67% |
Patrick McHardy | 4 | 2.17% | 1 | 16.67% |
Martin Devera | 4 | 2.17% | 1 | 16.67% |
David Woodhouse | 2 | 1.09% | 1 | 16.67% |
Vimalkumar | 1 | 0.54% | 1 | 16.67% |
Total | 184 | 100.00% | 6 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
David S. Miller | 16 | 72.73% | 1 | 33.33% |
David Woodhouse | 5 | 22.73% | 1 | 33.33% |
Stephen Hemminger | 1 | 4.55% | 1 | 33.33% |
Total | 22 | 100.00% | 3 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
David S. Miller | 60 | 75.95% | 1 | 33.33% |
Stephen Hemminger | 11 | 13.92% | 1 | 33.33% |
Eric Dumazet | 8 | 10.13% | 1 | 33.33% |
Total | 79 | 100.00% | 3 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Stephen Hemminger | 45 | 100.00% | 1 | 100.00% |
Total | 45 | 100.00% | 1 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
David S. Miller | 102 | 73.91% | 1 | 25.00% |
Eric Dumazet | 34 | 24.64% | 1 | 25.00% |
Stephen Hemminger | 2 | 1.45% | 2 | 50.00% |
Total | 138 | 100.00% | 4 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
David S. Miller | 137 | 86.16% | 1 | 25.00% |
Stephen Hemminger | 12 | 7.55% | 1 | 25.00% |
Eric Dumazet | 10 | 6.29% | 2 | 50.00% |
Total | 159 | 100.00% | 4 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
David S. Miller | 179 | 81.00% | 1 | 16.67% |
Martin Devera | 20 | 9.05% | 1 | 16.67% |
Eric Dumazet | 19 | 8.60% | 2 | 33.33% |
Patrick McHardy | 2 | 0.90% | 1 | 16.67% |
Stephen Hemminger | 1 | 0.45% | 1 | 16.67% |
Total | 221 | 100.00% | 6 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Stephen Hemminger | 26 | 74.29% | 1 | 33.33% |
Jesper Dangaard Brouer | 8 | 22.86% | 1 | 33.33% |
Vimalkumar | 1 | 2.86% | 1 | 33.33% |
Total | 35 | 100.00% | 3 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Stephen Hemminger | 26 | 74.29% | 1 | 33.33% |
Jesper Dangaard Brouer | 8 | 22.86% | 1 | 33.33% |
Vimalkumar | 1 | 2.86% | 1 | 33.33% |
Total | 35 | 100.00% | 3 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
David S. Miller | 74 | 89.16% | 1 | 25.00% |
Stephen Hemminger | 7 | 8.43% | 2 | 50.00% |
Vimalkumar | 2 | 2.41% | 1 | 25.00% |
Total | 83 | 100.00% | 4 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
David S. Miller | 88 | 97.78% | 1 | 33.33% |
Michael Hayes | 1 | 1.11% | 1 | 33.33% |
Vimalkumar | 1 | 1.11% | 1 | 33.33% |
Total | 90 | 100.00% | 3 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
David S. Miller | 85 | 92.39% | 1 | 25.00% |
Ilpo Järvinen | 5 | 5.43% | 1 | 25.00% |
Stephen Hemminger | 1 | 1.09% | 1 | 25.00% |
Jarek Poplawski | 1 | 1.09% | 1 | 25.00% |
Total | 92 | 100.00% | 4 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
David S. Miller | 47 | 94.00% | 1 | 33.33% |
Ilpo Järvinen | 2 | 4.00% | 1 | 33.33% |
Stephen Hemminger | 1 | 2.00% | 1 | 33.33% |
Total | 50 | 100.00% | 3 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Florian Westphal | 74 | 100.00% | 1 | 100.00% |
Total | 74 | 100.00% | 1 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
David S. Miller | 90 | 41.86% | 2 | 13.33% |
Jamal Hadi Salim | 55 | 25.58% | 1 | 6.67% |
Jarek Poplawski | 18 | 8.37% | 3 | 20.00% |
Eric Dumazet | 17 | 7.91% | 2 | 13.33% |
Asim Shankar | 7 | 3.26% | 1 | 6.67% |
Américo Wang | 7 | 3.26% | 1 | 6.67% |
John Fastabend | 6 | 2.79% | 1 | 6.67% |
Patrick McHardy | 6 | 2.79% | 1 | 6.67% |
Florian Westphal | 5 | 2.33% | 1 | 6.67% |
Stephen Hemminger | 3 | 1.40% | 1 | 6.67% |
Jussi Kivilinna | 1 | 0.47% | 1 | 6.67% |
Total | 215 | 100.00% | 15 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Jarek Poplawski | 74 | 93.67% | 1 | 33.33% |
Vimalkumar | 4 | 5.06% | 1 | 33.33% |
Jiri Pirko | 1 | 1.27% | 1 | 33.33% |
Total | 79 | 100.00% | 3 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Jarek Poplawski | 74 | 93.67% | 1 | 33.33% |
Vimalkumar | 4 | 5.06% | 1 | 33.33% |
Jiri Pirko | 1 | 1.27% | 1 | 33.33% |
Total | 79 | 100.00% | 3 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
David S. Miller | 175 | 76.75% | 1 | 9.09% |
Ranjit Manomohan | 11 | 4.82% | 1 | 9.09% |
Eric Dumazet | 11 | 4.82% | 2 | 18.18% |
Jarek Poplawski | 10 | 4.39% | 1 | 9.09% |
Patrick McHardy | 6 | 2.63% | 1 | 9.09% |
Stephen Hemminger | 6 | 2.63% | 2 | 18.18% |
Vimalkumar | 5 | 2.19% | 1 | 9.09% |
Jussi Kivilinna | 3 | 1.32% | 1 | 9.09% |
Thomas Graf | 1 | 0.44% | 1 | 9.09% |
Total | 228 | 100.00% | 11 | 100.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