update madwifi
[linux-2.6/zen-sources.git] / drivers / net / wireless / madwifi / ath_rate / minstrel / minstrel.txt
blob1156a89fa043b3a715a97f82d93f73493ebb8c36
1 minstrel
3 Introduction
4 ==============================================================================
6 This code is called minstrel, because we have taken a wandering minstrel
7 approach. Wander around the different rates, singing wherever you can. And
8 then, look at the performance, and make a choice. Note that the wandering
9 minstrel will always wander in directions where he/she feels he/she will get
10 paid the best for his/her work.
12 The minstrel autorate selection algorithm is an EWMA based algorithm and is
13 derived from
15  1) An initial rate module we released in 2005,
16   http://sourceforge.net/mailarchive/forum.php?forum_id=33966&max_rows=25&style=flat&viewmonth=200501&viewday=5
18  2) the "sample" module in the madwifi-ng source tree.
20 The code released in 2005 had some algorithmic and implementation flaws (one
21 of which was that it was based on the old madwifi codebase) and was shown to
22 be unstable. Performance of the sample module is poor
23 (http://www.madwifi.org/ticket/989), and we have observed similar issues.
25 We noted:
27  1) The rate chosen by sample did not alter to match changes in the radio
28     environment.
30  2) Higher throughput (between two nodes) could often be achieved by fixing
31     the bitrate of both nodes to some value.
33  3) After a long period of operation, "sample" appeared to be stuck in a low
34     data rate, and would not move to a higher data rate.
36 We examined the code in sample, and decided the best approach was a rewrite
37 based on sample and the module we released in January 2005.
39 Theory of operation
40 ==============================================================================
42 We defined the measure of successfulness (of packet transmission) as
44                                   Mega bits transmitted
45     Prob_success_transmission *  -----------------------
46                                       elapsed time
48 This measure of successfulness will therefore adjust the transmission speed to
49 get the maximum number of data bits through the radio interface. Further, it
50 means that the 1 Mbps rate (which has a very high probability of successful
51 transmission) will not be used in preference to the 11 Mbps rate.
53 We decided that the module should record the successfulness of all packets
54 that are transmitted. From this data, the module has sufficient information to
55 decide which packets are more successful than others. However, a variability
56 element was required. We had to force the module to examine bit rates other
57 than optimal. Consequently, some percent of the packets have to be sent at
58 rates regarded as non optimal.
60 10 times a second (this frequency is alterable by changing the driver code) a
61 timer fires, which evaluates the statistics table. EWMA calculations
62 (described below) are used to process the success history of each rate. On
63 completion of the calculation, a decision is made as to the rate which has the
64 best throughput, second best throughput, and highest probability of success.
65 This data is used for populating the retry chain during the next 100 ms.
67 As stated above, the minstrel algorithm collects statistics from all packet
68 attempts. Minstrel spends a particular percentage of frames, doing "look
69 around" i.e. randomly trying other rates, to gather statistics. The percentage
70 of "look around" frames, is set at boot time via the module parameter
71 "ath_lookaround_rate" and defaults to 10%. The distribution of lookaround
72 frames is also randomised somewhat to avoid any potential "strobing" of
73 lookaround between similar nodes.
75 TCP theory tells us that each packet sent must be delivered in under 26
76 ms. Any longer duration, and the TCP network layers will start to back off. A
77 delay of 26 ms implies that there is congestion in the network, and that fewer
78 packets should be injected to the device. Our conclusion was to adjust the
79 retry chain of each packet so the retry chain was guaranteed to be finished in
80 under 26 ms.
82 Retry Chain
83 ==============================================================================
85 The HAL provides a multirate retry chain - which consists of four
86 segments. Each segment is an advisement to the HAL to try to send the current
87 packet at some rate, with a fixed number of retry attempts. Once the packet is
88 successfully transmitted, the remainder of the retry chain is
89 ignored. Selection of the number of retry attempts was based on the desire to
90 get the packet out in under 26 ms, or fail. We provided a module parameter,
91 ath_segment_size, which has units of microseconds, and specifies the maximum
92 duration one segment in the retry chain can last. This module parameter has a
93 default of 6000. Our view is that a segment size of between 4000 and 6000
94 seems to fit most situations.
96 There is some room for movement here - if the traffic is UDP then the limit of
97 26 ms for the retry chain length is "meaningless". However, one may argue that
98 if the packet was not transmitted after some time period, it should
99 fail. Further, one does expect UDP packets to fail in transmission. We leave
100 it as an area for future improvement.
103 The (re)try segment chain is calculated in two possible manners. If this
104 packet is a normal tranmission packet (90% of packets are this) then the retry
105 count is best throughput, next best throughput, best probability, lowest
106 baserate. If it is a sample packet (10% of packets are this), then the retry
107 chain is random lookaround, best throughput, best probability, lowest base
108 rate. In tabular format:
110         Try | Lookaround rate    | Normal rate         
111         ------------------------------------------------
112          1  | Random lookaround  | Best throughput     
113          2  | Best throughput    | Next best throughput
114          3  | Best probability   | Best probability    
115          4  | Lowest Baserate    | Lowest Baserate     
117 The retry count is adjusted so that the transmission time for that section of
118 the retry chain is less than 26 ms.
120 After some discussion, we have adjusted the code so that the lowest rate is
121 never used for the lookaround packet. Our view is that since this rate is used
122 for management packets, this rate must be working. Alternatively, the link is
123 set up with management packets, data packets are acknowledged with management
124 packets. Should the lowest rate stop working, the link is going to die
125 reasonably soon.
127 Analysis of information in the /proc/net/madwifi/athX/rate_info file showed
128 that the system was sampling too hard at some rates. For those rates that
129 never work (54mb, 500m range) there is no point in sending 10 sample packets
130 (< 6 ms time). Consequently, for the very very low probability rates, we
131 sample at most twice.
133 The retry chain above does "work", but performance is suboptimal. The key
134 problem being that when the link is good, too much time is spent sampling the
135 slower rates. Thus, for two nodes adjacent to each other, the throughput
136 between them was several Mbps below using a fixed rate. The view was that
137 minstrel should not sample at the slower rates if the link is doing
138 well. However, if the link deteriorates, minstrel should immediately sample at
139 the lower rates.
141 Some time later, we realised that the only way to code this reliably was to
142 use the retry chain as the method of determining if the slower rates are
143 sampled. The retry chain was modified as:
145 Try |         Lookaround rate              | Normal rate         
146     | random < best    | random > best     |
147 --------------------------------------------------------------
148  1  | Best throughput  | Random rate       | Best throughput     
149  2  | Random rate      | Best throughput   | Next best throughput
150  3  | Best probability | Best probability  | Best probability    
151  4  | Lowest Baserate  | Lowest baserate   | Lowest baserate     
153 With this retry chain, if the randomly selected rate is slower than the
154 current best throughput, the randomly selected rate is placed second in the
155 chain. If the link is not good, then there will be data collected at the
156 randomly selected rate.  Thus, if the best throughput rate is currently 54
157 Mbps, the only time slower rates are sampled is when a packet fails in
158 transmission. Consequently, if the link is ideal, all packets will be sent at
159 the full rate of 54 Mbps. Which is good.
161 EWMA
162 ==============================================================================
164 The EWMA calculation is carried out 10 times a second, and is run for each
165 rate. This calculation has a smoothing effect, so that new results have a
166 reasonable (but not large) influence on the selected rate. However, with time,
167 a series of new results in some particular direction will predominate. Given
168 this smoothing, we can use words like inertia to describe the EWMA.
170 By "new results", we mean the results collected in the just completed 100 ms
171 interval. Old results are the EWMA scaling values from before the just
172 completed 100 ms interval.
174 EWMA scaling is set by the module parameter ath_ewma_level, and defaults to
175 75%. A value of 0% means use only the new results, ignore the old results.  A
176 value of 99% means use the old results, with a tiny influence from the new
177 results.
179 The calculation (performed for each rate, at each timer interrupt) of the
180 probability of success is:
182          Psucces_this_time_interval * (100 - ath_ewma_level) + (Pold * ath_ewma_level)
183 Pnew =  ------------------------------------------------------------------------------
184                   100
186                             number_packets_sent_successfully_this_rate_time_interval
187 Psuccess_this_time_interval=--------------------------------------------------------
188                              number_packets_sent_this_rate_time_interval
191 If no packets have been sent for a particular rate in a time interval, no
192 calculation is carried out. The Psuccess value for this rate is not changed.
194 If the new time interval is the first time interval (the module has just been
195 inserted), then Pnew is calculated from above with Pold set to 0.
197 The appropriate update interval was selected on the basis of choosing a
198 compromise between
200  * collecting enough success/failure information to be meaningful
201  * minimising the amount of cpu time spent do the updates
202  * providing a means to recover quickly enough from a bad rate selection.
204 The first two points are self explanatory. When there is a sudden change in
205 the radio environment, an update interval of 100 ms will mean that the rates
206 marked as optimal are very quickly marked as poor. Consequently, the sudden
207 change in radio environment will mean that minstrel will very quickly switch
208 to a better rate.
210 A sudden change in the transmission probabilities will happen when the
211 node has not transmitted any data for a while, and during that time
212 the environment has changed. On starting to transmit, the probability
213 of success at each rate will be quite different. The driver must adapt
214 as quickly as possible, so as to not upset the higher TCP network
215 layers.
217 Module Parameters
218 ==============================================================================
219 The module has three parameters:
221 name              default value    purpose
222 ath_ewma_level      75%            rate of response to new data. A value of 100 is VERY responsive.
223 ath_lookaround_rate 10%            percent of packets sent at non optimal speed.
224 ath_segment_size   6000            maximum duration of a retry segment (microseconds)
230 Test Network
231 ==============================================================================
233 We used three computers in our test network. The first two, equipped with
234 atheros cards running in adhoc mode. We used a program that sends a fixed
235 number of TCP packets between computers, and reports on the data rate. The
236 application reports on the data rate - at an application layer level, which is
237 considerably lower than the level used in transmitting the packets.
239 The third computer had an atheros card also, but was running network monitor
240 mode with ethereal. The monitor computer was used to see what data rates were
241 used on the air. This computer was a form of "logging of the connection"
242 without introducing any additional load on the first two computers.
244 It was from monitoring the results on the third computer that we started to
245 get some confidence in the correctness of the code. We observed TCP backoffs
246 (described above) on this box. There was much celebration when the throughput
247 increased simply because the retry chain was finished in under 26 ms.
249 Our view was that throughput between the two computers should be as close as
250 possible (or better than) what can be achieved by setting both ends to fixed
251 rates. Thus, if setting the both ends to fixed rates significantly increases
252 the throughput, a reasonable conclusion is that a fault exists in the adaptive
253 rate rate.
255 We recorded throughputs (with minstrel) that are within 10% of what is
256 achieved with the experimentally determined optimum fixed rate.
259 Notes on Timing
260 ==============================================================================
262 As noted above, minstrel calculates the throughput for each rate. This
263 calculation (using a packet of size 1200 bytes) determines the transmission
264 time on the radio medium. In these calculations, we assume a contention window
265 min and max value of 4 and 10 microseconds respectively.
267 Further, calculation of the transmission time is required so that we can
268 guarantee a packet is transmitted (or dropped) in a minimum time period.  The
269 transmission time is used in determining how many times a packet is
270 transmitted in each segment of the retry chain.
272 Indeed, the card will supply the cwmin/cwmax values directly
273  iwpriv if_name get_cwmin <0|1|2|3> <0|1>
275 We have not made direct calls to determine cwmin/cwmax - this is an area for
276 future work. Indeed, the cwmin/cwmax determination code could check to see if
277 the user has altered these values with the appropriate iwpriv.
279 The contention window size does vary with traffic class. For example, video
280 and voice have a contention window min of 3 and 2 microseconds
281 respectively. Currently, minstrel does not check traffic class.
283 Calculating the throughputs based on traffic class and bit rate and variable
284 packet size will significantly complicate the code and require many more
285 sample packets. More sample packets will lower the throughput achieved. Thus,
286 our view is that for this release, we should take a simple (but reasonable)
287 approach that works stably and gives good throughputs.
290 Values of cwin/cwmax of 4 and 10 microseconds are from 
291 IEEE Part 11: Wireless LAN Medium Access Control (MAC) and Physical Layer
292 (PHY) specifications, Amendment : Medium Access Control (MAC) Enhancements for
293 Quality of Service (QoS) P802.11e/D12.0, November 2004.
296 Internal variable reporting
297 ==============================================================================
299 The minstrel algorithm reports to the proc file system its internal
300 statistics, which can be viewed as text. A sample output is below:
302 cat /proc/net/madwifi/ath0/rate_info
305 rate data for node:: 00:02:6f:43:8c:7a
306 rate     throughput  ewma prob   this prob  this succ/attempt   success    attempts
307      1         0.0        0.0        0.0          0(  0)          0           0
308      2         1.6       92.4      100.0          0(  0)         11          11
309      5.5       3.9       89.9      100.0          0(  0)         11          11
310     11         6.5       86.6      100.0          0(  0)         10          11
311      6         4.8       92.4      100.0          0(  0)         11          11
312      9         6.9       92.4      100.0          0(  0)         11          11
313     12         9.0       92.4      100.0          0(  0)         11          11
314     18        12.1       89.9      100.0          0(  0)         11          11
315     24        15.5       92.4      100.0          0(  0)         11          11
316     36        20.6       92.4      100.0          0(  0)         11          11
317  t  48        23.6       89.9      100.0          0(  0)         12          12
318 T P 54        27.1       96.2       96.2          0(  0)        996        1029
321 Total packet count::    ideal 2344      lookaround 261
323 There is a separate table for each node in the neighbor table, which will
324 appear similar to above.
326 The possible datarates for this node are listed in the column at the left. The
327 calculated throughput and "ewma prob" are listed next, from which the rates
328 used in retry chain are selected. The rates with the maximum throughput,
329 second maximum throughput and maximum probability are indicated by the letters
330 T, t, and P respectively.
332 The statistics gathered in the last 100 ms time period are displayed in the
333 "this prob" and "this succ/attempt" columns.
335 Finally, the number of packets transmitted at each rate, since module loading
336 are listed in the last two columns. When interpreting the last four columns,
337 note that we use the words "succ" or "success" to mean packets successfully
338 sent from this node to the remote node. The driver determines success by
339 analysing reports from the hal. The word "attempt" or "attempts" means the
340 count of packets that we transmitted. Thus, the number in the success column
341 will always be lower than the number in the attempts column.
343 When the two nodes are brought closer together, the statistics starts
344 changing, and you see more successful attempts at the higher rates. The ewma
345 prob at the higher rates increases and then most packets are conveyed at the
346 higher rates.
348 When the rate is not on auto, but fixed, this table is still available, and
349 will report the throughput etc for the current bit rate. Changing the rate
350 from auto to fixed to auto will completely reset this table, and the operation
351 of the minstrel module.