From patchwork Thu Jun 3 13:20:32 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 54483 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 88E1DB7D1F for ; Thu, 3 Jun 2010 23:22:29 +1000 (EST) Received: from localhost ([127.0.0.1]:33936 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OKANN-0005sF-Jz for incoming@patchwork.ozlabs.org; Thu, 03 Jun 2010 09:22:25 -0400 Received: from [140.186.70.92] (port=52061 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OKALi-0005lI-Az for qemu-devel@nongnu.org; Thu, 03 Jun 2010 09:20:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OKALg-00019C-U3 for qemu-devel@nongnu.org; Thu, 03 Jun 2010 09:20:42 -0400 Received: from mail-ww0-f45.google.com ([74.125.82.45]:39474) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OKALg-000194-L5 for qemu-devel@nongnu.org; Thu, 03 Jun 2010 09:20:40 -0400 Received: by wwb13 with SMTP id 13so69152wwb.4 for ; Thu, 03 Jun 2010 06:20:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:from:to:cc:subject :date:message-id:x-mailer; bh=2TmSQh3awYHAiACbBpUAPs7uHeDgIXw+wEwpYkdpppI=; b=bbvWD2l+HgcinVd9qyD9YdPNFEgT1FfgClSMMABjxJuzEPu1x8Pl+l2uvM3TNhbCij Y+cr9RDobnBH1hEnT97rOj50LX3/a4gvhNhix5DXlGtZoqgRMFIh+U2aStPVKRqW2TsL s6nzUbmiBwElJVxH1aENnAcNgxzJ/L3H9/RcY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:date:message-id:x-mailer; b=KS4uJ0g7Dxj4C47lz42eflqAsCYouJrEq9J7QIGHoqr/yqSB1Z5Wpnt3EyjGxYQMN8 zyjjagn1bOF2S3U2mxR6tjUasC3hlLj+9850zGvcSTrPfRKDaqf427jnuknCSddNP24v aBDTPRzwQ0gmpH7mVD+GsjlbXgpHfahz7X0oM= Received: by 10.227.134.131 with SMTP id j3mr264009wbt.28.1275571239685; Thu, 03 Jun 2010 06:20:39 -0700 (PDT) Received: from localhost.localdomain ([209.132.186.34]) by mx.google.com with ESMTPS id l23sm920843wbb.2.2010.06.03.06.20.37 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 03 Jun 2010 06:20:38 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 3 Jun 2010 15:20:32 +0200 Message-Id: <1275571232-26486-1-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.0.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Cc: ego@in.ibm.com Subject: [Qemu-devel] [PATCH] make qemu_thread_create block all signals 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 All signals will thus be routed through the IO thread. Signed-off-by: Paolo Bonzini Acked-by: Richard Henderson --- cpus.c | 38 +++++++++++--------------------------- qemu-thread.c | 7 +++++++ 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/cpus.c b/cpus.c index 8341f6c..fcd0f09 100644 --- a/cpus.c +++ b/cpus.c @@ -318,8 +318,8 @@ static QemuCond qemu_system_cond; static QemuCond qemu_pause_cond; static QemuCond qemu_work_cond; -static void tcg_block_io_signals(void); -static void kvm_block_io_signals(CPUState *env); +static void tcg_init_ipi(void); +static void kvm_init_ipi(CPUState *env); static void unblock_io_signals(void); int qemu_init_main_loop(void) @@ -464,7 +464,7 @@ static void *kvm_cpu_thread_fn(void *arg) if (kvm_enabled()) kvm_init_vcpu(env); - kvm_block_io_signals(env); + kvm_init_ipi(env); /* signal CPU creation */ env->created = 1; @@ -487,7 +487,7 @@ static void *tcg_cpu_thread_fn(void *arg) { CPUState *env = arg; - tcg_block_io_signals(); + tcg_init_ipi(); qemu_thread_self(env->thread); /* signal CPU creation */ @@ -532,52 +532,36 @@ static void cpu_signal(int sig) exit_request = 1; } -static void tcg_block_io_signals(void) +static void tcg_init_ipi(void) { sigset_t set; struct sigaction sigact; - sigemptyset(&set); - sigaddset(&set, SIGUSR2); - sigaddset(&set, SIGIO); - sigaddset(&set, SIGALRM); - sigaddset(&set, SIGCHLD); - pthread_sigmask(SIG_BLOCK, &set, NULL); + memset(&sigact, 0, sizeof(sigact)); + sigact.sa_handler = cpu_signal; + sigaction(SIG_IPI, &sigact, NULL); sigemptyset(&set); sigaddset(&set, SIG_IPI); pthread_sigmask(SIG_UNBLOCK, &set, NULL); - - memset(&sigact, 0, sizeof(sigact)); - sigact.sa_handler = cpu_signal; - sigaction(SIG_IPI, &sigact, NULL); } static void dummy_signal(int sig) { } -static void kvm_block_io_signals(CPUState *env) +static void kvm_init_ipi(CPUState *env) { int r; sigset_t set; struct sigaction sigact; - sigemptyset(&set); - sigaddset(&set, SIGUSR2); - sigaddset(&set, SIGIO); - sigaddset(&set, SIGALRM); - sigaddset(&set, SIGCHLD); - sigaddset(&set, SIG_IPI); - pthread_sigmask(SIG_BLOCK, &set, NULL); - - pthread_sigmask(SIG_BLOCK, NULL, &set); - sigdelset(&set, SIG_IPI); - memset(&sigact, 0, sizeof(sigact)); sigact.sa_handler = dummy_signal; sigaction(SIG_IPI, &sigact, NULL); + pthread_sigmask(SIG_BLOCK, NULL, &set); + sigdelset(&set, SIG_IPI); r = kvm_set_signal_mask(env, &set); if (r) { fprintf(stderr, "kvm_set_signal_mask: %s\n", strerror(r)); diff --git a/qemu-thread.c b/qemu-thread.c index 3923db7..faf4061 100644 --- a/qemu-thread.c +++ b/qemu-thread.c @@ -137,9 +137,16 @@ void qemu_thread_create(QemuThread *thread, { int err; + /* Leave signal handling to the iothread. */ + sigset_t set, oldset; + + sigfillset(&set); + pthread_sigmask(SIG_SETMASK, &set, &oldset); err = pthread_create(&thread->thread, NULL, start_routine, arg); if (err) error_exit(err, __func__); + + pthread_sigmask(SIG_SETMASK, &oldset, NULL); } void qemu_thread_signal(QemuThread *thread, int sig)