* [PATCH] sch_red: fix weighted average calculation
@ 2012-09-13 13:43 Cyril Chemparathy
2012-09-13 13:53 ` Eric Dumazet
0 siblings, 1 reply; 4+ messages in thread
From: Cyril Chemparathy @ 2012-09-13 13:43 UTC (permalink / raw)
To: linux-kernel, netdev
Cc: davem, david.ward, eric.dumazet, jdowdal, paul.gortmaker,
Cyril Chemparathy
This patch fixes an apparent bug in the running weighted average calculation
used in the RED algorithm.
Going by the described formula:
qavg = qavg*(1-W) + backlog*W
=> qavg = qavg + (backlog - qavg) * W
... with W converted to a pre-calculated shift, this then becomes:
qavg = qavg + (backlog - qavg) >> logW
... giving the modified expression introduced by this patch.
Signed-off-by: John Dowdal <jdowdal@ti.com>
---
include/net/red.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/net/red.h b/include/net/red.h
index ef46058..05960a4 100644
--- a/include/net/red.h
+++ b/include/net/red.h
@@ -287,7 +287,7 @@ static inline unsigned long red_calc_qavg_no_idle_time(const struct red_parms *p
*
* --ANK (980924)
*/
- return v->qavg + (backlog - (v->qavg >> p->Wlog));
+ return v->qavg + (backlog - v->qavg) >> p->Wlog;
}
static inline unsigned long red_calc_qavg(const struct red_parms *p,
--
1.7.9.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] sch_red: fix weighted average calculation
2012-09-13 13:43 [PATCH] sch_red: fix weighted average calculation Cyril Chemparathy
@ 2012-09-13 13:53 ` Eric Dumazet
2012-09-14 13:01 ` Dowdal, John
0 siblings, 1 reply; 4+ messages in thread
From: Eric Dumazet @ 2012-09-13 13:53 UTC (permalink / raw)
To: Cyril Chemparathy
Cc: linux-kernel, netdev, davem, david.ward, jdowdal, paul.gortmaker
On Thu, 2012-09-13 at 09:43 -0400, Cyril Chemparathy wrote:
> This patch fixes an apparent bug in the running weighted average calculation
> used in the RED algorithm.
>
> Going by the described formula:
> qavg = qavg*(1-W) + backlog*W
> => qavg = qavg + (backlog - qavg) * W
>
> ... with W converted to a pre-calculated shift, this then becomes:
> qavg = qavg + (backlog - qavg) >> logW
>
> ... giving the modified expression introduced by this patch.
>
> Signed-off-by: John Dowdal <jdowdal@ti.com>
> ---
> include/net/red.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/net/red.h b/include/net/red.h
> index ef46058..05960a4 100644
> --- a/include/net/red.h
> +++ b/include/net/red.h
> @@ -287,7 +287,7 @@ static inline unsigned long red_calc_qavg_no_idle_time(const struct red_parms *p
> *
> * --ANK (980924)
> */
> - return v->qavg + (backlog - (v->qavg >> p->Wlog));
> + return v->qavg + (backlog - v->qavg) >> p->Wlog;
> }
>
> static inline unsigned long red_calc_qavg(const struct red_parms *p,
This is going to be a FPP (Frequently Posted Patch)
Current formulae is fine.
Thats because backlog, at start of red_calc_qavg_no_idle_time() is not
yet scaled by p->Wlog. v->avg is scaled, but not backlog.
Have you tested RED after your patch ?
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [PATCH] sch_red: fix weighted average calculation
2012-09-13 13:53 ` Eric Dumazet
@ 2012-09-14 13:01 ` Dowdal, John
2012-09-14 13:13 ` Eric Dumazet
0 siblings, 1 reply; 4+ messages in thread
From: Dowdal, John @ 2012-09-14 13:01 UTC (permalink / raw)
To: Eric Dumazet, Chemparathy, Cyril
Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
davem@davemloft.net, david.ward@ll.mit.edu,
paul.gortmaker@windriver.com
Eric, thank you for reviewing the code. I now see the problem with the patch since backlog is an integer and qavg is a fixed point number at logW.
We are considering another patch to update the comments to this code (with the actual C code change reverted) to stop the FPP by showing the derivation of the equation in the comments. Does this sound good?
-----Original Message-----
From: Eric Dumazet [mailto:eric.dumazet@gmail.com]
Sent: Thursday, September 13, 2012 9:54 AM
To: Chemparathy, Cyril
Cc: linux-kernel@vger.kernel.org; netdev@vger.kernel.org; davem@davemloft.net; david.ward@ll.mit.edu; Dowdal, John; paul.gortmaker@windriver.com
Subject: Re: [PATCH] sch_red: fix weighted average calculation
On Thu, 2012-09-13 at 09:43 -0400, Cyril Chemparathy wrote:
> This patch fixes an apparent bug in the running weighted average calculation
> used in the RED algorithm.
>
> Going by the described formula:
> qavg = qavg*(1-W) + backlog*W
> => qavg = qavg + (backlog - qavg) * W
>
> ... with W converted to a pre-calculated shift, this then becomes:
> qavg = qavg + (backlog - qavg) >> logW
>
> ... giving the modified expression introduced by this patch.
>
> Signed-off-by: John Dowdal <jdowdal@ti.com>
> ---
> include/net/red.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/net/red.h b/include/net/red.h
> index ef46058..05960a4 100644
> --- a/include/net/red.h
> +++ b/include/net/red.h
> @@ -287,7 +287,7 @@ static inline unsigned long red_calc_qavg_no_idle_time(const struct red_parms *p
> *
> * --ANK (980924)
> */
> - return v->qavg + (backlog - (v->qavg >> p->Wlog));
> + return v->qavg + (backlog - v->qavg) >> p->Wlog;
> }
>
> static inline unsigned long red_calc_qavg(const struct red_parms *p,
This is going to be a FPP (Frequently Posted Patch)
Current formulae is fine.
Thats because backlog, at start of red_calc_qavg_no_idle_time() is not
yet scaled by p->Wlog. v->avg is scaled, but not backlog.
Have you tested RED after your patch ?
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [PATCH] sch_red: fix weighted average calculation
2012-09-14 13:01 ` Dowdal, John
@ 2012-09-14 13:13 ` Eric Dumazet
0 siblings, 0 replies; 4+ messages in thread
From: Eric Dumazet @ 2012-09-14 13:13 UTC (permalink / raw)
To: Dowdal, John
Cc: Chemparathy, Cyril, linux-kernel@vger.kernel.org,
netdev@vger.kernel.org, davem@davemloft.net,
david.ward@ll.mit.edu, paul.gortmaker@windriver.com
On Fri, 2012-09-14 at 13:01 +0000, Dowdal, John wrote:
> Eric, thank you for reviewing the code. I now see the problem with
> the patch since backlog is an integer and qavg is a fixed point number
> at logW.
>
> We are considering another patch to update the comments to this code
> (with the actual C code change reverted) to stop the FPP by showing
> the derivation of the equation in the comments. Does this sound good?
This would be good, please do so.
Thanks
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-09-14 13:13 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-13 13:43 [PATCH] sch_red: fix weighted average calculation Cyril Chemparathy
2012-09-13 13:53 ` Eric Dumazet
2012-09-14 13:01 ` Dowdal, John
2012-09-14 13:13 ` Eric Dumazet
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox