Skip to content

Commit

Permalink
[PATCH] Cleanup patch for process freezing
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
clameter authored and Linus Torvalds committed Jun 26, 2005
1 parent b3e112b commit 3e1d1d2
Show file tree
Hide file tree
Showing 47 changed files with 126 additions and 113 deletions.
3 changes: 1 addition & 2 deletions Documentation/power/kernel_threads.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions Documentation/power/swsusp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 1 addition & 3 deletions arch/frv/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions arch/h8300/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion arch/i386/kernel/io_apic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 1 addition & 3 deletions arch/i386/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions arch/m32r/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions arch/ppc/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion arch/x86_64/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions drivers/block/pktcdvd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions drivers/ieee1394/ieee1394_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/ieee1394/nodemgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion drivers/input/gameport/gameport.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion drivers/input/serio/serio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 1 addition & 3 deletions drivers/macintosh/therm_adt746x.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions drivers/md/md.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 1 addition & 2 deletions drivers/media/dvb/dvb-core/dvb_frontend.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions drivers/media/video/msp3400.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 1 addition & 2 deletions drivers/media/video/video-buf-dvb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/8139too.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
3 changes: 1 addition & 2 deletions drivers/net/irda/sir_kthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ static int irda_thread(void *startup)
remove_wait_queue(&irda_rq_queue.kick, &wait);

/* make swsusp happy with our thread */
if (current->flags & PF_FREEZE)
refrigerator(PF_FREEZE);
try_to_freeze();

run_irda_queue();
}
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/irda/stir4200.c
Original file line number Diff line number Diff line change
Expand Up @@ -763,15 +763,15 @@ static int stir_transmit_thread(void *arg)
{
#ifdef CONFIG_PM
/* if suspending, then power off and wait */
if (unlikely(current->flags & PF_FREEZE)) {
if (unlikely(freezing(current))) {
if (stir->receiving)
receive_stop(stir);
else
fifo_txwait(stir, -1);

write_reg(stir, REG_CTRL1, CTRL1_TXPWD|CTRL1_RXPWD);

refrigerator(PF_FREEZE);
refrigerator();

if (change_speed(stir, stir->speed))
break;
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/wireless/airo.c
Original file line number Diff line number Diff line change
Expand Up @@ -2918,7 +2918,7 @@ static int airo_thread(void *data) {
flush_signals(current);

/* make swsusp happy with our thread */
try_to_freeze(PF_FREEZE);
try_to_freeze();

if (test_bit(JOB_DIE, &ai->flags))
break;
Expand Down
2 changes: 1 addition & 1 deletion drivers/pcmcia/cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ static int pccardd(void *__skt)
}

schedule();
try_to_freeze(PF_FREEZE);
try_to_freeze();

if (!skt->thread)
break;
Expand Down
2 changes: 1 addition & 1 deletion drivers/pnp/pnpbios/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ static int pnp_dock_thread(void * unused)
msleep_interruptible(2000);

if(signal_pending(current)) {
if (try_to_freeze(PF_FREEZE))
if (try_to_freeze())
continue;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/usb/core/hub.c
Original file line number Diff line number Diff line change
Expand Up @@ -2808,7 +2808,7 @@ static int hub_thread(void *__unused)
do {
hub_events();
wait_event_interruptible(khubd_wait, !list_empty(&hub_event_list));
try_to_freeze(PF_FREEZE);
try_to_freeze();
} while (!signal_pending(current));

pr_debug ("%s: khubd exiting\n", usbcore_name);
Expand Down
3 changes: 1 addition & 2 deletions drivers/usb/gadget/file_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -1554,8 +1554,7 @@ static int sleep_thread(struct fsg_dev *fsg)
rc = wait_event_interruptible(fsg->thread_wqh,
fsg->thread_wakeup_needed);
fsg->thread_wakeup_needed = 0;
if (current->flags & PF_FREEZE)
refrigerator(PF_FREEZE);
try_to_freeze();
return (rc ? -EINTR : 0);
}

Expand Down
4 changes: 1 addition & 3 deletions drivers/usb/storage/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -847,10 +847,8 @@ static int usb_stor_scan_thread(void * __us)
wait_event_interruptible_timeout(us->delay_wait,
test_bit(US_FLIDX_DISCONNECTING, &us->flags),
delay_use * HZ);
if (current->flags & PF_FREEZE) {
refrigerator(PF_FREEZE);
if (try_to_freeze())
goto retry;
}
}

/* If the device is still connected, perform the scanning */
Expand Down
4 changes: 2 additions & 2 deletions drivers/w1/w1.c
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ static int w1_control(void *data)
while (!control_needs_exit || have_to_wait) {
have_to_wait = 0;

try_to_freeze(PF_FREEZE);
try_to_freeze();
msleep_interruptible(w1_timeout * 1000);

if (signal_pending(current))
Expand Down Expand Up @@ -725,7 +725,7 @@ int w1_process(void *data)
allow_signal(SIGTERM);

while (!test_bit(W1_MASTER_NEED_EXIT, &dev->flags)) {
try_to_freeze(PF_FREEZE);
try_to_freeze();
msleep_interruptible(w1_timeout * 1000);

if (signal_pending(current))
Expand Down
2 changes: 1 addition & 1 deletion fs/afs/kafsasyncd.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ static int kafsasyncd(void *arg)
remove_wait_queue(&kafsasyncd_sleepq, &myself);
set_current_state(TASK_RUNNING);

try_to_freeze(PF_FREEZE);
try_to_freeze();

/* discard pending signals */
afs_discard_my_signals();
Expand Down
2 changes: 1 addition & 1 deletion fs/afs/kafstimod.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ static int kafstimod(void *arg)
complete_and_exit(&kafstimod_dead, 0);
}

try_to_freeze(PF_FREEZE);
try_to_freeze();

/* discard pending signals */
afs_discard_my_signals();
Expand Down
4 changes: 2 additions & 2 deletions fs/jbd/journal.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,15 @@ int kjournald(void *arg)
}

wake_up(&journal->j_wait_done_commit);
if (current->flags & PF_FREEZE) {
if (freezing(current)) {
/*
* The simpler the better. Flushing journal isn't a
* good idea, because that depends on threads that may
* be already stopped.
*/
jbd_debug(1, "Now suspending kjournald\n");
spin_unlock(&journal->j_state_lock);
refrigerator(PF_FREEZE);
refrigerator();
spin_lock(&journal->j_state_lock);
} else {
/*
Expand Down
4 changes: 2 additions & 2 deletions fs/jfs/jfs_logmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -2359,9 +2359,9 @@ int jfsIOWait(void *arg)
lbmStartIO(bp);
spin_lock_irq(&log_redrive_lock);
}
if (current->flags & PF_FREEZE) {
if (freezing(current)) {
spin_unlock_irq(&log_redrive_lock);
refrigerator(PF_FREEZE);
refrigerator();
} else {
add_wait_queue(&jfs_IO_thread_wait, &wq);
set_current_state(TASK_INTERRUPTIBLE);
Expand Down
8 changes: 4 additions & 4 deletions fs/jfs/jfs_txnmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -2788,9 +2788,9 @@ int jfs_lazycommit(void *arg)
/* In case a wakeup came while all threads were active */
jfs_commit_thread_waking = 0;

if (current->flags & PF_FREEZE) {
if (freezing(current)) {
LAZY_UNLOCK(flags);
refrigerator(PF_FREEZE);
refrigerator();
} else {
DECLARE_WAITQUEUE(wq, current);

Expand Down Expand Up @@ -2987,9 +2987,9 @@ int jfs_sync(void *arg)
/* Add anon_list2 back to anon_list */
list_splice_init(&TxAnchor.anon_list2, &TxAnchor.anon_list);

if (current->flags & PF_FREEZE) {
if (freezing(current)) {
TXN_UNLOCK();
refrigerator(PF_FREEZE);
refrigerator();
} else {
DECLARE_WAITQUEUE(wq, current);

Expand Down
2 changes: 1 addition & 1 deletion fs/lockd/clntproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ static int nlm_wait_on_grace(wait_queue_head_t *queue)
prepare_to_wait(queue, &wait, TASK_INTERRUPTIBLE);
if (!signalled ()) {
schedule_timeout(NLMCLNT_GRACE_WAIT);
try_to_freeze(PF_FREEZE);
try_to_freeze();
if (!signalled ())
status = 0;
}
Expand Down
Loading

0 comments on commit 3e1d1d2

Please sign in to comment.