Re: [PATCH] benet: use do_div() for 64 bit divide

Previous thread: Re: [Bugme-new] [Bug 12946] New: nfs-root fails with commit 303c6a0251852ecbdc5c15e466dcaff5971f7517 by Andrew Morton on Thursday, March 26, 2009 - 7:53 am. (1 message)

Next thread: [PATCH] smsc911x: enforce read-after-write timing restriction on eeprom access by Steve Glendinning on Thursday, March 26, 2009 - 10:14 am. (2 messages)
From: Randy Dunlap
Date: Thursday, March 26, 2009 - 8:46 am

on i386 build:

drivers/built-in.o: In function `be_worker':
be_main.c:(.text+0x827c7): undefined reference to `__udivdi3'
be_main.c:(.text+0x8286c): undefined reference to `__udivdi3'


Probably one of the called functions (that contains
division) is inlined.


-- 
~Randy
--

From: Stephen Hemminger
Date: Thursday, March 26, 2009 - 12:30 pm

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 - ...
From: Randy Dunlap
Date: Thursday, March 26, 2009 - 1:10 pm

Acked-by: Randy Dunlap <randy.dunlap@oracle.com> # and Tested-by: (built)



-- 
~Randy
--

From: David Miller
Date: Friday, March 27, 2009 - 12:26 am

From: Randy Dunlap <randy.dunlap@oracle.com>

Applied, thanks everyone.
--

Previous thread: Re: [Bugme-new] [Bug 12946] New: nfs-root fails with commit 303c6a0251852ecbdc5c15e466dcaff5971f7517 by Andrew Morton on Thursday, March 26, 2009 - 7:53 am. (1 message)

Next thread: [PATCH] smsc911x: enforce read-after-write timing restriction on eeprom access by Steve Glendinning on Thursday, March 26, 2009 - 10:14 am. (2 messages)