diff mbox

[21/21] add Win32 IPI service

Message ID 1298277820-8817-22-git-send-email-pbonzini@redhat.com
State New
Headers show

Commit Message

Paolo Bonzini Feb. 21, 2011, 8:43 a.m. UTC
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 cpus.c              |   23 ++++++++++++++++++++---
 qemu-thread-posix.c |    9 ---------
 qemu-thread-posix.h |    1 -
 3 files changed, 20 insertions(+), 13 deletions(-)

Comments

Jan Kiszka Feb. 21, 2011, noon UTC | #1
On 2011-02-21 09:43, Paolo Bonzini wrote:
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  cpus.c              |   23 ++++++++++++++++++++---
>  qemu-thread-posix.c |    9 ---------
>  qemu-thread-posix.h |    1 -
>  3 files changed, 20 insertions(+), 13 deletions(-)
> 
> diff --git a/cpus.c b/cpus.c
> index fd791a3..869ed1a 100644
> --- a/cpus.c
> +++ b/cpus.c
> @@ -854,13 +854,30 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)
>      return NULL;
>  }
>  
> +static void qemu_thread_kick(QemuThread *thread)
> +{
> +#ifndef _WIN32
> +    int err;
> +
> +    err = pthread_kill(thread->thread, SIG_IPI);
> +    if (err) {
> +        fprintf(stderr, "qemu:%s: %s", __func__, strerror(err));
> +        exit(1);
> +    }
> +#else /* _WIN32 */
> +    SuspendThread(thread->thread);
> +    cpu_signal(0);
> +    ResumeThread(thread->thread);
> +#endif
> +}
> +

qemu_thread_* services do not truly belong here.

What about defining SIG_IPI as QEMU_SIG_KICK which would be provided by
qemu-thread-posix.h? Then the qemu-thread-posix.c could implement
qemu_thread_kick() again.

>  void qemu_cpu_kick(void *_env)
>  {
>      CPUState *env = _env;
>  
>      qemu_cond_broadcast(env->halt_cond);
>      if (!env->thread_kicked) {
> -        qemu_thread_signal(env->thread, SIG_IPI);
> +        qemu_thread_kick(env->thread);
>          env->thread_kicked = true;
>      }
>  }
> @@ -871,7 +888,7 @@ void qemu_cpu_kick_self(void)
>      assert(cpu_single_env);
>  
>      if (!cpu_single_env->thread_kicked) {
> -        qemu_thread_signal(cpu_single_env->thread, SIG_IPI);
> +        qemu_thread_kick(cpu_single_env->thread);
>          cpu_single_env->thread_kicked = true;
>      }
>  #else
> @@ -893,7 +910,7 @@ void qemu_mutex_lock_iothread(void)
>      } else {
>          qemu_mutex_lock(&qemu_fair_mutex);
>          if (qemu_mutex_trylock(&qemu_global_mutex)) {
> -            qemu_thread_signal(tcg_cpu_thread, SIG_IPI);
> +            qemu_thread_kick(tcg_cpu_thread);
>              qemu_mutex_lock(&qemu_global_mutex);
>          }
>          qemu_mutex_unlock(&qemu_fair_mutex);
> diff --git a/qemu-thread-posix.c b/qemu-thread-posix.c
> index 2176f81..5fdf16b 100644
> --- a/qemu-thread-posix.c
> +++ b/qemu-thread-posix.c
> @@ -190,15 +190,6 @@ void qemu_thread_create(QemuThread *thread,
>      pthread_sigmask(SIG_SETMASK, &oldset, NULL);
>  }
>  
> -void qemu_thread_signal(QemuThread *thread, int sig)
> -{
> -    int err;
> -
> -    err = pthread_kill(thread->thread, sig);
> -    if (err)
> -        error_exit(err, __func__);
> -}
> -
>  void qemu_thread_self(QemuThread *thread)
>  {
>      thread->thread = pthread_self();
> diff --git a/qemu-thread-posix.h b/qemu-thread-posix.h
> index 11978db..35e0a8b 100644
> --- a/qemu-thread-posix.h
> +++ b/qemu-thread-posix.h
> @@ -15,5 +15,4 @@ struct QemuThread {
>      pthread_t thread;
>  };
>  
> -void qemu_thread_signal(QemuThread *thread, int sig);
>  #endif

Jan
Paolo Bonzini Feb. 21, 2011, 12:15 p.m. UTC | #2
On 02/21/2011 01:00 PM, Jan Kiszka wrote:
> qemu_thread_* services do not truly belong here.
>
> What about defining SIG_IPI as QEMU_SIG_KICK which would be provided by
> qemu-thread-posix.h? Then the qemu-thread-posix.c could implement
> qemu_thread_kick() again.

The function is really specific to VCPU threads.  It is simply a wrapper 
for the common bit of qemu_kick_vcpu and qemu_mutex_lock_iothread.  I'll 
rename it to qemu_cpu_kick_thread and make it accept a CPUState.

Paolo
Jan Kiszka Feb. 21, 2011, 12:25 p.m. UTC | #3
On 2011-02-21 13:15, Paolo Bonzini wrote:
> On 02/21/2011 01:00 PM, Jan Kiszka wrote:
>> qemu_thread_* services do not truly belong here.
>>
>> What about defining SIG_IPI as QEMU_SIG_KICK which would be provided by
>> qemu-thread-posix.h? Then the qemu-thread-posix.c could implement
>> qemu_thread_kick() again.
> 
> The function is really specific to VCPU threads.  It is simply a wrapper 
> for the common bit of qemu_kick_vcpu and qemu_mutex_lock_iothread.  I'll 
> rename it to qemu_cpu_kick_thread and make it accept a CPUState.

...or that way. We should just try to respect the abstraction layers.

Jan
diff mbox

Patch

diff --git a/cpus.c b/cpus.c
index fd791a3..869ed1a 100644
--- a/cpus.c
+++ b/cpus.c
@@ -854,13 +854,30 @@  static void *qemu_tcg_cpu_thread_fn(void *arg)
     return NULL;
 }
 
+static void qemu_thread_kick(QemuThread *thread)
+{
+#ifndef _WIN32
+    int err;
+
+    err = pthread_kill(thread->thread, SIG_IPI);
+    if (err) {
+        fprintf(stderr, "qemu:%s: %s", __func__, strerror(err));
+        exit(1);
+    }
+#else /* _WIN32 */
+    SuspendThread(thread->thread);
+    cpu_signal(0);
+    ResumeThread(thread->thread);
+#endif
+}
+
 void qemu_cpu_kick(void *_env)
 {
     CPUState *env = _env;
 
     qemu_cond_broadcast(env->halt_cond);
     if (!env->thread_kicked) {
-        qemu_thread_signal(env->thread, SIG_IPI);
+        qemu_thread_kick(env->thread);
         env->thread_kicked = true;
     }
 }
@@ -871,7 +888,7 @@  void qemu_cpu_kick_self(void)
     assert(cpu_single_env);
 
     if (!cpu_single_env->thread_kicked) {
-        qemu_thread_signal(cpu_single_env->thread, SIG_IPI);
+        qemu_thread_kick(cpu_single_env->thread);
         cpu_single_env->thread_kicked = true;
     }
 #else
@@ -893,7 +910,7 @@  void qemu_mutex_lock_iothread(void)
     } else {
         qemu_mutex_lock(&qemu_fair_mutex);
         if (qemu_mutex_trylock(&qemu_global_mutex)) {
-            qemu_thread_signal(tcg_cpu_thread, SIG_IPI);
+            qemu_thread_kick(tcg_cpu_thread);
             qemu_mutex_lock(&qemu_global_mutex);
         }
         qemu_mutex_unlock(&qemu_fair_mutex);
diff --git a/qemu-thread-posix.c b/qemu-thread-posix.c
index 2176f81..5fdf16b 100644
--- a/qemu-thread-posix.c
+++ b/qemu-thread-posix.c
@@ -190,15 +190,6 @@  void qemu_thread_create(QemuThread *thread,
     pthread_sigmask(SIG_SETMASK, &oldset, NULL);
 }
 
-void qemu_thread_signal(QemuThread *thread, int sig)
-{
-    int err;
-
-    err = pthread_kill(thread->thread, sig);
-    if (err)
-        error_exit(err, __func__);
-}
-
 void qemu_thread_self(QemuThread *thread)
 {
     thread->thread = pthread_self();
diff --git a/qemu-thread-posix.h b/qemu-thread-posix.h
index 11978db..35e0a8b 100644
--- a/qemu-thread-posix.h
+++ b/qemu-thread-posix.h
@@ -15,5 +15,4 @@  struct QemuThread {
     pthread_t thread;
 };
 
-void qemu_thread_signal(QemuThread *thread, int sig);
 #endif