[Qemu-devel] [PATCH] icount: fix deadlock when all cpus are sleeping

Clement Deschamps posted 1 patch 7 years ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20181021142103.19014-1-clement.deschamps@greensocs.com
Test docker-clang@ubuntu failed
Test checkpatch passed
Test asan passed
Test docker-mingw@fedora failed
Test docker-quick@centos7 passed
cpus.c | 8 ++++++++
1 file changed, 8 insertions(+)
[Qemu-devel] [PATCH] icount: fix deadlock when all cpus are sleeping
Posted by Clement Deschamps 7 years ago
When all cpus are sleeping (e.g in WFI), to avoid a deadlock
in the main_loop, wake it up in order to start the warp timer.

Signed-off-by: Clement Deschamps <clement.deschamps@greensocs.com>
---
 cpus.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/cpus.c b/cpus.c
index bb2a511483..798d43623a 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1554,6 +1554,14 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg)
             atomic_mb_set(&cpu->exit_request, 0);
         }
 
+        if (use_icount && all_cpu_threads_idle()) {
+            /*
+             * When all cpus are sleeping (e.g in WFI), to avoid a deadlock
+             * in the main_loop, wake it up in order to start the warp timer.
+             */
+            qemu_notify_event();
+        }
+
         qemu_tcg_rr_wait_io_event(cpu ? cpu : first_cpu);
         deal_with_unplugged_cpus();
     }
-- 
2.19.1


Re: [Qemu-devel] [PATCH] icount: fix deadlock when all cpus are sleeping
Posted by Paolo Bonzini 7 years ago
On 21/10/2018 16:21, Clement Deschamps wrote:
> When all cpus are sleeping (e.g in WFI), to avoid a deadlock
> in the main_loop, wake it up in order to start the warp timer.
> 
> Signed-off-by: Clement Deschamps <clement.deschamps@greensocs.com>
> ---
>  cpus.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/cpus.c b/cpus.c
> index bb2a511483..798d43623a 100644
> --- a/cpus.c
> +++ b/cpus.c
> @@ -1554,6 +1554,14 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg)
>              atomic_mb_set(&cpu->exit_request, 0);
>          }
>  
> +        if (use_icount && all_cpu_threads_idle()) {
> +            /*
> +             * When all cpus are sleeping (e.g in WFI), to avoid a deadlock
> +             * in the main_loop, wake it up in order to start the warp timer.
> +             */
> +            qemu_notify_event();
> +        }
> +
>          qemu_tcg_rr_wait_io_event(cpu ? cpu : first_cpu);
>          deal_with_unplugged_cpus();
>      }
> 

Queued, thanks.

Paolo