public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: "linux-pm" <linux-pm@lists.linux-foundation.org>
Cc: LKML <linux-kernel@vger.kernel.org>, Len Brown <lenb@kernel.org>,
	Pavel Machek <pavel@ucw.cz>,
	Alan Stern <stern@rowland.harvard.edu>,
	ACPI Devel Maling List <linux-acpi@vger.kernel.org>,
	Arjan van de Ven <arjan@infradead.org>,
	Zhang Rui <rui.zhang@intel.com>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Linux PCI <linux-pci@vger.kernel.org>
Subject: [PATCH 9]  PM: Measure device suspend and resume times (was: Re: [PATCH 0/6] PM: Asynchronous suspend and resume of devices)
Date: Sat, 29 Aug 2009 21:22:59 +0200	[thread overview]
Message-ID: <200908292122.59398.rjw@sisk.pl> (raw)
In-Reply-To: <200908262217.19609.rjw@sisk.pl>

On Wednesday 26 August 2009, Rafael J. Wysocki wrote:
> Hi,
> 
> The following patches introduce a mechanism allowing us to execute device
> drivers' suspend and resume callbacks asynchronously during system sleep
> transitions, such as suspend to RAM.
> 
> The idea is explained in the changelogs of the first two patches.
> 
> Comments welcome.

I have one more patch that adds time measurements to the code in
drivers/base/power/main.c, so that one can easily see how much these operations
take.

Thanks,
Rafael

---
From: Rafael J. Wysocki <rjw@sisk.pl>
Subject: PM: Measure device suspend and resume times

Measure and print the time of suspending and resuming all devices.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
 drivers/base/power/main.c |   56 +++++++++++++++++++++++++++++++++++++++++++++-
 include/linux/pm.h        |    3 ++
 kernel/power/swsusp.c     |    6 ----
 3 files changed, 59 insertions(+), 6 deletions(-)

Index: linux-2.6/kernel/power/swsusp.c
===================================================================
--- linux-2.6.orig/kernel/power/swsusp.c
+++ linux-2.6/kernel/power/swsusp.c
@@ -169,14 +169,10 @@ int swsusp_swap_in_use(void)
 void swsusp_show_speed(struct timeval *start, struct timeval *stop,
 			unsigned nr_pages, char *msg)
 {
-	s64 elapsed_centisecs64;
-	int centisecs;
+	int centisecs = pm_time_elapsed(start, stop);
 	int k;
 	int kps;
 
-	elapsed_centisecs64 = timeval_to_ns(stop) - timeval_to_ns(start);
-	do_div(elapsed_centisecs64, NSEC_PER_SEC / 100);
-	centisecs = elapsed_centisecs64;
 	if (centisecs == 0)
 		centisecs = 1;	/* avoid div-by-zero */
 	k = nr_pages * (PAGE_SIZE / 1024);
Index: linux-2.6/drivers/base/power/main.c
===================================================================
--- linux-2.6.orig/drivers/base/power/main.c
+++ linux-2.6/drivers/base/power/main.c
@@ -28,6 +28,7 @@
 #include <linux/interrupt.h>
 #include <linux/async.h>
 #include <linux/completion.h>
+#include <linux/time.h>
 
 #include "../base.h"
 #include "power.h"
@@ -434,6 +435,20 @@ static bool pm_op_started(struct device 
 	return ret;
 }
 
+/**
+ * pm_time_elapsed - Compute time elapsed between two timestamps.
+ * @start: First timestamp.
+ * @stop: Second timestamp.
+ */
+int pm_time_elapsed(struct timeval *start, struct timeval *stop)
+{
+	s64 elapsed_centisecs64;
+
+	elapsed_centisecs64 = timeval_to_ns(stop) - timeval_to_ns(start);
+	do_div(elapsed_centisecs64, NSEC_PER_SEC / 100);
+	return elapsed_centisecs64;
+}
+
 static char *pm_verb(int event)
 {
 	switch (event) {
@@ -458,6 +473,16 @@ static char *pm_verb(int event)
 	}
 }
 
+static void dpm_show_time(struct timeval *start, struct timeval *stop,
+			  pm_message_t state, const char *info)
+{
+	int centisecs = pm_time_elapsed(start, stop);
+
+	printk(KERN_INFO "PM: %s%s%s of devices complete in %d.%02d seconds\n",
+		info ? info : "", info ? " " : "", pm_verb(state.event),
+		centisecs / 100, centisecs % 100);
+}
+
 static void pm_dev_dbg(struct device *dev, pm_message_t state, char *info)
 {
 	dev_dbg(dev, "%s%s%s\n", info, pm_verb(state.event),
@@ -580,6 +605,9 @@ static int device_resume_noirq(struct de
 void dpm_resume_noirq(pm_message_t state)
 {
 	struct device *dev;
+	struct timeval start, stop;
+
+	do_gettimeofday(&start);
 
 	mutex_lock(&dpm_list_mtx);
 	transition_started = false;
@@ -595,6 +623,10 @@ void dpm_resume_noirq(pm_message_t state
 		}
 	dpm_synchronize_noirq();
 	mutex_unlock(&dpm_list_mtx);
+
+	do_gettimeofday(&stop);
+	dpm_show_time(&start, &stop, state, "EARLY");
+
 	resume_device_irqs();
 }
 EXPORT_SYMBOL_GPL(dpm_resume_noirq);
@@ -740,6 +772,9 @@ static int device_resume(struct device *
 static void dpm_resume(pm_message_t state)
 {
 	struct list_head list;
+	struct timeval start, stop;
+
+	do_gettimeofday(&start);
 
 	INIT_LIST_HEAD(&list);
 	mutex_lock(&dpm_list_mtx);
@@ -770,6 +805,9 @@ static void dpm_resume(pm_message_t stat
 	list_splice(&list, &dpm_list);
 	mutex_unlock(&dpm_list_mtx);
 	dpm_synchronize();
+
+	do_gettimeofday(&stop);
+	dpm_show_time(&start, &stop, state, NULL);
 }
 
 /**
@@ -985,8 +1023,11 @@ static int device_suspend_noirq(struct d
 int dpm_suspend_noirq(pm_message_t state)
 {
 	struct device *dev;
+	struct timeval start, stop;
 	int error = 0;
 
+	do_gettimeofday(&start);
+
 	suspend_device_irqs();
 	mutex_lock(&dpm_list_mtx);
 	pm_transition = state;
@@ -1004,8 +1045,12 @@ int dpm_suspend_noirq(pm_message_t state
 	}
 	dpm_synchronize_noirq();
 	mutex_unlock(&dpm_list_mtx);
-	if (error)
+	if (error) {
 		dpm_resume_noirq(resume_event(state));
+	} else {
+		do_gettimeofday(&stop);
+		dpm_show_time(&start, &stop, state, "LATE");
+	}
 	return error;
 }
 EXPORT_SYMBOL_GPL(dpm_suspend_noirq);
@@ -1157,8 +1202,11 @@ static int device_suspend(struct device 
 static int dpm_suspend(pm_message_t state)
 {
 	struct list_head list;
+	struct timeval start, stop;
 	int error = 0;
 
+	do_gettimeofday(&start);
+
 	INIT_LIST_HEAD(&list);
 	mutex_lock(&dpm_list_mtx);
 	pm_transition = state;
@@ -1188,6 +1236,12 @@ static int dpm_suspend(pm_message_t stat
 	list_splice(&list, dpm_list.prev);
 	mutex_unlock(&dpm_list_mtx);
 	dpm_synchronize();
+
+	if (!error) {
+		do_gettimeofday(&stop);
+		dpm_show_time(&start, &stop, state, NULL);
+	}
+
 	return error;
 }
 
Index: linux-2.6/include/linux/pm.h
===================================================================
--- linux-2.6.orig/include/linux/pm.h
+++ linux-2.6/include/linux/pm.h
@@ -505,6 +505,9 @@ extern int sysdev_suspend(pm_message_t s
 extern int dpm_suspend_noirq(pm_message_t state);
 extern int dpm_suspend_start(pm_message_t state);
 
+struct timeval;
+extern int pm_time_elapsed(struct timeval *start, struct timeval *stop);
+
 extern void __suspend_report_result(const char *function, void *fn, int ret);
 
 #define suspend_report_result(fn, ret)					\

      parent reply	other threads:[~2009-08-29 19:22 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-26 20:17 [PATCH 0/6] PM: Asynchronous suspend and resume of devices Rafael J. Wysocki
2009-08-26 20:20 ` [PATCH 1/6] PM: Introduce PM links framework Rafael J. Wysocki
2009-08-28 15:16   ` Alan Stern
2009-08-28 19:11     ` Rafael J. Wysocki
2009-08-26 20:21 ` [PATCH 2/6] PM: Asynchronous resume of devices Rafael J. Wysocki
2009-08-28 15:43   ` Alan Stern
2009-08-28 19:38     ` Rafael J. Wysocki
2009-08-28 19:59       ` Alan Stern
2009-08-28 22:22         ` Rafael J. Wysocki
2009-08-28 23:20           ` Rafael J. Wysocki
2009-08-29  2:06           ` Alan Stern
2009-08-29 12:49             ` Rafael J. Wysocki
2009-08-29 19:17               ` Rafael J. Wysocki
2009-08-30  0:53                 ` Alan Stern
2009-08-30  0:48               ` Alan Stern
2009-08-30 13:15                 ` Rafael J. Wysocki
2009-08-30 21:13                   ` [PATCH 10] PM: Measure suspend and resume times for individual devices (was: Re: [PATCH 2/6] PM: Asynchronous resume of devices) Rafael J. Wysocki
2009-08-31  7:25                     ` Ingo Molnar
2009-08-31 12:53                       ` Rafael J. Wysocki
2009-08-31 13:52                         ` Ingo Molnar
2009-08-31 15:56                           ` Rafael J. Wysocki
2009-08-31 21:32                             ` [PATCH 10 update] PM: Measure suspend and resume times for individual devices Rafael J. Wysocki
2009-09-04  7:51                             ` [PATCH 10] PM: Measure suspend and resume times for individual devices (was: Re: [PATCH 2/6] PM: Asynchronous resume of devices) Ingo Molnar
2009-09-04 14:42                               ` Rafael J. Wysocki
2009-09-04 19:12                                 ` Ingo Molnar
2009-09-04 21:56                                   ` [PATCH 10 update 2x] PM: Measure suspend and resume times for individual devices Rafael J. Wysocki
2009-09-06  4:44                                     ` Ingo Molnar
2009-09-06 12:13                                       ` Rafael J. Wysocki
2009-08-31 14:09                     ` [PATCH 10] PM: Measure suspend and resume times for individual devices (was: Re: [PATCH 2/6] PM: Asynchronous resume of devices) Alan Stern
2009-08-31 16:00                       ` Rafael J. Wysocki
2009-08-30  6:45               ` [PATCH 2/6] PM: Asynchronous resume of devices Pavel Machek
2009-08-30 13:09                 ` Rafael J. Wysocki
2009-08-26 20:21 ` [PATCH 3/6] PM: Asynchronous suspend " Rafael J. Wysocki
2009-08-26 20:22 ` [PATCH 4/6] PM: Allow PCI devices to suspend/resume asynchronously Rafael J. Wysocki
2009-08-26 20:23 ` [PATCH 5/6] PM: Allow ACPI " Rafael J. Wysocki
2009-08-26 20:24 ` [PATCH 6/6] PM: Allow serio input " Rafael J. Wysocki
2009-08-27 20:08   ` Dmitry Torokhov
2009-08-27 20:58     ` Rafael J. Wysocki
2009-08-26 22:25 ` [PATCH 0/6] PM: Asynchronous suspend and resume of devices Rafael J. Wysocki
2009-08-27 19:17   ` Rafael J. Wysocki
2009-08-27 19:19     ` [PATCH 7] PM: Add a switch for disabling/enabling asynchronous suspend/resume Rafael J. Wysocki
2009-08-27 20:07       ` Dmitry Torokhov
2009-08-27 22:22         ` [PATCH 7 updated] " Rafael J. Wysocki
2009-08-28  5:22           ` Dmitry Torokhov
2009-08-28 19:42             ` Rafael J. Wysocki
2009-08-27 19:20     ` [PATCH 8] PM: Allow user space to change the power.async_suspend flag of devices Rafael J. Wysocki
2009-08-27 20:04       ` Dmitry Torokhov
2009-08-27 22:24         ` Rafael J. Wysocki
2009-08-28  7:01           ` Pavel Machek
2009-08-29 19:20             ` [PATCH 8 update] " Rafael J. Wysocki
2009-08-27 20:46 ` [PATCH 0/6] PM: Asynchronous suspend and resume " Alan Stern
2009-08-27 21:18   ` Rafael J. Wysocki
2009-08-29 19:22 ` Rafael J. Wysocki [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200908292122.59398.rjw@sisk.pl \
    --to=rjw@sisk.pl \
    --cc=arjan@infradead.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-pm@lists.linux-foundation.org \
    --cc=pavel@ucw.cz \
    --cc=rui.zhang@intel.com \
    --cc=stern@rowland.harvard.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox