diff options
author | Johannes Berg <johannes.berg@intel.com> | 2017-02-15 03:49:26 -0500 |
---|---|---|
committer | Johannes Berg <johannes.berg@intel.com> | 2017-03-02 02:32:46 -0500 |
commit | eb1e011a14748a1d9df9a7d7df9a5711721a1bdb (patch) | |
tree | 599710c96a23bcbc25423cb0a99696dd0b257c7b | |
parent | 48cac18ecf1de82f76259a54402c3adb7839ad01 (diff) |
average: change to declare precision, not factor
Declaring the factor is counter-intuitive, and people are prone
to using small(-ish) values even when that makes no sense.
Change the DECLARE_EWMA() macro to take the fractional precision,
in bits, rather than a factor, and update all users.
While at it, add some more documentation.
Acked-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
-rw-r--r-- | drivers/net/virtio_net.c | 2 | ||||
-rw-r--r-- | drivers/net/wireless/ath/ath5k/ath5k.h | 2 | ||||
-rw-r--r-- | drivers/net/wireless/ralink/rt2x00/rt2x00.h | 2 | ||||
-rw-r--r-- | include/linux/average.h | 61 | ||||
-rw-r--r-- | net/batman-adv/types.h | 2 | ||||
-rw-r--r-- | net/mac80211/ieee80211_i.h | 2 | ||||
-rw-r--r-- | net/mac80211/sta_info.h | 2 |
7 files changed, 47 insertions, 26 deletions
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index bf95016f442a..e9d7e2b70085 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c | |||
@@ -51,7 +51,7 @@ module_param(gso, bool, 0444); | |||
51 | * at once, the weight is chosen so that the EWMA will be insensitive to short- | 51 | * at once, the weight is chosen so that the EWMA will be insensitive to short- |
52 | * term, transient changes in packet size. | 52 | * term, transient changes in packet size. |
53 | */ | 53 | */ |
54 | DECLARE_EWMA(pkt_len, 1, 64) | 54 | DECLARE_EWMA(pkt_len, 0, 64) |
55 | 55 | ||
56 | /* With mergeable buffers we align buffer address and use the low bits to | 56 | /* With mergeable buffers we align buffer address and use the low bits to |
57 | * encode its true size. Buffer size is up to 1 page so we need to align to | 57 | * encode its true size. Buffer size is up to 1 page so we need to align to |
diff --git a/drivers/net/wireless/ath/ath5k/ath5k.h b/drivers/net/wireless/ath/ath5k/ath5k.h index 67fedb61fcc0..979800c6f57f 100644 --- a/drivers/net/wireless/ath/ath5k/ath5k.h +++ b/drivers/net/wireless/ath/ath5k/ath5k.h | |||
@@ -1252,7 +1252,7 @@ struct ath5k_statistics { | |||
1252 | #define ATH5K_TXQ_LEN_MAX (ATH_TXBUF / 4) /* bufs per queue */ | 1252 | #define ATH5K_TXQ_LEN_MAX (ATH_TXBUF / 4) /* bufs per queue */ |
1253 | #define ATH5K_TXQ_LEN_LOW (ATH5K_TXQ_LEN_MAX / 2) /* low mark */ | 1253 | #define ATH5K_TXQ_LEN_LOW (ATH5K_TXQ_LEN_MAX / 2) /* low mark */ |
1254 | 1254 | ||
1255 | DECLARE_EWMA(beacon_rssi, 1024, 8) | 1255 | DECLARE_EWMA(beacon_rssi, 10, 8) |
1256 | 1256 | ||
1257 | /* Driver state associated with an instance of a device */ | 1257 | /* Driver state associated with an instance of a device */ |
1258 | struct ath5k_hw { | 1258 | struct ath5k_hw { |
diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00.h b/drivers/net/wireless/ralink/rt2x00/rt2x00.h index 26869b3bef45..340787894c69 100644 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00.h +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00.h | |||
@@ -257,7 +257,7 @@ struct link_qual { | |||
257 | int tx_failed; | 257 | int tx_failed; |
258 | }; | 258 | }; |
259 | 259 | ||
260 | DECLARE_EWMA(rssi, 1024, 8) | 260 | DECLARE_EWMA(rssi, 10, 8) |
261 | 261 | ||
262 | /* | 262 | /* |
263 | * Antenna settings about the currently active link. | 263 | * Antenna settings about the currently active link. |
diff --git a/include/linux/average.h b/include/linux/average.h index d04aa58280de..7ddaf340d2ac 100644 --- a/include/linux/average.h +++ b/include/linux/average.h | |||
@@ -1,45 +1,66 @@ | |||
1 | #ifndef _LINUX_AVERAGE_H | 1 | #ifndef _LINUX_AVERAGE_H |
2 | #define _LINUX_AVERAGE_H | 2 | #define _LINUX_AVERAGE_H |
3 | 3 | ||
4 | /* Exponentially weighted moving average (EWMA) */ | 4 | /* |
5 | * Exponentially weighted moving average (EWMA) | ||
6 | * | ||
7 | * This implements a fixed-precision EWMA algorithm, with both the | ||
8 | * precision and fall-off coefficient determined at compile-time | ||
9 | * and built into the generated helper funtions. | ||
10 | * | ||
11 | * The first argument to the macro is the name that will be used | ||
12 | * for the struct and helper functions. | ||
13 | * | ||
14 | * The second argument, the precision, expresses how many bits are | ||
15 | * used for the fractional part of the fixed-precision values. | ||
16 | * | ||
17 | * The third argument, the weight reciprocal, determines how the | ||
18 | * new values will be weighed vs. the old state, new values will | ||
19 | * get weight 1/weight_rcp and old values 1-1/weight_rcp. Note | ||
20 | * that this parameter must be a power of two for efficiency. | ||
21 | */ | ||
5 | 22 | ||
6 | #define DECLARE_EWMA(name, _factor, _weight) \ | 23 | #define DECLARE_EWMA(name, _precision, _weight_rcp) \ |
7 | struct ewma_##name { \ | 24 | struct ewma_##name { \ |
8 | unsigned long internal; \ | 25 | unsigned long internal; \ |
9 | }; \ | 26 | }; \ |
10 | static inline void ewma_##name##_init(struct ewma_##name *e) \ | 27 | static inline void ewma_##name##_init(struct ewma_##name *e) \ |
11 | { \ | 28 | { \ |
12 | BUILD_BUG_ON(!__builtin_constant_p(_factor)); \ | 29 | BUILD_BUG_ON(!__builtin_constant_p(_precision)); \ |
13 | BUILD_BUG_ON(!__builtin_constant_p(_weight)); \ | 30 | BUILD_BUG_ON(!__builtin_constant_p(_weight_rcp)); \ |
14 | BUILD_BUG_ON_NOT_POWER_OF_2(_factor); \ | 31 | /* \ |
15 | BUILD_BUG_ON_NOT_POWER_OF_2(_weight); \ | 32 | * Even if you want to feed it just 0/1 you should have \ |
33 | * some bits for the non-fractional part... \ | ||
34 | */ \ | ||
35 | BUILD_BUG_ON((_precision) > 30); \ | ||
36 | BUILD_BUG_ON_NOT_POWER_OF_2(_weight_rcp); \ | ||
16 | e->internal = 0; \ | 37 | e->internal = 0; \ |
17 | } \ | 38 | } \ |
18 | static inline unsigned long \ | 39 | static inline unsigned long \ |
19 | ewma_##name##_read(struct ewma_##name *e) \ | 40 | ewma_##name##_read(struct ewma_##name *e) \ |
20 | { \ | 41 | { \ |
21 | BUILD_BUG_ON(!__builtin_constant_p(_factor)); \ | 42 | BUILD_BUG_ON(!__builtin_constant_p(_precision)); \ |
22 | BUILD_BUG_ON(!__builtin_constant_p(_weight)); \ | 43 | BUILD_BUG_ON(!__builtin_constant_p(_weight_rcp)); \ |
23 | BUILD_BUG_ON_NOT_POWER_OF_2(_factor); \ | 44 | BUILD_BUG_ON((_precision) > 30); \ |
24 | BUILD_BUG_ON_NOT_POWER_OF_2(_weight); \ | 45 | BUILD_BUG_ON_NOT_POWER_OF_2(_weight_rcp); \ |
25 | return e->internal >> ilog2(_factor); \ | 46 | return e->internal >> (_precision); \ |
26 | } \ | 47 | } \ |
27 | static inline void ewma_##name##_add(struct ewma_##name *e, \ | 48 | static inline void ewma_##name##_add(struct ewma_##name *e, \ |
28 | unsigned long val) \ | 49 | unsigned long val) \ |
29 | { \ | 50 | { \ |
30 | unsigned long internal = ACCESS_ONCE(e->internal); \ | 51 | unsigned long internal = ACCESS_ONCE(e->internal); \ |
31 | unsigned long weight = ilog2(_weight); \ | 52 | unsigned long weight_rcp = ilog2(_weight_rcp); \ |
32 | unsigned long factor = ilog2(_factor); \ | 53 | unsigned long precision = _precision; \ |
33 | \ | 54 | \ |
34 | BUILD_BUG_ON(!__builtin_constant_p(_factor)); \ | 55 | BUILD_BUG_ON(!__builtin_constant_p(_precision)); \ |
35 | BUILD_BUG_ON(!__builtin_constant_p(_weight)); \ | 56 | BUILD_BUG_ON(!__builtin_constant_p(_weight_rcp)); \ |
36 | BUILD_BUG_ON_NOT_POWER_OF_2(_factor); \ | 57 | BUILD_BUG_ON((_precision) > 30); \ |
37 | BUILD_BUG_ON_NOT_POWER_OF_2(_weight); \ | 58 | BUILD_BUG_ON_NOT_POWER_OF_2(_weight_rcp); \ |
38 | \ | 59 | \ |
39 | ACCESS_ONCE(e->internal) = internal ? \ | 60 | ACCESS_ONCE(e->internal) = internal ? \ |
40 | (((internal << weight) - internal) + \ | 61 | (((internal << weight_rcp) - internal) + \ |
41 | (val << factor)) >> weight : \ | 62 | (val << precision)) >> weight_rcp : \ |
42 | (val << factor); \ | 63 | (val << precision); \ |
43 | } | 64 | } |
44 | 65 | ||
45 | #endif /* _LINUX_AVERAGE_H */ | 66 | #endif /* _LINUX_AVERAGE_H */ |
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h index 8f64a5c01345..66b25e410a41 100644 --- a/net/batman-adv/types.h +++ b/net/batman-adv/types.h | |||
@@ -402,7 +402,7 @@ struct batadv_gw_node { | |||
402 | struct rcu_head rcu; | 402 | struct rcu_head rcu; |
403 | }; | 403 | }; |
404 | 404 | ||
405 | DECLARE_EWMA(throughput, 1024, 8) | 405 | DECLARE_EWMA(throughput, 10, 8) |
406 | 406 | ||
407 | /** | 407 | /** |
408 | * struct batadv_hardif_neigh_node_bat_v - B.A.T.M.A.N. V private neighbor | 408 | * struct batadv_hardif_neigh_node_bat_v - B.A.T.M.A.N. V private neighbor |
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h index 159a1a733725..0e718437d080 100644 --- a/net/mac80211/ieee80211_i.h +++ b/net/mac80211/ieee80211_i.h | |||
@@ -428,7 +428,7 @@ struct ieee80211_sta_tx_tspec { | |||
428 | bool downgraded; | 428 | bool downgraded; |
429 | }; | 429 | }; |
430 | 430 | ||
431 | DECLARE_EWMA(beacon_signal, 16, 4) | 431 | DECLARE_EWMA(beacon_signal, 4, 4) |
432 | 432 | ||
433 | struct ieee80211_if_managed { | 433 | struct ieee80211_if_managed { |
434 | struct timer_list timer; | 434 | struct timer_list timer; |
diff --git a/net/mac80211/sta_info.h b/net/mac80211/sta_info.h index 15599c70a38f..e65cda34d2bc 100644 --- a/net/mac80211/sta_info.h +++ b/net/mac80211/sta_info.h | |||
@@ -372,7 +372,7 @@ struct mesh_sta { | |||
372 | unsigned int fail_avg; | 372 | unsigned int fail_avg; |
373 | }; | 373 | }; |
374 | 374 | ||
375 | DECLARE_EWMA(signal, 1024, 8) | 375 | DECLARE_EWMA(signal, 10, 8) |
376 | 376 | ||
377 | struct ieee80211_sta_rx_stats { | 377 | struct ieee80211_sta_rx_stats { |
378 | unsigned long packets; | 378 | unsigned long packets; |