LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [RFC] [PATCH] Power S3 Resume Optimization Patch. Request for Comment
@ 2007-01-19  8:08 Seshadri, Harinarayanan
  2007-01-19  9:29 ` Pavel Machek
  0 siblings, 1 reply; 4+ messages in thread
From: Seshadri, Harinarayanan @ 2007-01-19  8:08 UTC (permalink / raw)
  To: inux-pm; +Cc: linux-acpi, linux-kernel, Seshadri, Harinarayanan

[-- Attachment #1: Type: text/plain, Size: 4341 bytes --]

[RFC][PATCH] Power S3 Resume optimisation 
	Here is a simple patch for optimising the S3 resume. With this
patch the resume time is 0.85. Given the fact that device initialisation
on the resume takes almost 70% of time, By executing the whole
"device_resume()" function on a seperate kernel thread, the resume gets
completed( ie. the user can precieve) by ~0.85 sec.
	To avoid any possible race condition while processing the IO
request and to make sure all the io request are queued till the device
resume thread exits, the IO schedulars (patched cfq and as) checks a for
system_resume flag, which is set when the device resume thread starts,
if the flag is set, it doesnt put the request in the dispatch queue.
Once the flag is cleared i.e when the device resume thread is complete,
the IO-schedular behave as in normal situation.
 I did some validation of this patch on a  NAPA board ( Calistoga
chipset with Dothan Processor with and Without SMP)locally here and
havent noticed any issue so far.  Please review and let me know what
your comments. This patch is against 2.6.18 kernel
thanks
-hari
signed-off-by: hari < harinarayanan.seshadri@intel.com>
-----------------------------------
diff -ruN ../test/linux-vanilla/block/as-iosched.c
linux-2.6.18/block/as-iosched.c---
../test/linux-vanilla/block/as-iosched.c    2007-01-10
13:51:33.000000000 +0530
+++ linux-2.6.18/block/as-iosched.c     2007-01-18 13:37:01.000000000
+0530
@@ -1088,6 +1088,19 @@
        if (list_empty(&ad->fifo_list[adir]))
                return 0;

+       /*
+        * Check here for the System resume flag to be cleared, if flag
is
+       *  still set the resume thread hasnt completed yet, and hence
dont
+       *  takeout any new request from the FIFO
+       */
+       extern int system_resuming;
+       if (system_resuming != 0)
+       {
+#ifdef DEBUG
+               printk("  system resuming still \n");
+#endif
+               return 0;
+       }
        arq = list_entry_fifo(ad->fifo_list[adir].next);

        return time_after(jiffies, arq->expires);
diff -ruN ../test/linux-vanilla/block/cfq-iosched.c
linux-2.6.18/block/cfq-iosched.c
--- ../test/linux-vanilla/block/cfq-iosched.c   2007-01-11
07:59:33.000000000 +0530
+++ linux-2.6.18/block/cfq-iosched.c    2007-01-18 13:35:02.000000000
+0530
@@ -1156,6 +1156,19 @@
        if (!cfqd->busy_queues)
                return 0;

+       /*
+        * Check here for the System resume flag to be cleared, if flag
is s
+       *  still set the resume thread hasnt completed yet, and hence
dont
+       *  move any request from the read/write to dispatch queue
+       */
+       extern int system_resuming;
+       if (system_resuming != 0)
+       {
+#ifdef DEBUG
+               printk("System resuming still \n");
+#endif
+               return 0;
+       }
        if (unlikely(force))
                return cfq_forced_dispatch(cfqd);

diff -ruN ../test/linux-vanilla/kernel/power/main.c
linux-2.6.18/kernel/power/main.c
--- ../test/linux-vanilla/kernel/power/main.c   2007-01-11
08:00:11.000000000 +0530
+++ linux-2.6.18/kernel/power/main.c    2007-01-18 13:31:56.000000000
+0530
@@ -19,6 +19,7 @@

 #include "power.h"

+int system_resuming;
 /*This is just an arbitrary number */
 #define FREE_PAGE_NUMBER (100)

@@ -131,9 +132,29 @@
  *     console that we've allocated. This is not called for
suspend-to-disk.
  */

-static void suspend_finish(suspend_state_t state)
+static int dev_resume_proc(void * data)
{
+       /* Set the global resume flag, this will be checked by the
IO_schedular
+       * before dispatching the IO request
+       */
+       system_resuming =1;
        device_resume();
+       system_resuming = 0;
+#ifdef DEBUG
+       printk(" reseting system_resume \n");
+#endif
+       return (0);
+}
+static void suspend_finish(suspend_state_t state)
+{
+       int thread;
+       system_resuming = 0;
+       thread = kernel_thread(dev_resume_proc,NULL,CLONE_KERNEL);
+       if (thread < 0)
+       {
+               printk ("Suspend resume Cannot create Kernel_thread\n");
+               device_resume();
+       }
        resume_console();
        thaw_processes();
        enable_nonboot_cpus();
--------------------------------------

[-- Attachment #2: s3.patch.new --]
[-- Type: application/octet-stream, Size: 2618 bytes --]

diff -ruN ../test/linux-vanilla/block/as-iosched.c linux-2.6.18/block/as-iosched.c
--- ../test/linux-vanilla/block/as-iosched.c	2007-01-10 13:51:33.000000000 +0530
+++ linux-2.6.18/block/as-iosched.c	2007-01-18 13:37:01.000000000 +0530
@@ -1088,6 +1088,19 @@
 	if (list_empty(&ad->fifo_list[adir]))
 		return 0;
 
+	/*
+	 * Check here for the System resume flag to be cleared, if flag is 
+	*  still set the resume thread hasnt completed yet, and hence dont
+	*  takeout any new request from the FIFO
+	*/
+	extern int system_resuming;
+	if (system_resuming != 0)
+	{
+#ifdef DEBUG
+		printk("  system resuming still \n");
+#endif
+		return 0;
+	}
 	arq = list_entry_fifo(ad->fifo_list[adir].next);
 
 	return time_after(jiffies, arq->expires);
diff -ruN ../test/linux-vanilla/block/cfq-iosched.c linux-2.6.18/block/cfq-iosched.c
--- ../test/linux-vanilla/block/cfq-iosched.c	2007-01-11 07:59:33.000000000 +0530
+++ linux-2.6.18/block/cfq-iosched.c	2007-01-18 13:35:02.000000000 +0530
@@ -1156,6 +1156,19 @@
 	if (!cfqd->busy_queues)
 		return 0;
 
+	/*
+	 * Check here for the System resume flag to be cleared, if flag is s
+	*  still set the resume thread hasnt completed yet, and hence dont
+	*  move any request from the read/write to dispatch queue
+	*/
+	extern int system_resuming;
+	if (system_resuming != 0)
+	{
+#ifdef DEBUG
+		printk("System resuming still \n");
+#endif
+		return 0;
+	}
 	if (unlikely(force))
 		return cfq_forced_dispatch(cfqd);
 
diff -ruN ../test/linux-vanilla/kernel/power/main.c linux-2.6.18/kernel/power/main.c
--- ../test/linux-vanilla/kernel/power/main.c	2007-01-11 08:00:11.000000000 +0530
+++ linux-2.6.18/kernel/power/main.c	2007-01-18 13:31:56.000000000 +0530
@@ -19,6 +19,7 @@
 
 #include "power.h"
 
+int system_resuming;
 /*This is just an arbitrary number */
 #define FREE_PAGE_NUMBER (100)
 
@@ -131,9 +132,29 @@
  *	console that we've allocated. This is not called for suspend-to-disk.
  */
 
-static void suspend_finish(suspend_state_t state)
+static int dev_resume_proc(void * data)
 {
+	/* Set the global resume flag, this will be checked by the IO_schedular
+	* before dispatching the IO request
+	*/
+	system_resuming =1;
 	device_resume();
+	system_resuming = 0;
+#ifdef DEBUG
+	printk(" reseting system_resume \n");
+#endif
+	return (0);
+}
+static void suspend_finish(suspend_state_t state)
+{
+	int thread;
+	system_resuming = 0;
+	thread = kernel_thread(dev_resume_proc,NULL,CLONE_KERNEL);
+	if (thread < 0)
+	{
+		printk ("Suspend resume Cannot create Kernel_thread\n");
+		device_resume();
+	}
 	resume_console();
 	thaw_processes();
 	enable_nonboot_cpus();

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFC] [PATCH] Power S3 Resume Optimization Patch. Request for Comment
  2007-01-19  8:08 [RFC] [PATCH] Power S3 Resume Optimization Patch. Request for Comment Seshadri, Harinarayanan
@ 2007-01-19  9:29 ` Pavel Machek
  2007-01-22  3:55   ` Seshadri, Harinarayanan
  0 siblings, 1 reply; 4+ messages in thread
From: Pavel Machek @ 2007-01-19  9:29 UTC (permalink / raw)
  To: Seshadri, Harinarayanan; +Cc: inux-pm, linux-acpi, linux-kernel

Hi!

> [RFC][PATCH] Power S3 Resume optimisation 
> 	Here is a simple patch for optimising the S3 resume. With this
> patch the resume time is 0.85. Given the fact that device initialisation
> on the resume takes almost 70% of time, By executing the whole
> "device_resume()" function on a seperate kernel thread, the resume gets
> completed( ie. the user can precieve) by ~0.85 sec.

Yep, but you also break it completely...

> 	To avoid any possible race condition while processing the IO
> request and to make sure all the io request are queued till the device
> resume thread exits, the IO schedulars (patched cfq and as) checks a for
> system_resume flag, which is set when the device resume thread starts,
> if the flag is set, it doesnt put the request in the dispatch queue.
> Once the flag is cleared i.e when the device resume thread is complete,
> the IO-schedular behave as in normal situation.

And you noticed that, so you fixed obvious problems on block devices.
Ignoring char and net devices completely.


> @@ -1088,6 +1088,19 @@
>         if (list_empty(&ad->fifo_list[adir]))
>                 return 0;
> 
> +       /*
> +        * Check here for the System resume flag to be cleared, if flag
> is
> +       *  still set the resume thread hasnt completed yet, and hence
> dont
> +       *  takeout any new request from the FIFO
> +       */
> +       extern int system_resuming;
> +       if (system_resuming != 0)
> +       {

Locking. CodingStyle.

> -static void suspend_finish(suspend_state_t state)
> +static int dev_resume_proc(void * data)
> {
> +       /* Set the global resume flag, this will be checked by the
> IO_schedular

Broken mail client.

> +       * before dispatching the IO request
> +       */
> +       system_resuming =1;

Add mdelay(1 hour) here. Then try to use your wifi card and your tv
grabber.

>         device_resume();
> +       system_resuming = 0;
> +#ifdef DEBUG
> +       printk(" reseting system_resume \n");
> +#endif

							Pavel

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [RFC] [PATCH] Power S3 Resume Optimization Patch. Request for Comment
  2007-01-19  9:29 ` Pavel Machek
@ 2007-01-22  3:55   ` Seshadri, Harinarayanan
  2007-01-22 12:51     ` Pavel Machek
  0 siblings, 1 reply; 4+ messages in thread
From: Seshadri, Harinarayanan @ 2007-01-22  3:55 UTC (permalink / raw)
  To: Pavel Machek; +Cc: inux-pm, linux-acpi, linux-kernel, Seshadri, Harinarayanan

My initial idea was to execute only block device resume on the separate
thread, as it take almost 80% of the total device resume time ( I did
detailed profile of each device resume through rdtsc() counter) and rest
of them takes less than 20% in total( each device ( including char and
net)on its own takes less than 0.03 seconds). I could still save some
good amount of resume time ( apprx 1.2 sec). However Given this ratio,
and the fact that block device resume happening way at the end of the
list, I tried this with only taking care of Block devices. 
	I am not sure if there is a case where any scenario where Char
devices would take more resume time than normally it would. If so I can
modify the patch to put only block devices in separate thread for resume
Thanks
-hari
-----Original Message-----
From: Pavel Machek [mailto:pavel@ucw.cz] 
Sent: Friday, January 19, 2007 3:00 PM
To: Seshadri, Harinarayanan
Cc: inux-pm@lists.osdl.org; linux-acpi@vger.kernel.org;
linux-kernel@vger.kernel.org
Subject: Re: [RFC] [PATCH] Power S3 Resume Optimization Patch. Request
for Comment

Hi!

> [RFC][PATCH] Power S3 Resume optimisation 
> 	Here is a simple patch for optimising the S3 resume. With this
> patch the resume time is 0.85. Given the fact that device
initialisation
> on the resume takes almost 70% of time, By executing the whole
> "device_resume()" function on a seperate kernel thread, the resume
gets
> completed( ie. the user can precieve) by ~0.85 sec.

Yep, but you also break it completely...

> 	To avoid any possible race condition while processing the IO
> request and to make sure all the io request are queued till the device
> resume thread exits, the IO schedulars (patched cfq and as) checks a
for
> system_resume flag, which is set when the device resume thread starts,
> if the flag is set, it doesnt put the request in the dispatch queue.
> Once the flag is cleared i.e when the device resume thread is
complete,
> the IO-schedular behave as in normal situation.

And you noticed that, so you fixed obvious problems on block devices.
Ignoring char and net devices completely.


> @@ -1088,6 +1088,19 @@
>         if (list_empty(&ad->fifo_list[adir]))
>                 return 0;
> 
> +       /*
> +        * Check here for the System resume flag to be cleared, if
flag
> is
> +       *  still set the resume thread hasnt completed yet, and hence
> dont
> +       *  takeout any new request from the FIFO
> +       */
> +       extern int system_resuming;
> +       if (system_resuming != 0)
> +       {

Locking. CodingStyle.

> -static void suspend_finish(suspend_state_t state)
> +static int dev_resume_proc(void * data)
> {
> +       /* Set the global resume flag, this will be checked by the
> IO_schedular

Broken mail client.

> +       * before dispatching the IO request
> +       */
> +       system_resuming =1;

Add mdelay(1 hour) here. Then try to use your wifi card and your tv
grabber.

>         device_resume();
> +       system_resuming = 0;
> +#ifdef DEBUG
> +       printk(" reseting system_resume \n");
> +#endif

							Pavel

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures)
http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFC] [PATCH] Power S3 Resume Optimization Patch. Request for Comment
  2007-01-22  3:55   ` Seshadri, Harinarayanan
@ 2007-01-22 12:51     ` Pavel Machek
  0 siblings, 0 replies; 4+ messages in thread
From: Pavel Machek @ 2007-01-22 12:51 UTC (permalink / raw)
  To: Seshadri, Harinarayanan; +Cc: linux-pm, linux-acpi, linux-kernel

Hi!

> My initial idea was to execute only block device resume on the separate
> thread, as it take almost 80% of the total device resume time ( I did

If you do this in one block driver that is slow for you (sata?), then it is
probably acceptable. (Maintainer decides.) I'd encourage that option.

If you want to do it for _all_ block devices, you'll probably have to
audit all of them. _Lot_ of work.
							Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-01-22 12:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-19  8:08 [RFC] [PATCH] Power S3 Resume Optimization Patch. Request for Comment Seshadri, Harinarayanan
2007-01-19  9:29 ` Pavel Machek
2007-01-22  3:55   ` Seshadri, Harinarayanan
2007-01-22 12:51     ` Pavel Machek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).