NUMA: Validate CPU configuration
v2 cover NUMA: Validate CPU configuration
This adds extra checks to the NUMA code to make sure the CPU configuration is consistent. This needs to be applied on top of the following series:
Message-Id: <[email protected]>
Subject: [Qemu-devel] [PATCH 0/7] NUMA code cleanup
From: Eduardo Habkost <[email protected]>
Date: Sun, 8 Feb 2015 16:51:15 -0200
Git tree: https://github.com/ehabkost/qemu.git numa-next
Eduardo Habkost (3):
numa: Reject CPU indexes > max_cpus
numa: Reject configuration if CPU appears on multiple nodes
numa: Print warning if no node is assigned to a CPU
numa.c | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-)
Signature · 1 line
2.1.0
PATCH v2 1/3 numa: Reject CPU indexes > max_cpus
The CPU indexes for NUMA nodes make sense only up to max_cpus, and CPU indexes > max_cpus are ignored. Reject configuration which uses invalid CPU indexes.
--- numa.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
numa.c +4 -3
@@ -76,9 +76,10 @@ static void numa_node_parse(NumaNodeOptions *node, QemuOpts *opts, Error **errp) }for (cpus = node->cpus; cpus; cpus = cpus->next) { -if (cpus->value >MAX_CPUMASK_BITS ) { -error_setg (errp,"CPU number %" PRIu16" is bigger than %d" , - cpus->value,MAX_CPUMASK_BITS ); +if (cpus->value > max_cpus) { +error_setg (errp, +"CPU number %" PRIu16" is bigger than maxcpus (%d)" , + cpus->value, max_cpus);return ; }bitmap_set (numa_info[nodenr].node_cpu, cpus->value,1 );
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH v2 1/3] numa: Reject CPU indexes > max_cpus
Quoted 17 lines · On Mon, 9 Feb 2015 17:53:14 -0200 Eduardo Habkost <[email protected]> wrote:
The CPU indexes for NUMA nodes make sense only up to
max_cpus, and CPU indexes >max_cpusare ignored. Reject configuration which uses invalid CPU indexes.Signed-off-by Eduardo Habkost <[email protected]>--- numa.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)numa.c +0
-0@@ -76,9 +76,10 @@ static void numa_node_parse(NumaNodeOptions *node, QemuOpts *opts, Error **errp) }for (cpus = node->cpus; cpus; cpus = cpus->next) {
numa.c static void numa_node_parse(NumaNodeOptions *node, QemuOpts *opts, Error **errp) · line 85
Quoted 10 lines
numa.c +4
-3-if (cpus->value >MAX_CPUMASK_BITS ) { -error_setg (errp,"CPU number %" PRIu16" is bigger than %d" , - cpus->value,MAX_CPUMASK_BITS ); +if (cpus->value > max_cpus) { +error_setg (errp, +"CPU number %" PRIu16" is bigger than maxcpus (%d)" , + cpus->value, max_cpus);return ; }bitmap_set (numa_info[nodenr].node_cpu, cpus->value,1 );
PATCH v2 2/3 numa: Reject configuration if CPU appears on multiple nodes
In reply to Eduardo HabkostEach CPU can appear in only one NUMA node on the NUMA config. Reject configuration if a CPU appears in multiple nodes.
--- numa.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
numa.c +27 -0
@@ -167,6 +167,31 @@ error:return -1 ; } +static void validate_numa_cpus (void ) +{ +int i, cpu; +DECLARE_BITMAP (present_cpus,MAX_CPUMASK_BITS ); + +bitmap_zero (present_cpus,MAX_CPUMASK_BITS ); +for (i =0 ; i < nb_numa_nodes; i++) { +if (bitmap_intersects (present_cpus, numa_info[i].node_cpu, +MAX_CPUMASK_BITS )) { +bitmap_and (present_cpus, present_cpus, + numa_info[i].node_cpu,MAX_CPUMASK_BITS ); +fprintf (stderr,"CPU(s) present in multiple NUMA nodes:" ); +for (cpu =find_first_bit (present_cpus,MAX_CPUMASK_BITS ); + cpu <MAX_CPUMASK_BITS ; + cpu =find_next_bit (present_cpus,MAX_CPUMASK_BITS , cpu +1 )) { +fprintf (stderr," %d" , cpu); + } +fprintf (stderr,"\n" ); +exit (1 ); + } +bitmap_or (present_cpus, present_cpus, + numa_info[i].node_cpu,MAX_CPUMASK_BITS ); + } +} +void parse_numa_opts (void ) {int i;
@@ -244,6 +269,8 @@ void parse_numa_opts(void)set_bit (i, numa_info[i % nb_numa_nodes].node_cpu); } } + +validate_numa_cpus (); } }
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH v2 2/3] numa: Reject configuration if CPU appears on multiple nodes
Quoted 25 lines · On Mon, 9 Feb 2015 17:53:15 -0200 Eduardo Habkost <[email protected]> wrote:
Each CPU can appear in only one NUMA node on the NUMA config. Reject configuration if a CPU appears in multiple nodes.
Signed-off-by Eduardo Habkost <[email protected]>--- numa.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)numa.c +9
-0@@ -167,6 +167,31 @@ error:return -1 ; } +static void validate_numa_cpus (void ) +{ +int i, cpu; +DECLARE_BITMAP (present_cpus,MAX_CPUMASK_BITS ); + +bitmap_zero (present_cpus,MAX_CPUMASK_BITS ); +for (i =0 ; i < nb_numa_nodes; i++) { +if (bitmap_intersects (present_cpus, numa_info[i].node_cpu, +MAX_CPUMASK_BITS )) {
numa.c error: · line 188
Quoted 10 lines
numa.c +9
-0+bitmap_and (present_cpus, present_cpus, + numa_info[i].node_cpu,MAX_CPUMASK_BITS ); +fprintf (stderr,"CPU(s) present in multiple NUMA nodes:" ); +for (cpu =find_first_bit (present_cpus,MAX_CPUMASK_BITS ); + cpu <MAX_CPUMASK_BITS ; + cpu =find_next_bit (present_cpus,MAX_CPUMASK_BITS , cpu +1 )) { +fprintf (stderr," %d" , cpu); + } +fprintf (stderr,"\n" );
how about replacing a bunch if fprintf's with something like this:
cpu = 0;while((cpu = find_next_bit(present_cpus, MAX_CPUMASK_BITS, cpu + 1)) !=MAX_CPUMASK_BITS)
str = g_strdup_printf("%s %d", str, cpu);error_report("CPU(s) present in multiple NUMA nodes: %s\n", str);
Quoted 19 lines
numa.c +7
-0+exit (1 ); + } +bitmap_or (present_cpus, present_cpus, + numa_info[i].node_cpu,MAX_CPUMASK_BITS ); + } +} +void parse_numa_opts (void ) {int i;numa.c +2
-0@@ -244,6 +269,8 @@ void parse_numa_opts(void)set_bit (i, numa_info[i % nb_numa_nodes].node_cpu); } } + +validate_numa_cpus (); } }
Re: [Qemu-devel] [PATCH v2 2/3] numa: Reject configuration if CPU appears on multiple nodes
Quoted 7 lines · Igor Mammedov
how about replacing a bunch if fprintf's with something like this:
cpu = 0;
while((cpu = find_next_bit(present_cpus, MAX_CPUMASK_BITS, cpu + 1)) !=MAX_CPUMASK_BITS)str = g_strdup_printf("%s %d", str, cpu);
error_report("CPU(s) present in multiple NUMA nodes: %s\n", str);
As written above this leaks memory, and there should be no space before the final %s. So it's not that simple. :) But using error_report is nicer indeed, and you can use GString to avoid the leak.
Paolo
Re: [Qemu-devel] [PATCH v2 2/3] numa: Reject configuration if CPU appears on multiple nodes
Quoted 9 lines · Paolo Bonzini
Quoted 6 lines · Igor Mammedov
how about replacing a bunch if fprintf's with something like this:
cpu = 0;
while((cpu = find_next_bit(present_cpus, MAX_CPUMASK_BITS, cpu + 1)) !=MAX_CPUMASK_BITS)str = g_strdup_printf("%s %d", str, cpu);
Quoted 5 lines
Quoted 1 line
error_report("CPU(s) present in multiple NUMA nodes: %s\n", str);As written above this leaks memory, and there should be no space before the final %s. So it's not that simple. :) But using
error_reportis nicer indeed, and you can use GString to avoid the leak.
Complex string-building logic was exactly what I was trying to avoid when I decided to use fprintf(). But I didn't know about GString, I will give it a try on the next version. Thanks!
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v2 2/3] numa: Reject configuration if CPU appears on multiple nodes
In reply to Paolo BonziniQuoted 5 lines · On Thu, 12 Feb 2015 16:18:31 +0100 Paolo Bonzini <[email protected]> wrote:
Quoted 2 lines · Igor Mammedov
how about replacing a bunch if fprintf's with something like this:
Quoted 8 lines
Quoted 5 lines
cpu = 0;
while((cpu = find_next_bit(present_cpus, MAX_CPUMASK_BITS, cpu + 1)) !=MAX_CPUMASK_BITS)str = g_strdup_printf("%s %d", str, cpu);
error_report("CPU(s) present in multiple NUMA nodes: %s\n", str);As written above this leaks memory, and there should be no space before the final %s. So it's not that simple. :)
it hasn't been meant as working drop in code
Quoted 2 lines
But using
error_reportis
nicer indeed, and you can use GString to avoid the leak.
good to learn about GString
Quoted 3 lines
Paolo
Re: [Qemu-devel] [PATCH v2 2/3] numa: Reject configuration if CPU appears on multiple nodes
In reply to Eduardo HabkostQuoted 13 lines · On Mon, 9 Feb 2015 17:53:15 -0200 Eduardo Habkost <[email protected]> wrote:
Each CPU can appear in only one NUMA node on the NUMA config. Reject configuration if a CPU appears in multiple nodes.
Signed-off-by Eduardo Habkost <[email protected]>--- numa.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)numa.c +0
-0
numa.c error: · line 173
Quoted 7 lines
numa.c +4
-0@@ -167,6 +167,31 @@ error:return -1 ; } +static void validate_numa_cpus (void ) +{ +int i, cpu; +DECLARE_BITMAP (present_cpus,MAX_CPUMASK_BITS );
naming is a bit confusing, it's not really present CPUs but more like possible_cpus
Quoted 33 lines
numa.c +23
-0+ +bitmap_zero (present_cpus,MAX_CPUMASK_BITS ); +for (i =0 ; i < nb_numa_nodes; i++) { +if (bitmap_intersects (present_cpus, numa_info[i].node_cpu, +MAX_CPUMASK_BITS )) { +bitmap_and (present_cpus, present_cpus, + numa_info[i].node_cpu,MAX_CPUMASK_BITS ); +fprintf (stderr,"CPU(s) present in multiple NUMA nodes:" ); +for (cpu =find_first_bit (present_cpus,MAX_CPUMASK_BITS ); + cpu <MAX_CPUMASK_BITS ; + cpu =find_next_bit (present_cpus,MAX_CPUMASK_BITS , cpu +1 )) { +fprintf (stderr," %d" , cpu); + } +fprintf (stderr,"\n" ); +exit (1 ); + } +bitmap_or (present_cpus, present_cpus, + numa_info[i].node_cpu,MAX_CPUMASK_BITS ); + } +} +void parse_numa_opts (void ) {int i;@@ -244,6 +269,8 @@ void parse_numa_opts(void)set_bit (i, numa_info[i % nb_numa_nodes].node_cpu); } } + +validate_numa_cpus (); } }
Re: [Qemu-devel] [PATCH v2 2/3] numa: Reject configuration if CPU appears on multiple nodes
Quoted 19 lines · Igor Mammedov
Quoted 16 lines · On Mon, 9 Feb 2015 17:53:15 -0200 Eduardo Habkost <[email protected]> wrote:
Each CPU can appear in only one NUMA node on the NUMA config. Reject configuration if a CPU appears in multiple nodes.
Signed-off-by Eduardo Habkost <[email protected]>--- numa.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)numa.c +0
-0@@ -167,6 +167,31 @@ error:return -1 ; }
Quoted 6 lines
numa.c error: · line 173
Quoted 4 lines
numa.c +4
-0+static void validate_numa_cpus (void ) +{ +int i, cpu; +DECLARE_BITMAP (present_cpus,MAX_CPUMASK_BITS );naming is a bit confusing, it's not really present CPUs but more like
possible_cpus
I meant "present in the NUMA configuration". "Possible" wouldn't describe it IMO, as it is just tracking the CPUs seen in the config. I will rename it to "seen_cpus" in the next version.
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v2 2/3] numa: Reject configuration if CPU appears on multiple nodes
Quoted 27 lines · On Thu, 12 Feb 2015 13:24:26 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 19 lines · Igor Mammedov
Quoted 16 lines · On Mon, 9 Feb 2015 17:53:15 -0200 Eduardo Habkost <[email protected]> wrote:
Each CPU can appear in only one NUMA node on the NUMA config. Reject configuration if a CPU appears in multiple nodes.
Signed-off-by Eduardo Habkost <[email protected]>--- numa.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)numa.c +0
-0@@ -167,6 +167,31 @@ error:return -1 ; }Quoted 6 lines
numa.c error: · line 173
Quoted 4 lines
numa.c +4
-0+static void validate_numa_cpus (void ) +{ +int i, cpu; +DECLARE_BITMAP (present_cpus,MAX_CPUMASK_BITS );naming is a bit confusing, it's not really present CPUs but more like
possible_cpus
Quoted 3 lines
I meant "present in the NUMA configuration". "Possible" wouldn't describe it IMO, as it is just tracking the CPUs seen in the config. I will rename it to "
seen_cpus" in the next version.
or maybe numa_cpus
Re: [Qemu-devel] [PATCH v2 2/3] numa: Reject configuration if CPU appears on multiple nodes
Quoted 4 lines · Igor Mammedov
Quoted 1 line · On Thu, 12 Feb 2015 13:24:26 -0200 Eduardo Habkost <[email protected]> wrote:
On Thu, Feb 12, 2015 at 04:01:49PM +0100, Igor Mammedov wrote:
[...]
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
+
DECLARE_BITMAP(present_cpus, MAX_CPUMASK_BITS);naming is a bit confusing, it's not really present CPUs but more like
possible_cpusI meant "present in the NUMA configuration". "Possible" wouldn't describe it IMO, as it is just tracking the CPUs seen in the config. I will rename it to "
seen_cpus" in the next version.or maybe
numa_cpus
We're already inside numa.c in a function called validate_numa_cpus(). I believe a "numa_" prefix would be redundant.
(I just sent v3 of the series using seen_cpus, anyway)
Signature · 1 line
Eduardo
PATCH v2 3/3 numa: Print warning if no node is assigned to a CPU
In reply to Eduardo HabkostInstead of silently assigning CPU to node 0 when it is omitted from the command-line, check if all CPUs up to max_cpus are present in the NUMA configuration.
I am making this a warning and not a fatal error, to allow management software to be updated if necessary.
--- numa.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
numa.c +11 -0
@@ -190,6 +190,17 @@ static void validate_numa_cpus(void)bitmap_or (present_cpus, present_cpus, numa_info[i].node_cpu,MAX_CPUMASK_BITS ); } + + cpu =find_first_zero_bit (present_cpus,MAX_CPUMASK_BITS ); +if (cpu < max_cpus) { +fprintf (stderr,"warning: CPU(s) not present in any NUMA nodes:" ); +for (; + cpu < max_cpus; + cpu =find_next_zero_bit (present_cpus,MAX_CPUMASK_BITS , cpu +1 )) { +fprintf (stderr," %d" , cpu); + } +fprintf (stderr,"\n" ); + } }void parse_numa_opts (void )
Signature · 1 line
2.1.0