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
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:
10 text data bss dec hex filename
11 10024 116 0 10140 279c rc80211_minstrel_ht.o
14 text data bss dec hex filename
15 9368 116 0 9484 250c rc80211_minstrel_ht.o
17 Signed-off-by: Felix Fietkau <nbd@nbd.name>
20 --- a/net/mac80211/rc80211_minstrel_ht.c
21 +++ b/net/mac80211/rc80211_minstrel_ht.c
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, \
32 IEEE80211_TX_RC_MCS | \
33 (_sgi ? IEEE80211_TX_RC_SHORT_GI : 0) | \
34 (_ht40 ? IEEE80211_TX_RC_40_MHZ_WIDTH : 0), \
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 \
56 #define BW2VBPS(_bw, r3, r2, r1) \
57 (_bw == BW_80 ? r3 : _bw == BW_40 ? r2 : r1)
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, \
65 IEEE80211_TX_RC_VHT_MCS | \
66 (_sgi ? IEEE80211_TX_RC_SHORT_GI : 0) | \
68 _bw == BW_40 ? IEEE80211_TX_RC_40_MHZ_WIDTH : 0), \
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 \
103 @@ -121,19 +123,20 @@
104 (CCK_DURATION((_bitrate > 10 ? 20 : 10), false, 60) + \
105 CCK_DURATION(_bitrate, _short, AVG_PKT_SIZE))
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
119 +#define CCK_GROUP(_s) \
120 [MINSTREL_CCK_GROUP] = { \
125 - CCK_DURATION_LIST(false), \
126 - CCK_DURATION_LIST(true) \
127 + CCK_DURATION_LIST(false, _s), \
128 + CCK_DURATION_LIST(true, _s) \
132 @@ -151,47 +154,47 @@ MODULE_PARM_DESC(minstrel_vht_only,
133 * BW -> SGI -> #streams
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),
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),
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),
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),
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),
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),
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),
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),
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),
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),
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);
215 - nsecs += minstrel_mcs_groups[group].duration[rate];
216 + nsecs += minstrel_mcs_groups[group].duration[rate] <<
217 + minstrel_mcs_groups[group].shift;
220 * For the throughput calculation, limit the probability value to 90% to
221 @@ -780,7 +784,7 @@ minstrel_calc_retransmit(struct minstrel
222 mrs->retry_updated = true;
224 group = &minstrel_mcs_groups[index / MCS_GROUP_RATES];
225 - tx_time_data = group->duration[index % MCS_GROUP_RATES] * ampdu_len / 1000;
226 + tx_time_data = (group->duration[index % MCS_GROUP_RATES] << group->shift) * ampdu_len / 1000;
228 /* Contention time for first 2 tries */
229 ctime = (t_slot * cw) >> 1;
230 @@ -880,14 +884,14 @@ minstrel_ht_get_max_amsdu_len(struct min
233 /* If the rate is slower than single-stream MCS1, make A-MSDU limit small */
234 - if (g->duration[rate] > MCS_DURATION(1, 0, 52))
235 + if ((g->duration[rate] << g->shift) > MCS_DURATION(1, 0, 52))
239 * If the rate is slower than single-stream MCS4, limit A-MSDU to usual
242 - if (g->duration[rate] > MCS_DURATION(1, 0, 104))
243 + if ((g->duration[rate] << g->shift) > MCS_DURATION(1, 0, 104))
247 @@ -895,7 +899,7 @@ minstrel_ht_get_max_amsdu_len(struct min
248 * rate success probability is less than 75%, limit A-MSDU to twice the usual
251 - if (g->duration[rate] > MCS_DURATION(1, 0, 260) ||
252 + if ((g->duration[rate] << g->shift) > MCS_DURATION(1, 0, 260) ||
253 (minstrel_ht_get_prob_ewma(mi, mi->max_tp_rate[0]) <
254 MINSTREL_FRAC(75, 100)))
256 @@ -946,7 +950,7 @@ static inline int
257 minstrel_get_duration(int index)
259 const struct mcs_group *group = &minstrel_mcs_groups[index / MCS_GROUP_RATES];
260 - return group->duration[index % MCS_GROUP_RATES];
261 + return group->duration[index % MCS_GROUP_RATES] << group->shift;
265 --- a/net/mac80211/rc80211_minstrel_ht.h
266 +++ b/net/mac80211/rc80211_minstrel_ht.h
268 #define MCS_GROUP_RATES 10
272 - unsigned int streams;
273 - unsigned int duration[MCS_GROUP_RATES];
277 + u16 duration[MCS_GROUP_RATES];
280 extern const struct mcs_group minstrel_mcs_groups[];
281 --- a/net/mac80211/rc80211_minstrel_ht_debugfs.c
282 +++ b/net/mac80211/rc80211_minstrel_ht_debugfs.c
283 @@ -95,7 +95,7 @@ minstrel_ht_stats_dump(struct minstrel_h
284 p += sprintf(p, " %3u ", idx);
286 /* tx_time[rate(i)] in usec */
287 - tx_time = DIV_ROUND_CLOSEST(mg->duration[j], 1000);
288 + tx_time = DIV_ROUND_CLOSEST(mg->duration[j] << mg->shift, 1000);
289 p += sprintf(p, "%6u ", tx_time);
291 tp_max = minstrel_ht_get_tp_avg(mi, i, j, MINSTREL_FRAC(100, 100));
292 @@ -238,7 +238,7 @@ minstrel_ht_stats_csv_dump(struct minstr
295 p += sprintf(p, "%u,", idx);
296 - tx_time = DIV_ROUND_CLOSEST(mg->duration[j], 1000);
297 + tx_time = DIV_ROUND_CLOSEST(mg->duration[j] << mg->shift, 1000);
298 p += sprintf(p, "%u,", tx_time);
300 tp_max = minstrel_ht_get_tp_avg(mi, i, j, MINSTREL_FRAC(100, 100));