Improved/fixed frame statistics (low-pass filters). redundancy
authorFlorian Pose <fp@igh-essen.com>
Mon, 19 Mar 2012 10:43:09 +0100
branchredundancy
changeset 2372 d895cd1db2bf
parent 2371 a5052376202b
child 2373 593272e5a169
Improved/fixed frame statistics (low-pass filters).
master/device.c
master/device.h
master/ioctl.h
master/master.c
master/master.h
--- a/master/device.c	Mon Mar 19 09:56:36 2012 +0100
+++ b/master/device.c	Mon Mar 19 10:43:09 2012 +0100
@@ -465,25 +465,25 @@
 {
     unsigned int i;
 
-    u32 tx_frame_rate =
-        (u32) (device->tx_count - device->last_tx_count) * 1000;
-    u32 rx_frame_rate =
-        (u32) (device->rx_count - device->last_rx_count) * 1000;
-    u32 tx_byte_rate =
-        (device->tx_bytes - device->last_tx_bytes);
-    u32 rx_byte_rate =
-        (device->rx_bytes - device->last_rx_bytes);
-
+    s32 tx_frame_rate = (device->tx_count - device->last_tx_count) * 1000;
+    s32 rx_frame_rate = (device->rx_count - device->last_rx_count) * 1000;
+    s32 tx_byte_rate = (device->tx_bytes - device->last_tx_bytes);
+    s32 rx_byte_rate = (device->rx_bytes - device->last_rx_bytes);
+
+    /* Low-pass filter:
+     *      Y_n = y_(n - 1) + T / tau * (x - y_(n - 1))   | T = 1
+     *   -> Y_n += (x - y_(n - 1)) / tau
+     */
     for (i = 0; i < EC_RATE_COUNT; i++) {
-        unsigned int n = rate_intervals[i];
-        device->tx_frame_rates[i] =
-            (device->tx_frame_rates[i] * (n - 1) + tx_frame_rate) / n;
-        device->rx_frame_rates[i] =
-            (device->rx_frame_rates[i] * (n - 1) + rx_frame_rate) / n;
-        device->tx_byte_rates[i] =
-            (device->tx_byte_rates[i] * (n - 1) + tx_byte_rate) / n;
-        device->rx_byte_rates[i] =
-            (device->rx_byte_rates[i] * (n - 1) + rx_byte_rate) / n;
+        s32 n = rate_intervals[i];
+        device->tx_frame_rates[i] +=
+            (tx_frame_rate - device->tx_frame_rates[i]) / n;
+        device->rx_frame_rates[i] +=
+            (rx_frame_rate - device->rx_frame_rates[i]) / n;
+        device->tx_byte_rates[i] +=
+            (tx_byte_rate - device->tx_byte_rates[i]) / n;
+        device->rx_byte_rates[i] +=
+            (rx_byte_rate - device->rx_byte_rates[i]) / n;
     }
 
     device->last_tx_count = device->tx_count;
--- a/master/device.h	Mon Mar 19 09:56:36 2012 +0100
+++ b/master/device.h	Mon Mar 19 10:43:09 2012 +0100
@@ -109,18 +109,16 @@
     u64 last_rx_bytes; /**< Number of bytes received of last statistics cycle.
                         */
     u64 tx_errors; /**< Number of transmit errors. */
-    unsigned int tx_frame_rates[EC_RATE_COUNT]; /**< Transmit rates in
-                                                  frames/s for different
-                                                  statistics cycle periods. */
-    unsigned int rx_frame_rates[EC_RATE_COUNT]; /**< Receive rates in
-                                                  frames/s for different
-                                                  statistics cycle periods. */
-    unsigned int tx_byte_rates[EC_RATE_COUNT]; /**< Transmit rates in byte/s
-                                                 for different statistics
-                                                 cycle periods. */
-    unsigned int rx_byte_rates[EC_RATE_COUNT]; /**< Receive rates in byte/s
-                                                 for different statistics
-                                                 cycle periods. */
+    s32 tx_frame_rates[EC_RATE_COUNT]; /**< Transmit rates in frames/s for
+                                         different statistics cycle periods.
+                                        */
+    s32 rx_frame_rates[EC_RATE_COUNT]; /**< Receive rates in frames/s for
+                                         different statistics cycle periods.
+                                        */
+    s32 tx_byte_rates[EC_RATE_COUNT]; /**< Transmit rates in byte/s for
+                                        different statistics cycle periods. */
+    s32 rx_byte_rates[EC_RATE_COUNT]; /**< Receive rates in byte/s for
+                                        different statistics cycle periods. */
 
 #ifdef EC_DEBUG_IF
     ec_debug_t dbg; /**< debug device */
--- a/master/ioctl.h	Mon Mar 19 09:56:36 2012 +0100
+++ b/master/ioctl.h	Mon Mar 19 10:43:09 2012 +0100
@@ -56,7 +56,7 @@
  *
  * Increment this when changing the ioctl interface!
  */
-#define EC_IOCTL_VERSION_MAGIC 15
+#define EC_IOCTL_VERSION_MAGIC 16
 
 // Command-line tool
 #define EC_IOCTL_MODULE                EC_IOR(0x00, ec_ioctl_module_t)
@@ -170,19 +170,19 @@
         uint64_t tx_bytes;
         uint64_t rx_bytes;
         uint64_t tx_errors;
-        uint32_t tx_frame_rates[EC_RATE_COUNT];
-        uint32_t rx_frame_rates[EC_RATE_COUNT];
-        uint32_t tx_byte_rates[EC_RATE_COUNT];
-        uint32_t rx_byte_rates[EC_RATE_COUNT];
+        int32_t tx_frame_rates[EC_RATE_COUNT];
+        int32_t rx_frame_rates[EC_RATE_COUNT];
+        int32_t tx_byte_rates[EC_RATE_COUNT];
+        int32_t rx_byte_rates[EC_RATE_COUNT];
     } devices[EC_NUM_DEVICES];
     uint64_t tx_count;
     uint64_t rx_count;
     uint64_t tx_bytes;
     uint64_t rx_bytes;
-    uint32_t tx_frame_rates[EC_RATE_COUNT];
-    uint32_t rx_frame_rates[EC_RATE_COUNT];
-    uint32_t tx_byte_rates[EC_RATE_COUNT];
-    uint32_t rx_byte_rates[EC_RATE_COUNT];
+    int32_t tx_frame_rates[EC_RATE_COUNT];
+    int32_t rx_frame_rates[EC_RATE_COUNT];
+    int32_t tx_byte_rates[EC_RATE_COUNT];
+    int32_t rx_byte_rates[EC_RATE_COUNT];
     int32_t loss_rates[EC_RATE_COUNT];
     uint64_t app_time;
     uint16_t ref_clock;
--- a/master/master.c	Mon Mar 19 09:56:36 2012 +0100
+++ b/master/master.c	Mon Mar 19 10:43:09 2012 +0100
@@ -1229,9 +1229,8 @@
         )
 {
     ec_device_stats_t *s = &master->device_stats;
-    u32 tx_frame_rate, rx_frame_rate, tx_byte_rate, rx_byte_rate;
+    s32 tx_frame_rate, rx_frame_rate, tx_byte_rate, rx_byte_rate, loss_rate;
     u64 loss;
-    s32 loss_rate;
     unsigned int i;
 
     // frame statistics
@@ -1239,27 +1238,26 @@
         return;
     }
 
-    tx_frame_rate = (u32) (s->tx_count - s->last_tx_count) * 1000;
-    rx_frame_rate = (u32) (s->rx_count - s->last_rx_count) * 1000;
-    tx_byte_rate = (s->tx_bytes - s->last_tx_bytes);
-    rx_byte_rate = (s->rx_bytes - s->last_rx_bytes);
+    tx_frame_rate = (s->tx_count - s->last_tx_count) * 1000;
+    rx_frame_rate = (s->rx_count - s->last_rx_count) * 1000;
+    tx_byte_rate = s->tx_bytes - s->last_tx_bytes;
+    rx_byte_rate = s->rx_bytes - s->last_rx_bytes;
     loss = s->tx_count - s->rx_count;
-    loss_rate = (s32) (loss - s->last_loss) * 1000;
-
+    loss_rate = (loss - s->last_loss) * 1000;
+
+    /* Low-pass filter:
+     *      Y_n = y_(n - 1) + T / tau * (x - y_(n - 1))   | T = 1
+     *   -> Y_n += (x - y_(n - 1)) / tau
+     */
     for (i = 0; i < EC_RATE_COUNT; i++) {
-        unsigned int n = rate_intervals[i];
-        s->tx_frame_rates[i] =
-            (s->tx_frame_rates[i] * (n - 1) + tx_frame_rate) / n;
-        s->rx_frame_rates[i] =
-            (s->rx_frame_rates[i] * (n - 1) + rx_frame_rate) / n;
-        s->tx_byte_rates[i] =
-            (s->tx_byte_rates[i] * (n - 1) + tx_byte_rate) / n;
-        s->rx_byte_rates[i] =
-            (s->rx_byte_rates[i] * (n - 1) + rx_byte_rate) / n;
-        s->loss_rates[i] =
-            (s->loss_rates[i] * (n - 1) + loss_rate) / n;
-
-    }
+        s32 n = rate_intervals[i];
+        s->tx_frame_rates[i] += (tx_frame_rate - s->tx_frame_rates[i]) / n;
+        s->rx_frame_rates[i] += (rx_frame_rate - s->rx_frame_rates[i]) / n;
+        s->tx_byte_rates[i] += (tx_byte_rate - s->tx_byte_rates[i]) / n;
+        s->rx_byte_rates[i] += (rx_byte_rate - s->rx_byte_rates[i]) / n;
+        s->loss_rates[i] += (loss_rate - s->loss_rates[i]) / n;
+    }
+
     s->last_tx_count = s->tx_count;
     s->last_rx_count = s->rx_count;
     s->last_tx_bytes = s->tx_bytes;
--- a/master/master.h	Mon Mar 19 09:56:36 2012 +0100
+++ b/master/master.h	Mon Mar 19 10:43:09 2012 +0100
@@ -151,19 +151,17 @@
     u64 last_rx_bytes; /**< Number of bytes received of last statistics cycle.
                         */
     u64 last_loss; /**< Tx/Rx difference of last statistics cycle. */
-    unsigned int tx_frame_rates[EC_RATE_COUNT]; /**< Transmit rates in
-                                                  frames/s for different
-                                                  statistics cycle periods. */
-    unsigned int rx_frame_rates[EC_RATE_COUNT]; /**< Receive rates in
-                                                  frames/s for different
-                                                  statistics cycle periods. */
-    unsigned int tx_byte_rates[EC_RATE_COUNT]; /**< Transmit rates in byte/s
-                                                 for different statistics
-                                                 cycle periods. */
-    unsigned int rx_byte_rates[EC_RATE_COUNT]; /**< Receive rates in byte/s
-                                                 for different statistics
-                                                 cycle periods. */
-    int loss_rates[EC_RATE_COUNT]; /**< Frame loss rates for different
+    s32 tx_frame_rates[EC_RATE_COUNT]; /**< Transmit rates in frames/s for
+                                         different statistics cycle periods.
+                                        */
+    s32 rx_frame_rates[EC_RATE_COUNT]; /**< Receive rates in frames/s for
+                                         different statistics cycle periods.
+                                        */
+    s32 tx_byte_rates[EC_RATE_COUNT]; /**< Transmit rates in byte/s for
+                                        different statistics cycle periods. */
+    s32 rx_byte_rates[EC_RATE_COUNT]; /**< Receive rates in byte/s for
+                                        different statistics cycle periods. */
+    s32 loss_rates[EC_RATE_COUNT]; /**< Frame loss rates for different
                                      statistics cycle periods. */
     unsigned long jiffies; /**< Jiffies of last statistic cycle. */
 } ec_device_stats_t;