diff mbox

[3/3] cpu: make the function of cpu_common_map_numa_node more efficiently

Message ID 1484743207-10721-4-git-send-email-douly.fnst@cn.fujitsu.com
State New
Headers show

Commit Message

Dou Liyang Jan. 18, 2017, 12:40 p.m. UTC
Current function does some unnecessary operations, such as it makes
the assert() in the loop, and the loop was not stopped in time.

This patch moves the assert() out the loop and stops the loop in
time.

Signed-off-by: Dou Liyang <douly.fnst@cn.fujitsu.com>
---
 qom/cpu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Eduardo Habkost Jan. 18, 2017, 12:56 p.m. UTC | #1
On Wed, Jan 18, 2017 at 08:40:07PM +0800, Dou Liyang wrote:
> Current function does some unnecessary operations, such as it makes
> the assert() in the loop, and the loop was not stopped in time.
> 
> This patch moves the assert() out the loop and stops the loop in
> time.
> 
> Signed-off-by: Dou Liyang <douly.fnst@cn.fujitsu.com>


Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>

Can be squashed in patch 1/3.

> ---
>  qom/cpu.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/qom/cpu.c b/qom/cpu.c
> index e08dceb..3c655b2 100644
> --- a/qom/cpu.c
> +++ b/qom/cpu.c
> @@ -343,10 +343,11 @@ static void cpu_common_map_numa_node(CPUState *cpu)
>  {
>      int i;
>  
> +    assert(cpu->cpu_index < max_cpus);
>      for (i = 0; i < nb_numa_nodes; i++) {
> -        assert(cpu->cpu_index < max_cpus);
>          if (test_bit(cpu->cpu_index, numa_info[i].node_cpu)) {
>              cpu->numa_node = i;
> +            return;
>          }
>      }
>  }
> -- 
> 2.5.5
> 
> 
>
diff mbox

Patch

diff --git a/qom/cpu.c b/qom/cpu.c
index e08dceb..3c655b2 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -343,10 +343,11 @@  static void cpu_common_map_numa_node(CPUState *cpu)
 {
     int i;
 
+    assert(cpu->cpu_index < max_cpus);
     for (i = 0; i < nb_numa_nodes; i++) {
-        assert(cpu->cpu_index < max_cpus);
         if (test_bit(cpu->cpu_index, numa_info[i].node_cpu)) {
             cpu->numa_node = i;
+            return;
         }
     }
 }