From 564c5f598ef19738028f8098db5df74f7f017744 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Tue, 2 Apr 2013 00:31:05 +0200 Subject: [PATCH] properly backport EWMA functions Signed-off-by: Johannes Berg --- compat/compat/Kconfig | 7 +++++ compat/compat/Makefile | 2 +- compat/compat/{compat-2.6.38.c => average.c} | 2 +- compat/include/linux/average.h | 29 ++++++++++++++++++++ compat/include/linux/compat-2.6.38.h | 29 -------------------- 5 files changed, 38 insertions(+), 31 deletions(-) rename compat/compat/{compat-2.6.38.c => average.c} (98%) diff --git a/compat/compat/Kconfig b/compat/compat/Kconfig index 8d2b3f2071d2..958d8ac2f666 100644 --- a/compat/compat/Kconfig +++ b/compat/compat/Kconfig @@ -80,3 +80,10 @@ config BACKPORT_OPTION_BT_SOCK_CREATE_NEEDS_KERN bool # FIXME: REDHAT_6_0 also requires this default y if !BACKPORT_KERNEL_2_6_33 + +config BACKPORT_BUILD_AVERAGE + bool + default y if !AVERAGE && BACKPORT_AVERAGE + +config BACKPORT_AVERAGE + bool diff --git a/compat/compat/Makefile b/compat/compat/Makefile index 9b337fe0e803..20a94265304a 100644 --- a/compat/compat/Makefile +++ b/compat/compat/Makefile @@ -31,7 +31,7 @@ compat-$(CPTCFG_BACKPORT_KERNEL_2_6_34) += compat-2.6.34.o compat-$(CPTCFG_BACKPORT_KERNEL_2_6_35) += compat-2.6.35.o compat-$(CPTCFG_BACKPORT_KERNEL_2_6_36) += compat-2.6.36.o compat-$(CPTCFG_BACKPORT_KERNEL_2_6_37) += compat-2.6.37.o -compat-$(CPTCFG_BACKPORT_KERNEL_2_6_38) += compat-2.6.38.o +compat-$(CPTCFG_BACKPORT_BUILD_AVERAGE) += average.o compat-$(CPTCFG_BACKPORT_KERNEL_2_6_39) += compat-2.6.39.o kstrtox.o compat-$(CPTCFG_BACKPORT_KERNEL_3_0) += compat-3.0.o compat-$(CPTCFG_BACKPORT_KERNEL_3_1) += compat-3.1.o diff --git a/compat/compat/compat-2.6.38.c b/compat/compat/average.c similarity index 98% rename from compat/compat/compat-2.6.38.c rename to compat/compat/average.c index 0074ac625223..37cbfd6bdc7e 100644 --- a/compat/compat/compat-2.6.38.c +++ b/compat/compat/average.c @@ -8,7 +8,7 @@ * Compatibility file for Linux wireless for kernels 2.6.38. */ -#include +#include #include #include diff --git a/compat/include/linux/average.h b/compat/include/linux/average.h index ece86ca3a971..fb0f3975bcac 100644 --- a/compat/include/linux/average.h +++ b/compat/include/linux/average.h @@ -2,4 +2,33 @@ #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,37)) #include_next +#else +/* Exponentially weighted moving average (EWMA) */ + +/* For more documentation see lib/average.c */ + +struct ewma { + unsigned long internal; + unsigned long factor; + unsigned long weight; +}; + +#define ewma_init LINUX_BACKPORT(ewma_init) +extern void ewma_init(struct ewma *avg, unsigned long factor, + unsigned long weight); + +#define ewma_add LINUX_BACKPORT(ewma_add) +extern struct ewma *ewma_add(struct ewma *avg, unsigned long val); + +#define ewma_read LINUX_BACKPORT(ewma_read) +/** + * 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 DIV_ROUND_CLOSEST(avg->internal, avg->factor); +} #endif /* (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,37)) */ diff --git a/compat/include/linux/compat-2.6.38.h b/compat/include/linux/compat-2.6.38.h index 58ec64e5675b..4a823108c4d6 100644 --- a/compat/include/linux/compat-2.6.38.h +++ b/compat/include/linux/compat-2.6.38.h @@ -56,35 +56,6 @@ static inline void qdisc_bstats_update(struct Qdisc *sch, #define max_segs max_hw_segs -/* Exponentially weighted moving average (EWMA) */ - -/* For more documentation see lib/average.c */ - -struct ewma { - unsigned long internal; - unsigned long factor; - unsigned long weight; -}; - -#define ewma_init LINUX_BACKPORT(ewma_init) -extern void ewma_init(struct ewma *avg, unsigned long factor, - unsigned long weight); - -#define ewma_add LINUX_BACKPORT(ewma_add) -extern struct ewma *ewma_add(struct ewma *avg, unsigned long val); - -#define ewma_read LINUX_BACKPORT(ewma_read) -/** - * 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 DIV_ROUND_CLOSEST(avg->internal, avg->factor); -} - #define pr_warn pr_warning #define create_freezable_workqueue create_freezeable_workqueue -- 2.30.2