Commit be0d39d5 authored by Patrick McHardy's avatar Patrick McHardy Committed by David S. Miller

net-sched: sch_hfsc: use dynamic class hash helpers

Signed-off-by: default avatarPatrick McHardy <kaber@trash.net>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6fe1c7a5
...@@ -113,7 +113,7 @@ enum hfsc_class_flags ...@@ -113,7 +113,7 @@ enum hfsc_class_flags
struct hfsc_class struct hfsc_class
{ {
u32 classid; /* class id */ struct Qdisc_class_common cl_common;
unsigned int refcnt; /* usage count */ unsigned int refcnt; /* usage count */
struct gnet_stats_basic bstats; struct gnet_stats_basic bstats;
...@@ -134,7 +134,6 @@ struct hfsc_class ...@@ -134,7 +134,6 @@ struct hfsc_class
struct rb_node vt_node; /* parent's vt_tree member */ struct rb_node vt_node; /* parent's vt_tree member */
struct rb_root cf_tree; /* active children sorted by cl_f */ struct rb_root cf_tree; /* active children sorted by cl_f */
struct rb_node cf_node; /* parent's cf_heap member */ struct rb_node cf_node; /* parent's cf_heap member */
struct list_head hlist; /* hash list member */
struct list_head dlist; /* drop list member */ struct list_head dlist; /* drop list member */
u64 cl_total; /* total work in bytes */ u64 cl_total; /* total work in bytes */
...@@ -177,13 +176,11 @@ struct hfsc_class ...@@ -177,13 +176,11 @@ struct hfsc_class
unsigned long cl_nactive; /* number of active children */ unsigned long cl_nactive; /* number of active children */
}; };
#define HFSC_HSIZE 16
struct hfsc_sched struct hfsc_sched
{ {
u16 defcls; /* default class id */ u16 defcls; /* default class id */
struct hfsc_class root; /* root class */ struct hfsc_class root; /* root class */
struct list_head clhash[HFSC_HSIZE]; /* class hash */ struct Qdisc_class_hash clhash; /* class hash */
struct rb_root eligible; /* eligible tree */ struct rb_root eligible; /* eligible tree */
struct list_head droplist; /* active leaf class list (for struct list_head droplist; /* active leaf class list (for
dropping) */ dropping) */
...@@ -933,26 +930,16 @@ hfsc_adjust_levels(struct hfsc_class *cl) ...@@ -933,26 +930,16 @@ hfsc_adjust_levels(struct hfsc_class *cl)
} while ((cl = cl->cl_parent) != NULL); } while ((cl = cl->cl_parent) != NULL);
} }
static inline unsigned int
hfsc_hash(u32 h)
{
h ^= h >> 8;
h ^= h >> 4;
return h & (HFSC_HSIZE - 1);
}
static inline struct hfsc_class * static inline struct hfsc_class *
hfsc_find_class(u32 classid, struct Qdisc *sch) hfsc_find_class(u32 classid, struct Qdisc *sch)
{ {
struct hfsc_sched *q = qdisc_priv(sch); struct hfsc_sched *q = qdisc_priv(sch);
struct hfsc_class *cl; struct Qdisc_class_common *clc;
list_for_each_entry(cl, &q->clhash[hfsc_hash(classid)], hlist) { clc = qdisc_class_find(&q->clhash, classid);
if (cl->classid == classid) if (clc == NULL)
return cl;
}
return NULL; return NULL;
return container_of(clc, struct hfsc_class, cl_common);
} }
static void static void
...@@ -1032,7 +1019,8 @@ hfsc_change_class(struct Qdisc *sch, u32 classid, u32 parentid, ...@@ -1032,7 +1019,8 @@ hfsc_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
if (cl != NULL) { if (cl != NULL) {
if (parentid) { if (parentid) {
if (cl->cl_parent && cl->cl_parent->classid != parentid) if (cl->cl_parent &&
cl->cl_parent->cl_common.classid != parentid)
return -EINVAL; return -EINVAL;
if (cl->cl_parent == NULL && parentid != TC_H_ROOT) if (cl->cl_parent == NULL && parentid != TC_H_ROOT)
return -EINVAL; return -EINVAL;
...@@ -1091,8 +1079,8 @@ hfsc_change_class(struct Qdisc *sch, u32 classid, u32 parentid, ...@@ -1091,8 +1079,8 @@ hfsc_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
if (usc != NULL) if (usc != NULL)
hfsc_change_usc(cl, usc, 0); hfsc_change_usc(cl, usc, 0);
cl->cl_common.classid = classid;
cl->refcnt = 1; cl->refcnt = 1;
cl->classid = classid;
cl->sched = q; cl->sched = q;
cl->cl_parent = parent; cl->cl_parent = parent;
cl->qdisc = qdisc_create_dflt(sch->dev, &pfifo_qdisc_ops, classid); cl->qdisc = qdisc_create_dflt(sch->dev, &pfifo_qdisc_ops, classid);
...@@ -1103,7 +1091,7 @@ hfsc_change_class(struct Qdisc *sch, u32 classid, u32 parentid, ...@@ -1103,7 +1091,7 @@ hfsc_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
cl->cf_tree = RB_ROOT; cl->cf_tree = RB_ROOT;
sch_tree_lock(sch); sch_tree_lock(sch);
list_add_tail(&cl->hlist, &q->clhash[hfsc_hash(classid)]); qdisc_class_hash_insert(&q->clhash, &cl->cl_common);
list_add_tail(&cl->siblings, &parent->children); list_add_tail(&cl->siblings, &parent->children);
if (parent->level == 0) if (parent->level == 0)
hfsc_purge_queue(sch, parent); hfsc_purge_queue(sch, parent);
...@@ -1111,6 +1099,8 @@ hfsc_change_class(struct Qdisc *sch, u32 classid, u32 parentid, ...@@ -1111,6 +1099,8 @@ hfsc_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
cl->cl_pcvtoff = parent->cl_cvtoff; cl->cl_pcvtoff = parent->cl_cvtoff;
sch_tree_unlock(sch); sch_tree_unlock(sch);
qdisc_class_hash_grow(sch, &q->clhash);
if (tca[TCA_RATE]) if (tca[TCA_RATE])
gen_new_estimator(&cl->bstats, &cl->rate_est, gen_new_estimator(&cl->bstats, &cl->rate_est,
&sch->dev->queue_lock, tca[TCA_RATE]); &sch->dev->queue_lock, tca[TCA_RATE]);
...@@ -1145,7 +1135,7 @@ hfsc_delete_class(struct Qdisc *sch, unsigned long arg) ...@@ -1145,7 +1135,7 @@ hfsc_delete_class(struct Qdisc *sch, unsigned long arg)
hfsc_adjust_levels(cl->cl_parent); hfsc_adjust_levels(cl->cl_parent);
hfsc_purge_queue(sch, cl); hfsc_purge_queue(sch, cl);
list_del(&cl->hlist); qdisc_class_hash_remove(&q->clhash, &cl->cl_common);
if (--cl->refcnt == 0) if (--cl->refcnt == 0)
hfsc_destroy_class(sch, cl); hfsc_destroy_class(sch, cl);
...@@ -1212,7 +1202,7 @@ hfsc_graft_class(struct Qdisc *sch, unsigned long arg, struct Qdisc *new, ...@@ -1212,7 +1202,7 @@ hfsc_graft_class(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
return -EINVAL; return -EINVAL;
if (new == NULL) { if (new == NULL) {
new = qdisc_create_dflt(sch->dev, &pfifo_qdisc_ops, new = qdisc_create_dflt(sch->dev, &pfifo_qdisc_ops,
cl->classid); cl->cl_common.classid);
if (new == NULL) if (new == NULL)
new = &noop_qdisc; new = &noop_qdisc;
} }
...@@ -1345,8 +1335,9 @@ hfsc_dump_class(struct Qdisc *sch, unsigned long arg, struct sk_buff *skb, ...@@ -1345,8 +1335,9 @@ hfsc_dump_class(struct Qdisc *sch, unsigned long arg, struct sk_buff *skb,
struct hfsc_class *cl = (struct hfsc_class *)arg; struct hfsc_class *cl = (struct hfsc_class *)arg;
struct nlattr *nest; struct nlattr *nest;
tcm->tcm_parent = cl->cl_parent ? cl->cl_parent->classid : TC_H_ROOT; tcm->tcm_parent = cl->cl_parent ? cl->cl_parent->cl_common.classid :
tcm->tcm_handle = cl->classid; TC_H_ROOT;
tcm->tcm_handle = cl->cl_common.classid;
if (cl->level == 0) if (cl->level == 0)
tcm->tcm_info = cl->qdisc->handle; tcm->tcm_info = cl->qdisc->handle;
...@@ -1390,14 +1381,16 @@ static void ...@@ -1390,14 +1381,16 @@ static void
hfsc_walk(struct Qdisc *sch, struct qdisc_walker *arg) hfsc_walk(struct Qdisc *sch, struct qdisc_walker *arg)
{ {
struct hfsc_sched *q = qdisc_priv(sch); struct hfsc_sched *q = qdisc_priv(sch);
struct hlist_node *n;
struct hfsc_class *cl; struct hfsc_class *cl;
unsigned int i; unsigned int i;
if (arg->stop) if (arg->stop)
return; return;
for (i = 0; i < HFSC_HSIZE; i++) { for (i = 0; i < q->clhash.hashsize; i++) {
list_for_each_entry(cl, &q->clhash[i], hlist) { hlist_for_each_entry(cl, n, &q->clhash.hash[i],
cl_common.hnode) {
if (arg->count < arg->skip) { if (arg->count < arg->skip) {
arg->count++; arg->count++;
continue; continue;
...@@ -1433,21 +1426,22 @@ hfsc_init_qdisc(struct Qdisc *sch, struct nlattr *opt) ...@@ -1433,21 +1426,22 @@ hfsc_init_qdisc(struct Qdisc *sch, struct nlattr *opt)
{ {
struct hfsc_sched *q = qdisc_priv(sch); struct hfsc_sched *q = qdisc_priv(sch);
struct tc_hfsc_qopt *qopt; struct tc_hfsc_qopt *qopt;
unsigned int i; int err;
if (opt == NULL || nla_len(opt) < sizeof(*qopt)) if (opt == NULL || nla_len(opt) < sizeof(*qopt))
return -EINVAL; return -EINVAL;
qopt = nla_data(opt); qopt = nla_data(opt);
q->defcls = qopt->defcls; q->defcls = qopt->defcls;
for (i = 0; i < HFSC_HSIZE; i++) err = qdisc_class_hash_init(&q->clhash);
INIT_LIST_HEAD(&q->clhash[i]); if (err < 0)
return err;
q->eligible = RB_ROOT; q->eligible = RB_ROOT;
INIT_LIST_HEAD(&q->droplist); INIT_LIST_HEAD(&q->droplist);
skb_queue_head_init(&q->requeue); skb_queue_head_init(&q->requeue);
q->root.cl_common.classid = sch->handle;
q->root.refcnt = 1; q->root.refcnt = 1;
q->root.classid = sch->handle;
q->root.sched = q; q->root.sched = q;
q->root.qdisc = qdisc_create_dflt(sch->dev, &pfifo_qdisc_ops, q->root.qdisc = qdisc_create_dflt(sch->dev, &pfifo_qdisc_ops,
sch->handle); sch->handle);
...@@ -1457,7 +1451,8 @@ hfsc_init_qdisc(struct Qdisc *sch, struct nlattr *opt) ...@@ -1457,7 +1451,8 @@ hfsc_init_qdisc(struct Qdisc *sch, struct nlattr *opt)
q->root.vt_tree = RB_ROOT; q->root.vt_tree = RB_ROOT;
q->root.cf_tree = RB_ROOT; q->root.cf_tree = RB_ROOT;
list_add(&q->root.hlist, &q->clhash[hfsc_hash(q->root.classid)]); qdisc_class_hash_insert(&q->clhash, &q->root.cl_common);
qdisc_class_hash_grow(sch, &q->clhash);
qdisc_watchdog_init(&q->watchdog, sch); qdisc_watchdog_init(&q->watchdog, sch);
...@@ -1520,10 +1515,11 @@ hfsc_reset_qdisc(struct Qdisc *sch) ...@@ -1520,10 +1515,11 @@ hfsc_reset_qdisc(struct Qdisc *sch)
{ {
struct hfsc_sched *q = qdisc_priv(sch); struct hfsc_sched *q = qdisc_priv(sch);
struct hfsc_class *cl; struct hfsc_class *cl;
struct hlist_node *n;
unsigned int i; unsigned int i;
for (i = 0; i < HFSC_HSIZE; i++) { for (i = 0; i < q->clhash.hashsize; i++) {
list_for_each_entry(cl, &q->clhash[i], hlist) hlist_for_each_entry(cl, n, &q->clhash.hash[i], cl_common.hnode)
hfsc_reset_class(cl); hfsc_reset_class(cl);
} }
__skb_queue_purge(&q->requeue); __skb_queue_purge(&q->requeue);
...@@ -1537,17 +1533,20 @@ static void ...@@ -1537,17 +1533,20 @@ static void
hfsc_destroy_qdisc(struct Qdisc *sch) hfsc_destroy_qdisc(struct Qdisc *sch)
{ {
struct hfsc_sched *q = qdisc_priv(sch); struct hfsc_sched *q = qdisc_priv(sch);
struct hfsc_class *cl, *next; struct hlist_node *n, *next;
struct hfsc_class *cl;
unsigned int i; unsigned int i;
for (i = 0; i < HFSC_HSIZE; i++) { for (i = 0; i < q->clhash.hashsize; i++) {
list_for_each_entry(cl, &q->clhash[i], hlist) hlist_for_each_entry(cl, n, &q->clhash.hash[i], cl_common.hnode)
tcf_destroy_chain(&cl->filter_list); tcf_destroy_chain(&cl->filter_list);
} }
for (i = 0; i < HFSC_HSIZE; i++) { for (i = 0; i < q->clhash.hashsize; i++) {
list_for_each_entry_safe(cl, next, &q->clhash[i], hlist) hlist_for_each_entry_safe(cl, n, next, &q->clhash.hash[i],
cl_common.hnode)
hfsc_destroy_class(sch, cl); hfsc_destroy_class(sch, cl);
} }
qdisc_class_hash_destroy(&q->clhash);
__skb_queue_purge(&q->requeue); __skb_queue_purge(&q->requeue);
qdisc_watchdog_cancel(&q->watchdog); qdisc_watchdog_cancel(&q->watchdog);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment