CHROMIUM: power: add knob for printing device resume times
authorSameer Nanda <snanda@chromium.org>
Wed, 6 Jun 2012 18:03:57 +0000 (11:03 -0700)
committerGerrit <chrome-bot@google.com>
Wed, 6 Jun 2012 19:54:42 +0000 (12:54 -0700)
Added a new knob called /sys/power/pm_print_times. Setting it to 1
enables printing of time taken by devices to suspend and resume.
Setting it to 0 disables this printing (unless overridden by
initcall_debug kernel command line option).

This patch has been sent upstream but seems to be in limbo there.  Pushing
as a CHROMIUM patch for now and will revisit once the upstream discussion
happens.

BUG=chromium-os:30539
TEST=First enable device suspend/resume time printing by issuing this
command: "echo 1 > /sys/power/pm_print_times".  Then do a suspend/resume
cycle.  After resuming look at dmesg and there should be several "call
<device> returned 0 after <time> usecs".  The <time> in these messages
indicates the time taken by the <device> to suspend or resume.

Change-Id: I8f210acd6667a870d286bff412df6b8014438e8c
Signed-off-by: Sameer Nanda <snanda@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/24628
Reviewed-by: Olof Johansson <olofj@chromium.org>
Documentation/ABI/testing/sysfs-power
drivers/base/power/main.c
drivers/base/power/power.h
kernel/power/main.c

index b464d12..79210d1 100644 (file)
@@ -172,3 +172,16 @@ Description:
 
                Reading from this file will display the current value, which is
                set to 1 MB by default.
+
+What:          /sys/power/pm_print_times
+Date:          May 2012
+Contact:       Sameer Nanda <snanda@chromium.org>
+Description:
+               The /sys/power/pm_print_times file allows user space to
+               control whether the time taken by devices to suspend and
+               resume is printed.  These prints are useful for hunting down
+               devices that take too long to suspend or resume.
+
+               Writing a "1" enables this printing while writing a "0"
+               disables it.  The default value is "0".  Reading from this file
+               will display the current value.
index b462c0e..ca8b2b5 100644 (file)
@@ -166,7 +166,7 @@ static ktime_t initcall_debug_start(struct device *dev)
 {
        ktime_t calltime = ktime_set(0, 0);
 
-       if (initcall_debug) {
+       if (pm_print_times) {
                pr_info("calling  %s+ @ %i, parent: %s\n",
                        dev_name(dev), task_pid_nr(current),
                        dev->parent ? dev_name(dev->parent) : "none");
@@ -181,7 +181,7 @@ static void initcall_debug_report(struct device *dev, ktime_t calltime,
 {
        ktime_t delta, rettime;
 
-       if (initcall_debug) {
+       if (pm_print_times) {
                rettime = ktime_get();
                delta = ktime_sub(rettime, calltime);
                pr_info("call %s+ returned %d after %Ld usecs\n", dev_name(dev),
index eeb4bff..12c77b7 100644 (file)
@@ -85,3 +85,14 @@ static inline int pm_qos_sysfs_add(struct device *dev) { return 0; }
 static inline void pm_qos_sysfs_remove(struct device *dev) {}
 
 #endif
+
+#ifdef CONFIG_PM_DEBUG
+
+extern int pm_print_times_enabled;
+#define pm_print_times (initcall_debug || pm_print_times_enabled)
+
+#else /* CONFIG_PM_DEBUG */
+
+#define pm_print_times initcall_debug
+
+#endif /* CONFIG_PM_DEBUG */
index 1c12581..97eea04 100644 (file)
@@ -132,6 +132,39 @@ static ssize_t pm_test_store(struct kobject *kobj, struct kobj_attribute *attr,
 }
 
 power_attr(pm_test);
+
+/*
+ *     pm_print_times: print time taken by devices to suspend and resume.
+ *
+ *     show() returns whether printing of suspend and resume times is enabled.
+ *
+ *     store() accepts 0 or 1.  0 disables printing and 1 enables it.
+ */
+int pm_print_times_enabled;
+
+static ssize_t pm_print_times_show(struct kobject *kobj,
+                                  struct kobj_attribute *attr, char *buf)
+{
+       return sprintf(buf, "%d\n", pm_print_times_enabled);
+}
+
+static ssize_t pm_print_times_store(struct kobject *kobj,
+                                   struct kobj_attribute *attr,
+                                   const char *buf, size_t n)
+{
+       unsigned long val;
+
+       if (kstrtoul(buf, 10, &val))
+               return -EINVAL;
+
+       if (val > 1)
+               return -EINVAL;
+
+       pm_print_times_enabled = val;
+       return n;
+}
+
+power_attr(pm_print_times);
 #endif /* CONFIG_PM_DEBUG */
 
 #ifdef CONFIG_DEBUG_FS
@@ -411,6 +444,7 @@ static struct attribute * g[] = {
        &wakeup_count_attr.attr,
 #ifdef CONFIG_PM_DEBUG
        &pm_test_attr.attr,
+       &pm_print_times_attr.attr,
 #endif
 #endif
        NULL,