average.h 697 B

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