linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net/sched/sch_htb: clamp xstats tokens to fit into 32-bit int
@ 2016-07-16 14:08 Konstantin Khlebnikov
  2016-07-18 18:29 ` Cong Wang
  2016-07-19  5:45 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Konstantin Khlebnikov @ 2016-07-16 14:08 UTC (permalink / raw)
  To: David S. Miller; +Cc: netdev, Eric Dumazet, Jamal Hadi Salim, linux-kernel

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>
---
 net/sched/sch_htb.c |    6 ++++--
 1 file 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)
 
 	if (!cl->level && cl->un.leaf.q)
 		qlen = cl->un.leaf.q->q.qlen;
-	cl->xstats.tokens = PSCHED_NS2TICKS(cl->tokens);
-	cl->xstats.ctokens = PSCHED_NS2TICKS(cl->ctokens);
+	cl->xstats.tokens = clamp_t(s64, PSCHED_NS2TICKS(cl->tokens),
+				    INT_MIN, INT_MAX);
+	cl->xstats.ctokens = clamp_t(s64, PSCHED_NS2TICKS(cl->ctokens),
+				     INT_MIN, INT_MAX);
 
 	if (gnet_stats_copy_basic(d, NULL, &cl->bstats) < 0 ||
 	    gnet_stats_copy_rate_est(d, NULL, &cl->rate_est) < 0 ||

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] net/sched/sch_htb: clamp xstats tokens to fit into 32-bit int
  2016-07-16 14:08 [PATCH] net/sched/sch_htb: clamp xstats tokens to fit into 32-bit int Konstantin Khlebnikov
@ 2016-07-18 18:29 ` Cong Wang
  2016-07-19  5:45 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Cong Wang @ 2016-07-18 18:29 UTC (permalink / raw)
  To: Konstantin Khlebnikov
  Cc: David S. Miller, Linux Kernel Network Developers, Eric Dumazet,
	Jamal Hadi Salim, LKML

On Sat, Jul 16, 2016 at 7:08 AM, Konstantin Khlebnikov
<khlebnikov@yandex-team.ru> wrote:
> 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.

Makes sense to me, I don't know why we didn't use signed int in
the beginning, interpreting an unsigned int as signed is confusing.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] net/sched/sch_htb: clamp xstats tokens to fit into 32-bit int
  2016-07-16 14:08 [PATCH] net/sched/sch_htb: clamp xstats tokens to fit into 32-bit int Konstantin Khlebnikov
  2016-07-18 18:29 ` Cong Wang
@ 2016-07-19  5:45 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2016-07-19  5:45 UTC (permalink / raw)
  To: khlebnikov; +Cc: netdev, edumazet, jhs, linux-kernel

From: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
Date: Sat, 16 Jul 2016 17:08:56 +0300

> 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>

Applied.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-07-19  5:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-16 14:08 [PATCH] net/sched/sch_htb: clamp xstats tokens to fit into 32-bit int Konstantin Khlebnikov
2016-07-18 18:29 ` Cong Wang
2016-07-19  5:45 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).