lkml.org 
[lkml]   [2019]   [Sep]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 4/9] select: Micro-optimise __estimate_accuracy()
On Mon, Sep 09, 2019 at 11:23:35AM +0100, Dmitry Safonov wrote:
> Shift on s64 is faster than division, use it instead.
>
> As the result of the patch there is a hardly user-visible effect:
> poll(), select(), etc syscalls will be a bit more precise on ~2.3%
> than before because 1000 != 1024 :)
>
> Signed-off-by: Dmitry Safonov <dima@arista.com>

> ---
> fs/select.c | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/fs/select.c b/fs/select.c
> index 12cdefd3be2d..2477c202631e 100644
> --- a/fs/select.c
> +++ b/fs/select.c
> @@ -51,15 +51,14 @@
>
> static long __estimate_accuracy(ktime_t slack)
> {
> - int divfactor = 1000;
> -
> if (slack < 0)
> return 0;
>
> - if (task_nice(current) > 0)
> - divfactor = divfactor / 5;
> + /* A bit more precise than 0.1% */
> + slack = slack >> 10;
>
> - slack = ktime_divns(slack, divfactor);
> + if (task_nice(current) > 0)
> + slack = slack * 5;
>
> if (slack > MAX_SLACK)
> return MAX_SLACK;

Compiler precompute constants so it doesn't do division here.
But I didn't read the series yet so I might be missing
something obvious.

\
 
 \ /
  Last update: 2019-09-09 13:19    [W:0.153 / U:1.604 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site