From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jan Kiszka Subject: [PATCH] qemu-kvm: Consolidate kvm_eat_signal v2 Date: Fri, 16 May 2008 09:21:47 +0200 Message-ID: <482D360B.70904@web.de> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: Avi Kivity To: kvm-devel Return-path: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: kvm-devel-bounces@lists.sourceforge.net Errors-To: kvm-devel-bounces@lists.sourceforge.net List-Id: kvm.vger.kernel.org Here comes the second revision of the attempt to consolidate kvm_eat_signal[s]. It follows the suggestions to remove looping over kvm_eat_signal and folds everything into kvm_main_loop_wait. Signed-off-by: Jan Kiszka --- qemu/qemu-kvm.c | 43 ++++++++----------------------------------- 1 file changed, 8 insertions(+), 35 deletions(-) Index: b/qemu/qemu-kvm.c =================================================================== --- a/qemu/qemu-kvm.c +++ b/qemu/qemu-kvm.c @@ -173,64 +173,37 @@ static int has_work(CPUState *env) return kvm_arch_has_work(env); } -static int kvm_eat_signal(CPUState *env, int timeout) +static void kvm_main_loop_wait(CPUState *env, int timeout) { struct timespec ts; - int r, e, ret = 0; + int r, e; siginfo_t siginfo; sigset_t waitset; + pthread_mutex_unlock(&qemu_mutex); + ts.tv_sec = timeout / 1000; ts.tv_nsec = (timeout % 1000) * 1000000; sigemptyset(&waitset); sigaddset(&waitset, SIG_IPI); r = sigtimedwait(&waitset, &siginfo, &ts); - if (r == -1 && (errno == EAGAIN || errno == EINTR) && !timeout) - return 0; e = errno; pthread_mutex_lock(&qemu_mutex); - if (env && vcpu) - cpu_single_env = vcpu->env; - if (r == -1 && !(errno == EAGAIN || errno == EINTR)) { + + if (r == -1 && !(e == EAGAIN || e == EINTR)) { printf("sigtimedwait: %s\n", strerror(e)); exit(1); } - if (r != -1) - ret = 1; - if (env && vcpu_info[env->cpu_index].stop) { + if (vcpu_info[env->cpu_index].stop) { vcpu_info[env->cpu_index].stop = 0; vcpu_info[env->cpu_index].stopped = 1; pthread_cond_signal(&qemu_pause_cond); } - pthread_mutex_unlock(&qemu_mutex); - - return ret; -} - - -static void kvm_eat_signals(CPUState *env, int timeout) -{ - int r = 0; - - while (kvm_eat_signal(env, 0)) - r = 1; - if (!r && timeout) { - r = kvm_eat_signal(env, timeout); - if (r) - while (kvm_eat_signal(env, 0)) - ; - } -} - -static void kvm_main_loop_wait(CPUState *env, int timeout) -{ - pthread_mutex_unlock(&qemu_mutex); - kvm_eat_signals(env, timeout); - pthread_mutex_lock(&qemu_mutex); cpu_single_env = env; + vcpu_info[env->cpu_index].signalled = 0; } ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/