All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: mttcg@listserver.greensocs.com, qemu-devel@nongnu.org,
	fred.konrad@greensocs.com, a.rigo@virtualopensystems.com,
	cota@braap.org, bobby.prani@gmail.com, nikunj@linux.vnet.ibm.com
Cc: mark.burton@greensocs.com, pbonzini@redhat.com,
	jan.kiszka@siemens.com, serge.fdrv@gmail.com, rth@twiddle.net,
	peter.maydell@linaro.org, claudio.fontana@huawei.com,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Peter Crosthwaite" <crosthwaite.peter@gmail.com>
Subject: [Qemu-devel] [RFC v4 20/28] cpus: tweak sleeping and safe_work rules for MTTCG
Date: Thu, 11 Aug 2016 16:24:16 +0100	[thread overview]
Message-ID: <1470929064-4092-21-git-send-email-alex.bennee@linaro.org> (raw)
In-Reply-To: <1470929064-4092-1-git-send-email-alex.bennee@linaro.org>

Once TCG gains the ability to sleep individual threads we need to make
sure they don't sleep when safe work is pending as all threads need to
go through the process_queued_work function. Also if we have multiple
threads wait_for_safe_work can now sleep without deadlocking.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

---
v4
  - new for v4, ontop of async-safe-work-v5
---
 cpu-exec-common.c | 15 ++++++++++++++-
 cpus.c            |  2 +-
 include/qom/cpu.h |  8 ++++++++
 3 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/cpu-exec-common.c b/cpu-exec-common.c
index e29cf6d..84cb789 100644
--- a/cpu-exec-common.c
+++ b/cpu-exec-common.c
@@ -83,6 +83,18 @@ QemuCond qemu_exclusive_cond;
 
 static int safe_work_pending;
 
+/* No vCPUs can sleep while there is safe work pending as we need
+ * everything to finish up in process_cpu_work.
+ */
+bool cpu_has_queued_work(CPUState *cpu)
+{
+    if (cpu->queued_work || atomic_mb_read(&safe_work_pending) > 0) {
+        return true;
+    } else {
+        return false;
+    }
+}
+
 #ifdef CONFIG_USER_ONLY
 #define can_wait_for_safe() (1)
 #else
@@ -91,7 +103,8 @@ static int safe_work_pending;
  * all vCPUs are in the same thread. This will change for MTTCG
  * however.
  */
-#define can_wait_for_safe() (0)
+extern int smp_cpus;
+#define can_wait_for_safe() (mttcg_enabled && smp_cpus > 1)
 #endif
 
 void wait_safe_cpu_work(void)
diff --git a/cpus.c b/cpus.c
index 8a40a08..4fc5e4c 100644
--- a/cpus.c
+++ b/cpus.c
@@ -88,7 +88,7 @@ bool cpu_is_stopped(CPUState *cpu)
 
 static bool cpu_thread_is_idle(CPUState *cpu)
 {
-    if (cpu->stop || cpu->queued_work) {
+    if (cpu->stop || cpu_has_queued_work(cpu)) {
         return false;
     }
     if (cpu_is_stopped(cpu)) {
diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index 5ecbd29..d0db846 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -661,6 +661,14 @@ void async_run_on_cpu(CPUState *cpu, run_on_cpu_func func, void *data);
 void async_safe_run_on_cpu(CPUState *cpu, run_on_cpu_func func, void *data);
 
 /**
+ * cpu_has_queued_work:
+ * @cpu: The vCPU to check
+ *
+ * Returns true if there is *_run_on_cpu work to be done.
+ */
+bool cpu_has_queued_work(CPUState *cpu);
+
+/**
  * qemu_get_cpu:
  * @index: The CPUState@cpu_index value of the CPU to obtain.
  *
-- 
2.7.4

  parent reply	other threads:[~2016-08-11 15:30 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-11 15:23 [Qemu-devel] [RFC v4 00/28] Base enabling patches for MTTCG Alex Bennée
2016-08-11 15:23 ` [Qemu-devel] [RFC v4 01/28] cpus: make all_vcpus_paused() return bool Alex Bennée
2016-08-11 15:23 ` [Qemu-devel] [RFC v4 02/28] translate_all: DEBUG_FLUSH -> DEBUG_TB_FLUSH Alex Bennée
2016-08-11 15:23 ` [Qemu-devel] [RFC v4 03/28] translate-all: add DEBUG_LOCKING asserts Alex Bennée
2016-08-11 15:24 ` [Qemu-devel] [RFC v4 04/28] cpu-exec: include cpu_index in CPU_LOG_EXEC messages Alex Bennée
2016-09-07  2:21   ` Richard Henderson
2016-08-11 15:24 ` [Qemu-devel] [RFC v4 05/28] docs: new design document multi-thread-tcg.txt (DRAFTING) Alex Bennée
2016-08-11 15:24 ` [Qemu-devel] [RFC v4 06/28] tcg: comment on which functions have to be called with tb_lock held Alex Bennée
2016-09-07  2:30   ` Richard Henderson
2016-08-11 15:24 ` [Qemu-devel] [RFC v4 07/28] linux-user/elfload: ensure mmap_lock() held while setting up Alex Bennée
2016-09-07  2:34   ` Richard Henderson
2016-08-11 15:24 ` [Qemu-devel] [RFC v4 08/28] translate-all: Add assert_(memory|tb)_lock annotations Alex Bennée
2016-09-07  2:41   ` Richard Henderson
2016-09-07  7:08     ` Alex Bennée
2016-08-11 15:24 ` [Qemu-devel] [RFC v4 09/28] tcg: protect TBContext with tb_lock Alex Bennée
2016-09-07  2:48   ` Richard Henderson
2016-08-11 15:24 ` [Qemu-devel] [RFC v4 10/28] target-arm/arm-powerctl: wake up sleeping CPUs Alex Bennée
2016-08-11 15:24 ` [Qemu-devel] [RFC v4 11/28] tcg: move tcg_exec_all and helpers above thread fn Alex Bennée
2016-09-07  2:53   ` Richard Henderson
2016-08-11 15:24 ` [Qemu-devel] [RFC v4 12/28] tcg: cpus rm tcg_exec_all() Alex Bennée
2016-08-11 15:24 ` [Qemu-devel] [RFC v4 13/28] tcg: add options for enabling MTTCG Alex Bennée
2016-09-07  3:06   ` Richard Henderson
2016-08-11 15:24 ` [Qemu-devel] [RFC v4 14/28] tcg: add kick timer for single-threaded vCPU emulation Alex Bennée
2016-09-07  3:25   ` Richard Henderson
2016-09-07  5:40     ` Paolo Bonzini
2016-09-07 10:15       ` Alex Bennée
2016-09-07 10:19     ` Alex Bennée
2016-08-11 15:24 ` [Qemu-devel] [RFC v4 15/28] tcg: rename tcg_current_cpu to tcg_current_rr_cpu Alex Bennée
2016-09-07  3:34   ` Richard Henderson
2016-08-11 15:24 ` [Qemu-devel] [RFC v4 16/28] tcg: drop global lock during TCG code execution Alex Bennée
2016-09-07  4:03   ` Richard Henderson
2016-09-07  5:43     ` Paolo Bonzini
2016-09-07  6:43       ` Richard Henderson
2016-09-07 15:15         ` Paolo Bonzini
2016-08-11 15:24 ` [Qemu-devel] [RFC v4 17/28] cpus: re-factor out handle_icount_deadline Alex Bennée
2016-09-07  4:06   ` Richard Henderson
2016-08-11 15:24 ` [Qemu-devel] [RFC v4 18/28] tcg: remove global exit_request Alex Bennée
2016-09-07  4:11   ` Richard Henderson
2016-08-11 15:24 ` [Qemu-devel] [RFC v4 19/28] tcg: move locking for tb_invalidate_phys_page_range up Alex Bennée
2016-09-27 15:56   ` Paolo Bonzini
2016-08-11 15:24 ` Alex Bennée [this message]
2016-09-07  4:22   ` [Qemu-devel] [RFC v4 20/28] cpus: tweak sleeping and safe_work rules for MTTCG Richard Henderson
2016-09-07 10:05   ` Paolo Bonzini
2016-08-11 15:24 ` [Qemu-devel] [RFC v4 21/28] tcg: enable tb_lock() for SoftMMU Alex Bennée
2016-09-07  4:26   ` Richard Henderson
2016-09-27 16:16   ` Paolo Bonzini
2016-08-11 15:24 ` [Qemu-devel] [RFC v4 22/28] tcg: enable thread-per-vCPU Alex Bennée
2016-08-11 15:24 ` [Qemu-devel] [RFC v4 23/28] atomic: introduce cmpxchg_bool Alex Bennée
2016-09-08  0:12   ` Richard Henderson
2016-08-11 15:24 ` [Qemu-devel] [RFC v4 24/28] cputlb: add assert_cpu_is_self checks Alex Bennée
2016-09-08 17:19   ` Richard Henderson
2016-08-11 15:24 ` [Qemu-devel] [RFC v4 25/28] cputlb: introduce tlb_flush_* async work Alex Bennée
2016-09-07 10:08   ` Paolo Bonzini
2016-09-08 17:23   ` Richard Henderson
2016-08-11 15:24 ` [Qemu-devel] [RFC v4 26/28] cputlb: tweak qemu_ram_addr_from_host_nofail reporting Alex Bennée
2016-09-08 17:24   ` Richard Henderson
2016-08-11 15:24 ` [Qemu-devel] [RFC v4 27/28] cputlb: make tlb_reset_dirty safe for MTTCG Alex Bennée
2016-09-08 17:34   ` Richard Henderson
2016-08-11 15:24 ` [Qemu-devel] [RFC v4 28/28] cputlb: make tlb_flush_by_mmuidx " Alex Bennée
2016-09-07 10:09   ` Paolo Bonzini
2016-09-08 17:54   ` Richard Henderson
2016-08-11 17:22 ` [Qemu-devel] [RFC v4 00/28] Base enabling patches " Alex Bennée
2016-08-12  8:02   ` Alex Bennée
2016-09-06  9:24 ` Alex Bennée

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=1470929064-4092-21-git-send-email-alex.bennee@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=a.rigo@virtualopensystems.com \
    --cc=bobby.prani@gmail.com \
    --cc=claudio.fontana@huawei.com \
    --cc=cota@braap.org \
    --cc=crosthwaite.peter@gmail.com \
    --cc=fred.konrad@greensocs.com \
    --cc=jan.kiszka@siemens.com \
    --cc=mark.burton@greensocs.com \
    --cc=mttcg@listserver.greensocs.com \
    --cc=nikunj@linux.vnet.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    --cc=serge.fdrv@gmail.com \
    /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.