cpu-topology: Skip the exist but not possible cpu nodes
Subsystems (2)
PATCH 1/1 cpu-topology: Skip the exist but not possible cpu nodes
When CONFIG_NR_CPUS is smaller than the cpu nodes defined in the device tree, the cpu node parsing will fail. And this is not reasonable for a legal device tree configs.
In this patch, skip such cpu nodes rather than return an error.
--- drivers/base/arch_topology.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-)
drivers/base/arch_topology.c +26 -9
@@ -250,20 +250,34 @@ core_initcall(free_raw_capacity);#if defined(CONFIG_ARM64 ) || defined(CONFIG_RISCV )static int __init get_cpu_for_node (struct device_node *node) { -struct device_node *cpu_node; +struct device_node *cpu_node, *t;int cpu; +bool found = false; cpu_node =of_parse_phandle (node,"cpu" ,0 );if (!cpu_node) -return -1 ; +return -EINVAL ; + +for_each_of_cpu_node (t) +if (t == cpu_node) { + found = true; +break ; + } + +if (!found) { +pr_crit ("Unable to find CPU node for %pOF\n" , cpu_node); +return -EINVAL ; + } cpu =of_cpu_node_to_id (cpu_node);if (cpu >=0 )topology_parse_cpu_capacity (cpu_node, cpu); -else -pr_crit ("Unable to find CPU node for %pOF\n" , cpu_node); +else { +pr_warn ("CPU node for %pOF exist but the possible cpu range is :%*pbl\n" , + cpu_node,cpumask_pr_args (cpu_possible_mask)); + cpu = -ENODEV ; + } -of_node_put (cpu_node);return cpu; }
@@ -287,10 +301,13 @@ static int __init parse_core(struct device_node *core, int package_id, cpu_topology[cpu].core_id = core_id; cpu_topology[cpu].thread_id = i; }else { -pr_err ("%pOF: Can't get CPU for thread\n" , - t); +if (cpu != -ENODEV ) +pr_err ("%pOF: Can't get CPU for thread\n" , + t); +else + cpu =0 ;of_node_put (t); -return -EINVAL ; +return cpu; }of_node_put (t); }
@@ -307,7 +324,7 @@ static int __init parse_core(struct device_node *core, int package_id, cpu_topology[cpu].package_id = package_id; cpu_topology[cpu].core_id = core_id; - }else if (leaf) { + }else if (leaf && cpu != -ENODEV ) {pr_err ("%pOF: Can't get CPU for leaf core\n" , core);return -EINVAL ; }
Signature · 1 line
2.8.1
Quoted 4 lines · Zeng Tao
When
CONFIG_NR_CPUSis smaller than the cpu nodes defined in the device tree, the cpu node parsing will fail. And this is not reasonable for a legal device tree configs.
In this patch, skip such cpu nodes rather than return an error.
Is this extra code really necessary?
Currently you get warnings indicating that CONFIG_NR_CPUS is too small so you could correct the setup issue easily.
Example: Arm64 Juno board
$ grep "cpu@" ./arch/arm64/boot/dts/arm/juno.dts
A57_0: cpu@0 {
A57_1: cpu@1 {
A53_0: cpu@100 {
A53_1: cpu@101 {
A53_2: cpu@102 {
A53_3: cpu@103 {root@juno:~# uname -r 5.5.0-rc5
root@juno:~# zcat /proc/config.gz | grep CONFIG_NR_CPUS CONFIG_NR_CPUS=4
root@juno:~# cat /proc/cpuinfo | grep ^proc processor : 0 processor : 1 processor : 2 processor : 3
root@juno:~# dmesg | grep "Unable\|Can't" [ 0.085089] Unable to find CPU node for /cpus/cpu@102 [ 0.090179] /cpus/cpu-map/cluster1/core2: Can't get CPU for leaf core
[...]
Quoted 12 lines
-----Original Message-----
From: Dietmar Eggemann [mailto:[email protected]]
Sent: Tuesday, January 07, 2020 2:42 AM
To: Zengtao (B); [email protected]
Cc: Linuxarm; Greg Kroah-Hartman; Rafael J. Wysocki; [email protected]
Subject: Re: [PATCH] cpu-topology: Skip the exist but not possible cpu nodesQuoted 1 line · Zeng Tao
When
CONFIG_NR_CPUSis smaller than the cpu nodes defined in thedevice
Quoted 9 lines
Quoted 3 lines
tree, the cpu node parsing will fail. And this is not reasonable for a legal device tree configs.
In this patch, skip such cpu nodes rather than return an error.Is this extra code really necessary?
Currently you get warnings indicating that
CONFIG_NR_CPUSis too small so you could correct the setup issue easily.
Not only about warning messages, the problem is :
What we are expected to do if the CONFIG_NR_CPUS is too small? I think there are two choices:
1. Keep the dts parsing result, but skip the the CPU nodes whose id exceeds the the CONFIG_NR_CPUS, and this is what this patch do.
2. Just abort all the CPU nodes parsing, and using MPIDR to guess the topology, and this is what the current code do.
And i think choice 1 is better because:
1. It's a legal dts, we should keep the same result whether CONFIG_NR_CPUS is too small or not.
2. In the function of_parse_and_init_cpus, we just do the same way as choice 1.
But i am open for the issue, any suggestions are welcomed.
Thanks
Zengtao
Quoted 27 lines
Example: Arm64 Juno board
$ grep "cpu@" ./arch/arm64/boot/dts/arm/juno.dts A57_0: cpu@0 { A57_1: cpu@1 { A53_0: cpu@100 { A53_1: cpu@101 { A53_2: cpu@102 { A53_3: cpu@103 {root@juno:~# uname -r 5.5.0-rc5root@juno:~# zcat /proc/config.gz | grep CONFIG_NR_CPUS CONFIG_NR_CPUS=4root@juno:~# cat /proc/cpuinfo | grep ^proc processor : 0 processor : 1 processor : 2 processor : 3root@juno:~# dmesg | grep "Unable\|Can't" [ 0.085089] Unable to find CPU node for /cpus/cpu@102 [ 0.090179] /cpus/cpu-map/cluster1/core2: Can't get CPU for leaf core[...]
Quoted 22 lines · Zengtao (B)
Quoted 12 lines
-----Original Message-----
From: Dietmar Eggemann [mailto:[email protected]]
Sent: Tuesday, January 07, 2020 2:42 AM
To: Zengtao (B); [email protected]
Cc: Linuxarm; Greg Kroah-Hartman; Rafael J. Wysocki; [email protected]
Subject: Re: [PATCH] cpu-topology: Skip the exist but not possible cpu nodesQuoted 1 line · Zeng Tao
When
CONFIG_NR_CPUSis smaller than the cpu nodes defined in thedevice
Quoted 9 lines
Quoted 3 lines
tree, the cpu node parsing will fail. And this is not reasonable for a legal device tree configs.
In this patch, skip such cpu nodes rather than return an error.Is this extra code really necessary?
Currently you get warnings indicating that
CONFIG_NR_CPUSis too small so you could correct the setup issue easily.
Quoted 7 lines
Not only about warning messages, the problem is :
What we are expected to do if theCONFIG_NR_CPUSis too small? I think there are two choices:
1. Keep the dts parsing result, but skip the the CPU nodes whose id exceeds the theCONFIG_NR_CPUS, and this is what this patch do.
2. Just abort all the CPU nodes parsing, and using MPIDR to guess the topology, and this is what the current code do.
Ah, you're referring to:
530 void __init init_cpu_topology(void)
531 {
...
540 else if (of_have_populated_dt() && parse_dt_topology())
541 --> reset_cpu_topology();
With my Juno example (6 Cpus in DT but CONFIG_NR_CPUS=4):
root@juno:~# dmesg | grep "\*\*\|mpidr" [ 0.084760] ** get_cpu_for_node() cpu=1 [ 0.088706] ** get_cpu_for_node() cpu=2 [ 0.092592] ** get_cpu_for_node() cpu=0 [ 0.096550] ** get_cpu_for_node() cpu=3 [ 0.105578] ** get_cpu_for_node() cpu=-19 [ 0.116070] ** store_cpu_topology(): cpuid=0 [ 0.120355] CPU0: cluster 1 core 0 thread -1 mpidr 0x00000080000100 [ 0.242465] ** store_cpu_topology(): cpuid=1 [ 0.242471] CPU1: cluster 0 core 0 thread -1 mpidr 0x00000080000000 [ 0.286505] ** store_cpu_topology(): cpuid=2 [ 0.286510] CPU2: cluster 0 core 1 thread -1 mpidr 0x00000080000001 [ 0.330631] ** store_cpu_topology(): cpuid=3 [ 0.330637] CPU3: cluster 1 core 1 thread -1 mpidr 0x00000080000101
and with your patch:
root@juno:~# dmesg | grep "\*\*\|mpidr" [ 0.084778] ** get_cpu_for_node() cpu=1 [ 0.088742] ** get_cpu_for_node() cpu=2 [ 0.092662] ** get_cpu_for_node() cpu=0 [ 0.096627] ** get_cpu_for_node() cpu=3 [ 0.107942] ** get_cpu_for_node() cpu=-19 [ 0.119429] ** get_cpu_for_node() cpu=-19 [ 0.123461] ** store_cpu_topology(): cpuid=0 [ 0.243571] ** store_cpu_topology(): cpuid=1 [ 0.287610] ** store_cpu_topology(): cpuid=2 [ 0.331737] ** store_cpu_topology(): cpuid=3
so we bail out of store_cpu_topology() since 'cpuid_topo->package_id != -1'.
Quoted 6 lines
And i think choice 1 is better because:
1. It's a legal dts, we should keep the same result whetherCONFIG_NR_CPUSis too small or not.
2. In the functionof_parse_and_init_cpus, we just do the same way as choice 1.But i am open for the issue, any suggestions are welcomed.
[...]
Quoted 83 lines
-----Original Message-----
From: Dietmar Eggemann [mailto:[email protected]]
Sent: Tuesday, January 07, 2020 9:12 PM
To: Zengtao (B); [email protected]
Cc: Linuxarm; Greg Kroah-Hartman; Rafael J. Wysocki; [email protected]
Subject: Re: [PATCH] cpu-topology: Skip the exist but not possible cpu nodesQuoted 11 lines · Zengtao (B)
Quoted 11 lines
-----Original Message-----
From: Dietmar Eggemann [mailto:[email protected]]
Sent: Tuesday, January 07, 2020 2:42 AM
To: Zengtao (B); [email protected]
Cc: Linuxarm; Greg Kroah-Hartman; Rafael J. Wysocki; [email protected]
Subject: Re: [PATCH] cpu-topology: Skip the exist but not possible cpu nodesQuoted 1 line · Zeng Tao
When
CONFIG_NR_CPUSis smaller than the cpu nodes defined in theQuoted 8 lines
Quoted 8 lines
device
Quoted 3 lines
tree, the cpu node parsing will fail. And this is not reasonable for a legal device tree configs.
In this patch, skip such cpu nodes rather than return an error.Is this extra code really necessary?
Currently you get warnings indicating that
CONFIG_NR_CPUSis toosmall
Quoted 5 lines
Quoted 2 lines
so you could correct the setup issue easily.
Not only about warning messages, the problem is :
What we are expected to do if theCONFIG_NR_CPUSis too small? I thinkthere
Quoted 2 lines
are two choices:
1. Keep the dts parsing result, but skip the the CPU nodes whose idexceeds the
Quoted 2 lines
the
CONFIG_NR_CPUS, and this is what this patch do.
2. Just abort all the CPU nodes parsing, and using MPIDR to guess thetopology,
Quoted 1 line
and this is what the current code do.
Ah, you're referring to:
530 void
__initinit_cpu_topology(void)
531 {
...
540 else if (of_have_populated_dt()&&parse_dt_topology())
541 -->reset_cpu_topology();With my Juno example (6 Cpus in DT but
CONFIG_NR_CPUS=4):root@juno:~# dmesg | grep "\*\*\|mpidr" [ 0.084760] ** get_cpu_for_node() cpu=1 [ 0.088706] ** get_cpu_for_node() cpu=2 [ 0.092592] ** get_cpu_for_node() cpu=0 [ 0.096550] ** get_cpu_for_node() cpu=3 [ 0.105578] ** get_cpu_for_node() cpu=-19 [ 0.116070] ** store_cpu_topology(): cpuid=0 [ 0.120355] CPU0: cluster 1 core 0 thread -1 mpidr 0x00000080000100 [ 0.242465] ** store_cpu_topology(): cpuid=1 [ 0.242471] CPU1: cluster 0 core 0 thread -1 mpidr 0x00000080000000 [ 0.286505] ** store_cpu_topology(): cpuid=2 [ 0.286510] CPU2: cluster 0 core 1 thread -1 mpidr 0x00000080000001 [ 0.330631] ** store_cpu_topology(): cpuid=3 [ 0.330637] CPU3: cluster 1 core 1 thread -1 mpidr 0x00000080000101and with your patch:
root@juno:~# dmesg | grep "\*\*\|mpidr" [ 0.084778] ** get_cpu_for_node() cpu=1 [ 0.088742] ** get_cpu_for_node() cpu=2 [ 0.092662] ** get_cpu_for_node() cpu=0 [ 0.096627] ** get_cpu_for_node() cpu=3 [ 0.107942] ** get_cpu_for_node() cpu=-19 [ 0.119429] ** get_cpu_for_node() cpu=-19 [ 0.123461] ** store_cpu_topology(): cpuid=0 [ 0.243571] ** store_cpu_topology(): cpuid=1 [ 0.287610] ** store_cpu_topology(): cpuid=2 [ 0.331737] ** store_cpu_topology(): cpuid=3
Quoted 3 lines
so we bail out of
store_cpu_topology()since 'cpuid_topo->package_id!= -1'.
Good, you got me. And I found this issue when I test the NUMA issue. Thanks.
Quoted 10 lines
Quoted 2 lines
And i think choice 1 is better because:
1. It's a legal dts, we should keep the same result whether
CONFIG_NR_CPUSisQuoted 2 lines
too small or not.
2. In the functionof_parse_and_init_cpus, we just do the same way aschoice 1.
Quoted 2 lines
But i am open for the issue, any suggestions are welcomed.
[...]
Quoted 29 lines · Zeng Tao
When
CONFIG_NR_CPUSis smaller than the cpu nodes defined in the device tree, the cpu node parsing will fail. And this is not reasonable for a legal device tree configs.
In this patch, skip such cpu nodes rather than return an error.Signed-off-by Zeng Tao <[email protected]>--- drivers/base/arch_topology.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-)drivers/base/arch_topology.c +5
-2@@ -250,20 +250,34 @@ core_initcall(free_raw_capacity);#if defined(CONFIG_ARM64 ) || defined(CONFIG_RISCV )static int __init get_cpu_for_node (struct device_node *node) { -struct device_node *cpu_node; +struct device_node *cpu_node, *t;int cpu; +bool found = false; cpu_node =of_parse_phandle (node,"cpu" ,0 );if (!cpu_node) -return -1 ; +return -EINVAL ; + +for_each_of_cpu_node (t)
drivers/base/arch_topology.c core_initcall(free_raw_capacity); · line 271
Quoted 10 lines
drivers/base/arch_topology.c +9
-0+if (t == cpu_node) { + found = true; +break ; + } + +if (!found) { +pr_crit ("Unable to find CPU node for %pOF\n" , cpu_node); +return -EINVAL ; + }
The whole extra logic added above sounds redundant, details below...
drivers/base/arch_topology.c core_initcall(free_raw_capacity); · line 278
Quoted 9 lines
drivers/base/arch_topology.c +4
-2cpu =of_cpu_node_to_id (cpu_node);if (cpu >=0 )topology_parse_cpu_capacity (cpu_node, cpu); -else -pr_crit ("Unable to find CPU node for %pOF\n" , cpu_node); +else { +pr_warn ("CPU node for %pOF exist but the possible cpu range is :%*pbl\n" , + cpu_node,cpumask_pr_args (cpu_possible_mask)); + cpu = -ENODEV ;
.. of_cpu_node_to_id returns -ENODEV anyways so above assignment is also redundant. All you achieved is explicit error message. I think we should be fine combining them. Just extend existing error log with both message.
Quoted 7 lines
drivers/base/arch_topology.c +1
-1+ } -of_node_put (cpu_node);return cpu; }
drivers/base/arch_topology.c static int __init parse_core(struct device_node *core, int package_id, · line 308
Quoted 10 lines
drivers/base/arch_topology.c +5
-2@@ -287,10 +301,13 @@ static int __init parse_core(struct device_node *core, int package_id, cpu_topology[cpu].core_id = core_id; cpu_topology[cpu].thread_id = i; }else { -pr_err ("%pOF: Can't get CPU for thread\n" , - t); +if (cpu != -ENODEV ) +pr_err ("%pOF: Can't get CPU for thread\n" , + t); +else + cpu =0 ;
I would rather use another variable instead of reusing 'cpu'
drivers/base/arch_topology.c static int __init parse_core(struct device_node *core, int package_id, · line 310
Quoted 3 lines
drivers/base/arch_topology.c +1
-1of_node_put (t); -return -EINVAL ; +return cpu;
Shouldn't we continue here if cpu == -ENODEV instead of returning 0 ?
drivers/base/arch_topology.c static int __init parse_core(struct device_node *core, int package_id, · line 327
Quoted 9 lines
drivers/base/arch_topology.c +1
-1}of_node_put (t); }@@ -307,7 +324,7 @@ static int __init parse_core(struct device_node *core, int package_id, cpu_topology[cpu].package_id = package_id; cpu_topology[cpu].core_id = core_id; - }else if (leaf) { + }else if (leaf && cpu != -ENODEV ) {
I am still not sure on the approach, it is based on -ENODEV as valid error and allow to continue. It may be fine, I just need to make sure.
--
Regards,
Sudeep
Quoted 45 lines
-----Original Message-----
From: Sudeep Holla [mailto:[email protected]]
Sent: Tuesday, January 07, 2020 10:50 PM
To: Zengtao (B)
Cc: Linuxarm; Greg Kroah-Hartman; Rafael J. Wysocki; Sudeep Holla; [email protected]
Subject: Re: [PATCH] cpu-topology: Skip the exist but not possible cpu nodesQuoted 1 line · Zeng Tao
When
CONFIG_NR_CPUSis smaller than the cpu nodes defined in thedevice
Quoted 7 lines
tree, the cpu node parsing will fail. And this is not reasonable for a legal device tree configs.
In this patch, skip such cpu nodes rather than return an error.Signed-off-by Zeng Tao <[email protected]>--- drivers/base/arch_topology.c | 35++++++++++++++++++++++++++---------
Quoted 25 lines
1 file changed, 26 insertions(+), 9 deletions(-)drivers/base/arch_topology.c +9
-2@@ -250,20 +250,34 @@ core_initcall(free_raw_capacity);#if defined(CONFIG_ARM64 ) || defined(CONFIG_RISCV )static int __init get_cpu_for_node (struct device_node *node) { -struct device_node *cpu_node; +struct device_node *cpu_node, *t;int cpu; +bool found = false; cpu_node =of_parse_phandle (node,"cpu" ,0 );if (!cpu_node) -return -1 ; +return -EINVAL ; + +for_each_of_cpu_node (t) +if (t == cpu_node) { + found = true; +break ; + }
Quoted 8 lines
drivers/base/arch_topology.c core_initcall(free_raw_capacity); · line 271
Quoted 6 lines
drivers/base/arch_topology.c +5
-0+ +if (!found) { +pr_crit ("Unable to find CPU node for %pOF\n" , cpu_node); +return -EINVAL ; + }The whole extra logic added above sounds redundant, details below...
The above logic is different from what is done in of_cpu_node_to_id:
1. The above checks if the cpu node exist in the dts.
2. The of_cpu_node_to_id checks if the cpu node exist in the possible cpus.
And basically my idea is:
1. check if the cpu node exist or not.
If not exist, just return an error to indicate that this is a broken dts. If exist, goto 2.
2. check if the cpu node is a possible one?
And happy to continue if possible, or just skip and warn if not possible.
Quoted 38 lines
drivers/base/arch_topology.c core_initcall(free_raw_capacity);
Quoted 8 lines
drivers/base/arch_topology.c +2
-2cpu =of_cpu_node_to_id (cpu_node);if (cpu >=0 )topology_parse_cpu_capacity (cpu_node, cpu); -else -pr_crit ("Unable to find CPU node for %pOF\n" , cpu_node); +else { + pr_warn("CPU node for %pOF exist but the possible cpu rangeis :%*pbl\n",
drivers/base/arch_topology.c core_initcall(free_raw_capacity); · line 278
Quoted 2 lines
drivers/base/arch_topology.c +2
-0+ cpu_node, cpumask_pr_args(cpu_possible_mask)); + cpu = -ENODEV ;..
of_cpu_node_to_idreturns-ENODEVanyways so above assignment is also
redundant. All you achieved is explicit error message. I think we should be fine combining them. Just extend existing error log with both message.drivers/base/arch_topology.c static int __init parse_core(struct
Quoted 7 lines
drivers/base/arch_topology.c +1
-1+ } -of_node_put (cpu_node);return cpu; }@@ -287,10 +301,13 @@ static int __init parse_core(struct
device_node*core, intpackage_id,drivers/base/arch_topology.c static int __init parse_core(struct device_node *core, int package_id, · line 308
Quoted 10 lines
drivers/base/arch_topology.c +5
-2cpu_topology[cpu].core_id = core_id; cpu_topology[cpu].thread_id = i; }else { -pr_err ("%pOF: Can't get CPU for thread\n" , - t); +if (cpu != -ENODEV ) +pr_err ("%pOF: Can't get CPU for thread\n" , + t); +else + cpu =0 ;I would rather use another variable instead of reusing 'cpu'
Quoted 5 lines
drivers/base/arch_topology.c static int __init parse_core(struct device_node *core, int package_id, · line 310
Quoted 3 lines
drivers/base/arch_topology.c +1
-1of_node_put (t); -return -EINVAL ; +return cpu;Shouldn't we continue here if cpu ==
-ENODEVinstead of returning 0 ?
Good catch, I just focus on core parsing, and thread parsing shoud work the same way.
Quoted 7 lines
drivers/base/arch_topology.c static int __init parse_core(struct device_node
Quoted 5 lines
drivers/base/arch_topology.c +0
-0}of_node_put (t); }@@ -307,7 +324,7 @@ static int __init parse_core(struct device_node*core, int
package_id,Quoted 1 line
Quoted 8 lines
drivers/base/arch_topology.c static int __init parse_core(struct device_node *core, int package_id, · line 327
Quoted 4 lines
drivers/base/arch_topology.c +1
-1cpu_topology[cpu].package_id = package_id; cpu_topology[cpu].core_id = core_id; - }else if (leaf) { + }else if (leaf && cpu != -ENODEV ) {I am still not sure on the approach, it is based on
-ENODEVas valid error and allow to continue. It may be fine, I just need to make sure.
I have the same concern, I have tried to find out some other return values But seems not good enough.
Maybe it's better to introduce a new function to replace of_cpu_node_to_id Any good suggestion?
Thanks
Regards
Zengtao
On Wed, Jan 08, 2020 at 01:57:34AM +0000, Zengtao (B) wrote:
[...]
Quoted 5 lines
I have the same concern, I have tried to find out some other return values But seems not good enough.
Maybe it's better to introduce a new function to replaceof_cpu_node_to_idAny good suggestion?
No I don't have any. So please drop the extra logic, add a comment on -ENODEV return value and use it as needed.
--
Regards,
Sudeep
Quoted 14 lines
-----Original Message-----
From: Sudeep Holla [mailto:[email protected]]
Sent: Friday, January 10, 2020 7:16 PM
To: Zengtao (B)
Cc: Linuxarm; Greg Kroah-Hartman; Rafael J. Wysocki; [email protected]; Sudeep Holla
Subject: Re: [PATCH] cpu-topology: Skip the exist but not possible cpu nodesOn Wed, Jan 08, 2020 at 01:57:34AM +0000, Zengtao (B) wrote:
[...]Quoted 1 line
I have the same concern, I have tried to find out some other return
values
Quoted 8 lines
Quoted 2 lines
But seems not good enough.
Maybe it's better to introduce a new function to replace
of_cpu_node_to_idQuoted 2 lines
Any good suggestion?
No I don't have any. So please drop the extra logic, add a comment on
-ENODEVreturn value and use it as needed.
OK, I will address the review comments and send v2. Thanks
Zengtao