Commit 9ed3811a authored by Tejun Heo's avatar Tejun Heo

sched: refactor try_to_wake_up()

Factor ttwu_activate() and ttwu_woken_up() out of try_to_wake_up().
The factoring out doesn't affect try_to_wake_up() much
code-generation-wise.  Depending on configuration options, it ends up
generating the same object code as before or slightly different one
due to different register assignment.

This is to help future implementation of try_to_wake_up_local().

Mike Galbraith suggested rename to ttwu_post_activation() from
ttwu_woken_up() and comment update in try_to_wake_up().
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Acked-by: default avatarPeter Zijlstra <peterz@infradead.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Ingo Molnar <mingo@elte.hu>
parent 3a101d05
...@@ -2267,11 +2267,52 @@ static void update_avg(u64 *avg, u64 sample) ...@@ -2267,11 +2267,52 @@ static void update_avg(u64 *avg, u64 sample)
} }
#endif #endif
/*** static inline void ttwu_activate(struct task_struct *p, struct rq *rq,
bool is_sync, bool is_migrate, bool is_local,
unsigned long en_flags)
{
schedstat_inc(p, se.statistics.nr_wakeups);
if (is_sync)
schedstat_inc(p, se.statistics.nr_wakeups_sync);
if (is_migrate)
schedstat_inc(p, se.statistics.nr_wakeups_migrate);
if (is_local)
schedstat_inc(p, se.statistics.nr_wakeups_local);
else
schedstat_inc(p, se.statistics.nr_wakeups_remote);
activate_task(rq, p, en_flags);
}
static inline void ttwu_post_activation(struct task_struct *p, struct rq *rq,
int wake_flags, bool success)
{
trace_sched_wakeup(p, success);
check_preempt_curr(rq, p, wake_flags);
p->state = TASK_RUNNING;
#ifdef CONFIG_SMP
if (p->sched_class->task_woken)
p->sched_class->task_woken(rq, p);
if (unlikely(rq->idle_stamp)) {
u64 delta = rq->clock - rq->idle_stamp;
u64 max = 2*sysctl_sched_migration_cost;
if (delta > max)
rq->avg_idle = max;
else
update_avg(&rq->avg_idle, delta);
rq->idle_stamp = 0;
}
#endif
}
/**
* try_to_wake_up - wake up a thread * try_to_wake_up - wake up a thread
* @p: the to-be-woken-up thread * @p: the thread to be awakened
* @state: the mask of task states that can be woken * @state: the mask of task states that can be woken
* @sync: do a synchronous wakeup? * @wake_flags: wake modifier flags (WF_*)
* *
* Put it on the run-queue if it's not already there. The "current" * Put it on the run-queue if it's not already there. The "current"
* thread is always on the run-queue (except when the actual * thread is always on the run-queue (except when the actual
...@@ -2279,7 +2320,8 @@ static void update_avg(u64 *avg, u64 sample) ...@@ -2279,7 +2320,8 @@ static void update_avg(u64 *avg, u64 sample)
* the simpler "current->state = TASK_RUNNING" to mark yourself * the simpler "current->state = TASK_RUNNING" to mark yourself
* runnable without the overhead of this. * runnable without the overhead of this.
* *
* returns failure only if the task is already active. * Returns %true if @p was woken up, %false if it was already running
* or @state didn't match @p's state.
*/ */
static int try_to_wake_up(struct task_struct *p, unsigned int state, static int try_to_wake_up(struct task_struct *p, unsigned int state,
int wake_flags) int wake_flags)
...@@ -2359,38 +2401,11 @@ static int try_to_wake_up(struct task_struct *p, unsigned int state, ...@@ -2359,38 +2401,11 @@ static int try_to_wake_up(struct task_struct *p, unsigned int state,
out_activate: out_activate:
#endif /* CONFIG_SMP */ #endif /* CONFIG_SMP */
schedstat_inc(p, se.statistics.nr_wakeups); ttwu_activate(p, rq, wake_flags & WF_SYNC, orig_cpu != cpu,
if (wake_flags & WF_SYNC) cpu == this_cpu, en_flags);
schedstat_inc(p, se.statistics.nr_wakeups_sync);
if (orig_cpu != cpu)
schedstat_inc(p, se.statistics.nr_wakeups_migrate);
if (cpu == this_cpu)
schedstat_inc(p, se.statistics.nr_wakeups_local);
else
schedstat_inc(p, se.statistics.nr_wakeups_remote);
activate_task(rq, p, en_flags);
success = 1; success = 1;
out_running: out_running:
trace_sched_wakeup(p, success); ttwu_post_activation(p, rq, wake_flags, success);
check_preempt_curr(rq, p, wake_flags);
p->state = TASK_RUNNING;
#ifdef CONFIG_SMP
if (p->sched_class->task_woken)
p->sched_class->task_woken(rq, p);
if (unlikely(rq->idle_stamp)) {
u64 delta = rq->clock - rq->idle_stamp;
u64 max = 2*sysctl_sched_migration_cost;
if (delta > max)
rq->avg_idle = max;
else
update_avg(&rq->avg_idle, delta);
rq->idle_stamp = 0;
}
#endif
out: out:
task_rq_unlock(rq, &flags); task_rq_unlock(rq, &flags);
put_cpu(); put_cpu();
......
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