306-mac80211-minstrel-reduce-minstrel_mcs_groups-size.patch 11 KB

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