* [2.6.0, pktgen] divide-by-zero @ 2003-12-31 11:13 Lennert Buytenhek 2004-01-18 15:48 ` [PATCH] " Jörn Engel 0 siblings, 1 reply; 4+ messages in thread From: Lennert Buytenhek @ 2003-12-31 11:13 UTC (permalink / raw) To: linux-kernel; +Cc: netdev Hi, When generating packets with pktgen with count=10, I get a divide-by-zero oops in inject(). Line 273 in net/core/pktgen.c seems unsafe: __u64 pps = (__u32)(info->sofar * 1000) / ((__u32)(total) / 1000); What if total < 1000 ? cheers, Lennert ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] Re: [2.6.0, pktgen] divide-by-zero 2003-12-31 11:13 [2.6.0, pktgen] divide-by-zero Lennert Buytenhek @ 2004-01-18 15:48 ` Jörn Engel 2004-01-18 23:15 ` Robert Olsson 0 siblings, 1 reply; 4+ messages in thread From: Jörn Engel @ 2004-01-18 15:48 UTC (permalink / raw) To: Lennert Buytenhek; +Cc: linux-kernel, netdev On Wed, 31 December 2003 06:13:16 -0500, Lennert Buytenhek wrote: > > When generating packets with pktgen with count=10, I get a divide-by-zero > oops in inject(). > > Line 273 in net/core/pktgen.c seems unsafe: > __u64 pps = (__u32)(info->sofar * 1000) / ((__u32)(total) / 1000); > > What if total < 1000 ? Since noone else seemed to care, try this patch. Against -test11, yeah, I'm lazy again. Jörn -- Time? What's that? Time is only worth what you do with it. -- Theo de Raadt --- old/net/core/pktgen.c 2003-11-26 21:44:47.000000000 +0100 +++ new/net/core/pktgen.c 2004-01-18 16:27:10.000000000 +0100 @@ -720,7 +720,9 @@ { char *p = info->result; - __u64 pps = (__u32)(info->sofar * 1000) / ((__u32)(total) / 1000); + __u32 safe_total = (__u32)(total) / 1000; + safe_total += 1 - (!!safe_total); /* avoid divide-by-zero */ + __u64 pps = (__u32)(info->sofar * 1000) / safe_total; __u64 bps = pps * 8 * (info->pkt_size + 4); /* take 32bit ethernet CRC into account */ p += sprintf(p, "OK: %llu(c%llu+d%llu) usec, %llu (%dbyte,%dfrags) %llupps %lluMb/sec (%llubps) errors: %llu", (unsigned long long) total, ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] Re: [2.6.0, pktgen] divide-by-zero 2004-01-18 15:48 ` [PATCH] " Jörn Engel @ 2004-01-18 23:15 ` Robert Olsson 2004-01-19 17:24 ` David S. Miller 0 siblings, 1 reply; 4+ messages in thread From: Robert Olsson @ 2004-01-18 23:15 UTC (permalink / raw) To: Jörn Engel; +Cc: Lennert Buytenhek, linux-kernel, netdev Hello! Jörn Engel writes: > On Wed, 31 December 2003 06:13:16 -0500, Lennert Buytenhek wrote: > > > > When generating packets with pktgen with count=10, I get a divide-by-zero > > oops in inject(). > > > > Line 273 in net/core/pktgen.c seems unsafe: > > __u64 pps = (__u32)(info->sofar * 1000) / ((__u32)(total) / 1000); > > > > What if total < 1000 ? > > Since noone else seemed to care, try this patch. Against -test11, > yeah, I'm lazy again. Sorry I missed Lennerts original posting... I suggest the patch below to get integer precision at very short time intervals too. --- linux-2.6.1/net/core/pktgen.c.orig Sun Jan 18 21:56:56 2004 +++ linux-2.6.1/net/core/pktgen.c Sun Jan 18 23:15:03 2004 @@ -88,7 +88,7 @@ #define cycles() ((u32)get_cycles()) -#define VERSION "pktgen version 1.3" +#define VERSION "pktgen version 1.31" static char version[] __initdata = "pktgen.c: v1.3: Packet Generator for packet performance testing.\n"; @@ -720,8 +720,18 @@ { char *p = info->result; - __u64 pps = (__u32)(info->sofar * 1000) / ((__u32)(total) / 1000); - __u64 bps = pps * 8 * (info->pkt_size + 4); /* take 32bit ethernet CRC into account */ + __u64 bps, pps = 0; + + if (total > 1000) + pps = (__u32)(info->sofar * 1000) / ((__u32)(total) / 1000); + else if(total > 100) + pps = (__u32)(info->sofar * 10000) / ((__u32)(total) / 100); + else if(total > 10) + pps = (__u32)(info->sofar * 100000) / ((__u32)(total) / 10); + else if(total > 1) + pps = (__u32)(info->sofar * 1000000) / (__u32)total; + + bps = pps * 8 * (info->pkt_size + 4); /* take 32bit ethernet CRC into account */ p += sprintf(p, "OK: %llu(c%llu+d%llu) usec, %llu (%dbyte,%dfrags) %llupps %lluMb/sec (%llubps) errors: %llu", (unsigned long long) total, (unsigned long long) (total - idle), Cheers. --ro ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Re: [2.6.0, pktgen] divide-by-zero 2004-01-18 23:15 ` Robert Olsson @ 2004-01-19 17:24 ` David S. Miller 0 siblings, 0 replies; 4+ messages in thread From: David S. Miller @ 2004-01-19 17:24 UTC (permalink / raw) To: Robert Olsson; +Cc: joern, buytenh, linux-kernel, netdev On Mon, 19 Jan 2004 00:15:41 +0100 Robert Olsson <Robert.Olsson@data.slu.se> wrote: > I suggest the patch below to get integer precision at very short time > intervals too. Applied, thanks Robert. ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-01-19 17:24 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2003-12-31 11:13 [2.6.0, pktgen] divide-by-zero Lennert Buytenhek 2004-01-18 15:48 ` [PATCH] " Jörn Engel 2004-01-18 23:15 ` Robert Olsson 2004-01-19 17:24 ` David S. 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).