diff options
| author | Colin Cross <ccross@android.com> | 2013-05-22 01:32:14 -0400 |
|---|---|---|
| committer | John Stultz <john.stultz@linaro.org> | 2013-05-29 15:57:34 -0400 |
| commit | 5c83545f24ab3dd67e0ae0e2b795fea750f08c34 (patch) | |
| tree | 72ad0d3d33302a9100c17855bc08bf936cbdd081 /kernel/time | |
| parent | 11ffa9d6065f344a9bd769a2452f26f2f671e5f8 (diff) | |
power: Add option to log time spent in suspend
Below is a patch from android kernel that maintains a histogram of
suspend times. Please review and provide feedback.
Statistices on the time spent in suspend are kept in
/sys/kernel/debug/sleep_time.
Cc: Android Kernel Team <kernel-team@android.com>
Cc: Colin Cross <ccross@android.com>
Cc: Todd Poynor <toddpoynor@google.com>
Cc: San Mehat <san@google.com>
Cc: Benoit Goby <benoit@android.com>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Colin Cross <ccross@android.com>
Signed-off-by: Todd Poynor <toddpoynor@google.com>
[zoran.markovic@linaro.org: Re-formatted suspend time table to better
fit expected values. Moved accounting of suspend time into timekeeping
core. Removed CONFIG_SUSPEND_TIME flag and made the feature conditional
on CONFIG_DEBUG_FS. Changed the file name to sleep_time to better fit
terminology in timekeeping core. Changed seq_printf to seq_puts. Tweaked
commit message]
Signed-off-by: Zoran Markovic <zoran.markovic@linaro.org>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Diffstat (limited to 'kernel/time')
| -rw-r--r-- | kernel/time/Makefile | 1 | ||||
| -rw-r--r-- | kernel/time/timekeeping.c | 2 | ||||
| -rw-r--r-- | kernel/time/timekeeping_debug.c | 72 | ||||
| -rw-r--r-- | kernel/time/timekeeping_internal.h | 14 |
4 files changed, 89 insertions, 0 deletions
diff --git a/kernel/time/Makefile b/kernel/time/Makefile index ff7d9d2ab504..d52ac8bf0006 100644 --- a/kernel/time/Makefile +++ b/kernel/time/Makefile | |||
| @@ -7,3 +7,4 @@ obj-$(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) += tick-broadcast.o | |||
| 7 | obj-$(CONFIG_TICK_ONESHOT) += tick-oneshot.o | 7 | obj-$(CONFIG_TICK_ONESHOT) += tick-oneshot.o |
| 8 | obj-$(CONFIG_TICK_ONESHOT) += tick-sched.o | 8 | obj-$(CONFIG_TICK_ONESHOT) += tick-sched.o |
| 9 | obj-$(CONFIG_TIMER_STATS) += timer_stats.o | 9 | obj-$(CONFIG_TIMER_STATS) += timer_stats.o |
| 10 | obj-$(CONFIG_DEBUG_FS) += timekeeping_debug.o | ||
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 933efa4071c3..838fc0777b68 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c | |||
| @@ -25,6 +25,7 @@ | |||
| 25 | 25 | ||
| 26 | #include "tick-internal.h" | 26 | #include "tick-internal.h" |
| 27 | #include "ntp_internal.h" | 27 | #include "ntp_internal.h" |
| 28 | #include "timekeeping_internal.h" | ||
| 28 | 29 | ||
| 29 | static struct timekeeper timekeeper; | 30 | static struct timekeeper timekeeper; |
| 30 | static DEFINE_RAW_SPINLOCK(timekeeper_lock); | 31 | static DEFINE_RAW_SPINLOCK(timekeeper_lock); |
| @@ -851,6 +852,7 @@ static void __timekeeping_inject_sleeptime(struct timekeeper *tk, | |||
| 851 | tk_xtime_add(tk, delta); | 852 | tk_xtime_add(tk, delta); |
| 852 | tk_set_wall_to_mono(tk, timespec_sub(tk->wall_to_monotonic, *delta)); | 853 | tk_set_wall_to_mono(tk, timespec_sub(tk->wall_to_monotonic, *delta)); |
| 853 | tk_set_sleep_time(tk, timespec_add(tk->total_sleep_time, *delta)); | 854 | tk_set_sleep_time(tk, timespec_add(tk->total_sleep_time, *delta)); |
| 855 | tk_debug_account_sleep_time(delta); | ||
| 854 | } | 856 | } |
| 855 | 857 | ||
| 856 | /** | 858 | /** |
diff --git a/kernel/time/timekeeping_debug.c b/kernel/time/timekeeping_debug.c new file mode 100644 index 000000000000..802433a4f5eb --- /dev/null +++ b/kernel/time/timekeeping_debug.c | |||
| @@ -0,0 +1,72 @@ | |||
| 1 | /* | ||
| 2 | * debugfs file to track time spent in suspend | ||
| 3 | * | ||
| 4 | * Copyright (c) 2011, Google, Inc. | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License as published by | ||
| 8 | * the Free Software Foundation; either version 2 of the License, or | ||
| 9 | * (at your option) any later version. | ||
| 10 | * | ||
| 11 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
| 14 | * more details. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include <linux/debugfs.h> | ||
| 18 | #include <linux/err.h> | ||
| 19 | #include <linux/init.h> | ||
| 20 | #include <linux/kernel.h> | ||
| 21 | #include <linux/seq_file.h> | ||
| 22 | #include <linux/time.h> | ||
| 23 | |||
| 24 | static unsigned int sleep_time_bin[32] = {0}; | ||
| 25 | |||
| 26 | static int tk_debug_show_sleep_time(struct seq_file *s, void *data) | ||
| 27 | { | ||
| 28 | unsigned int bin; | ||
| 29 | seq_puts(s, " time (secs) count\n"); | ||
| 30 | seq_puts(s, "------------------------------\n"); | ||
| 31 | for (bin = 0; bin < 32; bin++) { | ||
| 32 | if (sleep_time_bin[bin] == 0) | ||
| 33 | continue; | ||
| 34 | seq_printf(s, "%10u - %-10u %4u\n", | ||
| 35 | bin ? 1 << (bin - 1) : 0, 1 << bin, | ||
| 36 | sleep_time_bin[bin]); | ||
| 37 | } | ||
| 38 | return 0; | ||
| 39 | } | ||
| 40 | |||
| 41 | static int tk_debug_sleep_time_open(struct inode *inode, struct file *file) | ||
| 42 | { | ||
| 43 | return single_open(file, tk_debug_show_sleep_time, NULL); | ||
| 44 | } | ||
| 45 | |||
| 46 | static const struct file_operations tk_debug_sleep_time_fops = { | ||
| 47 | .open = tk_debug_sleep_time_open, | ||
| 48 | .read = seq_read, | ||
| 49 | .llseek = seq_lseek, | ||
| 50 | .release = single_release, | ||
| 51 | }; | ||
| 52 | |||
| 53 | static int __init tk_debug_sleep_time_init(void) | ||
| 54 | { | ||
| 55 | struct dentry *d; | ||
| 56 | |||
| 57 | d = debugfs_create_file("sleep_time", 0444, NULL, NULL, | ||
| 58 | &tk_debug_sleep_time_fops); | ||
| 59 | if (!d) { | ||
| 60 | pr_err("Failed to create sleep_time debug file\n"); | ||
| 61 | return -ENOMEM; | ||
| 62 | } | ||
| 63 | |||
| 64 | return 0; | ||
| 65 | } | ||
| 66 | late_initcall(tk_debug_sleep_time_init); | ||
| 67 | |||
| 68 | void tk_debug_account_sleep_time(struct timespec *t) | ||
| 69 | { | ||
| 70 | sleep_time_bin[fls(t->tv_sec)]++; | ||
| 71 | } | ||
| 72 | |||
diff --git a/kernel/time/timekeeping_internal.h b/kernel/time/timekeeping_internal.h new file mode 100644 index 000000000000..13323ea08ffa --- /dev/null +++ b/kernel/time/timekeeping_internal.h | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | #ifndef _TIMEKEEPING_INTERNAL_H | ||
| 2 | #define _TIMEKEEPING_INTERNAL_H | ||
| 3 | /* | ||
| 4 | * timekeeping debug functions | ||
| 5 | */ | ||
| 6 | #include <linux/time.h> | ||
| 7 | |||
| 8 | #ifdef CONFIG_DEBUG_FS | ||
| 9 | extern void tk_debug_account_sleep_time(struct timespec *t); | ||
| 10 | #else | ||
| 11 | #define tk_debug_account_sleep_time(x) | ||
| 12 | #endif | ||
| 13 | |||
| 14 | #endif /* _TIMEKEEPING_INTERNAL_H */ | ||
