Skip to contentSkip to conversation

clocksource: Avoid creating dead devices

PATCH Applied Saravana Kannan 8 participants 29 messages Jan 11, 2020 – Mar 28, 2020 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clocksource: Avoid creating dead devices

Timer initialization is done during early boot way before the driver core starts processing devices and drivers. Timers initialized during this early boot period don't really need or use a struct device.

However, for timers represented as device tree nodes, the struct devices are still created and sit around unused and wasting memory. This change avoid this by marking the device tree nodes as "populated" if the corresponding timer is successfully initialized.

---
 drivers/clocksource/timer-probe.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/clocksource/timer-probe.c +2 -0
index ee9574da53c0..a10f28d750a9 100644
@@ -27,8 +27,10 @@ void __init timer_probe(void)
 
 		init_func_ret = match->data;
 
+		of_node_set_flag(np, OF_POPULATED);
 		ret = init_func_ret(np);
 		if (ret) {
+			of_node_clear_flag(np, OF_POPULATED);
 			if (ret != -EPROBE_DEFER)
 				pr_err("Failed to initialize '%pOF': %d\n", np,
 				       ret);
Signature · 1 line
2.25.0.rc1.283.g88dfdc4193-goog
#1 lore raw
Quoted 31 lines · Saravana Kannan

Timer initialization is done during early boot way before the driver core starts processing devices and drivers. Timers initialized during this early boot period don't really need or use a struct device.

However, for timers represented as device tree nodes, the struct devices are still created and sit around unused and wasting memory. This change avoid this by marking the device tree nodes as "populated" if the corresponding timer is successfully initialized.

---
 drivers/clocksource/timer-probe.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/clocksource/timer-probe.c +2 -1
index ee9574da53c0..a10f28d750a9 100644
@@ -27,8 +27,10 @@ void __init timer_probe(void)
 
                init_func_ret = match->data;
 
+               of_node_set_flag(np, OF_POPULATED);
                ret = init_func_ret(np);
                if (ret) {
+                       of_node_clear_flag(np, OF_POPULATED);
                        if (ret != -EPROBE_DEFER)
                                pr_err("Failed to initialize '%pOF': %d\n", np,
                                       ret);
--
Quoted 1 line

2.25.0.rc1.283.g88dfdc4193-goog

Gentle reminder.

-Saravana

#2 lore raw
In reply to Saravana Kannan
Quoted 19 lines · Saravana Kannan

Timer initialization is done during early boot way before the driver core starts processing devices and drivers. Timers initialized during this early boot period don't really need or use a struct device.

However, for timers represented as device tree nodes, the struct devices are still created and sit around unused and wasting memory. This change avoid this by marking the device tree nodes as "populated" if the corresponding timer is successfully initialized.

---
 drivers/clocksource/timer-probe.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/clocksource/timer-probe.c +0 -0
index ee9574da53c0..a10f28d750a9 100644

drivers/clocksource/timer-probe.c void __init timer_probe(void) · line 33

Quoted 7 lines
drivers/clocksource/timer-probe.c +2 -0
@@ -27,8 +27,10 @@ void __init timer_probe(void)
 
 		init_func_ret = match->data;
 
+		of_node_set_flag(np, OF_POPULATED);
 		ret = init_func_ret(np);
 		if (ret) {
+			of_node_clear_flag(np, OF_POPULATED);

Isn't it in conflict with:

drivers/clocksource/ingenic-timer.c

?

Quoted 4 lines
drivers/clocksource/timer-probe.c +0 -0
 			if (ret != -EPROBE_DEFER)
 				pr_err("Failed to initialize '%pOF': %d\n", np,
 				       ret);
Signature · 5 lines
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#3 lore raw
Quoted 31 lines · Daniel Lezcano
Quoted 19 lines · Saravana Kannan

Timer initialization is done during early boot way before the driver core starts processing devices and drivers. Timers initialized during this early boot period don't really need or use a struct device.

However, for timers represented as device tree nodes, the struct devices are still created and sit around unused and wasting memory. This change avoid this by marking the device tree nodes as "populated" if the corresponding timer is successfully initialized.

---
 drivers/clocksource/timer-probe.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/clocksource/timer-probe.c +0 -0
index ee9574da53c0..a10f28d750a9 100644

drivers/clocksource/timer-probe.c void __init timer_probe(void) · line 33

Quoted 7 lines
drivers/clocksource/timer-probe.c +2 -0
@@ -27,8 +27,10 @@ void __init timer_probe(void)
 
              init_func_ret = match->data;
 
+             of_node_set_flag(np, OF_POPULATED);
              ret = init_func_ret(np);
              if (ret) {
+                     of_node_clear_flag(np, OF_POPULATED);

Isn't it in conflict with:

Quoted 3 lines

drivers/clocksource/ingenic-timer.c

?

No, it won't interfere with that driver because:
1. This flag is getting set only if the driver already registered a timer init function using TIMER_OF_DECLARE.
2. And if the function fails, we clear the flag.

So in the case of ingenic-timer, the device will still be there and be probed by the driver.

My next step was going to be sending patches that'll actually allow compiling timer drivers as modules.

Thanks,
Saravana

#4 lore raw
Quoted 38 lines · Saravana Kannan
Quoted 31 lines · Daniel Lezcano
Quoted 19 lines · Saravana Kannan

Timer initialization is done during early boot way before the driver core starts processing devices and drivers. Timers initialized during this early boot period don't really need or use a struct device.

However, for timers represented as device tree nodes, the struct devices are still created and sit around unused and wasting memory. This change avoid this by marking the device tree nodes as "populated" if the corresponding timer is successfully initialized.

---
 drivers/clocksource/timer-probe.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/clocksource/timer-probe.c +0 -0
index ee9574da53c0..a10f28d750a9 100644

drivers/clocksource/timer-probe.c void __init timer_probe(void) · line 33

Quoted 7 lines
drivers/clocksource/timer-probe.c +2 -0
@@ -27,8 +27,10 @@ void __init timer_probe(void)
 
              init_func_ret = match->data;
 
+             of_node_set_flag(np, OF_POPULATED);
              ret = init_func_ret(np);
              if (ret) {
+                     of_node_clear_flag(np, OF_POPULATED);

Isn't it in conflict with:

Quoted 3 lines

drivers/clocksource/ingenic-timer.c

?

Quoted 7 lines

No, it won't interfere with that driver because:
1. This flag is getting set only if the driver already registered a timer init function using TIMER_OF_DECLARE.
2. And if the function fails, we clear the flag.

So in the case of ingenic-timer, the device will still be there and be probed by the driver.

Daniel, friendly reminder. Or do you have a patchworks link too that I can keep an eye on?

-Saravana

#5 lore raw
Quoted 6 lines · Saravana Kannan
Quoted 5 lines · Saravana Kannan
Quoted 2 lines · Daniel Lezcano

On 11/01/2020 06:21, Saravana Kannan wrote:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Timer initialization is done during early boot way before the driver core starts processing devices and drivers. Timers initialized during this early boot period don't really need or use a struct device.

However, for timers represented as device tree nodes, the struct devices are still created and sit around unused and wasting memory. This change avoid this by marking the device tree nodes as "populated" if the corresponding timer is successfully initialized.

TBH, I'm missing the rational with the explanation and the code. Can you elaborate or rephrase it?

Quoted 34 lines
Quoted 24 lines
Quoted 20 lines
Quoted 10 lines
---
 drivers/clocksource/timer-probe.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/clocksource/timer-probe.c +0 -0
index ee9574da53c0..a10f28d750a9 100644

drivers/clocksource/timer-probe.c void __init timer_probe(void) · line 33

Quoted 7 lines
drivers/clocksource/timer-probe.c +2 -0
@@ -27,8 +27,10 @@ void __init timer_probe(void)
 
              init_func_ret = match->data;
 
+             of_node_set_flag(np, OF_POPULATED);
              ret = init_func_ret(np);
              if (ret) {
+                     of_node_clear_flag(np, OF_POPULATED);

Isn't it in conflict with:

Quoted 3 lines

drivers/clocksource/ingenic-timer.c

?

Quoted 7 lines

No, it won't interfere with that driver because:
1. This flag is getting set only if the driver already registered a timer init function using TIMER_OF_DECLARE.
2. And if the function fails, we clear the flag.

So in the case of ingenic-timer, the device will still be there and be probed by the driver.

Daniel, friendly reminder. Or do you have a patchworks link too that I can keep an eye on?

Signature · 5 lines
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#6 lore raw
Quoted 12 lines · Daniel Lezcano
Quoted 10 lines · Saravana Kannan
Quoted 9 lines · Saravana Kannan
Quoted 6 lines · Daniel Lezcano
Quoted 4 lines · Saravana Kannan

Timer initialization is done during early boot way before the driver core starts processing devices and drivers. Timers initialized during this early boot period don't really need or use a struct device.

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

However, for timers represented as device tree nodes, the struct devices are still created and sit around unused and wasting memory. This change avoid this by marking the device tree nodes as "populated" if the corresponding timer is successfully initialized.

TBH, I'm missing the rational with the explanation and the code. Can you elaborate or rephrase it?

Ok, let me start from the top.

When the kernel boots, timer_probe() is called (via time_init()) way before any of the initcalls are called in do_initcalls().

In systems with CONFIG_OF, of_platform_default_populate_init() gets called at arch_initcall_sync() level. of_platform_default_populate_init() is what kicks off creating platform devices from device nodes in DT. However, if the struct device_node that corresponds to a device node in DT has OF_POPULATED flag set, a platform device is NOT created for it (because it's considered already "populated"/taken care of).

When a timer driver registers using TIMER_OF_DECLARE(), the driver's init code is called from timer_probe() on the struct device_node that corresponds to the timer device node. At this point the timer is already "probed". If you don't mark this device node with OF_POPULATED, at arch_initcall_sync() it's going to have a pointless struct platform_device created that's just using up memory and pointless.

So my patch sets the OF_POPULATED flag for all timer device_node's that are successfully probed from timer_probe().

If a timer driver doesn't use TIMER_OF_DECLARE() and just registers as a platform device, the driver init function won't be called from timer_probe() and it's corresponding devices won't have OF_POPULATED set in their device_node. So platform_devices will be created for them and they'll probe as normal platform devices. This is why my change doesn't break drivers/clocksource/ingenic-timer.c.

Btw, this is no different from what irqchip does with IRQCHIP_DECLARE.

Hope that clears it up.

Thanks,
Saravana

#7 lore raw
Quoted 53 lines · Saravana Kannan
Quoted 12 lines · Daniel Lezcano
Quoted 10 lines · Saravana Kannan
Quoted 9 lines · Saravana Kannan
Quoted 6 lines · Daniel Lezcano
Quoted 4 lines · Saravana Kannan

Timer initialization is done during early boot way before the driver core starts processing devices and drivers. Timers initialized during this early boot period don't really need or use a struct device.

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

However, for timers represented as device tree nodes, the struct devices are still created and sit around unused and wasting memory. This change avoid this by marking the device tree nodes as "populated" if the corresponding timer is successfully initialized.

TBH, I'm missing the rational with the explanation and the code. Can you elaborate or rephrase it?

Ok, let me start from the top.

When the kernel boots, timer_probe() is called (via time_init()) way before any of the initcalls are called in do_initcalls().

In systems with CONFIG_OF, of_platform_default_populate_init() gets called at arch_initcall_sync() level. of_platform_default_populate_init() is what kicks off creating platform devices from device nodes in DT. However, if the struct device_node that corresponds to a device node in DT has OF_POPULATED flag set, a platform device is NOT created for it (because it's considered already "populated"/taken care of).

When a timer driver registers using TIMER_OF_DECLARE(), the driver's init code is called from timer_probe() on the struct device_node that corresponds to the timer device node. At this point the timer is already "probed". If you don't mark this device node with OF_POPULATED, at arch_initcall_sync() it's going to have a pointless struct platform_device created that's just using up memory and pointless.

So my patch sets the OF_POPULATED flag for all timer device_node's that are successfully probed from timer_probe().

If a timer driver doesn't use TIMER_OF_DECLARE() and just registers as a platform device, the driver init function won't be called from timer_probe() and it's corresponding devices won't have OF_POPULATED set in their device_node. So platform_devices will be created for them and they'll probe as normal platform devices. This is why my change doesn't break drivers/clocksource/ingenic-timer.c.

Quoted 3 lines

Btw, this is no different from what irqchip does with IRQCHIP_DECLARE.

Hope that clears it up.

Yes, thanks for the explanation.

Why not just set the OF_POPULATED if the probe succeeds?

Like:

(quoted diff) +0 -0

b/drivers/clocksource/timer-probe.c
index ee9574da53c0..f290639ff824 100644

drivers/clocksource/timer-probe.c +1 -0
@@ -35,6 +35,7 @@ void __init timer_probe(void)
                        continue;
                }
 
+               of_node_set_flag(np, OF_POPULATED);
                timers++;
        }
 

instead of setting the flag and clearing it in case of failure?

Signature · 5 lines
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#8 lore raw
Quoted 78 lines · Daniel Lezcano
Quoted 53 lines · Saravana Kannan
Quoted 12 lines · Daniel Lezcano
Quoted 10 lines · Saravana Kannan
Quoted 9 lines · Saravana Kannan
Quoted 6 lines · Daniel Lezcano
Quoted 4 lines · Saravana Kannan

Timer initialization is done during early boot way before the driver core starts processing devices and drivers. Timers initialized during this early boot period don't really need or use a struct device.

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

However, for timers represented as device tree nodes, the struct devices are still created and sit around unused and wasting memory. This change avoid this by marking the device tree nodes as "populated" if the corresponding timer is successfully initialized.

TBH, I'm missing the rational with the explanation and the code. Can you elaborate or rephrase it?

Ok, let me start from the top.

When the kernel boots, timer_probe() is called (via time_init()) way before any of the initcalls are called in do_initcalls().

In systems with CONFIG_OF, of_platform_default_populate_init() gets called at arch_initcall_sync() level. of_platform_default_populate_init() is what kicks off creating platform devices from device nodes in DT. However, if the struct device_node that corresponds to a device node in DT has OF_POPULATED flag set, a platform device is NOT created for it (because it's considered already "populated"/taken care of).

When a timer driver registers using TIMER_OF_DECLARE(), the driver's init code is called from timer_probe() on the struct device_node that corresponds to the timer device node. At this point the timer is already "probed". If you don't mark this device node with OF_POPULATED, at arch_initcall_sync() it's going to have a pointless struct platform_device created that's just using up memory and pointless.

So my patch sets the OF_POPULATED flag for all timer device_node's that are successfully probed from timer_probe().

If a timer driver doesn't use TIMER_OF_DECLARE() and just registers as a platform device, the driver init function won't be called from timer_probe() and it's corresponding devices won't have OF_POPULATED set in their device_node. So platform_devices will be created for them and they'll probe as normal platform devices. This is why my change doesn't break drivers/clocksource/ingenic-timer.c.

Quoted 3 lines

Btw, this is no different from what irqchip does with IRQCHIP_DECLARE.

Hope that clears it up.

Yes, thanks for the explanation.

Why not just set the OF_POPULATED if the probe succeeds?

Like:

drivers/clocksource/timer-probe.c +1 -0
index ee9574da53c0..f290639ff824 100644
@@ -35,6 +35,7 @@ void __init timer_probe(void)
                        continue;
                }
 
+               of_node_set_flag(np, OF_POPULATED);
                timers++;
        }
 
Quoted 1 line

instead of setting the flag and clearing it in case of failure?

Looking at IRQ framework which first did it the way you suggested and then changed it to the way I did it, it looks like it allows for drivers that need to split the initialization between early init (not just error out, but init partly) and later driver probe. See [1].

Also, most of the other frameworks that set OF_POPULATED, set it before calling the initialization function for the device. Maybe it's to make sure the device node data "looks the same" whether a device is initialized during early init or during normal device probe (since the OF_POPULATED is set before the probe is called) -- i.e. have OF_POPULATED set before the device initialization code is actually run?

Honestly I don't have a strong opinion either way, but I lean towards following what IRQ does.

Thanks,
Saravana

[1] - https://lore.kernel.org/lkml/[email protected]/#t

#9 lore raw
Quoted 95 lines · Saravana Kannan
Quoted 78 lines · Daniel Lezcano
Quoted 53 lines · Saravana Kannan
Quoted 12 lines · Daniel Lezcano
Quoted 10 lines · Saravana Kannan
Quoted 9 lines · Saravana Kannan
Quoted 6 lines · Daniel Lezcano
Quoted 4 lines · Saravana Kannan

Timer initialization is done during early boot way before the driver core starts processing devices and drivers. Timers initialized during this early boot period don't really need or use a struct device.

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

However, for timers represented as device tree nodes, the struct devices are still created and sit around unused and wasting memory. This change avoid this by marking the device tree nodes as "populated" if the corresponding timer is successfully initialized.

TBH, I'm missing the rational with the explanation and the code. Can you elaborate or rephrase it?

Ok, let me start from the top.

When the kernel boots, timer_probe() is called (via time_init()) way before any of the initcalls are called in do_initcalls().

In systems with CONFIG_OF, of_platform_default_populate_init() gets called at arch_initcall_sync() level. of_platform_default_populate_init() is what kicks off creating platform devices from device nodes in DT. However, if the struct device_node that corresponds to a device node in DT has OF_POPULATED flag set, a platform device is NOT created for it (because it's considered already "populated"/taken care of).

When a timer driver registers using TIMER_OF_DECLARE(), the driver's init code is called from timer_probe() on the struct device_node that corresponds to the timer device node. At this point the timer is already "probed". If you don't mark this device node with OF_POPULATED, at arch_initcall_sync() it's going to have a pointless struct platform_device created that's just using up memory and pointless.

So my patch sets the OF_POPULATED flag for all timer device_node's that are successfully probed from timer_probe().

If a timer driver doesn't use TIMER_OF_DECLARE() and just registers as a platform device, the driver init function won't be called from timer_probe() and it's corresponding devices won't have OF_POPULATED set in their device_node. So platform_devices will be created for them and they'll probe as normal platform devices. This is why my change doesn't break drivers/clocksource/ingenic-timer.c.

Quoted 3 lines

Btw, this is no different from what irqchip does with IRQCHIP_DECLARE.

Hope that clears it up.

Yes, thanks for the explanation.

Why not just set the OF_POPULATED if the probe succeeds?

Like:

drivers/clocksource/timer-probe.c +1 -0
index ee9574da53c0..f290639ff824 100644
@@ -35,6 +35,7 @@ void __init timer_probe(void)
                        continue;
                }
 
+               of_node_set_flag(np, OF_POPULATED);
                timers++;
        }
 
Quoted 1 line

instead of setting the flag and clearing it in case of failure?

Looking at IRQ framework which first did it the way you suggested and then changed it to the way I did it, it looks like it allows for drivers that need to split the initialization between early init (not just error out, but init partly) and later driver probe. See [1].

Also, most of the other frameworks that set OF_POPULATED, set it before calling the initialization function for the device. Maybe it's to make sure the device node data "looks the same" whether a device is initialized during early init or during normal device probe (since the OF_POPULATED is set before the probe is called) -- i.e. have OF_POPULATED set before the device initialization code is actually run?

Quoted 2 lines

Honestly I don't have a strong opinion either way, but I lean towards following what IRQ does.

Thanks for the pointer. Indeed it is to catch situation where the driver is clearing the flag like:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/clocksource/ingenic-timer.c#n245

But I'm not able to figure out why it is cleared here :/

Paul?

Signature · 5 lines
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#10 lore raw
Quoted 100 lines · Daniel Lezcano
Quoted 95 lines · Saravana Kannan
Quoted 78 lines · Daniel Lezcano
Quoted 53 lines · Saravana Kannan
Quoted 12 lines · Daniel Lezcano
Quoted 10 lines · Saravana Kannan
Quoted 9 lines · Saravana Kannan
Quoted 6 lines · Daniel Lezcano
Quoted 4 lines · Saravana Kannan

Timer initialization is done during early boot way before the driver core starts processing devices and drivers. Timers initialized during this early boot period don't really need or use a struct device.

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

However, for timers represented as device tree nodes, the struct devices are still created and sit around unused and wasting memory. This change avoid this by marking the device tree nodes as "populated" if the corresponding timer is successfully initialized.

TBH, I'm missing the rational with the explanation and the code. Can you elaborate or rephrase it?

Ok, let me start from the top.

When the kernel boots, timer_probe() is called (via time_init()) way before any of the initcalls are called in do_initcalls().

In systems with CONFIG_OF, of_platform_default_populate_init() gets called at arch_initcall_sync() level. of_platform_default_populate_init() is what kicks off creating platform devices from device nodes in DT. However, if the struct device_node that corresponds to a device node in DT has OF_POPULATED flag set, a platform device is NOT created for it (because it's considered already "populated"/taken care of).

When a timer driver registers using TIMER_OF_DECLARE(), the driver's init code is called from timer_probe() on the struct device_node that corresponds to the timer device node. At this point the timer is already "probed". If you don't mark this device node with OF_POPULATED, at arch_initcall_sync() it's going to have a pointless struct platform_device created that's just using up memory and pointless.

So my patch sets the OF_POPULATED flag for all timer device_node's that are successfully probed from timer_probe().

If a timer driver doesn't use TIMER_OF_DECLARE() and just registers as a platform device, the driver init function won't be called from timer_probe() and it's corresponding devices won't have OF_POPULATED set in their device_node. So platform_devices will be created for them and they'll probe as normal platform devices. This is why my change doesn't break drivers/clocksource/ingenic-timer.c.

Quoted 3 lines

Btw, this is no different from what irqchip does with IRQCHIP_DECLARE.

Hope that clears it up.

Yes, thanks for the explanation.

Why not just set the OF_POPULATED if the probe succeeds?

Like:

drivers/clocksource/timer-probe.c +1 -0
index ee9574da53c0..f290639ff824 100644
@@ -35,6 +35,7 @@ void __init timer_probe(void)
                        continue;
                }
 
+               of_node_set_flag(np, OF_POPULATED);
                timers++;
        }
 
Quoted 1 line

instead of setting the flag and clearing it in case of failure?

Looking at IRQ framework which first did it the way you suggested and then changed it to the way I did it, it looks like it allows for drivers that need to split the initialization between early init (not just error out, but init partly) and later driver probe. See [1].

Also, most of the other frameworks that set OF_POPULATED, set it before calling the initialization function for the device. Maybe it's to make sure the device node data "looks the same" whether a device is initialized during early init or during normal device probe (since the OF_POPULATED is set before the probe is called) -- i.e. have OF_POPULATED set before the device initialization code is actually run?

Quoted 2 lines

Honestly I don't have a strong opinion either way, but I lean towards following what IRQ does.

Quoted 6 lines

Thanks for the pointer. Indeed it is to catch situation where the driver is clearing the flag like:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/clocksource/ingenic-timer.c#n245

But I'm not able to figure out why it is cleared here :/

I think I know what's going on. He wants to implement PM support for this timer. But PM support is tied to devices. So, clearing out the flag allows creating the device which then hooks into PM ops.

Although, it looks like the driver assumes the timer framework was setting the OF_POPULATED flag.

-Saravana

Quoted 11 lines

Paul?

--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog

A message that is not in the archive (sent off-list or not yet received): [email protected]

#12 lore raw
Quoted 144 lines · Paul Cercueil

Hi Saravana, Daniel,

Le lun. 16 mars 2020 à 11:15, Saravana Kannan <[email protected]> a écrit :

Quoted 138 lines
Quoted 135 lines · Daniel Lezcano
Quoted 9 lines · Saravana Kannan
Quoted 7 lines · Daniel Lezcano
Quoted 5 lines · Saravana Kannan
Quoted 3 lines · Daniel Lezcano
Quoted 1 line · Saravana Kannan

On Thu, Feb 27, 2020 at 1:22 PM Saravana Kannan

Quoted 6 lines · <[email protected]> wrote:
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines · Daniel Lezcano
Quoted 1 line · Saravana Kannan

Timer initialization is done during early boot way before

the driver

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

core starts processing devices and drivers. Timers

initialized during

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

this early boot period don't really need or use a struct

device.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

However, for timers represented as device tree nodes, the

struct devices

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

are still created and sit around unused and wasting

memory. This change

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

avoid this by marking the device tree nodes as "populated"

if the

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

corresponding timer is successfully initialized.

TBH, I'm missing the rational with the explanation and the

code. Can you

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line

elaborate or rephrase it?

Ok, let me start from the top.

When the kernel boots, timer_probe() is called (via

time_init()) way

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

before any of the initcalls are called in do_initcalls().

In systems with CONFIG_OF, of_platform_default_populate_init()

gets

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

called at arch_initcall_sync() level. of_platform_default_populate_init() is what kicks off creating platform devices from device nodes in DT. However, if the struct device_node that corresponds to a device node in DT has

OF_POPULATED

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

flag set, a platform device is NOT created for it (because it's considered already "populated"/taken care of).

When a timer driver registers using TIMER_OF_DECLARE(), the

driver's

Quoted 1 line
Quoted 1 line
Quoted 1 line

init code is called from timer_probe() on the struct

device_node that

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

corresponds to the timer device node. At this point the timer is already "probed". If you don't mark this device node with OF_POPULATED, at arch_initcall_sync() it's going to have a

pointless

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

struct platform_device created that's just using up memory and pointless.

So my patch sets the OF_POPULATED flag for all timer

device_node's

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

that are successfully probed from timer_probe().

If a timer driver doesn't use TIMER_OF_DECLARE() and just

registers as

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

a platform device, the driver init function won't be called from timer_probe() and it's corresponding devices won't have

OF_POPULATED

Quoted 1 line
Quoted 1 line
Quoted 1 line

set in their device_node. So platform_devices will be created

for them

Quoted 1 line
Quoted 1 line
Quoted 1 line

and they'll probe as normal platform devices. This is why my

change

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

doesn't break drivers/clocksource/ingenic-timer.c.

Btw, this is no different from what irqchip does with

IRQCHIP_DECLARE.

Quoted 18 lines
Quoted 18 lines
Quoted 2 lines

Hope that clears it up.

Yes, thanks for the explanation.

Why not just set the OF_POPULATED if the probe succeeds?

Like:

drivers/clocksource/timer-probe.c +0 -0
index ee9574da53c0..f290639ff824 100644
@@ -35,6 +35,7 @@ void __init timer_probe(void)
                        continue;
                }
 
Quoted 7 lines
Quoted 5 lines
drivers/clocksource/timer-probe.c +1 -0
+               of_node_set_flag(np, OF_POPULATED);
                timers++;
        }
 

instead of setting the flag and clearing it in case of failure?

Looking at IRQ framework which first did it the way you suggested

and

Quoted 2 lines

then changed it to the way I did it, it looks like it allows for drivers that need to split the initialization between early init

(not

Quoted 4 lines

just error out, but init partly) and later driver probe. See [1].

Also, most of the other frameworks that set OF_POPULATED, set it before calling the initialization function for the device. Maybe

it's

Quoted 1 line

to make sure the device node data "looks the same" whether a

device is

Quoted 1 line

initialized during early init or during normal device probe

(since the

Quoted 2 lines

OF_POPULATED is set before the probe is called) -- i.e. have OF_POPULATED set before the device initialization code is

actually

Quoted 3 lines

run?

Honestly I don't have a strong opinion either way, but I lean

towards

Quoted 1 line

following what IRQ does.

Thanks for the pointer. Indeed it is to catch situation where the
driver
is clearing the flag like:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/clocksource/ingenic-timer.c#n245

But I'm not able to figure out why it is cleared here :/

Quoted 7 lines
Quoted 3 lines

I think I know what's going on. He wants to implement PM support for this timer. But PM support is tied to devices. So, clearing out the flag allows creating the device which then hooks into PM ops.

That's correct - the OF_POPULATED flag is cleared so that the driver will probe as a platform_device. When I did write the driver this was required or the platform_device would not probe.

Interesting. I went and looked at the kernel when your patch merged. As far as I can tell, you shouldn't have needed to clear OF_POPULATED because the timer framework never set OF_POPULATED even back then.

If this driver was based in drivers/irqchip/irq-ingenic-tcu.c and you were initially just trying to get it to create a device, then you'd have needed to clear OF_POPULATED because IRQ chip framework does set the flag.

In any case, it's good that you cleared it -- it'll continue to work with my patch.

Daniel,

Looks like this answers all the concerns you had. I also checked every driver in drivers/clocksource that had the word "probe" in it to make sure it won't need any updates to ingenic-timer.c. Can we merge this?

Thanks,
Saravana

Quoted 22 lines

-Paul

Quoted 17 lines

Although, it looks like the driver assumes the timer framework was setting the OF_POPULATED flag.

-Saravana

Quoted 12 lines

Paul?

--
<http://www.linaro.org/> Linaro.org │ Open source software for
ARM SoCs

Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog

#13 lore raw
Quoted 1 line · Saravana Kannan

On Tue, Mar 17, 2020 at 4:36 AM Paul Cercueil <[email protected]> wrote:

[ ... ]

Quoted 68 lines
Quoted 51 lines
Quoted 51 lines
Quoted 50 lines
Quoted 13 lines
Quoted 13 lines

Why not just set the OF_POPULATED if the probe succeeds?

Like:

drivers/clocksource/timer-probe.c +0 -0
index ee9574da53c0..f290639ff824 100644
@@ -35,6 +35,7 @@ void __init timer_probe(void)
                        continue;
                }
 
Quoted 7 lines
Quoted 5 lines
drivers/clocksource/timer-probe.c +1 -0
+               of_node_set_flag(np, OF_POPULATED);
                timers++;
        }
 

instead of setting the flag and clearing it in case of failure?

Looking at IRQ framework which first did it the way you suggested

and

Quoted 2 lines

then changed it to the way I did it, it looks like it allows for drivers that need to split the initialization between early init

(not

Quoted 4 lines

just error out, but init partly) and later driver probe. See [1].

Also, most of the other frameworks that set OF_POPULATED, set it before calling the initialization function for the device. Maybe

it's

Quoted 1 line

to make sure the device node data "looks the same" whether a

device is

Quoted 1 line

initialized during early init or during normal device probe

(since the

Quoted 2 lines

OF_POPULATED is set before the probe is called) -- i.e. have OF_POPULATED set before the device initialization code is

actually

Quoted 3 lines

run?

Honestly I don't have a strong opinion either way, but I lean

towards

Quoted 1 line

following what IRQ does.

Thanks for the pointer. Indeed it is to catch situation where the
driver
is clearing the flag like:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/clocksource/ingenic-timer.c#n245

But I'm not able to figure out why it is cleared here :/

Quoted 7 lines
Quoted 3 lines

I think I know what's going on. He wants to implement PM support for this timer. But PM support is tied to devices. So, clearing out the flag allows creating the device which then hooks into PM ops.

That's correct - the OF_POPULATED flag is cleared so that the driver will probe as a platform_device. When I did write the driver this was required or the platform_device would not probe.

Interesting. I went and looked at the kernel when your patch merged. As far as I can tell, you shouldn't have needed to clear OF_POPULATED because the timer framework never set OF_POPULATED even back then.

If this driver was based in drivers/irqchip/irq-ingenic-tcu.c and you were initially just trying to get it to create a device, then you'd have needed to clear OF_POPULATED because IRQ chip framework does set the flag.

Quoted 8 lines

In any case, it's good that you cleared it -- it'll continue to work with my patch.

Daniel,

Looks like this answers all the concerns you had. I also checked every driver in drivers/clocksource that had the word "probe" in it to make sure it won't need any updates to ingenic-timer.c. Can we merge this?

Applied [1], thanks

-- Daniel

[1]
https://git.linaro.org/people/daniel.lezcano/linux.git/commit/?h=timers/drivers/next&id=4f41fe386a94639cd9a1831298d4f85db5662f1e

Signature · 5 lines
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#14 lore raw

[tip: timers/core] clocksource/drivers/timer-probe: Avoid creating dead devices

In reply to Saravana Kannan
The following commit has been merged into the timers/core branch of tip:

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     4f41fe386a94639cd9a1831298d4f85db5662f1e
Gitweb:        https://git.kernel.org/tip/4f41fe386a94639cd9a1831298d4f85db5662f1e
Author:        Saravana Kannan <[email protected]>
AuthorDate:    Fri, 10 Jan 2020 21:21:25 -08:00
Committer:     Daniel Lezcano <[email protected]>
CommitterDate: Tue, 17 Mar 2020 13:10:07 +01:00

clocksource/drivers/timer-probe: Avoid creating dead devices

Timer initialization is done during early boot way before the driver core starts processing devices and drivers. Timers initialized during this early boot period don't really need or use a struct device.

However, for timers represented as device tree nodes, the struct devices are still created and sit around unused and wasting memory. This change avoid this by marking the device tree nodes as "populated" if the corresponding timer is successfully initialized.

---
 drivers/clocksource/timer-probe.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/clocksource/timer-probe.c +2 -0
index ee9574d..a10f28d 100644
@@ -27,8 +27,10 @@ void __init timer_probe(void)
 
 		init_func_ret = match->data;
 
+		of_node_set_flag(np, OF_POPULATED);
 		ret = init_func_ret(np);
 		if (ret) {
+			of_node_clear_flag(np, OF_POPULATED);
 			if (ret != -EPROBE_DEFER)
 				pr_err("Failed to initialize '%pOF': %d\n", np,
 				       ret);
#15 lore raw

Re: [tip: timers/core] clocksource/drivers/timer-probe: Avoid creating dead devices

Hi guys,

Quoted 33 lines · On Thursday 19 Mar 2020 at 08:47:46 (-0000), tip-bot2 for Saravana Kannan wrote:

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     4f41fe386a94639cd9a1831298d4f85db5662f1e
Gitweb:        https://git.kernel.org/tip/4f41fe386a94639cd9a1831298d4f85db5662f1e
Author:        Saravana Kannan <[email protected]>
AuthorDate:    Fri, 10 Jan 2020 21:21:25 -08:00
Committer:     Daniel Lezcano <[email protected]>
CommitterDate: Tue, 17 Mar 2020 13:10:07 +01:00

clocksource/drivers/timer-probe: Avoid creating dead devices

Timer initialization is done during early boot way before the driver core starts processing devices and drivers. Timers initialized during this early boot period don't really need or use a struct device.

However, for timers represented as device tree nodes, the struct devices are still created and sit around unused and wasting memory. This change avoid this by marking the device tree nodes as "populated" if the corresponding timer is successfully initialized.

---
 drivers/clocksource/timer-probe.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/clocksource/timer-probe.c +0 -0
index ee9574d..a10f28d 100644

drivers/clocksource/timer-probe.c void __init timer_probe(void) · line 36

Quoted 10 lines
drivers/clocksource/timer-probe.c +2 -0
@@ -27,8 +27,10 @@ void __init timer_probe(void)
 
 		init_func_ret = match->data;
 
+		of_node_set_flag(np, OF_POPULATED);
 		ret = init_func_ret(np);
 		if (ret) {
+			of_node_clear_flag(np, OF_POPULATED);
 			if (ret != -EPROBE_DEFER)
 				pr_err("Failed to initialize '%pOF': %d\n", np,
 				       ret);

This patch is creating problems on some vexpress platforms - ones that are using CLKSRC_VERSATILE (drivers/clocksource/timer-versatile.c). I noticed issues on TC2 and FVPs (fixed virtual platforms) starting with next-20200318 and still reproducible with next-20200323.

It seems the issue this patch causes on TC2 and FVP is related to the vexpress-sysreg node being used early for sched_clock_init (timer_versatile.c: versatile_sched_clock_init). At this point (at time_init) the node will be marked as OF_POPULATED, which flags that a device is already created for it, but it is not, in this case.

Later at sysreg_init (vexpress-sysreg.c) a device will fail to be created for it, as one already exists. This will result in a failure to create a bridge and a system controller for a bunch of devices (mostly clocks and regulators).

I think on the FVP it does not cause many issues as clocks are fixed and regulator settings are probably nops so it boots fine and throws only some warnings. On TC2 on the other hand it fails to boot and it hangs at starting the kernel.

In my opinion the idea of the patch is not bad, but I'm not an expert on this so the most I can offer for now is the basic understanding of the issue. I've Cc-ed a few folks to potentially suggest alternatives/fixes.

For now, reverting this patch solves the problems on both platforms. I tested this on next-20200318 which introduced the problem.

Hope it helps,
Ionela.

#16 lore raw

Re: [tip: timers/core] clocksource/drivers/timer-probe: Avoid creating dead devices

Quoted 69 lines · Ionela Voinescu

Hi guys,

Quoted 33 lines · On Thursday 19 Mar 2020 at 08:47:46 (-0000), tip-bot2 for Saravana Kannan wrote:

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     4f41fe386a94639cd9a1831298d4f85db5662f1e
Gitweb:        https://git.kernel.org/tip/4f41fe386a94639cd9a1831298d4f85db5662f1e
Author:        Saravana Kannan <[email protected]>
AuthorDate:    Fri, 10 Jan 2020 21:21:25 -08:00
Committer:     Daniel Lezcano <[email protected]>
CommitterDate: Tue, 17 Mar 2020 13:10:07 +01:00

clocksource/drivers/timer-probe: Avoid creating dead devices

Timer initialization is done during early boot way before the driver core starts processing devices and drivers. Timers initialized during this early boot period don't really need or use a struct device.

However, for timers represented as device tree nodes, the struct devices are still created and sit around unused and wasting memory. This change avoid this by marking the device tree nodes as "populated" if the corresponding timer is successfully initialized.

---
 drivers/clocksource/timer-probe.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/clocksource/timer-probe.c +0 -0
index ee9574d..a10f28d 100644

drivers/clocksource/timer-probe.c void __init timer_probe(void) · line 36

Quoted 10 lines
drivers/clocksource/timer-probe.c +2 -0
@@ -27,8 +27,10 @@ void __init timer_probe(void)
 
              init_func_ret = match->data;
 
+             of_node_set_flag(np, OF_POPULATED);
              ret = init_func_ret(np);
              if (ret) {
+                     of_node_clear_flag(np, OF_POPULATED);
                      if (ret != -EPROBE_DEFER)
                              pr_err("Failed to initialize '%pOF': %d\n", np,
                                     ret);

This patch is creating problems on some vexpress platforms - ones that are using CLKSRC_VERSATILE (drivers/clocksource/timer-versatile.c). I noticed issues on TC2 and FVPs (fixed virtual platforms) starting with next-20200318 and still reproducible with next-20200323.

It seems the issue this patch causes on TC2 and FVP is related to the vexpress-sysreg node being used early for sched_clock_init (timer_versatile.c: versatile_sched_clock_init). At this point (at time_init) the node will be marked as OF_POPULATED, which flags that a device is already created for it, but it is not, in this case.

Later at sysreg_init (vexpress-sysreg.c) a device will fail to be created for it, as one already exists. This will result in a failure to create a bridge and a system controller for a bunch of devices (mostly clocks and regulators).

I think on the FVP it does not cause many issues as clocks are fixed and regulator settings are probably nops so it boots fine and throws only some warnings. On TC2 on the other hand it fails to boot and it hangs at starting the kernel.

Quoted 6 lines

In my opinion the idea of the patch is not bad, but I'm not an expert on this so the most I can offer for now is the basic understanding of the issue. I've Cc-ed a few folks to potentially suggest alternatives/fixes.

For now, reverting this patch solves the problems on both platforms. I tested this on next-20200318 which introduced the problem.

I'll reply later today after I take a closer look. But will something like what timer-ingenic.c did work for you? You can clear the flag inside your early init.

-Saravana

Quoted 3 lines

Hope it helps,
Ionela.

#17 lore raw

Re: [tip: timers/core] clocksource/drivers/timer-probe: Avoid creating dead devices

Quoted 76 lines · Saravana Kannan
Quoted 73 lines · Ionela Voinescu

Hi guys,

Quoted 33 lines · On Thursday 19 Mar 2020 at 08:47:46 (-0000), tip-bot2 for Saravana Kannan wrote:

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     4f41fe386a94639cd9a1831298d4f85db5662f1e
Gitweb:        https://git.kernel.org/tip/4f41fe386a94639cd9a1831298d4f85db5662f1e
Author:        Saravana Kannan <[email protected]>
AuthorDate:    Fri, 10 Jan 2020 21:21:25 -08:00
Committer:     Daniel Lezcano <[email protected]>
CommitterDate: Tue, 17 Mar 2020 13:10:07 +01:00

clocksource/drivers/timer-probe: Avoid creating dead devices

Timer initialization is done during early boot way before the driver core starts processing devices and drivers. Timers initialized during this early boot period don't really need or use a struct device.

However, for timers represented as device tree nodes, the struct devices are still created and sit around unused and wasting memory. This change avoid this by marking the device tree nodes as "populated" if the corresponding timer is successfully initialized.

---
 drivers/clocksource/timer-probe.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/clocksource/timer-probe.c +0 -0
index ee9574d..a10f28d 100644

drivers/clocksource/timer-probe.c void __init timer_probe(void) · line 36

Quoted 10 lines
drivers/clocksource/timer-probe.c +2 -0
@@ -27,8 +27,10 @@ void __init timer_probe(void)
 
              init_func_ret = match->data;
 
+             of_node_set_flag(np, OF_POPULATED);
              ret = init_func_ret(np);
              if (ret) {
+                     of_node_clear_flag(np, OF_POPULATED);
                      if (ret != -EPROBE_DEFER)
                              pr_err("Failed to initialize '%pOF': %d\n", np,
                                     ret);

This patch is creating problems on some vexpress platforms - ones that are using CLKSRC_VERSATILE (drivers/clocksource/timer-versatile.c). I noticed issues on TC2 and FVPs (fixed virtual platforms) starting with next-20200318 and still reproducible with next-20200323.

It seems the issue this patch causes on TC2 and FVP is related to the vexpress-sysreg node being used early for sched_clock_init (timer_versatile.c: versatile_sched_clock_init). At this point (at time_init) the node will be marked as OF_POPULATED, which flags that a device is already created for it, but it is not, in this case.

Later at sysreg_init (vexpress-sysreg.c) a device will fail to be created for it, as one already exists. This will result in a failure to create a bridge and a system controller for a bunch of devices (mostly clocks and regulators).

I think on the FVP it does not cause many issues as clocks are fixed and regulator settings are probably nops so it boots fine and throws only some warnings. On TC2 on the other hand it fails to boot and it hangs at starting the kernel.

In my opinion the idea of the patch is not bad, but I'm not an expert on this so the most I can offer for now is the basic understanding of the issue. I've Cc-ed a few folks to potentially suggest alternatives/fixes.

Quoted 6 lines
Quoted 2 lines

For now, reverting this patch solves the problems on both platforms. I tested this on next-20200318 which introduced the problem.

I'll reply later today after I take a closer look. But will something like what timer-ingenic.c did work for you? You can clear the flag inside your early init.

Firstly, sorry my patch broke your platform.

I took a closer look. So two different drivers [1] [2] are saying they know how to handle "arm,vexpress-sysreg" and are expecting to run at the same time. That seems a bit unusual to me. I wonder if this is a violation of the device-driver model because this expectation would never be allowed if these device drivers were actual drivers registered with driver-core. But that's a discussion for another time.

To fix this issue you are facing, this patch should work:
https://lore.kernel.org/lkml/[email protected]/T/#u

Can you please test it and give a Tested-by?

Thanks,
Saravana

[1] drivers/mfd/vexpress-sysreg.c: { .compatible = "arm,vexpress-sysreg", },
[2] drivers/clocksource/timer-versatile.c:TIMER_OF_DECLARE(vexpress, "arm,vexpress-sysreg"

#18 lore raw

Re: [tip: timers/core] clocksource/drivers/timer-probe: Avoid creating dead devices

Quoted 10 lines · Saravana Kannan

On Tue, Mar 24, 2020 at 11:34 AM Saravana Kannan <[email protected]> wrote:
I took a closer look. So two different drivers [1] [2] are saying they know how to handle "arm,vexpress-sysreg" and are expecting to run at the same time. That seems a bit unusual to me. I wonder if this is a violation of the device-driver model because this expectation would never be allowed if these device drivers were actual drivers registered with driver-core. But that's a discussion for another time.

To fix this issue you are facing, this patch should work:
https://lore.kernel.org/lkml/[email protected]/T/#u

Sorry, that's not a fix. That's a crude hack.

As this is also causing trouble on tegra30-cardhu-a04 the only sane solution is to revert it and start over with a proper solution for the vexpress problem and a root cause analysis for the tegra.

Thanks,

tglx

#19 lore raw

Re: [tip: timers/core] clocksource/drivers/timer-probe: Avoid creating dead devices

Quoted 10 lines · Thomas Gleixner
Quoted 8 lines · Saravana Kannan

On Tue, Mar 24, 2020 at 11:34 AM Saravana Kannan <[email protected]> wrote:
I took a closer look. So two different drivers [1] [2] are saying they know how to handle "arm,vexpress-sysreg" and are expecting to run at the same time. That seems a bit unusual to me. I wonder if this is a violation of the device-driver model because this expectation would never be allowed if these device drivers were actual drivers registered with driver-core. But that's a discussion for another time.

Quoted 4 lines
Quoted 2 lines

To fix this issue you are facing, this patch should work:
https://lore.kernel.org/lkml/[email protected]/T/#u

Sorry, that's not a fix. That's a crude hack.

If device nodes are being handled by drivers without binding a driver to struct devices, then not setting OF_POPULATED is wrong. So the original patch sets it. There are also very valid reasons for allowing OF_POPULATED to be cleared by a driver as discussed here [1].

The approach of the original patch (setting the flag and letting the driver sometimes clear it) is also followed by many other frameworks like irq, clk, i2c, etc. Even ingenic-timer.c already does it for the exact same reason.

So, why is the vexpress fix a crude hack?

Quoted 3 lines

As this is also causing trouble on tegra30-cardhu-a04 the only sane solution is to revert it and start over with a proper solution for the vexpress problem and a root cause analysis for the tegra.

If someone can tell me which of the timer drivers are relevant for tegra30-cardhu-a04, I can help fix it.
If you want to revert the original patch first before waiting for a tegra fix, that's okay by me.

However, for vexpress, what do you propose I do? The driver itself is doing weird stuff with two drivers handling the exact same device. I can't just go edit the DT files because technically I don't know their hardware. Looks to me like they should have a separate and proper device for the timer and not have two drivers handle the same device. If you don't like my vexpress fix, then don't take it but ask the vexpress maintainer to fix their DT and driver maybe? But that might break the kernel compatibility with existing DT binaries on devices (yes, vexpress seems like a virtual platform, so updating DT blobs might not be hard). My vexpress fix doesn't break backwards compatibility.

So, can you please accept my vexpress fix or tell us what you think is a "proper solution"?

-Saravana

#20 lore raw

Re: [tip: timers/core] clocksource/drivers/timer-probe: Avoid creating dead devices

Quoted 15 lines · Saravana Kannan
Quoted 13 lines · Thomas Gleixner
Quoted 10 lines · Saravana Kannan

On Tue, Mar 24, 2020 at 11:34 AM Saravana Kannan <[email protected]> wrote:
I took a closer look. So two different drivers [1] [2] are saying they know how to handle "arm,vexpress-sysreg" and are expecting to run at the same time. That seems a bit unusual to me. I wonder if this is a violation of the device-driver model because this expectation would never be allowed if these device drivers were actual drivers registered with driver-core. But that's a discussion for another time.

To fix this issue you are facing, this patch should work:
https://lore.kernel.org/lkml/[email protected]/T/#u

Quoted 6 lines
Quoted 1 line

Sorry, that's not a fix. That's a crude hack.

If device nodes are being handled by drivers without binding a driver to struct devices, then not setting OF_POPULATED is wrong. So the original patch sets it. There are also very valid reasons for allowing OF_POPULATED to be cleared by a driver as discussed here [1].

Forgot to include [1]
[1] - https://lore.kernel.org/lkml/[email protected]/T/#m7b043de4c75e6c1de309d3ca5146bb0c7b3dfc80
For some reason Paul's email is missing from lore.kernel.org.

-Saravana

#21 lore raw

Re: [tip: timers/core] clocksource/drivers/timer-probe: Avoid creating dead devices

In reply to Saravana Kannan

Hi Saravana,

Quoted 41 lines · Saravana Kannan
Quoted 12 lines · Thomas Gleixner
Quoted 10 lines · Saravana Kannan

On Tue, Mar 24, 2020 at 11:34 AM Saravana Kannan <[email protected]> wrote: I took a closer look. So two different drivers [1] [2] are saying they know how to handle "arm,vexpress-sysreg" and are expecting to run at the same time. That seems a bit unusual to me. I wonder if this is a violation of the device-driver model because this expectation would never be allowed if these device drivers were actual drivers registered with driver-core. But that's a discussion for another time.

Quoted 7 lines
Quoted 7 lines

To fix this issue you are facing, this patch should work:
https://lore.kernel.org/lkml/[email protected]/T/#u

Sorry, that's not a fix. That's a crude hack.

If device nodes are being handled by drivers without binding a driver to struct devices, then not setting OF_POPULATED is wrong. So the original patch sets it. There are also very valid reasons for allowing OF_POPULATED to be cleared by a driver as discussed here [1].

The approach of the original patch (setting the flag and letting the driver sometimes clear it) is also followed by many other frameworks like irq, clk, i2c, etc. Even ingenic-timer.c already does it for the exact same reason.

So, why is the vexpress fix a crude hack?

Quoted 4 lines

As this is also causing trouble on tegra30-cardhu-a04 the only sane solution is to revert it and start over with a proper solution for the vexpress problem and a root cause analysis for the tegra.

Quoted 4 lines

If someone can tell me which of the timer drivers are relevant for tegra30-cardhu-a04, I can help fix it. If you want to revert the original patch first before waiting for a tegra fix, that's okay by me.

It seems the OF_POPULATED flag change spotted something wrong in different drivers and that is a good thing. Thanks for your patch for that.

Without putting in question your analysis, we need to stabilize the release, can you send a revert of your patch?

Let's try to figure out what is happening and fix the issues in the other drivers for the next cycle.

Thanks

-- Daniel

Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#22 lore raw

Re: [tip: timers/core] clocksource/drivers/timer-probe: Avoid creating dead devices

Quoted 56 lines · Daniel Lezcano

Hi Saravana,

Quoted 41 lines · Saravana Kannan
Quoted 12 lines · Thomas Gleixner
Quoted 10 lines · Saravana Kannan

On Tue, Mar 24, 2020 at 11:34 AM Saravana Kannan <[email protected]> wrote: I took a closer look. So two different drivers [1] [2] are saying they know how to handle "arm,vexpress-sysreg" and are expecting to run at the same time. That seems a bit unusual to me. I wonder if this is a violation of the device-driver model because this expectation would never be allowed if these device drivers were actual drivers registered with driver-core. But that's a discussion for another time.

Quoted 7 lines
Quoted 7 lines

To fix this issue you are facing, this patch should work:
https://lore.kernel.org/lkml/[email protected]/T/#u

Sorry, that's not a fix. That's a crude hack.

If device nodes are being handled by drivers without binding a driver to struct devices, then not setting OF_POPULATED is wrong. So the original patch sets it. There are also very valid reasons for allowing OF_POPULATED to be cleared by a driver as discussed here [1].

The approach of the original patch (setting the flag and letting the driver sometimes clear it) is also followed by many other frameworks like irq, clk, i2c, etc. Even ingenic-timer.c already does it for the exact same reason.

So, why is the vexpress fix a crude hack?

Quoted 4 lines

As this is also causing trouble on tegra30-cardhu-a04 the only sane solution is to revert it and start over with a proper solution for the vexpress problem and a root cause analysis for the tegra.

Quoted 4 lines

If someone can tell me which of the timer drivers are relevant for tegra30-cardhu-a04, I can help fix it. If you want to revert the original patch first before waiting for a tegra fix, that's okay by me.

It seems the OF_POPULATED flag change spotted something wrong in different drivers and that is a good thing. Thanks for your patch for that.

Quoted 5 lines

Without putting in question your analysis, we need to stabilize the release, can you send a revert of your patch?

Let's try to figure out what is happening and fix the issues in the other drivers for the next cycle.

Make sense. Will do soon.

-Saravana

Quoted 13 lines

Thanks

-- Daniel

--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog

#23 lore raw

Re: [tip: timers/core] clocksource/drivers/timer-probe: Avoid creating dead devices

In reply to Saravana Kannan
Quoted 21 lines · Saravana Kannan
Quoted 9 lines · Thomas Gleixner
Quoted 8 lines · Saravana Kannan

On Tue, Mar 24, 2020 at 11:34 AM Saravana Kannan <[email protected]> wrote:
I took a closer look. So two different drivers [1] [2] are saying they know how to handle "arm,vexpress-sysreg" and are expecting to run at the same time. That seems a bit unusual to me. I wonder if this is a violation of the device-driver model because this expectation would never be allowed if these device drivers were actual drivers registered with driver-core. But that's a discussion for another time.

Quoted 4 lines
Quoted 2 lines

To fix this issue you are facing, this patch should work:
https://lore.kernel.org/lkml/[email protected]/T/#u

Sorry, that's not a fix. That's a crude hack.

If device nodes are being handled by drivers without binding a driver to struct devices, then not setting OF_POPULATED is wrong. So the original patch sets it. There are also very valid reasons for allowing OF_POPULATED to be cleared by a driver as discussed here [1].

Quoted 6 lines

The approach of the original patch (setting the flag and letting the driver sometimes clear it) is also followed by many other frameworks like irq, clk, i2c, etc. Even ingenic-timer.c already does it for the exact same reason.

So, why is the vexpress fix a crude hack?

If it's the right thing to do and accepted by the DT folks, then the changelog should provide a proper explanation for it. The one you provided just baffles me. Plus the clearing of the flag really needs a big fat comment.

It still does not make any sense to me.

arm,vexpress-sysreg is a MFD device, so can the ARM people please explain, why the sched clock part is not just another MFD sub-device or simply has it's own DT match?

Quoted 6 lines
Quoted 3 lines

As this is also causing trouble on tegra30-cardhu-a04 the only sane solution is to revert it and start over with a proper solution for the vexpress problem and a root cause analysis for the tegra.

If someone can tell me which of the timer drivers are relevant for tegra30-cardhu-a04, I can help fix it.

git grep perhaps? And that's pretty much the same problem:

drivers/clocksource/timer-tegra.c:TIMER_OF_DECLARE(tegra20_rtc, "nvidia,tegra20-rtc", tegra20_init_rtc);
drivers/rtc/rtc-tegra.c: { .compatible = "nvidia,tegra20-rtc", },

Without looking deeper I suspect that these two are not the only ones.

Can the DT folks pretty please comment on this and provide some guidance how to fix that w/o sprinkling

    of_node_clear_flag(node, OF_POPULATED);

all over the place?

Thanks,

tglx

#24 lore raw

Re: [tip: timers/core] clocksource/drivers/timer-probe: Avoid creating dead devices

Quoted 28 lines · Thomas Gleixner
Quoted 26 lines · Saravana Kannan
Quoted 9 lines · Thomas Gleixner
Quoted 8 lines · Saravana Kannan

On Tue, Mar 24, 2020 at 11:34 AM Saravana Kannan <[email protected]> wrote:
I took a closer look. So two different drivers [1] [2] are saying they know how to handle "arm,vexpress-sysreg" and are expecting to run at the same time. That seems a bit unusual to me. I wonder if this is a violation of the device-driver model because this expectation would never be allowed if these device drivers were actual drivers registered with driver-core. But that's a discussion for another time.

Quoted 4 lines
Quoted 2 lines

To fix this issue you are facing, this patch should work:
https://lore.kernel.org/lkml/[email protected]/T/#u

Sorry, that's not a fix. That's a crude hack.

If device nodes are being handled by drivers without binding a driver to struct devices, then not setting OF_POPULATED is wrong. So the original patch sets it. There are also very valid reasons for allowing OF_POPULATED to be cleared by a driver as discussed here [1].

The approach of the original patch (setting the flag and letting the driver sometimes clear it) is also followed by many other frameworks like irq, clk, i2c, etc. Even ingenic-timer.c already does it for the exact same reason.

Quoted 6 lines
Quoted 1 line

So, why is the vexpress fix a crude hack?

If it's the right thing to do and accepted by the DT folks, then the changelog should provide a proper explanation for it. The one you provided just baffles me. Plus the clearing of the flag really needs a big fat comment.

IMO, commit 4f41fe386a946 should be reverted and be done with it. There's no way the timer core can know whether a specific node should be scanned or not. If you really want to avoid a struct device, then set OF_POPULATED in specific timer drivers. But I'd rather not see more places mucking with OF_POPULATED. It's really only bus code that should be touching it.

Is having a struct device really a problem? If we want to save memory usage, I have some ideas that would save much more than 1 or 2 struct devices.

Quoted 5 lines

It still does not make any sense to me.

arm,vexpress-sysreg is a MFD device, so can the ARM people please explain, why the sched clock part is not just another MFD sub-device or simply has it's own DT match?

The issue is DT nodes and Linux drivers aren't necessarily 1-1. That would be nice, but hardware is messy and DT doesn't abstract that away. If we tried to always make things 1-1, then if/when the Linux driver structure changes we'd have to change the DT. If we decided to add a node now, we'd still have to support the old DT for backwards compatibility. We also have to consider the structure for another OS may be different.

Generally, if I see a node with a compatible only it gets NAKed as that's a sure sign of someone just trying to bind a driver and not describing the h/w. We only do MFD sub-devices if those devices provide or consume other DT resources.

Rob

#25 lore raw

Re: [tip: timers/core] clocksource/drivers/timer-probe: Avoid creating dead devices

Quoted 37 lines · Rob Herring
Quoted 28 lines · Thomas Gleixner
Quoted 26 lines · Saravana Kannan
Quoted 9 lines · Thomas Gleixner
Quoted 8 lines · Saravana Kannan

On Tue, Mar 24, 2020 at 11:34 AM Saravana Kannan <[email protected]> wrote:
I took a closer look. So two different drivers [1] [2] are saying they know how to handle "arm,vexpress-sysreg" and are expecting to run at the same time. That seems a bit unusual to me. I wonder if this is a violation of the device-driver model because this expectation would never be allowed if these device drivers were actual drivers registered with driver-core. But that's a discussion for another time.

Quoted 4 lines
Quoted 2 lines

To fix this issue you are facing, this patch should work:
https://lore.kernel.org/lkml/[email protected]/T/#u

Sorry, that's not a fix. That's a crude hack.

If device nodes are being handled by drivers without binding a driver to struct devices, then not setting OF_POPULATED is wrong. So the original patch sets it. There are also very valid reasons for allowing OF_POPULATED to be cleared by a driver as discussed here [1].

The approach of the original patch (setting the flag and letting the driver sometimes clear it) is also followed by many other frameworks like irq, clk, i2c, etc. Even ingenic-timer.c already does it for the exact same reason.

Quoted 6 lines
Quoted 1 line

So, why is the vexpress fix a crude hack?

If it's the right thing to do and accepted by the DT folks, then the changelog should provide a proper explanation for it. The one you provided just baffles me. Plus the clearing of the flag really needs a big fat comment.

Quoted 6 lines

IMO, commit 4f41fe386a946 should be reverted and be done with it. There's no way the timer core can know whether a specific node should be scanned or not. If you really want to avoid a struct device, then set OF_POPULATED in specific timer drivers. But I'd rather not see more places mucking with OF_POPULATED. It's really only bus code that should be touching it.

Since most drivers don't need the struct device, my patch sets the flag in the timer core. And for the few exception cases where the device is needed, we can clear the flag in the driver. That'll reduce the number of places mucking with OF_POPULATED.

Does this seem okay to you?

Quoted 3 lines

Is having a struct device really a problem? If we want to save memory usage, I have some ideas that would save much more than 1 or 2 struct devices.

Keep in mind that struct devices cost more than one struct device of memory. They also create a bunch of sysfs nodes, uevents, etc.

Quoted 10 lines
Quoted 5 lines

It still does not make any sense to me.

arm,vexpress-sysreg is a MFD device, so can the ARM people please explain, why the sched clock part is not just another MFD sub-device or simply has it's own DT match?

The issue is DT nodes and Linux drivers aren't necessarily 1-1. That would be nice, but hardware is messy and DT doesn't abstract that away. If we tried to always make things 1-1, then if/when the Linux driver structure changes we'd have to change the DT.

I agree with this. I'm definitely not asking to create a node just because we want another struct device.

Quoted 3 lines

If we decided to
add a node now, we'd still have to support the old DT for backwards compatibility.

Right, I agree it's too late to fix this DT for vexpress-sysreg now.

Quoted 7 lines

We also have to consider the structure for another OS may be different.

Generally, if I see a node with a compatible only it gets NAKed as that's a sure sign of someone just trying to bind a driver and not describing the h/w. We only do MFD sub-devices if those devices provide or consume other DT resources.

If we have a timer MFD, it'd technically consume a fixed-clock and not be empty. vexpress-sysreg just assumes the clock is 24 MHz right now.

My point about the vexpress DT nodes being weird is not about Linux devices, rather it's that:
1. It's already a MFD
2. Most of the functions are separated clearly into their functional device nodes
3. However, the timer functionality is combined with the parent MFD device when the parent MFD device implements a completely separate function (gpio?). Why?

If one wants to split out the functions, do it fully. If one wants it all under one mega driver (ugh!) then combine it all. Going halfway causes these weird issues. That's my complaint about how the DT layout is for this device.

Having said all that, I'd rather manipulate the OF_POPULATED flag than break DT backward compatibility at this point.

But in general, I think we should try to reject two separate drivers claiming to be compatible with the same device and expecting to work at the same time. That's just weird.

-Saravana

#26 lore raw

Re: [tip: timers/core] clocksource/drivers/timer-probe: Avoid creating dead devices

Quoted 46 lines · Saravana Kannan
Quoted 37 lines · Rob Herring
Quoted 28 lines · Thomas Gleixner
Quoted 26 lines · Saravana Kannan
Quoted 9 lines · Thomas Gleixner
Quoted 8 lines · Saravana Kannan

On Tue, Mar 24, 2020 at 11:34 AM Saravana Kannan <[email protected]> wrote:
I took a closer look. So two different drivers [1] [2] are saying they know how to handle "arm,vexpress-sysreg" and are expecting to run at the same time. That seems a bit unusual to me. I wonder if this is a violation of the device-driver model because this expectation would never be allowed if these device drivers were actual drivers registered with driver-core. But that's a discussion for another time.

Quoted 4 lines
Quoted 2 lines

To fix this issue you are facing, this patch should work:
https://lore.kernel.org/lkml/[email protected]/T/#u

Sorry, that's not a fix. That's a crude hack.

If device nodes are being handled by drivers without binding a driver to struct devices, then not setting OF_POPULATED is wrong. So the original patch sets it. There are also very valid reasons for allowing OF_POPULATED to be cleared by a driver as discussed here [1].

The approach of the original patch (setting the flag and letting the driver sometimes clear it) is also followed by many other frameworks like irq, clk, i2c, etc. Even ingenic-timer.c already does it for the exact same reason.

Quoted 6 lines
Quoted 1 line

So, why is the vexpress fix a crude hack?

If it's the right thing to do and accepted by the DT folks, then the changelog should provide a proper explanation for it. The one you provided just baffles me. Plus the clearing of the flag really needs a big fat comment.

Quoted 6 lines

IMO, commit 4f41fe386a946 should be reverted and be done with it. There's no way the timer core can know whether a specific node should be scanned or not. If you really want to avoid a struct device, then set OF_POPULATED in specific timer drivers. But I'd rather not see more places mucking with OF_POPULATED. It's really only bus code that should be touching it.

Quoted 6 lines

Since most drivers don't need the struct device, my patch sets the flag in the timer core. And for the few exception cases where the device is needed, we can clear the flag in the driver. That'll reduce the number of places mucking with OF_POPULATED.

Does this seem okay to you?

No. Like I said, I prefer fewer cases of these flags being mucked with.

There are some other ways to solve this. Add a new "ignore" flag. That would be somewhat better as OF_POPULATED is not necessarily static (overlays!). Another way would be changing 'status' property to something other than 'okay'.

Quoted 6 lines
Quoted 3 lines

Is having a struct device really a problem? If we want to save memory usage, I have some ideas that would save much more than 1 or 2 struct devices.

Keep in mind that struct devices cost more than one struct device of memory. They also create a bunch of sysfs nodes, uevents, etc.

Having the device in sysfs could be argued to be a feature.

How much memory would we be saving? Is this really the biggest problem we have for something that's been this way for at least 10 years now.

Quoted 23 lines
Quoted 10 lines
Quoted 5 lines

It still does not make any sense to me.

arm,vexpress-sysreg is a MFD device, so can the ARM people please explain, why the sched clock part is not just another MFD sub-device or simply has it's own DT match?

The issue is DT nodes and Linux drivers aren't necessarily 1-1. That would be nice, but hardware is messy and DT doesn't abstract that away. If we tried to always make things 1-1, then if/when the Linux driver structure changes we'd have to change the DT.

I agree with this. I'm definitely not asking to create a node just because we want another struct device.

Quoted 3 lines

If we decided to
add a node now, we'd still have to support the old DT for backwards compatibility.

Right, I agree it's too late to fix this DT for vexpress-sysreg now.

Quoted 3 lines

We also have to consider the structure for another OS may be different.

Quoted 7 lines
Quoted 4 lines

Generally, if I see a node with a compatible only it gets NAKed as that's a sure sign of someone just trying to bind a driver and not describing the h/w. We only do MFD sub-devices if those devices provide or consume other DT resources.

If we have a timer MFD, it'd technically consume a fixed-clock and not be empty. vexpress-sysreg just assumes the clock is 24 MHz right now.

Possibly. Depends if only the timer uses the clock or all the other functions use the clock.

If only someone had said the clock should be in DT [1].

Quoted 8 lines

My point about the vexpress DT nodes being weird is not about Linux devices, rather it's that:
1. It's already a MFD
2. Most of the functions are separated clearly into their functional device nodes
3. However, the timer functionality is combined with the parent MFD device when the parent MFD device implements a completely separate function (gpio?). Why?

Looking at the history, it doesn't look like this got much review and it would look a bit different if we were starting over. In any case, a node for just a counter register seems like overkill. I often get these MFD or system controller bindings piecemeal, so it's hard to make any intelligent design decisions.

Actually, the fact that sched clock support was added later on without doing a DT change was probably the main thing this binding got right.

Quoted 4 lines

If one wants to split out the functions, do it fully. If one wants it all under one mega driver (ugh!) then combine it all. Going halfway causes these weird issues. That's my complaint about how the DT layout is for this device.

It's not how the binding is split, but that the functions are split between a non-driver thing and driver things.

Quoted 6 lines

Having said all that, I'd rather manipulate the OF_POPULATED flag than break DT backward compatibility at this point.

But in general, I think we should try to reject two separate drivers claiming to be compatible with the same device and expecting to work at the same time. That's just weird.

If we had 2 proper drivers, we wouldn't be having this conversation. It's not a problem to have multiple child drivers for a single DT node when everything is a proper driver. We do that all the time.

Rob

[1] https://lkml.org/lkml/2014/4/16/422

maintainer
#27 lore raw

Re: [tip: timers/core] clocksource/drivers/timer-probe: Avoid creating dead devices

In reply to Ionela Voinescu
Quoted 38 lines · Ionela Voinescu

Hi guys,

Quoted 35 lines · On Thursday 19 Mar 2020 at 08:47:46 (-0000), tip-bot2 for Saravana Kannan wrote:

The following commit has been merged into the timers/core branch of tip:

Conommit-ID:     4f41fe386a94639cd9a1831298d4f85db5662f1e
Gitweb:        https://git.kernel.org/tip/4f41fe386a94639cd9a1831298d4f85db5662f1e
Author:        Saravana Kannan <[email protected]>
AuthorDate:    Fri, 10 Jan 2020 21:21:25 -08:00
Committer:     Daniel Lezcano <[email protected]>
CommitterDate: Tue, 17 Mar 2020 13:10:07 +01:00

clocksource/drivers/timer-probe: Avoid creating dead devices

Timer initialization is done during early boot way before the driver core starts processing devices and drivers. Timers initialized during this early boot period don't really need or use a struct device.

However, for timers represented as device tree nodes, the struct devices are still created and sit around unused and wasting memory. This change avoid this by marking the device tree nodes as "populated" if the corresponding timer is successfully initialized.

---
 drivers/clocksource/timer-probe.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/clocksource/timer-probe.c +0 -0
index ee9574d..a10f28d 100644
@@ -27,8 +27,10 @@ void __init timer_probe(void)
 
 		init_func_ret = match->data;
 
Quoted 13 lines

drivers/clocksource/timer-probe.c void __init timer_probe(void) · line 36

Quoted 8 lines
drivers/clocksource/timer-probe.c +2 -0
+		of_node_set_flag(np, OF_POPULATED);
 		ret = init_func_ret(np);
 		if (ret) {
+			of_node_clear_flag(np, OF_POPULATED);
 			if (ret != -EPROBE_DEFER)
 				pr_err("Failed to initialize '%pOF': %d\n", np,
 				       ret);

This patch is creating problems on some vexpress platforms - ones that are using CLKSRC_VERSATILE (drivers/clocksource/timer-versatile.c). I noticed issues on TC2 and FVPs (fixed virtual platforms) starting with next-20200318 and still reproducible with next-20200323.

I am also seeing a regression on tegra30-cardhu-a04 when testing system suspend on -next. Bisect is pointing to this commit and reverting on top of -next fixes the problem. Unfortunately, there is no crash dump observed, but the device hangs somewhere when testing suspend.

I have not looked into this any further but wanted to report the problem.

Cheers
Jon

Signature · 1 line
nvpublic
#28 lore raw

Re: [tip: timers/core] clocksource/drivers/timer-probe: Avoid creating dead devices

26.03.2020 00:29, Jon Hunter пишет:

Quoted 54 lines · Ionela Voinescu
Quoted 38 lines

Hi guys,

Quoted 35 lines · On Thursday 19 Mar 2020 at 08:47:46 (-0000), tip-bot2 for Saravana Kannan wrote:

The following commit has been merged into the timers/core branch of tip:

Conommit-ID:     4f41fe386a94639cd9a1831298d4f85db5662f1e
Gitweb:        https://git.kernel.org/tip/4f41fe386a94639cd9a1831298d4f85db5662f1e
Author:        Saravana Kannan <[email protected]>
AuthorDate:    Fri, 10 Jan 2020 21:21:25 -08:00
Committer:     Daniel Lezcano <[email protected]>
CommitterDate: Tue, 17 Mar 2020 13:10:07 +01:00

clocksource/drivers/timer-probe: Avoid creating dead devices

Timer initialization is done during early boot way before the driver core starts processing devices and drivers. Timers initialized during this early boot period don't really need or use a struct device.

However, for timers represented as device tree nodes, the struct devices are still created and sit around unused and wasting memory. This change avoid this by marking the device tree nodes as "populated" if the corresponding timer is successfully initialized.

---
 drivers/clocksource/timer-probe.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/clocksource/timer-probe.c +0 -0
index ee9574d..a10f28d 100644
@@ -27,8 +27,10 @@ void __init timer_probe(void)
 
 		init_func_ret = match->data;
 
Quoted 13 lines

drivers/clocksource/timer-probe.c void __init timer_probe(void) · line 36

Quoted 8 lines
drivers/clocksource/timer-probe.c +2 -0
+		of_node_set_flag(np, OF_POPULATED);
 		ret = init_func_ret(np);
 		if (ret) {
+			of_node_clear_flag(np, OF_POPULATED);
 			if (ret != -EPROBE_DEFER)
 				pr_err("Failed to initialize '%pOF': %d\n", np,
 				       ret);

This patch is creating problems on some vexpress platforms - ones that are using CLKSRC_VERSATILE (drivers/clocksource/timer-versatile.c). I noticed issues on TC2 and FVPs (fixed virtual platforms) starting with next-20200318 and still reproducible with next-20200323.

Quoted 6 lines

I am also seeing a regression on tegra30-cardhu-a04 when testing system suspend on -next. Bisect is pointing to this commit and reverting on top of -next fixes the problem. Unfortunately, there is no crash dump observed, but the device hangs somewhere when testing suspend.

I have not looked into this any further but wanted to report the problem.

IIUC, this should also break the watchdog driver on Tegra because the device tree node is shared by both clocksource and watchdog.

#29 lore raw

[tip: timers/core] Revert "clocksource/drivers/timer-probe: Avoid creating dead devices"

In reply to Ionela Voinescu
The following commit has been merged into the timers/core branch of tip:

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     4479730e9263befbb9ce9563a09563db2acb8f7c
Gitweb:        https://git.kernel.org/tip/4479730e9263befbb9ce9563a09563db2acb8f7c
Author:        Thomas Gleixner <[email protected]>
AuthorDate:    Sat, 28 Mar 2020 11:20:36 +01:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Sat, 28 Mar 2020 11:25:44 +01:00

Revert "clocksource/drivers/timer-probe: Avoid creating dead devices"

This reverts commit 4f41fe386a94639cd9a1831298d4f85db5662f1e.

The change breaks systems on which the DT node of a device is used by multiple drivers. The proposed workaround to clear OF_POPULATED is just a band aid and this needs to be cleaned up at the root of the problem.

Revert this for now.

---
 drivers/clocksource/timer-probe.c | 2 --
 1 file changed, 2 deletions(-)
drivers/clocksource/timer-probe.c +0 -2
index a10f28d..ee9574d 100644
@@ -27,10 +27,8 @@ void __init timer_probe(void)
 
 		init_func_ret = match->data;
 
-		of_node_set_flag(np, OF_POPULATED);
 		ret = init_func_ret(np);
 		if (ret) {
-			of_node_clear_flag(np, OF_POPULATED);
 			if (ret != -EPROBE_DEFER)
 				pr_err("Failed to initialize '%pOF': %d\n", np,
 				       ret);