Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 280375
b: refs/heads/master
c: a320122
h: refs/heads/master
i:
  280373: 5a3f1cd
  280371: 435d5a5
  280367: e956e13
v: v3
  • Loading branch information
Tejun Heo committed Nov 21, 2011
1 parent 7ba4dfd commit faaaea9
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 50 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 22b4e111fa01a1147aa562ceaf18a752a928ef4e
refs/heads/master: a3201227f803ad7fd43180c5195dbe5a2bf998aa
33 changes: 12 additions & 21 deletions trunk/include/linux/freezer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@

#include <linux/sched.h>
#include <linux/wait.h>
#include <linux/atomic.h>

#ifdef CONFIG_FREEZER
extern atomic_t system_freezing_cnt; /* nr of freezing conds in effect */
extern bool pm_freezing; /* PM freezing in effect */
extern bool pm_nosig_freezing; /* PM nosig freezing in effect */

/*
* Check if a process has been frozen
*/
Expand All @@ -15,28 +20,16 @@ static inline int frozen(struct task_struct *p)
return p->flags & PF_FROZEN;
}

/*
* Check if there is a request to freeze a process
*/
static inline int freezing(struct task_struct *p)
{
return test_tsk_thread_flag(p, TIF_FREEZE);
}
extern bool freezing_slow_path(struct task_struct *p);

/*
* Request that a process be frozen
*/
static inline void set_freeze_flag(struct task_struct *p)
{
set_tsk_thread_flag(p, TIF_FREEZE);
}

/*
* Sometimes we may need to cancel the previous 'freeze' request
* Check if there is a request to freeze a process
*/
static inline void clear_freeze_flag(struct task_struct *p)
static inline bool freezing(struct task_struct *p)
{
clear_tsk_thread_flag(p, TIF_FREEZE);
if (likely(!atomic_read(&system_freezing_cnt)))
return false;
return freezing_slow_path(p);
}

static inline bool should_send_signal(struct task_struct *p)
Expand Down Expand Up @@ -174,9 +167,7 @@ static inline void set_freezable_with_signal(void)
})
#else /* !CONFIG_FREEZER */
static inline int frozen(struct task_struct *p) { return 0; }
static inline int freezing(struct task_struct *p) { return 0; }
static inline void set_freeze_flag(struct task_struct *p) {}
static inline void clear_freeze_flag(struct task_struct *p) {}
static inline bool freezing(struct task_struct *p) { return false; }

static inline bool __refrigerator(bool check_kthr_stop) { return false; }
static inline int freeze_processes(void) { return -ENOSYS; }
Expand Down
10 changes: 9 additions & 1 deletion trunk/kernel/cgroup_freezer.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,11 @@ static struct cgroup_subsys_state *freezer_create(struct cgroup_subsys *ss,
static void freezer_destroy(struct cgroup_subsys *ss,
struct cgroup *cgroup)
{
kfree(cgroup_freezer(cgroup));
struct freezer *freezer = cgroup_freezer(cgroup);

if (freezer->state != CGROUP_THAWED)
atomic_dec(&system_freezing_cnt);
kfree(freezer);
}

/*
Expand Down Expand Up @@ -307,10 +311,14 @@ static int freezer_change_state(struct cgroup *cgroup,

switch (goal_state) {
case CGROUP_THAWED:
if (freezer->state != CGROUP_THAWED)
atomic_dec(&system_freezing_cnt);
freezer->state = CGROUP_THAWED;
unfreeze_cgroup(cgroup, freezer);
break;
case CGROUP_FROZEN:
if (freezer->state == CGROUP_THAWED)
atomic_inc(&system_freezing_cnt);
freezer->state = CGROUP_FREEZING;
retval = try_to_freeze_cgroup(cgroup, freezer);
break;
Expand Down
1 change: 0 additions & 1 deletion trunk/kernel/fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,6 @@ static void copy_flags(unsigned long clone_flags, struct task_struct *p)
new_flags |= PF_FORKNOEXEC;
new_flags |= PF_STARTING;
p->flags = new_flags;
clear_freeze_flag(p);
}

SYSCALL_DEFINE1(set_tid_address, int __user *, tidptr)
Expand Down
62 changes: 40 additions & 22 deletions trunk/kernel/freezer.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,41 @@
#include <linux/freezer.h>
#include <linux/kthread.h>

/* total number of freezing conditions in effect */
atomic_t system_freezing_cnt = ATOMIC_INIT(0);
EXPORT_SYMBOL(system_freezing_cnt);

/* indicate whether PM freezing is in effect, protected by pm_mutex */
bool pm_freezing;
bool pm_nosig_freezing;

/* protects freezing and frozen transitions */
static DEFINE_SPINLOCK(freezer_lock);

/**
* freezing_slow_path - slow path for testing whether a task needs to be frozen
* @p: task to be tested
*
* This function is called by freezing() if system_freezing_cnt isn't zero
* and tests whether @p needs to enter and stay in frozen state. Can be
* called under any context. The freezers are responsible for ensuring the
* target tasks see the updated state.
*/
bool freezing_slow_path(struct task_struct *p)
{
if (p->flags & PF_NOFREEZE)
return false;

if (pm_nosig_freezing || cgroup_freezing(p))
return true;

if (pm_freezing && !(p->flags & PF_FREEZER_NOSIG))
return true;

return false;
}
EXPORT_SYMBOL(freezing_slow_path);

/* Refrigerator is place where frozen processes are stored :-). */
bool __refrigerator(bool check_kthr_stop)
{
Expand All @@ -23,17 +55,11 @@ bool __refrigerator(bool check_kthr_stop)
long save;

/*
* Enter FROZEN. If NOFREEZE, schedule immediate thawing by
* clearing freezing.
* No point in checking freezing() again - the caller already did.
* Proceed to enter FROZEN.
*/
spin_lock_irq(&freezer_lock);
repeat:
if (!freezing(current)) {
spin_unlock_irq(&freezer_lock);
return was_frozen;
}
if (current->flags & PF_NOFREEZE)
clear_freeze_flag(current);
current->flags |= PF_FROZEN;
spin_unlock_irq(&freezer_lock);

Expand Down Expand Up @@ -99,18 +125,12 @@ static void fake_signal_wake_up(struct task_struct *p)
bool freeze_task(struct task_struct *p, bool sig_only)
{
unsigned long flags;
bool ret = false;

spin_lock_irqsave(&freezer_lock, flags);

if ((p->flags & PF_NOFREEZE) ||
(sig_only && !should_send_signal(p)))
goto out_unlock;

if (frozen(p))
goto out_unlock;

set_freeze_flag(p);
if (!freezing(p) || frozen(p)) {
spin_unlock_irqrestore(&freezer_lock, flags);
return false;
}

if (should_send_signal(p)) {
fake_signal_wake_up(p);
Expand All @@ -123,10 +143,9 @@ bool freeze_task(struct task_struct *p, bool sig_only)
} else {
wake_up_state(p, TASK_INTERRUPTIBLE);
}
ret = true;
out_unlock:

spin_unlock_irqrestore(&freezer_lock, flags);
return ret;
return true;
}

void __thaw_task(struct task_struct *p)
Expand All @@ -143,7 +162,6 @@ void __thaw_task(struct task_struct *p)
* avoid leaving dangling TIF_SIGPENDING behind.
*/
spin_lock_irqsave(&freezer_lock, flags);
clear_freeze_flag(p);
if (frozen(p)) {
wake_up_process(p);
} else {
Expand Down
15 changes: 11 additions & 4 deletions trunk/kernel/power/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ static int try_to_freeze_tasks(bool sig_only)
read_lock(&tasklist_lock);
do_each_thread(g, p) {
if (!wakeup && !freezer_should_skip(p) &&
freezing(p) && !frozen(p))
p != current && freezing(p) && !frozen(p))
sched_show_task(p);
} while_each_thread(g, p);
read_unlock(&tasklist_lock);
Expand All @@ -122,7 +122,11 @@ int freeze_processes(void)
{
int error;

if (!pm_freezing)
atomic_inc(&system_freezing_cnt);

printk("Freezing user space processes ... ");
pm_freezing = true;
error = try_to_freeze_tasks(true);
if (!error) {
printk("done.");
Expand All @@ -146,6 +150,7 @@ int freeze_kernel_threads(void)
int error;

printk("Freezing remaining freezable tasks ... ");
pm_nosig_freezing = true;
error = try_to_freeze_tasks(false);
if (!error)
printk("done.");
Expand All @@ -162,6 +167,11 @@ void thaw_processes(void)
{
struct task_struct *g, *p;

if (pm_freezing)
atomic_dec(&system_freezing_cnt);
pm_freezing = false;
pm_nosig_freezing = false;

oom_killer_enable();

printk("Restarting tasks ... ");
Expand All @@ -170,9 +180,6 @@ void thaw_processes(void)

read_lock(&tasklist_lock);
do_each_thread(g, p) {
if (cgroup_freezing(p))
continue;

__thaw_task(p);
} while_each_thread(g, p);
read_unlock(&tasklist_lock);
Expand Down

0 comments on commit faaaea9

Please sign in to comment.