diff options
Diffstat (limited to 'include/linux/average.h')
| -rw-r--r-- | include/linux/average.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/include/linux/average.h b/include/linux/average.h new file mode 100644 index 000000000000..c6028fd742c1 --- /dev/null +++ b/include/linux/average.h | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | #ifndef _LINUX_AVERAGE_H | ||
| 2 | #define _LINUX_AVERAGE_H | ||
| 3 | |||
| 4 | /* Exponentially weighted moving average (EWMA) */ | ||
| 5 | |||
| 6 | /* For more documentation see lib/average.c */ | ||
| 7 | |||
| 8 | struct ewma { | ||
| 9 | unsigned long internal; | ||
| 10 | unsigned long factor; | ||
| 11 | unsigned long weight; | ||
| 12 | }; | ||
| 13 | |||
| 14 | extern void ewma_init(struct ewma *avg, unsigned long factor, | ||
| 15 | unsigned long weight); | ||
| 16 | |||
| 17 | extern 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 | */ | ||
| 25 | static inline unsigned long ewma_read(const struct ewma *avg) | ||
| 26 | { | ||
| 27 | return avg->internal >> avg->factor; | ||
| 28 | } | ||
| 29 | |||
| 30 | #endif /* _LINUX_AVERAGE_H */ | ||
