All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ulrich Hecht <uli@suse.de>
To: aurelien@aurel32.net
Cc: riku.voipio@iki.fi, qemu-devel@nongnu.org, agraf@suse.de
Subject: [Qemu-devel] [PATCH 08/12] linux-user: don't do locking in single-threaded processes
Date: Wed, 21 Oct 2009 15:52:29 +0200	[thread overview]
Message-ID: <1256133153-3121-9-git-send-email-uli@suse.de> (raw)
In-Reply-To: <1256133153-3121-8-git-send-email-uli@suse.de>

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 <uli@suse.de>
---
 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.  */
-- 
1.6.2.1

  reply	other threads:[~2009-10-21 13:52 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-21 13:52 [Qemu-devel] [PATCH 00/12] S/390 support Ulrich Hecht
2009-10-21 13:52 ` [Qemu-devel] [PATCH 01/12] TCG "sync" op Ulrich Hecht
2009-10-21 13:52   ` [Qemu-devel] [PATCH 02/12] S/390 disassembler fixes Ulrich Hecht
2009-10-21 13:52     ` [Qemu-devel] [PATCH 03/12] S/390 CPU emulation Ulrich Hecht
2009-10-21 13:52       ` [Qemu-devel] [PATCH 04/12] S/390 host build system support Ulrich Hecht
2009-10-21 13:52         ` [Qemu-devel] [PATCH 05/12] S/390 target " Ulrich Hecht
2009-10-21 13:52           ` [Qemu-devel] [PATCH 06/12] S/390 host support for TCG Ulrich Hecht
2009-10-21 13:52             ` [Qemu-devel] [PATCH 07/12] linux-user: S/390 64-bit (s390x) support Ulrich Hecht
2009-10-21 13:52               ` Ulrich Hecht [this message]
2009-10-21 13:52                 ` [Qemu-devel] [PATCH 09/12] linux-user: dup3, fallocate syscalls Ulrich Hecht
2009-10-21 13:52                   ` [Qemu-devel] [PATCH 10/12] linux-user: define a couple of syscalls for non-uid16 targets Ulrich Hecht
2009-10-21 13:52                     ` [Qemu-devel] [PATCH 11/12] linux-user: getpriority errno fix Ulrich Hecht
2009-10-21 13:52                       ` [Qemu-devel] [PATCH 12/12] enable CPU_QuadU for s390x Ulrich Hecht
2009-10-22 21:51     ` [Qemu-devel] [PATCH 02/12] S/390 disassembler fixes Aurelien Jarno
2009-10-22 21:03   ` [Qemu-devel] Re: [PATCH 01/12] TCG "sync" op Aurelien Jarno
2009-10-22 21:27     ` malc
2009-11-11  0:56     ` Paul Brook
2009-11-16 13:54       ` Alexander Graf
2009-11-16 14:37         ` Paul Brook
2009-11-16 15:14           ` Alexander Graf
2009-11-17 23:40       ` Aurelien Jarno
2009-11-18  0:01         ` Alexander Graf
2009-11-18 15:12           ` Aurelien Jarno
2009-11-18 15:21             ` Alexander Graf
2009-11-18 15:33               ` Paul Brook

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1256133153-3121-9-git-send-email-uli@suse.de \
    --to=uli@suse.de \
    --cc=agraf@suse.de \
    --cc=aurelien@aurel32.net \
    --cc=qemu-devel@nongnu.org \
    --cc=riku.voipio@iki.fi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.