Re: [PATCH v3 3/8] perf sched stats: Add schedstat v17 support

Namhyung Kim
2025-03-15T02:27:29Z

On Tue, Mar 11, 2025 at 12:02:25PM +0000, Swapnil Sapkal wrote:
> /proc/schedstat file output is standardized with version number.
> Add support to record and raw dump v17 version layout.
>
> Co-developed-by: Ravi Bangoria <ravi.bangoria@amd.com>
> Signed-off-by: Ravi Bangoria <ravi.bangoria@amd.com>
> Signed-off-by: Swapnil Sapkal <swapnil.sapkal@amd.com>
> ---
> tools/lib/perf/Makefile | 2 +-
> tools/lib/perf/include/perf/event.h | 14 +++++
> tools/lib/perf/include/perf/schedstat-v17.h | 61 +++++++++++++++++++++
> tools/perf/util/event.c | 6 ++
> tools/perf/util/synthetic-events.c | 15 +++++
> 5 files changed, 97 insertions(+), 1 deletion(-)
> create mode 100644 tools/lib/perf/include/perf/schedstat-v17.h
>
> diff --git a/tools/lib/perf/Makefile b/tools/lib/perf/Makefile
> index d0506a13a97f..30712ce8b6b1 100644
> --- a/tools/lib/perf/Makefile
> +++ b/tools/lib/perf/Makefile
> @@ -174,7 +174,7 @@ install_lib: libs
> $(call do_install_mkdir,$(libdir_SQ)); \
> cp -fpR $(LIBPERF_ALL) $(DESTDIR)$(libdir_SQ)
>
> -HDRS := bpf_perf.h core.h cpumap.h threadmap.h evlist.h evsel.h event.h mmap.h schedstat-v15.h schedstat-v16.h
> +HDRS := bpf_perf.h core.h cpumap.h threadmap.h evlist.h evsel.h event.h mmap.h schedstat-v15.h schedstat-v16.h schedstat-v17.h

Please put them in a separate line like

HDRS += schedstat-v15.h schedstat-v16.h schedstat-v17.h

Thanks,
Namhyung

> INTERNAL_HDRS := cpumap.h evlist.h evsel.h lib.h mmap.h rc_check.h threadmap.h xyarray.h
>
> INSTALL_HDRS_PFX := $(DESTDIR)$(prefix)/include/perf
> diff --git a/tools/lib/perf/include/perf/event.h b/tools/lib/perf/include/perf/event.h
> index 8ef70799e070..0d1983ad9a41 100644
> --- a/tools/lib/perf/include/perf/event.h
> +++ b/tools/lib/perf/include/perf/event.h
> @@ -469,12 +469,19 @@ struct perf_record_schedstat_cpu_v16 {
> #undef CPU_FIELD
> };
>
> +struct perf_record_schedstat_cpu_v17 {
> +#define CPU_FIELD(_type, _name, _ver) _type _name
> +#include "schedstat-v17.h"
> +#undef CPU_FIELD
> +};
> +
> struct perf_record_schedstat_cpu {
> struct perf_event_header header;
> __u64 timestamp;
> union {
> struct perf_record_schedstat_cpu_v15 v15;
> struct perf_record_schedstat_cpu_v16 v16;
> + struct perf_record_schedstat_cpu_v17 v17;
> };
> __u32 cpu;
> __u16 version;
> @@ -492,6 +499,12 @@ struct perf_record_schedstat_domain_v16 {
> #undef DOMAIN_FIELD
> };
>
> +struct perf_record_schedstat_domain_v17 {
> +#define DOMAIN_FIELD(_type, _name, _ver) _type _name
> +#include "schedstat-v17.h"
> +#undef DOMAIN_FIELD
> +};
> +
> #define DOMAIN_NAME_LEN 16
>
> struct perf_record_schedstat_domain {
> @@ -504,6 +517,7 @@ struct perf_record_schedstat_domain {
> union {
> struct perf_record_schedstat_domain_v15 v15;
> struct perf_record_schedstat_domain_v16 v16;
> + struct perf_record_schedstat_domain_v17 v17;
> };
> __u16 nr_cpus;
> __u8 cpu_mask[];
> diff --git a/tools/lib/perf/include/perf/schedstat-v17.h b/tools/lib/perf/include/perf/schedstat-v17.h
> new file mode 100644
> index 000000000000..851d4f1f4ecb
> --- /dev/null
> +++ b/tools/lib/perf/include/perf/schedstat-v17.h
> @@ -0,0 +1,61 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +
> +#ifdef CPU_FIELD
> +CPU_FIELD(__u32, yld_count, v17);
> +CPU_FIELD(__u32, array_exp, v17);
> +CPU_FIELD(__u32, sched_count, v17);
> +CPU_FIELD(__u32, sched_goidle, v17);
> +CPU_FIELD(__u32, ttwu_count, v17);
> +CPU_FIELD(__u32, ttwu_local, v17);
> +CPU_FIELD(__u64, rq_cpu_time, v17);
> +CPU_FIELD(__u64, run_delay, v17);
> +CPU_FIELD(__u64, pcount, v17);
> +#endif
> +
> +#ifdef DOMAIN_FIELD
> +DOMAIN_FIELD(__u32, busy_lb_count, v17);
> +DOMAIN_FIELD(__u32, busy_lb_balanced, v17);
> +DOMAIN_FIELD(__u32, busy_lb_failed, v17);
> +DOMAIN_FIELD(__u32, busy_lb_imbalance_load, v17);
> +DOMAIN_FIELD(__u32, busy_lb_imbalance_util, v17);
> +DOMAIN_FIELD(__u32, busy_lb_imbalance_task, v17);
> +DOMAIN_FIELD(__u32, busy_lb_imbalance_misfit, v17);
> +DOMAIN_FIELD(__u32, busy_lb_gained, v17);
> +DOMAIN_FIELD(__u32, busy_lb_hot_gained, v17);
> +DOMAIN_FIELD(__u32, busy_lb_nobusyq, v17);
> +DOMAIN_FIELD(__u32, busy_lb_nobusyg, v17);
> +DOMAIN_FIELD(__u32, idle_lb_count, v17);
> +DOMAIN_FIELD(__u32, idle_lb_balanced, v17);
> +DOMAIN_FIELD(__u32, idle_lb_failed, v17);
> +DOMAIN_FIELD(__u32, idle_lb_imbalance_load, v17);
> +DOMAIN_FIELD(__u32, idle_lb_imbalance_util, v17);
> +DOMAIN_FIELD(__u32, idle_lb_imbalance_task, v17);
> +DOMAIN_FIELD(__u32, idle_lb_imbalance_misfit, v17);
> +DOMAIN_FIELD(__u32, idle_lb_gained, v17);
> +DOMAIN_FIELD(__u32, idle_lb_hot_gained, v17);
> +DOMAIN_FIELD(__u32, idle_lb_nobusyq, v17);
> +DOMAIN_FIELD(__u32, idle_lb_nobusyg, v17);
> +DOMAIN_FIELD(__u32, newidle_lb_count, v17);
> +DOMAIN_FIELD(__u32, newidle_lb_balanced, v17);
> +DOMAIN_FIELD(__u32, newidle_lb_failed, v17);
> +DOMAIN_FIELD(__u32, newidle_lb_imbalance_load, v17);
> +DOMAIN_FIELD(__u32, newidle_lb_imbalance_util, v17);
> +DOMAIN_FIELD(__u32, newidle_lb_imbalance_task, v17);
> +DOMAIN_FIELD(__u32, newidle_lb_imbalance_misfit, v17);
> +DOMAIN_FIELD(__u32, newidle_lb_gained, v17);
> +DOMAIN_FIELD(__u32, newidle_lb_hot_gained, v17);
> +DOMAIN_FIELD(__u32, newidle_lb_nobusyq, v17);
> +DOMAIN_FIELD(__u32, newidle_lb_nobusyg, v17);
> +DOMAIN_FIELD(__u32, alb_count, v17);
> +DOMAIN_FIELD(__u32, alb_failed, v17);
> +DOMAIN_FIELD(__u32, alb_pushed, v17);
> +DOMAIN_FIELD(__u32, sbe_count, v17);
> +DOMAIN_FIELD(__u32, sbe_balanced, v17);
> +DOMAIN_FIELD(__u32, sbe_pushed, v17);
> +DOMAIN_FIELD(__u32, sbf_count, v17);
> +DOMAIN_FIELD(__u32, sbf_balanced, v17);
> +DOMAIN_FIELD(__u32, sbf_pushed, v17);
> +DOMAIN_FIELD(__u32, ttwu_wake_remote, v17);
> +DOMAIN_FIELD(__u32, ttwu_move_affine, v17);
> +DOMAIN_FIELD(__u32, ttwu_move_balance, v17);
> +#endif
> diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
> index 64f81e7b7f70..d09c3c99ab48 100644
> --- a/tools/perf/util/event.c
> +++ b/tools/perf/util/event.c
> @@ -569,6 +569,9 @@ size_t perf_event__fprintf_schedstat_cpu(union perf_event *event, FILE *fp)
> } else if (version == 16) {
> #include <perf/schedstat-v16.h>
> return size;
> + } else if (version == 17) {
> +#include <perf/schedstat-v17.h>
> + return size;
> }
> #undef CPU_FIELD
>
> @@ -647,6 +650,9 @@ size_t perf_event__fprintf_schedstat_domain(union perf_event *event, FILE *fp)
> } else if (version == 16) {
> #include <perf/schedstat-v16.h>
> return size;
> + } else if (version == 17) {
> +#include <perf/schedstat-v17.h>
> + return size;
> }
> #undef DOMAIN_FIELD
>
> diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c
> index e9dc1e14cfea..fad0c472f297 100644
> --- a/tools/perf/util/synthetic-events.c
> +++ b/tools/perf/util/synthetic-events.c
> @@ -2551,6 +2551,8 @@ static union perf_event *__synthesize_schedstat_cpu(struct io *io, __u16 version
> #include <perf/schedstat-v15.h>
> } else if (version == 16) {
> #include <perf/schedstat-v16.h>
> + } else if (version == 17) {
> +#include <perf/schedstat-v17.h>
> }
> #undef CPU_FIELD
>
> @@ -2589,6 +2591,7 @@ static union perf_event *__synthesize_schedstat_domain(struct io *io, __u16 vers
> int nr_cpus_avail = perf_env__nr_cpus_avail(&env);
> struct perf_record_schedstat_domain *ds;
> union perf_event *event;
> + size_t d_name_len = 0;
> char *d_name = NULL;
> size_t cpu_mask_len = 0;
> char *cpu_mask = NULL;
> @@ -2604,6 +2607,12 @@ static union perf_event *__synthesize_schedstat_domain(struct io *io, __u16 vers
> return NULL;
>
> ch = io__get_dec(io, &d_num);
> + if (version >= 17) {
> + if (io__getdelim(io, &d_name, &d_name_len, ' ') < 0 || !d_name_len)
> + return NULL;
> + d_name[d_name_len - 1] = '\0';
> + d_name_len--;
> + }
>
> if (io__getdelim(io, &cpu_mask, &cpu_mask_len, ' ') < 0 || !cpu_mask_len)
> goto out;
> @@ -2650,6 +2659,7 @@ static union perf_event *__synthesize_schedstat_domain(struct io *io, __u16 vers
> low = !low;
> }
>
> + free(d_name);
> free(cpu_mask);
>
> #define DOMAIN_FIELD(_type, _name, _ver) \
> @@ -2665,6 +2675,8 @@ static union perf_event *__synthesize_schedstat_domain(struct io *io, __u16 vers
> #include <perf/schedstat-v15.h>
> } else if (version == 16) {
> #include <perf/schedstat-v16.h>
> + } else if (version == 17) {
> +#include <perf/schedstat-v17.h>
> }
> #undef DOMAIN_FIELD
>
> @@ -2676,6 +2688,7 @@ static union perf_event *__synthesize_schedstat_domain(struct io *io, __u16 vers
> out_cpu_mask:
> free(cpu_mask);
> out:
> + free(d_name);
> return NULL;
> }
>
> @@ -2709,6 +2722,8 @@ int perf_event__synthesize_schedstat(const struct perf_tool *tool,
> version = 15;
> } else if (!strcmp(line, "version 16\n")) {
> version = 16;
> + } else if (!strcmp(line, "version 17\n")) {
> + version = 17;
> } else {
> pr_err("Unsupported %s version: %s", path, line + 8);
> goto out_free_line;
> --
> 2.43.0
>