Fixed clearing frame statistics on link down.
authorFlorian Pose <fp@igh-essen.com>
Tue, 09 Mar 2010 09:59:32 +0100
changeset 1856 10175d5f35ea
parent 1855 30ddfc665fcb
child 1857 ed8b490b5bc3
Fixed clearing frame statistics on link down.
TODO
master/device.c
master/device.h
master/master.c
--- a/TODO	Mon Mar 08 12:20:19 2010 +0100
+++ b/TODO	Tue Mar 09 09:59:32 2010 +0100
@@ -46,7 +46,6 @@
     - Implement ranges for slaves and domains.
 * Output send errors in frame statistics.
 * Output tx rate [bytes/s] in frame statistics.
-* Fix clearing statistics on link down.
 
 Future issues:
 
--- a/master/device.c	Mon Mar 08 12:20:19 2010 +0100
+++ b/master/device.c	Tue Mar 09 09:59:32 2010 +0100
@@ -324,37 +324,22 @@
     // frame statistics
     if (unlikely(jiffies - device->stats_jiffies >= HZ)) {
         unsigned int i;
-        if (device->link_state) {
-            unsigned int tx_rate =
-                (device->tx_count - device->last_tx_count) * 1000;
-            int loss = device->tx_count - device->rx_count;
-            int loss_rate = (loss - device->last_loss) * 1000;
-            for (i = 0; i < EC_RATE_COUNT; i++) {
-                unsigned int n = rate_intervals[i];
-                device->tx_rates[i] =
-                    (device->tx_rates[i] * (n - 1) + tx_rate) / n;
-                device->loss_rates[i] =
-                    (device->loss_rates[i] * (n - 1) + loss_rate) / n;
-            }
-            device->last_tx_count = device->tx_count;
-            device->last_loss = loss;
-        } else {
-            // zero frame statistics
-            device->tx_count = 0;
-            device->rx_count = 0;
-            device->last_tx_count = 0;
-            device->last_loss = 0;
-            for (i = 0; i < EC_RATE_COUNT; i++) {
-                device->tx_rates[i] = 0;
-                device->loss_rates[i] = 0;
-            }
+        unsigned int tx_rate =
+            (device->tx_count - device->last_tx_count) * 1000;
+        int loss = device->tx_count - device->rx_count;
+        int loss_rate = (loss - device->last_loss) * 1000;
+        for (i = 0; i < EC_RATE_COUNT; i++) {
+            unsigned int n = rate_intervals[i];
+            device->tx_rates[i] =
+                (device->tx_rates[i] * (n - 1) + tx_rate) / n;
+            device->loss_rates[i] =
+                (device->loss_rates[i] * (n - 1) + loss_rate) / n;
         }
+        device->last_tx_count = device->tx_count;
+        device->last_loss = loss;
         device->stats_jiffies = jiffies;
     }
 
-    if (unlikely(!device->link_state)) // Link down
-        return;
-
     // set the right length for the data
     skb->len = ETH_HLEN + size;
 
@@ -384,6 +369,27 @@
 
 /*****************************************************************************/
 
+/** Clears the frame statistics.
+ */
+void ec_device_clear_stats(
+        ec_device_t *device /**< EtherCAT device */
+        )
+{
+    unsigned int i;
+
+    // zero frame statistics
+    device->tx_count = 0;
+    device->rx_count = 0;
+    device->last_tx_count = 0;
+    device->last_loss = 0;
+    for (i = 0; i < EC_RATE_COUNT; i++) {
+        device->tx_rates[i] = 0;
+        device->loss_rates[i] = 0;
+    }
+}
+
+/*****************************************************************************/
+
 #ifdef EC_DEBUG_RING
 /** Appends frame data to the debug ring.
  */
--- a/master/device.h	Mon Mar 08 12:20:19 2010 +0100
+++ b/master/device.h	Tue Mar 09 09:59:32 2010 +0100
@@ -134,6 +134,7 @@
 void ec_device_poll(ec_device_t *);
 uint8_t *ec_device_tx_data(ec_device_t *);
 void ec_device_send(ec_device_t *, size_t);
+void ec_device_clear_stats(ec_device_t *);
 
 #ifdef EC_DEBUG_RING
 void ec_device_debug_ring_append(ec_device_t *, ec_debug_frame_dir_t,
--- a/master/master.c	Mon Mar 08 12:20:19 2010 +0100
+++ b/master/master.c	Tue Mar 09 09:59:32 2010 +0100
@@ -2084,6 +2084,9 @@
 
         // query link state
         ec_device_poll(&master->main_device);
+
+        // clear frame statistics
+        ec_device_clear_stats(&master->main_device);
         return;
     }