hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/net/mac80211/rc80211_minstrel.h
....@@ -1,9 +1,6 @@
1
+/* SPDX-License-Identifier: GPL-2.0-only */
12 /*
23 * Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
3
- *
4
- * This program is free software; you can redistribute it and/or modify
5
- * it under the terms of the GNU General Public License version 2 as
6
- * published by the Free Software Foundation.
74 */
85
96 #ifndef __RC_MINSTREL_H
....@@ -22,6 +19,21 @@
2219 #define MAX_THR_RATES 4
2320
2421 /*
22
+ * Coefficients for moving average with noise filter (period=16),
23
+ * scaled by 10 bits
24
+ *
25
+ * a1 = exp(-pi * sqrt(2) / period)
26
+ * coeff2 = 2 * a1 * cos(sqrt(2) * 2 * pi / period)
27
+ * coeff3 = -sqr(a1)
28
+ * coeff1 = 1 - coeff2 - coeff3
29
+ */
30
+#define MINSTREL_AVG_COEFF1 (MINSTREL_FRAC(1, 1) - \
31
+ MINSTREL_AVG_COEFF2 - \
32
+ MINSTREL_AVG_COEFF3)
33
+#define MINSTREL_AVG_COEFF2 0x00001499
34
+#define MINSTREL_AVG_COEFF3 -0x0000092e
35
+
36
+/*
2537 * Perform EWMA (Exponentially Weighted Moving Average) calculation
2638 */
2739 static inline int
....@@ -35,17 +47,35 @@
3547 return old + incr;
3648 }
3749
38
-/*
39
- * Perform EWMV (Exponentially Weighted Moving Variance) calculation
40
- */
41
-static inline int
42
-minstrel_ewmv(int old_ewmv, int cur_prob, int prob_ewma, int weight)
50
+static inline int minstrel_filter_avg_add(u16 *prev_1, u16 *prev_2, s32 in)
4351 {
44
- int diff, incr;
52
+ s32 out_1 = *prev_1;
53
+ s32 out_2 = *prev_2;
54
+ s32 val;
4555
46
- diff = cur_prob - prob_ewma;
47
- incr = (EWMA_DIV - weight) * diff / EWMA_DIV;
48
- return weight * (old_ewmv + MINSTREL_TRUNC(diff * incr)) / EWMA_DIV;
56
+ if (!in)
57
+ in += 1;
58
+
59
+ if (!out_1) {
60
+ val = out_1 = in;
61
+ goto out;
62
+ }
63
+
64
+ val = MINSTREL_AVG_COEFF1 * in;
65
+ val += MINSTREL_AVG_COEFF2 * out_1;
66
+ val += MINSTREL_AVG_COEFF3 * out_2;
67
+ val >>= MINSTREL_SCALE;
68
+
69
+ if (val > 1 << MINSTREL_SCALE)
70
+ val = 1 << MINSTREL_SCALE;
71
+ if (val < 0)
72
+ val = 1;
73
+
74
+out:
75
+ *prev_2 = out_1;
76
+ *prev_1 = val;
77
+
78
+ return val;
4979 }
5080
5181 struct minstrel_rate_stats {
....@@ -56,11 +86,9 @@
5686 /* total attempts/success counters */
5787 u32 att_hist, succ_hist;
5888
59
- /* statistis of packet delivery probability
60
- * prob_ewma - exponential weighted moving average of prob
61
- * prob_ewmsd - exp. weighted moving standard deviation of prob */
62
- u16 prob_ewma;
63
- u16 prob_ewmv;
89
+ /* prob_avg - moving average of prob */
90
+ u16 prob_avg;
91
+ u16 prob_avg_1;
6492
6593 /* maximum retry counts */
6694 u8 retry_count;
....@@ -108,16 +136,13 @@
108136
109137 /* sampling table */
110138 u8 *sample_table;
111
-
112
-#ifdef CONFIG_MAC80211_DEBUGFS
113
- struct dentry *dbg_stats;
114
- struct dentry *dbg_stats_csv;
115
-#endif
116139 };
117140
118141 struct minstrel_priv {
119142 struct ieee80211_hw *hw;
120143 bool has_mrr;
144
+ bool new_avg;
145
+ u32 sample_switch;
121146 unsigned int cw_min;
122147 unsigned int cw_max;
123148 unsigned int max_retry;
....@@ -136,7 +161,6 @@
136161 * - setting will be applied on next update
137162 */
138163 u32 fixed_rate_idx;
139
- struct dentry *dbg_fixed_rate;
140164 #endif
141165 };
142166
....@@ -145,26 +169,16 @@
145169 char buf[];
146170 };
147171
148
-/* Get EWMSD (Exponentially Weighted Moving Standard Deviation) * 10 */
149
-static inline int
150
-minstrel_get_ewmsd10(struct minstrel_rate_stats *mrs)
151
-{
152
- unsigned int ewmv = mrs->prob_ewmv;
153
- return int_sqrt(MINSTREL_TRUNC(ewmv * 1000 * 1000));
154
-}
155
-
156172 extern const struct rate_control_ops mac80211_minstrel;
157173 void minstrel_add_sta_debugfs(void *priv, void *priv_sta, struct dentry *dir);
158
-void minstrel_remove_sta_debugfs(void *priv, void *priv_sta);
159174
160175 /* Recalculate success probabilities and counters for a given rate using EWMA */
161
-void minstrel_calc_rate_stats(struct minstrel_rate_stats *mrs);
162
-int minstrel_get_tp_avg(struct minstrel_rate *mr, int prob_ewma);
176
+void minstrel_calc_rate_stats(struct minstrel_priv *mp,
177
+ struct minstrel_rate_stats *mrs);
178
+int minstrel_get_tp_avg(struct minstrel_rate *mr, int prob_avg);
163179
164180 /* debugfs */
165181 int minstrel_stats_open(struct inode *inode, struct file *file);
166182 int minstrel_stats_csv_open(struct inode *inode, struct file *file);
167
-ssize_t minstrel_stats_read(struct file *file, char __user *buf, size_t len, loff_t *ppos);
168
-int minstrel_stats_release(struct inode *inode, struct file *file);
169183
170184 #endif