Re: [PATCH v2] power: add knob for printing device resume times

From: Sameer Nanda
Date: Mon Jun 04 2012 - 18:42:06 EST


On Wed, May 23, 2012 at 9:45 AM, Sameer Nanda <snanda@xxxxxxxxxxxx> wrote:
> 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).
>
> Signed-off-by: Sameer Nanda <snanda@xxxxxxxxxxxx>
> cc: Greg KH <gregkh@xxxxxxxxxxxxxxxxxxx>
> cc: Rafael J. Wysocki <rjw@xxxxxxx>
> cc: Steven Rostedt <rostedt@xxxxxxxxxxx>
> ---
> ÂDocumentation/ABI/testing/sysfs-power | Â 13 ++++++++++++
> Âdrivers/base/power/main.c       |  Â4 +-
> Âdrivers/base/power/power.h      Â|  11 ++++++++++
> Âkernel/power/main.c          |  34 +++++++++++++++++++++++++++++++++
> Â4 files changed, 60 insertions(+), 2 deletions(-)
>
> diff --git a/Documentation/ABI/testing/sysfs-power b/Documentation/ABI/testing/sysfs-power
> index b464d12..79210d1 100644
> --- a/Documentation/ABI/testing/sysfs-power
> +++ b/Documentation/ABI/testing/sysfs-power
> @@ -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@xxxxxxxxxxxx>
> +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.
> diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
> index b462c0e..ca8b2b5 100644
> --- a/drivers/base/power/main.c
> +++ b/drivers/base/power/main.c
> @@ -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),
> diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h
> index eeb4bff..12c77b7 100644
> --- a/drivers/base/power/power.h
> +++ b/drivers/base/power/power.h
> @@ -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 */
> diff --git a/kernel/power/main.c b/kernel/power/main.c
> index 1c12581..97eea04 100644
> --- a/kernel/power/main.c
> +++ b/kernel/power/main.c
> @@ -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,
> --
> 1.7.7.3
>

Greg KH, Rafael: any feedback on this patch? Questions I can help
answer to help push this along?
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/