Skip to contentSkip to conversation

of/platform: add initcall_debug logs for device creates

PATCH In review Todd Poynor 3 participants 5 messages Jun 19, 2018 – Jun 20, 2018 Device tree

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 of/platform: add initcall_debug logs for device creates

From: Todd Poynor <[email protected]>

Add initcall_debug logs for the amount of time taken by each OF platform bus device create call. For example:

of platform device create /reserved-memory/ramoops@a3800000 took 3255 usecs

initcall_debug already reports the total of all such device creates as a single entry for function of_platform_default_populate_init (or similar, depending on the board). The new logs help identify which of the potentially hundreds of device inits take significant amounts of time.

---
 drivers/of/platform.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

Note it's likely only a few devices take significant lengths of time to init, whereas there may be hundreds of uninteresting cases also logged. Adding a threshold for reporting might be desirable, although for boot time sleuthing it's probably fine to generate a ton of output and narrow down the points of interest with tools.

drivers/of/platform.c +27 -1
index 6925d993e1f0..eeb4c595f43c 100644
@@ -14,6 +14,7 @@
 #include <linux/amba/bus.h>
 #include <linux/device.h>
 #include <linux/dma-mapping.h>
+#include <linux/init.h>
 #include <linux/slab.h>
 #include <linux/of_address.h>
 #include <linux/of_device.h>
@@ -159,6 +160,19 @@ struct platform_device *of_device_alloc(struct device_node *np,
 }
 EXPORT_SYMBOL(of_device_alloc);
 
+static void of_platform_log_inittime(struct device_node *node,
+				     ktime_t starttime)
+{
+	ktime_t delta, endtime;
+	unsigned long long duration;
+
+	endtime = ktime_get();
+	delta = ktime_sub(endtime, starttime);
+	duration = (unsigned long long) ktime_to_ns(delta) >> 10;
+	pr_debug("of platform device create %s took %lld usecs\n",
+		 node->full_name, duration);
+}
+
 /**
  * of_platform_device_create_pdata - Alloc, initialize and register an of_device
  * @np: pointer to node to create device for
@@ -176,6 +190,8 @@ static struct platform_device *of_platform_device_create_pdata(
 					struct device *parent)
 {
 	struct platform_device *dev;
+	ktime_t starttime = 0;
+	int ret;
 
 	if (!of_device_is_available(np) ||
 	    of_node_test_and_set_flag(np, OF_POPULATED))
@@ -187,9 +203,14 @@ static struct platform_device *of_platform_device_create_pdata(
 
 	dev->dev.bus = &platform_bus_type;
 	dev->dev.platform_data = platform_data;
+	if (initcall_debug)
+		starttime = ktime_get();
 	of_msi_configure(&dev->dev, dev->dev.of_node);
+	ret = of_device_add(dev);
+	if (initcall_debug)
+		of_platform_log_inittime(np, starttime);
 
-	if (of_device_add(dev) != 0) {
+	if (ret != 0) {
 		platform_device_put(dev);
 		goto err_clear_flag;
 	}
@@ -352,6 +373,7 @@ static int of_platform_bus_create(struct device_node *bus,
 	struct platform_device *dev;
 	const char *bus_id = NULL;
 	void *platform_data = NULL;
+	ktime_t starttime = 0;
 	int rc = 0;
 
 	/* Make sure it has a compatible property */
@@ -384,7 +406,11 @@ static int of_platform_bus_create(struct device_node *bus,
 		 * Don't return an error here to keep compatibility with older
 		 * device tree files.
 		 */
+		if (initcall_debug)
+			starttime = ktime_get();
 		of_amba_device_create(bus, bus_id, platform_data, parent);
+		if (initcall_debug)
+			of_platform_log_inittime(bus, starttime);
 		return 0;
 	}
 
Signature · 1 line
2.18.0.rc1.244.gcf134e6275-goog
#1 lore raw
Quoted 5 lines · Todd Poynor

From: Todd Poynor <[email protected]>

Add initcall_debug logs for the amount of time taken by each OF platform bus device create call. For example:

Quoted 8 lines

of platform device create /reserved-memory/ramoops@a3800000 took 3255 usecs

initcall_debug already reports the total of all such device creates as a single entry for function of_platform_default_populate_init (or similar, depending on the board). The new logs help identify which of the potentially hundreds of device inits take significant amounts of time.

It's really the probe time that matters here. Outside of that, creating the devices should be fairly constant time. So why not add timing around non bus specific probe code (driver_probe_device) instead of adding this in multiple places. Then you can remove the timing from deferred probe code.

Rob

#2 lore raw
Quoted 6 lines · Rob Herring

It's really the probe time that matters here. Outside of that, creating the devices should be fairly constant time. So why not add timing around non bus specific probe code (driver_probe_device) instead of adding this in multiple places. Then you can remove the timing from deferred probe code.

Will do, thanks.

Todd

#3 lore raw
In reply to Todd Poynor

Hi Todd,

Quoted 38 lines · Todd Poynor

From: Todd Poynor <[email protected]>

Add initcall_debug logs for the amount of time taken by each OF platform bus device create call. For example:

of platform device create /reserved-memory/ramoops@a3800000 took 3255 usecs

initcall_debug already reports the total of all such device creates as a single entry for function of_platform_default_populate_init (or similar, depending on the board). The new logs help identify which of the potentially hundreds of device inits take significant amounts of time.

---
 drivers/of/platform.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

Note it's likely only a few devices take significant lengths of time to init, whereas there may be hundreds of uninteresting cases also logged. Adding a threshold for reporting might be desirable, although for boot time sleuthing it's probably fine to generate a ton of output and narrow down the points of interest with tools.

drivers/of/platform.c +1 -0
index 6925d993e1f0..eeb4c595f43c 100644
@@ -14,6 +14,7 @@
 #include <linux/amba/bus.h>
 #include <linux/device.h>
 #include <linux/dma-mapping.h>
+#include <linux/init.h>
 #include <linux/slab.h>
 #include <linux/of_address.h>
 #include <linux/of_device.h>

drivers/of/platform.c struct platform_device *of_device_alloc(struct device_node *np, · line 164

Quoted 5 lines
drivers/of/platform.c +2 -0
@@ -159,6 +160,19 @@ struct platform_device *of_device_alloc(struct device_node *np,
 }
 EXPORT_SYMBOL(of_device_alloc);
 
+static void of_platform_log_inittime(struct device_node *node,
+				     ktime_t starttime)

Please call it pr_delta_time() instead.

drivers/of/platform.c struct platform_device *of_device_alloc(struct device_node *np, · line 173

Quoted 9 lines
drivers/of/platform.c +9 -0
+{
+	ktime_t delta, endtime;
+	unsigned long long duration;
+
+	endtime = ktime_get();
+	delta = ktime_sub(endtime, starttime);
+	duration = (unsigned long long) ktime_to_ns(delta) >> 10;
+	pr_debug("of platform device create %s took %lld usecs\n",
+		 node->full_name, duration);

The device node full_name field no longer contains the full path of the node name. To deal with this, use %pOF on node instead of %s on node->full_name (core-api/printk-formats.rst).

drivers/of/platform.c static struct platform_device *of_platform_device_create_pdata( · line 193

Quoted 10 lines
drivers/of/platform.c +3 -0
+}
+
 /**
  * of_platform_device_create_pdata - Alloc, initialize and register an of_device
  * @np: pointer to node to create device for
@@ -176,6 +190,8 @@ static struct platform_device *of_platform_device_create_pdata(
 					struct device *parent)
 {
 	struct platform_device *dev;
+	ktime_t starttime = 0;

I assume the initialization to zero is to silence a compiler warning. Is my assumption correct?

Quoted 41 lines
drivers/of/platform.c +12 -1
+	int ret;
 
 	if (!of_device_is_available(np) ||
 	    of_node_test_and_set_flag(np, OF_POPULATED))
@@ -187,9 +203,14 @@ static struct platform_device *of_platform_device_create_pdata(
 
 	dev->dev.bus = &platform_bus_type;
 	dev->dev.platform_data = platform_data;
+	if (initcall_debug)
+		starttime = ktime_get();
 	of_msi_configure(&dev->dev, dev->dev.of_node);
+	ret = of_device_add(dev);
+	if (initcall_debug)
+		of_platform_log_inittime(np, starttime);
 
-	if (of_device_add(dev) != 0) {
+	if (ret != 0) {
 		platform_device_put(dev);
 		goto err_clear_flag;
 	}
@@ -352,6 +373,7 @@ static int of_platform_bus_create(struct device_node *bus,
 	struct platform_device *dev;
 	const char *bus_id = NULL;
 	void *platform_data = NULL;
+	ktime_t starttime = 0;
 	int rc = 0;
 
 	/* Make sure it has a compatible property */
@@ -384,7 +406,11 @@ static int of_platform_bus_create(struct device_node *bus,
 		 * Don't return an error here to keep compatibility with older
 		 * device tree files.
 		 */
+		if (initcall_debug)
+			starttime = ktime_get();
 		of_amba_device_create(bus, bus_id, platform_data, parent);
+		if (initcall_debug)
+			of_platform_log_inittime(bus, starttime);
 		return 0;
 	}
 
#4 lore raw
Quoted 2 lines · Frank Rowand

Hi Todd,

Hey Frank, long time!

Quoted 7 lines

drivers/of/platform.c struct platform_device *of_device_alloc(struct device_node *np, · line 173

Quoted 2 lines
drivers/of/platform.c +2 -0
+     pr_debug("of platform device create %s took %lld usecs\n",
+              node->full_name, duration);

The device node full_name field no longer contains the full path of the node name. To deal with this, use %pOF on node instead of %s on node->full_name (core-api/printk-formats.rst).

OK, the touched up patch just uses dev_name() in common code, can do something nicer for OF nodes if possible.

Quoted 10 lines

drivers/of/platform.c struct platform_device *of_device_alloc(struct device_node *np,

Quoted 6 lines
drivers/of/platform.c +2 -0
+}
+
 /**
  * of_platform_device_create_pdata - Alloc, initialize and register an

of_device

Review static struct platform_device

Quoted 2 lines

* @np: pointer to node to create device for

(quoted diff) +0 -0
@@ -176,6 +190,8 @@ static struct platform_device

*of_platform_device_create_pdata(

Quoted 9 lines

drivers/of/platform.c static struct platform_device *of_platform_device_create_pdata( · line 193

Quoted 4 lines
drivers/of/platform.c +1 -0
                                      struct device *parent)
 {
      struct platform_device *dev;
+     ktime_t starttime = 0;

I assume the initialization to zero is to silence a compiler warning. Is my
assumption correct?

Right, "may be used uninitialized". This goes away in the new code as well.

Thanks -- Todd