Skip to content

Commit fbd705a

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
sched: Introduce the 'trace_sched_waking' tracepoint
Mathieu reported that since 317f394 ("sched: Move the second half of ttwu() to the remote cpu") trace_sched_wakeup() can happen out of context of the waker. This is a problem when you want to analyse wakeup paths because it is now very hard to correlate the wakeup event to whoever issued the wakeup. OTOH trace_sched_wakeup() is issued at the point where we set p->state = TASK_RUNNING, which is right were we hand the task off to the scheduler, so this is an important point when looking at scheduling behaviour, up to here its been the wakeup path everything hereafter is due to scheduler policy. To bridge this gap, introduce a second tracepoint: trace_sched_waking. It is guaranteed to be called in the waker context. Reported-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Francis Giraldeau <francis.giraldeau@gmail.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Mike Galbraith <efault@gmx.de> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/20150609091336.GQ3644@twins.programming.kicks-ass.net Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 9d7fb04 commit fbd705a

File tree

4 files changed

+30
-14
lines changed

4 files changed

+30
-14
lines changed

include/trace/events/sched.h

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ TRACE_EVENT(sched_kthread_stop_ret,
5555
*/
5656
DECLARE_EVENT_CLASS(sched_wakeup_template,
5757

58-
TP_PROTO(struct task_struct *p, int success),
58+
TP_PROTO(struct task_struct *p),
5959

60-
TP_ARGS(__perf_task(p), success),
60+
TP_ARGS(__perf_task(p)),
6161

6262
TP_STRUCT__entry(
6363
__array( char, comm, TASK_COMM_LEN )
@@ -71,25 +71,37 @@ DECLARE_EVENT_CLASS(sched_wakeup_template,
7171
memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
7272
__entry->pid = p->pid;
7373
__entry->prio = p->prio;
74-
__entry->success = success;
74+
__entry->success = 1; /* rudiment, kill when possible */
7575
__entry->target_cpu = task_cpu(p);
7676
),
7777

78-
TP_printk("comm=%s pid=%d prio=%d success=%d target_cpu=%03d",
78+
TP_printk("comm=%s pid=%d prio=%d target_cpu=%03d",
7979
__entry->comm, __entry->pid, __entry->prio,
80-
__entry->success, __entry->target_cpu)
80+
__entry->target_cpu)
8181
);
8282

83+
/*
84+
* Tracepoint called when waking a task; this tracepoint is guaranteed to be
85+
* called from the waking context.
86+
*/
87+
DEFINE_EVENT(sched_wakeup_template, sched_waking,
88+
TP_PROTO(struct task_struct *p),
89+
TP_ARGS(p));
90+
91+
/*
92+
* Tracepoint called when the task is actually woken; p->state == TASK_RUNNNG.
93+
* It it not always called from the waking context.
94+
*/
8395
DEFINE_EVENT(sched_wakeup_template, sched_wakeup,
84-
TP_PROTO(struct task_struct *p, int success),
85-
TP_ARGS(p, success));
96+
TP_PROTO(struct task_struct *p),
97+
TP_ARGS(p));
8698

8799
/*
88100
* Tracepoint for waking up a new task:
89101
*/
90102
DEFINE_EVENT(sched_wakeup_template, sched_wakeup_new,
91-
TP_PROTO(struct task_struct *p, int success),
92-
TP_ARGS(p, success));
103+
TP_PROTO(struct task_struct *p),
104+
TP_ARGS(p));
93105

94106
#ifdef CREATE_TRACE_POINTS
95107
static inline long __trace_sched_switch_state(struct task_struct *p)

kernel/sched/core.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,9 +1654,9 @@ static void
16541654
ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags)
16551655
{
16561656
check_preempt_curr(rq, p, wake_flags);
1657-
trace_sched_wakeup(p, true);
1658-
16591657
p->state = TASK_RUNNING;
1658+
trace_sched_wakeup(p);
1659+
16601660
#ifdef CONFIG_SMP
16611661
if (p->sched_class->task_woken) {
16621662
/*
@@ -1874,6 +1874,8 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
18741874
if (!(p->state & state))
18751875
goto out;
18761876

1877+
trace_sched_waking(p);
1878+
18771879
success = 1; /* we're going to change ->state */
18781880
cpu = task_cpu(p);
18791881

@@ -1949,6 +1951,8 @@ static void try_to_wake_up_local(struct task_struct *p)
19491951
if (!(p->state & TASK_NORMAL))
19501952
goto out;
19511953

1954+
trace_sched_waking(p);
1955+
19521956
if (!task_on_rq_queued(p))
19531957
ttwu_activate(rq, p, ENQUEUE_WAKEUP);
19541958

@@ -2307,7 +2311,7 @@ void wake_up_new_task(struct task_struct *p)
23072311
rq = __task_rq_lock(p);
23082312
activate_task(rq, p, 0);
23092313
p->on_rq = TASK_ON_RQ_QUEUED;
2310-
trace_sched_wakeup_new(p, true);
2314+
trace_sched_wakeup_new(p);
23112315
check_preempt_curr(rq, p, WF_FORK);
23122316
#ifdef CONFIG_SMP
23132317
if (p->sched_class->task_woken)

kernel/trace/trace_sched_switch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ probe_sched_switch(void *ignore, struct task_struct *prev, struct task_struct *n
2626
}
2727

2828
static void
29-
probe_sched_wakeup(void *ignore, struct task_struct *wakee, int success)
29+
probe_sched_wakeup(void *ignore, struct task_struct *wakee)
3030
{
3131
if (unlikely(!sched_ref))
3232
return;

kernel/trace/trace_sched_wakeup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ static void wakeup_reset(struct trace_array *tr)
514514
}
515515

516516
static void
517-
probe_wakeup(void *ignore, struct task_struct *p, int success)
517+
probe_wakeup(void *ignore, struct task_struct *p)
518518
{
519519
struct trace_array_cpu *data;
520520
int cpu = smp_processor_id();

0 commit comments

Comments
 (0)