Store skipped information in datagrams; name datagrams for statistics
authorFlorian Pose <fp@igh-essen.com>
Wed, 12 Sep 2007 14:06:35 +0000
changeset 719 03d5b96632fb
parent 718 80df6930e7e6
child 720 9664a19978dd
Store skipped information in datagrams; name datagrams for statistics
output.
master/datagram.c
master/datagram.h
master/domain.c
master/ethernet.c
master/master.c
master/master.h
--- a/master/datagram.c	Wed Sep 12 13:20:59 2007 +0000
+++ b/master/datagram.c	Wed Sep 12 14:06:35 2007 +0000
@@ -82,6 +82,9 @@
     datagram->jiffies_sent = 0;
     datagram->cycles_received = 0;
     datagram->jiffies_received = 0;
+    datagram->skip_count = 0;
+    datagram->stats_output_jiffies = 0;
+    datagram->name[0] = 0x00;
 }
 
 /*****************************************************************************/
@@ -319,3 +322,26 @@
 }
 
 /*****************************************************************************/
+
+/**
+ * Outputs datagram statistics at most every second.
+ */
+
+void ec_datagram_output_stats(
+        ec_datagram_t *datagram
+        )
+{
+    if (jiffies - datagram->stats_output_jiffies < HZ) {
+        datagram->stats_output_jiffies = jiffies;
+    
+        if (unlikely(datagram->skip_count)) {
+            EC_WARN("Datagram %x (%s) was SKIPPED %u time%s.\n",
+                    (unsigned int) datagram, datagram->name,
+                    datagram->skip_count,
+                    datagram->skip_count == 1 ? "" : "s");
+            datagram->skip_count = 0;
+        }
+    }
+}
+
+/*****************************************************************************/
--- a/master/datagram.h	Wed Sep 12 13:20:59 2007 +0000
+++ b/master/datagram.h	Wed Sep 12 14:06:35 2007 +0000
@@ -49,6 +49,11 @@
 
 /*****************************************************************************/
 
+/** size of the datagram description string */
+#define EC_DATAGRAM_NAME_SIZE 20
+
+/*****************************************************************************/
+
 /**
    EtherCAT datagram type.
 */
@@ -103,7 +108,10 @@
     cycles_t cycles_sent; /**< time, the datagram was sent */
     unsigned long jiffies_sent; /**< jiffies, when the datagram was sent */
     cycles_t cycles_received; /**< time, when the datagram was received */
-    unsigned long jiffies_received; /**< jiffies, when the datagram was rec. */
+    unsigned long jiffies_received; /**< jiffies the datagram was received */
+    unsigned int skip_count; /**< number of requeues when not yet received */
+    unsigned long stats_output_jiffies; /**< last statistics output */
+    char name[EC_DATAGRAM_NAME_SIZE]; /**< description of the datagram */
 }
 ec_datagram_t;
 
@@ -122,6 +130,7 @@
 int ec_datagram_lrw(ec_datagram_t *, uint32_t, size_t);
 
 void ec_datagram_print_wc_error(const ec_datagram_t *);
+void ec_datagram_output_stats(ec_datagram_t *datagram);
 
 /*****************************************************************************/
 
--- a/master/domain.c	Wed Sep 12 13:20:59 2007 +0000
+++ b/master/domain.c	Wed Sep 12 14:06:35 2007 +0000
@@ -269,6 +269,8 @@
     }
 
     ec_datagram_init(datagram);
+    snprintf(datagram->name, EC_DATAGRAM_NAME_SIZE,
+            "domain%u-%u", domain->index, offset);
 
     if (ec_datagram_lrw(datagram, offset, data_size)) {
         kfree(datagram);
@@ -547,6 +549,7 @@
     working_counter_sum = 0;
     domain->state = 0;
     list_for_each_entry(datagram, &domain->datagrams, list) {
+        ec_datagram_output_stats(datagram);
         if (datagram->state == EC_DATAGRAM_RECEIVED) {
             working_counter_sum += datagram->working_counter;
         }
--- a/master/ethernet.c	Wed Sep 12 13:20:59 2007 +0000
+++ b/master/ethernet.c	Wed Sep 12 14:06:35 2007 +0000
@@ -94,7 +94,7 @@
 {
     ec_eoe_t **priv;
     int result, i;
-    char name[20];
+    char name[EC_DATAGRAM_NAME_SIZE];
 
     eoe->slave = slave;
 
@@ -120,10 +120,14 @@
     /* device name eoe<MASTER>[as]<SLAVE>, because networking scripts don't
      * like hyphens etc. in interface names. */
     if (slave->sii_alias) {
-        sprintf(name, "eoe%ua%u", slave->master->index, slave->sii_alias);
+        snprintf(name, EC_DATAGRAM_NAME_SIZE,
+                "eoe%ua%u", slave->master->index, slave->sii_alias);
     } else {
-        sprintf(name, "eoe%us%u", slave->master->index, slave->ring_position);
-    }
+        snprintf(name, EC_DATAGRAM_NAME_SIZE,
+                "eoe%us%u", slave->master->index, slave->ring_position);
+    }
+
+    snprintf(eoe->datagram.name, EC_DATAGRAM_NAME_SIZE, name);
 
     if (!(eoe->dev = alloc_netdev(sizeof(ec_eoe_t *), name, ether_setup))) {
         EC_ERR("Unable to allocate net_device %s for EoE handler!\n", name);
@@ -307,6 +311,7 @@
         eoe->tx_counter = 0;
         eoe->rate_jiffies = jiffies;
     }
+    ec_datagram_output_stats(&eoe->datagram);
 }
 
 /*****************************************************************************/
--- a/master/master.c	Wed Sep 12 13:20:59 2007 +0000
+++ b/master/master.c	Wed Sep 12 14:06:35 2007 +0000
@@ -143,7 +143,6 @@
 
     master->stats.timeouts = 0;
     master->stats.corrupted = 0;
-    master->stats.skipped = 0;
     master->stats.unmatched = 0;
     master->stats.output_jiffies = 0;
 
@@ -186,6 +185,7 @@
 
     // init state machine datagram
     ec_datagram_init(&master->fsm_datagram);
+    snprintf(master->fsm_datagram.name, EC_DATAGRAM_NAME_SIZE, "master-fsm");
     if (ec_datagram_prealloc(&master->fsm_datagram, EC_MAX_DATA_SIZE)) {
         EC_ERR("Failed to allocate FSM datagram.\n");
         goto out_clear_backup;
@@ -548,10 +548,9 @@
     // check, if the datagram is already queued
     list_for_each_entry(queued_datagram, &master->datagram_queue, queue) {
         if (queued_datagram == datagram) {
-            master->stats.skipped++;
+            datagram->skip_count++;
             if (master->debug_level)
                 EC_DBG("skipping datagram %x.\n", (unsigned int) datagram);
-            ec_master_output_stats(master);
             datagram->state = EC_DATAGRAM_QUEUED;
             return;
         }
@@ -798,11 +797,6 @@
                     master->stats.corrupted == 1 ? "" : "s");
             master->stats.corrupted = 0;
         }
-        if (master->stats.skipped) {
-            EC_WARN("%i datagram%s SKIPPED!\n", master->stats.skipped,
-                    master->stats.skipped == 1 ? "" : "s");
-            master->stats.skipped = 0;
-        }
         if (master->stats.unmatched) {
             EC_WARN("%i datagram%s UNMATCHED!\n", master->stats.unmatched,
                     master->stats.unmatched == 1 ? "" : "s");
@@ -826,6 +820,7 @@
 
     while (!signal_pending(current)) {
         cycles_start = get_cycles();
+        ec_datagram_output_stats(&master->fsm_datagram);
 
         if (ec_fsm_master_running(&master->fsm)) { // datagram on the way
             // receive
@@ -882,6 +877,7 @@
     allow_signal(SIGTERM);
 
     while (!signal_pending(current)) {
+        ec_datagram_output_stats(&master->fsm_datagram);
         if (master->injection_seq_rt != master->injection_seq_fsm ||
                 master->fsm_datagram.state == EC_DATAGRAM_SENT ||
                 master->fsm_datagram.state == EC_DATAGRAM_QUEUED)
--- a/master/master.h	Wed Sep 12 13:20:59 2007 +0000
+++ b/master/master.h	Wed Sep 12 14:06:35 2007 +0000
@@ -75,8 +75,6 @@
 {
     unsigned int timeouts; /**< datagram timeouts */
     unsigned int corrupted; /**< corrupted frames */
-    unsigned int skipped; /**< skipped datagrams (the ones that were
-                             requeued when not yet received) */
     unsigned int unmatched; /**< unmatched datagrams (received, but not
                                queued any longer) */
     unsigned long output_jiffies; /**< time of last output */