Merge Christoph's freeze cleanup patch

+126 -112
+1 -2
Documentation/power/kernel_threads.txt
··· 12 do { 13 hub_events(); 14 wait_event_interruptible(khubd_wait, !list_empty(&hub_event_list)); 15 - if (current->flags & PF_FREEZE) 16 - refrigerator(PF_FREEZE); 17 } while (!signal_pending(current)); 18 19 from drivers/usb/core/hub.c::hub_thread()
··· 12 do { 13 hub_events(); 14 wait_event_interruptible(khubd_wait, !list_empty(&hub_event_list)); 15 + try_to_freeze(); 16 } while (!signal_pending(current)); 17 18 from drivers/usb/core/hub.c::hub_thread()
+1 -1
Documentation/power/swsusp.txt
··· 164 should be held at that point and it must be safe to sleep there), and 165 add: 166 167 - try_to_freeze(PF_FREEZE); 168 169 If the thread is needed for writing the image to storage, you should 170 instead set the PF_NOFREEZE process flag when creating the thread (and
··· 164 should be held at that point and it must be safe to sleep there), and 165 add: 166 167 + try_to_freeze(); 168 169 If the thread is needed for writing the image to storage, you should 170 instead set the PF_NOFREEZE process flag when creating the thread (and
+1 -3
arch/frv/kernel/signal.c
··· 536 if (!user_mode(regs)) 537 return 1; 538 539 - if (current->flags & PF_FREEZE) { 540 - refrigerator(0); 541 goto no_signal; 542 - } 543 544 if (!oldset) 545 oldset = &current->blocked;
··· 536 if (!user_mode(regs)) 537 return 1; 538 539 + if (try_to_freeze()) 540 goto no_signal; 541 542 if (!oldset) 543 oldset = &current->blocked;
+1 -3
arch/h8300/kernel/signal.c
··· 517 if ((regs->ccr & 0x10)) 518 return 1; 519 520 - if (current->flags & PF_FREEZE) { 521 - refrigerator(0); 522 goto no_signal; 523 - } 524 525 current->thread.esp0 = (unsigned long) regs; 526
··· 517 if ((regs->ccr & 0x10)) 518 return 1; 519 520 + if (try_to_freeze()) 521 goto no_signal; 522 523 current->thread.esp0 = (unsigned long) regs; 524
+1 -1
arch/i386/kernel/io_apic.c
··· 573 for ( ; ; ) { 574 set_current_state(TASK_INTERRUPTIBLE); 575 time_remaining = schedule_timeout(time_remaining); 576 - try_to_freeze(PF_FREEZE); 577 if (time_after(jiffies, 578 prev_balance_time+balanced_irq_interval)) { 579 preempt_disable();
··· 573 for ( ; ; ) { 574 set_current_state(TASK_INTERRUPTIBLE); 575 time_remaining = schedule_timeout(time_remaining); 576 + try_to_freeze(); 577 if (time_after(jiffies, 578 prev_balance_time+balanced_irq_interval)) { 579 preempt_disable();
+1 -3
arch/i386/kernel/signal.c
··· 608 if (!user_mode(regs)) 609 return 1; 610 611 - if (current->flags & PF_FREEZE) { 612 - refrigerator(0); 613 goto no_signal; 614 - } 615 616 if (!oldset) 617 oldset = &current->blocked;
··· 608 if (!user_mode(regs)) 609 return 1; 610 611 + if (try_to_freeze) 612 goto no_signal; 613 614 if (!oldset) 615 oldset = &current->blocked;
+1 -3
arch/m32r/kernel/signal.c
··· 371 if (!user_mode(regs)) 372 return 1; 373 374 - if (current->flags & PF_FREEZE) { 375 - refrigerator(0); 376 goto no_signal; 377 - } 378 379 if (!oldset) 380 oldset = &current->blocked;
··· 371 if (!user_mode(regs)) 372 return 1; 373 374 + if (try_to_freeze()) 375 goto no_signal; 376 377 if (!oldset) 378 oldset = &current->blocked;
+1 -2
arch/ppc/kernel/signal.c
··· 705 unsigned long frame, newsp; 706 int signr, ret; 707 708 - if (current->flags & PF_FREEZE) { 709 - refrigerator(PF_FREEZE); 710 signr = 0; 711 if (!signal_pending(current)) 712 goto no_signal;
··· 705 unsigned long frame, newsp; 706 int signr, ret; 707 708 + if (try_to_freeze()) { 709 signr = 0; 710 if (!signal_pending(current)) 711 goto no_signal;
+1 -1
arch/x86_64/kernel/signal.c
··· 425 if (!user_mode(regs)) 426 return 1; 427 428 - if (try_to_freeze(0)) 429 goto no_signal; 430 431 if (!oldset)
··· 425 if (!user_mode(regs)) 426 return 1; 427 428 + if (try_to_freeze()) 429 goto no_signal; 430 431 if (!oldset)
+1 -2
drivers/block/pktcdvd.c
··· 1251 VPRINTK("kcdrwd: wake up\n"); 1252 1253 /* make swsusp happy with our thread */ 1254 - if (current->flags & PF_FREEZE) 1255 - refrigerator(PF_FREEZE); 1256 1257 list_for_each_entry(pkt, &pd->cdrw.pkt_active_list, list) { 1258 if (!pkt->sleep_time)
··· 1251 VPRINTK("kcdrwd: wake up\n"); 1252 1253 /* make swsusp happy with our thread */ 1254 + try_to_freeze(); 1255 1256 list_for_each_entry(pkt, &pd->cdrw.pkt_active_list, list) { 1257 if (!pkt->sleep_time)
+1 -3
drivers/ieee1394/ieee1394_core.c
··· 1041 1042 while (1) { 1043 if (down_interruptible(&khpsbpkt_sig)) { 1044 - if (current->flags & PF_FREEZE) { 1045 - refrigerator(0); 1046 continue; 1047 - } 1048 printk("khpsbpkt: received unexpected signal?!\n" ); 1049 break; 1050 }
··· 1041 1042 while (1) { 1043 if (down_interruptible(&khpsbpkt_sig)) { 1044 + if (try_to_freeze()) 1045 continue; 1046 printk("khpsbpkt: received unexpected signal?!\n" ); 1047 break; 1048 }
+1 -1
drivers/ieee1394/nodemgr.c
··· 1510 1511 if (down_interruptible(&hi->reset_sem) || 1512 down_interruptible(&nodemgr_serialize)) { 1513 - if (try_to_freeze(PF_FREEZE)) 1514 continue; 1515 printk("NodeMgr: received unexpected signal?!\n" ); 1516 break;
··· 1510 1511 if (down_interruptible(&hi->reset_sem) || 1512 down_interruptible(&nodemgr_serialize)) { 1513 + if (try_to_freeze()) 1514 continue; 1515 printk("NodeMgr: received unexpected signal?!\n" ); 1516 break;
+1 -1
drivers/input/gameport/gameport.c
··· 439 do { 440 gameport_handle_events(); 441 wait_event_interruptible(gameport_wait, !list_empty(&gameport_event_list)); 442 - try_to_freeze(PF_FREEZE); 443 } while (!signal_pending(current)); 444 445 printk(KERN_DEBUG "gameport: kgameportd exiting\n");
··· 439 do { 440 gameport_handle_events(); 441 wait_event_interruptible(gameport_wait, !list_empty(&gameport_event_list)); 442 + try_to_freeze(); 443 } while (!signal_pending(current)); 444 445 printk(KERN_DEBUG "gameport: kgameportd exiting\n");
+1 -1
drivers/input/serio/serio.c
··· 344 do { 345 serio_handle_events(); 346 wait_event_interruptible(serio_wait, !list_empty(&serio_event_list)); 347 - try_to_freeze(PF_FREEZE); 348 } while (!signal_pending(current)); 349 350 printk(KERN_DEBUG "serio: kseriod exiting\n");
··· 344 do { 345 serio_handle_events(); 346 wait_event_interruptible(serio_wait, !list_empty(&serio_event_list)); 347 + try_to_freeze(); 348 } while (!signal_pending(current)); 349 350 printk(KERN_DEBUG "serio: kseriod exiting\n");
+1 -3
drivers/macintosh/therm_adt746x.c
··· 328 struct thermostat* th = arg; 329 330 while(!kthread_should_stop()) { 331 - if (current->flags & PF_FREEZE) 332 - refrigerator(PF_FREEZE); 333 - 334 msleep_interruptible(2000); 335 336 #ifndef DEBUG
··· 328 struct thermostat* th = arg; 329 330 while(!kthread_should_stop()) { 331 + try_to_freeze(); 332 msleep_interruptible(2000); 333 334 #ifndef DEBUG
+1 -2
drivers/md/md.c
··· 2976 wait_event_interruptible_timeout(thread->wqueue, 2977 test_bit(THREAD_WAKEUP, &thread->flags), 2978 thread->timeout); 2979 - if (current->flags & PF_FREEZE) 2980 - refrigerator(PF_FREEZE); 2981 2982 clear_bit(THREAD_WAKEUP, &thread->flags); 2983
··· 2976 wait_event_interruptible_timeout(thread->wqueue, 2977 test_bit(THREAD_WAKEUP, &thread->flags), 2978 thread->timeout); 2979 + try_to_freeze(); 2980 2981 clear_bit(THREAD_WAKEUP, &thread->flags); 2982
+1 -2
drivers/media/dvb/dvb-core/dvb_frontend.c
··· 391 break; 392 } 393 394 - if (current->flags & PF_FREEZE) 395 - refrigerator(PF_FREEZE); 396 397 if (down_interruptible(&fepriv->sem)) 398 break;
··· 391 break; 392 } 393 394 + try_to_freeze(); 395 396 if (down_interruptible(&fepriv->sem)) 397 break;
+1 -2
drivers/media/video/msp3400.c
··· 750 #endif 751 } 752 } 753 - if (current->flags & PF_FREEZE) 754 - refrigerator(PF_FREEZE); 755 remove_wait_queue(&msp->wq, &wait); 756 return msp->restart; 757 }
··· 750 #endif 751 } 752 } 753 + try_to_freeze(); 754 remove_wait_queue(&msp->wq, &wait); 755 return msp->restart; 756 }
+1 -2
drivers/media/video/video-buf-dvb.c
··· 62 break; 63 if (kthread_should_stop()) 64 break; 65 - if (current->flags & PF_FREEZE) 66 - refrigerator(PF_FREEZE); 67 68 /* feed buffer data to demux */ 69 if (buf->state == STATE_DONE)
··· 62 break; 63 if (kthread_should_stop()) 64 break; 65 + try_to_freeze(); 66 67 /* feed buffer data to demux */ 68 if (buf->state == STATE_DONE)
+1 -1
drivers/net/8139too.c
··· 1606 do { 1607 timeout = interruptible_sleep_on_timeout (&tp->thr_wait, timeout); 1608 /* make swsusp happy with our thread */ 1609 - try_to_freeze(PF_FREEZE); 1610 } while (!signal_pending (current) && (timeout > 0)); 1611 1612 if (signal_pending (current)) {
··· 1606 do { 1607 timeout = interruptible_sleep_on_timeout (&tp->thr_wait, timeout); 1608 /* make swsusp happy with our thread */ 1609 + try_to_freeze(); 1610 } while (!signal_pending (current) && (timeout > 0)); 1611 1612 if (signal_pending (current)) {
+1 -2
drivers/net/irda/sir_kthread.c
··· 135 remove_wait_queue(&irda_rq_queue.kick, &wait); 136 137 /* make swsusp happy with our thread */ 138 - if (current->flags & PF_FREEZE) 139 - refrigerator(PF_FREEZE); 140 141 run_irda_queue(); 142 }
··· 135 remove_wait_queue(&irda_rq_queue.kick, &wait); 136 137 /* make swsusp happy with our thread */ 138 + try_to_freeze(); 139 140 run_irda_queue(); 141 }
+2 -2
drivers/net/irda/stir4200.c
··· 763 { 764 #ifdef CONFIG_PM 765 /* if suspending, then power off and wait */ 766 - if (unlikely(current->flags & PF_FREEZE)) { 767 if (stir->receiving) 768 receive_stop(stir); 769 else ··· 771 772 write_reg(stir, REG_CTRL1, CTRL1_TXPWD|CTRL1_RXPWD); 773 774 - refrigerator(PF_FREEZE); 775 776 if (change_speed(stir, stir->speed)) 777 break;
··· 763 { 764 #ifdef CONFIG_PM 765 /* if suspending, then power off and wait */ 766 + if (unlikely(freezing(current))) { 767 if (stir->receiving) 768 receive_stop(stir); 769 else ··· 771 772 write_reg(stir, REG_CTRL1, CTRL1_TXPWD|CTRL1_RXPWD); 773 774 + refrigerator(); 775 776 if (change_speed(stir, stir->speed)) 777 break;
+1 -1
drivers/net/wireless/airo.c
··· 2918 flush_signals(current); 2919 2920 /* make swsusp happy with our thread */ 2921 - try_to_freeze(PF_FREEZE); 2922 2923 if (test_bit(JOB_DIE, &ai->flags)) 2924 break;
··· 2918 flush_signals(current); 2919 2920 /* make swsusp happy with our thread */ 2921 + try_to_freeze(); 2922 2923 if (test_bit(JOB_DIE, &ai->flags)) 2924 break;
+1 -1
drivers/pcmcia/cs.c
··· 718 } 719 720 schedule(); 721 - try_to_freeze(PF_FREEZE); 722 723 if (!skt->thread) 724 break;
··· 718 } 719 720 schedule(); 721 + try_to_freeze(); 722 723 if (!skt->thread) 724 break;
+1 -1
drivers/pnp/pnpbios/core.c
··· 182 msleep_interruptible(2000); 183 184 if(signal_pending(current)) { 185 - if (try_to_freeze(PF_FREEZE)) 186 continue; 187 break; 188 }
··· 182 msleep_interruptible(2000); 183 184 if(signal_pending(current)) { 185 + if (try_to_freeze()) 186 continue; 187 break; 188 }
+1 -1
drivers/usb/core/hub.c
··· 2808 do { 2809 hub_events(); 2810 wait_event_interruptible(khubd_wait, !list_empty(&hub_event_list)); 2811 - try_to_freeze(PF_FREEZE); 2812 } while (!signal_pending(current)); 2813 2814 pr_debug ("%s: khubd exiting\n", usbcore_name);
··· 2808 do { 2809 hub_events(); 2810 wait_event_interruptible(khubd_wait, !list_empty(&hub_event_list)); 2811 + try_to_freeze(); 2812 } while (!signal_pending(current)); 2813 2814 pr_debug ("%s: khubd exiting\n", usbcore_name);
+1 -2
drivers/usb/gadget/file_storage.c
··· 1554 rc = wait_event_interruptible(fsg->thread_wqh, 1555 fsg->thread_wakeup_needed); 1556 fsg->thread_wakeup_needed = 0; 1557 - if (current->flags & PF_FREEZE) 1558 - refrigerator(PF_FREEZE); 1559 return (rc ? -EINTR : 0); 1560 } 1561
··· 1554 rc = wait_event_interruptible(fsg->thread_wqh, 1555 fsg->thread_wakeup_needed); 1556 fsg->thread_wakeup_needed = 0; 1557 + try_to_freeze(); 1558 return (rc ? -EINTR : 0); 1559 } 1560
+1 -3
drivers/usb/storage/usb.c
··· 847 wait_event_interruptible_timeout(us->delay_wait, 848 test_bit(US_FLIDX_DISCONNECTING, &us->flags), 849 delay_use * HZ); 850 - if (current->flags & PF_FREEZE) { 851 - refrigerator(PF_FREEZE); 852 goto retry; 853 - } 854 } 855 856 /* If the device is still connected, perform the scanning */
··· 847 wait_event_interruptible_timeout(us->delay_wait, 848 test_bit(US_FLIDX_DISCONNECTING, &us->flags), 849 delay_use * HZ); 850 + if (try_to_freeze()) 851 goto retry; 852 } 853 854 /* If the device is still connected, perform the scanning */
+2 -2
drivers/w1/w1.c
··· 646 while (!control_needs_exit || have_to_wait) { 647 have_to_wait = 0; 648 649 - try_to_freeze(PF_FREEZE); 650 msleep_interruptible(w1_timeout * 1000); 651 652 if (signal_pending(current)) ··· 725 allow_signal(SIGTERM); 726 727 while (!test_bit(W1_MASTER_NEED_EXIT, &dev->flags)) { 728 - try_to_freeze(PF_FREEZE); 729 msleep_interruptible(w1_timeout * 1000); 730 731 if (signal_pending(current))
··· 646 while (!control_needs_exit || have_to_wait) { 647 have_to_wait = 0; 648 649 + try_to_freeze(); 650 msleep_interruptible(w1_timeout * 1000); 651 652 if (signal_pending(current)) ··· 725 allow_signal(SIGTERM); 726 727 while (!test_bit(W1_MASTER_NEED_EXIT, &dev->flags)) { 728 + try_to_freeze(); 729 msleep_interruptible(w1_timeout * 1000); 730 731 if (signal_pending(current))
+1 -1
fs/afs/kafsasyncd.c
··· 116 remove_wait_queue(&kafsasyncd_sleepq, &myself); 117 set_current_state(TASK_RUNNING); 118 119 - try_to_freeze(PF_FREEZE); 120 121 /* discard pending signals */ 122 afs_discard_my_signals();
··· 116 remove_wait_queue(&kafsasyncd_sleepq, &myself); 117 set_current_state(TASK_RUNNING); 118 119 + try_to_freeze(); 120 121 /* discard pending signals */ 122 afs_discard_my_signals();
+1 -1
fs/afs/kafstimod.c
··· 91 complete_and_exit(&kafstimod_dead, 0); 92 } 93 94 - try_to_freeze(PF_FREEZE); 95 96 /* discard pending signals */ 97 afs_discard_my_signals();
··· 91 complete_and_exit(&kafstimod_dead, 0); 92 } 93 94 + try_to_freeze(); 95 96 /* discard pending signals */ 97 afs_discard_my_signals();
+2 -2
fs/jbd/journal.c
··· 167 } 168 169 wake_up(&journal->j_wait_done_commit); 170 - if (current->flags & PF_FREEZE) { 171 /* 172 * The simpler the better. Flushing journal isn't a 173 * good idea, because that depends on threads that may ··· 175 */ 176 jbd_debug(1, "Now suspending kjournald\n"); 177 spin_unlock(&journal->j_state_lock); 178 - refrigerator(PF_FREEZE); 179 spin_lock(&journal->j_state_lock); 180 } else { 181 /*
··· 167 } 168 169 wake_up(&journal->j_wait_done_commit); 170 + if (freezing(current)) { 171 /* 172 * The simpler the better. Flushing journal isn't a 173 * good idea, because that depends on threads that may ··· 175 */ 176 jbd_debug(1, "Now suspending kjournald\n"); 177 spin_unlock(&journal->j_state_lock); 178 + refrigerator(); 179 spin_lock(&journal->j_state_lock); 180 } else { 181 /*
+2 -2
fs/jfs/jfs_logmgr.c
··· 2359 lbmStartIO(bp); 2360 spin_lock_irq(&log_redrive_lock); 2361 } 2362 - if (current->flags & PF_FREEZE) { 2363 spin_unlock_irq(&log_redrive_lock); 2364 - refrigerator(PF_FREEZE); 2365 } else { 2366 add_wait_queue(&jfs_IO_thread_wait, &wq); 2367 set_current_state(TASK_INTERRUPTIBLE);
··· 2359 lbmStartIO(bp); 2360 spin_lock_irq(&log_redrive_lock); 2361 } 2362 + if (freezing(current)) { 2363 spin_unlock_irq(&log_redrive_lock); 2364 + refrigerator(); 2365 } else { 2366 add_wait_queue(&jfs_IO_thread_wait, &wq); 2367 set_current_state(TASK_INTERRUPTIBLE);
+4 -4
fs/jfs/jfs_txnmgr.c
··· 2788 /* In case a wakeup came while all threads were active */ 2789 jfs_commit_thread_waking = 0; 2790 2791 - if (current->flags & PF_FREEZE) { 2792 LAZY_UNLOCK(flags); 2793 - refrigerator(PF_FREEZE); 2794 } else { 2795 DECLARE_WAITQUEUE(wq, current); 2796 ··· 2987 /* Add anon_list2 back to anon_list */ 2988 list_splice_init(&TxAnchor.anon_list2, &TxAnchor.anon_list); 2989 2990 - if (current->flags & PF_FREEZE) { 2991 TXN_UNLOCK(); 2992 - refrigerator(PF_FREEZE); 2993 } else { 2994 DECLARE_WAITQUEUE(wq, current); 2995
··· 2788 /* In case a wakeup came while all threads were active */ 2789 jfs_commit_thread_waking = 0; 2790 2791 + if (freezing(current)) { 2792 LAZY_UNLOCK(flags); 2793 + refrigerator(); 2794 } else { 2795 DECLARE_WAITQUEUE(wq, current); 2796 ··· 2987 /* Add anon_list2 back to anon_list */ 2988 list_splice_init(&TxAnchor.anon_list2, &TxAnchor.anon_list); 2989 2990 + if (freezing(current)) { 2991 TXN_UNLOCK(); 2992 + refrigerator(); 2993 } else { 2994 DECLARE_WAITQUEUE(wq, current); 2995
+1 -1
fs/lockd/clntproc.c
··· 313 prepare_to_wait(queue, &wait, TASK_INTERRUPTIBLE); 314 if (!signalled ()) { 315 schedule_timeout(NLMCLNT_GRACE_WAIT); 316 - try_to_freeze(PF_FREEZE); 317 if (!signalled ()) 318 status = 0; 319 }
··· 313 prepare_to_wait(queue, &wait, TASK_INTERRUPTIBLE); 314 if (!signalled ()) { 315 schedule_timeout(NLMCLNT_GRACE_WAIT); 316 + try_to_freeze(); 317 if (!signalled ()) 318 status = 0; 319 }
+2 -2
fs/xfs/linux-2.6/xfs_buf.c
··· 1771 1772 INIT_LIST_HEAD(&tmp); 1773 do { 1774 - if (unlikely(current->flags & PF_FREEZE)) { 1775 xfsbufd_force_sleep = 1; 1776 - refrigerator(PF_FREEZE); 1777 } else { 1778 xfsbufd_force_sleep = 0; 1779 }
··· 1771 1772 INIT_LIST_HEAD(&tmp); 1773 do { 1774 + if (unlikely(freezing(current))) { 1775 xfsbufd_force_sleep = 1; 1776 + refrigerator(); 1777 } else { 1778 xfsbufd_force_sleep = 0; 1779 }
+1 -1
fs/xfs/linux-2.6/xfs_super.c
··· 483 set_current_state(TASK_INTERRUPTIBLE); 484 timeleft = schedule_timeout(timeleft); 485 /* swsusp */ 486 - try_to_freeze(PF_FREEZE); 487 if (vfsp->vfs_flag & VFS_UMOUNT) 488 break; 489
··· 483 set_current_state(TASK_INTERRUPTIBLE); 484 timeleft = schedule_timeout(timeleft); 485 /* swsusp */ 486 + try_to_freeze(); 487 if (vfsp->vfs_flag & VFS_UMOUNT) 488 break; 489
+59 -14
include/linux/sched.h
··· 1265 1266 #endif 1267 1268 - /* try_to_freeze 1269 - * 1270 - * Checks whether we need to enter the refrigerator 1271 - * and returns 1 if we did so. 1272 - */ 1273 #ifdef CONFIG_PM 1274 - extern void refrigerator(unsigned long); 1275 extern int freeze_processes(void); 1276 extern void thaw_processes(void); 1277 1278 - static inline int try_to_freeze(unsigned long refrigerator_flags) 1279 { 1280 - if (unlikely(current->flags & PF_FREEZE)) { 1281 - refrigerator(refrigerator_flags); 1282 return 1; 1283 } else 1284 return 0; 1285 } 1286 #else 1287 - static inline void refrigerator(unsigned long flag) {} 1288 static inline int freeze_processes(void) { BUG(); return 0; } 1289 static inline void thaw_processes(void) {} 1290 1291 - static inline int try_to_freeze(unsigned long refrigerator_flags) 1292 - { 1293 - return 0; 1294 - } 1295 #endif /* CONFIG_PM */ 1296 #endif /* __KERNEL__ */ 1297
··· 1265 1266 #endif 1267 1268 #ifdef CONFIG_PM 1269 + /* 1270 + * Check if a process has been frozen 1271 + */ 1272 + static inline int frozen(struct task_struct *p) 1273 + { 1274 + return p->flags & PF_FROZEN; 1275 + } 1276 + 1277 + /* 1278 + * Check if there is a request to freeze a process 1279 + */ 1280 + static inline int freezing(struct task_struct *p) 1281 + { 1282 + return p->flags & PF_FREEZE; 1283 + } 1284 + 1285 + /* 1286 + * Request that a process be frozen 1287 + * FIXME: SMP problem. We may not modify other process' flags! 1288 + */ 1289 + static inline void freeze(struct task_struct *p) 1290 + { 1291 + p->flags |= PF_FREEZE; 1292 + } 1293 + 1294 + /* 1295 + * Wake up a frozen process 1296 + */ 1297 + static inline int thaw_process(struct task_struct *p) 1298 + { 1299 + if (frozen(p)) { 1300 + p->flags &= ~PF_FROZEN; 1301 + wake_up_process(p); 1302 + return 1; 1303 + } 1304 + return 0; 1305 + } 1306 + 1307 + /* 1308 + * freezing is complete, mark process as frozen 1309 + */ 1310 + static inline void frozen_process(struct task_struct *p) 1311 + { 1312 + p->flags = (p->flags & ~PF_FREEZE) | PF_FROZEN; 1313 + } 1314 + 1315 + extern void refrigerator(void); 1316 extern int freeze_processes(void); 1317 extern void thaw_processes(void); 1318 1319 + static inline int try_to_freeze(void) 1320 { 1321 + if (freezing(current)) { 1322 + refrigerator(); 1323 return 1; 1324 } else 1325 return 0; 1326 } 1327 #else 1328 + static inline int frozen(struct task_struct *p) { return 0; } 1329 + static inline int freezing(struct task_struct *p) { return 0; } 1330 + static inline void freeze(struct task_struct *p) { BUG(); } 1331 + static inline int thaw_process(struct task_struct *p) { return 1; } 1332 + static inline void frozen_process(struct task_struct *p) { BUG(); } 1333 + 1334 + static inline void refrigerator(void) {} 1335 static inline int freeze_processes(void) { BUG(); return 0; } 1336 static inline void thaw_processes(void) {} 1337 1338 + static inline int try_to_freeze(void) { return 0; } 1339 + 1340 #endif /* CONFIG_PM */ 1341 #endif /* __KERNEL__ */ 1342
+10 -16
kernel/power/process.c
··· 32 } 33 34 /* Refrigerator is place where frozen processes are stored :-). */ 35 - void refrigerator(unsigned long flag) 36 { 37 /* Hmm, should we be allowed to suspend when there are realtime 38 processes around? */ ··· 41 current->state = TASK_UNINTERRUPTIBLE; 42 pr_debug("%s entered refrigerator\n", current->comm); 43 printk("="); 44 - current->flags &= ~PF_FREEZE; 45 46 spin_lock_irq(&current->sighand->siglock); 47 recalc_sigpending(); /* We sent fake signal, clean it up */ 48 spin_unlock_irq(&current->sighand->siglock); 49 50 - current->flags |= PF_FROZEN; 51 - while (current->flags & PF_FROZEN) 52 schedule(); 53 pr_debug("%s left refrigerator\n", current->comm); 54 current->state = save; ··· 56 /* 0 = success, else # of processes that we failed to stop */ 57 int freeze_processes(void) 58 { 59 - int todo; 60 - unsigned long start_time; 61 struct task_struct *g, *p; 62 - 63 printk( "Stopping tasks: " ); 64 start_time = jiffies; 65 do { ··· 69 unsigned long flags; 70 if (!freezeable(p)) 71 continue; 72 - if ((p->flags & PF_FROZEN) || 73 (p->state == TASK_TRACED) || 74 (p->state == TASK_STOPPED)) 75 continue; 76 77 - /* FIXME: smp problem here: we may not access other process' flags 78 - without locking */ 79 - p->flags |= PF_FREEZE; 80 spin_lock_irqsave(&p->sighand->siglock, flags); 81 signal_wake_up(p, 0); 82 spin_unlock_irqrestore(&p->sighand->siglock, flags); ··· 88 return todo; 89 } 90 } while(todo); 91 - 92 printk( "|\n" ); 93 BUG_ON(in_atomic()); 94 return 0; ··· 103 do_each_thread(g, p) { 104 if (!freezeable(p)) 105 continue; 106 - if (p->flags & PF_FROZEN) { 107 - p->flags &= ~PF_FROZEN; 108 - wake_up_process(p); 109 - } else 110 printk(KERN_INFO " Strange, %s not stopped\n", p->comm ); 111 } while_each_thread(g, p); 112
··· 32 } 33 34 /* Refrigerator is place where frozen processes are stored :-). */ 35 + void refrigerator(void) 36 { 37 /* Hmm, should we be allowed to suspend when there are realtime 38 processes around? */ ··· 41 current->state = TASK_UNINTERRUPTIBLE; 42 pr_debug("%s entered refrigerator\n", current->comm); 43 printk("="); 44 45 + frozen_process(current); 46 spin_lock_irq(&current->sighand->siglock); 47 recalc_sigpending(); /* We sent fake signal, clean it up */ 48 spin_unlock_irq(&current->sighand->siglock); 49 50 + while (frozen(current)) 51 schedule(); 52 pr_debug("%s left refrigerator\n", current->comm); 53 current->state = save; ··· 57 /* 0 = success, else # of processes that we failed to stop */ 58 int freeze_processes(void) 59 { 60 + int todo; 61 + unsigned long start_time; 62 struct task_struct *g, *p; 63 + 64 printk( "Stopping tasks: " ); 65 start_time = jiffies; 66 do { ··· 70 unsigned long flags; 71 if (!freezeable(p)) 72 continue; 73 + if ((frozen(p)) || 74 (p->state == TASK_TRACED) || 75 (p->state == TASK_STOPPED)) 76 continue; 77 78 + freeze(p); 79 spin_lock_irqsave(&p->sighand->siglock, flags); 80 signal_wake_up(p, 0); 81 spin_unlock_irqrestore(&p->sighand->siglock, flags); ··· 91 return todo; 92 } 93 } while(todo); 94 + 95 printk( "|\n" ); 96 BUG_ON(in_atomic()); 97 return 0; ··· 106 do_each_thread(g, p) { 107 if (!freezeable(p)) 108 continue; 109 + if (!thaw_process(p)) 110 printk(KERN_INFO " Strange, %s not stopped\n", p->comm ); 111 } while_each_thread(g, p); 112
+1 -2
kernel/sched.c
··· 4335 struct list_head *head; 4336 migration_req_t *req; 4337 4338 - if (current->flags & PF_FREEZE) 4339 - refrigerator(PF_FREEZE); 4340 4341 spin_lock_irq(&rq->lock); 4342
··· 4335 struct list_head *head; 4336 migration_req_t *req; 4337 4338 + try_to_freeze(); 4339 4340 spin_lock_irq(&rq->lock); 4341
+2 -3
kernel/signal.c
··· 213 fastcall void recalc_sigpending_tsk(struct task_struct *t) 214 { 215 if (t->signal->group_stop_count > 0 || 216 - (t->flags & PF_FREEZE) || 217 PENDING(&t->pending, &t->blocked) || 218 PENDING(&t->signal->shared_pending, &t->blocked)) 219 set_tsk_thread_flag(t, TIF_SIGPENDING); ··· 2231 current->state = TASK_INTERRUPTIBLE; 2232 timeout = schedule_timeout(timeout); 2233 2234 - if (current->flags & PF_FREEZE) 2235 - refrigerator(PF_FREEZE); 2236 spin_lock_irq(&current->sighand->siglock); 2237 sig = dequeue_signal(current, &these, &info); 2238 current->blocked = current->real_blocked;
··· 213 fastcall void recalc_sigpending_tsk(struct task_struct *t) 214 { 215 if (t->signal->group_stop_count > 0 || 216 + (freezing(t)) || 217 PENDING(&t->pending, &t->blocked) || 218 PENDING(&t->signal->shared_pending, &t->blocked)) 219 set_tsk_thread_flag(t, TIF_SIGPENDING); ··· 2231 current->state = TASK_INTERRUPTIBLE; 2232 timeout = schedule_timeout(timeout); 2233 2234 + try_to_freeze(); 2235 spin_lock_irq(&current->sighand->siglock); 2236 sig = dequeue_signal(current, &these, &info); 2237 current->blocked = current->real_blocked;
+1 -1
mm/pdflush.c
··· 105 spin_unlock_irq(&pdflush_lock); 106 107 schedule(); 108 - if (try_to_freeze(PF_FREEZE)) { 109 spin_lock_irq(&pdflush_lock); 110 continue; 111 }
··· 105 spin_unlock_irq(&pdflush_lock); 106 107 schedule(); 108 + if (try_to_freeze()) { 109 spin_lock_irq(&pdflush_lock); 110 continue; 111 }
+2 -2
mm/vmscan.c
··· 1216 order = 0; 1217 for ( ; ; ) { 1218 unsigned long new_order; 1219 - if (current->flags & PF_FREEZE) 1220 - refrigerator(PF_FREEZE); 1221 1222 prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE); 1223 new_order = pgdat->kswapd_max_order;
··· 1216 order = 0; 1217 for ( ; ; ) { 1218 unsigned long new_order; 1219 + 1220 + try_to_freeze(); 1221 1222 prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE); 1223 new_order = pgdat->kswapd_max_order;
+1 -1
net/rxrpc/krxiod.c
··· 138 139 _debug("### End Work"); 140 141 - try_to_freeze(PF_FREEZE); 142 143 /* discard pending signals */ 144 rxrpc_discard_my_signals();
··· 138 139 _debug("### End Work"); 140 141 + try_to_freeze(); 142 143 /* discard pending signals */ 144 rxrpc_discard_my_signals();
+1 -1
net/rxrpc/krxsecd.c
··· 107 108 _debug("### End Inbound Calls"); 109 110 - try_to_freeze(PF_FREEZE); 111 112 /* discard pending signals */ 113 rxrpc_discard_my_signals();
··· 107 108 _debug("### End Inbound Calls"); 109 110 + try_to_freeze(); 111 112 /* discard pending signals */ 113 rxrpc_discard_my_signals();
+1 -1
net/rxrpc/krxtimod.c
··· 90 complete_and_exit(&krxtimod_dead, 0); 91 } 92 93 - try_to_freeze(PF_FREEZE); 94 95 /* discard pending signals */ 96 rxrpc_discard_my_signals();
··· 90 complete_and_exit(&krxtimod_dead, 0); 91 } 92 93 + try_to_freeze(); 94 95 /* discard pending signals */ 96 rxrpc_discard_my_signals();
+3 -3
net/sunrpc/svcsock.c
··· 1185 arg->page_len = (pages-2)*PAGE_SIZE; 1186 arg->len = (pages-1)*PAGE_SIZE; 1187 arg->tail[0].iov_len = 0; 1188 - 1189 - try_to_freeze(PF_FREEZE); 1190 if (signalled()) 1191 return -EINTR; 1192 ··· 1227 1228 schedule_timeout(timeout); 1229 1230 - try_to_freeze(PF_FREEZE); 1231 1232 spin_lock_bh(&serv->sv_lock); 1233 remove_wait_queue(&rqstp->rq_wait, &wait);
··· 1185 arg->page_len = (pages-2)*PAGE_SIZE; 1186 arg->len = (pages-1)*PAGE_SIZE; 1187 arg->tail[0].iov_len = 0; 1188 + 1189 + try_to_freeze(); 1190 if (signalled()) 1191 return -EINTR; 1192 ··· 1227 1228 schedule_timeout(timeout); 1229 1230 + try_to_freeze(); 1231 1232 spin_lock_bh(&serv->sv_lock); 1233 remove_wait_queue(&rqstp->rq_wait, &wait);