EoE rate statistics.
authorFlorian Pose <fp@igh-essen.com>
Fri, 04 Aug 2006 15:31:12 +0000
changeset 336 360e5287c888
parent 335 1e37c856b74e
child 337 6fd537c56448
EoE rate statistics.
master/ethernet.c
master/ethernet.h
master/master.c
--- a/master/ethernet.c	Fri Aug 04 13:49:22 2006 +0000
+++ b/master/ethernet.c	Fri Aug 04 15:31:12 2006 +0000
@@ -101,6 +101,12 @@
     eoe->tx_frame_number = 0xFF;
     memset(&eoe->stats, 0, sizeof(struct net_device_stats));
 
+    eoe->rx_counter = 0;
+    eoe->tx_counter = 0;
+    eoe->rx_rate = 0;
+    eoe->tx_rate = 0;
+    eoe->t_last = 0;
+
     if (!(eoe->dev =
           alloc_netdev(sizeof(ec_eoe_t *), "eoe%d", ether_setup))) {
         EC_ERR("Unable to allocate net_device for EoE handler!\n");
@@ -272,10 +278,22 @@
 
 void ec_eoe_run(ec_eoe_t *eoe /**< EoE handler */)
 {
+    cycles_t t_now;
+
     if (!eoe->opened) return;
 
     // call state function
     eoe->state(eoe);
+
+    // update statistics
+    t_now = get_cycles();
+    if ((u32) (t_now - eoe->t_last) > cpu_khz * 1000) {
+        eoe->rx_rate = eoe->rx_counter * 8;
+        eoe->tx_rate = eoe->tx_counter * 8;
+        eoe->rx_counter = 0;
+        eoe->tx_counter = 0;
+        eoe->t_last = t_now;
+    }
 }
 
 /*****************************************************************************/
@@ -452,6 +470,7 @@
         // update statistics
         eoe->stats.rx_packets++;
         eoe->stats.rx_bytes += eoe->rx_skb->len;
+        eoe->rx_counter += eoe->rx_skb->len;
 
 #if EOE_DEBUG_LEVEL > 0
         EC_DBG("EoE RX frame completed with %u octets.\n",
@@ -568,6 +587,7 @@
     if (eoe->tx_offset >= eoe->tx_frame->skb->len) {
         eoe->stats.tx_packets++;
         eoe->stats.tx_bytes += eoe->tx_frame->skb->len;
+        eoe->tx_counter += eoe->tx_frame->skb->len;
         dev_kfree_skb(eoe->tx_frame->skb);
         kfree(eoe->tx_frame);
         eoe->tx_frame = NULL;
--- a/master/ethernet.h	Fri Aug 04 13:49:22 2006 +0000
+++ b/master/ethernet.h	Fri Aug 04 15:31:12 2006 +0000
@@ -90,6 +90,11 @@
     uint8_t tx_frame_number; /**< number of the transmitted frame */
     uint8_t tx_fragment_number; /**< number of the fragment */
     size_t tx_offset; /**< number of octets sent */
+    uint32_t rx_counter; /**< octets received during last second */
+    uint32_t tx_counter; /**< octets transmitted during last second */
+    uint32_t rx_rate; /**< receive rate (bps) */
+    uint32_t tx_rate; /**< transmit rate (bps) */
+    cycles_t t_last; /**< time of last output */
 };
 
 /*****************************************************************************/
--- a/master/master.c	Fri Aug 04 13:49:22 2006 +0000
+++ b/master/master.c	Fri Aug 04 15:31:12 2006 +0000
@@ -707,6 +707,7 @@
                        )
 {
     off_t off = 0;
+    ec_eoe_t *eoe;
     uint32_t cur, sum, min, max, pos, i;
 
     off += sprintf(buffer + off, "\nMode: ");
@@ -753,6 +754,13 @@
     off += sprintf(buffer + off, "  EoE cycle: %u / %u.%u / %u\n",
                    min, sum / HZ, (sum * 100 / HZ) % 100, max);
 
+    if (!list_empty(&master->eoe_handlers))
+        off += sprintf(buffer + off, "\nEoE Statistics (RX/TX) [bps]:");
+    list_for_each_entry(eoe, &master->eoe_handlers, list) {
+        off += sprintf(buffer + off, "  %s: %u / %u\n",
+                       eoe->dev->name, eoe->rx_rate, eoe->tx_rate);
+    }
+
     off += sprintf(buffer + off, "\n");
 
     return off;