Skip to contentSkip to conversation

Freezer cleanups

PATCH In review Rafael J. Wysocki 2 participants 7 messages May 26, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Freezer cleanups

Hi,

The following three patches contain minor freezer cleanups. Please have a look.

Greetings,
Rafael

#1 lore raw

PATCH 1/3 Freezer: Use __set_current_state in refrigerator

From: Rafael J. Wysocki <[email protected]>

Use __set_current_state() as appropriate in refrigerator() instead of accessing current->state directly.

---
 kernel/power/process.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/power/process.c +1 -1
Index: linux-2.6.22-rc2/kernel/power/process.c
===================================================================
@@ -72,7 +72,7 @@ void refrigerator(void)
 		schedule();
 	}
 	pr_debug("%s left refrigerator\n", current->comm);
-	current->state = save;
+	__set_current_state(save);
 }
 
 static void freeze_task(struct task_struct *p)
#2 lore raw

Re: [PATCH 1/3] Freezer: Use __set_current_state in refrigerator

Quoted 6 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Use __set_current_state() as appropriate in refrigerator() instead of accessing current->state directly.

ACK.

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#3 lore raw

PATCH 2/3 Freezer: Return int from freeze_processes

In reply to Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Make try_to_freeze_tasks() and freeze_processes() return -EBUSY on failure instead of the number of unfrozen tasks (none of the callers actually uses this number).

---
 kernel/power/process.c |   21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)
kernel/power/process.c +9 -12
Index: linux-2.6.22-rc2/kernel/power/process.c
===================================================================
@@ -105,7 +105,7 @@ static void cancel_freezing(struct task_
 	}
 }
 
-static unsigned int try_to_freeze_tasks(int freeze_user_space)
+static int try_to_freeze_tasks(int freeze_user_space)
 {
 	struct task_struct *g, *p;
 	unsigned long end_time;
@@ -175,28 +175,25 @@ static unsigned int try_to_freeze_tasks(
 		read_unlock(&tasklist_lock);
 	}
 
-	return todo;
+	return todo ? -EBUSY : 0;
 }
 
 /**
  *	freeze_processes - tell processes to enter the refrigerator
- *
- *	Returns 0 on success, or the number of processes that didn't freeze,
- *	although they were told to.
  */
 int freeze_processes(void)
 {
-	unsigned int nr_unfrozen;
+	int error;
 
 	printk("Stopping tasks ... ");
-	nr_unfrozen = try_to_freeze_tasks(FREEZER_USER_SPACE);
-	if (nr_unfrozen)
-		return nr_unfrozen;
+	error = try_to_freeze_tasks(FREEZER_USER_SPACE);
+	if (error)
+		return error;
 
 	sys_sync();
-	nr_unfrozen = try_to_freeze_tasks(FREEZER_KERNEL_THREADS);
-	if (nr_unfrozen)
-		return nr_unfrozen;
+	error = try_to_freeze_tasks(FREEZER_KERNEL_THREADS);
+	if (error)
+		return error;
 
 	printk("done.\n");
 	BUG_ON(in_atomic());
#4 lore raw

Re: [PATCH 2/3] Freezer: Return int from freeze_processes

Quoted 7 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Make try_to_freeze_tasks() and freeze_processes() return -EBUSY on failure instead of the number of unfrozen tasks (none of the callers actually uses this number).

ACK.

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#5 lore raw

PATCH 3/3 Freezer: Remove redundant check in try_to_freeze_tasks

In reply to Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

We don't need to check if todo is positive before calling time_after() in try_to_freeze_tasks(), because if todo is zero at this point, the loop will be broken anyway due to the while () condition being false.

---
 kernel/power/process.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/power/process.c +1 -1
Index: linux-2.6.22-rc2/kernel/power/process.c
===================================================================
@@ -149,7 +149,7 @@ static int try_to_freeze_tasks(int freez
 		} while_each_thread(g, p);
 		read_unlock(&tasklist_lock);
 		yield();			/* Yield is okay here */
-		if (todo && time_after(jiffies, end_time))
+		if (time_after(jiffies, end_time))
 			break;
 	} while (todo);
 
#6 lore raw

Re: [PATCH 3/3] Freezer: Remove redundant check in try_to_freeze_tasks

Quoted 7 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

We don't need to check if todo is positive before calling time_after() in try_to_freeze_tasks(), because if todo is zero at this point, the loop will be broken anyway due to the while () condition being false.

ACK. Thanks for the cleanups!
Pavel

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