From patchwork Fri Oct 16 12:38:52 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulrich Hecht X-Patchwork-Id: 36203 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 DDBF2B7BC7 for ; Fri, 16 Oct 2009 23:46:17 +1100 (EST) Received: from localhost ([127.0.0.1]:37714 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MymCD-0007jV-Qy for incoming@patchwork.ozlabs.org; Fri, 16 Oct 2009 08:46:13 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mym5S-0005Cd-F8 for qemu-devel@nongnu.org; Fri, 16 Oct 2009 08:39:14 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mym5L-0005AQ-TG for qemu-devel@nongnu.org; Fri, 16 Oct 2009 08:39:12 -0400 Received: from [199.232.76.173] (port=37641 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mym5L-00059z-5h for qemu-devel@nongnu.org; Fri, 16 Oct 2009 08:39:07 -0400 Received: from cantor2.suse.de ([195.135.220.15]:36677 helo=mx2.suse.de) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Mym5J-0005ib-GI for qemu-devel@nongnu.org; Fri, 16 Oct 2009 08:39:06 -0400 Received: from relay1.suse.de (relay-ext.suse.de [195.135.221.8]) by mx2.suse.de (Postfix) with ESMTP id B9FEA867E2; Fri, 16 Oct 2009 14:39:02 +0200 (CEST) From: Ulrich Hecht To: qemu-devel@nongnu.org Date: Fri, 16 Oct 2009 14:38:52 +0200 Message-Id: <1255696735-21396-7-git-send-email-uli@suse.de> X-Mailer: git-send-email 1.6.2.1 In-Reply-To: <1255696735-21396-6-git-send-email-uli@suse.de> References: <1255696735-21396-1-git-send-email-uli@suse.de> <1255696735-21396-2-git-send-email-uli@suse.de> <1255696735-21396-3-git-send-email-uli@suse.de> <1255696735-21396-4-git-send-email-uli@suse.de> <1255696735-21396-5-git-send-email-uli@suse.de> <1255696735-21396-6-git-send-email-uli@suse.de> X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.4-2.6 Cc: riku.voipio@iki.fi, agraf@suse.de Subject: [Qemu-devel] [PATCH 6/9] linux-user: don't do locking in single-threaded processes 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 Skips setting the tb_lock if a process doesn't have more than one thread, which is usually the case. Results in about 20% performance gain (measured with the s390x target, but the effect should be similar with other targets). Signed-off-by: Ulrich Hecht --- cpu-defs.h | 8 ++++++++ cpu-exec.c | 14 ++++++++++++-- linux-user/syscall.c | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/cpu-defs.h b/cpu-defs.h index 95068b5..c50c59e 100644 --- a/cpu-defs.h +++ b/cpu-defs.h @@ -135,6 +135,13 @@ typedef struct CPUWatchpoint { } CPUWatchpoint; #define CPU_TEMP_BUF_NLONGS 128 + +#ifdef CONFIG_USER_ONLY +#define MULTITHREAD uint32_t multithreaded; +#else +#define MULTITHREAD +#endif + #define CPU_COMMON \ struct TranslationBlock *current_tb; /* currently executing TB */ \ /* soft mmu support */ \ @@ -149,6 +156,7 @@ typedef struct CPUWatchpoint { uint32_t stop; /* Stop request */ \ uint32_t stopped; /* Artificially stopped */ \ uint32_t interrupt_request; \ + MULTITHREAD /* needs locking when accessing TBs */ \ volatile sig_atomic_t exit_request; \ /* The meaning of the MMU modes is defined in the target code. */ \ CPUTLBEntry tlb_table[NB_MMU_MODES][CPU_TLB_SIZE]; \ diff --git a/cpu-exec.c b/cpu-exec.c index 6b3391c..3fe2725 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -219,6 +219,9 @@ int cpu_exec(CPUState *env1) TranslationBlock *tb; uint8_t *tc_ptr; unsigned long next_tb; +#ifdef CONFIG_USER_ONLY + uint32_t multithreaded; +#endif if (cpu_halted(env1) == EXCP_HALTED) return EXCP_HALTED; @@ -576,7 +579,11 @@ int cpu_exec(CPUState *env1) #endif } #endif - spin_lock(&tb_lock); +#ifdef CONFIG_USER_ONLY + multithreaded = env->multithreaded; + if (multithreaded) +#endif + spin_lock(&tb_lock); tb = tb_find_fast(); /* Note: we do it here to avoid a gcc bug on Mac OS X when doing it in tb_find_slow */ @@ -600,7 +607,10 @@ int cpu_exec(CPUState *env1) tb_add_jump((TranslationBlock *)(next_tb & ~3), next_tb & 3, tb); } } - spin_unlock(&tb_lock); +#ifdef CONFIG_USER_ONLY + if (multithreaded) +#endif + spin_unlock(&tb_lock); env->current_tb = tb; /* cpu_interrupt might be called while translating the diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 617e031..f2a53d5 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -3549,6 +3549,7 @@ static int do_fork(CPUState *env, unsigned int flags, abi_ulong newsp, ts = qemu_mallocz(sizeof(TaskState) + NEW_STACK_SIZE); init_task_state(ts); new_stack = ts->stack; + env->multithreaded = 1; /* we create a new CPU instance. */ new_env = cpu_copy(env); /* Init regs that differ from the parent. */