lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Thu, 15 May 2008 17:15:50 +0200
From:	"Dmitry Adamushko" <dmitry.adamushko@...il.com>
To:	vatsa@...ux.vnet.ibm.com
Cc:	"Gautham R Shenoy" <ego@...ibm.com>, "Ingo Molnar" <mingo@...e.hu>,
	npiggin@...e.de, linux-kernel@...r.kernel.org,
	"Srivatsa Vaddagiri" <vatsa@...ibm.com>
Subject: Re: [PATCH] sched: Improve readability in update_cpu_load() code

2008/5/15 Srivatsa Vaddagiri <vatsa@...ux.vnet.ibm.com>:
> On Thu, May 15, 2008 at 06:34:59PM +0530, Gautham R Shenoy wrote:
>> Author: Gautham R Shenoy <ego@...ibm.com>
>> Date:   Thu May 15 17:55:49 2008 +0530
>>
>>     sched: Improve readability in update_cpu_load() code
>>
>>     Currently the cpu_load[i] is calculated as:
>>       this_rq->cpu_load[i] = (old_load*(scale-1) + new_load) >> i;
>>
>>     However, since scale = 2^i, this can be simplified as:
>>       this_rq->cpu_load[i] = old_load + ((new_load - old_load) >> i);
>>
>>     Makes it easier to read.
>>     Signed-off-by: Gautham R Shenoy <ego@...ibm.com>
>>
>> diff --git a/kernel/sched.c b/kernel/sched.c
>> index 2d7d8f1..e1a6985 100644
>> --- a/kernel/sched.c
>> +++ b/kernel/sched.c
>> @@ -2921,7 +2921,7 @@ static void update_cpu_load(struct rq *this_rq)
>>                */
>>               if (new_load > old_load)
>>                       new_load += scale-1;
>> -             this_rq->cpu_load[i] = (old_load*(scale-1) + new_load) >> i;
>> +             this_rq->cpu_load[i] = old_load + ((new_load - old_load) >> i);
>
> This wont work when new_load < old_load ..
>
> For ex: I tried this prog:
>
> #include <stdio.h>
>
> main()
> {
>        unsigned long old_load = 100, new_load = 90, this_load, this_load1;
>        int i = 1, scale = 2 << i;
>
>        this_load = (old_load*(scale-1) + new_load) >> i;
>        this_load1 = old_load + ((new_load - old_load) >> i);

it should be

this_load2 = 2 * old_load + (new_load >> i) - (old_load >> i);

scale == 2 << i == 1 << (i + 1), so scale >> i = 2.

and it may result in (probably) little difefrences due to different rounding.
I think, for me the currently existing version is more easy-to-read.


> --
> Regards,
> vatsa

-- 
Best regards,
Dmitry Adamushko
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ