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/nios2/cpu.c | 3 +++ target/nios2/helper.c | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/target/nios2/cpu.c b/target/nios2/cpu.c index fe5fd9adfd..fd05406eac 100644 --- a/target/nios2/cpu.c +++ b/target/nios2/cpu.c @@ -102,13 +102,16 @@ static bool nios2_cpu_exec_interrupt(CPUState *cs, int interrupt_request) { Nios2CPU *cpu = NIOS2_CPU(cs); CPUNios2State *env = &cpu->env; + qemu_mutex_lock_iothread(); if ((interrupt_request & CPU_INTERRUPT_HARD) && (env->regs[CR_STATUS] & CR_STATUS_PIE)) { cs->exception_index = EXCP_IRQ; nios2_cpu_do_interrupt(cs); + qemu_mutex_unlock_iothread(); return true; } + qemu_mutex_unlock_iothread(); return false; } diff --git a/target/nios2/helper.c b/target/nios2/helper.c index 57c97bde3c..46d53551d4 100644 --- a/target/nios2/helper.c +++ b/target/nios2/helper.c @@ -52,7 +52,10 @@ void nios2_cpu_do_interrupt(CPUState *cs) { Nios2CPU *cpu = NIOS2_CPU(cs); CPUNios2State *env = &cpu->env; - + bool bql = !qemu_mutex_iothread_locked(); + if (bql) { + qemu_mutex_lock_iothread(); + } switch (cs->exception_index) { case EXCP_IRQ: assert(env->regs[CR_STATUS] & CR_STATUS_PIE); @@ -198,6 +201,9 @@ void nios2_cpu_do_interrupt(CPUState *cs) cs->exception_index); break; } + if (bql) { + qemu_mutex_unlock_iothread(); + } } hwaddr nios2_cpu_get_phys_page_debug(CPUState *cs, vaddr addr) -- 2.17.1