average.h 653 B

12345678910111213141516171819202122232425262728293031
  1. #ifndef _LINUX_AVERAGE_H
  2. #define _LINUX_AVERAGE_H
  3. /* Exponentially weighted moving average (EWMA) */
  4. /* For more documentation see lib/average.c */
  5. struct ewma {
  6. unsigned long internal;
  7. unsigned long factor;
  8. unsigned long weight;
  9. };
  10. extern void ewma_init(struct ewma *avg, unsigned long factor,
  11. unsigned long weight);
  12. extern struct ewma *ewma_add(struct ewma *avg, unsigned long val);
  13. /**
  14. * ewma_read() - Get average value
  15. * @avg: Average structure
  16. *
  17. * Returns the average value held in @avg.
  18. */
  19. static inline unsigned long ewma_read(const struct ewma *avg)
  20. {
  21. return avg->internal >> avg->factor;
  22. }
  23. #endif /* _LINUX_AVERAGE_H */