bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] poll: prevent busy-waiting


From: Paolo Bonzini
Subject: Re: [PATCH] poll: prevent busy-waiting
Date: Fri, 18 May 2012 09:40:08 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120430 Thunderbird/12.0.1

Il 16/05/2012 21:16, Erik Faye-Lund ha scritto:
> From: theoleblond <address@hidden>
> 
> SwitchToThread() only gives away the rest of the current time
> slice to another thread in the current process. So if the
> thread that feeds the file decscriptor we're polling is not
> in the current process, we get busy-waiting. This can lead
> to very poor performance in some cases, so we better just
> wait a tiny amount instead.
> 
> * lib/poll.c: use SleepEx(1, TRUE) instead of SwitchToThread()
> ---
> 
> Here's a patch we've applied to Git for Windows. Perhaps it's
> useful upstream as well?
> 
> I'm forwarding it on behalf of Theodore, who was nice enough
> to debug a performance issue and nail down a fix. Thanks,
> Theodore!
> 
>  ChangeLog  | 13 +++++++++++++
>  lib/poll.c |  3 ++-
>  2 files changed, 15 insertions(+), 1 deletion(-)
> 
> diff --git a/ChangeLog b/ChangeLog
> index aeb3cf8..b94c311 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,16 @@
> +2012-05-16  theoleblond  <address@hidden>
> +
> +     poll: prevent busy-waiting
> +
> +     SwitchToThread() only gives away the rest of the current time
> +     slice to another thread in the current process. So if the
> +     thread that feeds the file decscriptor we're polling is not
> +     in the current process, we get busy-waiting. This can lead
> +     to very poor performance in some cases, so we better just
> +     wait a tiny amount instead.
> +
> +     * lib/poll.c: use SleepEx(1, TRUE) instead of SwitchToThread()
> +
>  2012-05-15  Pádraig Brady  <address@hidden>
>  
>       fsusage: fix block size returned on older Linux 2.6
> diff --git a/lib/poll.c b/lib/poll.c
> index 3071b12..235338e 100644
> --- a/lib/poll.c
> +++ b/lib/poll.c
> @@ -598,7 +598,8 @@ restart:
>  
>    if (!rc && timeout == INFTIM)
>      {
> -      SwitchToThread();
> +      /* Sleep 1 millisecond to avoid busy wait */
> +      SleepEx(1, TRUE);
>        goto restart;
>      }
>  

Looks good, do you have commit access?

Paolo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]