Commit 3e1d1d28 authored by Christoph Lameter's avatar Christoph Lameter Committed by Linus Torvalds
Browse files

[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: default avatarChristoph Lameter <christoph@lameter.com>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent b3e112bc
......@@ -12,8 +12,7 @@ refrigerator. Code to do this looks like this:
do {
hub_events();
wait_event_interruptible(khubd_wait, !list_empty(&hub_event_list));
if (current->flags & PF_FREEZE)
refrigerator(PF_FREEZE);
try_to_freeze();
} while (!signal_pending(current));
from drivers/usb/core/hub.c::hub_thread()
......
......@@ -164,8 +164,7 @@ place where the thread is safe to be frozen (no kernel semaphores
should be held at that point and it must be safe to sleep there), and
add:
if (current->flags & PF_FREEZE)
refrigerator(PF_FREEZE);
try_to_freeze();
If the thread is needed for writing the image to storage, you should
instead set the PF_NOFREEZE process flag when creating the thread.
......
......@@ -536,10 +536,8 @@ int do_signal(struct pt_regs *regs, sigset_t *oldset)
if (!user_mode(regs))
return 1;
if (current->flags & PF_FREEZE) {
refrigerator(0);
if (try_to_freeze())
goto no_signal;
}
if (!oldset)
oldset = &current->blocked;
......
......@@ -517,10 +517,8 @@ asmlinkage int do_signal(struct pt_regs *regs, sigset_t *oldset)
if ((regs->ccr & 0x10))
return 1;
if (current->flags & PF_FREEZE) {
refrigerator(0);
if (try_to_freeze())
goto no_signal;
}
current->thread.esp0 = (unsigned long) regs;
......
......@@ -573,7 +573,7 @@ static int balanced_irq(void *unused)
for ( ; ; ) {
set_current_state(TASK_INTERRUPTIBLE);
time_remaining = schedule_timeout(time_remaining);
try_to_freeze(PF_FREEZE);
try_to_freeze();
if (time_after(jiffies,
prev_balance_time+balanced_irq_interval)) {
do_irq_balance();
......
......@@ -608,10 +608,8 @@ int fastcall do_signal(struct pt_regs *regs, sigset_t *oldset)
if (!user_mode(regs))
return 1;
if (current->flags & PF_FREEZE) {
refrigerator(0);
if (try_to_freeze)
goto no_signal;
}
if (!oldset)
oldset = &current->blocked;
......
......@@ -371,10 +371,8 @@ int do_signal(struct pt_regs *regs, sigset_t *oldset)
if (!user_mode(regs))
return 1;
if (current->flags & PF_FREEZE) {
refrigerator(0);
if (try_to_freeze())
goto no_signal;
}
if (!oldset)
oldset = &current->blocked;
......
......@@ -705,8 +705,7 @@ int do_signal(sigset_t *oldset, struct pt_regs *regs)
unsigned long frame, newsp;
int signr, ret;
if (current->flags & PF_FREEZE) {
refrigerator(PF_FREEZE);
if (try_to_freeze()) {
signr = 0;
if (!signal_pending(current))
goto no_signal;
......
......@@ -425,7 +425,7 @@ int do_signal(struct pt_regs *regs, sigset_t *oldset)
if (!user_mode(regs))
return 1;
if (try_to_freeze(0))
if (try_to_freeze())
goto no_signal;
if (!oldset)
......
......@@ -1251,8 +1251,7 @@ static int kcdrwd(void *foobar)
VPRINTK("kcdrwd: wake up\n");
/* make swsusp happy with our thread */
if (current->flags & PF_FREEZE)
refrigerator(PF_FREEZE);
try_to_freeze();
list_for_each_entry(pkt, &pd->cdrw.pkt_active_list, list) {
if (!pkt->sleep_time)
......
......@@ -1041,10 +1041,8 @@ static int hpsbpkt_thread(void *__hi)
while (1) {
if (down_interruptible(&khpsbpkt_sig)) {
if (current->flags & PF_FREEZE) {
refrigerator(0);
if (try_to_freeze())
continue;
}
printk("khpsbpkt: received unexpected signal?!\n" );
break;
}
......
......@@ -1510,7 +1510,7 @@ static int nodemgr_host_thread(void *__hi)
if (down_interruptible(&hi->reset_sem) ||
down_interruptible(&nodemgr_serialize)) {
if (try_to_freeze(PF_FREEZE))
if (try_to_freeze())
continue;
printk("NodeMgr: received unexpected signal?!\n" );
break;
......
......@@ -439,7 +439,7 @@ static int gameport_thread(void *nothing)
do {
gameport_handle_events();
wait_event_interruptible(gameport_wait, !list_empty(&gameport_event_list));
try_to_freeze(PF_FREEZE);
try_to_freeze();
} while (!signal_pending(current));
printk(KERN_DEBUG "gameport: kgameportd exiting\n");
......
......@@ -344,7 +344,7 @@ static int serio_thread(void *nothing)
do {
serio_handle_events();
wait_event_interruptible(serio_wait, !list_empty(&serio_event_list));
try_to_freeze(PF_FREEZE);
try_to_freeze();
} while (!signal_pending(current));
printk(KERN_DEBUG "serio: kseriod exiting\n");
......
......@@ -328,9 +328,7 @@ static int monitor_task(void *arg)
struct thermostat* th = arg;
while(!kthread_should_stop()) {
if (current->flags & PF_FREEZE)
refrigerator(PF_FREEZE);
try_to_freeze();
msleep_interruptible(2000);
#ifndef DEBUG
......
......@@ -2976,8 +2976,7 @@ static int md_thread(void * arg)
wait_event_interruptible_timeout(thread->wqueue,
test_bit(THREAD_WAKEUP, &thread->flags),
thread->timeout);
if (current->flags & PF_FREEZE)
refrigerator(PF_FREEZE);
try_to_freeze();
clear_bit(THREAD_WAKEUP, &thread->flags);
......
......@@ -391,8 +391,7 @@ static int dvb_frontend_thread(void *data)
break;
}
if (current->flags & PF_FREEZE)
refrigerator(PF_FREEZE);
try_to_freeze();
if (down_interruptible(&fepriv->sem))
break;
......
......@@ -750,8 +750,7 @@ static int msp34xx_sleep(struct msp3400c *msp, int timeout)
#endif
}
}
if (current->flags & PF_FREEZE)
refrigerator(PF_FREEZE);
try_to_freeze();
remove_wait_queue(&msp->wq, &wait);
return msp->restart;
}
......
......@@ -62,8 +62,7 @@ static int videobuf_dvb_thread(void *data)
break;
if (kthread_should_stop())
break;
if (current->flags & PF_FREEZE)
refrigerator(PF_FREEZE);
try_to_freeze();
/* feed buffer data to demux */
if (buf->state == STATE_DONE)
......
......@@ -1606,7 +1606,7 @@ static int rtl8139_thread (void *data)
do {
timeout = interruptible_sleep_on_timeout (&tp->thr_wait, timeout);
/* make swsusp happy with our thread */
try_to_freeze(PF_FREEZE);
try_to_freeze();
} while (!signal_pending (current) && (timeout > 0));
if (signal_pending (current)) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment