Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 136061
b: refs/heads/master
c: 65f71b8
h: refs/heads/master
i:
  136059: 64342ee
v: v3
  • Loading branch information
Stephen Hemminger authored and David S. Miller committed Mar 27, 2009
1 parent cc9276b commit 1681fe9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 7d0b591c655ca0d72ebcbd242cf659a20a8995c5
refs/heads/master: 65f71b8bd2651e6d6ca9b09fe53a8db2da22b85c
28 changes: 18 additions & 10 deletions trunk/drivers/net/benet/be_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#include "be.h"
#include <asm/div64.h>

MODULE_VERSION(DRV_VER);
MODULE_DEVICE_TABLE(pci, be_dev_ids);
Expand Down Expand Up @@ -290,6 +291,17 @@ static struct net_device_stats *be_get_stats(struct net_device *dev)
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);
Expand All @@ -303,11 +315,9 @@ static void be_tx_rate_update(struct be_adapter *adapter)

/* 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;
}
Expand Down Expand Up @@ -599,7 +609,6 @@ static void be_rx_rate_update(struct be_adapter *adapter)
{
struct be_drvr_stats *stats = drvr_stats(adapter);
ulong now = jiffies;
u32 rate;

/* Wrapped around */
if (time_before(now, stats->be_rx_jiffies)) {
Expand All @@ -611,10 +620,9 @@ static void be_rx_rate_update(struct be_adapter *adapter)
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;
}
Expand Down

0 comments on commit 1681fe9

Please sign in to comment.