blob: c6028fd742c1a18309a323a016e3be076d9b13be [file] [log] [blame]
Bruno Randolfc5485a72010-11-16 10:58:37 +09001#ifndef _LINUX_AVERAGE_H
2#define _LINUX_AVERAGE_H
3
Bruno Randolfc5485a72010-11-16 10:58:37 +09004/* Exponentially weighted moving average (EWMA) */
5
6/* For more documentation see lib/average.c */
7
8struct ewma {
9 unsigned long internal;
10 unsigned long factor;
11 unsigned long weight;
12};
13
14extern void ewma_init(struct ewma *avg, unsigned long factor,
15 unsigned long weight);
16
17extern struct ewma *ewma_add(struct ewma *avg, unsigned long val);
18
19/**
20 * ewma_read() - Get average value
21 * @avg: Average structure
22 *
23 * Returns the average value held in @avg.
24 */
25static inline unsigned long ewma_read(const struct ewma *avg)
26{
Bruno Randolfaf556882010-12-02 19:50:37 +090027 return avg->internal >> avg->factor;
Bruno Randolfc5485a72010-11-16 10:58:37 +090028}
29
30#endif /* _LINUX_AVERAGE_H */