public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Pavel Machek <pavel@ucw.cz>
Cc: suspend-devel@lists.sourceforge.net,
	pm list <linux-pm@lists.osdl.org>,
	Stephen Hemminger <shemminger@osdl.org>
Subject: Re: [PATCH -mm 1/2]: PM: Fix handling of stopped tasks
Date: Tue, 5 Dec 2006 22:26:09 +0100	[thread overview]
Message-ID: <200612052226.10540.rjw@sisk.pl> (raw)
In-Reply-To: <200612052203.43977.rjw@sisk.pl>

On Tuesday, 5 December 2006 22:03, Rafael J. Wysocki wrote:
> Okay, I have replaced my [1/2] with the patch below ...
> 
> On Tuesday, 5 December 2006 11:34, Pavel Machek wrote:
<--snip--> 
> ... and it fails to freeze processes if there's a stopped task (to verify,
> run vi, press ^Z, and try to suspend).
> 
> It happens because we shouldn't count the stopped task as freezeable any
> more after we've set PF_FREEZE for it and we can fix that by adding
> 
> 	if (p->state == TASK_STOPPED && freezing(p))
> 		continue;
> 
> to the main loop in try_to_freeze_tasks().  Then we obtain the appended patch.
> 
> <tests again>
> 
> Now the stopped task doesn't prevent us from freezing processes.  So far so
> good.

Unfortunately, after the resume the task that was stopped before the suspend
goes to the refrigerator as soon as it receives the continuation signal (to verify,
run vi, press ^Z, suspend, resume, type fg and look at the output of ps ax -
on another terminal, becase this one will be unuseable ;-)).

Hm.  It looks like we have to clear the freezing request for the stopped task
before we thaw the other processes, but there may be more stopped tasks,
so we need to add something like this:

	read_lock(&tasklist_lock);
	do_each_thread(g, p) {
		if (p->state == TASK_STOPPED && freezing(p))
			cancel_freezing(p);
	} while_each_thread(g, p);
	read_unlock(&tasklist_lock);

to thaw_processes().  It's cleaner to add it as an inline function, though,
and once we've done it, we get the appended patch.

<tests again>

Well, now the task that was stopped before the suspend doesn't go to the
refrigerator when it's received the continuation signal after the resume.
Good, but is it sufficient?  [To be continued.]


Index: linux-2.6.19-rc6-mm2/kernel/power/process.c
===================================================================
--- linux-2.6.19-rc6-mm2.orig/kernel/power/process.c	2006-12-05 21:10:00.000000000 +0100
+++ linux-2.6.19-rc6-mm2/kernel/power/process.c	2006-12-05 22:28:56.000000000 +0100
@@ -28,8 +28,7 @@ static inline int freezeable(struct task
 	if ((p == current) || 
 	    (p->flags & PF_NOFREEZE) ||
 	    (p->exit_state == EXIT_ZOMBIE) ||
-	    (p->exit_state == EXIT_DEAD) ||
-	    (p->state == TASK_STOPPED))
+	    (p->exit_state == EXIT_DEAD))
 		return 0;
 	return 1;
 }
@@ -103,6 +102,9 @@ static unsigned int try_to_freeze_tasks(
 			if (frozen(p))
 				continue;
 
+			if (p->state == TASK_STOPPED && freezing(p))
+				continue;
+
 			if (p->state == TASK_TRACED &&
 			    (frozen(p->parent) ||
 			     p->parent->state == TASK_STOPPED)) {
@@ -185,6 +187,18 @@ int freeze_processes(void)
 	return 0;
 }
 
+static inline void release_stopped_tasks(void)
+{
+	struct task_struct *g, *p;
+
+	read_lock(&tasklist_lock);
+	do_each_thread(g, p) {
+		if (p->state == TASK_STOPPED && freezing(p))
+			cancel_freezing(p);
+	} while_each_thread(g, p);
+	read_unlock(&tasklist_lock);
+}
+
 static void thaw_tasks(int thaw_user_space)
 {
 	struct task_struct *g, *p;
@@ -207,6 +221,7 @@ static void thaw_tasks(int thaw_user_spa
 void thaw_processes(void)
 {
 	printk("Restarting tasks ... ");
+	release_stopped_tasks();
 	thaw_tasks(FREEZER_KERNEL_THREADS);
 	thaw_tasks(FREEZER_USER_SPACE);
 	schedule();
Index: linux-2.6.19-rc6-mm2/kernel/signal.c
===================================================================
--- linux-2.6.19-rc6-mm2.orig/kernel/signal.c	2006-12-05 21:10:00.000000000 +0100
+++ linux-2.6.19-rc6-mm2/kernel/signal.c	2006-12-05 21:11:31.000000000 +0100
@@ -1829,7 +1829,9 @@ finish_stop(int stop_count)
 		read_unlock(&tasklist_lock);
 	}
 
-	schedule();
+	do {
+		schedule();
+	} while (try_to_freeze());
 	/*
 	 * Now we don't run again until continued.
 	 */

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

  reply	other threads:[~2006-12-05 21:26 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-03 22:18 [PATCH -mm 0/2]: SMP-safe freezer Rafael J. Wysocki
2006-12-03 22:50 ` [PATCH -mm 1/2]: PM: Fix handling of stopped tasks Rafael J. Wysocki
2006-12-05 10:25   ` Pavel Machek
2006-12-05 10:34   ` Pavel Machek
2006-12-05 11:06     ` Rafael J. Wysocki
2006-12-05 14:13       ` Pavel Machek
2006-12-05 14:22         ` Rafael J. Wysocki
2006-12-05 11:24     ` Pavel Machek
2006-12-05 11:38       ` Rafael J. Wysocki
2006-12-05 14:12         ` Pavel Machek
2006-12-05 14:26           ` Rafael J. Wysocki
2006-12-05 14:33             ` Rafael J. Wysocki
2006-12-05 15:27             ` Pavel Machek
2006-12-05 17:22               ` Rafael J. Wysocki
2006-12-05 21:03     ` Rafael J. Wysocki
2006-12-05 21:26       ` Rafael J. Wysocki [this message]
2006-12-05 21:42         ` [Suspend-devel] " Rafael J. Wysocki
2006-12-05 22:19       ` Pavel Machek
2006-12-05 22:18         ` Rafael J. Wysocki
2006-12-06  0:07           ` [linux-pm] " Nigel Cunningham
2006-12-05 22:36       ` Pavel Machek
2006-12-05 22:45         ` Rafael J. Wysocki
2006-12-05 23:08           ` Rafael J. Wysocki
2006-12-05 23:45             ` Pavel Machek
2006-12-06  0:02               ` [Suspend-devel] " Nigel Cunningham
2006-12-06 23:13               ` Rafael J. Wysocki
2006-12-08 11:21                 ` Pavel Machek
2006-12-08 11:49                   ` Rafael J. Wysocki
2006-12-08 13:05                     ` Rafael J. Wysocki
2006-12-08 22:07                     ` Rafael J. Wysocki
2006-12-08 23:36                       ` Pavel Machek
2006-12-09 15:35                         ` Rafael J. Wysocki
2006-12-10  0:27                           ` Rafael J. Wysocki
2006-12-10 10:45                             ` Rafael J. Wysocki
2006-12-10 20:00                               ` Pavel Machek
2006-12-10 11:26                     ` Rafael J. Wysocki
2006-12-03 23:10 ` [PATCH -mm 2/2]: PM: SMP-safe freezer Rafael J. Wysocki
2006-12-04 10:30   ` Pavel Machek
2006-12-04 14:03     ` Rafael J. Wysocki
2006-12-04 19:44       ` Pavel Machek
2006-12-04 19:56         ` Rafael J. Wysocki
2006-12-05  5:43         ` [linux-pm] " David Brownell
2006-12-05 11:14           ` [Suspend-devel] " Rafael J. Wysocki

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=200612052226.10540.rjw@sisk.pl \
    --to=rjw@sisk.pl \
    --cc=linux-pm@lists.osdl.org \
    --cc=pavel@ucw.cz \
    --cc=shemminger@osdl.org \
    --cc=suspend-devel@lists.sourceforge.net \
    /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