Skip to contentSkip to conversation

backports: remove AVERAGE, backport DECLARE_EWMA

PATCH In review Johannes Berg 2 participants 2 messages Aug 24, 2015 – Sep 14, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 backports: remove AVERAGE, backport DECLARE_EWMA

From: Johannes Berg <[email protected]>

My patches to remove the out-of-line EWMA implemenation (under Kconfig symbol AVERAGE) went into net-next, so now we only need to backport DECLARE_EWMA as the only necessary macro.

---
 backport/backport-include/linux/average.h | 46 +++++++++++++++++++++++++++++++
 backport/compat/Kconfig                   | 11 --------
 2 files changed, 46 insertions(+), 11 deletions(-)
 create mode 100644 backport/backport-include/linux/average.h
backport/backport-include/linux/average.h new file +46 -0
new file mode 100644
index 000000000000..5d80041fe5e8
@@ -0,0 +1,46 @@
+#ifndef __BACKPORT_AVERAGE
+#define __BACKPORT_AVERAGE
+#include_next <linux/average.h>
+
+#ifndef DECLARE_EWMA
+#define DECLARE_EWMA(name, _factor, _weight)				\
+	struct ewma_##name {						\
+		unsigned long internal;					\
+	};								\
+	static inline void ewma_##name##_init(struct ewma_##name *e)	\
+	{								\
+		BUILD_BUG_ON(!__builtin_constant_p(_factor));		\
+		BUILD_BUG_ON(!__builtin_constant_p(_weight));		\
+		BUILD_BUG_ON_NOT_POWER_OF_2(_factor);			\
+		BUILD_BUG_ON_NOT_POWER_OF_2(_weight);			\
+		e->internal = 0;					\
+	}								\
+	static inline unsigned long					\
+	ewma_##name##_read(struct ewma_##name *e)			\
+	{								\
+		BUILD_BUG_ON(!__builtin_constant_p(_factor));		\
+		BUILD_BUG_ON(!__builtin_constant_p(_weight));		\
+		BUILD_BUG_ON_NOT_POWER_OF_2(_factor);			\
+		BUILD_BUG_ON_NOT_POWER_OF_2(_weight);			\
+		return e->internal >> ilog2(_factor);			\
+	}								\
+	static inline void ewma_##name##_add(struct ewma_##name *e,	\
+					     unsigned long val)		\
+	{								\
+		unsigned long internal = ACCESS_ONCE(e->internal);	\
+		unsigned long weight = ilog2(_weight);			\
+		unsigned long factor = ilog2(_factor);			\
+									\
+		BUILD_BUG_ON(!__builtin_constant_p(_factor));		\
+		BUILD_BUG_ON(!__builtin_constant_p(_weight));		\
+		BUILD_BUG_ON_NOT_POWER_OF_2(_factor);			\
+		BUILD_BUG_ON_NOT_POWER_OF_2(_weight);			\
+									\
+		ACCESS_ONCE(e->internal) = internal ?			\
+			(((internal << weight) - internal) +		\
+				(val << factor)) >> weight :		\
+			(val << factor);				\
+	}
+#endif /* DECLARE_EWMA */
+
+#endif /* __BACKPORT_AVERAGE */
backport/compat/Kconfig +0 -11
index ed600a3e53bb..7c88729c3ec2 100644
@@ -73,17 +73,6 @@ config BPAUTO_BUILD_CORDIC
 config BPAUTO_CORDIC
 	bool
 
-config BPAUTO_BUILD_AVERAGE
-	bool
-	depends on !AVERAGE
-	default y if BPAUTO_USERSEL_BUILD_ALL
-	default y if BPAUTO_AVERAGE
-	#h-file linux/average.h
-	#c-file lib/average.c
-
-config BPAUTO_AVERAGE
-	bool
-
 config BPAUTO_MII
 	bool
 
Signature · 4 lines
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe backports" in
#1 lore raw
Quoted 6 lines · Johannes Berg

From: Johannes Berg <[email protected]>

My patches to remove the out-of-line EWMA implemenation (under Kconfig symbol AVERAGE) went into net-next, so now we only need to backport DECLARE_EWMA as the only necessary macro.

Quoted 7 lines
---
 backport/backport-include/linux/average.h | 46 +++++++++++++++++++++++++++++++
 backport/compat/Kconfig                   | 11 --------
 2 files changed, 46 insertions(+), 11 deletions(-)
 create mode 100644 backport/backport-include/linux/average.h

Thank you for the patch, it was applied and pushed out.

Hauke

--
To unsubscribe from this list: send the line "unsubscribe backports" in