All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH iproute2] nstat: 64bit support on 32bit arches
@ 2014-08-25 14:27 Eric Dumazet
  2014-08-25 21:48 ` Stephen Hemminger
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Dumazet @ 2014-08-25 14:27 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev

From: Eric Dumazet <edumazet@google.com>

SNMP counters can be provided as 64bit numbers.
nstat needs to cope with this even if running in 32bit mode.

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 misc/nstat.c |   13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/misc/nstat.c b/misc/nstat.c
index d3f8621..e54b3ae 100644
--- a/misc/nstat.c
+++ b/misc/nstat.c
@@ -77,7 +77,6 @@ struct nstat_ent
 	struct nstat_ent *next;
 	char		 *id;
 	unsigned long long val;
-	unsigned long	   ival;
 	double		   rate;
 };
 
@@ -143,7 +142,6 @@ static void load_good_table(FILE *fp)
 		if ((n = malloc(sizeof(*n))) == NULL)
 			abort();
 		n->id = strdup(idbuf);
-		n->ival = (unsigned long)val;
 		n->val = val;
 		n->rate = rate;
 		n->next = db;
@@ -206,9 +204,8 @@ static void load_ugly_table(FILE *fp)
 			if (!p)
 				abort();
 			*p = 0;
-			if (sscanf(p+1, "%lu", &n->ival) != 1)
+			if (sscanf(p+1, "%llu", &n->val) != 1)
 				abort();
-			n->val = n->ival;
 			/* Trick to skip "dummy" trailing ICMP MIB in 2.4 */
 			if (strcmp(idbuf, "IcmpOutAddrMaskReps") == 0)
 				idbuf[5] = 0;
@@ -365,10 +362,10 @@ static void update_db(int interval)
 		for (h1 = h; h1; h1 = h1->next) {
 			if (strcmp(h1->id, n->id) == 0) {
 				double sample;
-				unsigned long incr = h1->ival - n->ival;
-				n->val += incr;
-				n->ival = h1->ival;
-				sample = (double)(incr*1000)/interval;
+				unsigned long long incr = h1->val - n->val;
+
+				n->val = h1->val;
+				sample = (double)incr * 1000.0 / interval;
 				if (interval >= scan_interval) {
 					n->rate += W*(sample-n->rate);
 				} else if (interval >= 1000) {

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

* Re: [PATCH iproute2] nstat: 64bit support on 32bit arches
  2014-08-25 14:27 [PATCH iproute2] nstat: 64bit support on 32bit arches Eric Dumazet
@ 2014-08-25 21:48 ` Stephen Hemminger
  2014-08-25 22:52   ` Eric Dumazet
  0 siblings, 1 reply; 3+ messages in thread
From: Stephen Hemminger @ 2014-08-25 21:48 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: netdev

On Mon, 25 Aug 2014 07:27:54 -0700
Eric Dumazet <eric.dumazet@gmail.com> wrote:

> From: Eric Dumazet <edumazet@google.com>
> 
> SNMP counters can be provided as 64bit numbers.
> nstat needs to cope with this even if running in 32bit mode.
> 
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> ---
>  misc/nstat.c |   13 +++++--------
>  1 file changed, 5 insertions(+), 8 deletions(-)
> 
> diff --git a/misc/nstat.c b/misc/nstat.c
> index d3f8621..e54b3ae 100644
> --- a/misc/nstat.c
> +++ b/misc/nstat.c
> @@ -77,7 +77,6 @@ struct nstat_ent
>  	struct nstat_ent *next;
>  	char		 *id;
>  	unsigned long long val;
> -	unsigned long	   ival;
>  	double		   rate;
>  };
>  
> @@ -143,7 +142,6 @@ static void load_good_table(FILE *fp)
>  		if ((n = malloc(sizeof(*n))) == NULL)
>  			abort();
>  		n->id = strdup(idbuf);
> -		n->ival = (unsigned long)val;
>  		n->val = val;
>  		n->rate = rate;
>  		n->next = db;
> @@ -206,9 +204,8 @@ static void load_ugly_table(FILE *fp)
>  			if (!p)
>  				abort();
>  			*p = 0;
> -			if (sscanf(p+1, "%lu", &n->ival) != 1)
> +			if (sscanf(p+1, "%llu", &n->val) != 1)
>  				abort();
> -			n->val = n->ival;
>  			/* Trick to skip "dummy" trailing ICMP MIB in 2.4 */
>  			if (strcmp(idbuf, "IcmpOutAddrMaskReps") == 0)
>  				idbuf[5] = 0;
> @@ -365,10 +362,10 @@ static void update_db(int interval)
>  		for (h1 = h; h1; h1 = h1->next) {
>  			if (strcmp(h1->id, n->id) == 0) {
>  				double sample;
> -				unsigned long incr = h1->ival - n->ival;
> -				n->val += incr;
> -				n->ival = h1->ival;
> -				sample = (double)(incr*1000)/interval;
> +				unsigned long long incr = h1->val - n->val;
> +
> +				n->val = h1->val;
> +				sample = (double)incr * 1000.0 / interval;
>  				if (interval >= scan_interval) {
>  					n->rate += W*(sample-n->rate);
>  				} else if (interval >= 1000) {
> 
> 

Maybe time to convert to using uint64_t and the printf formats in inttypes.h

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

* Re: [PATCH iproute2] nstat: 64bit support on 32bit arches
  2014-08-25 21:48 ` Stephen Hemminger
@ 2014-08-25 22:52   ` Eric Dumazet
  0 siblings, 0 replies; 3+ messages in thread
From: Eric Dumazet @ 2014-08-25 22:52 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev

On Mon, 2014-08-25 at 14:48 -0700, Stephen Hemminger wrote:

> 
> Maybe time to convert to using uint64_t and the printf formats in inttypes.h

Yes, that would be a cleanup, but end result is quite ugly if you ask
me.

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

end of thread, other threads:[~2014-08-25 22:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-25 14:27 [PATCH iproute2] nstat: 64bit support on 32bit arches Eric Dumazet
2014-08-25 21:48 ` Stephen Hemminger
2014-08-25 22:52   ` Eric Dumazet

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.