Re: sched: odd values for effective load calculations

Peter Zijlstra
2014-12-19T11:20:44Z

On Fri, Dec 19, 2014 at 08:29:56AM +0800, Yuyang Du wrote:
> Subject: [PATCH] sched: Fix long and unsigned long multiplication error in effective_load
>
> In effective_load, we have (long w * unsigned long tg->shares) / long W,
> when w is negative, it is cast to unsigned long and hence the product is
> insanely large. Fix this by casting tg->shares to long.
>
> Reported-by: Sasha Levin <sasha.levin@oracle.com>
> Signed-off-by: Yuyang Du <yuyang.du@intel.com>
> ---
> kernel/sched/fair.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index df2cdf7..6b99659 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -4424,7 +4424,7 @@ static long effective_load(struct task_group *tg, int cpu, long wl, long wg)
> * wl = S * s'_i; see (2)
> */
> if (W > 0 && w < W)
> - wl = (w * tg->shares) / W;
> + wl = (w * (long)tg->shares) / W;
> else
> wl = tg->shares;

Oh, nice! thanks!