diff mbox series

[v2,2/2] of, numa: Fetch empty NUMA node ID from distance map

Message ID 20210927064119.127285-3-gshan@redhat.com
State Accepted, archived
Headers show
Series Specify empty NUMA node | expand

Checks

Context Check Description
robh/checkpatch success

Commit Message

Gavin Shan Sept. 27, 2021, 6:41 a.m. UTC
There is no device node for the empty NUMA node. However, the
corresponding NUMA node ID and distance map is still valid in
"numa-distance-map-v1" compatible device node.

This fetches the NUMA node ID and distance map for these empty
NUMA node from "numa-distance-map-v1" compatible device node.

Signed-off-by: Gavin Shan <gshan@redhat.com>
---
 drivers/of/of_numa.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Rob Herring (Arm) Sept. 27, 2021, 2:49 p.m. UTC | #1
On Mon, Sep 27, 2021 at 1:42 AM Gavin Shan <gshan@redhat.com> wrote:
>
> There is no device node for the empty NUMA node. However, the
> corresponding NUMA node ID and distance map is still valid in
> "numa-distance-map-v1" compatible device node.
>
> This fetches the NUMA node ID and distance map for these empty
> NUMA node from "numa-distance-map-v1" compatible device node.

This is much nicer.

> Signed-off-by: Gavin Shan <gshan@redhat.com>
> ---
>  drivers/of/of_numa.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/drivers/of/of_numa.c b/drivers/of/of_numa.c
> index fe6b13608e51..5949829a1b00 100644
> --- a/drivers/of/of_numa.c
> +++ b/drivers/of/of_numa.c
> @@ -111,6 +111,8 @@ static int __init of_numa_parse_distance_map_v1(struct device_node *map)
>                         return -EINVAL;
>                 }
>
> +               node_set(nodea, numa_nodes_parsed);
> +

With this, couldn't we remove of_numa_parse_cpu_nodes() as the only
thing it does is node_set()?

>                 numa_set_distance(nodea, nodeb, distance);
>
>                 /* Set default distance of node B->A same as A->B */
> --
> 2.23.0
>
Gavin Shan Sept. 27, 2021, 11:59 p.m. UTC | #2
Hi Rob,

On 9/28/21 12:49 AM, Rob Herring wrote:
> On Mon, Sep 27, 2021 at 1:42 AM Gavin Shan <gshan@redhat.com> wrote:
>>
>> There is no device node for the empty NUMA node. However, the
>> corresponding NUMA node ID and distance map is still valid in
>> "numa-distance-map-v1" compatible device node.
>>
>> This fetches the NUMA node ID and distance map for these empty
>> NUMA node from "numa-distance-map-v1" compatible device node.
> 
> This is much nicer.
> 

Indeed, thanks for your suggestions :)

>> Signed-off-by: Gavin Shan <gshan@redhat.com>
>> ---
>>   drivers/of/of_numa.c | 2 ++
>>   1 file changed, 2 insertions(+)
>>
>> diff --git a/drivers/of/of_numa.c b/drivers/of/of_numa.c
>> index fe6b13608e51..5949829a1b00 100644
>> --- a/drivers/of/of_numa.c
>> +++ b/drivers/of/of_numa.c
>> @@ -111,6 +111,8 @@ static int __init of_numa_parse_distance_map_v1(struct device_node *map)
>>                          return -EINVAL;
>>                  }
>>
>> +               node_set(nodea, numa_nodes_parsed);
>> +
> 
> With this, couldn't we remove of_numa_parse_cpu_nodes() as the only
> thing it does is node_set()?
> 

I don't think so for couple of reasons:

(1) With problematic device-tree, the distance map node might be missed
     or incomplete. In this case, of_numa_parse_cpu_nodes() still helps.

(2) @numa_nodes_parsed is also updated when the memory nodes are iterated
     in of_numa_parse_memory_nodes() and numa_add_memblk().

So @numa_nodes_parsed, which is synchronized to @node_possible_map afterwards,
is the gathering output of CPU nodes, memory nodes and distance map node.

>>                  numa_set_distance(nodea, nodeb, distance);
>>
>>                  /* Set default distance of node B->A same as A->B */

Thanks,
Gavin
Rob Herring (Arm) Sept. 28, 2021, 5:22 p.m. UTC | #3
On Mon, Sep 27, 2021 at 6:59 PM Gavin Shan <gshan@redhat.com> wrote:
>
> Hi Rob,
>
> On 9/28/21 12:49 AM, Rob Herring wrote:
> > On Mon, Sep 27, 2021 at 1:42 AM Gavin Shan <gshan@redhat.com> wrote:
> >>
> >> There is no device node for the empty NUMA node. However, the
> >> corresponding NUMA node ID and distance map is still valid in
> >> "numa-distance-map-v1" compatible device node.
> >>
> >> This fetches the NUMA node ID and distance map for these empty
> >> NUMA node from "numa-distance-map-v1" compatible device node.
> >
> > This is much nicer.
> >
>
> Indeed, thanks for your suggestions :)
>
> >> Signed-off-by: Gavin Shan <gshan@redhat.com>
> >> ---
> >>   drivers/of/of_numa.c | 2 ++
> >>   1 file changed, 2 insertions(+)
> >>
> >> diff --git a/drivers/of/of_numa.c b/drivers/of/of_numa.c
> >> index fe6b13608e51..5949829a1b00 100644
> >> --- a/drivers/of/of_numa.c
> >> +++ b/drivers/of/of_numa.c
> >> @@ -111,6 +111,8 @@ static int __init of_numa_parse_distance_map_v1(struct device_node *map)
> >>                          return -EINVAL;
> >>                  }
> >>
> >> +               node_set(nodea, numa_nodes_parsed);
> >> +
> >
> > With this, couldn't we remove of_numa_parse_cpu_nodes() as the only
> > thing it does is node_set()?
> >
>
> I don't think so for couple of reasons:
>
> (1) With problematic device-tree, the distance map node might be missed
>      or incomplete. In this case, of_numa_parse_cpu_nodes() still helps.

It's not the kernel's job to validate the DT (if it was, it is doing a
terrible job). I would suggest writing some checks for dtc if we're
worried about correctness. (The schemas don't work too well for cross
node checks.)

> (2) @numa_nodes_parsed is also updated when the memory nodes are iterated
>      in of_numa_parse_memory_nodes() and numa_add_memblk().
>
> So @numa_nodes_parsed, which is synchronized to @node_possible_map afterwards,
> is the gathering output of CPU nodes, memory nodes and distance map node.

Is it valid to have node id's that are not in the distance map?

Rob
Gavin Shan Sept. 29, 2021, 2 a.m. UTC | #4
On 9/29/21 3:22 AM, Rob Herring wrote:
> On Mon, Sep 27, 2021 at 6:59 PM Gavin Shan <gshan@redhat.com> wrote:
>> On 9/28/21 12:49 AM, Rob Herring wrote:
>>> On Mon, Sep 27, 2021 at 1:42 AM Gavin Shan <gshan@redhat.com> wrote:
>>>>
>>>> There is no device node for the empty NUMA node. However, the
>>>> corresponding NUMA node ID and distance map is still valid in
>>>> "numa-distance-map-v1" compatible device node.
>>>>
>>>> This fetches the NUMA node ID and distance map for these empty
>>>> NUMA node from "numa-distance-map-v1" compatible device node.
>>>
>>> This is much nicer.
>>>
>>
>> Indeed, thanks for your suggestions :)
>>
>>>> Signed-off-by: Gavin Shan <gshan@redhat.com>
>>>> ---
>>>>    drivers/of/of_numa.c | 2 ++
>>>>    1 file changed, 2 insertions(+)
>>>>
>>>> diff --git a/drivers/of/of_numa.c b/drivers/of/of_numa.c
>>>> index fe6b13608e51..5949829a1b00 100644
>>>> --- a/drivers/of/of_numa.c
>>>> +++ b/drivers/of/of_numa.c
>>>> @@ -111,6 +111,8 @@ static int __init of_numa_parse_distance_map_v1(struct device_node *map)
>>>>                           return -EINVAL;
>>>>                   }
>>>>
>>>> +               node_set(nodea, numa_nodes_parsed);
>>>> +
>>>
>>> With this, couldn't we remove of_numa_parse_cpu_nodes() as the only
>>> thing it does is node_set()?
>>>
>>
>> I don't think so for couple of reasons:
>>
>> (1) With problematic device-tree, the distance map node might be missed
>>       or incomplete. In this case, of_numa_parse_cpu_nodes() still helps.
> 
> It's not the kernel's job to validate the DT (if it was, it is doing a
> terrible job). I would suggest writing some checks for dtc if we're
> worried about correctness. (The schemas don't work too well for cross
> node checks.)
> 

I didn't look into dtc's code and not sure if dtc has this sort of validation.
Besides, dtc is out of scope when QEMU is involved. The device-tree blob isn't
produced by dtc in QEMU.


>> (2) @numa_nodes_parsed is also updated when the memory nodes are iterated
>>       in of_numa_parse_memory_nodes() and numa_add_memblk().
>>
>> So @numa_nodes_parsed, which is synchronized to @node_possible_map afterwards,
>> is the gathering output of CPU nodes, memory nodes and distance map node.
> 
> Is it valid to have node id's that are not in the distance map?
> 

Yes, it's valid from the kernel's perspective. The default distance
matrix, where the local and remote distances are 10 and 20, is applied
if the distance map is missed in device-tree. The code can be found from
drivers/base/arch_numa.c::numa_alloc_distance()

Besides, it's possible that the distance map isn't populated by QEMU.
However, I'm going to improve the situation so the distance map will
be populated unconditionally.

The following option is supported by QEMU, to specify the distance
between two NUMA nodes. However, it's not mandatory. The distance
map in device-tree won't be populated if the option is missed.

     -numa dist,a=<src_numa_node>,b=<dst_numa_node>,val=<distance>

Thanks,
Gavin
Rob Herring (Arm) Oct. 4, 2021, 6:13 p.m. UTC | #5
On Mon, 27 Sep 2021 14:41:19 +0800, Gavin Shan wrote:
> There is no device node for the empty NUMA node. However, the
> corresponding NUMA node ID and distance map is still valid in
> "numa-distance-map-v1" compatible device node.
> 
> This fetches the NUMA node ID and distance map for these empty
> NUMA node from "numa-distance-map-v1" compatible device node.
> 
> Signed-off-by: Gavin Shan <gshan@redhat.com>
> ---
>  drivers/of/of_numa.c | 2 ++
>  1 file changed, 2 insertions(+)
> 

Applied, thanks!
diff mbox series

Patch

diff --git a/drivers/of/of_numa.c b/drivers/of/of_numa.c
index fe6b13608e51..5949829a1b00 100644
--- a/drivers/of/of_numa.c
+++ b/drivers/of/of_numa.c
@@ -111,6 +111,8 @@  static int __init of_numa_parse_distance_map_v1(struct device_node *map)
 			return -EINVAL;
 		}
 
+		node_set(nodea, numa_nodes_parsed);
+
 		numa_set_distance(nodea, nodeb, distance);
 
 		/* Set default distance of node B->A same as A->B */