Skip to contentSkip to conversation

initcall_debug: add deferred probe times

PATCH In review Todd Poynor 2 participants 4 messages Jul 25, 2017 – Aug 4, 2017 Driver core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 initcall_debug: add deferred probe times

initcall_debug attributes all deferred device probe retries for the late_initcall level to function deferred_probe_initcall. Add logs of the individual device probe routines called, to identify which drivers are executing for how long during the initcall path. Deferred probes that occur after initcall processing are not shown.

Example log messages added:

[    0.505119] deferred probe my-sound-device @ 6
[    0.517656] deferred probe my-sound-device returned after 1227 usecs
---
 drivers/base/dd.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)
drivers/base/dd.c +27 -1
index 4882f06d12df..6831cb48e9dd 100644
@@ -20,6 +20,7 @@
 #include <linux/device.h>
 #include <linux/delay.h>
 #include <linux/dma-mapping.h>
+#include <linux/init.h>
 #include <linux/module.h>
 #include <linux/kthread.h>
 #include <linux/wait.h>
@@ -53,6 +54,7 @@ static DEFINE_MUTEX(deferred_probe_mutex);
 static LIST_HEAD(deferred_probe_pending_list);
 static LIST_HEAD(deferred_probe_active_list);
 static atomic_t deferred_trigger_count = ATOMIC_INIT(0);
+static bool initcalls_done;
 
 /*
  * In some cases, like suspend to RAM or hibernation, It might be reasonable
@@ -61,6 +63,26 @@ static atomic_t deferred_trigger_count = ATOMIC_INIT(0);
  */
 static bool defer_all_probes;
 
+/*
+ * For initcall_debug, show the deferred probes executed in late_initcall
+ * processing.
+ */
+static void deferred_probe_debug(struct device *dev)
+{
+	ktime_t calltime, delta, rettime;
+	unsigned long long duration;
+
+	printk(KERN_DEBUG "deferred probe %s @ %i\n", dev_name(dev),
+	       task_pid_nr(current));
+	calltime = ktime_get();
+	bus_probe_device(dev);
+	rettime = ktime_get();
+	delta = ktime_sub(rettime, calltime);
+	duration = (unsigned long long) ktime_to_ns(delta) >> 10;
+	printk(KERN_DEBUG "deferred probe %s returned after %lld usecs\n",
+	       dev_name(dev), duration);
+}
+
 /*
  * deferred_probe_work_func() - Retry probing devices in the active list.
  */
@@ -106,7 +128,10 @@ static void deferred_probe_work_func(struct work_struct *work)
 		device_pm_unlock();
 
 		dev_dbg(dev, "Retrying from deferred list\n");
-		bus_probe_device(dev);
+		if (initcall_debug && !initcalls_done)
+			deferred_probe_debug(dev);
+		else
+			bus_probe_device(dev);
 
 		mutex_lock(&deferred_probe_mutex);
 
@@ -215,6 +240,7 @@ static int deferred_probe_initcall(void)
 	driver_deferred_probe_trigger();
 	/* Sort as many dependencies as possible before exiting initcalls */
 	flush_work(&deferred_probe_work);
+	initcalls_done = true;
 	return 0;
 }
 late_initcall(deferred_probe_initcall);
Signature · 1 line
2.14.0.rc0.400.g1c36432dff-goog
#1 lore raw
Quoted 10 lines · Todd Poynor

initcall_debug attributes all deferred device probe retries for the late_initcall level to function deferred_probe_initcall. Add logs of the individual device probe routines called, to identify which drivers are executing for how long during the initcall path. Deferred probes that occur after initcall processing are not shown.

Example log messages added:

[    0.505119] deferred probe my-sound-device @ 6
[    0.517656] deferred probe my-sound-device returned after 1227 usecs

Can't you subtract the timestamp number right there?

And doesn't the tools/power/pm-graph/ scripts do this type of thing automatically for you to give you pretty graphs you can use to drill down on what is taking how long and such?

Quoted 30 lines
---
 drivers/base/dd.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)
drivers/base/dd.c +3 -0
index 4882f06d12df..6831cb48e9dd 100644
@@ -20,6 +20,7 @@
 #include <linux/device.h>
 #include <linux/delay.h>
 #include <linux/dma-mapping.h>
+#include <linux/init.h>
 #include <linux/module.h>
 #include <linux/kthread.h>
 #include <linux/wait.h>
@@ -53,6 +54,7 @@ static DEFINE_MUTEX(deferred_probe_mutex);
 static LIST_HEAD(deferred_probe_pending_list);
 static LIST_HEAD(deferred_probe_active_list);
 static atomic_t deferred_trigger_count = ATOMIC_INIT(0);
+static bool initcalls_done;
 
 /*
  * In some cases, like suspend to RAM or hibernation, It might be reasonable
@@ -61,6 +63,26 @@ static atomic_t deferred_trigger_count = ATOMIC_INIT(0);
  */
 static bool defer_all_probes;
 
+/*

drivers/base/dd.c static atomic_t deferred_trigger_count = ATOMIC_INIT(0); · line 76

Quoted 10 lines
drivers/base/dd.c +10 -0
+ * For initcall_debug, show the deferred probes executed in late_initcall
+ * processing.
+ */
+static void deferred_probe_debug(struct device *dev)
+{
+	ktime_t calltime, delta, rettime;
+	unsigned long long duration;
+
+	printk(KERN_DEBUG "deferred probe %s @ %i\n", dev_name(dev),
+	       task_pid_nr(current));

_if_ I were to take something like this, it would be best to use dev_info(), right?

But look at the analyze_boot.py script, I think it does all of this for you automagically...

thanks,

greg k-h

#2 lore raw
Quoted 7 lines · Greg Kroah-Hartman
Quoted 6 lines · Todd Poynor

initcall_debug attributes all deferred device probe retries for the late_initcall level to function deferred_probe_initcall. Add logs of the individual device probe routines called, to identify which drivers are executing for how long during the initcall path. Deferred probes that occur after initcall processing are not shown.

Quoted 6 lines
Quoted 4 lines

Example log messages added:

[    0.505119] deferred probe my-sound-device @ 6
[    0.517656] deferred probe my-sound-device returned after 1227 usecs

Can't you subtract the timestamp number right there?

This patch extends the existing initcall_debug functionality; I've copied the methods used by do_one_initcall_debug() to compute and report timing info in a compatible format. If it's better to change the way this is reported, I can also suggest changes to the existing initcall_debug code. cc'ed the maintainers (I should have in the first place).

Quoted 3 lines

And doesn't the tools/power/pm-graph/ scripts do this type of thing automatically for you to give you pretty graphs you can use to drill down on what is taking how long and such?

analyze_boot.py parses the dmesg output printed by initcall_debug to produce those graphs (and can also produce ftrace-based function callgraphs). The initcall_debug output printed (and graphed) for deferred probe calls are lumped into a single entry "deferred_probe_initcall". This patch logs the times of the individual deferred probe calls by device name, to better help developers understand where the time is spent. If this feature finds favor, it may also be deemed useful to update analyze_boot.py to graph this information.

Quoted 29 lines
Quoted 29 lines
---
 drivers/base/dd.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)
drivers/base/dd.c +2 -0
index 4882f06d12df..6831cb48e9dd 100644
@@ -20,6 +20,7 @@
 #include <linux/device.h>
 #include <linux/delay.h>
 #include <linux/dma-mapping.h>
+#include <linux/init.h>
 #include <linux/module.h>
 #include <linux/kthread.h>
 #include <linux/wait.h>
@@ -53,6 +54,7 @@ static DEFINE_MUTEX(deferred_probe_mutex);
 static LIST_HEAD(deferred_probe_pending_list);
 static LIST_HEAD(deferred_probe_active_list);
 static atomic_t deferred_trigger_count = ATOMIC_INIT(0);
+static bool initcalls_done;
 
 /*
  * In some cases, like suspend to RAM or hibernation, It might be reasonable
@@ -61,6 +63,26 @@ static atomic_t deferred_trigger_count = ATOMIC_INIT(0);
  */
 static bool defer_all_probes;
 
Quoted 14 lines

drivers/base/dd.c static atomic_t deferred_trigger_count = ATOMIC_INIT(0); · line 76

Quoted 11 lines
drivers/base/dd.c +11 -0
+/*
+ * For initcall_debug, show the deferred probes executed in late_initcall
+ * processing.
+ */
+static void deferred_probe_debug(struct device *dev)
+{
+     ktime_t calltime, delta, rettime;
+     unsigned long long duration;
+
+     printk(KERN_DEBUG "deferred probe %s @ %i\n", dev_name(dev),
+            task_pid_nr(current));

_if_ I were to take something like this, it would be best to use dev_info(), right?

dev_info() is fine by me, if the initcall_debug command line parameter is specified I would think it shouldn't be required to use the debug loglevel. But we may want to change the existing initcall_debug messages to use info loglevel as well.

Quoted 6 lines

But look at the analyze_boot.py script, I think it does all of this for you automagically...

thanks,

greg k-h

Thanks -- Todd

#3 lore raw
Quoted 14 lines · Todd Poynor
Quoted 12 lines · Greg Kroah-Hartman
Quoted 10 lines · Todd Poynor

initcall_debug attributes all deferred device probe retries for the late_initcall level to function deferred_probe_initcall. Add logs of the individual device probe routines called, to identify which drivers are executing for how long during the initcall path. Deferred probes that occur after initcall processing are not shown.

Example log messages added:

[    0.505119] deferred probe my-sound-device @ 6
[    0.517656] deferred probe my-sound-device returned after 1227 usecs
Quoted 8 lines
Quoted 1 line

Can't you subtract the timestamp number right there?

This patch extends the existing initcall_debug functionality; I've copied the methods used by do_one_initcall_debug() to compute and report timing info in a compatible format. If it's better to change the way this is reported, I can also suggest changes to the existing initcall_debug code. cc'ed the maintainers (I should have in the first place).

Ah, ok, I missed that, I was looking at the driver probe debug path, this makes a lot more sense then.

Quoted 4 lines
Quoted 3 lines

And doesn't the tools/power/pm-graph/ scripts do this type of thing automatically for you to give you pretty graphs you can use to drill down on what is taking how long and such?

Quoted 9 lines

analyze_boot.py parses the dmesg output printed by initcall_debug to produce those graphs (and can also produce ftrace-based function callgraphs). The initcall_debug output printed (and graphed) for deferred probe calls are lumped into a single entry "deferred_probe_initcall". This patch logs the times of the individual deferred probe calls by device name, to better help developers understand where the time is spent. If this feature finds favor, it may also be deemed useful to update analyze_boot.py to graph this information.

I think updating it would be good, but for now this should be fine. Thanks for the information.

greg k-h