From: "Emilio G. Cota" <cota@braap.org>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org, David Gibson <david@gibson.dropbear.id.au>,
Alexander Graf <agraf@suse.de>,
qemu-ppc@nongnu.org
Subject: Re: [Qemu-devel] [RFC v3 48/56] ppc: acquire the BQL in cpu_has_work
Date: Sat, 20 Oct 2018 12:31:05 -0400 [thread overview]
Message-ID: <20181020163105.GA1734@flamenco> (raw)
In-Reply-To: <b76f9b0e-16f6-e51b-250b-4a0f3b71552c@redhat.com>
On Fri, Oct 19, 2018 at 08:58:31 +0200, Paolo Bonzini wrote:
> On 19/10/2018 03:06, Emilio G. Cota wrote:
> > Soon we will call cpu_has_work without the BQL.
> >
> > Cc: David Gibson <david@gibson.dropbear.id.au>
> > Cc: Alexander Graf <agraf@suse.de>
> > Cc: qemu-ppc@nongnu.org
> > Signed-off-by: Emilio G. Cota <cota@braap.org>
> > ---
> > target/ppc/translate_init.inc.c | 77 +++++++++++++++++++++++++++++++--
> > 1 file changed, 73 insertions(+), 4 deletions(-)
> >
>
> Perhaps we should instead define both ->cpu_has_work and
> ->cpu_has_work_with_iothread_lock members, and move the generic
> unlock/relock code to common code?
I like this. How does the appended look?
Thanks,
Emilio
---8<---
[PATCH] cpu: introduce cpu_has_work_with_iothread_lock
It will gain some users soon.
Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Emilio G. Cota <cota@braap.org>
---
include/qom/cpu.h | 42 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index ad8859d014..d9e6f5d4d2 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -26,6 +26,7 @@
#include "exec/memattrs.h"
#include "qapi/qapi-types-run-state.h"
#include "qemu/bitmap.h"
+#include "qemu/main-loop.h"
#include "qemu/rcu_queue.h"
#include "qemu/queue.h"
#include "qemu/thread.h"
@@ -86,6 +87,8 @@ struct TranslationBlock;
* @reset_dump_flags: #CPUDumpFlags to use for reset logging.
* @has_work: Callback for checking if there is work to do. Called with the
* CPU lock held.
+ * @has_work_with_iothread_lock: Callback for checking if there is work to do.
+ * Called with both the BQL and the CPU lock held.
* @do_interrupt: Callback for interrupt handling.
* @do_unassigned_access: Callback for unassigned access handling.
* (this is deprecated: new targets should use do_transaction_failed instead)
@@ -157,6 +160,7 @@ typedef struct CPUClass {
void (*reset)(CPUState *cpu);
int reset_dump_flags;
bool (*has_work)(CPUState *cpu);
+ bool (*has_work_with_iothread_lock)(CPUState *cpu);
void (*do_interrupt)(CPUState *cpu);
CPUUnassignedAccess do_unassigned_access;
void (*do_unaligned_access)(CPUState *cpu, vaddr addr,
@@ -774,6 +778,40 @@ CPUState *cpu_create(const char *typename);
*/
const char *parse_cpu_model(const char *cpu_model);
+/* do not call directly; use cpu_has_work instead */
+static inline bool cpu_has_work_bql(CPUState *cpu)
+{
+ CPUClass *cc = CPU_GET_CLASS(cpu);
+ bool has_cpu_lock = cpu_mutex_locked(cpu);
+ bool has_bql = qemu_mutex_iothread_locked();
+ bool ret;
+
+ if (has_bql) {
+ if (has_cpu_lock) {
+ return cc->has_work_with_iothread_lock(cpu);
+ }
+ cpu_mutex_lock(cpu);
+ ret = cc->has_work_with_iothread_lock(cpu);
+ cpu_mutex_unlock(cpu);
+ return ret;
+ }
+
+ if (has_cpu_lock) {
+ /* avoid deadlock by acquiring the locks in order */
+ cpu_mutex_unlock(cpu);
+ }
+ qemu_mutex_lock_iothread();
+ cpu_mutex_lock(cpu);
+
+ ret = cc->has_work_with_iothread_lock(cpu);
+
+ qemu_mutex_unlock_iothread();
+ if (!has_cpu_lock) {
+ cpu_mutex_unlock(cpu);
+ }
+ return ret;
+}
+
/**
* cpu_has_work:
* @cpu: The vCPU to check.
@@ -787,6 +825,10 @@ static inline bool cpu_has_work(CPUState *cpu)
CPUClass *cc = CPU_GET_CLASS(cpu);
bool ret;
+ if (cc->has_work_with_iothread_lock) {
+ return cpu_has_work_bql(cpu);
+ }
+
g_assert(cc->has_work);
if (cpu_mutex_locked(cpu)) {
return cc->has_work(cpu);
--
2.17.1
next prev parent reply other threads:[~2018-10-20 16:34 UTC|newest]
Thread overview: 118+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-19 1:05 [Qemu-devel] [RFC v3 0/56] per-CPU locks Emilio G. Cota
2018-10-19 1:05 ` [Qemu-devel] [RFC v3 01/56] cpu: convert queued work to a QSIMPLEQ Emilio G. Cota
2018-10-19 6:26 ` Richard Henderson
2018-10-19 1:05 ` [Qemu-devel] [RFC v3 02/56] cpu: rename cpu->work_mutex to cpu->lock Emilio G. Cota
2018-10-19 6:26 ` Richard Henderson
2018-10-19 1:05 ` [Qemu-devel] [RFC v3 03/56] cpu: introduce cpu_mutex_lock/unlock Emilio G. Cota
2018-10-19 1:05 ` [Qemu-devel] [RFC v3 04/56] cpu: make qemu_work_cond per-cpu Emilio G. Cota
2018-10-19 1:05 ` [Qemu-devel] [RFC v3 05/56] cpu: move run_on_cpu to cpus-common Emilio G. Cota
2018-10-19 6:39 ` Richard Henderson
2018-10-19 1:05 ` [Qemu-devel] [RFC v3 06/56] cpu: introduce process_queued_cpu_work_locked Emilio G. Cota
2018-10-19 6:41 ` Richard Henderson
2018-10-19 1:05 ` [Qemu-devel] [RFC v3 07/56] target/m68k: rename cpu_halted to cpu_halt Emilio G. Cota
2018-10-21 12:53 ` Richard Henderson
2018-10-21 13:38 ` Richard Henderson
2018-10-22 22:58 ` Emilio G. Cota
2018-10-19 1:05 ` [Qemu-devel] [RFC v3 08/56] cpu: define cpu_halted helpers Emilio G. Cota
2018-10-21 12:54 ` Richard Henderson
2018-10-19 1:05 ` [Qemu-devel] [RFC v3 09/56] arm: convert to cpu_halted Emilio G. Cota
2018-10-21 12:55 ` Richard Henderson
2018-10-19 1:05 ` [Qemu-devel] [RFC v3 10/56] ppc: " Emilio G. Cota
2018-10-21 12:56 ` Richard Henderson
2018-10-22 21:12 ` Emilio G. Cota
2018-10-19 1:05 ` [Qemu-devel] [RFC v3 11/56] sh4: " Emilio G. Cota
2018-10-21 12:57 ` Richard Henderson
2018-10-19 1:05 ` [Qemu-devel] [RFC v3 12/56] i386: " Emilio G. Cota
2018-10-21 12:59 ` Richard Henderson
2018-10-19 1:05 ` [Qemu-devel] [RFC v3 13/56] lm32: " Emilio G. Cota
2018-10-21 13:00 ` Richard Henderson
2018-10-19 1:05 ` [Qemu-devel] [RFC v3 14/56] m68k: " Emilio G. Cota
2018-10-21 13:01 ` Richard Henderson
2018-10-19 1:05 ` [Qemu-devel] [RFC v3 15/56] mips: " Emilio G. Cota
2018-10-21 13:02 ` Richard Henderson
2018-10-19 1:05 ` [Qemu-devel] [RFC v3 16/56] riscv: " Emilio G. Cota
2018-10-19 17:24 ` Palmer Dabbelt
2018-10-19 1:05 ` [Qemu-devel] [RFC v3 17/56] s390x: " Emilio G. Cota
2018-10-21 13:04 ` Richard Henderson
2018-10-19 1:05 ` [Qemu-devel] [RFC v3 18/56] sparc: " Emilio G. Cota
2018-10-21 13:04 ` Richard Henderson
2018-10-19 1:05 ` [Qemu-devel] [RFC v3 19/56] xtensa: " Emilio G. Cota
2018-10-21 13:10 ` Richard Henderson
2018-10-19 1:05 ` [Qemu-devel] [RFC v3 20/56] gdbstub: " Emilio G. Cota
2018-10-21 13:10 ` Richard Henderson
2018-10-19 1:05 ` [Qemu-devel] [RFC v3 21/56] openrisc: " Emilio G. Cota
2018-10-21 13:11 ` Richard Henderson
2018-10-19 1:05 ` [Qemu-devel] [RFC v3 22/56] cpu-exec: " Emilio G. Cota
2018-10-19 1:05 ` [Qemu-devel] [RFC v3 23/56] cpu: define cpu_interrupt_request helpers Emilio G. Cota
2018-10-21 13:15 ` Richard Henderson
2018-10-19 1:05 ` [Qemu-devel] [RFC v3 24/56] ppc: use cpu_reset_interrupt Emilio G. Cota
2018-10-21 13:15 ` Richard Henderson
2018-10-19 1:05 ` [Qemu-devel] [RFC v3 25/56] exec: " Emilio G. Cota
2018-10-21 13:17 ` Richard Henderson
2018-10-22 23:28 ` Emilio G. Cota
2018-10-19 1:05 ` [Qemu-devel] [RFC v3 26/56] i386: " Emilio G. Cota
2018-10-21 13:18 ` Richard Henderson
2018-10-19 1:05 ` [Qemu-devel] [RFC v3 27/56] s390x: " Emilio G. Cota
2018-10-21 13:18 ` Richard Henderson
2018-10-19 1:05 ` [Qemu-devel] [RFC v3 28/56] openrisc: " Emilio G. Cota
2018-10-21 13:18 ` Richard Henderson
2018-10-19 1:05 ` [Qemu-devel] [RFC v3 29/56] arm: convert to cpu_interrupt_request Emilio G. Cota
2018-10-21 13:21 ` Richard Henderson
2018-10-19 1:05 ` [Qemu-devel] [RFC v3 30/56] i386: " Emilio G. Cota
2018-10-21 13:27 ` Richard Henderson
2018-10-23 20:28 ` Emilio G. Cota
2018-10-19 1:06 ` [Qemu-devel] [RFC v3 31/56] ppc: " Emilio G. Cota
2018-10-19 1:06 ` [Qemu-devel] [RFC v3 32/56] sh4: " Emilio G. Cota
2018-10-21 13:28 ` Richard Henderson
2018-10-19 1:06 ` [Qemu-devel] [RFC v3 33/56] cris: " Emilio G. Cota
2018-10-21 13:29 ` Richard Henderson
2018-10-19 1:06 ` [Qemu-devel] [RFC v3 34/56] hppa: " Emilio G. Cota
2018-10-21 13:29 ` Richard Henderson
2018-10-19 1:06 ` [Qemu-devel] [RFC v3 35/56] lm32: " Emilio G. Cota
2018-10-21 13:29 ` Richard Henderson
2018-10-19 1:06 ` [Qemu-devel] [RFC v3 36/56] m68k: " Emilio G. Cota
2018-10-21 13:29 ` Richard Henderson
2018-10-19 1:06 ` [Qemu-devel] [RFC v3 37/56] mips: " Emilio G. Cota
2018-10-21 13:30 ` Richard Henderson
2018-10-22 23:38 ` Emilio G. Cota
2018-10-19 1:06 ` [Qemu-devel] [RFC v3 38/56] nios: " Emilio G. Cota
2018-10-21 13:30 ` Richard Henderson
2018-10-19 1:06 ` [Qemu-devel] [RFC v3 39/56] s390x: " Emilio G. Cota
2018-10-21 13:30 ` Richard Henderson
2018-10-19 1:06 ` [Qemu-devel] [RFC v3 40/56] alpha: " Emilio G. Cota
2018-10-21 13:31 ` Richard Henderson
2018-10-19 1:06 ` [Qemu-devel] [RFC v3 41/56] moxie: " Emilio G. Cota
2018-10-21 13:31 ` Richard Henderson
2018-10-19 1:06 ` [Qemu-devel] [RFC v3 42/56] sparc: " Emilio G. Cota
2018-10-21 13:32 ` Richard Henderson
2018-10-19 1:06 ` [Qemu-devel] [RFC v3 43/56] openrisc: " Emilio G. Cota
2018-10-21 13:32 ` Richard Henderson
2018-10-19 1:06 ` [Qemu-devel] [RFC v3 44/56] unicore32: " Emilio G. Cota
2018-10-21 13:33 ` Richard Henderson
2018-10-19 1:06 ` [Qemu-devel] [RFC v3 45/56] microblaze: " Emilio G. Cota
2018-10-21 13:33 ` Richard Henderson
2018-10-19 1:06 ` [Qemu-devel] [RFC v3 46/56] accel/tcg: " Emilio G. Cota
2018-10-21 13:34 ` Richard Henderson
2018-10-22 23:50 ` Emilio G. Cota
2018-10-23 2:17 ` Richard Henderson
2018-10-23 20:21 ` Emilio G. Cota
2018-10-19 1:06 ` [Qemu-devel] [RFC v3 47/56] cpu: call .cpu_has_work with the CPU lock held Emilio G. Cota
2018-10-19 1:06 ` [Qemu-devel] [RFC v3 48/56] ppc: acquire the BQL in cpu_has_work Emilio G. Cota
2018-10-19 6:58 ` Paolo Bonzini
2018-10-20 16:31 ` Emilio G. Cota [this message]
2018-10-21 13:42 ` Richard Henderson
2018-10-19 1:06 ` [Qemu-devel] [RFC v3 49/56] mips: " Emilio G. Cota
2018-10-19 1:06 ` [Qemu-devel] [RFC v3 50/56] s390: " Emilio G. Cota
2018-10-19 1:06 ` [Qemu-devel] [RFC v3 51/56] riscv: " Emilio G. Cota
2018-10-19 17:24 ` Palmer Dabbelt
2018-10-19 1:06 ` [Qemu-devel] [RFC v3 52/56] sparc: " Emilio G. Cota
2018-10-19 1:06 ` [Qemu-devel] [RFC v3 53/56] xtensa: " Emilio G. Cota
2018-10-19 1:06 ` [Qemu-devel] [RFC v3 54/56] cpu: protect most CPU state with cpu->lock Emilio G. Cota
2018-10-19 1:06 ` [Qemu-devel] [RFC v3 55/56] cpu: add async_run_on_cpu_no_bql Emilio G. Cota
2018-10-19 1:06 ` [Qemu-devel] [RFC v3 56/56] cputlb: queue async flush jobs without the BQL Emilio G. Cota
2018-10-19 6:59 ` [Qemu-devel] [RFC v3 0/56] per-CPU locks Paolo Bonzini
2018-10-19 14:50 ` Emilio G. Cota
2018-10-19 16:01 ` Paolo Bonzini
2018-10-19 19:29 ` Emilio G. Cota
2018-10-19 23:46 ` Emilio G. Cota
2018-10-22 15:30 ` Paolo Bonzini
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=20181020163105.GA1734@flamenco \
--to=cota@braap.org \
--cc=agraf@suse.de \
--cc=david@gibson.dropbear.id.au \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).