All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] thread-posix: optimize qemu_sem_timedwait with zero timeout
@ 2022-02-23  8:36 Paolo Bonzini
  2022-02-23 10:27 ` longpeng2--- via
  2022-02-23 10:44 ` Philippe Mathieu-Daudé
  0 siblings, 2 replies; 3+ messages in thread
From: Paolo Bonzini @ 2022-02-23  8:36 UTC (permalink / raw)
  To: qemu-devel; +Cc: Longpeng(Mike)

In this case there is no need to call pthread_cond_timedwait; the
function is just a trywait and waiting on the condition variable would
always time out.

Based-on: <20220222090507.2028-1-longpeng2@huawei.com>
Cc: "Longpeng(Mike)" <longpeng2@huawei.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 util/qemu-thread-posix.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c
index f2ce47d36b..89c23f1d64 100644
--- a/util/qemu-thread-posix.c
+++ b/util/qemu-thread-posix.c
@@ -282,8 +282,12 @@ int qemu_sem_timedwait(QemuSemaphore *sem, int ms)
     compute_abs_deadline(&ts, ms);
     qemu_mutex_lock(&sem->mutex);
     while (sem->count == 0) {
-        rc = qemu_cond_timedwait_ts(&sem->cond, &sem->mutex, &ts,
-                                    __FILE__, __LINE__);
+        if (ms == 0) {
+            rc = false;
+        } else {
+            rc = qemu_cond_timedwait_ts(&sem->cond, &sem->mutex, &ts,
+                                        __FILE__, __LINE__);
+        }
         if (!rc) { /* timeout */
             break;
         }
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* RE: [PATCH] thread-posix: optimize qemu_sem_timedwait with zero timeout
  2022-02-23  8:36 [PATCH] thread-posix: optimize qemu_sem_timedwait with zero timeout Paolo Bonzini
@ 2022-02-23 10:27 ` longpeng2--- via
  2022-02-23 10:44 ` Philippe Mathieu-Daudé
  1 sibling, 0 replies; 3+ messages in thread
From: longpeng2--- via @ 2022-02-23 10:27 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel



> -----Original Message-----
> From: Paolo Bonzini [mailto:paolo.bonzini@gmail.com] On Behalf Of Paolo Bonzini
> Sent: Wednesday, February 23, 2022 4:36 PM
> To: qemu-devel@nongnu.org
> Cc: Longpeng (Mike, Cloud Infrastructure Service Product Dept.)
> <longpeng2@huawei.com>
> Subject: [PATCH] thread-posix: optimize qemu_sem_timedwait with zero timeout
> 
> In this case there is no need to call pthread_cond_timedwait; the
> function is just a trywait and waiting on the condition variable would
> always time out.
> 
> Based-on: <20220222090507.2028-1-longpeng2@huawei.com>
> Cc: "Longpeng(Mike)" <longpeng2@huawei.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  util/qemu-thread-posix.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c
> index f2ce47d36b..89c23f1d64 100644
> --- a/util/qemu-thread-posix.c
> +++ b/util/qemu-thread-posix.c
> @@ -282,8 +282,12 @@ int qemu_sem_timedwait(QemuSemaphore *sem, int ms)
>      compute_abs_deadline(&ts, ms);
>      qemu_mutex_lock(&sem->mutex);
>      while (sem->count == 0) {
> -        rc = qemu_cond_timedwait_ts(&sem->cond, &sem->mutex, &ts,
> -                                    __FILE__, __LINE__);
> +        if (ms == 0) {
> +            rc = false;
> +        } else {
> +            rc = qemu_cond_timedwait_ts(&sem->cond, &sem->mutex, &ts,
> +                                        __FILE__, __LINE__);
> +        }
>          if (!rc) { /* timeout */
>              break;
>          }
> --
> 2.34.1

Reviewed-by: Longpeng <longpeng2@huawei.com>

Thanks.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] thread-posix: optimize qemu_sem_timedwait with zero timeout
  2022-02-23  8:36 [PATCH] thread-posix: optimize qemu_sem_timedwait with zero timeout Paolo Bonzini
  2022-02-23 10:27 ` longpeng2--- via
@ 2022-02-23 10:44 ` Philippe Mathieu-Daudé
  1 sibling, 0 replies; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2022-02-23 10:44 UTC (permalink / raw)
  To: Paolo Bonzini, qemu-devel; +Cc: Longpeng(Mike)

On 23/2/22 09:36, Paolo Bonzini wrote:
> In this case there is no need to call pthread_cond_timedwait; the
> function is just a trywait and waiting on the condition variable would
> always time out.
> 
> Based-on: <20220222090507.2028-1-longpeng2@huawei.com>

^ Please remove when applying.

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> Cc: "Longpeng(Mike)" <longpeng2@huawei.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>   util/qemu-thread-posix.c | 8 ++++++--
>   1 file changed, 6 insertions(+), 2 deletions(-)


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-02-23 10:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-23  8:36 [PATCH] thread-posix: optimize qemu_sem_timedwait with zero timeout Paolo Bonzini
2022-02-23 10:27 ` longpeng2--- via
2022-02-23 10:44 ` Philippe Mathieu-Daudé

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.