Neal Cardwell | a4f1f9a | 2016-09-19 23:39:09 -0400 | [diff] [blame] | 1 | /** |
| 2 | * lib/minmax.c: windowed min/max tracker by Kathleen Nichols. |
| 3 | * |
| 4 | */ |
| 5 | #ifndef MINMAX_H |
| 6 | #define MINMAX_H |
| 7 | |
| 8 | #include <linux/types.h> |
| 9 | |
| 10 | /* A single data point for our parameterized min-max tracker */ |
| 11 | struct minmax_sample { |
| 12 | u32 t; /* time measurement was taken */ |
| 13 | u32 v; /* value measured */ |
| 14 | }; |
| 15 | |
| 16 | /* State for the parameterized min-max tracker */ |
| 17 | struct minmax { |
| 18 | struct minmax_sample s[3]; |
| 19 | }; |
| 20 | |
| 21 | static inline u32 minmax_get(const struct minmax *m) |
| 22 | { |
| 23 | return m->s[0].v; |
| 24 | } |
| 25 | |
| 26 | static inline u32 minmax_reset(struct minmax *m, u32 t, u32 meas) |
| 27 | { |
| 28 | struct minmax_sample val = { .t = t, .v = meas }; |
| 29 | |
| 30 | m->s[2] = m->s[1] = m->s[0] = val; |
| 31 | return m->s[0].v; |
| 32 | } |
| 33 | |
| 34 | u32 minmax_running_max(struct minmax *m, u32 win, u32 t, u32 meas); |
| 35 | u32 minmax_running_min(struct minmax *m, u32 win, u32 t, u32 meas); |
| 36 | |
| 37 | #endif |