Skip to contentSkip to conversation

cpus: use cpu_is_stopped efficiently

PATCH Applied Tiejun Chen 2 participants 3 messages Aug 2, 2013 – Aug 5, 2013

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 cpus: use cpu_is_stopped efficiently

It makes more sense and simple later.

---
v1 -> v2:

To optimize performance slightly, we can reorder the two conditions to avoid the non-inline function call if cpu->stopped.

 cpus.c |   14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
cpus.c +7 -7
index c232265..7e76506 100644
@@ -62,6 +62,11 @@
 
 static CPUArchState *next_cpu;
 
+bool cpu_is_stopped(CPUState *cpu)
+{
+    return cpu->stopped || !runstate_is_running();
+}
+
 static bool cpu_thread_is_idle(CPUArchState *env)
 {
     CPUState *cpu = ENV_GET_CPU(env);
@@ -69,7 +74,7 @@ static bool cpu_thread_is_idle(CPUArchState *env)
     if (cpu->stop || cpu->queued_work_first) {
         return false;
     }
-    if (cpu->stopped || !runstate_is_running()) {
+    if (cpu_is_stopped(cpu)) {
         return true;
     }
     if (!cpu->halted || qemu_cpu_has_work(cpu) ||
@@ -432,11 +437,6 @@ void cpu_synchronize_all_post_init(void)
     }
 }
 
-bool cpu_is_stopped(CPUState *cpu)
-{
-    return !runstate_is_running() || cpu->stopped;
-}
-
 static void do_vm_stop(RunState state)
 {
     if (runstate_is_running()) {
@@ -455,7 +455,7 @@ static bool cpu_can_run(CPUState *cpu)
     if (cpu->stop) {
         return false;
     }
-    if (cpu->stopped || !runstate_is_running()) {
+    if (cpu_is_stopped(cpu)) {
         return false;
     }
     return true;
Signature · 1 line
1.7.9.5
#1 lore raw

Am 02.08.2013 03:43, schrieb Tiejun Chen:

Quoted 8 lines

It makes more sense and simple later.

---
v1 -> v2:

To optimize performance slightly, we can reorder the two conditions to avoid the non-inline function call if cpu->stopped.

Patch doesn't apply to qemu.git: next_cpu and cpu_thread_is_idle() use CPUState since a few weeks and do_vm_stop() changed from void to int. Please remember to rebase before sending patches.

Thanks, applied to qom-cpu-next (with modified commit message):
https://github.com/afaerber/qemu-cpu/commits/qom-cpu-next

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#2 lore raw
Quoted 7 lines · On 08/02/2013 09:33 PM, � wrote:

Am 02.08.2013 03:43, schrieb Tiejun Chen:

Quoted 6 lines

It makes more sense and simple later.

---
v1 -> v2:

Quoted 6 lines
Quoted 2 lines

To optimize performance slightly, we can reorder the two conditions to avoid the non-inline function call if cpu->stopped.

Patch doesn't apply to qemu.git: next_cpu and cpu_thread_is_idle() use CPUState since a few weeks and do_vm_stop() changed from void to int. Please remember to rebase before sending patches.

Okay, sorry for this inconvenience.

Tiejun

Quoted 6 lines

Thanks, applied to qom-cpu-next (with modified commit message):
https://github.com/afaerber/qemu-cpu/commits/qom-cpu-next

Andreas