Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /**
0003  * lib/minmax.c: windowed min/max tracker by Kathleen Nichols.
0004  *
0005  */
0006 #ifndef MINMAX_H
0007 #define MINMAX_H
0008 
0009 #include <linux/types.h>
0010 
0011 /* A single data point for our parameterized min-max tracker */
0012 struct minmax_sample {
0013     u32 t;  /* time measurement was taken */
0014     u32 v;  /* value measured */
0015 };
0016 
0017 /* State for the parameterized min-max tracker */
0018 struct minmax {
0019     struct minmax_sample s[3];
0020 };
0021 
0022 static inline u32 minmax_get(const struct minmax *m)
0023 {
0024     return m->s[0].v;
0025 }
0026 
0027 static inline u32 minmax_reset(struct minmax *m, u32 t, u32 meas)
0028 {
0029     struct minmax_sample val = { .t = t, .v = meas };
0030 
0031     m->s[2] = m->s[1] = m->s[0] = val;
0032     return m->s[0].v;
0033 }
0034 
0035 u32 minmax_running_max(struct minmax *m, u32 win, u32 t, u32 meas);
0036 u32 minmax_running_min(struct minmax *m, u32 win, u32 t, u32 meas);
0037 
0038 #endif