[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v10 62/73] cpu: introduce cpu_has_work_with_iothread_lock
From: |
Robert Foley |
Subject: |
[PATCH v10 62/73] cpu: introduce cpu_has_work_with_iothread_lock |
Date: |
Wed, 17 Jun 2020 17:02:20 -0400 |
From: "Emilio G. Cota" <cota@braap.org>
It will gain some users soon.
Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Emilio G. Cota <cota@braap.org>
Signed-off-by: Robert Foley <robert.foley@linaro.org>
---
include/hw/core/cpu.h | 37 ++++++++++++++++++++++++++++++++++---
1 file changed, 34 insertions(+), 3 deletions(-)
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 79da78cd10..720bc85a84 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/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"
@@ -82,6 +83,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_unaligned_access: Callback for unaligned access handling, if
* the target defines #TARGET_ALIGNED_ONLY.
@@ -167,6 +170,7 @@ typedef struct CPUClass {
int reset_dump_flags;
bool (*has_work)(CPUState *cpu);
+ bool (*has_work_with_iothread_lock)(CPUState *cpu);
void (*do_interrupt)(CPUState *cpu);
void (*do_unaligned_access)(CPUState *cpu, vaddr addr,
MMUAccessType access_type,
@@ -805,14 +809,41 @@ const char *parse_cpu_option(const char *cpu_option);
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
- [PATCH v10 51/73] nios: convert to cpu_interrupt_request, (continued)
- [PATCH v10 51/73] nios: convert to cpu_interrupt_request, Robert Foley, 2020/06/17
- [PATCH v10 52/73] s390x: convert to cpu_interrupt_request, Robert Foley, 2020/06/17
- [PATCH v10 53/73] alpha: convert to cpu_interrupt_request, Robert Foley, 2020/06/17
- [PATCH v10 57/73] unicore32: convert to cpu_interrupt_request, Robert Foley, 2020/06/17
- [PATCH v10 54/73] moxie: convert to cpu_interrupt_request, Robert Foley, 2020/06/17
- [PATCH v10 55/73] sparc: convert to cpu_interrupt_request, Robert Foley, 2020/06/17
- [PATCH v10 59/73] accel/tcg: convert to cpu_interrupt_request, Robert Foley, 2020/06/17
- [PATCH v10 56/73] openrisc: convert to cpu_interrupt_request, Robert Foley, 2020/06/17
- [PATCH v10 58/73] microblaze: convert to cpu_interrupt_request, Robert Foley, 2020/06/17
- [PATCH v10 60/73] cpu: convert to interrupt_request, Robert Foley, 2020/06/17
- [PATCH v10 62/73] cpu: introduce cpu_has_work_with_iothread_lock,
Robert Foley <=
- [PATCH v10 63/73] ppc: convert to cpu_has_work_with_iothread_lock, Robert Foley, 2020/06/17
- [PATCH v10 61/73] cpu: call .cpu_has_work with the CPU lock held, Robert Foley, 2020/06/17
- [PATCH v10 64/73] mips: convert to cpu_has_work_with_iothread_lock, Robert Foley, 2020/06/17
- [PATCH v10 66/73] riscv: convert to cpu_has_work_with_iothread_lock, Robert Foley, 2020/06/17
- [PATCH v10 68/73] xtensa: convert to cpu_has_work_with_iothread_lock, Robert Foley, 2020/06/17
- [PATCH v10 65/73] s390x: convert to cpu_has_work_with_iothread_lock, Robert Foley, 2020/06/17
- [PATCH v10 69/73] cpu: rename all_cpu_threads_idle to qemu_tcg_rr_all_cpu_threads_idle, Robert Foley, 2020/06/17
- [PATCH v10 70/73] cpu: protect CPU state with cpu->lock instead of the BQL, Robert Foley, 2020/06/17
- [PATCH v10 73/73] cputlb: queue async flush jobs without the BQL, Robert Foley, 2020/06/17
- [PATCH v10 72/73] cpu: add async_run_on_cpu_no_bql, Robert Foley, 2020/06/17