.. | .. |
---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
---|
1 | 2 | /* |
---|
2 | 3 | * 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. |
---|
7 | 4 | */ |
---|
8 | 5 | |
---|
9 | 6 | #ifndef __RC_MINSTREL_H |
---|
.. | .. |
---|
22 | 19 | #define MAX_THR_RATES 4 |
---|
23 | 20 | |
---|
24 | 21 | /* |
---|
| 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 | +/* |
---|
25 | 37 | * Perform EWMA (Exponentially Weighted Moving Average) calculation |
---|
26 | 38 | */ |
---|
27 | 39 | static inline int |
---|
.. | .. |
---|
35 | 47 | return old + incr; |
---|
36 | 48 | } |
---|
37 | 49 | |
---|
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) |
---|
43 | 51 | { |
---|
44 | | - int diff, incr; |
---|
| 52 | + s32 out_1 = *prev_1; |
---|
| 53 | + s32 out_2 = *prev_2; |
---|
| 54 | + s32 val; |
---|
45 | 55 | |
---|
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; |
---|
49 | 79 | } |
---|
50 | 80 | |
---|
51 | 81 | struct minstrel_rate_stats { |
---|
.. | .. |
---|
56 | 86 | /* total attempts/success counters */ |
---|
57 | 87 | u32 att_hist, succ_hist; |
---|
58 | 88 | |
---|
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; |
---|
64 | 92 | |
---|
65 | 93 | /* maximum retry counts */ |
---|
66 | 94 | u8 retry_count; |
---|
.. | .. |
---|
108 | 136 | |
---|
109 | 137 | /* sampling table */ |
---|
110 | 138 | u8 *sample_table; |
---|
111 | | - |
---|
112 | | -#ifdef CONFIG_MAC80211_DEBUGFS |
---|
113 | | - struct dentry *dbg_stats; |
---|
114 | | - struct dentry *dbg_stats_csv; |
---|
115 | | -#endif |
---|
116 | 139 | }; |
---|
117 | 140 | |
---|
118 | 141 | struct minstrel_priv { |
---|
119 | 142 | struct ieee80211_hw *hw; |
---|
120 | 143 | bool has_mrr; |
---|
| 144 | + bool new_avg; |
---|
| 145 | + u32 sample_switch; |
---|
121 | 146 | unsigned int cw_min; |
---|
122 | 147 | unsigned int cw_max; |
---|
123 | 148 | unsigned int max_retry; |
---|
.. | .. |
---|
136 | 161 | * - setting will be applied on next update |
---|
137 | 162 | */ |
---|
138 | 163 | u32 fixed_rate_idx; |
---|
139 | | - struct dentry *dbg_fixed_rate; |
---|
140 | 164 | #endif |
---|
141 | 165 | }; |
---|
142 | 166 | |
---|
.. | .. |
---|
145 | 169 | char buf[]; |
---|
146 | 170 | }; |
---|
147 | 171 | |
---|
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 | | - |
---|
156 | 172 | extern const struct rate_control_ops mac80211_minstrel; |
---|
157 | 173 | void minstrel_add_sta_debugfs(void *priv, void *priv_sta, struct dentry *dir); |
---|
158 | | -void minstrel_remove_sta_debugfs(void *priv, void *priv_sta); |
---|
159 | 174 | |
---|
160 | 175 | /* 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); |
---|
163 | 179 | |
---|
164 | 180 | /* debugfs */ |
---|
165 | 181 | int minstrel_stats_open(struct inode *inode, struct file *file); |
---|
166 | 182 | 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); |
---|
169 | 183 | |
---|
170 | 184 | #endif |
---|