blob: d78c65b78b4caec5cf8e090747cbd9ee34097dd4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
/* Public domain. */
#ifndef _LINUX_AVERAGE_H
#define _LINUX_AVERAGE_H
#include <sys/types.h>
#include <lib/libkern/libkern.h>
#define DECLARE_EWMA(name, precision, recip) \
struct ewma_##name { \
u_long value; \
}; \
\
static inline void \
ewma_##name##_init(struct ewma_##name *p) \
{ \
p->value = 0; \
} \
\
static inline void \
ewma_##name##_add(struct ewma_##name *p, u_long value) \
{ \
u_long shift = fls(recip) - 1; \
\
if (p->value == 0) \
p->value = (value << (precision)); \
else \
p->value = ((((p->value << shift) - p->value) + \
(value << (precision))) >> shift); \
} \
\
static inline u_long \
ewma_##name##_read(struct ewma_##name *p) \
{ \
return (p->value >> (precision)); \
}
#endif
|