diff mbox

[1/5] cpu-exec: Move halt handling out of cpu_exec()

Message ID 1462895205-8411-2-git-send-email-sergey.fedorov@linaro.org
State New
Headers show

Commit Message

sergey.fedorov@linaro.org May 10, 2016, 3:46 p.m. UTC
From: Sergey Fedorov <serge.fdrv@gmail.com>

Simplify cpu_exec() by extracting CPU halt state handling code out of
cpu_exec() into a new static inline function cpu_handle_halt().

Signed-off-by: Sergey Fedorov <serge.fdrv@gmail.com>
Signed-off-by: Sergey Fedorov <sergey.fedorov@linaro.org>
---
 cpu-exec.c | 39 +++++++++++++++++++++++++--------------
 1 file changed, 25 insertions(+), 14 deletions(-)

Comments

Richard Henderson May 10, 2016, 4:13 p.m. UTC | #1
On 05/10/2016 05:46 AM, Sergey Fedorov wrote:
> +#if defined(TARGET_I386) && !defined(CONFIG_USER_ONLY)
> +        X86CPU *x86_cpu = X86_CPU(cpu);
> +
> +        if ((cpu->interrupt_request & CPU_INTERRUPT_POLL)
> +            && replay_interrupt()) {
> +            apic_poll_irq(x86_cpu->apic_state);

Since you're moving this around, you might as well place the x86_cpu variable 
in the inner-most if, next to its only use.

Otherwise,

Reviewed-by: Richard Henderson <rth@twiddle.net>


r~
Sergey Fedorov May 10, 2016, 7:13 p.m. UTC | #2
On 10/05/16 19:13, Richard Henderson wrote:
> On 05/10/2016 05:46 AM, Sergey Fedorov wrote:
>> +#if defined(TARGET_I386) && !defined(CONFIG_USER_ONLY)
>> +        X86CPU *x86_cpu = X86_CPU(cpu);
>> +
>> +        if ((cpu->interrupt_request & CPU_INTERRUPT_POLL)
>> +            && replay_interrupt()) {
>> +            apic_poll_irq(x86_cpu->apic_state);
>
> Since you're moving this around, you might as well place the x86_cpu
> variable in the inner-most if, next to its only use.

Agree, will fix in v2.

>
> Otherwise,
>
> Reviewed-by: Richard Henderson <rth@twiddle.net>

Kind regards,
Sergey
diff mbox

Patch

diff --git a/cpu-exec.c b/cpu-exec.c
index d55faa5114c7..fb72f102742c 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -352,6 +352,29 @@  static inline TranslationBlock *tb_find_fast(CPUState *cpu,
     return tb;
 }
 
+static inline bool cpu_handle_halt(CPUState *cpu)
+{
+    if (cpu->halted) {
+#if defined(TARGET_I386) && !defined(CONFIG_USER_ONLY)
+        X86CPU *x86_cpu = X86_CPU(cpu);
+
+        if ((cpu->interrupt_request & CPU_INTERRUPT_POLL)
+            && replay_interrupt()) {
+            apic_poll_irq(x86_cpu->apic_state);
+            cpu_reset_interrupt(cpu, CPU_INTERRUPT_POLL);
+        }
+#endif
+        if (!cpu_has_work(cpu)) {
+            current_cpu = NULL;
+            return true;
+        }
+
+        cpu->halted = 0;
+    }
+
+    return false;
+}
+
 static void cpu_handle_debug_exception(CPUState *cpu)
 {
     CPUClass *cc = CPU_GET_CLASS(cpu);
@@ -383,20 +406,8 @@  int cpu_exec(CPUState *cpu)
     /* replay_interrupt may need current_cpu */
     current_cpu = cpu;
 
-    if (cpu->halted) {
-#if defined(TARGET_I386) && !defined(CONFIG_USER_ONLY)
-        if ((cpu->interrupt_request & CPU_INTERRUPT_POLL)
-            && replay_interrupt()) {
-            apic_poll_irq(x86_cpu->apic_state);
-            cpu_reset_interrupt(cpu, CPU_INTERRUPT_POLL);
-        }
-#endif
-        if (!cpu_has_work(cpu)) {
-            current_cpu = NULL;
-            return EXCP_HALTED;
-        }
-
-        cpu->halted = 0;
+    if (cpu_handle_halt(cpu)) {
+        return EXCP_HALTED;
     }
 
     atomic_mb_set(&tcg_current_cpu, cpu);