diff options
author | Christoph Lameter <christoph@lameter.com> | 2005-06-25 02:13:50 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-06-25 20:10:13 -0400 |
commit | 3e1d1d28d99dabe63c64f7f40f1ca1d646de1f73 (patch) | |
tree | d1e7c1e2e8902072042aefc3a7976b271cf76021 /kernel/power/process.c | |
parent | b3e112bcc19abd8e9657dca34a87316786e096f3 (diff) |
[PATCH] Cleanup patch for process freezing
1. Establish a simple API for process freezing defined in linux/include/sched.h:
frozen(process) Check for frozen process
freezing(process) Check if a process is being frozen
freeze(process) Tell a process to freeze (go to refrigerator)
thaw_process(process) Restart process
frozen_process(process) Process is frozen now
2. Remove all references to PF_FREEZE and PF_FROZEN from all
kernel sources except sched.h
3. Fix numerous locations where try_to_freeze is manually done by a driver
4. Remove the argument that is no longer necessary from two function calls.
5. Some whitespace cleanup
6. Clear potential race in refrigerator (provides an open window of PF_FREEZE
cleared before setting PF_FROZEN, recalc_sigpending does not check
PF_FROZEN).
This patch does not address the problem of freeze_processes() violating the rule
that a task may only modify its own flags by setting PF_FREEZE. This is not clean
in an SMP environment. freeze(process) is therefore not SMP safe!
Signed-off-by: Christoph Lameter <christoph@lameter.com>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'kernel/power/process.c')
-rw-r--r-- | kernel/power/process.c | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/kernel/power/process.c b/kernel/power/process.c index 78d92dc6a1ed..0a086640bcfc 100644 --- a/kernel/power/process.c +++ b/kernel/power/process.c | |||
@@ -32,7 +32,7 @@ static inline int freezeable(struct task_struct * p) | |||
32 | } | 32 | } |
33 | 33 | ||
34 | /* Refrigerator is place where frozen processes are stored :-). */ | 34 | /* Refrigerator is place where frozen processes are stored :-). */ |
35 | void refrigerator(unsigned long flag) | 35 | void refrigerator(void) |
36 | { | 36 | { |
37 | /* Hmm, should we be allowed to suspend when there are realtime | 37 | /* Hmm, should we be allowed to suspend when there are realtime |
38 | processes around? */ | 38 | processes around? */ |
@@ -41,14 +41,13 @@ void refrigerator(unsigned long flag) | |||
41 | current->state = TASK_UNINTERRUPTIBLE; | 41 | current->state = TASK_UNINTERRUPTIBLE; |
42 | pr_debug("%s entered refrigerator\n", current->comm); | 42 | pr_debug("%s entered refrigerator\n", current->comm); |
43 | printk("="); | 43 | printk("="); |
44 | current->flags &= ~PF_FREEZE; | ||
45 | 44 | ||
45 | frozen_process(current); | ||
46 | spin_lock_irq(¤t->sighand->siglock); | 46 | spin_lock_irq(¤t->sighand->siglock); |
47 | recalc_sigpending(); /* We sent fake signal, clean it up */ | 47 | recalc_sigpending(); /* We sent fake signal, clean it up */ |
48 | spin_unlock_irq(¤t->sighand->siglock); | 48 | spin_unlock_irq(¤t->sighand->siglock); |
49 | 49 | ||
50 | current->flags |= PF_FROZEN; | 50 | while (frozen(current)) |
51 | while (current->flags & PF_FROZEN) | ||
52 | schedule(); | 51 | schedule(); |
53 | pr_debug("%s left refrigerator\n", current->comm); | 52 | pr_debug("%s left refrigerator\n", current->comm); |
54 | current->state = save; | 53 | current->state = save; |
@@ -57,10 +56,10 @@ void refrigerator(unsigned long flag) | |||
57 | /* 0 = success, else # of processes that we failed to stop */ | 56 | /* 0 = success, else # of processes that we failed to stop */ |
58 | int freeze_processes(void) | 57 | int freeze_processes(void) |
59 | { | 58 | { |
60 | int todo; | 59 | int todo; |
61 | unsigned long start_time; | 60 | unsigned long start_time; |
62 | struct task_struct *g, *p; | 61 | struct task_struct *g, *p; |
63 | 62 | ||
64 | printk( "Stopping tasks: " ); | 63 | printk( "Stopping tasks: " ); |
65 | start_time = jiffies; | 64 | start_time = jiffies; |
66 | do { | 65 | do { |
@@ -70,14 +69,12 @@ int freeze_processes(void) | |||
70 | unsigned long flags; | 69 | unsigned long flags; |
71 | if (!freezeable(p)) | 70 | if (!freezeable(p)) |
72 | continue; | 71 | continue; |
73 | if ((p->flags & PF_FROZEN) || | 72 | if ((frozen(p)) || |
74 | (p->state == TASK_TRACED) || | 73 | (p->state == TASK_TRACED) || |
75 | (p->state == TASK_STOPPED)) | 74 | (p->state == TASK_STOPPED)) |
76 | continue; | 75 | continue; |
77 | 76 | ||
78 | /* FIXME: smp problem here: we may not access other process' flags | 77 | freeze(p); |
79 | without locking */ | ||
80 | p->flags |= PF_FREEZE; | ||
81 | spin_lock_irqsave(&p->sighand->siglock, flags); | 78 | spin_lock_irqsave(&p->sighand->siglock, flags); |
82 | signal_wake_up(p, 0); | 79 | signal_wake_up(p, 0); |
83 | spin_unlock_irqrestore(&p->sighand->siglock, flags); | 80 | spin_unlock_irqrestore(&p->sighand->siglock, flags); |
@@ -91,7 +88,7 @@ int freeze_processes(void) | |||
91 | return todo; | 88 | return todo; |
92 | } | 89 | } |
93 | } while(todo); | 90 | } while(todo); |
94 | 91 | ||
95 | printk( "|\n" ); | 92 | printk( "|\n" ); |
96 | BUG_ON(in_atomic()); | 93 | BUG_ON(in_atomic()); |
97 | return 0; | 94 | return 0; |
@@ -106,10 +103,7 @@ void thaw_processes(void) | |||
106 | do_each_thread(g, p) { | 103 | do_each_thread(g, p) { |
107 | if (!freezeable(p)) | 104 | if (!freezeable(p)) |
108 | continue; | 105 | continue; |
109 | if (p->flags & PF_FROZEN) { | 106 | if (!thaw_process(p)) |
110 | p->flags &= ~PF_FROZEN; | ||
111 | wake_up_process(p); | ||
112 | } else | ||
113 | printk(KERN_INFO " Strange, %s not stopped\n", p->comm ); | 107 | printk(KERN_INFO " Strange, %s not stopped\n", p->comm ); |
114 | } while_each_thread(g, p); | 108 | } while_each_thread(g, p); |
115 | 109 | ||