mt76: update to the latest version
[oweals/openwrt.git] / package / kernel / mac80211 / patches / 372-mac80211-minstrel-reduce-minstrel_mcs_groups-size.patch
1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Sat, 10 Feb 2018 12:45:47 +0100
3 Subject: [PATCH] mac80211: minstrel: reduce minstrel_mcs_groups size
4
5 By storing a shift value for all duration values of a group, we can
6 reduce precision by a neglegible amount to make it fit into a u16 value.
7 This improves cache footprint and reduces size:
8
9 Before:
10    text    data     bss     dec     hex filename
11   10024     116       0   10140    279c rc80211_minstrel_ht.o
12
13 After:
14    text    data     bss     dec     hex filename
15    9368     116       0    9484    250c rc80211_minstrel_ht.o
16
17 Signed-off-by: Felix Fietkau <nbd@nbd.name>
18 ---
19
20 --- a/net/mac80211/rc80211_minstrel_ht.c
21 +++ b/net/mac80211/rc80211_minstrel_ht.c
22 @@ -52,22 +52,23 @@
23         _streams - 1
24  
25  /* MCS rate information for an MCS group */
26 -#define MCS_GROUP(_streams, _sgi, _ht40)                               \
27 +#define MCS_GROUP(_streams, _sgi, _ht40, _s)                           \
28         [GROUP_IDX(_streams, _sgi, _ht40)] = {                          \
29         .streams = _streams,                                            \
30 +       .shift = _s,                                                    \
31         .flags =                                                        \
32                 IEEE80211_TX_RC_MCS |                                   \
33                 (_sgi ? IEEE80211_TX_RC_SHORT_GI : 0) |                 \
34                 (_ht40 ? IEEE80211_TX_RC_40_MHZ_WIDTH : 0),             \
35         .duration = {                                                   \
36 -               MCS_DURATION(_streams, _sgi, _ht40 ? 54 : 26),          \
37 -               MCS_DURATION(_streams, _sgi, _ht40 ? 108 : 52),         \
38 -               MCS_DURATION(_streams, _sgi, _ht40 ? 162 : 78),         \
39 -               MCS_DURATION(_streams, _sgi, _ht40 ? 216 : 104),        \
40 -               MCS_DURATION(_streams, _sgi, _ht40 ? 324 : 156),        \
41 -               MCS_DURATION(_streams, _sgi, _ht40 ? 432 : 208),        \
42 -               MCS_DURATION(_streams, _sgi, _ht40 ? 486 : 234),        \
43 -               MCS_DURATION(_streams, _sgi, _ht40 ? 540 : 260)         \
44 +               MCS_DURATION(_streams, _sgi, _ht40 ? 54 : 26) >> _s,    \
45 +               MCS_DURATION(_streams, _sgi, _ht40 ? 108 : 52) >> _s,   \
46 +               MCS_DURATION(_streams, _sgi, _ht40 ? 162 : 78) >> _s,   \
47 +               MCS_DURATION(_streams, _sgi, _ht40 ? 216 : 104) >> _s,  \
48 +               MCS_DURATION(_streams, _sgi, _ht40 ? 324 : 156) >> _s,  \
49 +               MCS_DURATION(_streams, _sgi, _ht40 ? 432 : 208) >> _s,  \
50 +               MCS_DURATION(_streams, _sgi, _ht40 ? 486 : 234) >> _s,  \
51 +               MCS_DURATION(_streams, _sgi, _ht40 ? 540 : 260) >> _s   \
52         }                                                               \
53  }
54  
55 @@ -80,9 +81,10 @@
56  #define BW2VBPS(_bw, r3, r2, r1)                                       \
57         (_bw == BW_80 ? r3 : _bw == BW_40 ? r2 : r1)
58  
59 -#define VHT_GROUP(_streams, _sgi, _bw)                                 \
60 +#define VHT_GROUP(_streams, _sgi, _bw, _s)                             \
61         [VHT_GROUP_IDX(_streams, _sgi, _bw)] = {                        \
62         .streams = _streams,                                            \
63 +       .shift = _s,                                                    \
64         .flags =                                                        \
65                 IEEE80211_TX_RC_VHT_MCS |                               \
66                 (_sgi ? IEEE80211_TX_RC_SHORT_GI : 0) |                 \
67 @@ -90,25 +92,25 @@
68                  _bw == BW_40 ? IEEE80211_TX_RC_40_MHZ_WIDTH : 0),      \
69         .duration = {                                                   \
70                 MCS_DURATION(_streams, _sgi,                            \
71 -                            BW2VBPS(_bw,  117,  54,  26)),             \
72 +                            BW2VBPS(_bw,  117,  54,  26)) >> _s,       \
73                 MCS_DURATION(_streams, _sgi,                            \
74 -                            BW2VBPS(_bw,  234, 108,  52)),             \
75 +                            BW2VBPS(_bw,  234, 108,  52)) >> _s,       \
76                 MCS_DURATION(_streams, _sgi,                            \
77 -                            BW2VBPS(_bw,  351, 162,  78)),             \
78 +                            BW2VBPS(_bw,  351, 162,  78)) >> _s,       \
79                 MCS_DURATION(_streams, _sgi,                            \
80 -                            BW2VBPS(_bw,  468, 216, 104)),             \
81 +                            BW2VBPS(_bw,  468, 216, 104)) >> _s,       \
82                 MCS_DURATION(_streams, _sgi,                            \
83 -                            BW2VBPS(_bw,  702, 324, 156)),             \
84 +                            BW2VBPS(_bw,  702, 324, 156)) >> _s,       \
85                 MCS_DURATION(_streams, _sgi,                            \
86 -                            BW2VBPS(_bw,  936, 432, 208)),             \
87 +                            BW2VBPS(_bw,  936, 432, 208)) >> _s,       \
88                 MCS_DURATION(_streams, _sgi,                            \
89 -                            BW2VBPS(_bw, 1053, 486, 234)),             \
90 +                            BW2VBPS(_bw, 1053, 486, 234)) >> _s,       \
91                 MCS_DURATION(_streams, _sgi,                            \
92 -                            BW2VBPS(_bw, 1170, 540, 260)),             \
93 +                            BW2VBPS(_bw, 1170, 540, 260)) >> _s,       \
94                 MCS_DURATION(_streams, _sgi,                            \
95 -                            BW2VBPS(_bw, 1404, 648, 312)),             \
96 +                            BW2VBPS(_bw, 1404, 648, 312)) >> _s,       \
97                 MCS_DURATION(_streams, _sgi,                            \
98 -                            BW2VBPS(_bw, 1560, 720, 346))              \
99 +                            BW2VBPS(_bw, 1560, 720, 346)) >> _s        \
100         }                                                               \
101  }
102  
103 @@ -121,19 +123,20 @@
104         (CCK_DURATION((_bitrate > 10 ? 20 : 10), false, 60) +   \
105          CCK_DURATION(_bitrate, _short, AVG_PKT_SIZE))
106  
107 -#define CCK_DURATION_LIST(_short)                      \
108 -       CCK_ACK_DURATION(10, _short),                   \
109 -       CCK_ACK_DURATION(20, _short),                   \
110 -       CCK_ACK_DURATION(55, _short),                   \
111 -       CCK_ACK_DURATION(110, _short)
112 +#define CCK_DURATION_LIST(_short, _s)                  \
113 +       CCK_ACK_DURATION(10, _short) >> _s,             \
114 +       CCK_ACK_DURATION(20, _short) >> _s,             \
115 +       CCK_ACK_DURATION(55, _short) >> _s,             \
116 +       CCK_ACK_DURATION(110, _short) >> _s
117  
118 -#define CCK_GROUP                                      \
119 +#define CCK_GROUP(_s)                                  \
120         [MINSTREL_CCK_GROUP] = {                        \
121                 .streams = 0,                           \
122                 .flags = 0,                             \
123 +               .shift = _s,                            \
124                 .duration = {                           \
125 -                       CCK_DURATION_LIST(false),       \
126 -                       CCK_DURATION_LIST(true)         \
127 +                       CCK_DURATION_LIST(false, _s),   \
128 +                       CCK_DURATION_LIST(true, _s)     \
129                 }                                       \
130         }
131  
132 @@ -151,47 +154,47 @@ MODULE_PARM_DESC(minstrel_vht_only,
133   * BW -> SGI -> #streams
134   */
135  const struct mcs_group minstrel_mcs_groups[] = {
136 -       MCS_GROUP(1, 0, BW_20),
137 -       MCS_GROUP(2, 0, BW_20),
138 -       MCS_GROUP(3, 0, BW_20),
139 +       MCS_GROUP(1, 0, BW_20, 5),
140 +       MCS_GROUP(2, 0, BW_20, 4),
141 +       MCS_GROUP(3, 0, BW_20, 4),
142  
143 -       MCS_GROUP(1, 1, BW_20),
144 -       MCS_GROUP(2, 1, BW_20),
145 -       MCS_GROUP(3, 1, BW_20),
146 +       MCS_GROUP(1, 1, BW_20, 5),
147 +       MCS_GROUP(2, 1, BW_20, 4),
148 +       MCS_GROUP(3, 1, BW_20, 4),
149  
150 -       MCS_GROUP(1, 0, BW_40),
151 -       MCS_GROUP(2, 0, BW_40),
152 -       MCS_GROUP(3, 0, BW_40),
153 +       MCS_GROUP(1, 0, BW_40, 4),
154 +       MCS_GROUP(2, 0, BW_40, 4),
155 +       MCS_GROUP(3, 0, BW_40, 4),
156  
157 -       MCS_GROUP(1, 1, BW_40),
158 -       MCS_GROUP(2, 1, BW_40),
159 -       MCS_GROUP(3, 1, BW_40),
160 +       MCS_GROUP(1, 1, BW_40, 4),
161 +       MCS_GROUP(2, 1, BW_40, 4),
162 +       MCS_GROUP(3, 1, BW_40, 4),
163  
164 -       CCK_GROUP,
165 +       CCK_GROUP(8),
166  
167 -       VHT_GROUP(1, 0, BW_20),
168 -       VHT_GROUP(2, 0, BW_20),
169 -       VHT_GROUP(3, 0, BW_20),
170 +       VHT_GROUP(1, 0, BW_20, 5),
171 +       VHT_GROUP(2, 0, BW_20, 4),
172 +       VHT_GROUP(3, 0, BW_20, 4),
173  
174 -       VHT_GROUP(1, 1, BW_20),
175 -       VHT_GROUP(2, 1, BW_20),
176 -       VHT_GROUP(3, 1, BW_20),
177 +       VHT_GROUP(1, 1, BW_20, 5),
178 +       VHT_GROUP(2, 1, BW_20, 4),
179 +       VHT_GROUP(3, 1, BW_20, 4),
180  
181 -       VHT_GROUP(1, 0, BW_40),
182 -       VHT_GROUP(2, 0, BW_40),
183 -       VHT_GROUP(3, 0, BW_40),
184 +       VHT_GROUP(1, 0, BW_40, 4),
185 +       VHT_GROUP(2, 0, BW_40, 4),
186 +       VHT_GROUP(3, 0, BW_40, 4),
187  
188 -       VHT_GROUP(1, 1, BW_40),
189 -       VHT_GROUP(2, 1, BW_40),
190 -       VHT_GROUP(3, 1, BW_40),
191 +       VHT_GROUP(1, 1, BW_40, 4),
192 +       VHT_GROUP(2, 1, BW_40, 4),
193 +       VHT_GROUP(3, 1, BW_40, 4),
194  
195 -       VHT_GROUP(1, 0, BW_80),
196 -       VHT_GROUP(2, 0, BW_80),
197 -       VHT_GROUP(3, 0, BW_80),
198 +       VHT_GROUP(1, 0, BW_80, 4),
199 +       VHT_GROUP(2, 0, BW_80, 4),
200 +       VHT_GROUP(3, 0, BW_80, 4),
201  
202 -       VHT_GROUP(1, 1, BW_80),
203 -       VHT_GROUP(2, 1, BW_80),
204 -       VHT_GROUP(3, 1, BW_80),
205 +       VHT_GROUP(1, 1, BW_80, 4),
206 +       VHT_GROUP(2, 1, BW_80, 4),
207 +       VHT_GROUP(3, 1, BW_80, 4),
208  };
209  
210  static u8 sample_table[SAMPLE_COLUMNS][MCS_GROUP_RATES] __read_mostly;
211 @@ -307,7 +310,8 @@ minstrel_ht_get_tp_avg(struct minstrel_h
212         if (group != MINSTREL_CCK_GROUP)
213                 nsecs = 1000 * mi->overhead / MINSTREL_TRUNC(mi->avg_ampdu_len);
214  
215 -       nsecs += minstrel_mcs_groups[group].duration[rate];
216 +       nsecs += minstrel_mcs_groups[group].duration[rate] <<
217 +                minstrel_mcs_groups[group].shift;
218  
219         /*
220          * For the throughput calculation, limit the probability value to 90% to
221 @@ -755,12 +759,19 @@ minstrel_ht_tx_status(void *priv, struct
222                 minstrel_ht_update_rates(mp, mi);
223  }
224  
225 +static inline int
226 +minstrel_get_duration(int index)
227 +{
228 +       const struct mcs_group *group = &minstrel_mcs_groups[index / MCS_GROUP_RATES];
229 +       unsigned int duration = group->duration[index % MCS_GROUP_RATES];
230 +       return duration << group->shift;
231 +}
232 +
233  static void
234  minstrel_calc_retransmit(struct minstrel_priv *mp, struct minstrel_ht_sta *mi,
235                           int index)
236  {
237         struct minstrel_rate_stats *mrs;
238 -       const struct mcs_group *group;
239         unsigned int tx_time, tx_time_rtscts, tx_time_data;
240         unsigned int cw = mp->cw_min;
241         unsigned int ctime = 0;
242 @@ -779,8 +790,7 @@ minstrel_calc_retransmit(struct minstrel
243         mrs->retry_count_rtscts = 2;
244         mrs->retry_updated = true;
245  
246 -       group = &minstrel_mcs_groups[index / MCS_GROUP_RATES];
247 -       tx_time_data = group->duration[index % MCS_GROUP_RATES] * ampdu_len / 1000;
248 +       tx_time_data = minstrel_get_duration(index) * ampdu_len / 1000;
249  
250         /* Contention time for first 2 tries */
251         ctime = (t_slot * cw) >> 1;
252 @@ -874,20 +884,24 @@ minstrel_ht_get_max_amsdu_len(struct min
253         int group = mi->max_prob_rate / MCS_GROUP_RATES;
254         const struct mcs_group *g = &minstrel_mcs_groups[group];
255         int rate = mi->max_prob_rate % MCS_GROUP_RATES;
256 +       unsigned int duration;
257  
258         /* Disable A-MSDU if max_prob_rate is bad */
259         if (mi->groups[group].rates[rate].prob_ewma < MINSTREL_FRAC(50, 100))
260                 return 1;
261  
262 +       duration = g->duration[rate];
263 +       duration <<= g->shift;
264 +
265         /* If the rate is slower than single-stream MCS1, make A-MSDU limit small */
266 -       if (g->duration[rate] > MCS_DURATION(1, 0, 52))
267 +       if (duration > MCS_DURATION(1, 0, 52))
268                 return 500;
269  
270         /*
271          * If the rate is slower than single-stream MCS4, limit A-MSDU to usual
272          * data packet size
273          */
274 -       if (g->duration[rate] > MCS_DURATION(1, 0, 104))
275 +       if (duration > MCS_DURATION(1, 0, 104))
276                 return 1600;
277  
278         /*
279 @@ -895,7 +909,7 @@ minstrel_ht_get_max_amsdu_len(struct min
280          * rate success probability is less than 75%, limit A-MSDU to twice the usual
281          * data packet size
282          */
283 -       if (g->duration[rate] > MCS_DURATION(1, 0, 260) ||
284 +       if (duration > MCS_DURATION(1, 0, 260) ||
285             (minstrel_ht_get_prob_ewma(mi, mi->max_tp_rate[0]) <
286              MINSTREL_FRAC(75, 100)))
287                 return 3200;
288 @@ -942,13 +956,6 @@ minstrel_ht_update_rates(struct minstrel
289         rate_control_set_rates(mp->hw, mi->sta, rates);
290  }
291  
292 -static inline int
293 -minstrel_get_duration(int index)
294 -{
295 -       const struct mcs_group *group = &minstrel_mcs_groups[index / MCS_GROUP_RATES];
296 -       return group->duration[index % MCS_GROUP_RATES];
297 -}
298 -
299  static int
300  minstrel_get_sample_rate(struct minstrel_priv *mp, struct minstrel_ht_sta *mi)
301  {
302 --- a/net/mac80211/rc80211_minstrel_ht.h
303 +++ b/net/mac80211/rc80211_minstrel_ht.h
304 @@ -33,9 +33,10 @@
305  #define MCS_GROUP_RATES                10
306  
307  struct mcs_group {
308 -       u32 flags;
309 -       unsigned int streams;
310 -       unsigned int duration[MCS_GROUP_RATES];
311 +       u16 flags;
312 +       u8 streams;
313 +       u8 shift;
314 +       u16 duration[MCS_GROUP_RATES];
315  };
316  
317  extern const struct mcs_group minstrel_mcs_groups[];
318 --- a/net/mac80211/rc80211_minstrel_ht_debugfs.c
319 +++ b/net/mac80211/rc80211_minstrel_ht_debugfs.c
320 @@ -58,6 +58,7 @@ minstrel_ht_stats_dump(struct minstrel_h
321                 static const int bitrates[4] = { 10, 20, 55, 110 };
322                 int idx = i * MCS_GROUP_RATES + j;
323                 unsigned int prob_ewmsd;
324 +               unsigned int duration;
325  
326                 if (!(mi->supported[i] & BIT(j)))
327                         continue;
328 @@ -95,7 +96,9 @@ minstrel_ht_stats_dump(struct minstrel_h
329                 p += sprintf(p, "  %3u  ", idx);
330  
331                 /* tx_time[rate(i)] in usec */
332 -               tx_time = DIV_ROUND_CLOSEST(mg->duration[j], 1000);
333 +               duration = mg->duration[j];
334 +               duration <<= mg->shift;
335 +               tx_time = DIV_ROUND_CLOSEST(duration, 1000);
336                 p += sprintf(p, "%6u  ", tx_time);
337  
338                 tp_max = minstrel_ht_get_tp_avg(mi, i, j, MINSTREL_FRAC(100, 100));
339 @@ -204,6 +207,7 @@ minstrel_ht_stats_csv_dump(struct minstr
340                 static const int bitrates[4] = { 10, 20, 55, 110 };
341                 int idx = i * MCS_GROUP_RATES + j;
342                 unsigned int prob_ewmsd;
343 +               unsigned int duration;
344  
345                 if (!(mi->supported[i] & BIT(j)))
346                         continue;
347 @@ -238,7 +242,10 @@ minstrel_ht_stats_csv_dump(struct minstr
348                 }
349  
350                 p += sprintf(p, "%u,", idx);
351 -               tx_time = DIV_ROUND_CLOSEST(mg->duration[j], 1000);
352 +
353 +               duration = mg->duration[j];
354 +               duration <<= mg->shift;
355 +               tx_time = DIV_ROUND_CLOSEST(duration, 1000);
356                 p += sprintf(p, "%u,", tx_time);
357  
358                 tp_max = minstrel_ht_get_tp_avg(mi, i, j, MINSTREL_FRAC(100, 100));