mac80211: fix sign error in pid controller
authorBob Copeland <me@bobcopeland.com>
Sat, 16 Jan 2010 19:36:52 +0000 (14:36 -0500)
committerJohn W. Linville <linville@tuxdriver.com>
Mon, 18 Jan 2010 20:07:02 +0000 (15:07 -0500)
While testing the pid rate controller in mac80211_hwsim, I noticed
that once the controller reached 54 Mbit rates, it would fail to
lower the rate when necessary.  The debug log shows:

1945 186786 pf_sample 50 3534 3577 50

My interpretation is that the fixed point scaling of the target
error value (pf) is incorrect: the error value of 50 compared to
a target of 14 case should result in a scaling value of
(14-50) = -36 * 256 or -9216, but instead it is (14 * 256)-50, or
3534.

Correct this by doing fixed point scaling after subtraction.

Signed-off-by: Bob Copeland <me@bobcopeland.com>
Acked-by: Stefano Brivio <stefano.brivio@polimi.it>
Acked-by: Mattias Nissler <mattias.nissler@gmx.de>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
net/mac80211/rc80211_pid_algo.c

index 699d3ed869c4114a95f7a29f8adbea036d2c61a3..29bc4c516238ed9cfafbd5c7416c0bdc13d528fd 100644 (file)
@@ -190,7 +190,7 @@ static void rate_control_pid_sample(struct rc_pid_info *pinfo,
        rate_control_pid_normalize(pinfo, sband->n_bitrates);
 
        /* Compute the proportional, integral and derivative errors. */
-       err_prop = (pinfo->target << RC_PID_ARITH_SHIFT) - pf;
+       err_prop = (pinfo->target - pf) << RC_PID_ARITH_SHIFT;
 
        err_avg = spinfo->err_avg_sc >> pinfo->smoothing_shift;
        spinfo->err_avg_sc = spinfo->err_avg_sc - err_avg + err_prop;