devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] of: to support binding numa node to root subnode(non-bus)
@ 2015-08-24 12:30 Zhen Lei
  2015-08-24 13:25 ` Rob Herring
  0 siblings, 1 reply; 4+ messages in thread
From: Zhen Lei @ 2015-08-24 12:30 UTC (permalink / raw)
  To: Grant Likely, Rob Herring, devicetree, Greg Kroah-Hartman,
	linux-kernel
  Cc: Zefan Li, Xinwei Hu, Tianhong Ding, Hanjun Guo, Zhen Lei

If use of_platform_populate to scan dt-nodes and add devices, the
subnode of root(such as /smmu), when being scanned and invoke
of_device_add, the ofdev->dev.parent is always equal &platform_bus. So
that, function set_dev_node will not be called. And in device_add,
dev_to_node(parent) always return NUMA_NO_NODE.

Signed-off-by: Zhen Lei <thunder.leizhen-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
---
 drivers/base/core.c | 2 +-
 drivers/of/device.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index dafae6d..5df4f46b 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -1017,7 +1017,7 @@ int device_add(struct device *dev)
 		dev->kobj.parent = kobj;

 	/* use parent numa_node */
-	if (parent)
+	if (parent && (parent != &platform_bus))
 		set_dev_node(dev, dev_to_node(parent));

 	/* first, register with generic layer. */
diff --git a/drivers/of/device.c b/drivers/of/device.c
index 8b91ea2..96ebece 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -63,7 +63,7 @@ int of_device_add(struct platform_device *ofdev)
 	/* device_add will assume that this device is on the same node as
 	 * the parent. If there is no parent defined, set the node
 	 * explicitly */
-	if (!ofdev->dev.parent)
+	if (!ofdev->dev.parent || (ofdev->dev.parent == &platform_bus))
 		set_dev_node(&ofdev->dev, of_node_to_nid(ofdev->dev.of_node));

 	return device_add(&ofdev->dev);
--
2.5.0


--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] of: to support binding numa node to root subnode(non-bus)
  2015-08-24 12:30 [PATCH 1/1] of: to support binding numa node to root subnode(non-bus) Zhen Lei
@ 2015-08-24 13:25 ` Rob Herring
  2015-08-25  2:24   ` Leizhen (ThunderTown)
  0 siblings, 1 reply; 4+ messages in thread
From: Rob Herring @ 2015-08-24 13:25 UTC (permalink / raw)
  To: Zhen Lei, Benjamin Herrenschmidt
  Cc: Grant Likely, Rob Herring, devicetree, Greg Kroah-Hartman,
	linux-kernel, Zefan Li, Xinwei Hu, Tianhong Ding, Hanjun Guo

+benh

On Mon, Aug 24, 2015 at 7:30 AM, Zhen Lei <thunder.leizhen@huawei.com> wrote:
> If use of_platform_populate to scan dt-nodes and add devices, the
> subnode of root(such as /smmu), when being scanned and invoke

You should have a bus as the sub-node of root rather than devices
directly off of root. You still have a problem though...

> of_device_add, the ofdev->dev.parent is always equal &platform_bus. So
> that, function set_dev_node will not be called. And in device_add,
> dev_to_node(parent) always return NUMA_NO_NODE.
>
> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
> ---
>  drivers/base/core.c | 2 +-
>  drivers/of/device.c | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index dafae6d..5df4f46b 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -1017,7 +1017,7 @@ int device_add(struct device *dev)
>                 dev->kobj.parent = kobj;
>
>         /* use parent numa_node */
> -       if (parent)
> +       if (parent && (parent != &platform_bus))

This is only fixing one specific case, but I think things are broken
for any case where the NUMA associativity if not set at the top level
bus node. I think this should be something like:

if (parent && (dev_to_node(dev) != NO_NUMA_NODE))

Then the OF code can set the node however it wants.

>                 set_dev_node(dev, dev_to_node(parent));
>
>         /* first, register with generic layer. */
> diff --git a/drivers/of/device.c b/drivers/of/device.c
> index 8b91ea2..96ebece 100644
> --- a/drivers/of/device.c
> +++ b/drivers/of/device.c
> @@ -63,7 +63,7 @@ int of_device_add(struct platform_device *ofdev)
>         /* device_add will assume that this device is on the same node as
>          * the parent. If there is no parent defined, set the node
>          * explicitly */
> -       if (!ofdev->dev.parent)
> +       if (!ofdev->dev.parent || (ofdev->dev.parent == &platform_bus))

And then remove the if here.

>                 set_dev_node(&ofdev->dev, of_node_to_nid(ofdev->dev.of_node));
>
>         return device_add(&ofdev->dev);
> --
> 2.5.0
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe devicetree" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] of: to support binding numa node to root subnode(non-bus)
  2015-08-24 13:25 ` Rob Herring
@ 2015-08-25  2:24   ` Leizhen (ThunderTown)
       [not found]     ` <55DBD1F8.1010206-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Leizhen (ThunderTown) @ 2015-08-25  2:24 UTC (permalink / raw)
  To: Rob Herring, Benjamin Herrenschmidt
  Cc: Grant Likely, Rob Herring, devicetree, Greg Kroah-Hartman,
	linux-kernel, Zefan Li, Xinwei Hu, Tianhong Ding, Hanjun Guo



On 2015/8/24 21:25, Rob Herring wrote:
> +benh
> 
> On Mon, Aug 24, 2015 at 7:30 AM, Zhen Lei <thunder.leizhen@huawei.com> wrote:
>> If use of_platform_populate to scan dt-nodes and add devices, the
>> subnode of root(such as /smmu), when being scanned and invoke
> 
> You should have a bus as the sub-node of root rather than devices
> directly off of root. You still have a problem though...

But actually the parent of bus is also &platform_bus if we didn't have special initialization.
For example:
The function of_platform_device_create_pdata invoke of_device_alloc first, then invoke of_device_add.
But in of_device_alloc, we can find that:
	dev->dev.parent = parent ? : &platform_bus;

> 
>> of_device_add, the ofdev->dev.parent is always equal &platform_bus. So
>> that, function set_dev_node will not be called. And in device_add,
>> dev_to_node(parent) always return NUMA_NO_NODE.
>>
>> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
>> ---
>>  drivers/base/core.c | 2 +-
>>  drivers/of/device.c | 2 +-
>>  2 files changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/base/core.c b/drivers/base/core.c
>> index dafae6d..5df4f46b 100644
>> --- a/drivers/base/core.c
>> +++ b/drivers/base/core.c
>> @@ -1017,7 +1017,7 @@ int device_add(struct device *dev)
>>                 dev->kobj.parent = kobj;
>>
>>         /* use parent numa_node */
>> -       if (parent)
>> +       if (parent && (parent != &platform_bus))
> 
> This is only fixing one specific case, but I think things are broken
> for any case where the NUMA associativity if not set at the top level
> bus node. I think this should be something like:
> 
> if (parent && (dev_to_node(dev) != NO_NUMA_NODE))

It seems a mistake, we should use equal sign.
if (parent && (dev_to_node(dev) == NUMA_NO_NODE))

> 
> Then the OF code can set the node however it wants.

OK. I will send patch v2 base upon your advice. Thank you.

> 
>>                 set_dev_node(dev, dev_to_node(parent));
>>
>>         /* first, register with generic layer. */
>> diff --git a/drivers/of/device.c b/drivers/of/device.c
>> index 8b91ea2..96ebece 100644
>> --- a/drivers/of/device.c
>> +++ b/drivers/of/device.c
>> @@ -63,7 +63,7 @@ int of_device_add(struct platform_device *ofdev)
>>         /* device_add will assume that this device is on the same node as
>>          * the parent. If there is no parent defined, set the node
>>          * explicitly */
>> -       if (!ofdev->dev.parent)
>> +       if (!ofdev->dev.parent || (ofdev->dev.parent == &platform_bus))
> 
> And then remove the if here.
> 

OK. I also think remove this statement will be better. Althouth set_dev_node maybe called two times,
but it only spends very little time, and this almost happened at initialization phase.

>>                 set_dev_node(&ofdev->dev, of_node_to_nid(ofdev->dev.of_node));
>>
>>         return device_add(&ofdev->dev);
>> --
>> 2.5.0
>>
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe devicetree" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
> .
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] of: to support binding numa node to root subnode(non-bus)
       [not found]     ` <55DBD1F8.1010206-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
@ 2015-08-25 16:05       ` Rob Herring
  0 siblings, 0 replies; 4+ messages in thread
From: Rob Herring @ 2015-08-25 16:05 UTC (permalink / raw)
  To: Leizhen (ThunderTown)
  Cc: Benjamin Herrenschmidt, Grant Likely, Rob Herring, devicetree,
	Greg Kroah-Hartman, linux-kernel, Zefan Li, Xinwei Hu,
	Tianhong Ding, Hanjun Guo

On Mon, Aug 24, 2015 at 9:24 PM, Leizhen (ThunderTown)
<thunder.leizhen-hv44wF8Li93QT0dZR+AlfA@public.gmane.org> wrote:
>
>
> On 2015/8/24 21:25, Rob Herring wrote:
>> +benh
>>
>> On Mon, Aug 24, 2015 at 7:30 AM, Zhen Lei <thunder.leizhen-hv44wF8Li93QT0dZR+AlfA@public.gmane.org> wrote:
>>> If use of_platform_populate to scan dt-nodes and add devices, the
>>> subnode of root(such as /smmu), when being scanned and invoke
>>
>> You should have a bus as the sub-node of root rather than devices
>> directly off of root. You still have a problem though...
>
> But actually the parent of bus is also &platform_bus if we didn't have special initialization.
> For example:
> The function of_platform_device_create_pdata invoke of_device_alloc first, then invoke of_device_add.
> But in of_device_alloc, we can find that:
>         dev->dev.parent = parent ? : &platform_bus;

This syntax is confusing, but in GCC this is the same as:

dev->dev.parent = parent ? parent : &platform_bus;

And parent is set for everything except nodes off of root.
/sys/devices/platform/* will show the hierarchy.

>>> of_device_add, the ofdev->dev.parent is always equal &platform_bus. So
>>> that, function set_dev_node will not be called. And in device_add,
>>> dev_to_node(parent) always return NUMA_NO_NODE.
>>>
>>> Signed-off-by: Zhen Lei <thunder.leizhen-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
>>> ---
>>>  drivers/base/core.c | 2 +-
>>>  drivers/of/device.c | 2 +-
>>>  2 files changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/base/core.c b/drivers/base/core.c
>>> index dafae6d..5df4f46b 100644
>>> --- a/drivers/base/core.c
>>> +++ b/drivers/base/core.c
>>> @@ -1017,7 +1017,7 @@ int device_add(struct device *dev)
>>>                 dev->kobj.parent = kobj;
>>>
>>>         /* use parent numa_node */
>>> -       if (parent)
>>> +       if (parent && (parent != &platform_bus))
>>
>> This is only fixing one specific case, but I think things are broken
>> for any case where the NUMA associativity if not set at the top level
>> bus node. I think this should be something like:
>>
>> if (parent && (dev_to_node(dev) != NO_NUMA_NODE))
>
> It seems a mistake, we should use equal sign.
> if (parent && (dev_to_node(dev) == NUMA_NO_NODE))

Ah, yes.

Rob
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-08-25 16:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-24 12:30 [PATCH 1/1] of: to support binding numa node to root subnode(non-bus) Zhen Lei
2015-08-24 13:25 ` Rob Herring
2015-08-25  2:24   ` Leizhen (ThunderTown)
     [not found]     ` <55DBD1F8.1010206-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2015-08-25 16:05       ` Rob Herring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).