From 337d7f763b050bb1749b0904a35890a2cfb1ec0a Mon Sep 17 00:00:00 2001 From: Florian Pose Date: Fri, 4 Aug 2006 15:31:12 +0000 Subject: [PATCH] EoE rate statistics. --- master/ethernet.c | 20 ++++++++++++++++++++ master/ethernet.h | 5 +++++ master/master.c | 8 ++++++++ 3 files changed, 33 insertions(+) diff --git a/master/ethernet.c b/master/ethernet.c index ce5cc69d..eb1f30c4 100644 --- a/master/ethernet.c +++ b/master/ethernet.c @@ -101,6 +101,12 @@ int ec_eoe_init(ec_eoe_t *eoe /**< EoE handler */) 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 @@ int ec_eoe_send(ec_eoe_t *eoe /**< EoE handler */) 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 @@ void ec_eoe_state_rx_fetch(ec_eoe_t *eoe /**< EoE handler */) // 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 @@ void ec_eoe_state_tx_sent(ec_eoe_t *eoe /**< EoE handler */) 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; diff --git a/master/ethernet.h b/master/ethernet.h index 1810362b..7b269218 100644 --- a/master/ethernet.h +++ b/master/ethernet.h @@ -90,6 +90,11 @@ struct ec_eoe 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 */ }; /*****************************************************************************/ diff --git a/master/master.c b/master/master.c index c8f738bf..28cb9635 100644 --- a/master/master.c +++ b/master/master.c @@ -707,6 +707,7 @@ ssize_t ec_master_info(ec_master_t *master, /**< EtherCAT master */ ) { 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 @@ ssize_t ec_master_info(ec_master_t *master, /**< EtherCAT master */ 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;