[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v7 62/73] cpu: introduce cpu_has_work_with_iothread_
From: |
Emilio G. Cota |
Subject: |
[Qemu-devel] [PATCH v7 62/73] cpu: introduce cpu_has_work_with_iothread_lock |
Date: |
Mon, 4 Mar 2019 13:18:02 -0500 |
It will gain some users soon.
Suggested-by: Paolo Bonzini <address@hidden>
Reviewed-by: Richard Henderson <address@hidden>
Reviewed-by: Alex Bennée <address@hidden>
Signed-off-by: Emilio G. Cota <address@hidden>
---
include/qom/cpu.h | 37 ++++++++++++++++++++++++++++++++++---
1 file changed, 34 insertions(+), 3 deletions(-)
diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index 651e1ab4d8..fc768bbe00 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -27,6 +27,7 @@
#include "qapi/qapi-types-run-state.h"
#include "qemu/bitmap.h"
#include "qemu/fprintf-fn.h"
+#include "qemu/main-loop.h"
#include "qemu/rcu_queue.h"
#include "qemu/queue.h"
#include "qemu/thread.h"
@@ -87,6 +88,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)
@@ -170,6 +173,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,
@@ -809,14 +813,41 @@ const char *parse_cpu_model(const char *cpu_model);
static inline bool cpu_has_work(CPUState *cpu)
{
CPUClass *cc = CPU_GET_CLASS(cpu);
+ bool has_cpu_lock = cpu_mutex_locked(cpu);
+ bool (*func)(CPUState *cpu);
bool ret;
+ /* some targets require us to hold the BQL when checking for work */
+ if (cc->has_work_with_iothread_lock) {
+ if (qemu_mutex_iothread_locked()) {
+ func = cc->has_work_with_iothread_lock;
+ goto call_func;
+ }
+
+ 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;
+ }
+
g_assert(cc->has_work);
- if (cpu_mutex_locked(cpu)) {
- return cc->has_work(cpu);
+ func = cc->has_work;
+ call_func:
+ if (has_cpu_lock) {
+ return func(cpu);
}
cpu_mutex_lock(cpu);
- ret = cc->has_work(cpu);
+ ret = func(cpu);
cpu_mutex_unlock(cpu);
return ret;
}
--
2.17.1
- [Qemu-devel] [PATCH v7 39/73] i386: convert to cpu_interrupt_request, (continued)
- [Qemu-devel] [PATCH v7 39/73] i386: convert to cpu_interrupt_request, Emilio G. Cota, 2019/03/04
- [Qemu-devel] [PATCH v7 45/73] sh4: convert to cpu_interrupt_request, Emilio G. Cota, 2019/03/04
- [Qemu-devel] [PATCH v7 55/73] sparc: convert to cpu_interrupt_request, Emilio G. Cota, 2019/03/04
- [Qemu-devel] [PATCH v7 68/73] xtensa: convert to cpu_has_work_with_iothread_lock, Emilio G. Cota, 2019/03/04
- [Qemu-devel] [PATCH v7 46/73] cris: convert to cpu_interrupt_request, Emilio G. Cota, 2019/03/04
- [Qemu-devel] [PATCH v7 57/73] unicore32: convert to cpu_interrupt_request, Emilio G. Cota, 2019/03/04
- [Qemu-devel] [PATCH v7 40/73] i386/kvm: convert to cpu_interrupt_request, Emilio G. Cota, 2019/03/04
- [Qemu-devel] [PATCH v7 71/73] cpus-common: release BQL earlier in run_on_cpu, Emilio G. Cota, 2019/03/04
- [Qemu-devel] [PATCH v7 73/73] cputlb: queue async flush jobs without the BQL, Emilio G. Cota, 2019/03/04
- [Qemu-devel] [PATCH v7 56/73] openrisc: convert to cpu_interrupt_request, Emilio G. Cota, 2019/03/04
- [Qemu-devel] [PATCH v7 62/73] cpu: introduce cpu_has_work_with_iothread_lock,
Emilio G. Cota <=
- [Qemu-devel] [PATCH v7 63/73] ppc: convert to cpu_has_work_with_iothread_lock, Emilio G. Cota, 2019/03/04
- [Qemu-devel] [PATCH v7 48/73] lm32: convert to cpu_interrupt_request, Emilio G. Cota, 2019/03/04
- [Qemu-devel] [PATCH v7 52/73] s390x: convert to cpu_interrupt_request, Emilio G. Cota, 2019/03/04
- [Qemu-devel] [PATCH v7 60/73] cpu: convert to interrupt_request, Emilio G. Cota, 2019/03/04
- [Qemu-devel] [PATCH v7 41/73] i386/hax-all: convert to cpu_interrupt_request, Emilio G. Cota, 2019/03/04
- [Qemu-devel] [PATCH v7 43/73] i386/hvf: convert to cpu_request_interrupt, Emilio G. Cota, 2019/03/04
- [Qemu-devel] [PATCH v7 58/73] microblaze: convert to cpu_interrupt_request, Emilio G. Cota, 2019/03/04
- [Qemu-devel] [PATCH v7 72/73] cpu: add async_run_on_cpu_no_bql, Emilio G. Cota, 2019/03/04
- [Qemu-devel] [PATCH v7 70/73] cpu: protect CPU state with cpu->lock instead of the BQL, Emilio G. Cota, 2019/03/04
- [Qemu-devel] [PATCH v7 65/73] s390x: convert to cpu_has_work_with_iothread_lock, Emilio G. Cota, 2019/03/04