From nobody@FreeBSD.org  Fri Dec  1 09:09:29 2006
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 8376216A415
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  1 Dec 2006 09:09:29 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [69.147.83.33])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 0917843CA7
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  1 Dec 2006 09:09:16 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id kB199STi019355
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 1 Dec 2006 09:09:28 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id kB199Su5019349;
	Fri, 1 Dec 2006 09:09:28 GMT
	(envelope-from nobody)
Message-Id: <200612010909.kB199Su5019349@www.freebsd.org>
Date: Fri, 1 Dec 2006 09:09:28 GMT
From: Rostislav Krasny<rosti.bsd@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [PATCH] wrong definition of kilobit per second in systat(1)
X-Send-Pr-Version: www-3.0

>Number:         106116
>Category:       bin
>Synopsis:       [PATCH] wrong definition of kilobit per second in systat(1)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Dec 01 09:10:18 GMT 2006
>Closed-Date:    Thu Jan 25 14:28:32 GMT 2007
>Last-Modified:  Thu Jan 25 14:30:29 GMT 2007
>Originator:     Rostislav Krasny
>Release:        
>Organization:
>Environment:
>Description:
Revision 1.11 of src/usr.bin/systat/convtbl.c has following definitions:

#define BIT	(8)
#define BYTE	(1)

#define BITS	(1)
#define BYTES	(1)
#define KILO	(1024LL)
#define MEGA	(KILO * 1024)
#define GIGA	(MEGA * 1024)
#define TERA	(GIGA * 1024)

static struct convtbl convtbl[] = {
	/* mul, scale, str, name */
	[SC_BYTE] =	{ BYTE, BYTES, "B",  "byte"  },
	[SC_KILOBYTE] =	{ BYTE, KILO,  "KB", "kbyte" },
	[SC_MEGABYTE] =	{ BYTE, MEGA,  "MB", "mbyte" },
	[SC_GIGABYTE] =	{ BYTE, GIGA,  "GB", "gbyte" },
	[SC_TERABYTE] =	{ BYTE, TERA,  "TB", "tbyte" },

	[SC_BIT] =	{ BIT, BITS, "b",  "bit"  },
	[SC_KILOBIT] =	{ BIT, KILO, "Kb", "kbit" },
	[SC_MEGABIT] =	{ BIT, MEGA, "Mb", "mbit" },
	[SC_GIGABIT] =	{ BIT, GIGA, "Gb", "gbit" },
	[SC_TERABIT] =	{ BIT, TERA, "Tb", "tbit" },

	[SC_AUTO] =	{ 0, 0, "", "auto" }
};

As you can see it defines kilobit as 1024 bits, megabit as 1024 kilobits and so on. But this is wrong. Unlike prefixes of bytes, prefixes of bits are powers of 10 and not powers of 2. For example 1.5 Mbps means 1500000 bps and not 1572864 bps.

For more information see this http://physics.nist.gov/cuu/Units/binary.html

You can also find following definitions on src/sys/net/if.h

#define	IF_Kbps(x)	((x) * 1000)		/* kilobits/sec. */
#define	IF_Mbps(x)	(IF_Kbps((x) * 1000))	/* megabits/sec. */
#define	IF_Gbps(x)	(IF_Mbps((x) * 1000))	/* gigabits/sec. */

They were added by Sam Leffler in revision 1.81 as an adoption from NetBSD. These definitions exist in FreeBSD, NetBSD, OpenBSD and DragonflyBSD. So a current version of the systat(1) util is inconsistent to any BSD kernel.

In a Linux camp a kilobit is also defined as a power of 10:
http://www.lpi.org/en/lpi/english/certification/the_lpic_program/glossary_of_terms#K
>How-To-Repeat:
Just check the code.
>Fix:
--- convtbl.c.orig	Tue Nov 28 11:58:37 2006
+++ convtbl.c	Tue Nov 28 12:09:25 2006
@@ -37,11 +37,16 @@
 #define BYTE	(1)
 
 #define BITS	(1)
+#define KILOBIT	(1000LL)
+#define MEGABIT	(KILOBIT * KILOBIT)
+#define GIGABIT	(MEGABIT * KILOBIT)
+#define TERABIT	(GIGABIT * KILOBIT)
+
 #define BYTES	(1)
 #define KILO	(1024LL)
-#define MEGA	(KILO * 1024)
-#define GIGA	(MEGA * 1024)
-#define TERA	(GIGA * 1024)
+#define MEGA	(KILO * KILO)
+#define GIGA	(MEGA * KILO)
+#define TERA	(GIGA * KILO)
 
 struct convtbl {
 	uintmax_t	 mul;
@@ -58,11 +63,11 @@
 	[SC_GIGABYTE] =	{ BYTE, GIGA,  "GB", "gbyte" },
 	[SC_TERABYTE] =	{ BYTE, TERA,  "TB", "tbyte" },
 
-	[SC_BIT] =	{ BIT, BITS, "b",  "bit"  },
-	[SC_KILOBIT] =	{ BIT, KILO, "Kb", "kbit" },
-	[SC_MEGABIT] =	{ BIT, MEGA, "Mb", "mbit" },
-	[SC_GIGABIT] =	{ BIT, GIGA, "Gb", "gbit" },
-	[SC_TERABIT] =	{ BIT, TERA, "Tb", "tbit" },
+	[SC_BIT] =	{ BIT, BITS,	"b",  "bit"  },
+	[SC_KILOBIT] =	{ BIT, KILOBIT, "Kb", "kbit" },
+	[SC_MEGABIT] =	{ BIT, MEGABIT, "Mb", "mbit" },
+	[SC_GIGABIT] =	{ BIT, GIGABIT, "Gb", "gbit" },
+	[SC_TERABIT] =	{ BIT, TERABIT, "Tb", "tbit" },
 
 	[SC_AUTO] =	{ 0, 0, "", "auto" }
 };

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->yar 
Responsible-Changed-By: ru 
Responsible-Changed-When: Fri Dec 1 13:08:21 UTC 2006 
Responsible-Changed-Why:  
Switch over to person who'll fix it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=106116 
Responsible-Changed-From-To: yar->freebsd-bugs 
Responsible-Changed-By: yar 
Responsible-Changed-When: Mon Dec 18 12:45:30 UTC 2006 
Responsible-Changed-Why:  
I'm an old fart who thinks that decimal prefixes are evil. 
Well, I'm not old enough to really insist on sticking to 
binary prefixes for bits regardless of the standard; but 
mixing decimal and binary prefixes in one systat(1) display 
still is no good IMHO.  That's why I'm not going to deal 
with this PR. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=106116 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/106116: commit references a PR
Date: Thu, 18 Jan 2007 09:24:24 +0000 (UTC)

 ru          2007-01-18 09:24:08 UTC
 
   FreeBSD src repository
 
   Modified files:
     usr.bin/systat       convtbl.c 
   Log:
   Fix definitions of kilobits etc.
   
   PR:             bin/106116
   Nudged by:      Rostislav Krasny
   MFC after:      3 days
   
   Revision  Changes    Path
   1.12      +25 -21    src/usr.bin/systat/convtbl.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->closed 
State-Changed-By: ru 
State-Changed-When: Thu Jan 25 14:28:17 UTC 2007 
State-Changed-Why:  
Fixed. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=106116 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/106116: commit references a PR
Date: Thu, 25 Jan 2007 14:28:11 +0000 (UTC)

 ru          2007-01-25 14:28:02 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_6)
     usr.bin/systat       convtbl.c 
   Log:
   MFC: 1.12: Fix definitions of kilobits etc.
   
   PR:     bin/106116
   
   Revision  Changes    Path
   1.3.8.3   +25 -21    src/usr.bin/systat/convtbl.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
>Unformatted:
