blob: 56569604278f27277635ce63f1d696a4877f0568 [file] [log] [blame]
Neal Cardwella4f1f9a2016-09-19 23:39:09 -04001/**
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 */
11struct minmax_sample {
12 u32 t; /* time measurement was taken */
13 u32 v; /* value measured */
14};
15
16/* State for the parameterized min-max tracker */
17struct minmax {
18 struct minmax_sample s[3];
19};
20
21static inline u32 minmax_get(const struct minmax *m)
22{
23 return m->s[0].v;
24}
25
26static 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
34u32 minmax_running_max(struct minmax *m, u32 win, u32 t, u32 meas);
35u32 minmax_running_min(struct minmax *m, u32 win, u32 t, u32 meas);
36
37#endif