diff options
author | Konstantin Khlebnikov <khlebnikov@yandex-team.ru> | 2016-07-16 10:08:56 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2016-07-19 01:44:31 -0400 |
commit | 0564bf0afae443deeb16f36e2c39fefff89d05f2 (patch) | |
tree | c5e1ce04411e5a08980e5a5b7411632d893f1607 | |
parent | 8e6ce7ebeb34f0992f56de078c3744fb383657fa (diff) |
net/sched/sch_htb: clamp xstats tokens to fit into 32-bit int
In kernel HTB keeps tokens in signed 64-bit in nanoseconds. In netlink
protocol these values are converted into pshed ticks (64ns for now) and
truncated to 32-bit. In struct tc_htb_xstats fields "tokens" and "ctokens"
are declared as unsigned 32-bit but they could be negative thus tool 'tc'
prints them as signed. Big values loose higher bits and/or become negative.
This patch clamps tokens in xstat into range from INT_MIN to INT_MAX.
In this way it's easier to understand what's going on here.
Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | net/sched/sch_htb.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/net/sched/sch_htb.c b/net/sched/sch_htb.c index 62f9d8100c6e..052f84d6cc23 100644 --- a/net/sched/sch_htb.c +++ b/net/sched/sch_htb.c | |||
@@ -1140,8 +1140,10 @@ htb_dump_class_stats(struct Qdisc *sch, unsigned long arg, struct gnet_dump *d) | |||
1140 | 1140 | ||
1141 | if (!cl->level && cl->un.leaf.q) | 1141 | if (!cl->level && cl->un.leaf.q) |
1142 | qlen = cl->un.leaf.q->q.qlen; | 1142 | qlen = cl->un.leaf.q->q.qlen; |
1143 | cl->xstats.tokens = PSCHED_NS2TICKS(cl->tokens); | 1143 | cl->xstats.tokens = clamp_t(s64, PSCHED_NS2TICKS(cl->tokens), |
1144 | cl->xstats.ctokens = PSCHED_NS2TICKS(cl->ctokens); | 1144 | INT_MIN, INT_MAX); |
1145 | cl->xstats.ctokens = clamp_t(s64, PSCHED_NS2TICKS(cl->ctokens), | ||
1146 | INT_MIN, INT_MAX); | ||
1145 | 1147 | ||
1146 | if (gnet_stats_copy_basic(d, NULL, &cl->bstats) < 0 || | 1148 | if (gnet_stats_copy_basic(d, NULL, &cl->bstats) < 0 || |
1147 | gnet_stats_copy_rate_est(d, NULL, &cl->rate_est) < 0 || | 1149 | gnet_stats_copy_rate_est(d, NULL, &cl->rate_est) < 0 || |