[PATCH v5 07/10] perf sched stats: Add support for live mode

Swapnil Sapkal posted 10 patches 2 weeks, 4 days ago
[PATCH v5 07/10] perf sched stats: Add support for live mode
Posted by Swapnil Sapkal 2 weeks, 4 days ago
The live mode works similar to simple `perf stat` command, by profiling
the target and printing results on the terminal as soon as the target
finishes.

Example usage:

  # perf sched stats -- true
  Description
  ----------------------------------------------------------------------------------------------------
  DESC                          -> Description of the field
  COUNT                         -> Value of the field
  PCT_CHANGE                    -> Percent change with corresponding base value
  AVG_JIFFIES                   -> Avg time in jiffies between two consecutive occurrence of event
  ----------------------------------------------------------------------------------------------------

  Time elapsed (in jiffies)                                        :           1
  ----------------------------------------------------------------------------------------------------
  CPU: <ALL CPUS SUMMARY>
  ----------------------------------------------------------------------------------------------------
  DESC                                                                     COUNT   PCT_CHANGE
  ----------------------------------------------------------------------------------------------------
  yld_count                                                        :           0
  array_exp                                                        :           0
  sched_count                                                      :           0
  sched_goidle                                                     :           0  (     0.00% )
  ttwu_count                                                       :           0
  ttwu_local                                                       :           0  (     0.00% )
  rq_cpu_time                                                      :       27875
  run_delay                                                        :           0  (     0.00% )
  pcount                                                           :           0
  ----------------------------------------------------------------------------------------------------
  CPU: <ALL CPUS SUMMARY> | DOMAIN: SMT
  ----------------------------------------------------------------------------------------------------
  DESC                                                                     COUNT    AVG_JIFFIES
  ----------------------------------------- <Category busy> ------------------------------------------
  busy_lb_count                                                    :           0  $        0.00 $
  busy_lb_balanced                                                 :           0  $        0.00 $
  busy_lb_failed                                                   :           0  $        0.00 $
  busy_lb_imbalance_load                                           :           0
  busy_lb_imbalance_util                                           :           0
  busy_lb_imbalance_task                                           :           0
  busy_lb_imbalance_misfit                                         :           0
  busy_lb_gained                                                   :           0
  busy_lb_hot_gained                                               :           0
  busy_lb_nobusyq                                                  :           0  $        0.00 $
  busy_lb_nobusyg                                                  :           0  $        0.00 $
  *busy_lb_success_count                                           :           0
  *busy_lb_avg_pulled                                              :        0.00

  ... and so on. Output will show similar data for all the cpus in the
system.

Co-developed-by: Ravi Bangoria <ravi.bangoria@amd.com>
Signed-off-by: Ravi Bangoria <ravi.bangoria@amd.com>
Tested-by: James Clark <james.clark@linaro.org>
Signed-off-by: Swapnil Sapkal <swapnil.sapkal@amd.com>
---
 tools/perf/builtin-sched.c | 99 +++++++++++++++++++++++++++++++++++++-
 tools/perf/util/header.c   |  3 +-
 tools/perf/util/header.h   |  3 ++
 3 files changed, 102 insertions(+), 3 deletions(-)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index c6b054b9b12a..8993308439bc 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -4426,6 +4426,103 @@ static int perf_sched__schedstat_report(struct perf_sched *sched)
 	return err;
 }
 
+static int process_synthesized_event_live(const struct perf_tool *tool __maybe_unused,
+					  union perf_event *event,
+					  struct perf_sample *sample __maybe_unused,
+					  struct machine *machine __maybe_unused)
+{
+	return perf_sched__process_schedstat(tool, NULL, event);
+}
+
+static int perf_sched__schedstat_live(struct perf_sched *sched,
+				      int argc, const char **argv)
+{
+	struct cpu_domain_map **cd_map = NULL;
+	struct target target = {};
+	u32 __maybe_unused md;
+	struct evlist *evlist;
+	u32 nr = 0, sv;
+	int reset = 0;
+	int err = 0;
+
+	signal(SIGINT, sighandler);
+	signal(SIGCHLD, sighandler);
+	signal(SIGTERM, sighandler);
+
+	evlist = evlist__new();
+	if (!evlist)
+		return -ENOMEM;
+
+	/*
+	 * `perf sched schedstat` does not support workload profiling (-p pid)
+	 * since /proc/schedstat file contains cpu specific data only. Hence, a
+	 * profile target is either set of cpus or systemwide, never a process.
+	 * Note that, although `-- <workload>` is supported, profile data are
+	 * still cpu/systemwide.
+	 */
+	if (cpu_list)
+		target.cpu_list = cpu_list;
+	else
+		target.system_wide = true;
+
+	if (argc) {
+		err = evlist__prepare_workload(evlist, &target, argv, false, NULL);
+		if (err)
+			goto out;
+	}
+
+	err = evlist__create_maps(evlist, &target);
+	if (err < 0)
+		goto out;
+
+	user_requested_cpus = evlist->core.user_requested_cpus;
+
+	err = perf_event__synthesize_schedstat(&(sched->tool),
+					       process_synthesized_event_live,
+					       user_requested_cpus);
+	if (err < 0)
+		goto out;
+
+	err = enable_sched_schedstats(&reset);
+	if (err < 0)
+		goto out;
+
+	if (argc)
+		evlist__start_workload(evlist);
+
+	/* wait for signal */
+	pause();
+
+	if (reset) {
+		err = disable_sched_schedstat();
+		if (err < 0)
+			goto out;
+	}
+
+	err = perf_event__synthesize_schedstat(&(sched->tool),
+					       process_synthesized_event_live,
+					       user_requested_cpus);
+	if (err)
+		goto out;
+
+	setup_pager();
+
+	if (list_empty(&cpu_head)) {
+		pr_err("Data is not available\n");
+		err = -1;
+		goto out;
+	}
+
+	nr = cpu__max_present_cpu().cpu;
+	cd_map = build_cpu_domain_map(&sv, &md, nr);
+	show_schedstat_data(&cpu_head, cd_map);
+out:
+	free_cpu_domain_info(cd_map, sv, nr);
+	free_schedstat(&cpu_head);
+	evlist__delete(evlist);
+	return err;
+}
+
 static bool schedstat_events_exposed(void)
 {
 	/*
@@ -4751,7 +4848,7 @@ int cmd_sched(int argc, const char **argv)
 						     stats_usage, 0);
 			return perf_sched__schedstat_report(&sched);
 		}
-		usage_with_options(stats_usage, stats_options);
+		return perf_sched__schedstat_live(&sched, argc, argv);
 	} else {
 		usage_with_options(sched_usage, sched_options);
 	}
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 673d53bb2a2c..9a15dd4b7640 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1614,8 +1614,7 @@ static int write_pmu_caps(struct feat_fd *ff,
 	return 0;
 }
 
-static struct cpu_domain_map **build_cpu_domain_map(u32 *schedstat_version, u32 *max_sched_domains,
-						    u32 nr)
+struct cpu_domain_map **build_cpu_domain_map(u32 *schedstat_version, u32 *max_sched_domains, u32 nr)
 {
 	struct domain_info *domain_info;
 	struct cpu_domain_map **cd_map;
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
index c62f3275a80f..36cc74e2d14d 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -211,4 +211,7 @@ char *get_cpuid_str(struct perf_cpu cpu);
 char *get_cpuid_allow_env_override(struct perf_cpu cpu);
 
 int strcmp_cpuid_str(const char *s1, const char *s2);
+
+struct cpu_domain_map **build_cpu_domain_map(u32 *schedstat_version, u32 *max_sched_domains,
+					     u32 nr);
 #endif /* __PERF_HEADER_H */
-- 
2.43.0
Re: [PATCH v5 07/10] perf sched stats: Add support for live mode
Posted by Arnaldo Carvalho de Melo 2 weeks, 2 days ago
On Mon, Jan 19, 2026 at 05:58:29PM +0000, Swapnil Sapkal wrote:
> The live mode works similar to simple `perf stat` command, by profiling
> the target and printing results on the terminal as soon as the target
> finishes.
> 
> Example usage:
> 
>   # perf sched stats -- true
>   Description
>   ----------------------------------------------------------------------------------------------------
>   DESC                          -> Description of the field
>   COUNT                         -> Value of the field
>   PCT_CHANGE                    -> Percent change with corresponding base value
>   AVG_JIFFIES                   -> Avg time in jiffies between two consecutive occurrence of event
>   ----------------------------------------------------------------------------------------------------
> 
>   Time elapsed (in jiffies)                                        :           1
>   ----------------------------------------------------------------------------------------------------
>   CPU: <ALL CPUS SUMMARY>
>   ----------------------------------------------------------------------------------------------------
>   DESC                                                                     COUNT   PCT_CHANGE
>   ----------------------------------------------------------------------------------------------------
>   yld_count                                                        :           0
>   array_exp                                                        :           0
>   sched_count                                                      :           0
>   sched_goidle                                                     :           0  (     0.00% )
>   ttwu_count                                                       :           0
>   ttwu_local                                                       :           0  (     0.00% )
>   rq_cpu_time                                                      :       27875
>   run_delay                                                        :           0  (     0.00% )
>   pcount                                                           :           0
>   ----------------------------------------------------------------------------------------------------
>   CPU: <ALL CPUS SUMMARY> | DOMAIN: SMT
>   ----------------------------------------------------------------------------------------------------
>   DESC                                                                     COUNT    AVG_JIFFIES
>   ----------------------------------------- <Category busy> ------------------------------------------
>   busy_lb_count                                                    :           0  $        0.00 $
>   busy_lb_balanced                                                 :           0  $        0.00 $
>   busy_lb_failed                                                   :           0  $        0.00 $
>   busy_lb_imbalance_load                                           :           0
>   busy_lb_imbalance_util                                           :           0
>   busy_lb_imbalance_task                                           :           0
>   busy_lb_imbalance_misfit                                         :           0
>   busy_lb_gained                                                   :           0
>   busy_lb_hot_gained                                               :           0
>   busy_lb_nobusyq                                                  :           0  $        0.00 $
>   busy_lb_nobusyg                                                  :           0  $        0.00 $
>   *busy_lb_success_count                                           :           0
>   *busy_lb_avg_pulled                                              :        0.00
> 
>   ... and so on. Output will show similar data for all the cpus in the
> system.
> 
> Co-developed-by: Ravi Bangoria <ravi.bangoria@amd.com>
> Signed-off-by: Ravi Bangoria <ravi.bangoria@amd.com>
> Tested-by: James Clark <james.clark@linaro.org>
> Signed-off-by: Swapnil Sapkal <swapnil.sapkal@amd.com>
> ---
>  tools/perf/builtin-sched.c | 99 +++++++++++++++++++++++++++++++++++++-
>  tools/perf/util/header.c   |  3 +-
>  tools/perf/util/header.h   |  3 ++
>  3 files changed, 102 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
> index c6b054b9b12a..8993308439bc 100644
> --- a/tools/perf/builtin-sched.c
> +++ b/tools/perf/builtin-sched.c
> @@ -4426,6 +4426,103 @@ static int perf_sched__schedstat_report(struct perf_sched *sched)
>  	return err;
>  }
>  
> +static int process_synthesized_event_live(const struct perf_tool *tool __maybe_unused,
> +					  union perf_event *event,
> +					  struct perf_sample *sample __maybe_unused,
> +					  struct machine *machine __maybe_unused)
> +{
> +	return perf_sched__process_schedstat(tool, NULL, event);
> +}
> +
> +static int perf_sched__schedstat_live(struct perf_sched *sched,
> +				      int argc, const char **argv)
> +{
> +	struct cpu_domain_map **cd_map = NULL;
> +	struct target target = {};
> +	u32 __maybe_unused md;
> +	struct evlist *evlist;
> +	u32 nr = 0, sv;
> +	int reset = 0;
> +	int err = 0;
> +
> +	signal(SIGINT, sighandler);
> +	signal(SIGCHLD, sighandler);
> +	signal(SIGTERM, sighandler);
> +
> +	evlist = evlist__new();
> +	if (!evlist)
> +		return -ENOMEM;
> +
> +	/*
> +	 * `perf sched schedstat` does not support workload profiling (-p pid)
> +	 * since /proc/schedstat file contains cpu specific data only. Hence, a
> +	 * profile target is either set of cpus or systemwide, never a process.
> +	 * Note that, although `-- <workload>` is supported, profile data are
> +	 * still cpu/systemwide.
> +	 */
> +	if (cpu_list)
> +		target.cpu_list = cpu_list;
> +	else
> +		target.system_wide = true;
> +
> +	if (argc) {
> +		err = evlist__prepare_workload(evlist, &target, argv, false, NULL);
> +		if (err)
> +			goto out;
> +	}
> +
> +	err = evlist__create_maps(evlist, &target);
> +	if (err < 0)
> +		goto out;
> +
> +	user_requested_cpus = evlist->core.user_requested_cpus;
> +
> +	err = perf_event__synthesize_schedstat(&(sched->tool),
> +					       process_synthesized_event_live,
> +					       user_requested_cpus);
> +	if (err < 0)
> +		goto out;
> +
> +	err = enable_sched_schedstats(&reset);
> +	if (err < 0)
> +		goto out;
> +
> +	if (argc)
> +		evlist__start_workload(evlist);
> +
> +	/* wait for signal */
> +	pause();
> +
> +	if (reset) {
> +		err = disable_sched_schedstat();
> +		if (err < 0)
> +			goto out;
> +	}
> +
> +	err = perf_event__synthesize_schedstat(&(sched->tool),
> +					       process_synthesized_event_live,
> +					       user_requested_cpus);
> +	if (err)
> +		goto out;
> +
> +	setup_pager();
> +
> +	if (list_empty(&cpu_head)) {
> +		pr_err("Data is not available\n");
> +		err = -1;
> +		goto out;
> +	}
> +
> +	nr = cpu__max_present_cpu().cpu;
> +	cd_map = build_cpu_domain_map(&sv, &md, nr);
> +	show_schedstat_data(&cpu_head, cd_map);
> +out:

With clang on almalinux 10:

+ make ARCH= CROSS_COMPILE= EXTRA_CFLAGS= -C tools/perf O=/tmp/build/perf CC=clang
make: Entering directory '/git/perf-6.19.0-rc4/tools/perf'
  GEN     /tmp/build/perf/pmu-events/arch/powerpc/power8/memory.json
builtin-sched.c:4709:6: error: variable 'sv' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
 4709 |         if (list_empty(&cpu_head)) {
      |             ^~~~~~~~~~~~~~~~~~~~~
  GEN     /tmp/build/perf/pmu-events/arch/powerpc/power8/metrics.json
  GEN     /tmp/build/perf/pmu-events/arch/powerpc/power8/other.json
  CC      /tmp/build/perf/tests/kmod-path.o
builtin-sched.c:4719:31: note: uninitialized use occurs here
  GEN     /tmp/build/perf/pmu-events/arch/powerpc/power8/pipeline.json
 4719 |         free_cpu_domain_info(cd_map, sv, nr);
      |                                      ^~

But then it doesn't build on 32-bit arches with:

    20.64 almalinux:9-i386              : FAIL gcc version 11.4.1 20231218 (Red Hat 11.4.1-3) (GCC)
          |                             ^~~
    /tmp/build/perf/libperf/include/perf/schedstat-v15.h:4:1: note: in expansion of macro ‘CPU_FIELD’
        4 | CPU_FIELD(__u32, yld_count, "sched_yield() count",
          | ^~~~~~~~~
    In file included from util/event.c:3:
    /usr/include/inttypes.h:105:41: note: format string is defined here
      105 | # define PRIu64         __PRI64_PREFIX "u"
    util/event.c:583:29: error: format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 3 has type ‘long unsigned int’ [-Werror=format=]
      583 |         size += fprintf(fp, "%" PRIu64 " ", (unsigned long)cs->_ver._name)
          |                             ^~~
    /tmp/build/perf/libperf/include/perf/schedstat-v15.h:6:1: note: in expansion of macro ‘CPU_FIELD’
        6 | CPU_FIELD(__u32, array_exp, "Legacy counter can be ignored",
          | ^~~~~~~~~
    In file included from util/event.c:3:
    /usr/include/inttypes.h:105:41: note: format string is defined here
      105 | # define PRIu64         __PRI64_PREFIX "u"
    util/event.c:583:29: error: format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 3 has type ‘long unsigned int’ [-Werror=format=]
      583 |         size += fprintf(fp, "%" PRIu64 " ", (unsigned long)cs->_ver._name)
          |                             ^~~
    /tmp/build/perf/libperf/include/perf/schedstat-v15.h:8:1: note: in expansion of macro ‘CPU_FIELD’
        8 | CPU_FIELD(__u32, sched_count, "schedule() called",


So continuing to test build up to:

⬢ [acme@toolbx perf-tools-next]$ git log --oneline -5
139b45df27c05531 (HEAD -> perf-tools-next) perf sched stats: Add schedstat v17 support
e092c5d4541da7f0 perf sched stats: Add schedstat v16 support
e659d5e11000b7ff perf sched stats: Add record and rawdump support
900884770020691c perf header: Support CPU DOMAIN relation info
a02829a0e6c65b12 tools/lib: Add list_is_first()
⬢ [acme@toolbx perf-tools-next]$

- Arnaldo

> +	free_cpu_domain_info(cd_map, sv, nr);
> +	free_schedstat(&cpu_head);
> +	evlist__delete(evlist);
> +	return err;
> +}
> +
>  static bool schedstat_events_exposed(void)
>  {
>  	/*
> @@ -4751,7 +4848,7 @@ int cmd_sched(int argc, const char **argv)
>  						     stats_usage, 0);
>  			return perf_sched__schedstat_report(&sched);
>  		}
> -		usage_with_options(stats_usage, stats_options);
> +		return perf_sched__schedstat_live(&sched, argc, argv);
>  	} else {
>  		usage_with_options(sched_usage, sched_options);
>  	}
> diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
> index 673d53bb2a2c..9a15dd4b7640 100644
> --- a/tools/perf/util/header.c
> +++ b/tools/perf/util/header.c
> @@ -1614,8 +1614,7 @@ static int write_pmu_caps(struct feat_fd *ff,
>  	return 0;
>  }
>  
> -static struct cpu_domain_map **build_cpu_domain_map(u32 *schedstat_version, u32 *max_sched_domains,
> -						    u32 nr)
> +struct cpu_domain_map **build_cpu_domain_map(u32 *schedstat_version, u32 *max_sched_domains, u32 nr)
>  {
>  	struct domain_info *domain_info;
>  	struct cpu_domain_map **cd_map;
> diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
> index c62f3275a80f..36cc74e2d14d 100644
> --- a/tools/perf/util/header.h
> +++ b/tools/perf/util/header.h
> @@ -211,4 +211,7 @@ char *get_cpuid_str(struct perf_cpu cpu);
>  char *get_cpuid_allow_env_override(struct perf_cpu cpu);
>  
>  int strcmp_cpuid_str(const char *s1, const char *s2);
> +
> +struct cpu_domain_map **build_cpu_domain_map(u32 *schedstat_version, u32 *max_sched_domains,
> +					     u32 nr);
>  #endif /* __PERF_HEADER_H */
> -- 
> 2.43.0
Re: [PATCH v5 07/10] perf sched stats: Add support for live mode
Posted by Arnaldo Carvalho de Melo 2 weeks, 1 day ago
On Wed, Jan 21, 2026 at 09:54:16PM -0300, Arnaldo Carvalho de Melo wrote:
> On Mon, Jan 19, 2026 at 05:58:29PM +0000, Swapnil Sapkal wrote:
> > The live mode works similar to simple `perf stat` command, by profiling
> > the target and printing results on the terminal as soon as the target
> > finishes.
> > 
> > Example usage:
> > 
> >   # perf sched stats -- true
> >   Description
> >   ----------------------------------------------------------------------------------------------------
> >   DESC                          -> Description of the field
> >   COUNT                         -> Value of the field
> >   PCT_CHANGE                    -> Percent change with corresponding base value
> >   AVG_JIFFIES                   -> Avg time in jiffies between two consecutive occurrence of event
> >   ----------------------------------------------------------------------------------------------------
> > 
> >   Time elapsed (in jiffies)                                        :           1
> >   ----------------------------------------------------------------------------------------------------
> >   CPU: <ALL CPUS SUMMARY>
> >   ----------------------------------------------------------------------------------------------------
> >   DESC                                                                     COUNT   PCT_CHANGE
> >   ----------------------------------------------------------------------------------------------------
> >   yld_count                                                        :           0
> >   array_exp                                                        :           0
> >   sched_count                                                      :           0
> >   sched_goidle                                                     :           0  (     0.00% )
> >   ttwu_count                                                       :           0
> >   ttwu_local                                                       :           0  (     0.00% )
> >   rq_cpu_time                                                      :       27875
> >   run_delay                                                        :           0  (     0.00% )
> >   pcount                                                           :           0
> >   ----------------------------------------------------------------------------------------------------
> >   CPU: <ALL CPUS SUMMARY> | DOMAIN: SMT
> >   ----------------------------------------------------------------------------------------------------
> >   DESC                                                                     COUNT    AVG_JIFFIES
> >   ----------------------------------------- <Category busy> ------------------------------------------
> >   busy_lb_count                                                    :           0  $        0.00 $
> >   busy_lb_balanced                                                 :           0  $        0.00 $
> >   busy_lb_failed                                                   :           0  $        0.00 $
> >   busy_lb_imbalance_load                                           :           0
> >   busy_lb_imbalance_util                                           :           0
> >   busy_lb_imbalance_task                                           :           0
> >   busy_lb_imbalance_misfit                                         :           0
> >   busy_lb_gained                                                   :           0
> >   busy_lb_hot_gained                                               :           0
> >   busy_lb_nobusyq                                                  :           0  $        0.00 $
> >   busy_lb_nobusyg                                                  :           0  $        0.00 $
> >   *busy_lb_success_count                                           :           0
> >   *busy_lb_avg_pulled                                              :        0.00
> > 
> >   ... and so on. Output will show similar data for all the cpus in the
> > system.
> > 
> > Co-developed-by: Ravi Bangoria <ravi.bangoria@amd.com>
> > Signed-off-by: Ravi Bangoria <ravi.bangoria@amd.com>
> > Tested-by: James Clark <james.clark@linaro.org>
> > Signed-off-by: Swapnil Sapkal <swapnil.sapkal@amd.com>
> > ---
> >  tools/perf/builtin-sched.c | 99 +++++++++++++++++++++++++++++++++++++-
> >  tools/perf/util/header.c   |  3 +-
> >  tools/perf/util/header.h   |  3 ++
> >  3 files changed, 102 insertions(+), 3 deletions(-)
> > 
> > diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
> > index c6b054b9b12a..8993308439bc 100644
> > --- a/tools/perf/builtin-sched.c
> > +++ b/tools/perf/builtin-sched.c
> > @@ -4426,6 +4426,103 @@ static int perf_sched__schedstat_report(struct perf_sched *sched)
> >  	return err;
> >  }
> >  
> > +static int process_synthesized_event_live(const struct perf_tool *tool __maybe_unused,
> > +					  union perf_event *event,
> > +					  struct perf_sample *sample __maybe_unused,
> > +					  struct machine *machine __maybe_unused)
> > +{
> > +	return perf_sched__process_schedstat(tool, NULL, event);
> > +}
> > +
> > +static int perf_sched__schedstat_live(struct perf_sched *sched,
> > +				      int argc, const char **argv)
> > +{
> > +	struct cpu_domain_map **cd_map = NULL;
> > +	struct target target = {};
> > +	u32 __maybe_unused md;
> > +	struct evlist *evlist;
> > +	u32 nr = 0, sv;
> > +	int reset = 0;
> > +	int err = 0;
> > +
> > +	signal(SIGINT, sighandler);
> > +	signal(SIGCHLD, sighandler);
> > +	signal(SIGTERM, sighandler);
> > +
> > +	evlist = evlist__new();
> > +	if (!evlist)
> > +		return -ENOMEM;
> > +
> > +	/*
> > +	 * `perf sched schedstat` does not support workload profiling (-p pid)
> > +	 * since /proc/schedstat file contains cpu specific data only. Hence, a
> > +	 * profile target is either set of cpus or systemwide, never a process.
> > +	 * Note that, although `-- <workload>` is supported, profile data are
> > +	 * still cpu/systemwide.
> > +	 */
> > +	if (cpu_list)
> > +		target.cpu_list = cpu_list;
> > +	else
> > +		target.system_wide = true;
> > +
> > +	if (argc) {
> > +		err = evlist__prepare_workload(evlist, &target, argv, false, NULL);
> > +		if (err)
> > +			goto out;
> > +	}
> > +
> > +	err = evlist__create_maps(evlist, &target);
> > +	if (err < 0)
> > +		goto out;
> > +
> > +	user_requested_cpus = evlist->core.user_requested_cpus;
> > +
> > +	err = perf_event__synthesize_schedstat(&(sched->tool),
> > +					       process_synthesized_event_live,
> > +					       user_requested_cpus);
> > +	if (err < 0)
> > +		goto out;
> > +
> > +	err = enable_sched_schedstats(&reset);
> > +	if (err < 0)
> > +		goto out;
> > +
> > +	if (argc)
> > +		evlist__start_workload(evlist);
> > +
> > +	/* wait for signal */
> > +	pause();
> > +
> > +	if (reset) {
> > +		err = disable_sched_schedstat();
> > +		if (err < 0)
> > +			goto out;
> > +	}
> > +
> > +	err = perf_event__synthesize_schedstat(&(sched->tool),
> > +					       process_synthesized_event_live,
> > +					       user_requested_cpus);
> > +	if (err)
> > +		goto out;
> > +
> > +	setup_pager();
> > +
> > +	if (list_empty(&cpu_head)) {
> > +		pr_err("Data is not available\n");
> > +		err = -1;
> > +		goto out;
> > +	}
> > +
> > +	nr = cpu__max_present_cpu().cpu;
> > +	cd_map = build_cpu_domain_map(&sv, &md, nr);
> > +	show_schedstat_data(&cpu_head, cd_map);
> > +out:
> 
> With clang on almalinux 10:
> 
> + make ARCH= CROSS_COMPILE= EXTRA_CFLAGS= -C tools/perf O=/tmp/build/perf CC=clang
> make: Entering directory '/git/perf-6.19.0-rc4/tools/perf'
>   GEN     /tmp/build/perf/pmu-events/arch/powerpc/power8/memory.json
> builtin-sched.c:4709:6: error: variable 'sv' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
>  4709 |         if (list_empty(&cpu_head)) {
>       |             ^~~~~~~~~~~~~~~~~~~~~
>   GEN     /tmp/build/perf/pmu-events/arch/powerpc/power8/metrics.json
>   GEN     /tmp/build/perf/pmu-events/arch/powerpc/power8/other.json
>   CC      /tmp/build/perf/tests/kmod-path.o
> builtin-sched.c:4719:31: note: uninitialized use occurs here
>   GEN     /tmp/build/perf/pmu-events/arch/powerpc/power8/pipeline.json
>  4719 |         free_cpu_domain_info(cd_map, sv, nr);
>       |                                      ^~
> 

Moving the label does the trick as free_cpu_domain_info() only needs to
be called if build_cpu_domain_map() was called.

- Arnaldo

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 8993308439bc5998..ec9fa29196b24f5a 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -4516,8 +4516,8 @@ static int perf_sched__schedstat_live(struct perf_sched *sched,
 	nr = cpu__max_present_cpu().cpu;
 	cd_map = build_cpu_domain_map(&sv, &md, nr);
 	show_schedstat_data(&cpu_head, cd_map);
-out:
 	free_cpu_domain_info(cd_map, sv, nr);
+out:
 	free_schedstat(&cpu_head);
 	evlist__delete(evlist);
 	return err;
Re: [PATCH v5 07/10] perf sched stats: Add support for live mode
Posted by Arnaldo Carvalho de Melo 2 weeks, 2 days ago
On Wed, Jan 21, 2026 at 09:54:16PM -0300, Arnaldo Carvalho de Melo wrote:
> So continuing to test build up to:
 
> ⬢ [acme@toolbx perf-tools-next]$ git log --oneline -5
> 139b45df27c05531 (HEAD -> perf-tools-next) perf sched stats: Add schedstat v17 support
> e092c5d4541da7f0 perf sched stats: Add schedstat v16 support
> e659d5e11000b7ff perf sched stats: Add record and rawdump support
> 900884770020691c perf header: Support CPU DOMAIN relation info
> a02829a0e6c65b12 tools/lib: Add list_is_first()
> ⬢ [acme@toolbx perf-tools-next]$

Just the first two patches build on 32-bit arches, I'll look at it
tomorrow after some coffee, for now at least the first two are merged,
to make some progress.

- Arnaldo
Re: [PATCH v5 07/10] perf sched stats: Add support for live mode
Posted by Arnaldo Carvalho de Melo 2 weeks, 1 day ago
On Wed, Jan 21, 2026 at 10:32:54PM -0300, Arnaldo Carvalho de Melo wrote:
> On Wed, Jan 21, 2026 at 09:54:16PM -0300, Arnaldo Carvalho de Melo wrote:
> > So continuing to test build up to:
>  
> > ⬢ [acme@toolbx perf-tools-next]$ git log --oneline -5
> > 139b45df27c05531 (HEAD -> perf-tools-next) perf sched stats: Add schedstat v17 support
> > e092c5d4541da7f0 perf sched stats: Add schedstat v16 support
> > e659d5e11000b7ff perf sched stats: Add record and rawdump support
> > 900884770020691c perf header: Support CPU DOMAIN relation info
> > a02829a0e6c65b12 tools/lib: Add list_is_first()
> > ⬢ [acme@toolbx perf-tools-next]$
 
> Just the first two patches build on 32-bit arches, I'll look at it
> tomorrow after some coffee, for now at least the first two are merged,
> to make some progress.

Its simple stuff like:

acme@five:~/git/perf-tools-next$ git diff
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index f1051224124437c6..5a98c16e10923d57 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -599,7 +599,7 @@ size_t perf_event__fprintf_schedstat_domain(union perf_event *event, FILE *fp)
        size_t size = fprintf(fp, "\ndomain%u ", ds->domain);

 #define DOMAIN_FIELD(_type, _name, _desc, _format, _is_jiffies, _ver)          \
-       size += fprintf(fp, "%" PRIu64 " ", (unsigned long)ds->_ver._name)
+       size += fprintf(fp, "%" PRIu64 " ", (uint64_t)ds->_ver._name)

        if (version == 15) {
 #include <perf/schedstat-v15.h>
acme@five:~/git/perf-tools-next$

I'm fixing it here,

- Arnaldo