Clear frame statistics on link loss.
authorFlorian Pose <fp@igh-essen.com>
Mon, 08 Mar 2010 08:01:26 +0100
changeset 1854 b61bece1ec1c
parent 1853 e0b9c4611f0a
child 1855 30ddfc665fcb
Clear frame statistics on link loss.
TODO
master/device.c
master/device.h
--- a/TODO	Mon Mar 08 07:46:36 2010 +0100
+++ b/TODO	Mon Mar 08 08:01:26 2010 +0100
@@ -44,6 +44,8 @@
 * ethercat tool:
     - Data type abbreviations.
     - Implement ranges for slaves and domains.
+* Output send errors in frame statistics.
+* Output tx rate [bytes/s] in frame statistics.
 
 Future issues:
 
--- a/master/device.c	Mon Mar 08 07:46:36 2010 +0100
+++ b/master/device.c	Mon Mar 08 08:01:26 2010 +0100
@@ -324,19 +324,31 @@
     // frame statistics
     if (unlikely(jiffies - device->stats_jiffies >= HZ)) {
         unsigned int i;
-        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;
+        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;
+            }
         }
-        device->last_tx_count = device->tx_count;
-        device->last_loss = loss;
         device->stats_jiffies = jiffies;
     }
 
--- a/master/device.h	Mon Mar 08 07:46:36 2010 +0100
+++ b/master/device.h	Mon Mar 08 08:01:26 2010 +0100
@@ -96,13 +96,19 @@
     struct timeval timeval_poll;
 #endif
     unsigned long jiffies_poll; /**< jiffies of last poll */
-    unsigned int tx_count; /**< number of frames sent */
-    unsigned int rx_count; /**< number of frames received */
-    unsigned int last_tx_count;
-    unsigned int tx_rates[EC_RATE_COUNT];
-    int last_loss; /**< Tx/Rx difference of last cycle. */
-    int loss_rates[EC_RATE_COUNT];
-    unsigned long stats_jiffies;
+
+    // Frame statistics
+    unsigned int tx_count; /**< Number of frames sent. */
+    unsigned int rx_count; /**< Number of frames received. */
+    unsigned int last_tx_count; /**< Number of frames sent of last statistics
+                                  cycle. */
+    unsigned int tx_rates[EC_RATE_COUNT]; /**< Transmit rates for different
+                                            statistics cycle periods. */
+    int last_loss; /**< Tx/Rx difference of last statistics cycle. */
+    int loss_rates[EC_RATE_COUNT]; /**< Frame loss rates for different
+                                     statistics cycle periods. */
+    unsigned long stats_jiffies; /**< Jiffies of last statistic cycle. */
+
 #ifdef EC_DEBUG_IF
     ec_debug_t dbg; /**< debug device */
 #endif