Skip to content

Commit

Permalink
sch_htb: Stats for offloaded HTB
Browse files Browse the repository at this point in the history
This commit adds support for statistics of offloaded HTB. Bytes and
packets counters for leaf and inner nodes are supported, the values are
taken from per-queue qdiscs, and the numbers that the user sees should
have the same behavior as the software (non-offloaded) HTB.

Signed-off-by: Maxim Mikityanskiy <maximmi@mellanox.com>
Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Maxim Mikityanskiy authored and Jakub Kicinski committed Jan 23, 2021
1 parent d03b195 commit 8327158
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions net/sched/sch_htb.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ struct htb_class {
* Written often fields
*/
struct gnet_stats_basic_packed bstats;
struct gnet_stats_basic_packed bstats_bias;
struct tc_htb_xstats xstats; /* our special stats */

/* token bucket parameters */
Expand Down Expand Up @@ -1220,6 +1221,7 @@ static int htb_dump_class(struct Qdisc *sch, unsigned long arg,
struct sk_buff *skb, struct tcmsg *tcm)
{
struct htb_class *cl = (struct htb_class *)arg;
struct htb_sched *q = qdisc_priv(sch);
struct nlattr *nest;
struct tc_htb_opt opt;

Expand All @@ -1246,6 +1248,8 @@ static int htb_dump_class(struct Qdisc *sch, unsigned long arg,
opt.level = cl->level;
if (nla_put(skb, TCA_HTB_PARMS, sizeof(opt), &opt))
goto nla_put_failure;
if (q->offload && nla_put_flag(skb, TCA_HTB_OFFLOAD))
goto nla_put_failure;
if ((cl->rate.rate_bytes_ps >= (1ULL << 32)) &&
nla_put_u64_64bit(skb, TCA_HTB_RATE64, cl->rate.rate_bytes_ps,
TCA_HTB_PAD))
Expand All @@ -1262,10 +1266,39 @@ static int htb_dump_class(struct Qdisc *sch, unsigned long arg,
return -1;
}

static void htb_offload_aggregate_stats(struct htb_sched *q,
struct htb_class *cl)
{
struct htb_class *c;
unsigned int i;

memset(&cl->bstats, 0, sizeof(cl->bstats));

for (i = 0; i < q->clhash.hashsize; i++) {
hlist_for_each_entry(c, &q->clhash.hash[i], common.hnode) {
struct htb_class *p = c;

while (p && p->level < cl->level)
p = p->parent;

if (p != cl)
continue;

cl->bstats.bytes += c->bstats_bias.bytes;
cl->bstats.packets += c->bstats_bias.packets;
if (c->level == 0) {
cl->bstats.bytes += c->leaf.q->bstats.bytes;
cl->bstats.packets += c->leaf.q->bstats.packets;
}
}
}
}

static int
htb_dump_class_stats(struct Qdisc *sch, unsigned long arg, struct gnet_dump *d)
{
struct htb_class *cl = (struct htb_class *)arg;
struct htb_sched *q = qdisc_priv(sch);
struct gnet_stats_queue qs = {
.drops = cl->drops,
.overlimits = cl->overlimits,
Expand All @@ -1280,6 +1313,19 @@ htb_dump_class_stats(struct Qdisc *sch, unsigned long arg, struct gnet_dump *d)
cl->xstats.ctokens = clamp_t(s64, PSCHED_NS2TICKS(cl->ctokens),
INT_MIN, INT_MAX);

if (q->offload) {
if (!cl->level) {
if (cl->leaf.q)
cl->bstats = cl->leaf.q->bstats;
else
memset(&cl->bstats, 0, sizeof(cl->bstats));
cl->bstats.bytes += cl->bstats_bias.bytes;
cl->bstats.packets += cl->bstats_bias.packets;
} else {
htb_offload_aggregate_stats(q, cl);
}
}

if (gnet_stats_copy_basic(qdisc_root_sleeping_running(sch),
d, NULL, &cl->bstats) < 0 ||
gnet_stats_copy_rate_est(d, &cl->rate_est) < 0 ||
Expand Down Expand Up @@ -1464,6 +1510,11 @@ static int htb_destroy_class_offload(struct Qdisc *sch, struct htb_class *cl,
WARN_ON(old != q);
}

if (cl->parent) {
cl->parent->bstats_bias.bytes += q->bstats.bytes;
cl->parent->bstats_bias.packets += q->bstats.packets;
}

offload_opt = (struct tc_htb_qopt_offload) {
.command = !last_child ? TC_HTB_LEAF_DEL :
destroying ? TC_HTB_LEAF_DEL_LAST_FORCE :
Expand Down Expand Up @@ -1803,6 +1854,8 @@ static int htb_change_class(struct Qdisc *sch, u32 classid,
htb_graft_helper(dev_queue, old_q);
goto err_kill_estimator;
}
parent->bstats_bias.bytes += old_q->bstats.bytes;
parent->bstats_bias.packets += old_q->bstats.packets;
qdisc_put(old_q);
}
new_q = qdisc_create_dflt(dev_queue, &pfifo_qdisc_ops,
Expand Down

0 comments on commit 8327158

Please sign in to comment.