From: Stephen Hemminger <shemminger@vyatta.com>
To: Randy Dunlap <randy.dunlap@oracle.com>,
"David S. Miller" <davem@davemloft.net>,
Sathya Perla <sathyap@serverengines.com>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>,
linux-next@vger.kernel.org, netdev@vger.kernel.org,
linux-drivers@serverengines.com
Subject: [PATCH] benet: use do_div() for 64 bit divide
Date: Thu, 26 Mar 2009 12:30:05 -0700 [thread overview]
Message-ID: <20090326123005.34acd9fe@s6510> (raw)
In-Reply-To: <49CBA351.2000007@oracle.com>
The benet driver is doing a 64 bit divide, which is not supported in Linux kernel
on 32 bit architectures. The correct way to do this is to use do_div().
Compile tested on i386 only.
Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
--- a/drivers/net/benet/be_main.c 2009-03-25 15:31:35.000000000 -0700
+++ b/drivers/net/benet/be_main.c 2009-03-26 12:28:21.645388379 -0700
@@ -16,6 +16,7 @@
*/
#include "be.h"
+#include <asm/div64.h>
MODULE_VERSION(DRV_VER);
MODULE_DEVICE_TABLE(pci, be_dev_ids);
@@ -290,6 +291,17 @@ static struct net_device_stats *be_get_s
return &adapter->stats.net_stats;
}
+static u32 be_calc_rate(u64 bytes, unsigned long ticks)
+{
+ u64 rate = bytes;
+
+ do_div(rate, ticks / HZ);
+ rate <<= 3; /* bytes/sec -> bits/sec */
+ do_div(rate, 1000000ul); /* MB/Sec */
+
+ return rate;
+}
+
static void be_tx_rate_update(struct be_adapter *adapter)
{
struct be_drvr_stats *stats = drvr_stats(adapter);
@@ -303,11 +315,9 @@ static void be_tx_rate_update(struct be_
/* Update tx rate once in two seconds */
if ((now - stats->be_tx_jiffies) > 2 * HZ) {
- u32 r;
- r = (stats->be_tx_bytes - stats->be_tx_bytes_prev) /
- ((now - stats->be_tx_jiffies) / HZ);
- r = r / 1000000; /* M bytes/s */
- stats->be_tx_rate = r * 8; /* M bits/s */
+ stats->be_tx_rate = be_calc_rate(stats->be_tx_bytes
+ - stats->be_tx_bytes_prev,
+ now - stats->be_tx_jiffies);
stats->be_tx_jiffies = now;
stats->be_tx_bytes_prev = stats->be_tx_bytes;
}
@@ -599,7 +609,6 @@ static void be_rx_rate_update(struct be_
{
struct be_drvr_stats *stats = drvr_stats(adapter);
ulong now = jiffies;
- u32 rate;
/* Wrapped around */
if (time_before(now, stats->be_rx_jiffies)) {
@@ -610,11 +619,10 @@ static void be_rx_rate_update(struct be_
/* Update the rate once in two seconds */
if ((now - stats->be_rx_jiffies) < 2 * HZ)
return;
-
- rate = (stats->be_rx_bytes - stats->be_rx_bytes_prev) /
- ((now - stats->be_rx_jiffies) / HZ);
- rate = rate / 1000000; /* MB/Sec */
- stats->be_rx_rate = rate * 8; /* Mega Bits/Sec */
+
+ stats->be_rx_rate = be_calc_rate(stats->be_rx_bytes
+ - stats->be_rx_bytes_prev,
+ now - stats->be_rx_jiffies);
stats->be_rx_jiffies = now;
stats->be_rx_bytes_prev = stats->be_rx_bytes;
}
next prev parent reply other threads:[~2009-03-26 19:30 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20090326190130.54fc6fde.sfr@canb.auug.org.au>
2009-03-26 15:46 ` linux-next: Tree for March 26 (benet) Randy Dunlap
2009-03-26 19:30 ` Stephen Hemminger [this message]
2009-03-26 20:10 ` [PATCH] benet: use do_div() for 64 bit divide Randy Dunlap
2009-03-27 7:26 ` David 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=20090326123005.34acd9fe@s6510 \
--to=shemminger@vyatta.com \
--cc=davem@davemloft.net \
--cc=linux-drivers@serverengines.com \
--cc=linux-next@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=randy.dunlap@oracle.com \
--cc=sathyap@serverengines.com \
--cc=sfr@canb.auug.org.au \
/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).