]> git.karo-electronics.de Git - mv-sheeva.git/blobdiff - include/linux/average.h
Merge branch 'master' into tk71
[mv-sheeva.git] / include / linux / average.h
diff --git a/include/linux/average.h b/include/linux/average.h
new file mode 100644 (file)
index 0000000..c6028fd
--- /dev/null
@@ -0,0 +1,30 @@
+#ifndef _LINUX_AVERAGE_H
+#define _LINUX_AVERAGE_H
+
+/* Exponentially weighted moving average (EWMA) */
+
+/* For more documentation see lib/average.c */
+
+struct ewma {
+       unsigned long internal;
+       unsigned long factor;
+       unsigned long weight;
+};
+
+extern void ewma_init(struct ewma *avg, unsigned long factor,
+                     unsigned long weight);
+
+extern struct ewma *ewma_add(struct ewma *avg, unsigned long val);
+
+/**
+ * ewma_read() - Get average value
+ * @avg: Average structure
+ *
+ * Returns the average value held in @avg.
+ */
+static inline unsigned long ewma_read(const struct ewma *avg)
+{
+       return avg->internal >> avg->factor;
+}
+
+#endif /* _LINUX_AVERAGE_H */