From 4cdc1cd137e0b98766916a7cdf2d5a9b3c6632fa Mon Sep 17 00:00:00 2001 From: Aurelien Jarno Date: Sat, 25 Dec 2010 22:56:32 +0100 Subject: target-mips: fix host CPU consumption when guest is idle When the CPU is in wait state, do not wake-up if an interrupt can't be taken. This avoid host CPU running at 100% if a device (e.g. timer) has an interrupt line left enabled. Also factorize code to check if interrupts are enabled in cpu_mips_hw_interrupts_pending(). Based on a patch from Edgar E. Iglesias Signed-off-by: Aurelien Jarno Acked-by: Edgar E. Iglesias --- target-mips/exec.h | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'target-mips/exec.h') diff --git a/target-mips/exec.h b/target-mips/exec.h index af61b54dcf..12736543ac 100644 --- a/target-mips/exec.h +++ b/target-mips/exec.h @@ -19,10 +19,22 @@ register struct CPUMIPSState *env asm(AREG0); static inline int cpu_has_work(CPUState *env) { - return (env->interrupt_request & - (CPU_INTERRUPT_HARD | CPU_INTERRUPT_TIMER)); -} + int has_work = 0; + + /* It is implementation dependent if non-enabled interrupts + wake-up the CPU, however most of the implementations only + check for interrupts that can be taken. */ + if ((env->interrupt_request & CPU_INTERRUPT_HARD) && + cpu_mips_hw_interrupts_pending(env)) { + has_work = 1; + } + if (env->interrupt_request & CPU_INTERRUPT_TIMER) { + has_work = 1; + } + + return has_work; +} static inline int cpu_halted(CPUState *env) { -- cgit v1.2.3