From: Andrea Righi <arighi@nvidia.com>
To: Changwoo Min <changwoo@igalia.com>
Cc: tj@kernel.org, void@manifault.com, kernel-dev@igalia.com,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] sched_ext: Add trace point to track sched_ext core events
Date: Fri, 28 Feb 2025 11:03:54 +0100 [thread overview]
Message-ID: <Z8GKCkWNVN_Pbcc0@gpd3> (raw)
In-Reply-To: <20250228085944.19451-1-changwoo@igalia.com>
On Fri, Feb 28, 2025 at 05:59:44PM +0900, Changwoo Min wrote:
> Add tracing support to track sched_ext core events
> (/sched_ext/sched_ext_event). This may be useful for debugging sched_ext
> schedulers that trigger a particular event.
>
> The trace point can be used as other trace points, so it can be used in,
> for example, `perf trace` and BPF programs, as follows:
>
> ======
> $> sudo perf trace -e sched_ext:sched_ext_event --filter 'name == "SCX_EV_ENQ_SLICE_DFL"'
> ======
>
> ======
> struct tp_sched_ext_event {
> struct trace_entry ent;
> u32 __data_loc_name;
> u64 delta;
> };
>
> SEC("tracepoint/sched_ext/sched_ext_event")
> int rtp_add_event(struct tp_sched_ext_event *ctx)
> {
> char event_name[128];
> unsigned short offset = ctx->__data_loc_name & 0xFFFF;
> bpf_probe_read_str((void *)event_name, 128, (char *)ctx + offset);
>
> bpf_printk("name %s delta %llu", event_name, ctx->delta);
> return 0;
> }
> ======
>
> Signed-off-by: Changwoo Min <changwoo@igalia.com>
> ---
>
> ChangeLog v1 -> v2:
> - Rename @added field to @delta for clarity.
> - Rename sched_ext_add_event to sched_ext_event.
> - Drop the @offset field to avoid the potential misuse of non-portable numbers.
>
> include/trace/events/sched_ext.h | 19 +++++++++++++++++++
> kernel/sched/ext.c | 2 ++
> 2 files changed, 21 insertions(+)
>
> diff --git a/include/trace/events/sched_ext.h b/include/trace/events/sched_ext.h
> index fe19da7315a9..b73499981682 100644
> --- a/include/trace/events/sched_ext.h
> +++ b/include/trace/events/sched_ext.h
> @@ -26,6 +26,25 @@ TRACE_EVENT(sched_ext_dump,
> )
> );
>
> +TRACE_EVENT(sched_ext_event,
> + TP_PROTO(const char *name, __u64 delta),
> + TP_ARGS(name, delta),
> +
> + TP_STRUCT__entry(
> + __string(name, name)
> + __field( __u64, delta )
I'm wondering if we should use a __s64 here (and %lld below). We don't have
negative deltas right now, but in the future who knows...
Apart than that, everything else looks good to me.
Thanks,
-Andrea
> + ),
> +
> + TP_fast_assign(
> + __assign_str(name);
> + __entry->delta = delta;
> + ),
> +
> + TP_printk("name %s delta %llu",
> + __get_str(name), __entry->delta
> + )
> +);
> +
> #endif /* _TRACE_SCHED_EXT_H */
>
> /* This part must be outside protection */
> diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
> index 986b655911df..53729c584b63 100644
> --- a/kernel/sched/ext.c
> +++ b/kernel/sched/ext.c
> @@ -1554,6 +1554,7 @@ static DEFINE_PER_CPU(struct scx_event_stats, event_stats_cpu);
> */
> #define scx_add_event(name, cnt) do { \
> this_cpu_add(event_stats_cpu.name, cnt); \
> + trace_sched_ext_event(#name, cnt); \
> } while(0)
>
> /**
> @@ -1565,6 +1566,7 @@ static DEFINE_PER_CPU(struct scx_event_stats, event_stats_cpu);
> */
> #define __scx_add_event(name, cnt) do { \
> __this_cpu_add(event_stats_cpu.name, cnt); \
> + trace_sched_ext_event(#name, cnt); \
> } while(0)
>
> /**
> --
> 2.48.1
>
next prev parent reply other threads:[~2025-02-28 10:04 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-28 8:59 [PATCH v2] sched_ext: Add trace point to track sched_ext core events Changwoo Min
2025-02-28 10:03 ` Andrea Righi [this message]
2025-02-28 17:31 ` Tejun Heo
2025-02-28 23:33 ` Changwoo Min
2025-02-28 23:50 ` Tejun Heo
2025-03-01 0:46 ` Changwoo Min
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z8GKCkWNVN_Pbcc0@gpd3 \
--to=arighi@nvidia.com \
--cc=changwoo@igalia.com \
--cc=kernel-dev@igalia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tj@kernel.org \
--cc=void@manifault.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.