From patchwork Tue May 4 12:45:20 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 51609 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 6681FB6ED0 for ; Wed, 5 May 2010 00:01:44 +1000 (EST) Received: from localhost ([127.0.0.1]:48734 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O9Icq-0006Xe-9P for incoming@patchwork.ozlabs.org; Tue, 04 May 2010 09:57:28 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O9IVe-00027Z-EN for qemu-devel@nongnu.org; Tue, 04 May 2010 09:50:02 -0400 Received: from [140.186.70.92] (port=53044 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O9IVc-000242-Hr for qemu-devel@nongnu.org; Tue, 04 May 2010 09:50:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O9IVW-00045B-3p for qemu-devel@nongnu.org; Tue, 04 May 2010 09:50:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:13815) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O9IVV-00044o-S3 for qemu-devel@nongnu.org; Tue, 04 May 2010 09:49:54 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o44Dnq8J019847 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 4 May 2010 09:49:53 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o44DbLmk000317; Tue, 4 May 2010 09:49:51 -0400 Received: from amt.cnet (vpn2-10-150.ams2.redhat.com [10.36.10.150]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id o44CwSmX023282; Tue, 4 May 2010 09:00:13 -0400 Received: from amt.cnet (amt.cnet [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 866F068A98D; Tue, 4 May 2010 09:54:52 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.3/8.14.3/Submit) id o44Cso90016559; Tue, 4 May 2010 09:54:50 -0300 Message-Id: <20100504124634.221277834@redhat.com> User-Agent: quilt/0.47-1 Date: Tue, 04 May 2010 09:45:20 -0300 From: Marcelo Tosatti To: kvm@vger.kernel.org, qemu-devel@nongnu.org References: <20100504124518.979470863@redhat.com> Content-Disposition: inline; filename=qemu-remove-signal-lock X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Marcelo Tosatti Subject: [Qemu-devel] [patch uq/master 2/9] make SIG_IPI to tcg vcpu thread reliable 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 Store tcg loop exit request on a global variable, and transfer it to per-CPUState exit_request after assignment of cpu_single_env. This makes exit request signal from robust. Drop the timedlock hack. Signed-off-by: Marcelo Tosatti Index: qemu/cpu-exec.c =================================================================== --- qemu.orig/cpu-exec.c +++ qemu/cpu-exec.c @@ -213,6 +213,8 @@ static void cpu_handle_debug_exception(C /* main execution loop */ +volatile sig_atomic_t exit_request; + int cpu_exec(CPUState *env1) { volatile host_reg_t saved_env_reg; @@ -234,6 +236,11 @@ int cpu_exec(CPUState *env1) asm(""); env = env1; + if (exit_request) { + env->exit_request = 1; + exit_request = 0; + } + #if defined(TARGET_I386) if (!kvm_enabled()) { /* put eflags in CPU temporary format */ Index: qemu/cpus.c =================================================================== --- qemu.orig/cpus.c +++ qemu/cpus.c @@ -472,6 +472,7 @@ static void cpu_signal(int sig) { if (cpu_single_env) cpu_exit(cpu_single_env); + exit_request = 1; } static void tcg_block_io_signals(void) @@ -542,26 +543,20 @@ static void unblock_io_signals(void) pthread_sigmask(SIG_BLOCK, &set, NULL); } -static void qemu_signal_lock(unsigned int msecs) -{ - qemu_mutex_lock(&qemu_fair_mutex); - - while (qemu_mutex_trylock(&qemu_global_mutex)) { - qemu_thread_signal(tcg_cpu_thread, SIG_IPI); - if (!qemu_mutex_timedlock(&qemu_global_mutex, msecs)) - break; - } - qemu_mutex_unlock(&qemu_fair_mutex); -} - void qemu_mutex_lock_iothread(void) { if (kvm_enabled()) { qemu_mutex_lock(&qemu_fair_mutex); qemu_mutex_lock(&qemu_global_mutex); qemu_mutex_unlock(&qemu_fair_mutex); - } else - qemu_signal_lock(100); + } else { + qemu_mutex_lock(&qemu_fair_mutex); + if (qemu_mutex_trylock(&qemu_global_mutex)) { + qemu_thread_signal(tcg_cpu_thread, SIG_IPI); + qemu_mutex_lock(&qemu_global_mutex); + } + qemu_mutex_unlock(&qemu_fair_mutex); + } } void qemu_mutex_unlock_iothread(void) Index: qemu/exec-all.h =================================================================== --- qemu.orig/exec-all.h +++ qemu/exec-all.h @@ -339,4 +339,7 @@ CPUDebugExcpHandler *cpu_set_debug_excp_ /* vl.c */ extern int singlestep; +/* cpu-exec.c */ +extern volatile sig_atomic_t exit_request; + #endif