This is part of a series of changes to remove the implied BQL from the common code of cpu_handle_interrupt and cpu_handle_exception. As part of removing the implied BQL from the common code, we are pushing the BQL holding down into the per-arch implementation functions of do_interrupt and cpu_exec_interrupt.
The purpose of this set of changes is to set the groundwork so that an arch could move towards removing the BQL from the cpu_handle_interrupt/exception paths. This approach was suggested by Paolo Bonzini. For reference, here are two key posts in the discussion, explaining the reasoning/benefits of this approach. https://lists.gnu.org/archive/html/qemu-devel/2020-07/msg08731.html https://lists.gnu.org/archive/html/qemu-devel/2020-08/msg00044.html Signed-off-by: Robert Foley <robert.fo...@linaro.org> --- target/openrisc/interrupt.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/target/openrisc/interrupt.c b/target/openrisc/interrupt.c index 3eab771dcd..361f242954 100644 --- a/target/openrisc/interrupt.c +++ b/target/openrisc/interrupt.c @@ -28,6 +28,10 @@ void openrisc_cpu_do_interrupt(CPUState *cs) { + bool bql = !qemu_mutex_iothread_locked(); + if (bql) { + qemu_mutex_lock_iothread(); + } #ifndef CONFIG_USER_ONLY OpenRISCCPU *cpu = OPENRISC_CPU(cs); CPUOpenRISCState *env = &cpu->env; @@ -99,6 +103,9 @@ void openrisc_cpu_do_interrupt(CPUState *cs) #endif cs->exception_index = -1; + if (bql) { + qemu_mutex_unlock_iothread(); + } } bool openrisc_cpu_exec_interrupt(CPUState *cs, int interrupt_request) @@ -106,6 +113,7 @@ bool openrisc_cpu_exec_interrupt(CPUState *cs, int interrupt_request) OpenRISCCPU *cpu = OPENRISC_CPU(cs); CPUOpenRISCState *env = &cpu->env; int idx = -1; + qemu_mutex_lock_iothread(); if ((interrupt_request & CPU_INTERRUPT_HARD) && (env->sr & SR_IEE)) { idx = EXCP_INT; @@ -116,7 +124,9 @@ bool openrisc_cpu_exec_interrupt(CPUState *cs, int interrupt_request) if (idx >= 0) { cs->exception_index = idx; openrisc_cpu_do_interrupt(cs); + qemu_mutex_unlock_iothread(); return true; } + qemu_mutex_unlock_iothread(); return false; } -- 2.17.1