linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Washing suspend code
@ 2003-07-02  8:43 ffrederick
  2003-07-02 13:10 ` Dave Jones
  0 siblings, 1 reply; 3+ messages in thread
From: ffrederick @ 2003-07-02  8:43 UTC (permalink / raw)
  To: linux-kernel

-replacing INTERESTING macro by touchable_process fx
-moving flags declaration fx global
-yield after 'time_after'
-some code washing
-removing 'lock comment' we already do the read_lock() on tasklist


--- linux-2.5.73/kernel/suspend.c	2003-06-22 20:32:38.000000000 +0200
+++ edited/kernel/suspend.c	2003-07-02 10:07:44.000000000 +0200
@@ -29,6 +29,9 @@
  * Alex Badea <vampire@go.ro>:
  * Fixed runaway init
  *
+ * Fabian Frédérick <ffrederick@users.sourceforge.net>
+ * Washing code in freeze_processes
+ * 
  * More state savers are welcome. Especially for the scsi layer...
  *
  * For TODOs,FIXMEs also look in Documentation/swsusp.txt
@@ -164,15 +167,6 @@ static const char name_resume[] = "Resum
  * 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;
-
 /* Refrigerator is place where frozen processes are stored :-). */
 void refrigerator(unsigned long flag)
 {
@@ -197,12 +191,20 @@ void refrigerator(unsigned long flag)
 	PRINTK("%s left refrigerator\n", current->comm);
 	current->state = save;
 }
+int touchable_process (struct task_struct *p)
+{
+	return(!((p->flags & PF_IOTHREAD) || (p == current) || (p->state == TASK_ZOMBIE)))
+
+}
 
-/* 0 = success, else # of processes that we failed to stop */
+/* Trying to freeze all processes without kernel threads, zombies and current 
+ * Returns 0 : Success
+ *         # : 
+ */
 int freeze_processes(void)
 {
-       int todo;
-       unsigned long start_time;
+	int todo;
+	unsigned long start_time, flags;
 	struct task_struct *g, *p;
 	
 	printk( "Stopping tasks: " );
@@ -211,26 +213,23 @@ int freeze_processes(void)
 		todo = 0;
 		read_lock(&tasklist_lock);
 		do_each_thread(g, p) {
-			unsigned long flags;
-			INTERESTING(p);
-			if (p->flags & PF_FROZEN)
-				continue;
-
-			/* FIXME: smp problem here: we may not access other process' flags
-			   without locking */
-			p->flags |= PF_FREEZE;
-			spin_lock_irqsave(&p->sighand->siglock, flags);
-			signal_wake_up(p, 0);
-			spin_unlock_irqrestore(&p->sighand->siglock, flags);
-			todo++;
+			if(touchable_process(p)){
+				if (p->flags & PF_FROZEN)
+					continue;
+				p->flags |= PF_FREEZE;
+				spin_lock_irqsave(&p->sighand->siglock, flags);
+				signal_wake_up(p, 0);
+				spin_unlock_irqrestore(&p->sighand->siglock, flags);
+				todo++;
+			}
 		} while_each_thread(g, p);
 		read_unlock(&tasklist_lock);
-		yield();			/* Yield is okay here */
 		if (time_after(jiffies, start_time + TIMEOUT)) {
 			printk( "\n" );
 			printk(KERN_ERR " stopping tasks failed (%d tasks remaining)\n", todo );
 			return todo;
 		}
+		yield();
 	} while(todo);
 	
 	printk( "|\n" );
@@ -245,12 +244,13 @@ void thaw_processes(void)
 	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(touchable_process(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);
+		}
 	} while_each_thread(g, p);
 
 	read_unlock(&tasklist_lock);


___________________________________




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

* Re: [PATCH] Washing suspend code
  2003-07-02  8:43 [PATCH] Washing suspend code ffrederick
@ 2003-07-02 13:10 ` Dave Jones
  2003-07-21  2:55   ` David Woodhouse
  0 siblings, 1 reply; 3+ messages in thread
From: Dave Jones @ 2003-07-02 13:10 UTC (permalink / raw)
  To: ffrederick; +Cc: linux-kernel

On Wed, Jul 02, 2003 at 10:43:11AM +0200, ffrederick@prov-liege.be wrote:
 >  }
 > +int touchable_process (struct task_struct *p)
 > +{
 > +	return(!((p->flags & PF_IOTHREAD) || (p == current) || (p->state == TASK_ZOMBIE)))
 > +
 > +}

*horror*. Please keep the formatting of the original macro.
It's a) more readable, and b) Documentation/CodingStyle compliant.

		Dave


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

* Re: [PATCH] Washing suspend code
  2003-07-02 13:10 ` Dave Jones
@ 2003-07-21  2:55   ` David Woodhouse
  0 siblings, 0 replies; 3+ messages in thread
From: David Woodhouse @ 2003-07-21  2:55 UTC (permalink / raw)
  To: Dave Jones; +Cc: ffrederick, linux-kernel

On Wed, 2003-07-02 at 14:10, Dave Jones wrote:
> On Wed, Jul 02, 2003 at 10:43:11AM +0200, ffrederick@prov-liege.be wrote:
>  >  }
>  > +int touchable_process (struct task_struct *p)
>  > +{
>  > +	return(!((p->flags & PF_IOTHREAD) || (p == current) || (p->state == TASK_ZOMBIE)))
>  > +
>  > +}
> 
> *horror*. Please keep the formatting of the original macro.
> It's a) more readable, and b) Documentation/CodingStyle compliant.

Bugger the formatting. The original macro invocation 'INTERESTING(p)'
may invoke 'continue;' and change the flow of execution in an utterly
unobvious manner. The 'if (something) continue;' form is _definitely_
better.

-- 
dwmw2


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

end of thread, other threads:[~2003-07-21  2:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-02  8:43 [PATCH] Washing suspend code ffrederick
2003-07-02 13:10 ` Dave Jones
2003-07-21  2:55   ` David Woodhouse

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).