linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] PID controller fixes
@ 2010-01-16 19:36 Bob Copeland
  2010-01-16 19:36 ` [PATCH 1/2] mac80211: fix sign error in pid controller Bob Copeland
  2010-01-16 19:36 ` [PATCH 2/2] mac80211: pid: replace open-coded msecs_to_jiffies Bob Copeland
  0 siblings, 2 replies; 5+ messages in thread
From: Bob Copeland @ 2010-01-16 19:36 UTC (permalink / raw)
  To: linville; +Cc: linux-wireless, Bob Copeland

Here are two fixes to the PID rc.  The first one improves PID
performance by quite a bit on my test setup, and seems correct,
but I am not an expert on the algo so comments welcome.  The
other is just a minor cleanup.  With the change, Minstrel is
still a bit better in my tests.

Bob Copeland (2):
  mac80211: fix sign error in pid controller
  mac80211: pid: replace open-coded msecs_to_jiffies

 net/mac80211/rc80211_pid_algo.c |   10 +++-------
 1 files changed, 3 insertions(+), 7 deletions(-)



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] mac80211: fix sign error in pid controller
  2010-01-16 19:36 [PATCH 0/2] PID controller fixes Bob Copeland
@ 2010-01-16 19:36 ` Bob Copeland
  2010-01-16 21:35   ` Stefano Brivio
  2010-01-17 22:49   ` Mattias Nissler
  2010-01-16 19:36 ` [PATCH 2/2] mac80211: pid: replace open-coded msecs_to_jiffies Bob Copeland
  1 sibling, 2 replies; 5+ messages in thread
From: Bob Copeland @ 2010-01-16 19:36 UTC (permalink / raw)
  To: linville; +Cc: linux-wireless, Bob Copeland, stefano.brivio, mattias.nissler

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.

Cc: stefano.brivio@polimi.it
Cc: mattias.nissler@gmx.de
Signed-off-by: Bob Copeland <me@bobcopeland.com>
---

Mattias / Stefano, please advise if I missed something.

 net/mac80211/rc80211_pid_algo.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/net/mac80211/rc80211_pid_algo.c b/net/mac80211/rc80211_pid_algo.c
index 699d3ed..29bc4c5 100644
--- a/net/mac80211/rc80211_pid_algo.c
+++ b/net/mac80211/rc80211_pid_algo.c
@@ -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;
-- 
1.6.3.3



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] mac80211: pid: replace open-coded msecs_to_jiffies
  2010-01-16 19:36 [PATCH 0/2] PID controller fixes Bob Copeland
  2010-01-16 19:36 ` [PATCH 1/2] mac80211: fix sign error in pid controller Bob Copeland
@ 2010-01-16 19:36 ` Bob Copeland
  1 sibling, 0 replies; 5+ messages in thread
From: Bob Copeland @ 2010-01-16 19:36 UTC (permalink / raw)
  To: linville; +Cc: linux-wireless, Bob Copeland

Code directly scaling by HZ and rounding can be more efficiently
and clearly performed with msecs_to_jiffies.

Signed-off-by: Bob Copeland <me@bobcopeland.com>
---
 net/mac80211/rc80211_pid_algo.c |    8 ++------
 1 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/net/mac80211/rc80211_pid_algo.c b/net/mac80211/rc80211_pid_algo.c
index 29bc4c5..2652a37 100644
--- a/net/mac80211/rc80211_pid_algo.c
+++ b/net/mac80211/rc80211_pid_algo.c
@@ -157,9 +157,7 @@ static void rate_control_pid_sample(struct rc_pid_info *pinfo,
 
 	/* In case nothing happened during the previous control interval, turn
 	 * the sharpening factor on. */
-	period = (HZ * pinfo->sampling_period + 500) / 1000;
-	if (!period)
-		period = 1;
+	period = msecs_to_jiffies(pinfo->sampling_period);
 	if (jiffies - spinfo->last_sample > 2 * period)
 		spinfo->sharp_cnt = pinfo->sharpen_duration;
 
@@ -252,9 +250,7 @@ static void rate_control_pid_tx_status(void *priv, struct ieee80211_supported_ba
 	}
 
 	/* Update PID controller state. */
-	period = (HZ * pinfo->sampling_period + 500) / 1000;
-	if (!period)
-		period = 1;
+	period = msecs_to_jiffies(pinfo->sampling_period);
 	if (time_after(jiffies, spinfo->last_sample + period))
 		rate_control_pid_sample(pinfo, sband, sta, spinfo);
 }
-- 
1.6.3.3



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] mac80211: fix sign error in pid controller
  2010-01-16 19:36 ` [PATCH 1/2] mac80211: fix sign error in pid controller Bob Copeland
@ 2010-01-16 21:35   ` Stefano Brivio
  2010-01-17 22:49   ` Mattias Nissler
  1 sibling, 0 replies; 5+ messages in thread
From: Stefano Brivio @ 2010-01-16 21:35 UTC (permalink / raw)
  To: Bob Copeland; +Cc: linville, linux-wireless

On Sat, 16 Jan 2010 14:36:52 -0500
Bob Copeland <me@bobcopeland.com> wrote:

> 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.

Good catch! I actually wonder why nobody hit this before. One possible
explanation is that the proportional error alone, in most cases, isn't
significant "enough" with regard to the other ones.

Mattias, could you please double check this anyway?

> Cc: stefano.brivio@polimi.it
> Cc: mattias.nissler@gmx.de
> Signed-off-by: Bob Copeland <me@bobcopeland.com>

Acked-by: Stefano Brivio <stefano.brivio@polimi.it>


--
Ciao
Stefano

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] mac80211: fix sign error in pid controller
  2010-01-16 19:36 ` [PATCH 1/2] mac80211: fix sign error in pid controller Bob Copeland
  2010-01-16 21:35   ` Stefano Brivio
@ 2010-01-17 22:49   ` Mattias Nissler
  1 sibling, 0 replies; 5+ messages in thread
From: Mattias Nissler @ 2010-01-17 22:49 UTC (permalink / raw)
  To: Bob Copeland; +Cc: linville, linux-wireless, stefano.brivio

[-- Attachment #1: Type: text/plain, Size: 1780 bytes --]

On Sat, 2010-01-16 at 14:36 -0500, Bob Copeland wrote:
> 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.
> 
> Cc: stefano.brivio@polimi.it
> Cc: mattias.nissler@gmx.de
> Signed-off-by: Bob Copeland <me@bobcopeland.com>

I took a quick look and found that you're right. pf is an unscaled
value, so we should subtract it before scaling.

Acked-by: Mattias Nissler <mattias.nissler@gmx.de>

> ---
> 
> Mattias / Stefano, please advise if I missed something.
> 
>  net/mac80211/rc80211_pid_algo.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/net/mac80211/rc80211_pid_algo.c b/net/mac80211/rc80211_pid_algo.c
> index 699d3ed..29bc4c5 100644
> --- a/net/mac80211/rc80211_pid_algo.c
> +++ b/net/mac80211/rc80211_pid_algo.c
> @@ -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;


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-01-17 22:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-16 19:36 [PATCH 0/2] PID controller fixes Bob Copeland
2010-01-16 19:36 ` [PATCH 1/2] mac80211: fix sign error in pid controller Bob Copeland
2010-01-16 21:35   ` Stefano Brivio
2010-01-17 22:49   ` Mattias Nissler
2010-01-16 19:36 ` [PATCH 2/2] mac80211: pid: replace open-coded msecs_to_jiffies Bob Copeland

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).