Improved/fixed frame statistics (low-pass filters).

This commit is contained in:
Florian Pose 2012-03-19 10:43:09 +01:00
parent e960e20bb3
commit f30e8a0572
5 changed files with 64 additions and 70 deletions

View File

@ -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;

View File

@ -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 */

View File

@ -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;

View File

@ -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;

View File

@ -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;