[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC v4 59/71] cpu: introduce cpu_has_work_with_iothread_lo
From: |
Emilio G. Cota |
Subject: |
[Qemu-devel] [RFC v4 59/71] cpu: introduce cpu_has_work_with_iothread_lock |
Date: |
Thu, 25 Oct 2018 10:46:32 -0400 |
It will gain some users soon.
Suggested-by: Paolo Bonzini <address@hidden>
Signed-off-by: Emilio G. Cota <address@hidden>
---
include/qom/cpu.h | 36 +++++++++++++++++++++++++++++++++---
1 file changed, 33 insertions(+), 3 deletions(-)
diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index 9826cdfa4c..b5c3b2c734 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,
@@ -794,14 +798,40 @@ 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;
+ 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] [RFC v4 36/71] arm: convert to cpu_interrupt_request, (continued)
- [Qemu-devel] [RFC v4 36/71] arm: convert to cpu_interrupt_request, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC v4 68/71] cpu: add async_run_on_cpu_no_bql, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC v4 63/71] riscv: convert to cpu_has_work_with_iothread_lock, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC v4 52/71] moxie: convert to cpu_interrupt_request, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC v4 66/71] cpu: protect most CPU state with cpu->lock, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC v4 59/71] cpu: introduce cpu_has_work_with_iothread_lock,
Emilio G. Cota <=
- [Qemu-devel] [RFC v4 54/71] openrisc: convert to cpu_interrupt_request, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC v4 49/71] nios: convert to cpu_interrupt_request, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC v4 48/71] mips: convert to cpu_interrupt_request, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC v4 31/71] ppc: use cpu_reset_interrupt, Emilio G. Cota, 2018/10/25