diff mbox series

[23/51] accel/qtest: Support qtest accelerator for Windows

Message ID 20220824094029.1634519-24-bmeng.cn@gmail.com (mailing list archive)
State New, archived
Headers show
Series tests/qtest: Enable running qtest on Windows | expand

Commit Message

Bin Meng Aug. 24, 2022, 9:40 a.m. UTC
From: Xuzhou Cheng <xuzhou.cheng@windriver.com>

Currently signal SIGIPI [=SIGUSR1] is used to kick the dummy CPU
when qtest accelerator is used. However SIGUSR1 is unsupported on
Windows. To support Windows, we add a QemuSemaphore CPUState::sem
to kick the dummy CPU instead for Windows.

Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
Signed-off-by: Bin Meng <bin.meng@windriver.com>
---

 include/hw/core/cpu.h   |  1 +
 accel/dummy-cpus.c      | 14 ++++++++++++--
 softmmu/cpus.c          |  9 +++++----
 accel/meson.build       |  1 +
 accel/qtest/meson.build |  1 +
 5 files changed, 20 insertions(+), 6 deletions(-)

Comments

Marc-André Lureau Aug. 31, 2022, 1:49 p.m. UTC | #1
Hi

On Wed, Aug 24, 2022 at 2:31 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
>
> Currently signal SIGIPI [=SIGUSR1] is used to kick the dummy CPU
> when qtest accelerator is used. However SIGUSR1 is unsupported on
> Windows. To support Windows, we add a QemuSemaphore CPUState::sem
> to kick the dummy CPU instead for Windows.
>
> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>

What if we replace signals by the semaphore on posix as well?

but lgtm,
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>


> ---
>
>  include/hw/core/cpu.h   |  1 +
>  accel/dummy-cpus.c      | 14 ++++++++++++--
>  softmmu/cpus.c          |  9 +++++----
>  accel/meson.build       |  1 +
>  accel/qtest/meson.build |  1 +
>  5 files changed, 20 insertions(+), 6 deletions(-)
>
> diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
> index 500503da13..c564108877 100644
> --- a/include/hw/core/cpu.h
> +++ b/include/hw/core/cpu.h
> @@ -325,6 +325,7 @@ struct CPUState {
>      struct QemuThread *thread;
>  #ifdef _WIN32
>      HANDLE hThread;
> +    QemuSemaphore sem;
>  #endif
>      int thread_id;
>      bool running, has_waiter;
> diff --git a/accel/dummy-cpus.c b/accel/dummy-cpus.c
> index 10429fdfb2..d6a1b8d0a2 100644
> --- a/accel/dummy-cpus.c
> +++ b/accel/dummy-cpus.c
> @@ -21,8 +21,6 @@
>  static void *dummy_cpu_thread_fn(void *arg)
>  {
>      CPUState *cpu = arg;
> -    sigset_t waitset;
> -    int r;
>
>      rcu_register_thread();
>
> @@ -32,8 +30,13 @@ static void *dummy_cpu_thread_fn(void *arg)
>      cpu->can_do_io = 1;
>      current_cpu = cpu;
>
> +#ifndef _WIN32
> +    sigset_t waitset;
> +    int r;
> +
>      sigemptyset(&waitset);
>      sigaddset(&waitset, SIG_IPI);
> +#endif
>
>      /* signal CPU creation */
>      cpu_thread_signal_created(cpu);
> @@ -41,6 +44,7 @@ static void *dummy_cpu_thread_fn(void *arg)
>
>      do {
>          qemu_mutex_unlock_iothread();
> +#ifndef _WIN32
>          do {
>              int sig;
>              r = sigwait(&waitset, &sig);
> @@ -49,6 +53,9 @@ static void *dummy_cpu_thread_fn(void *arg)
>              perror("sigwait");
>              exit(1);
>          }
> +#else
> +        qemu_sem_wait(&cpu->sem);
> +#endif
>          qemu_mutex_lock_iothread();
>          qemu_wait_io_event(cpu);
>      } while (!cpu->unplug);
> @@ -69,4 +76,7 @@ void dummy_start_vcpu_thread(CPUState *cpu)
>               cpu->cpu_index);
>      qemu_thread_create(cpu->thread, thread_name, dummy_cpu_thread_fn, cpu,
>                         QEMU_THREAD_JOINABLE);
> +#ifdef _WIN32
> +    qemu_sem_init(&cpu->sem, 0);
> +#endif
>  }
> diff --git a/softmmu/cpus.c b/softmmu/cpus.c
> index 23b30484b2..fd10db927a 100644
> --- a/softmmu/cpus.c
> +++ b/softmmu/cpus.c
> @@ -437,18 +437,19 @@ void qemu_wait_io_event(CPUState *cpu)
>
>  void cpus_kick_thread(CPUState *cpu)
>  {
> -#ifndef _WIN32
> -    int err;
> -
>      if (cpu->thread_kicked) {
>          return;
>      }
>      cpu->thread_kicked = true;
> -    err = pthread_kill(cpu->thread->thread, SIG_IPI);
> +
> +#ifndef _WIN32
> +    int err = pthread_kill(cpu->thread->thread, SIG_IPI);
>      if (err && err != ESRCH) {
>          fprintf(stderr, "qemu:%s: %s", __func__, strerror(err));
>          exit(1);
>      }
> +#else
> +    qemu_sem_post(&cpu->sem);
>  #endif
>  }
>
> diff --git a/accel/meson.build b/accel/meson.build
> index b9a963cf80..b21c85dc0a 100644
> --- a/accel/meson.build
> +++ b/accel/meson.build
> @@ -17,4 +17,5 @@ dummy_ss.add(files(
>  ))
>
>  specific_ss.add_all(when: ['CONFIG_SOFTMMU', 'CONFIG_POSIX'], if_true:
> dummy_ss)
> +specific_ss.add_all(when: ['CONFIG_WIN32'], if_true: dummy_ss)
>  specific_ss.add_all(when: ['CONFIG_XEN'], if_true: dummy_ss)
> diff --git a/accel/qtest/meson.build b/accel/qtest/meson.build
> index 4c65600293..a4876fc0f2 100644
> --- a/accel/qtest/meson.build
> +++ b/accel/qtest/meson.build
> @@ -1,2 +1,3 @@
>  qtest_module_ss.add(when: ['CONFIG_SOFTMMU', 'CONFIG_POSIX'],
>                      if_true: files('qtest.c'))
> +qtest_module_ss.add(when: ['CONFIG_WIN32'], if_true: files('qtest.c'))
> --
> 2.34.1
>
>
>
Bin Meng Sept. 2, 2022, 8:28 a.m. UTC | #2
On Wed, Aug 31, 2022 at 9:50 PM Marc-André Lureau
<marcandre.lureau@gmail.com> wrote:
>
> Hi
>
> On Wed, Aug 24, 2022 at 2:31 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>>
>> From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
>>
>> Currently signal SIGIPI [=SIGUSR1] is used to kick the dummy CPU
>> when qtest accelerator is used. However SIGUSR1 is unsupported on
>> Windows. To support Windows, we add a QemuSemaphore CPUState::sem
>> to kick the dummy CPU instead for Windows.
>>
>> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
>> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>
>
> What if we replace signals by the semaphore on posix as well?

Yeah, with that we can make this a complete portable implementation.
Will do in v2.

>
> but lgtm,
> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>
>>
>> ---
>>
>>  include/hw/core/cpu.h   |  1 +
>>  accel/dummy-cpus.c      | 14 ++++++++++++--
>>  softmmu/cpus.c          |  9 +++++----
>>  accel/meson.build       |  1 +
>>  accel/qtest/meson.build |  1 +
>>  5 files changed, 20 insertions(+), 6 deletions(-)
>>

Regards,
Bin
diff mbox series

Patch

diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 500503da13..c564108877 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -325,6 +325,7 @@  struct CPUState {
     struct QemuThread *thread;
 #ifdef _WIN32
     HANDLE hThread;
+    QemuSemaphore sem;
 #endif
     int thread_id;
     bool running, has_waiter;
diff --git a/accel/dummy-cpus.c b/accel/dummy-cpus.c
index 10429fdfb2..d6a1b8d0a2 100644
--- a/accel/dummy-cpus.c
+++ b/accel/dummy-cpus.c
@@ -21,8 +21,6 @@ 
 static void *dummy_cpu_thread_fn(void *arg)
 {
     CPUState *cpu = arg;
-    sigset_t waitset;
-    int r;
 
     rcu_register_thread();
 
@@ -32,8 +30,13 @@  static void *dummy_cpu_thread_fn(void *arg)
     cpu->can_do_io = 1;
     current_cpu = cpu;
 
+#ifndef _WIN32
+    sigset_t waitset;
+    int r;
+
     sigemptyset(&waitset);
     sigaddset(&waitset, SIG_IPI);
+#endif
 
     /* signal CPU creation */
     cpu_thread_signal_created(cpu);
@@ -41,6 +44,7 @@  static void *dummy_cpu_thread_fn(void *arg)
 
     do {
         qemu_mutex_unlock_iothread();
+#ifndef _WIN32
         do {
             int sig;
             r = sigwait(&waitset, &sig);
@@ -49,6 +53,9 @@  static void *dummy_cpu_thread_fn(void *arg)
             perror("sigwait");
             exit(1);
         }
+#else
+        qemu_sem_wait(&cpu->sem);
+#endif
         qemu_mutex_lock_iothread();
         qemu_wait_io_event(cpu);
     } while (!cpu->unplug);
@@ -69,4 +76,7 @@  void dummy_start_vcpu_thread(CPUState *cpu)
              cpu->cpu_index);
     qemu_thread_create(cpu->thread, thread_name, dummy_cpu_thread_fn, cpu,
                        QEMU_THREAD_JOINABLE);
+#ifdef _WIN32
+    qemu_sem_init(&cpu->sem, 0);
+#endif
 }
diff --git a/softmmu/cpus.c b/softmmu/cpus.c
index 23b30484b2..fd10db927a 100644
--- a/softmmu/cpus.c
+++ b/softmmu/cpus.c
@@ -437,18 +437,19 @@  void qemu_wait_io_event(CPUState *cpu)
 
 void cpus_kick_thread(CPUState *cpu)
 {
-#ifndef _WIN32
-    int err;
-
     if (cpu->thread_kicked) {
         return;
     }
     cpu->thread_kicked = true;
-    err = pthread_kill(cpu->thread->thread, SIG_IPI);
+
+#ifndef _WIN32
+    int err = pthread_kill(cpu->thread->thread, SIG_IPI);
     if (err && err != ESRCH) {
         fprintf(stderr, "qemu:%s: %s", __func__, strerror(err));
         exit(1);
     }
+#else
+    qemu_sem_post(&cpu->sem);
 #endif
 }
 
diff --git a/accel/meson.build b/accel/meson.build
index b9a963cf80..b21c85dc0a 100644
--- a/accel/meson.build
+++ b/accel/meson.build
@@ -17,4 +17,5 @@  dummy_ss.add(files(
 ))
 
 specific_ss.add_all(when: ['CONFIG_SOFTMMU', 'CONFIG_POSIX'], if_true: dummy_ss)
+specific_ss.add_all(when: ['CONFIG_WIN32'], if_true: dummy_ss)
 specific_ss.add_all(when: ['CONFIG_XEN'], if_true: dummy_ss)
diff --git a/accel/qtest/meson.build b/accel/qtest/meson.build
index 4c65600293..a4876fc0f2 100644
--- a/accel/qtest/meson.build
+++ b/accel/qtest/meson.build
@@ -1,2 +1,3 @@ 
 qtest_module_ss.add(when: ['CONFIG_SOFTMMU', 'CONFIG_POSIX'],
                     if_true: files('qtest.c'))
+qtest_module_ss.add(when: ['CONFIG_WIN32'], if_true: files('qtest.c'))