On 04.10.19 14:11, Peter Maydell wrote: > On Fri, 4 Oct 2019 at 09:02, David Hildenbrand <da...@redhat.com> wrote: >> So shall we leave this patch as-is (adding a summary of what you >> explained to the description) or shall we somehow factor out the >> TCG-internal-thingy check? > > Nothing else in target code touches the icount data structures, > so if this s390 insn needs to make this check I think it ought > to do it by calling a function implemented by the tcg code; > that can then have a good name that describes what it's doing > and a doc comment explaining the reason we need to have it. > > thanks > -- PMM >
I can offer something like this: diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 49db07ba0b..d370ac0134 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -72,6 +72,26 @@ void QEMU_NORETURN cpu_loop_exit(CPUState *cpu); void QEMU_NORETURN cpu_loop_exit_restore(CPUState *cpu, uintptr_t pc); void QEMU_NORETURN cpu_loop_exit_atomic(CPUState *cpu, uintptr_t pc); +/** + * cpu_cond_loop_exit_restore: + * @cpu: the vCPU state to be restored + * @pc: the host PC + * + * Trigger a cpu_loop_exit_restore() in case somebody asked for a return + * to the main loop (e.g. cpu_exit() or cpu_interrupt()). + * + * This is helpful for architectures that support interruptible + * instructions. After writing back all state to registers/memory, this + * call can be used to conditionally return back to the main loop or to + * continue executing the interruptible instruction. + */ +static inline void cpu_cond_loop_exit_restore(CPUState *cpu, uintptr_t pc) +{ + if (unlikely((int32_t)atomic_read(&cpu_neg(cs)->icount_decr.u32) < 0)) { + cpu_loop_exit_restore(cs, ra); + } +} + #if !defined(CONFIG_USER_ONLY) void cpu_reloading_memory_map(void); /** Or, as alternative, something like "cpu_shall_exit()" which only wraps the single check. -- Thanks, David / dhildenb