netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@osdl.org>
To: netdev@oss.sgi.com
Subject: Fw: [PATCH] pktgen divides by zero on short runs
Date: Thu, 4 Sep 2003 23:27:13 -0700	[thread overview]
Message-ID: <20030904232713.7dd4e99f.akpm@osdl.org> (raw)



Begin forwarded message:

Date: Fri, 5 Sep 2003 01:40:27 -0400 (EDT)
From: Najati Imam <najati@netlab.uky.edu>
To: linux-kernel@vger.kernel.org
Subject: [PATCH] pktgen divides by zero on short runs


On very short runs when computing the packets per second the time that is
used can be zero. For small packets this can happen with as many as 100,
maybe more, packets. The patch below checks the denominator before
dividing and if it is zero puts a notice in the results output that
explains why pbs, bps and mbps are all zero, like so

Result: OK: 10(c10+d0) usec, 1 (64byte,0frags) 0pps 0Mb/sec (0bps) \
  (Time too short to measure) errors: 0

Hope this hasn't already been addressed (it was present in 2.6.0-test4,
which is what I generated the patch from), also this is my first
submission, so if I did it all wrong, I will accept the appropriate
punishment.

Najati Imam




diff -urN linux-2.6.0-test4/net/core/pktgen.c linux-2.6.0-test4-nri/net/core/pktgen.c
--- linux-2.6.0-test4/net/core/pktgen.c 2003-08-22 19:57:49.000000000 -0400
+++ linux-2.6.0-test4-nri/net/core/pktgen.c     2003-09-05 01:15:20.000000000 -0400
@@ -50,6 +50,9 @@
  * Fix refcount off by one if first packet fails, potential null deref, 
  * memleak 030710- KJP
  *
+ * Check for potential div by zero in the event of a really short send time
+ * 030905 NRI 
+ *
  * See Documentation/networking/pktgen.txt for how to use this.
  */
 
@@ -720,9 +723,10 @@
 
        {
                char *p = info->result;
-               __u64 pps = (__u32)(info->sofar * 1000) / ((__u32)(total) / 1000);
+               __u32 tt = ((__u32)(total) / 1000);
+               __u64 pps = (tt) ? (__u32)(info->sofar * 1000) / ((__u32)(total) / 1000) : 0;
                __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",
+               p += sprintf(p, "OK: %llu(c%llu+d%llu) usec, %llu (%dbyte,%dfrags) %llupps %lluMb/sec (%llubps) %s errors: %llu",
                             (unsigned long long) total,
                             (unsigned long long) (total - idle),
                             (unsigned long long) idle,
@@ -732,6 +736,7 @@
                             (unsigned long long) pps,
                             (unsigned long long) (bps / (u64) 1024 / (u64) 1024),
                             (unsigned long long) bps,
+                            (tt) ? "" : "(Time too short to measure)",
                             (unsigned long long) info->errors
                             );
        }



             reply	other threads:[~2003-09-05  6:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-09-05  6:27 Andrew Morton [this message]
2003-09-05  8:16 ` Fw: [PATCH] pktgen divides by zero on short runs David S. Miller
2003-09-05  9:11   ` Andrew Morton
2003-09-05  9:51     ` David S. Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030904232713.7dd4e99f.akpm@osdl.org \
    --to=akpm@osdl.org \
    --cc=netdev@oss.sgi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).