linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: <ffrederick@prov-liege.be>
To: <linux-kernel@vger.kernel.org>
Subject: [PATCH] Washing suspend code
Date: Wed, 2 Jul 2003 10:43:11 CEST	[thread overview]
Message-ID: <S263945AbTGBIGc/20030702080632Z+4079@vger.kernel.org> (raw)

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


___________________________________




             reply	other threads:[~2003-07-02  8:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-02  8:43 ffrederick [this message]
2003-07-02 13:10 ` [PATCH] Washing suspend code Dave Jones
2003-07-21  2:55   ` David Woodhouse

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=S263945AbTGBIGc/20030702080632Z+4079@vger.kernel.org \
    --to=ffrederick@prov-liege.be \
    --cc=linux-kernel@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).