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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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. + MCS_GROUP(1, 0, BW_20, 5),
  128. + MCS_GROUP(2, 0, BW_20, 4),
  129. + MCS_GROUP(3, 0, BW_20, 4),
  130. - MCS_GROUP(1, 1, BW_20),
  131. - MCS_GROUP(2, 1, BW_20),
  132. - MCS_GROUP(3, 1, BW_20),
  133. + MCS_GROUP(1, 1, BW_20, 5),
  134. + MCS_GROUP(2, 1, BW_20, 4),
  135. + MCS_GROUP(3, 1, BW_20, 4),
  136. - MCS_GROUP(1, 0, BW_40),
  137. - MCS_GROUP(2, 0, BW_40),
  138. - MCS_GROUP(3, 0, BW_40),
  139. + MCS_GROUP(1, 0, BW_40, 4),
  140. + MCS_GROUP(2, 0, BW_40, 4),
  141. + MCS_GROUP(3, 0, BW_40, 4),
  142. - MCS_GROUP(1, 1, BW_40),
  143. - MCS_GROUP(2, 1, BW_40),
  144. - MCS_GROUP(3, 1, BW_40),
  145. + MCS_GROUP(1, 1, BW_40, 4),
  146. + MCS_GROUP(2, 1, BW_40, 4),
  147. + MCS_GROUP(3, 1, BW_40, 4),
  148. - CCK_GROUP,
  149. + CCK_GROUP(8),
  150. - VHT_GROUP(1, 0, BW_20),
  151. - VHT_GROUP(2, 0, BW_20),
  152. - VHT_GROUP(3, 0, BW_20),
  153. + VHT_GROUP(1, 0, BW_20, 5),
  154. + VHT_GROUP(2, 0, BW_20, 4),
  155. + VHT_GROUP(3, 0, BW_20, 4),
  156. - VHT_GROUP(1, 1, BW_20),
  157. - VHT_GROUP(2, 1, BW_20),
  158. - VHT_GROUP(3, 1, BW_20),
  159. + VHT_GROUP(1, 1, BW_20, 5),
  160. + VHT_GROUP(2, 1, BW_20, 4),
  161. + VHT_GROUP(3, 1, BW_20, 4),
  162. - VHT_GROUP(1, 0, BW_40),
  163. - VHT_GROUP(2, 0, BW_40),
  164. - VHT_GROUP(3, 0, BW_40),
  165. + VHT_GROUP(1, 0, BW_40, 4),
  166. + VHT_GROUP(2, 0, BW_40, 4),
  167. + VHT_GROUP(3, 0, BW_40, 4),
  168. - VHT_GROUP(1, 1, BW_40),
  169. - VHT_GROUP(2, 1, BW_40),
  170. - VHT_GROUP(3, 1, BW_40),
  171. + VHT_GROUP(1, 1, BW_40, 4),
  172. + VHT_GROUP(2, 1, BW_40, 4),
  173. + VHT_GROUP(3, 1, BW_40, 4),
  174. - VHT_GROUP(1, 0, BW_80),
  175. - VHT_GROUP(2, 0, BW_80),
  176. - VHT_GROUP(3, 0, BW_80),
  177. + VHT_GROUP(1, 0, BW_80, 4),
  178. + VHT_GROUP(2, 0, BW_80, 4),
  179. + VHT_GROUP(3, 0, BW_80, 4),
  180. - VHT_GROUP(1, 1, BW_80),
  181. - VHT_GROUP(2, 1, BW_80),
  182. - VHT_GROUP(3, 1, BW_80),
  183. + VHT_GROUP(1, 1, BW_80, 4),
  184. + VHT_GROUP(2, 1, BW_80, 4),
  185. + VHT_GROUP(3, 1, BW_80, 4),
  186. };
  187. static u8 sample_table[SAMPLE_COLUMNS][MCS_GROUP_RATES] __read_mostly;
  188. @@ -307,7 +310,8 @@ minstrel_ht_get_tp_avg(struct minstrel_h
  189. if (group != MINSTREL_CCK_GROUP)
  190. nsecs = 1000 * mi->overhead / MINSTREL_TRUNC(mi->avg_ampdu_len);
  191. - nsecs += minstrel_mcs_groups[group].duration[rate];
  192. + nsecs += minstrel_mcs_groups[group].duration[rate] <<
  193. + minstrel_mcs_groups[group].shift;
  194. /*
  195. * For the throughput calculation, limit the probability value to 90% to
  196. @@ -755,12 +759,19 @@ minstrel_ht_tx_status(void *priv, struct
  197. minstrel_ht_update_rates(mp, mi);
  198. }
  199. +static inline int
  200. +minstrel_get_duration(int index)
  201. +{
  202. + const struct mcs_group *group = &minstrel_mcs_groups[index / MCS_GROUP_RATES];
  203. + unsigned int duration = group->duration[index % MCS_GROUP_RATES];
  204. + return duration << group->shift;
  205. +}
  206. +
  207. static void
  208. minstrel_calc_retransmit(struct minstrel_priv *mp, struct minstrel_ht_sta *mi,
  209. int index)
  210. {
  211. struct minstrel_rate_stats *mrs;
  212. - const struct mcs_group *group;
  213. unsigned int tx_time, tx_time_rtscts, tx_time_data;
  214. unsigned int cw = mp->cw_min;
  215. unsigned int ctime = 0;
  216. @@ -779,8 +790,7 @@ minstrel_calc_retransmit(struct minstrel
  217. mrs->retry_count_rtscts = 2;
  218. mrs->retry_updated = true;
  219. - group = &minstrel_mcs_groups[index / MCS_GROUP_RATES];
  220. - tx_time_data = group->duration[index % MCS_GROUP_RATES] * ampdu_len / 1000;
  221. + tx_time_data = minstrel_get_duration(index) * ampdu_len / 1000;
  222. /* Contention time for first 2 tries */
  223. ctime = (t_slot * cw) >> 1;
  224. @@ -874,20 +884,24 @@ minstrel_ht_get_max_amsdu_len(struct min
  225. int group = mi->max_prob_rate / MCS_GROUP_RATES;
  226. const struct mcs_group *g = &minstrel_mcs_groups[group];
  227. int rate = mi->max_prob_rate % MCS_GROUP_RATES;
  228. + unsigned int duration;
  229. /* Disable A-MSDU if max_prob_rate is bad */
  230. if (mi->groups[group].rates[rate].prob_ewma < MINSTREL_FRAC(50, 100))
  231. return 1;
  232. + duration = g->duration[rate];
  233. + duration <<= g->shift;
  234. +
  235. /* If the rate is slower than single-stream MCS1, make A-MSDU limit small */
  236. - if (g->duration[rate] > MCS_DURATION(1, 0, 52))
  237. + if (duration > MCS_DURATION(1, 0, 52))
  238. return 500;
  239. /*
  240. * If the rate is slower than single-stream MCS4, limit A-MSDU to usual
  241. * data packet size
  242. */
  243. - if (g->duration[rate] > MCS_DURATION(1, 0, 104))
  244. + if (duration > MCS_DURATION(1, 0, 104))
  245. return 1600;
  246. /*
  247. @@ -895,7 +909,7 @@ minstrel_ht_get_max_amsdu_len(struct min
  248. * rate success probability is less than 75%, limit A-MSDU to twice the usual
  249. * data packet size
  250. */
  251. - if (g->duration[rate] > MCS_DURATION(1, 0, 260) ||
  252. + if (duration > MCS_DURATION(1, 0, 260) ||
  253. (minstrel_ht_get_prob_ewma(mi, mi->max_tp_rate[0]) <
  254. MINSTREL_FRAC(75, 100)))
  255. return 3200;
  256. @@ -942,13 +956,6 @@ minstrel_ht_update_rates(struct minstrel
  257. rate_control_set_rates(mp->hw, mi->sta, rates);
  258. }
  259. -static inline int
  260. -minstrel_get_duration(int index)
  261. -{
  262. - const struct mcs_group *group = &minstrel_mcs_groups[index / MCS_GROUP_RATES];
  263. - return group->duration[index % MCS_GROUP_RATES];
  264. -}
  265. -
  266. static int
  267. minstrel_get_sample_rate(struct minstrel_priv *mp, struct minstrel_ht_sta *mi)
  268. {
  269. --- a/net/mac80211/rc80211_minstrel_ht.h
  270. +++ b/net/mac80211/rc80211_minstrel_ht.h
  271. @@ -33,9 +33,10 @@
  272. #define MCS_GROUP_RATES 10
  273. struct mcs_group {
  274. - u32 flags;
  275. - unsigned int streams;
  276. - unsigned int duration[MCS_GROUP_RATES];
  277. + u16 flags;
  278. + u8 streams;
  279. + u8 shift;
  280. + u16 duration[MCS_GROUP_RATES];
  281. };
  282. extern const struct mcs_group minstrel_mcs_groups[];
  283. --- a/net/mac80211/rc80211_minstrel_ht_debugfs.c
  284. +++ b/net/mac80211/rc80211_minstrel_ht_debugfs.c
  285. @@ -58,6 +58,7 @@ minstrel_ht_stats_dump(struct minstrel_h
  286. static const int bitrates[4] = { 10, 20, 55, 110 };
  287. int idx = i * MCS_GROUP_RATES + j;
  288. unsigned int prob_ewmsd;
  289. + unsigned int duration;
  290. if (!(mi->supported[i] & BIT(j)))
  291. continue;
  292. @@ -95,7 +96,9 @@ minstrel_ht_stats_dump(struct minstrel_h
  293. p += sprintf(p, " %3u ", idx);
  294. /* tx_time[rate(i)] in usec */
  295. - tx_time = DIV_ROUND_CLOSEST(mg->duration[j], 1000);
  296. + duration = mg->duration[j];
  297. + duration <<= mg->shift;
  298. + tx_time = DIV_ROUND_CLOSEST(duration, 1000);
  299. p += sprintf(p, "%6u ", tx_time);
  300. tp_max = minstrel_ht_get_tp_avg(mi, i, j, MINSTREL_FRAC(100, 100));
  301. @@ -204,6 +207,7 @@ minstrel_ht_stats_csv_dump(struct minstr
  302. static const int bitrates[4] = { 10, 20, 55, 110 };
  303. int idx = i * MCS_GROUP_RATES + j;
  304. unsigned int prob_ewmsd;
  305. + unsigned int duration;
  306. if (!(mi->supported[i] & BIT(j)))
  307. continue;
  308. @@ -238,7 +242,10 @@ minstrel_ht_stats_csv_dump(struct minstr
  309. }
  310. p += sprintf(p, "%u,", idx);
  311. - tx_time = DIV_ROUND_CLOSEST(mg->duration[j], 1000);
  312. +
  313. + duration = mg->duration[j];
  314. + duration <<= mg->shift;
  315. + tx_time = DIV_ROUND_CLOSEST(duration, 1000);
  316. p += sprintf(p, "%u,", tx_time);
  317. tp_max = minstrel_ht_get_tp_avg(mi, i, j, MINSTREL_FRAC(100, 100));