aboutsummaryrefslogtreecommitdiffstats
path: root/net/mac80211/rc80211_pid.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/mac80211/rc80211_pid.c')
-rw-r--r--net/mac80211/rc80211_pid.c35
1 files changed, 27 insertions, 8 deletions
diff --git a/net/mac80211/rc80211_pid.c b/net/mac80211/rc80211_pid.c
index 1116dc67ddd0..7f8cf27ad2f9 100644
--- a/net/mac80211/rc80211_pid.c
+++ b/net/mac80211/rc80211_pid.c
@@ -23,13 +23,16 @@
23 * 23 *
24 * The controller basically computes the following: 24 * The controller basically computes the following:
25 * 25 *
26 * adj = CP * err + CI * err_avg + CD * (err - last_err) 26 * adj = CP * err + CI * err_avg + CD * (err - last_err) * (1 + sharpening)
27 * 27 *
28 * where 28 * where
29 * adj adjustment value that is used to switch TX rate (see below) 29 * adj adjustment value that is used to switch TX rate (see below)
30 * err current error: target vs. current failed frames percentage 30 * err current error: target vs. current failed frames percentage
31 * last_err last error 31 * last_err last error
32 * err_avg average (i.e. poor man's integral) of recent errors 32 * err_avg average (i.e. poor man's integral) of recent errors
33 * sharpening non-zero when fast response is needed (i.e. right after
34 * association or no frames sent for a long time), heading
35 * to zero over time
33 * CP Proportional coefficient 36 * CP Proportional coefficient
34 * CI Integral coefficient 37 * CI Integral coefficient
35 * CD Derivative coefficient 38 * CD Derivative coefficient
@@ -65,6 +68,10 @@
65#define RC_PID_SMOOTHING_SHIFT 3 68#define RC_PID_SMOOTHING_SHIFT 3
66#define RC_PID_SMOOTHING (1 << RC_PID_SMOOTHING_SHIFT) 69#define RC_PID_SMOOTHING (1 << RC_PID_SMOOTHING_SHIFT)
67 70
71/* Sharpening factor (used for D part of PID controller) */
72#define RC_PID_SHARPENING_FACTOR 0
73#define RC_PID_SHARPENING_DURATION 0
74
68/* Fixed point arithmetic shifting amount. */ 75/* Fixed point arithmetic shifting amount. */
69#define RC_PID_ARITH_SHIFT 8 76#define RC_PID_ARITH_SHIFT 8
70 77
@@ -131,8 +138,11 @@ struct rc_pid_sta_info {
131 */ 138 */
132 s32 err_avg_sc; 139 s32 err_avg_sc;
133 140
134 /* Last framed failes percentage sample */ 141 /* Last framed failes percentage sample. */
135 u32 last_pf; 142 u32 last_pf;
143
144 /* Sharpening needed. */
145 u8 sharp_cnt;
136}; 146};
137 147
138/* Algorithm parameters. We keep them on a per-algorithm approach, so they can 148/* Algorithm parameters. We keep them on a per-algorithm approach, so they can
@@ -267,20 +277,26 @@ static void rate_control_pid_sample(struct rc_pid_info *pinfo,
267 277
268 mode = local->oper_hw_mode; 278 mode = local->oper_hw_mode;
269 spinfo = sta->rate_ctrl_priv; 279 spinfo = sta->rate_ctrl_priv;
280
281 /* In case nothing happened during the previous control interval, turn
282 * the sharpening factor on. */
283 if (jiffies - spinfo->last_sample > 2 * RC_PID_INTERVAL)
284 spinfo->sharp_cnt = RC_PID_SHARPENING_DURATION;
285
270 spinfo->last_sample = jiffies; 286 spinfo->last_sample = jiffies;
271 287
272 /* If no frames were transmitted, we assume the old sample is 288 /* This should never happen, but in case, we assume the old sample is
273 * still a good measurement and copy it. */ 289 * still a good measurement and copy it. */
274 if (spinfo->tx_num_xmit == 0) 290 if (unlikely(spinfo->tx_num_xmit == 0))
275 pf = spinfo->last_pf; 291 pf = spinfo->last_pf;
276 else { 292 else {
277 pf = spinfo->tx_num_failed * 100 / spinfo->tx_num_xmit; 293 pf = spinfo->tx_num_failed * 100 / spinfo->tx_num_xmit;
278 pf <<= RC_PID_ARITH_SHIFT; 294 pf <<= RC_PID_ARITH_SHIFT;
279
280 spinfo->tx_num_xmit = 0;
281 spinfo->tx_num_failed = 0;
282 } 295 }
283 296
297 spinfo->tx_num_xmit = 0;
298 spinfo->tx_num_failed = 0;
299
284 /* If we just switched rate, update the rate behaviour info. */ 300 /* If we just switched rate, update the rate behaviour info. */
285 if (pinfo->oldrate != sta->txrate) { 301 if (pinfo->oldrate != sta->txrate) {
286 302
@@ -302,8 +318,11 @@ static void rate_control_pid_sample(struct rc_pid_info *pinfo,
302 spinfo->err_avg_sc = spinfo->err_avg_sc - err_avg + err_prop; 318 spinfo->err_avg_sc = spinfo->err_avg_sc - err_avg + err_prop;
303 err_int = spinfo->err_avg_sc >> RC_PID_SMOOTHING_SHIFT; 319 err_int = spinfo->err_avg_sc >> RC_PID_SMOOTHING_SHIFT;
304 320
305 err_der = pf - spinfo->last_pf; 321 err_der = pf - spinfo->last_pf
322 * (1 + RC_PID_SHARPENING_FACTOR * spinfo->sharp_cnt);
306 spinfo->last_pf = pf; 323 spinfo->last_pf = pf;
324 if (spinfo->sharp_cnt)
325 spinfo->sharp_cnt--;
307 326
308 /* Compute the controller output. */ 327 /* Compute the controller output. */
309 adj = (err_prop * pinfo->coeff_p + err_int * pinfo->coeff_i 328 adj = (err_prop * pinfo->coeff_p + err_int * pinfo->coeff_i