From: Pavel Dovgalyuk <pavel.dovgalyuk@ispras.ru>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, richard.henderson@linaro.org
Subject: Re: [PATCH] replay: don't wait in run_on_cpu
Date: Mon, 15 Mar 2021 08:59:23 +0300 [thread overview]
Message-ID: <e7fa6729-2e22-1ee9-a0cd-e213146f30f2@ispras.ru> (raw)
In-Reply-To: <161544684811.80476.11634004581744007934.stgit@pasha-ThinkPad-X280>
ping
On 11.03.2021 10:14, Pavel Dovgalyuk wrote:
> In record/replay mode waiting for vCPU to execute
> the task scheduled by run_on_cpu may lead to deadlock,
> because when run_on_cpu is executed in main_loop
> (e.g., in loadvm processing) it holds replay mutex.
> This patch allows running scheduled task in iothread
> when it holds the replay mutex.
>
> Signed-off-by: Pavel Dovgalyuk <Pavel.Dovgalyuk@ispras.ru>
> ---
> cpus-common.c | 9 ++++++++-
> include/sysemu/replay.h | 1 +
> replay/replay-internal.h | 1 -
> stubs/replay-tools.c | 5 +++++
> 4 files changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/cpus-common.c b/cpus-common.c
> index 6e73d3e58d..38ff510175 100644
> --- a/cpus-common.c
> +++ b/cpus-common.c
> @@ -23,6 +23,7 @@
> #include "hw/core/cpu.h"
> #include "sysemu/cpus.h"
> #include "qemu/lockable.h"
> +#include "sysemu/replay.h"
>
> static QemuMutex qemu_cpu_list_lock;
> static QemuCond exclusive_cond;
> @@ -136,7 +137,13 @@ void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data,
> {
> struct qemu_work_item wi;
>
> - if (qemu_cpu_is_self(cpu)) {
> + if (qemu_cpu_is_self(cpu)
> + /*
> + * vCPU thread is waiting when replay mutex is locked
> + * and the task is not exclusive, the function may be called
> + * without other synchronization.
> + */
> + || (replay_mode != REPLAY_MODE_NONE && replay_mutex_locked())) {
> func(cpu, data);
> return;
> }
> diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h
> index 0f3b0f7eac..032256533b 100644
> --- a/include/sysemu/replay.h
> +++ b/include/sysemu/replay.h
> @@ -62,6 +62,7 @@ extern char *replay_snapshot;
>
> void replay_mutex_lock(void);
> void replay_mutex_unlock(void);
> +bool replay_mutex_locked(void);
>
> /* Replay process control functions */
>
> diff --git a/replay/replay-internal.h b/replay/replay-internal.h
> index 97649ed8d7..dada623527 100644
> --- a/replay/replay-internal.h
> +++ b/replay/replay-internal.h
> @@ -117,7 +117,6 @@ void replay_get_array_alloc(uint8_t **buf, size_t *size);
> * synchronisation between vCPU and main-loop threads. */
>
> void replay_mutex_init(void);
> -bool replay_mutex_locked(void);
>
> /*! Checks error status of the file. */
> void replay_check_error(void);
> diff --git a/stubs/replay-tools.c b/stubs/replay-tools.c
> index 43296b3d4e..a42f2483d5 100644
> --- a/stubs/replay-tools.c
> +++ b/stubs/replay-tools.c
> @@ -48,6 +48,11 @@ void replay_mutex_unlock(void)
> {
> }
>
> +bool replay_mutex_locked(void)
> +{
> + return false;
> +}
> +
> void replay_register_char_driver(Chardev *chr)
> {
> }
>
next prev parent reply other threads:[~2021-03-15 6:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-11 7:14 [PATCH] replay: don't wait in run_on_cpu Pavel Dovgalyuk
2021-03-15 5:59 ` Pavel Dovgalyuk [this message]
-- strict thread matches above, loose matches on Subject: below --
2021-03-29 8:05 Pavel Dovgalyuk
2021-03-29 9:42 ` Paolo Bonzini
2021-03-29 10:55 ` Pavel Dovgalyuk
2021-03-29 12:11 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e7fa6729-2e22-1ee9-a0cd-e213146f30f2@ispras.ru \
--to=pavel.dovgalyuk@ispras.ru \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).