2 * Copyright 2010 Hauke Mehrtens <hauke@hauke-m.de>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 * Compatibility file for Linux wireless for kernels 2.6.38.
11 #include <linux/compat.h>
12 #include <linux/module.h>
13 #include <linux/bug.h>
16 * ewma_init() - Initialize EWMA parameters
17 * @avg: Average structure
18 * @factor: Factor to use for the scaled up internal value. The maximum value
19 * of averages can be ULONG_MAX/(factor*weight).
20 * @weight: Exponential weight, or decay rate. This defines how fast the
21 * influence of older values decreases. Has to be bigger than 1.
23 * Initialize the EWMA parameters for a given struct ewma @avg.
25 void ewma_init(struct ewma *avg, unsigned long factor, unsigned long weight)
27 WARN_ON(weight <= 1 || factor == 0);
32 EXPORT_SYMBOL(ewma_init);
35 * ewma_add() - Exponentially weighted moving average (EWMA)
36 * @avg: Average structure
39 * Add a sample to the average.
41 struct ewma *ewma_add(struct ewma *avg, unsigned long val)
43 avg->internal = avg->internal ?
44 (((avg->internal * (avg->weight - 1)) +
45 (val * avg->factor)) / avg->weight) :
49 EXPORT_SYMBOL(ewma_add);