accel/tcg: Push BQL down into per-target do_interrupt handlers
v3 cover accel/tcg: Push BQL down into per-target do_interrupt handlers
This is a respin of Robert Foley's v2 series from August 2020 [1] triggered by a broader review of BQL contract in my halt-to-exec transitions series by Peter [2] and Mark [3].
v3:
- kind of rebase
- rename misleading fake_user_interrupt callback names for clarity
- restrict interrupt handlers to their appropriate modes (system vs user)
- explicitly document that do_interrupt() and cpu_exec_interrupt() callbacks are called WITH BQL held (explicit BQL contract in docstrings)
v2 Summary
----------
This series pushes the Big QEMU Lock (BQL) down from the core TCG cpu_handle_interrupt/cpu_handle_exception paths into per-target implementations. This allows each architecture to manage BQL locking granularity independently, reducing contention on a known bottleneck as measured by QEMU sync profiling (qsp).
The BQL has long been a scaling bottleneck in QEMU, and the interrupt/exception handling path is one of its heaviest users. By allowing targets to acquire the BQL only when needed, we enable future per-target optimizations.
Refs:
[1] https://lore.kernel.org/qemu-devel/[email protected]/
[2] https://lore.kernel.org/qemu-devel/CAFEAcA8xk8y1W0UvttpVhKYuoMBSQqZoF_15of0Rrq4wKkWDuw@mail.gmail.com/
[3] https://lore.kernel.org/qemu-devel/[email protected]/
Philippe Mathieu-Daudé (10):
target/arm: Call arm*_cpu_do_interrupt directly instead of via
TCGCPUOps
target/s390x: Restrict interrupt handlers to system mode target/i386: Rename fake_do_interrupt to fake_user_exception accel/tcg: Document cpu_exec_interrupt() callback contract accel/tcg: Document do_interrupt() callback contract accel/tcg: Add do_interrupt() wrapper for targets to manage BQL target/hexagon: Move to do_interrupt() (BQL acquired internally)
targets: Move interrupt handlers to do_interrupt()
targets: Move BQL locking into do_interrupt() handlers accel/tcg: Remove do_interrupt_locked() callback
Robert Foley (1):
accel/tcg: Rename do_interrupt() to do_interrupt_locked()
include/accel/tcg/cpu-ops.h | 32 +++++++++++++++++++++++++---- target/arm/internals.h | 2 +- target/i386/tcg/helper-tcg.h | 4 +++- target/s390x/s390x-internal.h | 5 ++--- accel/tcg/cpu-exec.c | 7 +++---- target/alpha/helper.c | 3 +++ target/arm/cpu-irq.c | 2 +- target/arm/helper.c | 1 + target/arm/tcg/cpu-v7m.c | 2 +- target/arm/tcg/m_helper.c | 2 ++ target/avr/helper.c | 3 +++ target/hppa/int_helper.c | 2 ++ target/i386/tcg/system/seg_helper.c | 2 ++ target/i386/tcg/tcg-cpu.c | 2 +- target/i386/tcg/user/seg_helper.c | 6 +++--- target/mips/tcg/system/tlb_helper.c | 3 +++ target/ppc/excp_helper.c | 2 ++ target/rx/helper.c | 3 +++ target/s390x/tcg/excp_helper.c | 8 +++----- target/sh4/helper.c | 3 +++ target/sparc/int32_helper.c | 2 ++ target/sparc/int64_helper.c | 2 ++ target/xtensa/exc_helper.c | 2 ++ 23 files changed, 76 insertions(+), 24 deletions(-)
Signature · 1 line
2.53.0
PATCH v3 3/11 target/i386: Rename fake_do_interrupt to fake_user_exception
The fake_user_exception hook handles exceptions in the outer exception loop (cpu_handle_exception), not inner loop interrupts (cpu_handle_interrupt). Rename to clarify the scope and intent.
--- include/accel/tcg/cpu-ops.h | 4 ++-- target/i386/tcg/helper-tcg.h | 4 +++- accel/tcg/cpu-exec.c | 4 ++-- target/i386/tcg/tcg-cpu.c | 2 +- target/i386/tcg/user/seg_helper.c | 6 +++--- 5 files changed, 11 insertions(+), 9 deletions(-)
include/accel/tcg/cpu-ops.h +2 -2
@@ -106,12 +106,12 @@ struct TCGCPUOps {#ifdef CONFIG_USER_ONLY /** -* @fake_user_interrupt: Callback for 'fake exception' handling. +* @fake_user_exception: Callback for 'fake exception' handling. * * Simulate 'fake exception' which will be handled outside the * cpu execution loop (hack for x86 user mode). */ -void (*fake_user_interrupt)(CPUState *cpu); +void (*fake_user_exception)(CPUState *cpu);/** * record_sigsegv:
target/i386/tcg/helper-tcg.h +3 -1
@@ -35,11 +35,13 @@* x86_cpu_do_interrupt: * @cpu: vCPU the interrupt is to be handled by. */ -void x86_cpu_do_interrupt (CPUState *cpu);#ifndef CONFIG_USER_ONLY +void x86_cpu_do_interrupt (CPUState *cpu);bool x86_cpu_exec_halt (CPUState *cpu);bool x86_need_replay_interrupt (int interrupt_request);bool x86_cpu_exec_interrupt (CPUState *cpu,int int_req); +#else +void x86_cpu_fake_user_exception (CPUState *cs);#endif void breakpoint_handler (CPUState *cs);
accel/tcg/cpu-exec.c +2 -2
@@ -717,8 +717,8 @@ static inline bool cpu_handle_exception(CPUState *cpu, int *ret)* handled outside the cpu execution loop. */ const TCGCPUOps *tcg_ops = cpu->cc->tcg_ops; -if (tcg_ops->fake_user_interrupt) { - tcg_ops->fake_user_interrupt (cpu); +if (tcg_ops->fake_user_exception) { + tcg_ops->fake_user_exception (cpu); } *ret = cpu->exception_index; cpu->exception_index =-1 ;
target/i386/tcg/tcg-cpu.c +1 -1
@@ -173,7 +173,7 @@ const TCGCPUOps x86_tcg_ops = { .cpu_exec_enter = x86_cpu_exec_enter, .cpu_exec_exit = x86_cpu_exec_exit, #ifdef CONFIG_USER_ONLY - .fake_user_interrupt = x86_cpu_do_interrupt, + .fake_user_exception = x86_cpu_fake_user_exception, .record_sigsegv = x86_cpu_record_sigsegv, .record_sigbus = x86_cpu_record_sigbus, #else
target/i386/tcg/user/seg_helper.c +3 -3
@@ -42,7 +42,7 @@ void helper_syscall(CPUX86State *env, int next_eip_addend)* instruction. It is only relevant if is_int is TRUE or if intno * is EXCP_SYSCALL. */ -static void do_interrupt_user (CPUX86State *env,int intno,int is_int, +static void do_exception_user (CPUX86State *env,int intno,int is_int,int error_code,target_ulong next_eip) {if (is_int) {
@@ -76,7 +76,7 @@ static void do_interrupt_user(CPUX86State *env, int intno, int is_int, } } -void x86_cpu_do_interrupt (CPUState *cs) +void x86_cpu_fake_user_exception (CPUState *cs) {X86CPU *cpu =X86_CPU (cs);CPUX86State *env = &cpu->env;
@@ -84,7 +84,7 @@ void x86_cpu_do_interrupt(CPUState *cs)/* if user mode only, we simulate a fake exception which will be handled outside the cpu execution loop */ -do_interrupt_user (env, cs->exception_index, +do_exception_user (env, cs->exception_index, env->exception_is_int, env->error_code, env->exception_next_eip);
Signature · 1 line
2.53.0
PATCH v3 4/11 accel/tcg: Document cpu_exec_interrupt() callback contract
In reply to Philippe Mathieu-DaudéExpand docstring to clarify that @interrupt_request is a bitmask, the handler is called with BQL held, and document the return value semantics. Fix typo in arm_cpu_exec_interrupt() documentation (s/inrerrupt/interrupt).
--- include/accel/tcg/cpu-ops.h | 15 ++++++++++++++- target/arm/internals.h | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-)
include/accel/tcg/cpu-ops.h +14 -1
@@ -171,8 +171,21 @@ struct TCGCPUOps {#else /** @do_interrupt: Callback for interrupt handling. */ void (*do_interrupt)(CPUState *cpu); -/** @cpu_exec_interrupt: Callback for processing interrupts in cpu_exec */ + +/** +* @cpu_exec_interrupt: Callback for processing target-specific interrupts +* @cpu: cpu context +* @interrupt_request: Bitmask of pending interrupts +* +* Called from cpu_handle_interrupt() with the BQL held. Process the +* pending interrupt according to the target specific @interrupt_request +* masking rules. +* +* Returns: %true if an interrupt was processed and the next TB should +* be restarted, %false to continue normal execution. +*/ bool (*cpu_exec_interrupt)(CPUState *cpu,int interrupt_request); +/** @cpu_exec_reset: Callback for reset in cpu_exec. */ void (*cpu_exec_reset)(CPUState *cpu);/**
target/arm/internals.h +1 -1
@@ -1248,7 +1248,7 @@ static inline const char *aarch32_mode_name(uint32_t psr) }/** -* arm_cpu_exec_interrupt(): Implementation of the cpu_exec_inrerrupt hook. +* arm_cpu_exec_interrupt(): Implementation of the cpu_exec_interrupt hook. */ bool arm_cpu_exec_interrupt (CPUState *cs,int interrupt_request);
Signature · 1 line
2.53.0
PATCH v3 6/11 accel/tcg: Rename do_interrupt() to do_interrupt_locked()
In reply to Philippe Mathieu-DaudéFrom: Robert Foley <[email protected]>
Prepare for pushing BQL locking down to per-target implementations. The old do_interrupt() name will later be reused for a wrapper that acquires BQL and calls do_interrupt_locked(), enabling targets to eventually remove BQL from the cpu_handle_interrupt/exception paths.
--- include/accel/tcg/cpu-ops.h | 4 ++-- accel/tcg/cpu-exec.c | 4 ++-- target/alpha/cpu.c | 2 +- target/arm/cpu.c | 2 +- target/arm/tcg/cpu-v7m.c | 2 +- target/avr/cpu.c | 2 +- target/hexagon/cpu.c | 2 +- target/hppa/cpu.c | 2 +- target/i386/tcg/tcg-cpu.c | 2 +- target/loongarch/tcg/tcg_cpu.c | 2 +- target/m68k/cpu.c | 2 +- target/microblaze/cpu.c | 2 +- target/mips/cpu.c | 2 +- target/or1k/cpu.c | 2 +- target/ppc/cpu_init.c | 2 +- target/riscv/tcg/tcg-cpu.c | 2 +- target/rx/cpu.c | 2 +- target/s390x/cpu.c | 2 +- target/sh4/cpu.c | 2 +- target/sparc/cpu.c | 2 +- target/xtensa/cpu.c | 2 +- 21 files changed, 23 insertions(+), 23 deletions(-)
include/accel/tcg/cpu-ops.h +2 -2
@@ -170,7 +170,7 @@ struct TCGCPUOps {vaddr (*untagged_addr)(CPUState *cs,vaddr addr);#else /** -* @do_interrupt: Deliver a pending exception/interrupt to the CPU +* @do_interrupt_locked: Deliver a pending exception/interrupt to the CPU * @cpu: cpu context * * Called when cs->exception_index contains an exception code to deliver.
@@ -179,7 +179,7 @@ struct TCGCPUOps {* * Called from cpu_handle_exception() with BQL held. */ -void (*do_interrupt)(CPUState *cpu); +void (*do_interrupt_locked)(CPUState *cpu);/** * @cpu_exec_interrupt: Callback for processing target-specific interrupts
accel/tcg/cpu-exec.c +2 -2
@@ -728,7 +728,7 @@ static inline bool cpu_handle_exception(CPUState *cpu, int *ret)const TCGCPUOps *tcg_ops = cpu->cc->tcg_ops;bql_lock (); - tcg_ops->do_interrupt (cpu); + tcg_ops->do_interrupt_locked (cpu);bql_unlock (); cpu->exception_index =-1 ;
@@ -1059,7 +1059,7 @@ bool tcg_exec_realizefn(CPUState *cpu, Error **errp)assert (tcg_ops->cpu_exec_halt);assert (tcg_ops->cpu_exec_interrupt);assert (tcg_ops->cpu_exec_reset); -assert (tcg_ops->do_interrupt); +assert (tcg_ops->do_interrupt_locked);assert (tcg_ops->pointer_wrap);#endif /* !CONFIG_USER_ONLY */ assert (tcg_ops->translate_code);
target/alpha/cpu.c +1 -1
@@ -267,7 +267,7 @@ static const TCGCPUOps alpha_tcg_ops = { .cpu_exec_interrupt = alpha_cpu_exec_interrupt, .cpu_exec_halt = alpha_cpu_has_work, .cpu_exec_reset = cpu_reset, - .do_interrupt = alpha_cpu_do_interrupt, + .do_interrupt_locked = alpha_cpu_do_interrupt, .do_transaction_failed = alpha_cpu_do_transaction_failed, .do_unaligned_access = alpha_cpu_do_unaligned_access,#endif /* !CONFIG_USER_ONLY */
target/arm/cpu.c +1 -1
@@ -2606,7 +2606,7 @@ static const TCGCPUOps arm_tcg_ops = { .cpu_exec_interrupt = arm_cpu_exec_interrupt, .cpu_exec_halt = arm_cpu_exec_halt, .cpu_exec_reset = cpu_reset, - .do_interrupt = arm_cpu_do_interrupt, + .do_interrupt_locked = arm_cpu_do_interrupt, .do_transaction_failed = arm_cpu_do_transaction_failed, .do_unaligned_access = arm_cpu_do_unaligned_access, .adjust_watchpoint_address = arm_adjust_watchpoint_address,
target/arm/tcg/cpu-v7m.c +1 -1
@@ -304,7 +304,7 @@ static const TCGCPUOps arm_v7m_tcg_ops = { .cpu_exec_interrupt = arm_v7m_cpu_exec_interrupt, .cpu_exec_halt = arm_cpu_exec_halt, .cpu_exec_reset = cpu_reset, - .do_interrupt = arm_v7m_cpu_do_interrupt, + .do_interrupt_locked = arm_v7m_cpu_do_interrupt, .do_transaction_failed = arm_cpu_do_transaction_failed, .do_unaligned_access = arm_cpu_do_unaligned_access, .adjust_watchpoint_address = arm_adjust_watchpoint_address,
target/avr/cpu.c +1 -1
@@ -249,7 +249,7 @@ static const TCGCPUOps avr_tcg_ops = { .cpu_exec_halt = avr_cpu_has_work, .cpu_exec_reset = cpu_reset, .tlb_fill = avr_cpu_tlb_fill, - .do_interrupt = avr_cpu_do_interrupt, + .do_interrupt_locked = avr_cpu_do_interrupt,/* * TODO: code and data wrapping are different, but for the most part * AVR only references bytes or aligned code fetches. But we use
target/hexagon/cpu.c +1 -1
@@ -769,7 +769,7 @@ static const TCGCPUOps hexagon_tcg_ops = { .tlb_fill = hexagon_tlb_fill, .do_unaligned_access = hexagon_cpu_do_unaligned_access, .cpu_exec_halt = hexagon_cpu_has_work, - .do_interrupt = hexagon_cpu_do_interrupt, + .do_interrupt_locked = hexagon_cpu_do_interrupt,#endif /* !CONFIG_USER_ONLY */ };
target/hppa/cpu.c +1 -1
@@ -272,7 +272,7 @@ static const TCGCPUOps hppa_tcg_ops = { .cpu_exec_interrupt = hppa_cpu_exec_interrupt, .cpu_exec_halt = hppa_cpu_has_work, .cpu_exec_reset = cpu_reset, - .do_interrupt = hppa_cpu_do_interrupt, + .do_interrupt_locked = hppa_cpu_do_interrupt, .do_unaligned_access = hppa_cpu_do_unaligned_access, .do_transaction_failed = hppa_cpu_do_transaction_failed,#endif /* !CONFIG_USER_ONLY */
target/i386/tcg/tcg-cpu.c +1 -1
@@ -179,7 +179,7 @@ const TCGCPUOps x86_tcg_ops = {#else .tlb_fill = x86_cpu_tlb_fill, .pointer_wrap = x86_pointer_wrap, - .do_interrupt = x86_cpu_do_interrupt, + .do_interrupt_locked = x86_cpu_do_interrupt, .cpu_exec_halt = x86_cpu_exec_halt, .cpu_exec_interrupt = x86_cpu_exec_interrupt, .cpu_exec_reset = x86_cpu_exec_reset,
target/loongarch/tcg/tcg_cpu.c +1 -1
@@ -329,7 +329,7 @@ const TCGCPUOps loongarch_tcg_ops = { .cpu_exec_interrupt = loongarch_cpu_exec_interrupt, .cpu_exec_halt = loongarch_cpu_has_work, .cpu_exec_reset = cpu_reset, - .do_interrupt = loongarch_cpu_do_interrupt, + .do_interrupt_locked = loongarch_cpu_do_interrupt, .do_transaction_failed = loongarch_cpu_do_transaction_failed,#endif };
target/m68k/cpu.c +1 -1
@@ -712,7 +712,7 @@ static const TCGCPUOps m68k_tcg_ops = { .cpu_exec_interrupt = m68k_cpu_exec_interrupt, .cpu_exec_halt = m68k_cpu_has_work, .cpu_exec_reset = cpu_reset, - .do_interrupt = m68k_cpu_do_interrupt, + .do_interrupt_locked = m68k_cpu_do_interrupt, .do_transaction_failed = m68k_cpu_transaction_failed,#endif /* !CONFIG_USER_ONLY */ };
target/microblaze/cpu.c +1 -1
@@ -450,7 +450,7 @@ static const TCGCPUOps mb_tcg_ops = { .cpu_exec_interrupt = mb_cpu_exec_interrupt, .cpu_exec_halt = mb_cpu_has_work, .cpu_exec_reset = cpu_reset, - .do_interrupt = mb_cpu_do_interrupt, + .do_interrupt_locked = mb_cpu_do_interrupt, .do_transaction_failed = mb_cpu_transaction_failed, .do_unaligned_access = mb_cpu_do_unaligned_access,#endif /* !CONFIG_USER_ONLY */
target/mips/cpu.c +1 -1
@@ -718,7 +718,7 @@ static const TCGCPUOps mips_tcg_ops = { .cpu_exec_interrupt = mips_cpu_exec_interrupt, .cpu_exec_halt = mips_cpu_has_work, .cpu_exec_reset = cpu_reset, - .do_interrupt = mips_cpu_do_interrupt, + .do_interrupt_locked = mips_cpu_do_interrupt, .do_transaction_failed = mips_cpu_do_transaction_failed, .do_unaligned_access = mips_cpu_do_unaligned_access, .io_recompile_replay_branch = mips_io_recompile_replay_branch,
target/or1k/cpu.c +1 -1
@@ -268,7 +268,7 @@ static const TCGCPUOps openrisc_tcg_ops = { .cpu_exec_interrupt = openrisc_cpu_exec_interrupt, .cpu_exec_halt = openrisc_cpu_has_work, .cpu_exec_reset = cpu_reset, - .do_interrupt = openrisc_cpu_do_interrupt, + .do_interrupt_locked = openrisc_cpu_do_interrupt,#endif /* !CONFIG_USER_ONLY */ };
target/ppc/cpu_init.c +1 -1
@@ -7498,7 +7498,7 @@ static const TCGCPUOps ppc_tcg_ops = { .cpu_exec_interrupt = ppc_cpu_exec_interrupt, .cpu_exec_halt = ppc_cpu_has_work, .cpu_exec_reset = cpu_reset, - .do_interrupt = ppc_cpu_do_interrupt, + .do_interrupt_locked = ppc_cpu_do_interrupt, .cpu_exec_enter = ppc_cpu_exec_enter, .cpu_exec_exit = ppc_cpu_exec_exit, .do_unaligned_access = ppc_cpu_do_unaligned_access,
target/riscv/tcg/tcg-cpu.c +1 -1
@@ -289,7 +289,7 @@ const TCGCPUOps riscv_tcg_ops = { .cpu_exec_interrupt = riscv_cpu_exec_interrupt, .cpu_exec_halt = riscv_cpu_has_work, .cpu_exec_reset = cpu_reset, - .do_interrupt = riscv_cpu_do_interrupt, + .do_interrupt_locked = riscv_cpu_do_interrupt, .do_transaction_failed = riscv_cpu_do_transaction_failed, .do_unaligned_access = riscv_cpu_do_unaligned_access, .debug_excp_handler = riscv_cpu_debug_excp_handler,
target/rx/cpu.c +1 -1
@@ -229,7 +229,7 @@ static const TCGCPUOps rx_tcg_ops = { .cpu_exec_interrupt = rx_cpu_exec_interrupt, .cpu_exec_halt = rx_cpu_has_work, .cpu_exec_reset = cpu_reset, - .do_interrupt = rx_cpu_do_interrupt, + .do_interrupt_locked = rx_cpu_do_interrupt, };static void rx_cpu_class_init (ObjectClass *klass,const void *data)
target/s390x/cpu.c +1 -1
@@ -386,7 +386,7 @@ static const TCGCPUOps s390_tcg_ops = { .cpu_exec_interrupt = s390_cpu_exec_interrupt, .cpu_exec_halt = s390_cpu_has_work, .cpu_exec_reset = cpu_reset, - .do_interrupt = s390_cpu_do_interrupt, + .do_interrupt_locked = s390_cpu_do_interrupt, .debug_excp_handler = s390x_cpu_debug_excp_handler, .do_unaligned_access = s390x_cpu_do_unaligned_access,#endif /* !CONFIG_USER_ONLY */
target/sh4/cpu.c +1 -1
@@ -314,7 +314,7 @@ static const TCGCPUOps superh_tcg_ops = { .cpu_exec_interrupt = superh_cpu_exec_interrupt, .cpu_exec_halt = superh_cpu_has_work, .cpu_exec_reset = cpu_reset, - .do_interrupt = superh_cpu_do_interrupt, + .do_interrupt_locked = superh_cpu_do_interrupt, .do_unaligned_access = superh_cpu_do_unaligned_access, .io_recompile_replay_branch = superh_io_recompile_replay_branch,#endif /* !CONFIG_USER_ONLY */
target/sparc/cpu.c +1 -1
@@ -1076,7 +1076,7 @@ static const TCGCPUOps sparc_tcg_ops = { .cpu_exec_interrupt = sparc_cpu_exec_interrupt, .cpu_exec_halt = sparc_cpu_has_work, .cpu_exec_reset = cpu_reset, - .do_interrupt = sparc_cpu_do_interrupt, + .do_interrupt_locked = sparc_cpu_do_interrupt, .do_transaction_failed = sparc_cpu_do_transaction_failed, .do_unaligned_access = sparc_cpu_do_unaligned_access,#endif /* !CONFIG_USER_ONLY */
target/xtensa/cpu.c +1 -1
@@ -327,7 +327,7 @@ static const TCGCPUOps xtensa_tcg_ops = { .cpu_exec_interrupt = xtensa_cpu_exec_interrupt, .cpu_exec_halt = xtensa_cpu_has_work, .cpu_exec_reset = cpu_reset, - .do_interrupt = xtensa_cpu_do_interrupt, + .do_interrupt_locked = xtensa_cpu_do_interrupt, .do_transaction_failed = xtensa_cpu_do_transaction_failed, .do_unaligned_access = xtensa_cpu_do_unaligned_access, .debug_check_breakpoint = xtensa_debug_check_breakpoint,
Signature · 1 line
2.53.0
PATCH v3 7/11 accel/tcg: Add do_interrupt() wrapper for targets to manage BQL
In reply to Philippe Mathieu-DaudéAdd TCGCPUOps::do_interrupt() as a wrapper that targets can implement to control BQL locking independently. The existing do_interrupt_locked() callback remains for BQL-held contexts. This allows each target to decide when to acquire the BQL.
--- include/accel/tcg/cpu-ops.h | 14 ++++++++++++++ accel/tcg/cpu-exec.c | 12 ++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-)
include/accel/tcg/cpu-ops.h +14 -0
@@ -169,6 +169,20 @@ struct TCGCPUOps {*/ vaddr (*untagged_addr)(CPUState *cs,vaddr addr);#else +/** +* @do_interrupt: Deliver a pending exception/interrupt to the CPU +* +* Called when cs->exception_index contains the exception code to deliver. +* Updates CPU architectural state (usually before executing a guest +* exception handler). +* +* Called from cpu_handle_exception(). Implementations must acquire the +* BQL before modifying CPU state and hold it for the duration of the +* handler (this ensures safe access to shared CPU and device state during +* exception delivery, which may be cross-vCPU). +*/ +void (*do_interrupt)(CPUState *cpu); +/** * @do_interrupt_locked: Deliver a pending exception/interrupt to the CPU * @cpu: cpu context
accel/tcg/cpu-exec.c +8 -4
@@ -727,9 +727,13 @@ static inline bool cpu_handle_exception(CPUState *cpu, int *ret)if (replay_exception ()) {const TCGCPUOps *tcg_ops = cpu->cc->tcg_ops; -bql_lock (); - tcg_ops->do_interrupt_locked (cpu); -bql_unlock (); +if (tcg_ops->do_interrupt) { + tcg_ops->do_interrupt (cpu); + }else { +bql_lock (); + tcg_ops->do_interrupt_locked (cpu); +bql_unlock (); + } cpu->exception_index =-1 ;if (unlikely (cpu_single_stepping (cpu))) {
@@ -1059,7 +1063,7 @@ bool tcg_exec_realizefn(CPUState *cpu, Error **errp)assert (tcg_ops->cpu_exec_halt);assert (tcg_ops->cpu_exec_interrupt);assert (tcg_ops->cpu_exec_reset); -assert (tcg_ops->do_interrupt_locked); +assert (tcg_ops->do_interrupt || tcg_ops->do_interrupt_locked);assert (tcg_ops->pointer_wrap);#endif /* !CONFIG_USER_ONLY */ assert (tcg_ops->translate_code);
Signature · 1 line
2.53.0
PATCH v3 1/11 target/arm: Call arm*_cpu_do_interrupt directly instead of via TCGCPUOps
In reply to Philippe Mathieu-DaudéThe TCGCPUOps.do_interrupt handler is a target-specific callback installed for use by target-agnostic TCG core methods. Target-specific code should not dispatch through this indirection; call the ARM implementation directly instead.
--- target/arm/cpu-irq.c | 2 +- target/arm/tcg/cpu-v7m.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
target/arm/cpu-irq.c +1 -1
@@ -270,7 +270,7 @@ bool arm_cpu_exec_interrupt(CPUState *cs, int interrupt_request) found: cs->exception_index = excp_idx; env->exception.target_el = target_el; - cs->cc->tcg_ops->do_interrupt (cs); +arm_cpu_do_interrupt (cs); return true; }#endif /* CONFIG_TCG */
target/arm/tcg/cpu-v7m.c +1 -1
@@ -34,7 +34,7 @@ static bool arm_v7m_cpu_exec_interrupt(CPUState *cs, int interrupt_request)if (interrupt_request &CPU_INTERRUPT_HARD && (armv7m_nvic_can_take_pending_exception (env->nvic))) { cs->exception_index =EXCP_IRQ ; - cs->cc->tcg_ops->do_interrupt (cs); +arm_v7m_cpu_do_interrupt (cs); ret = true; }return ret;
Signature · 1 line
2.53.0
PATCH v3 8/11 target/hexagon: Move to do_interrupt() (BQL acquired internally)
In reply to Philippe Mathieu-Daudéhexagon_cpu_do_interrupt() already acquires the BQL internally, so register it as do_interrupt() instead of do_interrupt_locked(). This reflects the actual locking model used by the target.
--- target/hexagon/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/hexagon/cpu.c +1 -1
@@ -769,7 +769,7 @@ static const TCGCPUOps hexagon_tcg_ops = { .tlb_fill = hexagon_tlb_fill, .do_unaligned_access = hexagon_cpu_do_unaligned_access, .cpu_exec_halt = hexagon_cpu_has_work, - .do_interrupt_locked = hexagon_cpu_do_interrupt, + .do_interrupt = hexagon_cpu_do_interrupt,#endif /* !CONFIG_USER_ONLY */ };
Signature · 1 line
2.53.0
RFC PATCH v3 10/11 targets: Move BQL locking into do_interrupt() handlers
In reply to Philippe Mathieu-DaudéMigrate 13 targets to acquire the BQL explicitly within their do_interrupt() implementations instead of relying on the TCG core to hold it. This allows per-target control over locking granularity and paves the way for fine-grained BQL optimization.
--- target/alpha/cpu.c | 2 +- target/alpha/helper.c | 3 +++ target/arm/cpu.c | 2 +- target/arm/helper.c | 1 + target/arm/tcg/cpu-v7m.c | 2 +- target/arm/tcg/m_helper.c | 2 ++ target/avr/cpu.c | 2 +- target/avr/helper.c | 3 +++ target/hppa/cpu.c | 2 +- target/hppa/int_helper.c | 2 ++ target/i386/tcg/system/seg_helper.c | 2 ++ target/i386/tcg/tcg-cpu.c | 2 +- target/mips/cpu.c | 2 +- target/mips/tcg/system/tlb_helper.c | 3 +++ target/ppc/cpu_init.c | 2 +- target/ppc/excp_helper.c | 2 ++ target/riscv/tcg/tcg-cpu.c | 2 +- target/rx/cpu.c | 2 +- target/rx/helper.c | 3 +++ target/s390x/cpu.c | 2 +- target/s390x/tcg/excp_helper.c | 3 +++ target/sh4/cpu.c | 2 +- target/sh4/helper.c | 3 +++ target/sparc/cpu.c | 2 +- target/sparc/int32_helper.c | 2 ++ target/sparc/int64_helper.c | 2 ++ target/xtensa/cpu.c | 2 +- target/xtensa/exc_helper.c | 2 ++ 28 files changed, 47 insertions(+), 14 deletions(-)
target/alpha/cpu.c +1 -1
@@ -267,7 +267,7 @@ static const TCGCPUOps alpha_tcg_ops = { .cpu_exec_interrupt = alpha_cpu_exec_interrupt, .cpu_exec_halt = alpha_cpu_has_work, .cpu_exec_reset = cpu_reset, - .do_interrupt_locked = alpha_cpu_do_interrupt, + .do_interrupt = alpha_cpu_do_interrupt, .do_transaction_failed = alpha_cpu_do_transaction_failed, .do_unaligned_access = alpha_cpu_do_unaligned_access,#endif /* !CONFIG_USER_ONLY */
target/alpha/helper.c +3 -0
@@ -26,6 +26,7 @@#include "fpu/softfloat-types.h" #include "fpu/softfloat-helpers.h" #include "exec/helper-proto.h" +#include "qemu/main-loop.h" #include "qemu/qemu-print.h" #include "system/memory.h" #include "accel/tcg/cpu-loop.h"
@@ -341,6 +342,8 @@ void alpha_cpu_do_interrupt(CPUState *cs)int i = cs->exception_index;uint64_t last_pc = env->pc; +BQL_LOCK_GUARD (); +if (qemu_loglevel_mask (CPU_LOG_INT )) {static int count;const char *name ="<unknown>" ;
target/arm/cpu.c +1 -1
@@ -2606,7 +2606,7 @@ static const TCGCPUOps arm_tcg_ops = { .cpu_exec_interrupt = arm_cpu_exec_interrupt, .cpu_exec_halt = arm_cpu_exec_halt, .cpu_exec_reset = cpu_reset, - .do_interrupt_locked = arm_cpu_do_interrupt, + .do_interrupt = arm_cpu_do_interrupt, .do_transaction_failed = arm_cpu_do_transaction_failed, .do_unaligned_access = arm_cpu_do_unaligned_access, .adjust_watchpoint_address = arm_adjust_watchpoint_address,
target/arm/helper.c +1 -0
@@ -9714,6 +9714,7 @@ void arm_cpu_do_interrupt(CPUState *cs)uint64_t last_pc = cs->cc->get_pc (cs);assert (!arm_feature (env,ARM_FEATURE_M )); +BQL_LOCK_GUARD ();arm_log_exception (cs); qemu_log_mask(CPU_LOG_INT, "...from EL%d to EL%d\n", arm_current_el(env),
target/arm/tcg/cpu-v7m.c +1 -1
@@ -304,7 +304,7 @@ static const TCGCPUOps arm_v7m_tcg_ops = { .cpu_exec_interrupt = arm_v7m_cpu_exec_interrupt, .cpu_exec_halt = arm_cpu_exec_halt, .cpu_exec_reset = cpu_reset, - .do_interrupt_locked = arm_v7m_cpu_do_interrupt, + .do_interrupt = arm_v7m_cpu_do_interrupt, .do_transaction_failed = arm_cpu_do_transaction_failed, .do_unaligned_access = arm_cpu_do_unaligned_access, .adjust_watchpoint_address = arm_adjust_watchpoint_address,
target/arm/tcg/m_helper.c +2 -0
@@ -2214,6 +2214,8 @@ void arm_v7m_cpu_do_interrupt(CPUState *cs)bool ignore_stackfaults;uint64_t last_pc = env->regs[15 ]; +BQL_LOCK_GUARD (); +arm_log_exception (cs);/*
target/avr/cpu.c +1 -1
@@ -249,7 +249,7 @@ static const TCGCPUOps avr_tcg_ops = { .cpu_exec_halt = avr_cpu_has_work, .cpu_exec_reset = cpu_reset, .tlb_fill = avr_cpu_tlb_fill, - .do_interrupt_locked = avr_cpu_do_interrupt, + .do_interrupt = avr_cpu_do_interrupt,/* * TODO: code and data wrapping are different, but for the most part * AVR only references bytes or aligned code fetches. But we use
target/avr/helper.c +3 -0
@@ -21,6 +21,7 @@#include "qemu/osdep.h" #include "qemu/log.h" #include "qemu/error-report.h" +#include "qemu/main-loop.h" #include "cpu.h" #include "accel/tcg/cpu-ops.h" #include "accel/tcg/cpu-loop.h"
@@ -89,6 +90,8 @@ void avr_cpu_do_interrupt(CPUState *cs) vector =ctz64 (env->intsrc) +1 ; } +BQL_LOCK_GUARD (); +if (avr_feature (env,AVR_FEATURE_3_BYTE_PC )) {do_stb (env, env->sp--, ret,0 );do_stb (env, env->sp--, ret >>8 ,0 );
target/hppa/cpu.c +1 -1
@@ -272,7 +272,7 @@ static const TCGCPUOps hppa_tcg_ops = { .cpu_exec_interrupt = hppa_cpu_exec_interrupt, .cpu_exec_halt = hppa_cpu_has_work, .cpu_exec_reset = cpu_reset, - .do_interrupt_locked = hppa_cpu_do_interrupt, + .do_interrupt = hppa_cpu_do_interrupt, .do_unaligned_access = hppa_cpu_do_unaligned_access, .do_transaction_failed = hppa_cpu_do_transaction_failed,#endif /* !CONFIG_USER_ONLY */
target/hppa/int_helper.c +2 -0
@@ -98,6 +98,8 @@ void hppa_cpu_do_interrupt(CPUState *cs)uint64_t old_psw, old_gva_offset_mask;uint64_t last_pc = cs->cc->get_pc (cs); +BQL_LOCK_GUARD (); +/* As documented in pa2.0 -- interruption handling. */ /* step 1 */ env->cr[CR_IPSW ] = old_psw =cpu_hppa_get_psw (env);
target/i386/tcg/system/seg_helper.c +2 -0
@@ -115,6 +115,8 @@ void x86_cpu_do_interrupt(CPUState *cs)X86CPU *cpu =X86_CPU (cs);CPUX86State *env = &cpu->env; +BQL_LOCK_GUARD (); +if (cs->exception_index ==EXCP_VMEXIT ) {assert (env->old_exception ==-1 );do_vmexit (env);
target/i386/tcg/tcg-cpu.c +1 -1
@@ -179,7 +179,7 @@ const TCGCPUOps x86_tcg_ops = {#else .tlb_fill = x86_cpu_tlb_fill, .pointer_wrap = x86_pointer_wrap, - .do_interrupt_locked = x86_cpu_do_interrupt, + .do_interrupt = x86_cpu_do_interrupt, .cpu_exec_halt = x86_cpu_exec_halt, .cpu_exec_interrupt = x86_cpu_exec_interrupt, .cpu_exec_reset = x86_cpu_exec_reset,
target/mips/cpu.c +1 -1
@@ -718,7 +718,7 @@ static const TCGCPUOps mips_tcg_ops = { .cpu_exec_interrupt = mips_cpu_exec_interrupt, .cpu_exec_halt = mips_cpu_has_work, .cpu_exec_reset = cpu_reset, - .do_interrupt_locked = mips_cpu_do_interrupt, + .do_interrupt = mips_cpu_do_interrupt, .do_transaction_failed = mips_cpu_do_transaction_failed, .do_unaligned_access = mips_cpu_do_unaligned_access, .io_recompile_replay_branch = mips_io_recompile_replay_branch,
target/mips/tcg/system/tlb_helper.c +3 -0
@@ -18,6 +18,7 @@*/ #include "qemu/osdep.h" #include "qemu/bitops.h" +#include "qemu/main-loop.h" #include "qemu/plugin.h" #include "cpu.h"
@@ -1045,6 +1046,8 @@ void mips_cpu_do_interrupt(CPUState *cs)int cause =-1 ;uint64_t last_pc = env->active_tc.PC; +BQL_LOCK_GUARD (); +if (qemu_loglevel_mask (CPU_LOG_INT ) && cs->exception_index !=EXCP_EXT_INTERRUPT ) { qemu_log("%s enter: PC " TARGET_FMT_lx " EPC " TARGET_FMT_lx
target/ppc/cpu_init.c +1 -1
@@ -7498,7 +7498,7 @@ static const TCGCPUOps ppc_tcg_ops = { .cpu_exec_interrupt = ppc_cpu_exec_interrupt, .cpu_exec_halt = ppc_cpu_has_work, .cpu_exec_reset = cpu_reset, - .do_interrupt_locked = ppc_cpu_do_interrupt, + .do_interrupt = ppc_cpu_do_interrupt, .cpu_exec_enter = ppc_cpu_exec_enter, .cpu_exec_exit = ppc_cpu_exec_exit, .do_unaligned_access = ppc_cpu_do_unaligned_access,
target/ppc/excp_helper.c +2 -0
@@ -1761,6 +1761,8 @@ void ppc_cpu_do_interrupt(CPUState *cs) {PowerPCCPU *cpu =POWERPC_CPU (cs); +BQL_LOCK_GUARD (); +powerpc_excp (cpu, cs->exception_index); }
target/riscv/tcg/tcg-cpu.c +1 -1
@@ -289,7 +289,7 @@ const TCGCPUOps riscv_tcg_ops = { .cpu_exec_interrupt = riscv_cpu_exec_interrupt, .cpu_exec_halt = riscv_cpu_has_work, .cpu_exec_reset = cpu_reset, - .do_interrupt_locked = riscv_cpu_do_interrupt, + .do_interrupt = riscv_cpu_do_interrupt, .do_transaction_failed = riscv_cpu_do_transaction_failed, .do_unaligned_access = riscv_cpu_do_unaligned_access, .debug_excp_handler = riscv_cpu_debug_excp_handler,
target/rx/cpu.c +1 -1
@@ -229,7 +229,7 @@ static const TCGCPUOps rx_tcg_ops = { .cpu_exec_interrupt = rx_cpu_exec_interrupt, .cpu_exec_halt = rx_cpu_has_work, .cpu_exec_reset = cpu_reset, - .do_interrupt_locked = rx_cpu_do_interrupt, + .do_interrupt = rx_cpu_do_interrupt, };static void rx_cpu_class_init (ObjectClass *klass,const void *data)
target/rx/helper.c +3 -0
@@ -18,6 +18,7 @@#include "qemu/osdep.h" #include "qemu/bitops.h" +#include "qemu/main-loop.h" #include "cpu.h" #include "exec/log.h" #include "accel/tcg/cpu-ldst.h"
@@ -47,6 +48,8 @@ void rx_cpu_do_interrupt(CPUState *cs)uint32_t save_psw;uint64_t last_pc = env->pc; +BQL_LOCK_GUARD (); + env->in_sleep =0 ;if (env->psw_u) {
target/s390x/cpu.c +1 -1
@@ -386,7 +386,7 @@ static const TCGCPUOps s390_tcg_ops = { .cpu_exec_interrupt = s390_cpu_exec_interrupt, .cpu_exec_halt = s390_cpu_has_work, .cpu_exec_reset = cpu_reset, - .do_interrupt_locked = s390_cpu_do_interrupt, + .do_interrupt = s390_cpu_do_interrupt, .debug_excp_handler = s390x_cpu_debug_excp_handler, .do_unaligned_access = s390x_cpu_do_unaligned_access,#endif /* !CONFIG_USER_ONLY */
target/s390x/tcg/excp_helper.c +3 -0
@@ -28,6 +28,7 @@#include "s390x-internal.h" #include "tcg_s390x.h" #ifndef CONFIG_USER_ONLY +#include "qemu/main-loop.h" #include "qemu/timer.h" #include "system/address-spaces.h" #include "system/memory.h"
@@ -503,6 +504,8 @@ void s390_cpu_do_interrupt(CPUState *cs)bool stopped = false;uint64_t last_pc = cpu->env.psw.addr; +BQL_LOCK_GUARD (); +qemu_log_mask (CPU_LOG_INT ,"%s: %d at psw=%" PRIx64":%" PRIx64"\n" , __func__, cs->exception_index, env->psw.mask, env->psw.addr);
target/sh4/cpu.c +1 -1
@@ -314,7 +314,7 @@ static const TCGCPUOps superh_tcg_ops = { .cpu_exec_interrupt = superh_cpu_exec_interrupt, .cpu_exec_halt = superh_cpu_has_work, .cpu_exec_reset = cpu_reset, - .do_interrupt_locked = superh_cpu_do_interrupt, + .do_interrupt = superh_cpu_do_interrupt, .do_unaligned_access = superh_cpu_do_unaligned_access, .io_recompile_replay_branch = superh_io_recompile_replay_branch,#endif /* !CONFIG_USER_ONLY */
target/sh4/helper.c +3 -0
@@ -28,6 +28,7 @@#include "qemu/plugin.h" #if !defined(CONFIG_USER_ONLY ) +#include "qemu/main-loop.h" #include "hw/sh4/sh_intc.h" #include "system/runstate.h" #endif
@@ -64,6 +65,8 @@ void superh_cpu_do_interrupt(CPUState *cs)int do_exp, irq_vector = cs->exception_index;uint64_t last_pc = env->pc; +BQL_LOCK_GUARD (); +/* prioritize exceptions over interrupts */ do_exp = cs->exception_index !=-1 ;
target/sparc/cpu.c +1 -1
@@ -1076,7 +1076,7 @@ static const TCGCPUOps sparc_tcg_ops = { .cpu_exec_interrupt = sparc_cpu_exec_interrupt, .cpu_exec_halt = sparc_cpu_has_work, .cpu_exec_reset = cpu_reset, - .do_interrupt_locked = sparc_cpu_do_interrupt, + .do_interrupt = sparc_cpu_do_interrupt, .do_transaction_failed = sparc_cpu_do_transaction_failed, .do_unaligned_access = sparc_cpu_do_unaligned_access,#endif /* !CONFIG_USER_ONLY */
target/sparc/int32_helper.c +2 -0
@@ -105,6 +105,8 @@ void sparc_cpu_do_interrupt(CPUState *cs)CPUSPARCState *env =cpu_env (cs);int cwp, intno = cs->exception_index; +BQL_LOCK_GUARD (); +if (qemu_loglevel_mask (CPU_LOG_INT )) {static int count;const char *name;
target/sparc/int64_helper.c +2 -0
@@ -138,6 +138,8 @@ void sparc_cpu_do_interrupt(CPUState *cs)int intno = cs->exception_index;trap_state *tsptr; +BQL_LOCK_GUARD (); +#ifdef DEBUG_PCALL if (qemu_loglevel_mask (CPU_LOG_INT )) {static int count;
target/xtensa/cpu.c +1 -1
@@ -327,7 +327,7 @@ static const TCGCPUOps xtensa_tcg_ops = { .cpu_exec_interrupt = xtensa_cpu_exec_interrupt, .cpu_exec_halt = xtensa_cpu_has_work, .cpu_exec_reset = cpu_reset, - .do_interrupt_locked = xtensa_cpu_do_interrupt, + .do_interrupt = xtensa_cpu_do_interrupt, .do_transaction_failed = xtensa_cpu_do_transaction_failed, .do_unaligned_access = xtensa_cpu_do_unaligned_access, .debug_check_breakpoint = xtensa_debug_check_breakpoint,
target/xtensa/exc_helper.c +2 -0
@@ -208,6 +208,8 @@ void xtensa_cpu_do_interrupt(CPUState *cs) {CPUXtensaState *env =cpu_env (cs); +BQL_LOCK_GUARD (); +if (cs->exception_index ==EXC_IRQ ) {uint64_t last_pc = env->pc;
Signature · 1 line
2.53.0
RFC PATCH v3 9/11 targets: Move interrupt handlers to do_interrupt()
In reply to Philippe Mathieu-DaudéLoongArch, M68K, MicroBlaze, and OpenRISC interrupt handlers don't require external BQL protection, so move them from do_interrupt_locked() to do_interrupt().
--- target/loongarch/tcg/tcg_cpu.c | 2 +- target/m68k/cpu.c | 2 +- target/microblaze/cpu.c | 2 +- target/or1k/cpu.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)
target/loongarch/tcg/tcg_cpu.c +1 -1
@@ -329,7 +329,7 @@ const TCGCPUOps loongarch_tcg_ops = { .cpu_exec_interrupt = loongarch_cpu_exec_interrupt, .cpu_exec_halt = loongarch_cpu_has_work, .cpu_exec_reset = cpu_reset, - .do_interrupt_locked = loongarch_cpu_do_interrupt, + .do_interrupt = loongarch_cpu_do_interrupt, .do_transaction_failed = loongarch_cpu_do_transaction_failed,#endif };
target/m68k/cpu.c +1 -1
@@ -712,7 +712,7 @@ static const TCGCPUOps m68k_tcg_ops = { .cpu_exec_interrupt = m68k_cpu_exec_interrupt, .cpu_exec_halt = m68k_cpu_has_work, .cpu_exec_reset = cpu_reset, - .do_interrupt_locked = m68k_cpu_do_interrupt, + .do_interrupt = m68k_cpu_do_interrupt, .do_transaction_failed = m68k_cpu_transaction_failed,#endif /* !CONFIG_USER_ONLY */ };
target/microblaze/cpu.c +1 -1
@@ -450,7 +450,7 @@ static const TCGCPUOps mb_tcg_ops = { .cpu_exec_interrupt = mb_cpu_exec_interrupt, .cpu_exec_halt = mb_cpu_has_work, .cpu_exec_reset = cpu_reset, - .do_interrupt_locked = mb_cpu_do_interrupt, + .do_interrupt = mb_cpu_do_interrupt, .do_transaction_failed = mb_cpu_transaction_failed, .do_unaligned_access = mb_cpu_do_unaligned_access,#endif /* !CONFIG_USER_ONLY */
target/or1k/cpu.c +1 -1
@@ -268,7 +268,7 @@ static const TCGCPUOps openrisc_tcg_ops = { .cpu_exec_interrupt = openrisc_cpu_exec_interrupt, .cpu_exec_halt = openrisc_cpu_has_work, .cpu_exec_reset = cpu_reset, - .do_interrupt_locked = openrisc_cpu_do_interrupt, + .do_interrupt = openrisc_cpu_do_interrupt,#endif /* !CONFIG_USER_ONLY */ };
Signature · 1 line
2.53.0
PATCH v3 5/11 accel/tcg: Document do_interrupt() callback contract
In reply to Philippe Mathieu-DaudéExpand docstring to clarify the handler is called with BQL held. Add assertion that this callback is mandatory and never NULL, since all targets must implement interrupt handling.
--- include/accel/tcg/cpu-ops.h | 11 ++++++++++- accel/tcg/cpu-exec.c | 1 + 2 files changed, 11 insertions(+), 1 deletion(-)
include/accel/tcg/cpu-ops.h +10 -1
@@ -169,7 +169,16 @@ struct TCGCPUOps {*/ vaddr (*untagged_addr)(CPUState *cs,vaddr addr);#else -/** @do_interrupt: Callback for interrupt handling. */ +/** +* @do_interrupt: Deliver a pending exception/interrupt to the CPU +* @cpu: cpu context +* +* Called when cs->exception_index contains an exception code to deliver. +* Updates CPU architectural state (usually before executing a guest +* exception handler). +* +* Called from cpu_handle_exception() with BQL held. +*/ void (*do_interrupt)(CPUState *cpu);/**
accel/tcg/cpu-exec.c +1 -0
@@ -1059,6 +1059,7 @@ bool tcg_exec_realizefn(CPUState *cpu, Error **errp)assert (tcg_ops->cpu_exec_halt);assert (tcg_ops->cpu_exec_interrupt);assert (tcg_ops->cpu_exec_reset); +assert (tcg_ops->do_interrupt);assert (tcg_ops->pointer_wrap);#endif /* !CONFIG_USER_ONLY */ assert (tcg_ops->translate_code);
Signature · 1 line
2.53.0
PATCH v3 11/11 accel/tcg: Remove do_interrupt_locked() callback
In reply to Philippe Mathieu-DaudéAll targets now manage their own BQL locking via do_interrupt(), making the do_interrupt_locked() hook unnecessary. Remove it to simplify the TCGCPUOps interface.
--- include/accel/tcg/cpu-ops.h | 12 ------------ accel/tcg/cpu-exec.c | 10 ++-------- 2 files changed, 2 insertions(+), 20 deletions(-)
include/accel/tcg/cpu-ops.h +0 -12
@@ -183,18 +183,6 @@ struct TCGCPUOps {*/ void (*do_interrupt)(CPUState *cpu); -/** -* @do_interrupt_locked: Deliver a pending exception/interrupt to the CPU -* @cpu: cpu context -* -* Called when cs->exception_index contains an exception code to deliver. -* Updates CPU architectural state (usually before executing a guest -* exception handler). -* -* Called from cpu_handle_exception() with BQL held. -*/ -void (*do_interrupt_locked)(CPUState *cpu); -/** * @cpu_exec_interrupt: Callback for processing target-specific interrupts * @cpu: cpu context
accel/tcg/cpu-exec.c +2 -8
@@ -727,13 +727,7 @@ static inline bool cpu_handle_exception(CPUState *cpu, int *ret)if (replay_exception ()) {const TCGCPUOps *tcg_ops = cpu->cc->tcg_ops; -if (tcg_ops->do_interrupt) { - tcg_ops->do_interrupt (cpu); - }else { -bql_lock (); - tcg_ops->do_interrupt_locked (cpu); -bql_unlock (); - } + tcg_ops->do_interrupt (cpu); cpu->exception_index =-1 ;if (unlikely (cpu_single_stepping (cpu))) {
@@ -1063,7 +1057,7 @@ bool tcg_exec_realizefn(CPUState *cpu, Error **errp)assert (tcg_ops->cpu_exec_halt);assert (tcg_ops->cpu_exec_interrupt);assert (tcg_ops->cpu_exec_reset); -assert (tcg_ops->do_interrupt || tcg_ops->do_interrupt_locked); +assert (tcg_ops->do_interrupt);assert (tcg_ops->pointer_wrap);#endif /* !CONFIG_USER_ONLY */ assert (tcg_ops->translate_code);
Signature · 1 line
2.53.0
Quoted 5 lines · Philippe Mathieu-Daudé
This is a respin of Robert Foley's v2 series from August 2020 [1] triggered by a broader review of BQL contract in my halt-to-exec transitions series by Peter [2] and Mark [3].
Quoted 8 lines
v2 Summary
----------This series pushes the Big QEMU Lock (BQL) down from the core TCG cpu_handle_interrupt/cpu_handle_exception paths into per-target implementations. This allows each architecture to manage BQL locking granularity independently, reducing contention on a known bottleneck as measured by QEMU sync profiling (qsp).
(I couldn't find what/where 'QEMU sync profiling' is).
Quoted 5 lines
The BQL has long been a scaling bottleneck in QEMU, and the interrupt/exception handling path is one of its heaviest users. By allowing targets to acquire the BQL only when needed, we enable future per-target optimizations.
Re: [PATCH v3 01/11] target/arm: Call arm*_cpu_do_interrupt directly instead of via TCGCPUOps
In reply to Philippe Mathieu-DaudéQuoted 5 lines · Philippe Mathieu-Daudé
The TCGCPUOps.do_interrupt handler is a target-specific callback installed for use by target-agnostic TCG core methods. Target-specific code should not dispatch through this indirection; call the ARM implementation directly instead.
Quoted 7 lines
Reported-by Richard Henderson <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/arm/cpu-irq.c | 2 +- target/arm/tcg/cpu-v7m.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
Pierrick Bouvier
Reviewed-byRe: [PATCH v3 02/11] target/s390x: Restrict interrupt handlers to system mode
In reply to a message not in the archiveQuoted 10 lines · Philippe Mathieu-Daudé
Move
s390_cpu_do_interrupt()ands390_cpu_exec_interrupt()declarations from system/user shared header to system-mode-only section, removing the unused user-mode stub.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/s390x/s390x-internal.h | 5 ++--- target/s390x/tcg/excp_helper.c | 5 ----- 2 files changed, 2 insertions(+), 8 deletions(-)
Re: [PATCH v3 05/11] accel/tcg: Document do_interrupt() callback contract
In reply to Philippe Mathieu-DaudéQuoted 18 lines · Philippe Mathieu-Daudé
Expand docstring to clarify the handler is called with BQL held. Add assertion that this callback is mandatory and never NULL, since all targets must implement interrupt handling.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/accel/tcg/cpu-ops.h | 11 ++++++++++- accel/tcg/cpu-exec.c | 1 + 2 files changed, 11 insertions(+), 1 deletion(-)include/accel/tcg/cpu-ops.h +0
-0@@ -169,7 +169,16 @@ struct TCGCPUOps {*/ vaddr (*untagged_addr)(CPUState *cs,vaddr addr);#else
include/accel/tcg/cpu-ops.h struct TCGCPUOps { · line 180
Quoted 10 lines
include/accel/tcg/cpu-ops.h +9
-1-/** @do_interrupt: Callback for interrupt handling. */ +/** +* @do_interrupt: Deliver a pending exception/interrupt to the CPU +* @cpu: cpu context +* +* Called when cs->exception_index contains an exception code to deliver. +* Updates CPU architectural state (usually before executing a guest +* exception handler). +* +* Called from cpu_handle_exception() with BQL held.
Would that be clearer to ensure this with an assert instead or relying on comment?
Quoted 16 lines
include/accel/tcg/cpu-ops.h +1
-0+*/ void (*do_interrupt)(CPUState *cpu);/** accel/tcg/cpu-exec.c +1
-0@@ -1059,6 +1059,7 @@ bool tcg_exec_realizefn(CPUState *cpu, Error **errp)assert (tcg_ops->cpu_exec_halt);assert (tcg_ops->cpu_exec_interrupt);assert (tcg_ops->cpu_exec_reset); +assert (tcg_ops->do_interrupt);assert (tcg_ops->pointer_wrap);#endif /* !CONFIG_USER_ONLY */ assert (tcg_ops->translate_code);
Re: [PATCH v3 05/11] accel/tcg: Document do_interrupt() callback contract
Quoted 24 lines · Pierrick Bouvier
Quoted 23 lines · Philippe Mathieu-Daudé
Expand docstring to clarify the handler is called with BQL held. Add assertion that this callback is mandatory and never NULL, since all targets must implement interrupt handling.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/accel/tcg/cpu-ops.h | 11 ++++++++++- accel/tcg/cpu-exec.c | 1 + 2 files changed, 11 insertions(+), 1 deletion(-)include/accel/tcg/cpu-ops.h +4
-1@@ -169,7 +169,16 @@ struct TCGCPUOps {*/ vaddr (*untagged_addr)(CPUState *cs,vaddr addr);#else -/** @do_interrupt: Callback for interrupt handling. */ +/** +* @do_interrupt: Deliver a pending exception/interrupt to the CPU +* @cpu: cpu context +*
Quoted 8 lines
include/accel/tcg/cpu-ops.h struct TCGCPUOps { · line 180
Quoted 5 lines
include/accel/tcg/cpu-ops.h +5
-0+* Called when cs->exception_index contains an exception code to deliver. +* Updates CPU architectural state (usually before executing a guest +* exception handler). +* +* Called from cpu_handle_exception() with BQL held. Would that be clearer to ensure this with an assert instead or relying on comment?
This docstring contract is a help to implement callees.
Quoted 19 lines
Quoted 17 lines
include/accel/tcg/cpu-ops.h +1
-0+*/ void (*do_interrupt)(CPUState *cpu);/** accel/tcg/cpu-exec.c +1
-0@@ -1059,6 +1059,7 @@ bool tcg_exec_realizefn(CPUState *cpu, Error **errp)assert (tcg_ops->cpu_exec_halt);assert (tcg_ops->cpu_exec_interrupt);assert (tcg_ops->cpu_exec_reset); +assert (tcg_ops->do_interrupt);assert (tcg_ops->pointer_wrap);#endif /* !CONFIG_USER_ONLY */ assert (tcg_ops->translate_code);
Re: [PATCH v3 08/11] target/hexagon: Move to do_interrupt() (BQL acquired internally)
In reply to Philippe Mathieu-DaudéQuoted 5 lines · Philippe Mathieu-Daudé
hexagon_cpu_do_interrupt()already acquires the BQL internally, so register it asdo_interrupt()instead ofdo_interrupt_locked(). This reflects the actual locking model used by the target.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 17 lines
--- target/hexagon/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/hexagon/cpu.c +1
-1@@ -769,7 +769,7 @@ static const TCGCPUOps hexagon_tcg_ops = { .tlb_fill = hexagon_tlb_fill, .do_unaligned_access = hexagon_cpu_do_unaligned_access, .cpu_exec_halt = hexagon_cpu_has_work, - .do_interrupt_locked = hexagon_cpu_do_interrupt, + .do_interrupt = hexagon_cpu_do_interrupt,#endif /* !CONFIG_USER_ONLY */ };
Re: [PATCH v3 01/11] target/arm: Call arm*_cpu_do_interrupt directly instead of via TCGCPUOps
In reply to Philippe Mathieu-DaudéQuoted 31 lines · Philippe Mathieu-Daudé
The TCGCPUOps.do_interrupt handler is a target-specific callback installed for use by target-agnostic TCG core methods. Target-specific code should not dispatch through this indirection; call the ARM implementation directly instead.
Reported-by Richard Henderson <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/arm/cpu-irq.c | 2 +- target/arm/tcg/cpu-v7m.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)target/arm/cpu-irq.c +1
-1@@ -270,7 +270,7 @@ bool arm_cpu_exec_interrupt(CPUState *cs, int interrupt_request) found: cs->exception_index = excp_idx; env->exception.target_el = target_el; - cs->cc->tcg_ops->do_interrupt (cs); +arm_cpu_do_interrupt (cs); return true; }#endif /* CONFIG_TCG */ target/arm/tcg/cpu-v7m.c +0
-0
target/arm/tcg/cpu-v7m.c static bool arm_v7m_cpu_exec_interrupt(CPUState *cs, int interrupt_request) · line 39
Quoted 7 lines
target/arm/tcg/cpu-v7m.c +1
-1@@ -34,7 +34,7 @@ static bool arm_v7m_cpu_exec_interrupt(CPUState *cs, int interrupt_request)if (interrupt_request &CPU_INTERRUPT_HARD && (armv7m_nvic_can_take_pending_exception (env->nvic))) { cs->exception_index =EXCP_IRQ ; - cs->cc->tcg_ops->do_interrupt (cs); +arm_v7m_cpu_do_interrupt (cs); ret = true; }
This works because we have separate cpu_exec_interrupt methods for M-profile and A/R-profile, so we can drop the indirection. If we had anywhere where we were trying to do "call the appropriate do_interrupt function" from code that's agnostic to M vs A/R this wouldn't work, but happily we don't.
thanks
-- PMM
Re: [PATCH v3 04/11] accel/tcg: Document cpu_exec_interrupt() callback contract
In reply to Philippe Mathieu-DaudéQuoted 20 lines · Philippe Mathieu-Daudé
Expand docstring to clarify that @interrupt_request is a bitmask, the handler is called with BQL held, and document the return value semantics. Fix typo in
arm_cpu_exec_interrupt()documentation (s/inrerrupt/interrupt).Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/accel/tcg/cpu-ops.h | 15 ++++++++++++++- target/arm/internals.h | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-)include/accel/tcg/cpu-ops.h +0
-0@@ -171,8 +171,21 @@ struct TCGCPUOps {#else /** @do_interrupt: Callback for interrupt handling. */ void (*do_interrupt)(CPUState *cpu);
include/accel/tcg/cpu-ops.h struct TCGCPUOps { · line 182
Quoted 10 lines
include/accel/tcg/cpu-ops.h +9
-1-/** @cpu_exec_interrupt: Callback for processing interrupts in cpu_exec */ + +/** +* @cpu_exec_interrupt: Callback for processing target-specific interrupts +* @cpu: cpu context +* @interrupt_request: Bitmask of pending interrupts +* +* Called from cpu_handle_interrupt() with the BQL held. Process the +* pending interrupt according to the target specific @interrupt_request +* masking rules.
I think we could clarify this a little to explain what to do with multiple pending interrupts. How about:
Identify which, if any, of the possibly multiple pending interrupts specified by @interrupt_request should be taken, using the target architecture's rules for interrupt prioritization and masking. If an interrupt can validly be taken, take it (by updating the emulated CPU state for an interrupt entry).
?
(I'm trying to get across that the function sets things up for execution of the interrupt handler as the next thing, it doesn't cause the whole interrupt handler to run. But maybe that's obvious enough we don't need to say so.)
Quoted 14 lines
include/accel/tcg/cpu-ops.h +5
-0+* +* Returns: %true if an interrupt was processed and the next TB should +* be restarted, %false to continue normal execution. +*/ bool (*cpu_exec_interrupt)(CPUState *cpu,int interrupt_request); +/** @cpu_exec_reset: Callback for reset in cpu_exec. */ void (*cpu_exec_reset)(CPUState *cpu);/** target/arm/internals.h +0
-0
target/arm/internals.h static inline const char *aarch32_mode_name(uint32_t psr) · line 1254
Quoted 8 lines
target/arm/internals.h +1
-1@@ -1248,7 +1248,7 @@ static inline const char *aarch32_mode_name(uint32_t psr) }/** -* arm_cpu_exec_interrupt(): Implementation of the cpu_exec_inrerrupt hook. +* arm_cpu_exec_interrupt(): Implementation of the cpu_exec_interrupt hook. */ bool arm_cpu_exec_interrupt (CPUState *cs,int interrupt_request);
-- PMM
Richard Henderson
Reviewed-byRe: [PATCH v3 02/11] target/s390x: Restrict interrupt handlers to system mode
In reply to a message not in the archiveQuoted 9 lines · Philippe Mathieu-Daudé
Move
s390_cpu_do_interrupt()ands390_cpu_exec_interrupt()declarations from system/user shared header to system-mode-only section, removing the unused user-mode stub.Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- target/s390x/s390x-internal.h | 5 ++--- target/s390x/tcg/excp_helper.c | 5 ----- 2 files changed, 2 insertions(+), 8 deletions(-)
r~
Re: [PATCH v3 03/11] target/i386: Rename fake_do_interrupt to fake_user_exception
In reply to Philippe Mathieu-DaudéQuoted 4 lines · Philippe Mathieu-Daudé
The
fake_user_exceptionhook handles exceptions in the outer exception loop (cpu_handle_exception), not inner loop interrupts (cpu_handle_interrupt). Rename to clarify the scope and intent.
Quoted 8 lines
Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- include/accel/tcg/cpu-ops.h | 4 ++-- target/i386/tcg/helper-tcg.h | 4 +++- accel/tcg/cpu-exec.c | 4 ++-- target/i386/tcg/tcg-cpu.c | 2 +- target/i386/tcg/user/seg_helper.c | 6 +++--- 5 files changed, 11 insertions(+), 9 deletions(-)
r~
Re: [PATCH v3 01/11] target/arm: Call arm*_cpu_do_interrupt directly instead of via TCGCPUOps
In reply to Philippe Mathieu-DaudéQuoted 11 lines · Philippe Mathieu-Daudé
The TCGCPUOps.do_interrupt handler is a target-specific callback installed for use by target-agnostic TCG core methods. Target-specific code should not dispatch through this indirection; call the ARM implementation directly instead.
Reported-by Richard Henderson<[email protected]>Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- target/arm/cpu-irq.c | 2 +- target/arm/tcg/cpu-v7m.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
r~
Re: [PATCH v3 05/11] accel/tcg: Document do_interrupt() callback contract
In reply to Philippe Mathieu-DaudéQuoted 9 lines · Philippe Mathieu-Daudé
Expand docstring to clarify the handler is called with BQL held. Add assertion that this callback is mandatory and never NULL, since all targets must implement interrupt handling.
Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- include/accel/tcg/cpu-ops.h | 11 ++++++++++- accel/tcg/cpu-exec.c | 1 + 2 files changed, 11 insertions(+), 1 deletion(-)
r~
Re: [PATCH v3 06/11] accel/tcg: Rename do_interrupt() to do_interrupt_locked()
In reply to Philippe Mathieu-DaudéQuoted 7 lines · Philippe Mathieu-Daudé
From: Robert Foley<[email protected]>
Prepare for pushing BQL locking down to per-target implementations. The old
do_interrupt()name will later be reused for a wrapper that acquires BQL and callsdo_interrupt_locked(), enabling targets to eventually remove BQL from the cpu_handle_interrupt/exception paths.
Quoted 5 lines
Suggested-by Paolo Bonzini<[email protected]>Signed-off-by Robert Foley<[email protected]>[PMD: Rebased and reworded description]Signed-off-by Philippe Mathieu-Daudé<[email protected]>---
r~
Re: [PATCH v3 07/11] accel/tcg: Add do_interrupt() wrapper for targets to manage BQL
In reply to Philippe Mathieu-DaudéQuoted 10 lines · Philippe Mathieu-Daudé
Add
TCGCPUOps::do_interrupt()as a wrapper that targets can implement to control BQL locking independently. The existingdo_interrupt_locked()callback remains for BQL-held contexts. This allows each target to decide when to acquire the BQL.Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- include/accel/tcg/cpu-ops.h | 14 ++++++++++++++ accel/tcg/cpu-exec.c | 12 ++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-)
r~
Re: [PATCH v3 08/11] target/hexagon: Move to do_interrupt() (BQL acquired internally)
In reply to Philippe Mathieu-DaudéQuoted 14 lines · Philippe Mathieu-Daudé
hexagon_cpu_do_interrupt()already acquires the BQL internally, so register it asdo_interrupt()instead ofdo_interrupt_locked(). This reflects the actual locking model used by the target.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/hexagon/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/hexagon/cpu.c +0
-0
target/hexagon/cpu.c static const TCGCPUOps hexagon_tcg_ops = { · line 775
Quoted 8 lines
target/hexagon/cpu.c +1
-1@@ -769,7 +769,7 @@ static const TCGCPUOps hexagon_tcg_ops = { .tlb_fill = hexagon_tlb_fill, .do_unaligned_access = hexagon_cpu_do_unaligned_access, .cpu_exec_halt = hexagon_cpu_has_work, - .do_interrupt_locked = hexagon_cpu_do_interrupt, + .do_interrupt = hexagon_cpu_do_interrupt,#endif /* !CONFIG_USER_ONLY */ };
Eh. Except all that hexagon does is acquire the lock at the beginning of the function and keep it for the entire duration. I think hexagon should stay using _locked and *not* do internal locking.
r~
Re: [RFC PATCH v3 09/11] targets: Move interrupt handlers to do_interrupt()
In reply to Philippe Mathieu-DaudéQuoted 11 lines · Philippe Mathieu-Daudé
LoongArch, M68K, MicroBlaze, and OpenRISC interrupt handlers don't require external BQL protection, so move them from
do_interrupt_locked()todo_interrupt().Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/loongarch/tcg/tcg_cpu.c | 2 +- target/m68k/cpu.c | 2 +- target/microblaze/cpu.c | 2 +- target/or1k/cpu.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)
How did you determine that these do not require locking? E.g. why does alpha require locking when loongarch does not?
r~
Re: [PATCH v3 11/11] accel/tcg: Remove do_interrupt_locked() callback
In reply to Philippe Mathieu-DaudéQuoted 9 lines · Philippe Mathieu-Daudé
All targets now manage their own BQL locking via
do_interrupt(), making thedo_interrupt_locked()hook unnecessary. Remove it to simplify the TCGCPUOps interface.Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- include/accel/tcg/cpu-ops.h | 12 ------------ accel/tcg/cpu-exec.c | 10 ++-------- 2 files changed, 2 insertions(+), 20 deletions(-)
Oh I see. Objection to hexagon change retracted.
r~
Re: [PATCH v3 01/11] target/arm: Call arm*_cpu_do_interrupt directly instead of via TCGCPUOps
In reply to Peter MaydellQuoted 48 lines · Peter Maydell
Quoted 31 lines · Philippe Mathieu-Daudé
The TCGCPUOps.do_interrupt handler is a target-specific callback installed for use by target-agnostic TCG core methods. Target-specific code should not dispatch through this indirection; call the ARM implementation directly instead.
Reported-by Richard Henderson <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/arm/cpu-irq.c | 2 +- target/arm/tcg/cpu-v7m.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)target/arm/cpu-irq.c +1
-1@@ -270,7 +270,7 @@ bool arm_cpu_exec_interrupt(CPUState *cs, int interrupt_request) found: cs->exception_index = excp_idx; env->exception.target_el = target_el; - cs->cc->tcg_ops->do_interrupt (cs); +arm_cpu_do_interrupt (cs); return true; }#endif /* CONFIG_TCG */ target/arm/tcg/cpu-v7m.c +0
-0target/arm/tcg/cpu-v7m.c static bool arm_v7m_cpu_exec_interrupt(CPUState *cs, int interrupt_request) · line 39
Quoted 7 lines
target/arm/tcg/cpu-v7m.c +1
-1@@ -34,7 +34,7 @@ static bool arm_v7m_cpu_exec_interrupt(CPUState *cs, int interrupt_request)if (interrupt_request &CPU_INTERRUPT_HARD && (armv7m_nvic_can_take_pending_exception (env->nvic))) { cs->exception_index =EXCP_IRQ ; - cs->cc->tcg_ops->do_interrupt (cs); +arm_v7m_cpu_do_interrupt (cs); ret = true; }This works because we have separate
cpu_exec_interruptmethods for M-profile and A/R-profile, so we can drop the indirection. If we had anywhere where we were trying to do "call the appropriatedo_interruptfunction" from code that's agnostic to M vs A/R this wouldn't work, but happily we don't.
Quoted 1 line
Reviewed-by Peter Maydell <[email protected]>
Thanks for the clarification, I amended:
This is valid because M-profile and A/R-profile have separate cpu_exec_interrupt() implementations. Code agnostic to these profiles would still require an appropriate dispatch mechanism, but no such caller exists here.
Regards,
Phil.
Re: [PATCH v3 08/11] target/hexagon: Move to do_interrupt() (BQL acquired internally)
In reply to Richard HendersonQuoted 10 lines · Richard Henderson
Quoted 9 lines · Philippe Mathieu-Daudé
hexagon_cpu_do_interrupt()already acquires the BQL internally, so register it asdo_interrupt()instead ofdo_interrupt_locked(). This reflects the actual locking model used by the target.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
target/hexagon/cpu.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines
target/hexagon/cpu.c static const TCGCPUOps hexagon_tcg_ops = { · line 774
Quoted 12 lines
target/hexagon/cpu.c +1
-1@@ -769,7 +769,7 @@ static const TCGCPUOps hexagon_tcg_ops = { .tlb_fill = hexagon_tlb_fill, .do_unaligned_access = hexagon_cpu_do_unaligned_access, .cpu_exec_halt = hexagon_cpu_has_work, - .do_interrupt_locked = hexagon_cpu_do_interrupt, + .do_interrupt = hexagon_cpu_do_interrupt, #endif /* !CONFIG_USER_ONLY */ };Eh. Except all that hexagon does is acquire the lock at the beginning of the function and keep it for the entire duration. I think hexagon should stay using
_lockedand *not* do internal locking.
I'm rewording to clarify:
``` target/hexagon: Use do_interrupt() for internal BQL locking hexagon_cpu_do_interrupt() acquires the BQL with BQL_LOCK_GUARD() and holds it throughout exception delivery. Register it as do_interrupt() to match this locking contract and allow removal of do_interrupt_locked(). ```
Re: [PATCH v3 04/11] accel/tcg: Document cpu_exec_interrupt() callback contract
In reply to Peter MaydellQuoted 36 lines · Peter Maydell
Quoted 20 lines · Philippe Mathieu-Daudé
Expand docstring to clarify that @interrupt_request is a bitmask, the handler is called with BQL held, and document the return value semantics. Fix typo in
arm_cpu_exec_interrupt()documentation (s/inrerrupt/interrupt).Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/accel/tcg/cpu-ops.h | 15 ++++++++++++++- target/arm/internals.h | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-)include/accel/tcg/cpu-ops.h +0
-0@@ -171,8 +171,21 @@ struct TCGCPUOps {#else /** @do_interrupt: Callback for interrupt handling. */ void (*do_interrupt)(CPUState *cpu);include/accel/tcg/cpu-ops.h struct TCGCPUOps { · line 182
Quoted 10 lines
include/accel/tcg/cpu-ops.h +9
-1-/** @cpu_exec_interrupt: Callback for processing interrupts in cpu_exec */ + +/** +* @cpu_exec_interrupt: Callback for processing target-specific interrupts +* @cpu: cpu context +* @interrupt_request: Bitmask of pending interrupts +* +* Called from cpu_handle_interrupt() with the BQL held. Process the +* pending interrupt according to the target specific @interrupt_request +* masking rules. I think we could clarify this a little to explain what to do with multiple pending interrupts. How about:
Quoted 5 lines
Identify which, if any, of the possibly multiple pending interrupts specified by @interrupt_request should be taken, using the target architecture's rules for interrupt prioritization and masking. If an interrupt can validly be taken, take it (by updating the emulated CPU state for an interrupt entry).
Does that update sound good to you?
* Called from cpu_handle_interrupt() with the BQL held. Identify which,
* if any, of the possibly multiple pending interrupts specified by
* @interrupt_request should be taken, using the target architecture's
* prioritization and masking rules. If an interrupt can be taken, update
* the emulated CPU state for interrupt entry.
With the update desc I wonder if we should rename the helper as cpu_take_interrupt()...
Quoted 29 lines
(I'm trying to get across that the function sets things up for execution of the interrupt handler as the next thing, it doesn't cause the whole interrupt handler to run. But maybe that's obvious enough we don't need to say so.)
Quoted 14 lines
include/accel/tcg/cpu-ops.h +5
-0+* +* Returns: %true if an interrupt was processed and the next TB should +* be restarted, %false to continue normal execution. +*/ bool (*cpu_exec_interrupt)(CPUState *cpu,int interrupt_request); +/** @cpu_exec_reset: Callback for reset in cpu_exec. */ void (*cpu_exec_reset)(CPUState *cpu);/** target/arm/internals.h +0
-0target/arm/internals.h static inline const char *aarch32_mode_name(uint32_t psr) · line 1254
Quoted 8 lines
target/arm/internals.h +1
-1@@ -1248,7 +1248,7 @@ static inline const char *aarch32_mode_name(uint32_t psr) }/** -* arm_cpu_exec_interrupt(): Implementation of the cpu_exec_inrerrupt hook. +* arm_cpu_exec_interrupt(): Implementation of the cpu_exec_interrupt hook. */ bool arm_cpu_exec_interrupt (CPUState *cs,int interrupt_request);-- PMM
Re: [PATCH v3 04/11] accel/tcg: Document cpu_exec_interrupt() callback contract
Quoted 7 lines · Philippe Mathieu-Daudé
Does that update sound good to you?
* Called from
cpu_handle_interrupt()with the BQL held. Identify which,
* if any, of the possibly multiple pending interrupts specified by
* @interrupt_request should be taken, using the target architecture's
* prioritization and masking rules. If an interrupt can be taken, update
* the emulated CPU state for interrupt entry.
Looks good to me.
Quoted 2 lines
With the update desc I wonder if we should rename the helper as
cpu_take_interrupt()...
Mmm. the "exec" in the current method name is "because it's called by cpu_exec", I think (compare cpu_exec_reset, cpu_exec_halt), which is not necessarily a very useful thing to encode in the method name.
I guess my opinions are:
* don't bother renaming unless we think we have a clearly better name/set of names
* if we rename one of the cpu_exec_foo then we should probably rename all of them in some consistent way
* a new set of names would ideally make it clearer what the difference is between do_interrupt and cpu_exec_interrupt (I can't remember myself why we need both or what the difference is offhand...)
thanks
-- PMM
Re: [RFC PATCH v3 09/11] targets: Move interrupt handlers to do_interrupt()
In reply to Richard HendersonQuoted 13 lines · Richard Henderson
Quoted 11 lines · Philippe Mathieu-Daudé
LoongArch, M68K, MicroBlaze, and OpenRISC interrupt handlers don't require external BQL protection, so move them from
do_interrupt_locked()todo_interrupt().Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
target/loongarch/tcg/tcg_cpu.c| 2 +-
target/m68k/cpu.c | 2 +-
target/microblaze/cpu.c | 2 +-
target/or1k/cpu.c | 2 +-4 files changed, 4 insertions(+), 4 deletions(-)
Quoted 2 lines
How did you determine that these do not require locking? E.g. why does alpha require locking when loongarch does not?
I couldn't find explicit BQL use in these, but now I see why this poor audit isn't good enough. Better to convert all targets to use explicit BQL locking (next patch), then remove unnecessary locking one target at a time, with good justification in commit description.
Re: [PATCH v3 04/11] accel/tcg: Document cpu_exec_interrupt() callback contract
In reply to Peter MaydellQuoted 12 lines · Peter Maydell
Quoted 7 lines · Philippe Mathieu-Daudé
Does that update sound good to you?
* Called from
cpu_handle_interrupt()with the BQL held. Identify which,
* if any, of the possibly multiple pending interrupts specified by
* @interrupt_request should be taken, using the target architecture's
* prioritization and masking rules. If an interrupt can be taken, update
* the emulated CPU state for interrupt entry.Looks good to me.
Quoted 7 lines
Quoted 2 lines
With the update desc I wonder if we should rename the helper as
cpu_take_interrupt()...Mmm. the "exec" in the current method name is "because it's called by
cpu_exec", I think (comparecpu_exec_reset,cpu_exec_halt), which is not necessarily a very useful thing to encode in the method name.
(also IIRC they were first defined in cpu-exec.c but got moved around)
Quoted 6 lines
I guess my opinions are:
* don't bother renaming unless we think we have a clearly better name/set of names
* if we rename one of thecpu_exec_foothen we should probably rename all of them in some consistent way
OK.
Quoted 4 lines
* a new set of names would ideally make it clearer what the difference is between
do_interruptandcpu_exec_interrupt(I can't remember myself why we need both or what the difference is offhand...)
/* main execution loop */cpu_exec_loop(CPUState *cpu, SyncClocks *sc)
{
/* if an exception is pending, we execute it here */
// examine async requests
// per-target mask / prioritization
// select (accept) intr
while (!cpu_handle_exception(cpu, &excp)) {
// target consume selected intr
while (!cpu_handle_interrupt(cpu, &last_tb)) {So an option:
- cpu_handle_exception() -> cpu_select_interrupt() (examines pending interrupt_request bitmask)
- cpu_handle_interrupt() -> cpu_enter_exception() (intr / synchronous exception)