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