linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PM] Fix up refrigerator to work with ^Z-ed processes
@ 2003-07-26 22:51 Pavel Machek
  2003-08-05  0:58 ` Patrick Mochel
  0 siblings, 1 reply; 3+ messages in thread
From: Pavel Machek @ 2003-07-26 22:51 UTC (permalink / raw)
  To: kernel list, Patrick Mochel

Hi!

This makes refrigerator work with ^Z-ed processes (and not eat
disks). Thanks to (have to find out who, I should sleep and not be
splitting patches). [Hand edited, apply by hand; or there should be
script for recomputing @@ X,Y Z,T @@'s somewhere].

schedule() added makes processes start at exactly that point, making
printouts nicer.

									Pavel

Index: linux/kernel/suspend.c
===================================================================
--- linux.orig/kernel/suspend.c	2003-07-22 13:39:43.000000000 +0200
+++ linux/kernel/suspend.c	2003-07-22 13:46:26.000000000 +0200
@@ 1,-1 1,-1 @@ 
 /*
  * Refrigerator and related stuff
  */
 
-#define INTERESTING(p) \
-			/* We don't want to touch kernel_threads..*/ \
-			if (p->flags & PF_IOTHREAD) \
-				continue; \
-			if (p == current) \
-				continue; \
-			if (p->state == TASK_ZOMBIE) \
-				continue;
+/* 0 = Ignore this process when freezing/thawing, 1 = freeze/thaw this process */
+static inline int interesting_process(struct task_struct *p)
+{
+	if (p->flags & PF_IOTHREAD)
+		return 0;
+	if (p == current)
+		return 0;
+	if ((p->state == TASK_ZOMBIE) || (p->state == TASK_DEAD))
+		return 0;
+
+	return 1;
+}
+
+#define TIMEOUT	(6 * HZ)			/* Timeout for stopping processes */
 
 /* Refrigerator is place where frozen processes are stored :-). */
 void refrigerator(unsigned long flag)
@@ -212,9 +218,12 @@
 		read_lock(&tasklist_lock);
 		do_each_thread(g, p) {
 			unsigned long flags;
-			INTERESTING(p);
+			if (!interesting_process(p))
+				continue;
 			if (p->flags & PF_FROZEN)
 				continue;
+			if (p->state == TASK_STOPPED)
+				continue;
 
 			/* FIXME: smp problem here: we may not access other process' flags
 			   without locking */
@@ -245,19 +254,56 @@
 	printk( "Restarting tasks..." );
 	read_lock(&tasklist_lock);
 	do_each_thread(g, p) {
-		INTERESTING(p);
-		
-		if (p->flags & PF_FROZEN) p->flags &= ~PF_FROZEN;
-		else
-			printk(KERN_INFO " Strange, %s not stopped\n", p->comm );
-		wake_up_process(p);
+ 		if (!interesting_process(p))
+			continue;
+ 		if (p->flags & PF_FROZEN) {
+ 			p->flags &= ~PF_FROZEN;
+ 			wake_up_process(p);
+ 		} else
+ 			PRINTK(KERN_INFO " Strange, %s not frozen\n", p->comm );
 	} while_each_thread(g, p);
 
 	read_unlock(&tasklist_lock);
+	schedule();
 	printk( " done\n" );
 	MDELAY(500);
 }



-- 
When do you have a heart between your knees?
[Johanka's followup: and *two* hearts?]

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

* Re: [PM] Fix up refrigerator to work with ^Z-ed processes
  2003-07-26 22:51 [PM] Fix up refrigerator to work with ^Z-ed processes Pavel Machek
@ 2003-08-05  0:58 ` Patrick Mochel
  2003-08-05  9:14   ` Pavel Machek
  0 siblings, 1 reply; 3+ messages in thread
From: Patrick Mochel @ 2003-08-05  0:58 UTC (permalink / raw)
  To: Pavel Machek; +Cc: kernel list



> This makes refrigerator work with ^Z-ed processes (and not eat
> disks). Thanks to (have to find out who, I should sleep and not be
> splitting patches). [Hand edited, apply by hand; or there should be
> script for recomputing @@ X,Y Z,T @@'s somewhere].
> 
> schedule() added makes processes start at exactly that point, making
> printouts nicer.

This didn't apply, so in making the changes by hand, I took the liberty to 
rename interesting_process() to freezeable() to make it a bit easier to 
read. Revised patch below. 


	-pat

ChangeSet 1.1516, 2003/08/04 16:08:22-07:00, mochel@osdl.org

[power] Fix up refrigerator to work with ^Z-ed processes

Originally from Pavel Machek: 

schedule() added makes processes start at exactly that point, making
printouts nicer.


 kernel/power/process.c |   35 +++++++++++++++++++++--------------
 1 files changed, 21 insertions(+), 14 deletions(-)


diff -Nru a/kernel/power/process.c b/kernel/power/process.c
--- a/kernel/power/process.c	Mon Aug  4 17:45:10 2003
+++ b/kernel/power/process.c	Mon Aug  4 17:45:10 2003
@@ -23,14 +23,16 @@
  */
 #define TIMEOUT	(6 * HZ)
 
-#define INTERESTING(p) \
-			/* We don't want to touch kernel_threads..*/ \
-			if (p->flags & PF_IOTHREAD) \
-				continue; \
-			if (p == current) \
-				continue; \
-			if (p->state == TASK_ZOMBIE) \
-				continue;
+
+static inline int freezeable(struct task_struct * p)
+{
+	if ((p == current) || 
+	    (p->flags & PF_IOTHREAD) || 
+	    (p->state == TASK_ZOMBIE) ||
+	    (p->state == TASK_DEAD))
+		return 0;
+	return 1;
+}
 
 /* Refrigerator is place where frozen processes are stored :-). */
 void refrigerator(unsigned long flag)
@@ -71,8 +73,10 @@
 		read_lock(&tasklist_lock);
 		do_each_thread(g, p) {
 			unsigned long flags;
-			INTERESTING(p);
-			if (p->flags & PF_FROZEN)
+			if (!freezeable(p))
+				continue;
+			if ((p->flags & PF_FROZEN) ||
+			    (p->state == TASK_STOPPED))
 				continue;
 
 			/* FIXME: smp problem here: we may not access other process' flags
@@ -104,15 +108,18 @@
 	printk( "Restarting tasks..." );
 	read_lock(&tasklist_lock);
 	do_each_thread(g, p) {
-		INTERESTING(p);
-		
-		if (p->flags & PF_FROZEN) p->flags &= ~PF_FROZEN;
-		else
+		if (!freezeable(p))
+			continue;
+		if (p->flags & PF_FROZEN) {
+			p->flags &= ~PF_FROZEN;
+			wake_up_process(p);
+		} else
 			printk(KERN_INFO " Strange, %s not stopped\n", p->comm );
 		wake_up_process(p);
 	} while_each_thread(g, p);
 
 	read_unlock(&tasklist_lock);
+	schedule();
 	printk( " done\n" );
 	MDELAY(500);
 }


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

* Re: [PM] Fix up refrigerator to work with ^Z-ed processes
  2003-08-05  0:58 ` Patrick Mochel
@ 2003-08-05  9:14   ` Pavel Machek
  0 siblings, 0 replies; 3+ messages in thread
From: Pavel Machek @ 2003-08-05  9:14 UTC (permalink / raw)
  To: Patrick Mochel; +Cc: kernel list

Hi!

> > This makes refrigerator work with ^Z-ed processes (and not eat
> > disks). Thanks to (have to find out who, I should sleep and not be
> > splitting patches). [Hand edited, apply by hand; or there should be
> > script for recomputing @@ X,Y Z,T @@'s somewhere].
> > 
> > schedule() added makes processes start at exactly that point, making
> > printouts nicer.
> 
> This didn't apply, so in making the changes by hand, I took the liberty to 
> rename interesting_process() to freezeable() to make it a bit easier to 
> read. Revised patch below. 

Yes, that's better name, patch looks good. Thanks,
								Pavel

-- 
When do you have a heart between your knees?
[Johanka's followup: and *two* hearts?]

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

end of thread, other threads:[~2003-08-05  9:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-26 22:51 [PM] Fix up refrigerator to work with ^Z-ed processes Pavel Machek
2003-08-05  0:58 ` Patrick Mochel
2003-08-05  9:14   ` 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).