Patchwork [06/18] kvm: Refactor qemu_kvm_eat_signals

login
register
mail settings
Submitter Jan Kiszka
Date Jan. 10, 2011, 8:31 a.m.
Message ID <8630ac717d7c3fefaf091b70feaf17e63c411c26.1294648329.git.jan.kiszka@web.de>
Download mbox | patch
Permalink /patch/78092/
State New
Headers show

Comments

Jan Kiszka - Jan. 10, 2011, 8:31 a.m.
From: Jan Kiszka <jan.kiszka@siemens.com>

We do not use the timeout, so drop its logic. As we always poll our
signals, we do not need to drop the global lock. Removing those calls
allows some further simplifications. Also fix the error processing of
sigpending at this chance.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 cpus.c |   23 +++++++----------------
 1 files changed, 7 insertions(+), 16 deletions(-)
Paolo Bonzini - Jan. 10, 2011, 10:15 a.m.
On 01/10/2011 09:31 AM, Jan Kiszka wrote:
> From: Jan Kiszka<jan.kiszka@siemens.com>
>
> We do not use the timeout, so drop its logic. As we always poll our
> signals, we do not need to drop the global lock. Removing those calls
> allows some further simplifications. Also fix the error processing of
> sigpending at this chance.
>
> Signed-off-by: Jan Kiszka<jan.kiszka@siemens.com>
> ---
>   cpus.c |   23 +++++++----------------
>   1 files changed, 7 insertions(+), 16 deletions(-)
>
> diff --git a/cpus.c b/cpus.c
> index bf0fb85..6da0f8f 100644
> --- a/cpus.c
> +++ b/cpus.c
> @@ -617,31 +617,22 @@ static void sigbus_handler(int n, struct qemu_signalfd_siginfo *siginfo,
>       }
>   }
>
> -static void qemu_kvm_eat_signal(CPUState *env, int timeout)
> +static void qemu_kvm_eat_signals(CPUState *env)
>   {
> -    struct timespec ts;
> -    int r, e;
> +    struct timespec ts = { 0, 0 };
>       siginfo_t siginfo;
>       sigset_t waitset;
>       sigset_t chkset;
> -
> -    ts.tv_sec = timeout / 1000;
> -    ts.tv_nsec = (timeout % 1000) * 1000000;
> +    int r;
>
>       sigemptyset(&waitset);
>       sigaddset(&waitset, SIG_IPI);
>       sigaddset(&waitset, SIGBUS);
>
>       do {
> -        qemu_mutex_unlock(&qemu_global_mutex);
> -
>           r = sigtimedwait(&waitset,&siginfo,&ts);
> -        e = errno;
> -
> -        qemu_mutex_lock(&qemu_global_mutex);
> -
> -        if (r == -1&&  !(e == EAGAIN || e == EINTR)) {
> -            fprintf(stderr, "sigtimedwait: %s\n", strerror(e));
> +        if (r == -1&&  !(errno == EAGAIN || errno == EINTR)) {
> +            perror("sigtimedwait");
>               exit(1);
>           }
>
> @@ -657,7 +648,7 @@ static void qemu_kvm_eat_signal(CPUState *env, int timeout)
>
>           r = sigpending(&chkset);
>           if (r == -1) {
> -            fprintf(stderr, "sigpending: %s\n", strerror(e));
> +            perror("sigpending");
>               exit(1);
>           }
>       } while (sigismember(&chkset, SIG_IPI) || sigismember(&chkset, SIGBUS));
> @@ -668,7 +659,7 @@ static void qemu_kvm_wait_io_event(CPUState *env)
>       while (!cpu_has_work(env))
>           qemu_cond_timedwait(env->halt_cond,&qemu_global_mutex, 1000);
>
> -    qemu_kvm_eat_signal(env, 0);
> +    qemu_kvm_eat_signals(env);
>       qemu_wait_io_event_common(env);
>   }
>

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

Paolo

Patch

diff --git a/cpus.c b/cpus.c
index bf0fb85..6da0f8f 100644
--- a/cpus.c
+++ b/cpus.c
@@ -617,31 +617,22 @@  static void sigbus_handler(int n, struct qemu_signalfd_siginfo *siginfo,
     }
 }
 
-static void qemu_kvm_eat_signal(CPUState *env, int timeout)
+static void qemu_kvm_eat_signals(CPUState *env)
 {
-    struct timespec ts;
-    int r, e;
+    struct timespec ts = { 0, 0 };
     siginfo_t siginfo;
     sigset_t waitset;
     sigset_t chkset;
-
-    ts.tv_sec = timeout / 1000;
-    ts.tv_nsec = (timeout % 1000) * 1000000;
+    int r;
 
     sigemptyset(&waitset);
     sigaddset(&waitset, SIG_IPI);
     sigaddset(&waitset, SIGBUS);
 
     do {
-        qemu_mutex_unlock(&qemu_global_mutex);
-
         r = sigtimedwait(&waitset, &siginfo, &ts);
-        e = errno;
-
-        qemu_mutex_lock(&qemu_global_mutex);
-
-        if (r == -1 && !(e == EAGAIN || e == EINTR)) {
-            fprintf(stderr, "sigtimedwait: %s\n", strerror(e));
+        if (r == -1 && !(errno == EAGAIN || errno == EINTR)) {
+            perror("sigtimedwait");
             exit(1);
         }
 
@@ -657,7 +648,7 @@  static void qemu_kvm_eat_signal(CPUState *env, int timeout)
 
         r = sigpending(&chkset);
         if (r == -1) {
-            fprintf(stderr, "sigpending: %s\n", strerror(e));
+            perror("sigpending");
             exit(1);
         }
     } while (sigismember(&chkset, SIG_IPI) || sigismember(&chkset, SIGBUS));
@@ -668,7 +659,7 @@  static void qemu_kvm_wait_io_event(CPUState *env)
     while (!cpu_has_work(env))
         qemu_cond_timedwait(env->halt_cond, &qemu_global_mutex, 1000);
 
-    qemu_kvm_eat_signal(env, 0);
+    qemu_kvm_eat_signals(env);
     qemu_wait_io_event_common(env);
 }