From patchwork Tue Apr 30 22:28:34 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zoran Markovic X-Patchwork-Id: 2506461 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 61706DFB75 for ; Tue, 30 Apr 2013 22:29:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933784Ab3D3W3x (ORCPT ); Tue, 30 Apr 2013 18:29:53 -0400 Received: from mail-pd0-f182.google.com ([209.85.192.182]:54462 "EHLO mail-pd0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933732Ab3D3W3w (ORCPT ); Tue, 30 Apr 2013 18:29:52 -0400 Received: by mail-pd0-f182.google.com with SMTP id 14so543671pdj.41 for ; Tue, 30 Apr 2013 15:29:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=c9HV73Lz7huxVr6jd6C1jaJChZCoX7F40r5Xoy9ii0w=; b=fAup1HxJ7g6FleFtYR8b+uTZworSfaKPYwGA38Vy9JBCOQgA5qtQ8M7vKV/Ew10kP6 NqK1iL+mWptzjAyMyS2Fj8LOyzodahDd4IwQwHov2dyyyyHcl6O7VIiraQH/QMWRQ+Kc 41TQkAuI6MsWcFI9YHLXk0RpECoK1EQxV8Pua+GgiIUkj+YabJV1j37anssrLnDGJyNL x9dDMqpTewh5FJX5v085mUE0styqjLuGPCutFwy/vRURNVPbLClY2/Ky/x+xi1hB6Y/U idfpFtIy7t8c31m8n9ccblLOXriINHPeXhMai99IVJmCgJK007lZqM89Z5HQcYjCYZIU OXSA== X-Received: by 10.68.244.38 with SMTP id xd6mr401089pbc.131.1367360991516; Tue, 30 Apr 2013 15:29:51 -0700 (PDT) Received: from vb-linaro.ric.broadcom.com ([216.31.219.19]) by mx.google.com with ESMTPSA id at4sm257750pbc.40.2013.04.30.15.29.49 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 30 Apr 2013 15:29:50 -0700 (PDT) From: Zoran Markovic To: linux-kernel@vger.kernel.org Cc: linux-pm@vger.kernel.org, Colin Cross , Android Kernel Team , Todd Poynor , San Mehat , Benoit Goby , John Stultz , Pavel Machek , "Rafael J. Wysocki" , Len Brown , Zoran Markovic Subject: [RFC PATCH] power: Add option to log time spent in suspend Date: Tue, 30 Apr 2013 15:28:34 -0700 Message-Id: <1367360914-23389-2-git-send-email-zoran.markovic@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1367360914-23389-1-git-send-email-zoran.markovic@linaro.org> References: <1367360914-23389-1-git-send-email-zoran.markovic@linaro.org> X-Gm-Message-State: ALoCoQnNvnfbGX5pAY/zx5EBV8F8JU6AB09U0CgW0L+Lctw5C1RWP5hKZ5UQZyjbXyoQI1UfxbvS Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Colin Cross Below is a patch from android kernel that maintains a histogram of suspend times. Please review and provide feedback. Prints the time spent in suspend in the kernel log, and keeps statistics on the time spent in suspend in /sys/kernel/debug/suspend_time Cc: Android Kernel Team Cc: Colin Cross Cc: Todd Poynor Cc: San Mehat Cc: Benoit Goby Cc: John Stultz Cc: Pavel Machek Cc: Rafael J. Wysocki Cc: Len Brown Signed-off-by: Colin Cross Signed-off-by: Todd Poynor [zoran.markovic@linaro.org: Re-formatted suspend time table to better fit expected values, tweaked commit message] Signed-off-by: Zoran Markovic --- kernel/power/Kconfig | 7 +++ kernel/power/Makefile | 1 + kernel/power/suspend_time.c | 111 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 kernel/power/suspend_time.c diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig index 5dfdc9e..edc8bdd 100644 --- a/kernel/power/Kconfig +++ b/kernel/power/Kconfig @@ -274,3 +274,10 @@ config PM_GENERIC_DOMAINS_RUNTIME config CPU_PM bool depends on SUSPEND || CPU_IDLE + +config SUSPEND_TIME + bool "Log time spent in suspend" + ---help--- + Prints the time spent in suspend in the kernel log, and + keeps statistics on the time spent in suspend in + /sys/kernel/debug/suspend_time diff --git a/kernel/power/Makefile b/kernel/power/Makefile index 29472bf..578e20e 100644 --- a/kernel/power/Makefile +++ b/kernel/power/Makefile @@ -11,5 +11,6 @@ obj-$(CONFIG_HIBERNATION) += hibernate.o snapshot.o swap.o user.o \ block_io.o obj-$(CONFIG_PM_AUTOSLEEP) += autosleep.o obj-$(CONFIG_PM_WAKELOCKS) += wakelock.o +obj-$(CONFIG_SUSPEND_TIME) += suspend_time.o obj-$(CONFIG_MAGIC_SYSRQ) += poweroff.o diff --git a/kernel/power/suspend_time.c b/kernel/power/suspend_time.c new file mode 100644 index 0000000..a613ede --- /dev/null +++ b/kernel/power/suspend_time.c @@ -0,0 +1,111 @@ +/* + * debugfs file to track time spent in suspend + * + * Copyright (c) 2011, Google, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + */ + +#include +#include +#include +#include +#include +#include +#include + +static struct timespec suspend_time_before; +static unsigned int time_in_suspend_bins[32]; + +#ifdef CONFIG_DEBUG_FS +static int suspend_time_debug_show(struct seq_file *s, void *data) +{ + unsigned int bin; + seq_printf(s, " time (secs) count\n"); + seq_printf(s, "------------------------------\n"); + for (bin = 0; bin < 32; bin++) { + if (time_in_suspend_bins[bin] == 0) + continue; + seq_printf(s, "%10u - %-10u %4u\n", + bin ? 1 << (bin - 1) : 0, 1 << bin, + time_in_suspend_bins[bin]); + } + return 0; +} + +static int suspend_time_debug_open(struct inode *inode, struct file *file) +{ + return single_open(file, suspend_time_debug_show, NULL); +} + +static const struct file_operations suspend_time_debug_fops = { + .open = suspend_time_debug_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static int __init suspend_time_debug_init(void) +{ + struct dentry *d; + + d = debugfs_create_file("suspend_time", 0444, NULL, NULL, + &suspend_time_debug_fops); + if (!d) { + pr_err("Failed to create suspend_time debug file\n"); + return -ENOMEM; + } + + return 0; +} + +late_initcall(suspend_time_debug_init); +#endif + +static int suspend_time_syscore_suspend(void) +{ + read_persistent_clock(&suspend_time_before); + + return 0; +} + +static void suspend_time_syscore_resume(void) +{ + struct timespec after; + + read_persistent_clock(&after); + + after = timespec_sub(after, suspend_time_before); + + time_in_suspend_bins[fls(after.tv_sec)]++; + + pr_info("Suspended for %lu.%03lu seconds\n", after.tv_sec, + after.tv_nsec / NSEC_PER_MSEC); +} + +static struct syscore_ops suspend_time_syscore_ops = { + .suspend = suspend_time_syscore_suspend, + .resume = suspend_time_syscore_resume, +}; + +static int suspend_time_syscore_init(void) +{ + register_syscore_ops(&suspend_time_syscore_ops); + + return 0; +} + +static void suspend_time_syscore_exit(void) +{ + unregister_syscore_ops(&suspend_time_syscore_ops); +} +module_init(suspend_time_syscore_init); +module_exit(suspend_time_syscore_exit);