mirror of
https://gitlab.com/etherlab.org/ethercat.git
synced 2026-02-06 03:41:52 +08:00
Fixed clearing frame statistics on link down.
This commit is contained in:
1
TODO
1
TODO
@@ -46,7 +46,6 @@ Version 1.5.0:
|
||||
- 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:
|
||||
|
||||
|
||||
@@ -324,37 +324,22 @@ void ec_device_send(
|
||||
// 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 @@ void ec_device_send(
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/** 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.
|
||||
*/
|
||||
|
||||
@@ -134,6 +134,7 @@ int ec_device_close(ec_device_t *);
|
||||
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,
|
||||
|
||||
@@ -2084,6 +2084,9 @@ void ecrt_master_send(ec_master_t *master)
|
||||
|
||||
// query link state
|
||||
ec_device_poll(&master->main_device);
|
||||
|
||||
// clear frame statistics
|
||||
ec_device_clear_stats(&master->main_device);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user