* [lttng-dev] [RFC PATCH] sched: Fix sched_wakeup tracepoint
[not found] ` <1433592142.1495.22.camel@twins>
@ 2015-06-07 10:20 ` Mathieu Desnoyers
2015-06-08 17:27 ` Steven Rostedt
0 siblings, 1 reply; 6+ messages in thread
From: Mathieu Desnoyers @ 2015-06-07 10:20 UTC (permalink / raw)
----- On Jun 6, 2015, at 2:02 PM, Peter Zijlstra peterz at infradead.org wrote:
> On Fri, 2015-06-05 at 13:23 +0000, Mathieu Desnoyers wrote:
>> OK, so considering the definition naming feedback you provided, we
>> may need a 3 tracepoint if we want to calculate both wakeup latency
>> and scheduling latency (naming ofc open to discussion):
>>
>> sched_wakeup: when try_to_wake_up{,_local} is called in the waker.
>> sched_activate_task: when the wakee is marked runnable.
>> sched_switch: when scheduling actually happens.
>
> I would propose:
>
> sched_waking: upon calling try_to_wake_up() as soon as we know we need
> to change state; guaranteed to be called from the context doing the
> wakeup.
>
> sched_woken: the wakeup is complete (task is runnable, any delay
> between this and actually getting on a cpu is down to the scheduler).
>
> sched_switch: when switching from task @prev to @next.
Agreed,
>
> This means abandoning trace_sched_wakeup(); which might be a problem,
> which is why I bloody hate tracepoints :-(
OK. I guess it's about time we dive into that question. Should tracepoint
semantic be kept cast in stone forever ? Not in my opinion, and here is why.
Most of the Linux kernel ABI exposed to userspace serves as support to
runtime (system calls, virtual file systems, etc). For all that, it makes
tons of sense to keep it stable, following the Documentation/ABI/README
guidelines. Even there, we have provisions for obsolescence and removal
of an ABI if need be, which provides userspace some time to adapt to
changes.
How are tracepoints different ? Well, those are not meant to be used in
runtime support, but rather for analyzing systems, which means that
userspace tools using the tracepoint content do not need it to _run_,
but rather as information source to perform analyses.
Even though I dislike analogies, I think we need one here. Let's consider
CAN bus ports for car debugging. Even though the transport is covered by
standards, it does not mandate the semantics of the data per se. I would
not expect a debugging device made in 2005 to work for newest generations
of car. However, I would expect that new debug devices are compatible with
older cars, and that those debug devices have means to query which type of
car it is debugging. Otherwise, the debugging device is simply crap,
because it cannot adapt to change. What should a debug device created in
2005 do if connected to a new car ? Ideally, it should gracefully decline
to interact with this car, and require a software upgrade.
OK, now back to kernel tracepoints. My opinion is that it is a fundamental
requirement that trace analysis tools should be able to detect that they
are unable understand tracepoint data they care about. It seems perfectly
fine to me to require that analysis tool upgrades are needed to interact
with a new kernel. However, a tool should be able to handle a range of
older kernel versions too.
This can be done by many means, including making sure preexisting event name
and fields semantic are immutable, or by versioning of tracepoints on a
per-event basis.
Here, in the case of sched_wakeup: we end up noticing that it accidentally
changed location in the kernel across versions, which makes it useless for
many analyses unless they use kernel version information to get the right
semantic associated with this event.
So here, for introducing sched_waking/sched_woken, we have a few ways
forward:
1) Keep sched_wakeup as it is, and add those two new events. Analyses
can then continue using the old event for a while, and if they sees
that sched_waking/sched_woken are there, they can use those more
precise events instead. This could allow us to do a gradual
deprecation phase for the sched_wakeup tracepoint.
2) Remove sched_wakeup event, replacing it by sched_waking/sched_woken.
Require immediate analysis tool upgrade to deal with this new
information. Old tools should gracefully fail and ask users to
upgrade. If they don't, fix them so they can handle change.
Thoughts ?
Thanks,
Mathieu
--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* [lttng-dev] [RFC PATCH] sched: Fix sched_wakeup tracepoint
2015-06-07 10:20 ` [lttng-dev] [RFC PATCH] sched: Fix sched_wakeup tracepoint Mathieu Desnoyers
@ 2015-06-08 17:27 ` Steven Rostedt
2015-06-09 9:13 ` Peter Zijlstra
0 siblings, 1 reply; 6+ messages in thread
From: Steven Rostedt @ 2015-06-08 17:27 UTC (permalink / raw)
[ Keeping entire email because I added Linus ]
On Sun, 7 Jun 2015 10:20:14 +0000 (UTC)
Mathieu Desnoyers <mathieu.desnoyers at efficios.com> wrote:
> ----- On Jun 6, 2015, at 2:02 PM, Peter Zijlstra peterz at infradead.org wrote:
>
> > On Fri, 2015-06-05 at 13:23 +0000, Mathieu Desnoyers wrote:
> >> OK, so considering the definition naming feedback you provided, we
> >> may need a 3 tracepoint if we want to calculate both wakeup latency
> >> and scheduling latency (naming ofc open to discussion):
> >>
> >> sched_wakeup: when try_to_wake_up{,_local} is called in the waker.
> >> sched_activate_task: when the wakee is marked runnable.
> >> sched_switch: when scheduling actually happens.
> >
> > I would propose:
> >
> > sched_waking: upon calling try_to_wake_up() as soon as we know we need
> > to change state; guaranteed to be called from the context doing the
> > wakeup.
> >
> > sched_woken: the wakeup is complete (task is runnable, any delay
> > between this and actually getting on a cpu is down to the scheduler).
> >
> > sched_switch: when switching from task @prev to @next.
>
> Agreed,
>
> >
> > This means abandoning trace_sched_wakeup(); which might be a problem,
> > which is why I bloody hate tracepoints :-(
>
> OK. I guess it's about time we dive into that question. Should tracepoint
> semantic be kept cast in stone forever ? Not in my opinion, and here is why.
>
> Most of the Linux kernel ABI exposed to userspace serves as support to
> runtime (system calls, virtual file systems, etc). For all that, it makes
> tons of sense to keep it stable, following the Documentation/ABI/README
> guidelines. Even there, we have provisions for obsolescence and removal
> of an ABI if need be, which provides userspace some time to adapt to
> changes.
>
> How are tracepoints different ? Well, those are not meant to be used in
> runtime support, but rather for analyzing systems, which means that
> userspace tools using the tracepoint content do not need it to _run_,
> but rather as information source to perform analyses.
>
> Even though I dislike analogies, I think we need one here. Let's consider
> CAN bus ports for car debugging. Even though the transport is covered by
> standards, it does not mandate the semantics of the data per se. I would
> not expect a debugging device made in 2005 to work for newest generations
> of car. However, I would expect that new debug devices are compatible with
> older cars, and that those debug devices have means to query which type of
> car it is debugging. Otherwise, the debugging device is simply crap,
> because it cannot adapt to change. What should a debug device created in
> 2005 do if connected to a new car ? Ideally, it should gracefully decline
> to interact with this car, and require a software upgrade.
>
> OK, now back to kernel tracepoints. My opinion is that it is a fundamental
> requirement that trace analysis tools should be able to detect that they
> are unable understand tracepoint data they care about. It seems perfectly
> fine to me to require that analysis tool upgrades are needed to interact
> with a new kernel. However, a tool should be able to handle a range of
> older kernel versions too.
>
> This can be done by many means, including making sure preexisting event name
> and fields semantic are immutable, or by versioning of tracepoints on a
> per-event basis.
>
> Here, in the case of sched_wakeup: we end up noticing that it accidentally
> changed location in the kernel across versions, which makes it useless for
> many analyses unless they use kernel version information to get the right
> semantic associated with this event.
>
> So here, for introducing sched_waking/sched_woken, we have a few ways
> forward:
>
> 1) Keep sched_wakeup as it is, and add those two new events. Analyses
> can then continue using the old event for a while, and if they sees
> that sched_waking/sched_woken are there, they can use those more
> precise events instead. This could allow us to do a gradual
> deprecation phase for the sched_wakeup tracepoint.
>
> 2) Remove sched_wakeup event, replacing it by sched_waking/sched_woken.
> Require immediate analysis tool upgrade to deal with this new
> information. Old tools should gracefully fail and ask users to
> upgrade. If they don't, fix them so they can handle change.
2 will break tools and even if they fail "gracefully" that probably
still isn't acceptable as the sched_wakeup tracepoint is a popular one.
3) Add the two tracepoints and remove the sched_wakeup() one, but
then add a manual tracepoint for perf and ftrace that can simulate
the sched_wakeup() from the other two tracepoints. This should keep
tools working and we can have better wake up tracepoints implemented,
without the overhead of the third "obsolete" tracepoint in the
scheduling code.
-- Steve
^ permalink raw reply [flat|nested] 6+ messages in thread
* [lttng-dev] [RFC PATCH] sched: Fix sched_wakeup tracepoint
2015-06-08 17:27 ` Steven Rostedt
@ 2015-06-09 9:13 ` Peter Zijlstra
2015-06-09 18:48 ` Mathieu Desnoyers
2015-06-17 18:23 ` Cong Wang
0 siblings, 2 replies; 6+ messages in thread
From: Peter Zijlstra @ 2015-06-09 9:13 UTC (permalink / raw)
So how about we introduce the 'waking' tracepoint and leave the existing
wakeup one in place and preserve its woken semantics.
Steven, can we do aliases? Where one tracepoint is known to userspace
under multiple names? In that case we could rename the thing to woken
and have an alias wakeup which we can phase out over time.
The patch also takes away the success parameter to the tracepoint, but
does not quite go as far as actually removing it from the tracepoint
itself.
We can do that in a follow up patch which we can quickly revert if it
turns out people are actually still using that for something.
---
include/trace/events/sched.h | 28 ++++++++++++++++++++--------
kernel/sched/core.c | 9 ++++++---
2 files changed, 26 insertions(+), 11 deletions(-)
diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h
index d57a575fe31f..b1608d5679e2 100644
--- a/include/trace/events/sched.h
+++ b/include/trace/events/sched.h
@@ -55,7 +55,7 @@ TRACE_EVENT(sched_kthread_stop_ret,
*/
DECLARE_EVENT_CLASS(sched_wakeup_template,
- TP_PROTO(struct task_struct *p, int success),
+ TP_PROTO(struct task_struct *p),
TP_ARGS(__perf_task(p), success),
@@ -71,25 +71,37 @@ DECLARE_EVENT_CLASS(sched_wakeup_template,
memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
__entry->pid = p->pid;
__entry->prio = p->prio;
- __entry->success = success;
+ __entry->success = 1; /* rudiment, kill when possible */
__entry->target_cpu = task_cpu(p);
),
- TP_printk("comm=%s pid=%d prio=%d success=%d target_cpu=%03d",
+ TP_printk("comm=%s pid=%d prio=%d target_cpu=%03d",
__entry->comm, __entry->pid, __entry->prio,
- __entry->success, __entry->target_cpu)
+ __entry->target_cpu)
);
+/*
+ * Tracepoint called when waking a task; this tracepoint is guaranteed to be
+ * called from the waking context.
+ */
+DEFINE_EVENT(sched_wakeup_template, sched_waking,
+ TP_PROTO(struct task_struct *p),
+ TP_ARGS(p));
+
+/*
+ * Tracepoint called when the task is actually woken; p->state == TASK_RUNNNG.
+ * It it not always called from the waking context.
+ */
DEFINE_EVENT(sched_wakeup_template, sched_wakeup,
- TP_PROTO(struct task_struct *p, int success),
- TP_ARGS(p, success));
+ TP_PROTO(struct task_struct *p),
+ TP_ARGS(p));
/*
* Tracepoint for waking up a new task:
*/
DEFINE_EVENT(sched_wakeup_template, sched_wakeup_new,
- TP_PROTO(struct task_struct *p, int success),
- TP_ARGS(p, success));
+ TP_PROTO(struct task_struct *p),
+ TP_ARGS(p));
#ifdef CREATE_TRACE_POINTS
static inline long __trace_sched_switch_state(struct task_struct *p)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index d5078c0f20e6..354e667620a9 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -1487,9 +1487,9 @@ static void
ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags)
{
check_preempt_curr(rq, p, wake_flags);
- trace_sched_wakeup(p, true);
-
p->state = TASK_RUNNING;
+ trace_sched_wakeup(p);
+
#ifdef CONFIG_SMP
if (p->sched_class->task_woken)
p->sched_class->task_woken(rq, p);
@@ -1695,6 +1695,7 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
goto out;
success = 1; /* we're going to change ->state */
+ trace_sched_waking(p);
cpu = task_cpu(p);
if (p->on_rq && ttwu_remote(p, wake_flags))
@@ -1761,6 +1762,8 @@ static void try_to_wake_up_local(struct task_struct *p)
if (!(p->state & TASK_NORMAL))
goto out;
+ trace_sched_waking(p);
+
if (!task_on_rq_queued(p))
ttwu_activate(rq, p, ENQUEUE_WAKEUP);
@@ -2119,7 +2122,7 @@ void wake_up_new_task(struct task_struct *p)
rq = __task_rq_lock(p);
activate_task(rq, p, 0);
p->on_rq = TASK_ON_RQ_QUEUED;
- trace_sched_wakeup_new(p, true);
+ trace_sched_wakeup_new(p);
check_preempt_curr(rq, p, WF_FORK);
#ifdef CONFIG_SMP
if (p->sched_class->task_woken)
^ permalink raw reply [flat|nested] 6+ messages in thread
* [lttng-dev] [RFC PATCH] sched: Fix sched_wakeup tracepoint
2015-06-09 9:13 ` Peter Zijlstra
@ 2015-06-09 18:48 ` Mathieu Desnoyers
2015-06-17 18:23 ` Cong Wang
1 sibling, 0 replies; 6+ messages in thread
From: Mathieu Desnoyers @ 2015-06-09 18:48 UTC (permalink / raw)
----- On Jun 9, 2015, at 11:13 AM, Peter Zijlstra peterz at infradead.org wrote:
> So how about we introduce the 'waking' tracepoint and leave the existing
> wakeup one in place and preserve its woken semantics.
That would work for me, but leaves me wondering how you would move
to the new 'woken' name.
>
> Steven, can we do aliases? Where one tracepoint is known to userspace
> under multiple names? In that case we could rename the thing to woken
> and have an alias wakeup which we can phase out over time.
In LTTng, I have a LTTNG_TRACEPOINT_EVENT_MAP() macro, which allows me
to map a kernel event to my own event naming scheme. It allows me
to correct namespacing of some odd kernel tracepoints from within the
tracer. A similar implementation could be used to implement a tracepoint
alias within the kernel: one parameter is the named as exposed to userspace,
and the other field is the name of the tracepoint it hooks to.
You could then rename the tracepoint name from 'wakeup' to 'woken', and
create an alias exposing the old 'wakeup' event.
>
> The patch also takes away the success parameter to the tracepoint, but
> does not quite go as far as actually removing it from the tracepoint
> itself.
Sounds like a good intermediate step. If you ensure that the alias
declaration allows you to show a different set of fields for the alias,
you could even remove the success parameter from 'woken', and only show
it for the 'wakeup' alias.
>
> We can do that in a follow up patch which we can quickly revert if it
> turns out people are actually still using that for something.
Or just pull the plug on the old 'wakeup' event after a deprecation
phase (to be defined).
Thanks,
Mathieu
>
> ---
> include/trace/events/sched.h | 28 ++++++++++++++++++++--------
> kernel/sched/core.c | 9 ++++++---
> 2 files changed, 26 insertions(+), 11 deletions(-)
>
> diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h
> index d57a575fe31f..b1608d5679e2 100644
> --- a/include/trace/events/sched.h
> +++ b/include/trace/events/sched.h
> @@ -55,7 +55,7 @@ TRACE_EVENT(sched_kthread_stop_ret,
> */
> DECLARE_EVENT_CLASS(sched_wakeup_template,
>
> - TP_PROTO(struct task_struct *p, int success),
> + TP_PROTO(struct task_struct *p),
>
> TP_ARGS(__perf_task(p), success),
>
> @@ -71,25 +71,37 @@ DECLARE_EVENT_CLASS(sched_wakeup_template,
> memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
> __entry->pid = p->pid;
> __entry->prio = p->prio;
> - __entry->success = success;
> + __entry->success = 1; /* rudiment, kill when possible */
> __entry->target_cpu = task_cpu(p);
> ),
>
> - TP_printk("comm=%s pid=%d prio=%d success=%d target_cpu=%03d",
> + TP_printk("comm=%s pid=%d prio=%d target_cpu=%03d",
> __entry->comm, __entry->pid, __entry->prio,
> - __entry->success, __entry->target_cpu)
> + __entry->target_cpu)
> );
>
> +/*
> + * Tracepoint called when waking a task; this tracepoint is guaranteed to be
> + * called from the waking context.
> + */
> +DEFINE_EVENT(sched_wakeup_template, sched_waking,
> + TP_PROTO(struct task_struct *p),
> + TP_ARGS(p));
> +
> +/*
> + * Tracepoint called when the task is actually woken; p->state == TASK_RUNNNG.
> + * It it not always called from the waking context.
> + */
> DEFINE_EVENT(sched_wakeup_template, sched_wakeup,
> - TP_PROTO(struct task_struct *p, int success),
> - TP_ARGS(p, success));
> + TP_PROTO(struct task_struct *p),
> + TP_ARGS(p));
>
> /*
> * Tracepoint for waking up a new task:
> */
> DEFINE_EVENT(sched_wakeup_template, sched_wakeup_new,
> - TP_PROTO(struct task_struct *p, int success),
> - TP_ARGS(p, success));
> + TP_PROTO(struct task_struct *p),
> + TP_ARGS(p));
>
> #ifdef CREATE_TRACE_POINTS
> static inline long __trace_sched_switch_state(struct task_struct *p)
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index d5078c0f20e6..354e667620a9 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -1487,9 +1487,9 @@ static void
> ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags)
> {
> check_preempt_curr(rq, p, wake_flags);
> - trace_sched_wakeup(p, true);
> -
> p->state = TASK_RUNNING;
> + trace_sched_wakeup(p);
> +
> #ifdef CONFIG_SMP
> if (p->sched_class->task_woken)
> p->sched_class->task_woken(rq, p);
> @@ -1695,6 +1695,7 @@ try_to_wake_up(struct task_struct *p, unsigned int state,
> int wake_flags)
> goto out;
>
> success = 1; /* we're going to change ->state */
> + trace_sched_waking(p);
> cpu = task_cpu(p);
>
> if (p->on_rq && ttwu_remote(p, wake_flags))
> @@ -1761,6 +1762,8 @@ static void try_to_wake_up_local(struct task_struct *p)
> if (!(p->state & TASK_NORMAL))
> goto out;
>
> + trace_sched_waking(p);
> +
> if (!task_on_rq_queued(p))
> ttwu_activate(rq, p, ENQUEUE_WAKEUP);
>
> @@ -2119,7 +2122,7 @@ void wake_up_new_task(struct task_struct *p)
> rq = __task_rq_lock(p);
> activate_task(rq, p, 0);
> p->on_rq = TASK_ON_RQ_QUEUED;
> - trace_sched_wakeup_new(p, true);
> + trace_sched_wakeup_new(p);
> check_preempt_curr(rq, p, WF_FORK);
> #ifdef CONFIG_SMP
> if (p->sched_class->task_woken)
--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* [lttng-dev] [RFC PATCH] sched: Fix sched_wakeup tracepoint
2015-06-09 9:13 ` Peter Zijlstra
2015-06-09 18:48 ` Mathieu Desnoyers
@ 2015-06-17 18:23 ` Cong Wang
2015-06-17 18:47 ` Steven Rostedt
1 sibling, 1 reply; 6+ messages in thread
From: Cong Wang @ 2015-06-17 18:23 UTC (permalink / raw)
On Tue, Jun 9, 2015 at 2:13 AM, Peter Zijlstra <peterz at infradead.org> wrote:
>
> So how about we introduce the 'waking' tracepoint and leave the existing
> wakeup one in place and preserve its woken semantics.
>
> Steven, can we do aliases? Where one tracepoint is known to userspace
> under multiple names? In that case we could rename the thing to woken
> and have an alias wakeup which we can phase out over time.
>
> The patch also takes away the success parameter to the tracepoint, but
> does not quite go as far as actually removing it from the tracepoint
> itself.
>
> We can do that in a follow up patch which we can quickly revert if it
> turns out people are actually still using that for something.
+1 to this patch. How is it going?
Here at Twitter, we are analyzing scheduling latencies too, with our
own tool using existing tracepoints, it would be nice to have more
granularity on the scheduling latency.
And, you probably want to change perf sched to respect this
new 'waking' event too. ;)
Thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [lttng-dev] [RFC PATCH] sched: Fix sched_wakeup tracepoint
2015-06-17 18:23 ` Cong Wang
@ 2015-06-17 18:47 ` Steven Rostedt
0 siblings, 0 replies; 6+ messages in thread
From: Steven Rostedt @ 2015-06-17 18:47 UTC (permalink / raw)
On Wed, 17 Jun 2015 11:23:00 -0700
Cong Wang <xiyou.wangcong at gmail.com> wrote:
> On Tue, Jun 9, 2015 at 2:13 AM, Peter Zijlstra <peterz at infradead.org> wrote:
> >
> > So how about we introduce the 'waking' tracepoint and leave the existing
> > wakeup one in place and preserve its woken semantics.
> >
> > Steven, can we do aliases? Where one tracepoint is known to userspace
> > under multiple names? In that case we could rename the thing to woken
> > and have an alias wakeup which we can phase out over time.
> >
> > The patch also takes away the success parameter to the tracepoint, but
> > does not quite go as far as actually removing it from the tracepoint
> > itself.
> >
> > We can do that in a follow up patch which we can quickly revert if it
> > turns out people are actually still using that for something.
>
> +1 to this patch. How is it going?
It's not a top priority. But it shouldn't be too hard to implement.
This could be something I do after the 4.2 merge window closes.
-- Steve
>
> Here at Twitter, we are analyzing scheduling latencies too, with our
> own tool using existing tracepoints, it would be nice to have more
> granularity on the scheduling latency.
>
> And, you probably want to change perf sched to respect this
> new 'waking' event too. ;)
>
> Thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-06-17 18:47 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <1433504509-17013-1-git-send-email-mathieu.desnoyers@efficios.com>
[not found] ` <20150605120909.GG19282@twins.programming.kicks-ass.net>
[not found] ` <479621151.4836.1433507522491.JavaMail.zimbra@efficios.com>
[not found] ` <1433508695.1495.16.camel@twins>
[not found] ` <600031664.4911.1433510581646.JavaMail.zimbra@efficios.com>
[not found] ` <1433592142.1495.22.camel@twins>
2015-06-07 10:20 ` [lttng-dev] [RFC PATCH] sched: Fix sched_wakeup tracepoint Mathieu Desnoyers
2015-06-08 17:27 ` Steven Rostedt
2015-06-09 9:13 ` Peter Zijlstra
2015-06-09 18:48 ` Mathieu Desnoyers
2015-06-17 18:23 ` Cong Wang
2015-06-17 18:47 ` Steven Rostedt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox