[PATCH 3/7] chardev/char.c: Use qemu_co_sleep_ns if in coroutine

Zhang Chen posted 7 patches 5 years, 8 months ago
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, Li Zhijian <lizhijian@cn.fujitsu.com>, Jason Wang <jasowang@redhat.com>, Zhang Chen <chen.zhang@intel.com>
There is a newer version of this series
[PATCH 3/7] chardev/char.c: Use qemu_co_sleep_ns if in coroutine
Posted by Zhang Chen 5 years, 8 months ago
From: Lukas Straub <lukasstraub2@web.de>

This will be needed in the next patch.

Signed-off-by: Lukas Straub <lukasstraub2@web.de>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Zhang Chen <chen.zhang@intel.com>
Signed-off-by: Zhang Chen <chen.zhang@intel.com>
---
 chardev/char.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/chardev/char.c b/chardev/char.c
index 0196e2887b..4c58ea1836 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -38,6 +38,7 @@
 #include "qemu/module.h"
 #include "qemu/option.h"
 #include "qemu/id.h"
+#include "qemu/coroutine.h"
 
 #include "chardev/char-mux.h"
 
@@ -119,7 +120,11 @@ static int qemu_chr_write_buffer(Chardev *s,
     retry:
         res = cc->chr_write(s, buf + *offset, len - *offset);
         if (res < 0 && errno == EAGAIN && write_all) {
-            g_usleep(100);
+            if (qemu_in_coroutine()) {
+                qemu_co_sleep_ns(QEMU_CLOCK_REALTIME, 100000);
+            } else {
+                g_usleep(100);
+            }
             goto retry;
         }
 
-- 
2.17.1


Re: [PATCH 3/7] chardev/char.c: Use qemu_co_sleep_ns if in coroutine
Posted by Philippe Mathieu-Daudé 5 years, 8 months ago
On 5/19/20 10:02 PM, Zhang Chen wrote:
> From: Lukas Straub <lukasstraub2@web.de>
> 
> This will be needed in the next patch.

Can you reword to something clearer, maybe:

"To be able to convert compare_chr_send to a coroutine in the
next commit, use qemu_co_sleep_ns if in coroutine."

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> 
> Signed-off-by: Lukas Straub <lukasstraub2@web.de>
> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> Reviewed-by: Zhang Chen <chen.zhang@intel.com>
> Signed-off-by: Zhang Chen <chen.zhang@intel.com>
> ---
>   chardev/char.c | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/chardev/char.c b/chardev/char.c
> index 0196e2887b..4c58ea1836 100644
> --- a/chardev/char.c
> +++ b/chardev/char.c
> @@ -38,6 +38,7 @@
>   #include "qemu/module.h"
>   #include "qemu/option.h"
>   #include "qemu/id.h"
> +#include "qemu/coroutine.h"
>   
>   #include "chardev/char-mux.h"
>   
> @@ -119,7 +120,11 @@ static int qemu_chr_write_buffer(Chardev *s,
>       retry:
>           res = cc->chr_write(s, buf + *offset, len - *offset);
>           if (res < 0 && errno == EAGAIN && write_all) {
> -            g_usleep(100);
> +            if (qemu_in_coroutine()) {
> +                qemu_co_sleep_ns(QEMU_CLOCK_REALTIME, 100000);
> +            } else {
> +                g_usleep(100);
> +            }
>               goto retry;
>           }
>   
>