# HG changeset patch # User Florian Pose # Date 1268125172 -3600 # Node ID 10175d5f35ea68077fef11a977b6c90f807d30f9 # Parent 30ddfc665fcb393f8d6c51e8b57e7ddaa975e170 Fixed clearing frame statistics on link down. diff -r 30ddfc665fcb -r 10175d5f35ea TODO --- a/TODO Mon Mar 08 12:20:19 2010 +0100 +++ b/TODO Tue Mar 09 09:59:32 2010 +0100 @@ -46,7 +46,6 @@ - Implement ranges for slaves and domains. * Output send errors in frame statistics. * Output tx rate [bytes/s] in frame statistics. -* Fix clearing statistics on link down. Future issues: diff -r 30ddfc665fcb -r 10175d5f35ea master/device.c --- a/master/device.c Mon Mar 08 12:20:19 2010 +0100 +++ b/master/device.c Tue Mar 09 09:59:32 2010 +0100 @@ -324,37 +324,22 @@ // frame statistics if (unlikely(jiffies - device->stats_jiffies >= HZ)) { unsigned int i; - if (device->link_state) { - unsigned int tx_rate = - (device->tx_count - device->last_tx_count) * 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->loss_rates[i] = - (device->loss_rates[i] * (n - 1) + loss_rate) / n; - } - device->last_tx_count = device->tx_count; - device->last_loss = loss; - } else { - // zero frame statistics - 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; - } + unsigned int tx_rate = + (device->tx_count - device->last_tx_count) * 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->loss_rates[i] = + (device->loss_rates[i] * (n - 1) + loss_rate) / n; } + device->last_tx_count = device->tx_count; + device->last_loss = loss; device->stats_jiffies = jiffies; } - if (unlikely(!device->link_state)) // Link down - return; - // set the right length for the data skb->len = ETH_HLEN + size; @@ -384,6 +369,27 @@ /*****************************************************************************/ +/** Clears the frame statistics. + */ +void ec_device_clear_stats( + ec_device_t *device /**< EtherCAT device */ + ) +{ + unsigned int i; + + // zero frame statistics + 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; + } +} + +/*****************************************************************************/ + #ifdef EC_DEBUG_RING /** Appends frame data to the debug ring. */ diff -r 30ddfc665fcb -r 10175d5f35ea master/device.h --- a/master/device.h Mon Mar 08 12:20:19 2010 +0100 +++ b/master/device.h Tue Mar 09 09:59:32 2010 +0100 @@ -134,6 +134,7 @@ void ec_device_poll(ec_device_t *); uint8_t *ec_device_tx_data(ec_device_t *); void ec_device_send(ec_device_t *, size_t); +void ec_device_clear_stats(ec_device_t *); #ifdef EC_DEBUG_RING void ec_device_debug_ring_append(ec_device_t *, ec_debug_frame_dir_t, diff -r 30ddfc665fcb -r 10175d5f35ea master/master.c --- a/master/master.c Mon Mar 08 12:20:19 2010 +0100 +++ b/master/master.c Tue Mar 09 09:59:32 2010 +0100 @@ -2084,6 +2084,9 @@ // query link state ec_device_poll(&master->main_device); + + // clear frame statistics + ec_device_clear_stats(&master->main_device); return; }