diff options
author | Sathya Perla <sathyap@serverengines.com> | 2009-03-24 19:40:13 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-03-24 19:40:13 -0400 |
commit | 4097f663cbe9e58de7ebed222f8af33267f297a8 (patch) | |
tree | 9cc5c70cba6e95405dbc1ae11a1bd79f96ee110c | |
parent | 38938bfe3489394e2eed5e40c9bb8f66a2ce1405 (diff) |
be2net: cleanup rx/tx rate calculations
Hi, Pls accept this patch to cleanup rx/tx rate calculations as follows:
- check for jiffies wraparound
- remove typecast of a denominator
- do rate calculation only in workqueue context periodically
Signed-off-by: Sathya Perla <sathyap@serverengines.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | drivers/net/benet/be.h | 12 | ||||
-rw-r--r-- | drivers/net/benet/be_main.c | 96 |
2 files changed, 72 insertions, 36 deletions
diff --git a/drivers/net/benet/be.h b/drivers/net/benet/be.h index f327be57ca96..c49ddd08b2aa 100644 --- a/drivers/net/benet/be.h +++ b/drivers/net/benet/be.h | |||
@@ -100,9 +100,9 @@ struct be_drvr_stats { | |||
100 | u32 be_tx_wrbs; /* number of tx WRBs used */ | 100 | u32 be_tx_wrbs; /* number of tx WRBs used */ |
101 | u32 be_tx_events; /* number of tx completion events */ | 101 | u32 be_tx_events; /* number of tx completion events */ |
102 | u32 be_tx_compl; /* number of tx completion entries processed */ | 102 | u32 be_tx_compl; /* number of tx completion entries processed */ |
103 | u64 be_tx_jiffies; | 103 | ulong be_tx_jiffies; |
104 | ulong be_tx_bytes; | 104 | u64 be_tx_bytes; |
105 | ulong be_tx_bytes_prev; | 105 | u64 be_tx_bytes_prev; |
106 | u32 be_tx_rate; | 106 | u32 be_tx_rate; |
107 | 107 | ||
108 | u32 cache_barrier[16]; | 108 | u32 cache_barrier[16]; |
@@ -113,9 +113,9 @@ struct be_drvr_stats { | |||
113 | u32 be_rx_compl; /* number of rx completion entries processed */ | 113 | u32 be_rx_compl; /* number of rx completion entries processed */ |
114 | u32 be_lro_hgram_data[8]; /* histogram of LRO data packets */ | 114 | u32 be_lro_hgram_data[8]; /* histogram of LRO data packets */ |
115 | u32 be_lro_hgram_ack[8]; /* histogram of LRO ACKs */ | 115 | u32 be_lro_hgram_ack[8]; /* histogram of LRO ACKs */ |
116 | u64 be_rx_jiffies; | 116 | ulong be_rx_jiffies; |
117 | ulong be_rx_bytes; | 117 | u64 be_rx_bytes; |
118 | ulong be_rx_bytes_prev; | 118 | u64 be_rx_bytes_prev; |
119 | u32 be_rx_rate; | 119 | u32 be_rx_rate; |
120 | /* number of non ether type II frames dropped where | 120 | /* number of non ether type II frames dropped where |
121 | * frame len > length field of Mac Hdr */ | 121 | * frame len > length field of Mac Hdr */ |
diff --git a/drivers/net/benet/be_main.c b/drivers/net/benet/be_main.c index 0ecaffb70e58..f901fee79a20 100644 --- a/drivers/net/benet/be_main.c +++ b/drivers/net/benet/be_main.c | |||
@@ -245,19 +245,29 @@ static void be_link_status_update(struct be_adapter *adapter) | |||
245 | /* Update the EQ delay n BE based on the RX frags consumed / sec */ | 245 | /* Update the EQ delay n BE based on the RX frags consumed / sec */ |
246 | static void be_rx_eqd_update(struct be_adapter *adapter) | 246 | static void be_rx_eqd_update(struct be_adapter *adapter) |
247 | { | 247 | { |
248 | u32 eqd; | ||
249 | struct be_ctrl_info *ctrl = &adapter->ctrl; | 248 | struct be_ctrl_info *ctrl = &adapter->ctrl; |
250 | struct be_eq_obj *rx_eq = &adapter->rx_eq; | 249 | struct be_eq_obj *rx_eq = &adapter->rx_eq; |
251 | struct be_drvr_stats *stats = &adapter->stats.drvr_stats; | 250 | struct be_drvr_stats *stats = &adapter->stats.drvr_stats; |
251 | ulong now = jiffies; | ||
252 | u32 eqd; | ||
253 | |||
254 | if (!rx_eq->enable_aic) | ||
255 | return; | ||
256 | |||
257 | /* Wrapped around */ | ||
258 | if (time_before(now, stats->rx_fps_jiffies)) { | ||
259 | stats->rx_fps_jiffies = now; | ||
260 | return; | ||
261 | } | ||
252 | 262 | ||
253 | /* Update once a second */ | 263 | /* Update once a second */ |
254 | if (((jiffies - stats->rx_fps_jiffies) < HZ) || rx_eq->enable_aic == 0) | 264 | if ((now - stats->rx_fps_jiffies) < HZ) |
255 | return; | 265 | return; |
256 | 266 | ||
257 | stats->be_rx_fps = (stats->be_rx_frags - stats->be_prev_rx_frags) / | 267 | stats->be_rx_fps = (stats->be_rx_frags - stats->be_prev_rx_frags) / |
258 | ((jiffies - stats->rx_fps_jiffies) / HZ); | 268 | ((now - stats->rx_fps_jiffies) / HZ); |
259 | 269 | ||
260 | stats->rx_fps_jiffies = jiffies; | 270 | stats->rx_fps_jiffies = now; |
261 | stats->be_prev_rx_frags = stats->be_rx_frags; | 271 | stats->be_prev_rx_frags = stats->be_rx_frags; |
262 | eqd = stats->be_rx_fps / 110000; | 272 | eqd = stats->be_rx_fps / 110000; |
263 | eqd = eqd << 3; | 273 | eqd = eqd << 3; |
@@ -280,26 +290,38 @@ static struct net_device_stats *be_get_stats(struct net_device *dev) | |||
280 | return &adapter->stats.net_stats; | 290 | return &adapter->stats.net_stats; |
281 | } | 291 | } |
282 | 292 | ||
293 | static void be_tx_rate_update(struct be_adapter *adapter) | ||
294 | { | ||
295 | struct be_drvr_stats *stats = drvr_stats(adapter); | ||
296 | ulong now = jiffies; | ||
297 | |||
298 | /* Wrapped around? */ | ||
299 | if (time_before(now, stats->be_tx_jiffies)) { | ||
300 | stats->be_tx_jiffies = now; | ||
301 | return; | ||
302 | } | ||
303 | |||
304 | /* Update tx rate once in two seconds */ | ||
305 | if ((now - stats->be_tx_jiffies) > 2 * HZ) { | ||
306 | u32 r; | ||
307 | r = (stats->be_tx_bytes - stats->be_tx_bytes_prev) / | ||
308 | ((now - stats->be_tx_jiffies) / HZ); | ||
309 | r = r / 1000000; /* M bytes/s */ | ||
310 | stats->be_tx_rate = r * 8; /* M bits/s */ | ||
311 | stats->be_tx_jiffies = now; | ||
312 | stats->be_tx_bytes_prev = stats->be_tx_bytes; | ||
313 | } | ||
314 | } | ||
315 | |||
283 | static void be_tx_stats_update(struct be_adapter *adapter, | 316 | static void be_tx_stats_update(struct be_adapter *adapter, |
284 | u32 wrb_cnt, u32 copied, bool stopped) | 317 | u32 wrb_cnt, u32 copied, bool stopped) |
285 | { | 318 | { |
286 | struct be_drvr_stats *stats = &adapter->stats.drvr_stats; | 319 | struct be_drvr_stats *stats = drvr_stats(adapter); |
287 | stats->be_tx_reqs++; | 320 | stats->be_tx_reqs++; |
288 | stats->be_tx_wrbs += wrb_cnt; | 321 | stats->be_tx_wrbs += wrb_cnt; |
289 | stats->be_tx_bytes += copied; | 322 | stats->be_tx_bytes += copied; |
290 | if (stopped) | 323 | if (stopped) |
291 | stats->be_tx_stops++; | 324 | stats->be_tx_stops++; |
292 | |||
293 | /* Update tx rate once in two seconds */ | ||
294 | if ((jiffies - stats->be_tx_jiffies) > 2 * HZ) { | ||
295 | u32 r; | ||
296 | r = (stats->be_tx_bytes - stats->be_tx_bytes_prev) / | ||
297 | ((u32) (jiffies - stats->be_tx_jiffies) / HZ); | ||
298 | r = (r / 1000000); /* M bytes/s */ | ||
299 | stats->be_tx_rate = (r * 8); /* M bits/s */ | ||
300 | stats->be_tx_jiffies = jiffies; | ||
301 | stats->be_tx_bytes_prev = stats->be_tx_bytes; | ||
302 | } | ||
303 | } | 325 | } |
304 | 326 | ||
305 | /* Determine number of WRB entries needed to xmit data in an skb */ | 327 | /* Determine number of WRB entries needed to xmit data in an skb */ |
@@ -573,28 +595,40 @@ static void be_set_multicast_list(struct net_device *netdev) | |||
573 | } | 595 | } |
574 | } | 596 | } |
575 | 597 | ||
576 | static void be_rx_rate_update(struct be_adapter *adapter, u32 pktsize, | 598 | static void be_rx_rate_update(struct be_adapter *adapter) |
577 | u16 numfrags) | ||
578 | { | 599 | { |
579 | struct be_drvr_stats *stats = &adapter->stats.drvr_stats; | 600 | struct be_drvr_stats *stats = drvr_stats(adapter); |
601 | ulong now = jiffies; | ||
580 | u32 rate; | 602 | u32 rate; |
581 | 603 | ||
582 | stats->be_rx_compl++; | 604 | /* Wrapped around */ |
583 | stats->be_rx_frags += numfrags; | 605 | if (time_before(now, stats->be_rx_jiffies)) { |
584 | stats->be_rx_bytes += pktsize; | 606 | stats->be_rx_jiffies = now; |
607 | return; | ||
608 | } | ||
585 | 609 | ||
586 | /* Update the rate once in two seconds */ | 610 | /* Update the rate once in two seconds */ |
587 | if ((jiffies - stats->be_rx_jiffies) < 2 * HZ) | 611 | if ((now - stats->be_rx_jiffies) < 2 * HZ) |
588 | return; | 612 | return; |
589 | 613 | ||
590 | rate = (stats->be_rx_bytes - stats->be_rx_bytes_prev) / | 614 | rate = (stats->be_rx_bytes - stats->be_rx_bytes_prev) / |
591 | ((u32) (jiffies - stats->be_rx_jiffies) / HZ); | 615 | ((now - stats->be_rx_jiffies) / HZ); |
592 | rate = (rate / 1000000); /* MB/Sec */ | 616 | rate = rate / 1000000; /* MB/Sec */ |
593 | stats->be_rx_rate = (rate * 8); /* Mega Bits/Sec */ | 617 | stats->be_rx_rate = rate * 8; /* Mega Bits/Sec */ |
594 | stats->be_rx_jiffies = jiffies; | 618 | stats->be_rx_jiffies = now; |
595 | stats->be_rx_bytes_prev = stats->be_rx_bytes; | 619 | stats->be_rx_bytes_prev = stats->be_rx_bytes; |
596 | } | 620 | } |
597 | 621 | ||
622 | static void be_rx_stats_update(struct be_adapter *adapter, | ||
623 | u32 pktsize, u16 numfrags) | ||
624 | { | ||
625 | struct be_drvr_stats *stats = drvr_stats(adapter); | ||
626 | |||
627 | stats->be_rx_compl++; | ||
628 | stats->be_rx_frags += numfrags; | ||
629 | stats->be_rx_bytes += pktsize; | ||
630 | } | ||
631 | |||
598 | static struct be_rx_page_info * | 632 | static struct be_rx_page_info * |
599 | get_rx_page_info(struct be_adapter *adapter, u16 frag_idx) | 633 | get_rx_page_info(struct be_adapter *adapter, u16 frag_idx) |
600 | { | 634 | { |
@@ -700,7 +734,7 @@ static void skb_fill_rx_data(struct be_adapter *adapter, | |||
700 | memset(page_info, 0, sizeof(*page_info)); | 734 | memset(page_info, 0, sizeof(*page_info)); |
701 | } | 735 | } |
702 | 736 | ||
703 | be_rx_rate_update(adapter, pktsize, num_rcvd); | 737 | be_rx_stats_update(adapter, pktsize, num_rcvd); |
704 | return; | 738 | return; |
705 | } | 739 | } |
706 | 740 | ||
@@ -799,7 +833,7 @@ static void be_rx_compl_process_lro(struct be_adapter *adapter, | |||
799 | vid, NULL, 0); | 833 | vid, NULL, 0); |
800 | } | 834 | } |
801 | 835 | ||
802 | be_rx_rate_update(adapter, pkt_size, num_rcvd); | 836 | be_rx_stats_update(adapter, pkt_size, num_rcvd); |
803 | return; | 837 | return; |
804 | } | 838 | } |
805 | 839 | ||
@@ -841,7 +875,6 @@ static void be_post_rx_frags(struct be_adapter *adapter) | |||
841 | u64 page_dmaaddr = 0, frag_dmaaddr; | 875 | u64 page_dmaaddr = 0, frag_dmaaddr; |
842 | u32 posted, page_offset = 0; | 876 | u32 posted, page_offset = 0; |
843 | 877 | ||
844 | |||
845 | page_info = &page_info_tbl[rxq->head]; | 878 | page_info = &page_info_tbl[rxq->head]; |
846 | for (posted = 0; posted < MAX_RX_POST && !page_info->page; posted++) { | 879 | for (posted = 0; posted < MAX_RX_POST && !page_info->page; posted++) { |
847 | if (!pagep) { | 880 | if (!pagep) { |
@@ -1305,6 +1338,9 @@ static void be_worker(struct work_struct *work) | |||
1305 | /* Set EQ delay */ | 1338 | /* Set EQ delay */ |
1306 | be_rx_eqd_update(adapter); | 1339 | be_rx_eqd_update(adapter); |
1307 | 1340 | ||
1341 | be_tx_rate_update(adapter); | ||
1342 | be_rx_rate_update(adapter); | ||
1343 | |||
1308 | if (adapter->rx_post_starved) { | 1344 | if (adapter->rx_post_starved) { |
1309 | adapter->rx_post_starved = false; | 1345 | adapter->rx_post_starved = false; |
1310 | be_post_rx_frags(adapter); | 1346 | be_post_rx_frags(adapter); |