From f30e8a0572f958f510ecf9e5e3f90aaffc9b449a Mon Sep 17 00:00:00 2001 From: Florian Pose Date: Mon, 19 Mar 2012 10:43:09 +0100 Subject: [PATCH] Improved/fixed frame statistics (low-pass filters). --- master/device.c | 34 +++++++++++++++++----------------- master/device.h | 22 ++++++++++------------ master/ioctl.h | 18 +++++++++--------- master/master.c | 36 +++++++++++++++++------------------- master/master.h | 24 +++++++++++------------- 5 files changed, 64 insertions(+), 70 deletions(-) diff --git a/master/device.c b/master/device.c index 276055cf..0b4176fa 100644 --- a/master/device.c +++ b/master/device.c @@ -465,25 +465,25 @@ void ec_device_update_stats( { unsigned int i; - u32 tx_frame_rate = - (u32) (device->tx_count - device->last_tx_count) * 1000; - u32 rx_frame_rate = - (u32) (device->rx_count - device->last_rx_count) * 1000; - u32 tx_byte_rate = - (device->tx_bytes - device->last_tx_bytes); - u32 rx_byte_rate = - (device->rx_bytes - device->last_rx_bytes); + s32 tx_frame_rate = (device->tx_count - device->last_tx_count) * 1000; + s32 rx_frame_rate = (device->rx_count - device->last_rx_count) * 1000; + s32 tx_byte_rate = (device->tx_bytes - device->last_tx_bytes); + s32 rx_byte_rate = (device->rx_bytes - device->last_rx_bytes); + /* Low-pass filter: + * Y_n = y_(n - 1) + T / tau * (x - y_(n - 1)) | T = 1 + * -> Y_n += (x - y_(n - 1)) / tau + */ for (i = 0; i < EC_RATE_COUNT; i++) { - unsigned int n = rate_intervals[i]; - device->tx_frame_rates[i] = - (device->tx_frame_rates[i] * (n - 1) + tx_frame_rate) / n; - device->rx_frame_rates[i] = - (device->rx_frame_rates[i] * (n - 1) + rx_frame_rate) / n; - device->tx_byte_rates[i] = - (device->tx_byte_rates[i] * (n - 1) + tx_byte_rate) / n; - device->rx_byte_rates[i] = - (device->rx_byte_rates[i] * (n - 1) + rx_byte_rate) / n; + s32 n = rate_intervals[i]; + device->tx_frame_rates[i] += + (tx_frame_rate - device->tx_frame_rates[i]) / n; + device->rx_frame_rates[i] += + (rx_frame_rate - device->rx_frame_rates[i]) / n; + device->tx_byte_rates[i] += + (tx_byte_rate - device->tx_byte_rates[i]) / n; + device->rx_byte_rates[i] += + (rx_byte_rate - device->rx_byte_rates[i]) / n; } device->last_tx_count = device->tx_count; diff --git a/master/device.h b/master/device.h index c1f3a240..31486bf1 100644 --- a/master/device.h +++ b/master/device.h @@ -109,18 +109,16 @@ struct ec_device u64 last_rx_bytes; /**< Number of bytes received of last statistics cycle. */ u64 tx_errors; /**< Number of transmit errors. */ - unsigned int tx_frame_rates[EC_RATE_COUNT]; /**< Transmit rates in - frames/s for different - statistics cycle periods. */ - unsigned int rx_frame_rates[EC_RATE_COUNT]; /**< Receive rates in - frames/s for different - statistics cycle periods. */ - unsigned int tx_byte_rates[EC_RATE_COUNT]; /**< Transmit rates in byte/s - for different statistics - cycle periods. */ - unsigned int rx_byte_rates[EC_RATE_COUNT]; /**< Receive rates in byte/s - for different statistics - cycle periods. */ + s32 tx_frame_rates[EC_RATE_COUNT]; /**< Transmit rates in frames/s for + different statistics cycle periods. + */ + s32 rx_frame_rates[EC_RATE_COUNT]; /**< Receive rates in frames/s for + different statistics cycle periods. + */ + s32 tx_byte_rates[EC_RATE_COUNT]; /**< Transmit rates in byte/s for + different statistics cycle periods. */ + s32 rx_byte_rates[EC_RATE_COUNT]; /**< Receive rates in byte/s for + different statistics cycle periods. */ #ifdef EC_DEBUG_IF ec_debug_t dbg; /**< debug device */ diff --git a/master/ioctl.h b/master/ioctl.h index aa01a35b..8659c4b4 100644 --- a/master/ioctl.h +++ b/master/ioctl.h @@ -56,7 +56,7 @@ * * Increment this when changing the ioctl interface! */ -#define EC_IOCTL_VERSION_MAGIC 15 +#define EC_IOCTL_VERSION_MAGIC 16 // Command-line tool #define EC_IOCTL_MODULE EC_IOR(0x00, ec_ioctl_module_t) @@ -170,19 +170,19 @@ typedef struct { uint64_t tx_bytes; uint64_t rx_bytes; uint64_t tx_errors; - uint32_t tx_frame_rates[EC_RATE_COUNT]; - uint32_t rx_frame_rates[EC_RATE_COUNT]; - uint32_t tx_byte_rates[EC_RATE_COUNT]; - uint32_t rx_byte_rates[EC_RATE_COUNT]; + int32_t tx_frame_rates[EC_RATE_COUNT]; + int32_t rx_frame_rates[EC_RATE_COUNT]; + int32_t tx_byte_rates[EC_RATE_COUNT]; + int32_t rx_byte_rates[EC_RATE_COUNT]; } devices[EC_NUM_DEVICES]; uint64_t tx_count; uint64_t rx_count; uint64_t tx_bytes; uint64_t rx_bytes; - uint32_t tx_frame_rates[EC_RATE_COUNT]; - uint32_t rx_frame_rates[EC_RATE_COUNT]; - uint32_t tx_byte_rates[EC_RATE_COUNT]; - uint32_t rx_byte_rates[EC_RATE_COUNT]; + int32_t tx_frame_rates[EC_RATE_COUNT]; + int32_t rx_frame_rates[EC_RATE_COUNT]; + int32_t tx_byte_rates[EC_RATE_COUNT]; + int32_t rx_byte_rates[EC_RATE_COUNT]; int32_t loss_rates[EC_RATE_COUNT]; uint64_t app_time; uint16_t ref_clock; diff --git a/master/master.c b/master/master.c index 80de0664..9444c728 100644 --- a/master/master.c +++ b/master/master.c @@ -1229,9 +1229,8 @@ void ec_master_update_device_stats( ) { ec_device_stats_t *s = &master->device_stats; - u32 tx_frame_rate, rx_frame_rate, tx_byte_rate, rx_byte_rate; + s32 tx_frame_rate, rx_frame_rate, tx_byte_rate, rx_byte_rate, loss_rate; u64 loss; - s32 loss_rate; unsigned int i; // frame statistics @@ -1239,27 +1238,26 @@ void ec_master_update_device_stats( return; } - tx_frame_rate = (u32) (s->tx_count - s->last_tx_count) * 1000; - rx_frame_rate = (u32) (s->rx_count - s->last_rx_count) * 1000; - tx_byte_rate = (s->tx_bytes - s->last_tx_bytes); - rx_byte_rate = (s->rx_bytes - s->last_rx_bytes); + tx_frame_rate = (s->tx_count - s->last_tx_count) * 1000; + rx_frame_rate = (s->rx_count - s->last_rx_count) * 1000; + tx_byte_rate = s->tx_bytes - s->last_tx_bytes; + rx_byte_rate = s->rx_bytes - s->last_rx_bytes; loss = s->tx_count - s->rx_count; - loss_rate = (s32) (loss - s->last_loss) * 1000; + loss_rate = (loss - s->last_loss) * 1000; + /* Low-pass filter: + * Y_n = y_(n - 1) + T / tau * (x - y_(n - 1)) | T = 1 + * -> Y_n += (x - y_(n - 1)) / tau + */ for (i = 0; i < EC_RATE_COUNT; i++) { - unsigned int n = rate_intervals[i]; - s->tx_frame_rates[i] = - (s->tx_frame_rates[i] * (n - 1) + tx_frame_rate) / n; - s->rx_frame_rates[i] = - (s->rx_frame_rates[i] * (n - 1) + rx_frame_rate) / n; - s->tx_byte_rates[i] = - (s->tx_byte_rates[i] * (n - 1) + tx_byte_rate) / n; - s->rx_byte_rates[i] = - (s->rx_byte_rates[i] * (n - 1) + rx_byte_rate) / n; - s->loss_rates[i] = - (s->loss_rates[i] * (n - 1) + loss_rate) / n; - + s32 n = rate_intervals[i]; + s->tx_frame_rates[i] += (tx_frame_rate - s->tx_frame_rates[i]) / n; + s->rx_frame_rates[i] += (rx_frame_rate - s->rx_frame_rates[i]) / n; + s->tx_byte_rates[i] += (tx_byte_rate - s->tx_byte_rates[i]) / n; + s->rx_byte_rates[i] += (rx_byte_rate - s->rx_byte_rates[i]) / n; + s->loss_rates[i] += (loss_rate - s->loss_rates[i]) / n; } + s->last_tx_count = s->tx_count; s->last_rx_count = s->rx_count; s->last_tx_bytes = s->tx_bytes; diff --git a/master/master.h b/master/master.h index 5115635a..308667dc 100644 --- a/master/master.h +++ b/master/master.h @@ -151,19 +151,17 @@ typedef struct { u64 last_rx_bytes; /**< Number of bytes received of last statistics cycle. */ u64 last_loss; /**< Tx/Rx difference of last statistics cycle. */ - unsigned int tx_frame_rates[EC_RATE_COUNT]; /**< Transmit rates in - frames/s for different - statistics cycle periods. */ - unsigned int rx_frame_rates[EC_RATE_COUNT]; /**< Receive rates in - frames/s for different - statistics cycle periods. */ - unsigned int tx_byte_rates[EC_RATE_COUNT]; /**< Transmit rates in byte/s - for different statistics - cycle periods. */ - unsigned int rx_byte_rates[EC_RATE_COUNT]; /**< Receive rates in byte/s - for different statistics - cycle periods. */ - int loss_rates[EC_RATE_COUNT]; /**< Frame loss rates for different + s32 tx_frame_rates[EC_RATE_COUNT]; /**< Transmit rates in frames/s for + different statistics cycle periods. + */ + s32 rx_frame_rates[EC_RATE_COUNT]; /**< Receive rates in frames/s for + different statistics cycle periods. + */ + s32 tx_byte_rates[EC_RATE_COUNT]; /**< Transmit rates in byte/s for + different statistics cycle periods. */ + s32 rx_byte_rates[EC_RATE_COUNT]; /**< Receive rates in byte/s for + different statistics cycle periods. */ + s32 loss_rates[EC_RATE_COUNT]; /**< Frame loss rates for different statistics cycle periods. */ unsigned long jiffies; /**< Jiffies of last statistic cycle. */ } ec_device_stats_t;