summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Olsson <robert.olsson@data.slu.se>2004-01-18 17:30:45 -0800
committerHideaki Yoshifuji <yoshfuji@linux-ipv6.org>2004-01-18 17:30:45 -0800
commit0ffec775e4eadbd6337692423896196f479f77dd (patch)
treee937e69c879b3ef35d97e402628d6fc93182efd8
parent1c2a00adf2f9ba610137142a01561ae146c106a8 (diff)
[PKTGEN]: Fix divide by zero and get integer precision at very short time intervals.
-rw-r--r--net/core/pktgen.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index 0652fdaf9079..cfabfe1a1214 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -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 @@ static void inject(struct pktgen_info* info)
{
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),