From patchwork Sun Apr 18 21:10:17 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 50421 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 68233B6F11 for ; Mon, 19 Apr 2010 07:11:05 +1000 (EST) Received: from localhost ([127.0.0.1]:40935 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O3ble-00086s-0K for incoming@patchwork.ozlabs.org; Sun, 18 Apr 2010 17:11:02 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O3bl2-000858-GE for qemu-devel@nongnu.org; Sun, 18 Apr 2010 17:10:24 -0400 Received: from [140.186.70.92] (port=42546 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O3bl1-000848-4z for qemu-devel@nongnu.org; Sun, 18 Apr 2010 17:10:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O3bkz-0000Qb-40 for qemu-devel@nongnu.org; Sun, 18 Apr 2010 17:10:23 -0400 Received: from cantor.suse.de ([195.135.220.2]:38271 helo=mx1.suse.de) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O3bky-0000QF-Ps for qemu-devel@nongnu.org; Sun, 18 Apr 2010 17:10:21 -0400 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.221.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.suse.de (Postfix) with ESMTP id 104D38E8CC; Sun, 18 Apr 2010 23:10:18 +0200 (CEST) From: Alexander Graf To: qemu-devel Developers Date: Sun, 18 Apr 2010 23:10:17 +0200 Message-Id: <1271625017-4946-1-git-send-email-agraf@suse.de> X-Mailer: git-send-email 1.6.0.2 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 Cc: Aurelien Jarno Subject: [Qemu-devel] [PATCH] [PPC] [KVM] Make iothread work X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org When running with --enable-io-thread the timer we have doesn't help, because it doesn't wake up the CPU thread. So instead we need to actually kick it. While at it I refined the logic a bit to not dumbly trigger a timer every 500ms, but rather do it more often after an interrupt got injected. If there's no level based interrupt to be expected, we don't need the timer anyways. This makes qemu-system-ppc with --enable-io-thread work when using KVM. Signed-off-by: Alexander Graf --- target-ppc/kvm.c | 30 +++++++++++++++--------------- 1 files changed, 15 insertions(+), 15 deletions(-) diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c index aa3d432..6e7a023 100644 --- a/target-ppc/kvm.c +++ b/target-ppc/kvm.c @@ -37,20 +37,20 @@ do { } while (0) #endif -/* XXX For some odd reason we sometimes hang inside KVM forever. I'd guess it's - * a race condition where we actually have a level triggered interrupt, but - * the infrastructure can't expose that yet, so the guest ACKs it, goes to - * sleep and never gets notified that there's still an interrupt pending. +/* XXX We have a race condition where we actually have a level triggered + * interrupt, but the infrastructure can't expose that yet, so the guest + * takes but ignores it, goes to sleep and never gets notified that there's + * still an interrupt pending. * - * As a quick workaround, let's just wake up every 500 ms. That way we can - * assure that we're always reinjecting interrupts in time. + * As a quick workaround, let's just wake up again 20 ms after we injected + * an interrupt. That way we can assure that we're always reinjecting + * interrupts in case the guest swallowed them. */ static QEMUTimer *idle_timer; -static void do_nothing(void *opaque) +static void kvm_kick_env(void *env) { - qemu_mod_timer(idle_timer, qemu_get_clock(vm_clock) + - (get_ticks_per_sec() / 2)); + qemu_cpu_kick(env); } int kvm_arch_init(KVMState *s, int smp_cpus) @@ -66,6 +66,8 @@ int kvm_arch_init_vcpu(CPUState *cenv) sregs.pvr = cenv->spr[SPR_PVR]; ret = kvm_vcpu_ioctl(cenv, KVM_SET_SREGS, &sregs); + idle_timer = qemu_new_timer(vm_clock, kvm_kick_env, cenv); + return ret; } @@ -189,12 +191,6 @@ int kvm_arch_pre_run(CPUState *env, struct kvm_run *run) int r; unsigned irq; - if (!idle_timer) { - idle_timer = qemu_new_timer(vm_clock, do_nothing, NULL); - qemu_mod_timer(idle_timer, qemu_get_clock(vm_clock) + - (get_ticks_per_sec() / 2)); - } - /* PowerPC Qemu tracks the various core input pins (interrupt, critical * interrupt, reset, etc) in PPC-specific env->irq_input_state. */ if (run->ready_for_interrupt_injection && @@ -211,6 +207,10 @@ int kvm_arch_pre_run(CPUState *env, struct kvm_run *run) r = kvm_vcpu_ioctl(env, KVM_INTERRUPT, &irq); if (r < 0) printf("cpu %d fail inject %x\n", env->cpu_index, irq); + + /* Always wake up soon in case the interrupt was level based */ + qemu_mod_timer(idle_timer, qemu_get_clock(vm_clock) + + (get_ticks_per_sec() / 50)); } /* We don't know if there are more interrupts pending after this. However,