Output tx errors and tx rate in byte/s.
authorFlorian Pose <fp@igh-essen.com>
Tue, 09 Mar 2010 10:22:32 +0100
changeset 1857 ed8b490b5bc3
parent 1856 10175d5f35ea
child 1858 4d4aa4c0fc1e
Output tx errors and tx rate in byte/s.
TODO
master/cdev.c
master/device.c
master/device.h
master/ioctl.h
tool/CommandMaster.cpp
--- a/TODO	Tue Mar 09 09:59:32 2010 +0100
+++ b/TODO	Tue Mar 09 10:22:32 2010 +0100
@@ -44,8 +44,6 @@
 * 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/cdev.c	Tue Mar 09 09:59:32 2010 +0100
+++ b/master/cdev.c	Tue Mar 09 10:22:32 2010 +0100
@@ -212,8 +212,13 @@
     data.devices[0].link_state = master->main_device.link_state ? 1 : 0;
     data.devices[0].tx_count = master->main_device.tx_count;
     data.devices[0].rx_count = master->main_device.rx_count;
+    data.devices[0].tx_bytes = master->main_device.tx_bytes;
+    data.devices[0].tx_errors = master->main_device.tx_errors;
     for (i = 0; i < EC_RATE_COUNT; i++) {
-        data.devices[0].tx_rates[i] = master->main_device.tx_rates[i];
+        data.devices[0].tx_frame_rates[i] =
+            master->main_device.tx_frame_rates[i];
+        data.devices[0].tx_byte_rates[i] =
+            master->main_device.tx_byte_rates[i];
         data.devices[0].loss_rates[i] = master->main_device.loss_rates[i];
     }
 
@@ -227,8 +232,13 @@
     data.devices[1].link_state = master->backup_device.link_state ? 1 : 0;
     data.devices[1].tx_count = master->backup_device.tx_count;
     data.devices[1].rx_count = master->backup_device.rx_count;
+    data.devices[1].tx_bytes = master->backup_device.tx_bytes;
+    data.devices[1].tx_errors = master->backup_device.tx_errors;
     for (i = 0; i < EC_RATE_COUNT; i++) {
-        data.devices[1].tx_rates[i] = master->backup_device.tx_rates[i];
+        data.devices[1].tx_frame_rates[i] =
+            master->backup_device.tx_frame_rates[i];
+        data.devices[1].tx_byte_rates[i] =
+            master->backup_device.tx_byte_rates[i];
         data.devices[1].loss_rates[i] = master->backup_device.loss_rates[i];
     }
 
--- a/master/device.c	Tue Mar 09 09:59:32 2010 +0100
+++ b/master/device.c	Tue Mar 09 10:22:32 2010 +0100
@@ -198,15 +198,9 @@
     device->module = NULL;
     device->open = 0;
     device->link_state = 0; // down
-    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->stats_jiffies = 0;
+
+    ec_device_clear_stats(device);
+
     for (i = 0; i < EC_TX_RING_SIZE; i++)
         device->tx_skb[i]->dev = NULL;
 }
@@ -222,7 +216,6 @@
         )
 {
     int ret;
-    unsigned int i;
 
     if (!device->dev) {
         EC_ERR("No net_device to open!\n");
@@ -235,15 +228,8 @@
     }
 
     device->link_state = 0;
-    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->stats_jiffies = 0;
+
+    ec_device_clear_stats(device);
 
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29)
     ret = device->dev->netdev_ops->ndo_open(device->dev);
@@ -324,18 +310,23 @@
     // frame statistics
     if (unlikely(jiffies - device->stats_jiffies >= HZ)) {
         unsigned int i;
-        unsigned int tx_rate =
+        unsigned int tx_frame_rate =
             (device->tx_count - device->last_tx_count) * 1000;
+        unsigned int tx_byte_rate =
+            (device->tx_bytes - device->last_tx_bytes) * 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->tx_frame_rates[i] =
+                (device->tx_frame_rates[i] * (n - 1) + tx_frame_rate) / n;
+            device->tx_byte_rates[i] =
+                (device->tx_byte_rates[i] * (n - 1) + tx_byte_rate) / n;
             device->loss_rates[i] =
                 (device->loss_rates[i] * (n - 1) + loss_rate) / n;
         }
         device->last_tx_count = device->tx_count;
+        device->last_tx_bytes = device->tx_bytes;
         device->last_loss = loss;
         device->stats_jiffies = jiffies;
     }
@@ -357,6 +348,7 @@
 #endif
     {
         device->tx_count++;
+        device->tx_bytes += ETH_HLEN + size;
 #ifdef EC_DEBUG_IF
         ec_debug_send(&device->dbg, skb->data, ETH_HLEN + size);
 #endif
@@ -364,6 +356,8 @@
         ec_device_debug_ring_append(
                 device, TX, skb->data + ETH_HLEN, size);
 #endif
+    } else {
+        device->tx_errors++;
     }
 }
 
@@ -380,10 +374,14 @@
     // zero frame statistics
     device->tx_count = 0;
     device->rx_count = 0;
+    device->tx_errors = 0;
+    device->tx_bytes = 0;
     device->last_tx_count = 0;
+    device->last_tx_bytes = 0;
     device->last_loss = 0;
     for (i = 0; i < EC_RATE_COUNT; i++) {
-        device->tx_rates[i] = 0;
+        device->tx_frame_rates[i] = 0;
+        device->tx_byte_rates[i] = 0;
         device->loss_rates[i] = 0;
     }
 }
--- a/master/device.h	Tue Mar 09 09:59:32 2010 +0100
+++ b/master/device.h	Tue Mar 09 10:22:32 2010 +0100
@@ -100,10 +100,18 @@
     // Frame statistics
     unsigned int tx_count; /**< Number of frames sent. */
     unsigned int rx_count; /**< Number of frames received. */
+    unsigned int tx_bytes; /**< Number of frames sent. */
+    unsigned int 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 tx_byte_rates[EC_RATE_COUNT]; /**< Transmit rates in byte/s
+                                                 for different statistics
+                                                 cycle periods. */
     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. */
+    unsigned int last_tx_bytes; /**< Number of bytes sent of last statistics
+                                  cycle. */
     int last_loss; /**< Tx/Rx difference of last statistics cycle. */
     int loss_rates[EC_RATE_COUNT]; /**< Frame loss rates for different
                                      statistics cycle periods. */
--- a/master/ioctl.h	Tue Mar 09 09:59:32 2010 +0100
+++ b/master/ioctl.h	Tue Mar 09 10:22:32 2010 +0100
@@ -157,13 +157,16 @@
     uint8_t phase;
     uint8_t active;
     uint8_t scan_busy;
-    struct {
+    struct ec_ioctl_device {
         uint8_t address[6];
         uint8_t attached;
         uint8_t link_state;
         uint32_t tx_count;
         uint32_t rx_count;
-        uint32_t tx_rates[EC_RATE_COUNT];
+        uint32_t tx_bytes;
+        uint32_t tx_errors;
+        uint32_t tx_frame_rates[EC_RATE_COUNT];
+        uint32_t tx_byte_rates[EC_RATE_COUNT];
         int32_t loss_rates[EC_RATE_COUNT];
     } devices[2];
     uint64_t app_time;
--- a/tool/CommandMaster.cpp	Tue Mar 09 09:59:32 2010 +0100
+++ b/tool/CommandMaster.cpp	Tue Mar 09 10:22:32 2010 +0100
@@ -131,31 +131,44 @@
                     << (data.devices[i].link_state ? "UP" : "DOWN") << endl
                     << "      Tx count: " << data.devices[i].tx_count << endl
                     << "      Rx count: " << data.devices[i].rx_count << endl
-                    << "      Tx rate [frames/s]:   "
+                    << "      Tx bytes: " << data.devices[i].tx_bytes << endl
+                    << "      Tx errors: " << data.devices[i].tx_errors << endl
+                    << "      Tx frame rate [1/s]: "
                     << setfill(' ') << setprecision(0) << fixed;
                 for (j = 0; j < EC_RATE_COUNT; j++) {
-                    cout << setw(5) << data.devices[i].tx_rates[j] / 1000.0;
+                    cout <<
+                        setw(5) << data.devices[i].tx_frame_rates[j] / 1000.0;
                     if (j < EC_RATE_COUNT - 1) {
                         cout << " ";
                     }
                 }
                 cout << endl
-                    << "      Loss rate [frames/s]: "
+                    << "      Tx rate [KByte/s]:   "
                     << setprecision(0) << fixed;
                 for (j = 0; j < EC_RATE_COUNT; j++) {
+                    cout <<
+                        setw(5) << data.devices[i].tx_byte_rates[j] / 1000.0;
+                    if (j < EC_RATE_COUNT - 1) {
+                        cout << " ";
+                    }
+                }
+                cout << endl
+                    << "      Loss rate [1/s]:     "
+                    << setprecision(0) << fixed;
+                for (j = 0; j < EC_RATE_COUNT; j++) {
                     cout << setw(5) << data.devices[i].loss_rates[j] / 1000.0;
                     if (j < EC_RATE_COUNT - 1) {
                         cout << " ";
                     }
                 }
                 cout << endl
-                    << "      Frame loss [%]:       "
+                    << "      Frame loss [%]:      "
                     << setprecision(1) << fixed;
                 for (j = 0; j < EC_RATE_COUNT; j++) {
                     double perc = 0.0;
-                    if (data.devices[i].tx_rates[j]) {
+                    if (data.devices[i].tx_frame_rates[j]) {
                         perc = 100.0 * data.devices[i].loss_rates[j] /
-                            data.devices[i].tx_rates[j];
+                            data.devices[i].tx_frame_rates[j];
                     }
                     cout << setw(5) << perc;
                     if (j < EC_RATE_COUNT - 1) {