Skip to contentSkip to conversation

perf sched: Introduce stats tool

PATCH In review Ravi Bangoria 5 participants 17 messages Sep 16, 2024 – Sep 27, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover perf sched: Introduce stats tool

MOTIVATION
----------

Existing perf sched is quite exhaustive and provides lot of insights into scheduler behavior but it quickly becomes impractical to use for long running or scheduler intensive workload. For ex, perf sched record has ~7.77% overhead on hackbench (with 25 groups each running 700K loops on a 2-socket 128 Cores 256 Threads 3rd Generation EPYC Server), and it generates huge 56G perf.data for which perf takes ~137 mins to prepare and write it to disk [1].

Unlike perf sched record, which hooks onto set of scheduler tracepoints and generates samples on a tracepoint hit, perf sched stats record takes snapshot of the /proc/schedstat file before and after the workload, i.e. there is almost zero interference on workload run. Also, it takes very minimal time to parse /proc/schedstat, convert it into perf samples and save those samples into perf.data file. Result perf.data file is much smaller. So, overall perf sched stats record is much more light weight compare to perf sched record.

We, internally at AMD, have been using this (a variant of this, known as "sched-scoreboard"[2]) and found it to be very useful to analyse impact of any scheduler code changes[3][4].

Please note that, this is not a replacement of perf sched record/report. The intended users of the new tool are scheduler developers, not regular users.

USAGE
-----

  # perf sched stats record
  # perf sched stats report

Note: Although perf sched stats tool supports workload profiling syntax (i.e. -- <workload> ), the recorded profile is still systemwide since the /proc/schedstat is a systemwide file.

HOW TO INTERPRET THE REPORT
---------------------------

The perf sched stats report starts with total time profiling was active in terms of jiffies:

----------------------------------------------------------------------------------------------------
Time elapsed (in jiffies) : 24537
----------------------------------------------------------------------------------------------------

Next is CPU scheduling statistics. These are simple diffs of /proc/schedstat CPU lines along with description. The report also prints % relative to base stat.

In the example below, schedule() left the CPU0 idle 98.19% of the time. 16.54% of total try_to_wake_up() was to wakeup local CPU. And, the total waittime by tasks on CPU0 is 0.49% of the total runtime by tasks on the same CPU.

----------------------------------------------------------------------------------------------------
CPU 0
----------------------------------------------------------------------------------------------------

  sched_yield() count                                         :           0
  Legacy counter can be ignored                               :           0
  schedule() called                                           :       17138
  schedule() left the processor idle                          :       16827 ( 98.19% )
  try_to_wake_up() was called                                 :         508
  try_to_wake_up() was called to wake up the local cpu        :          84 ( 16.54% )
  total runtime by tasks on this processor (in jiffies)       :  2408959243
  total waittime by tasks on this processor (in jiffies)      :    11731825 ( 0.49% )
  total timeslices run on this cpu                            :         311

----------------------------------------------------------------------------------------------------

Next is load balancing statistics. For each of the sched domains (eg: SMT, MC, DIE...), the scheduler computes statistics under the following three categories:

1) Idle Load Balance: Load balancing performed on behalf of a long idling CPU by some other CPU.
2) Busy Load Balance: Load balancing performed when the CPU was busy.
3) New Idle Balance : Load balancing performed when a CPU just became idle.

Under each of these three categories, sched stats report provides different load balancing statistics. Along with direct stats, the report also contains derived metrics prefixed with *. Example:

----------------------------------------------------------------------------------------------------
CPU 0 DOMAIN SMT CPUS <0, 64>
----------------------------------------- <Category idle> ------------------------------------------

  load_balance() count on cpu idle                                 :          50   $      490.74 $
  load_balance() found balanced on cpu idle                        :          42   $      584.21 $
  load_balance() move task failed on cpu idle                      :           8   $     3067.12 $
  imbalance sum on cpu idle                                        :           8
  pull_task() count on cpu idle                                    :           0
  pull_task() when target task was cache-hot on cpu idle           :           0
  load_balance() failed to find busier queue on cpu idle           :           0   $        0.00 $
  load_balance() failed to find busier group on cpu idle           :          42   $      584.21 $
  *load_balance() success count on cpu idle                        :           0
  *avg task pulled per successful lb attempt (cpu idle)            :        0.00
  ----------------------------------------- <Category busy> ------------------------------------------
  load_balance() count on cpu busy                                 :           2   $    12268.50 $
  load_balance() found balanced on cpu busy                        :           2   $    12268.50 $
  load_balance() move task failed on cpu busy                      :           0   $        0.00 $
  imbalance sum on cpu busy                                        :           0
  pull_task() count on cpu busy                                    :           0
  pull_task() when target task was cache-hot on cpu busy           :           0
  load_balance() failed to find busier queue on cpu busy           :           0   $        0.00 $
  load_balance() failed to find busier group on cpu busy           :           1   $    24537.00 $
  *load_balance() success count on cpu busy                        :           0
  *avg task pulled per successful lb attempt (cpu busy)            :        0.00
  ---------------------------------------- <Category newidle> ----------------------------------------
  load_balance() count on cpu newly idle                           :         427   $       57.46 $
  load_balance() found balanced on cpu newly idle                  :         382   $       64.23 $
  load_balance() move task failed on cpu newly idle                :          45   $      545.27 $
  imbalance sum on cpu newly idle                                  :          48
  pull_task() count on cpu newly idle                              :           0
  pull_task() when target task was cache-hot on cpu newly idle     :           0
  load_balance() failed to find busier queue on cpu newly idle     :           0   $        0.00 $
  load_balance() failed to find busier group on cpu newly idle     :         382   $       64.23 $
  *load_balance() success count on cpu newly idle                  :           0
  *avg task pulled per successful lb attempt (cpu newly idle)      :        0.00

----------------------------------------------------------------------------------------------------

Consider following line:

load_balance() found balanced on cpu newly idle : 382 $ 64.23 $

While profiling was active, the load-balancer found 382 times the load needs to be balanced on a newly idle CPU 0. Following value encapsulated inside $ is average jiffies between two events (24537 / 382 = 64.23).

Next are active_load_balance() stats. alb did not trigger while the profiling was active, hence it's all 0s.

--------------------------------- <Category active_load_balance()> ---------------------------------

  active_load_balance() count                                      :           0
  active_load_balance() move task failed                           :           0
  active_load_balance() successfully moved a task                  :           0

----------------------------------------------------------------------------------------------------

Next are sched_balance_exec() and sched_balance_fork() stats. They are not used but we kept it in RFC just for legacy purpose. Unless opposed, we plan to remove them in next revision.

Next are wakeup statistics. For every domain, the report also shows task-wakeup statistics. Example:

------------------------------------------- <Wakeup Info> ------------------------------------------

  try_to_wake_up() awoke a task that last ran on a diff cpu       :       12070
  try_to_wake_up() moved task because cache-cold on own cpu       :        3324
  try_to_wake_up() started passive balancing                      :           0

----------------------------------------------------------------------------------------------------

Same set of stats are reported for each CPU and each domain level.

RFC: https://lore.kernel.org/r/[email protected]
RFC->v1:
- [Kernel] Print domain name along with domain number in /proc/schedstat file.
- s/schedstat/stats/ for the subcommand.
- Record domain name and cpumask details, also show them in report.
- Add CPU filtering capability at record and report time.
- Add /proc/schedstat v16 support.
- Live mode support. Similar to perf stat command, live mode prints the sched stats on the stdout.
- Add pager support in perf sched stats report for better scrolling.
- Some minor cosmetic changes in report output to improve readability.
- Rebase to latest perf-tools-next/perf-tools-next (1de5b5dcb835).

TODO:
- Add perf unit tests to test basic sched stats functionalities
- Describe new tool, it's usage and interpretation of report data in the perf-sched man page.
- Currently sched stats tool provides statistics of only one run but we are planning to add perf sched stats diff which can compare the data of two different runs (possibly good and bad) and highlight where scheduler decisions are impacting workload performance.
- perf sched stats records /proc/schedstat which is a CPU and domain level scheduler statistic. We are planning to add taskstat tool which reads task stats from procfs and generate scheduler statistic report at task granularity. this will probably a standalone tool, something like perf sched taskstat record/report.
- Except pre-processor related checkpatch warnings, we have addressed most of the other possible warnings.

Patches are prepared on perf-tools-next/perf-tools-next (1de5b5dcb835).

Apologies for the long delay in respin. sched-ext was proposed while we were working on next revision. So, we held on for a moment to settle down dusts and get a clear idea of whether the new tool will be useful or not.

[1] https://youtu.be/lg-9aG2ajA0?t=283
[2] https://github.com/AMDESE/sched-scoreboard
[3] https://lore.kernel.org/lkml/[email protected]/
[4] https://lore.kernel.org/lkml/[email protected]/

K Prateek Nayak (1):
sched/stats: Print domain name in /proc/schedstat

Swapnil Sapkal (4):
perf sched stats: Add record and rawdump support perf sched stats: Add schedstat v16 support perf sched stats: Add support for report subcommand perf sched stats: Add support for live mode

 Documentation/scheduler/sched-stats.rst       |   8 +-
 kernel/sched/stats.c                          |   6 +-
 tools/lib/perf/Documentation/libperf.txt      |   2 +
 tools/lib/perf/Makefile                       |   2 +-
 tools/lib/perf/include/perf/event.h           |  56 ++
 .../lib/perf/include/perf/schedstat-cpu-v15.h |  22 +
 .../lib/perf/include/perf/schedstat-cpu-v16.h |  22 +
 .../perf/include/perf/schedstat-domain-v15.h  | 121 +++
 .../perf/include/perf/schedstat-domain-v16.h  | 121 +++
 tools/perf/builtin-inject.c                   |   2 +
 tools/perf/builtin-sched.c                    | 778 +++++++++++++++++-
 tools/perf/util/event.c                       | 104 +++
 tools/perf/util/event.h                       |   2 +
 tools/perf/util/session.c                     |  20 +
 tools/perf/util/synthetic-events.c            | 255 ++++++
 tools/perf/util/synthetic-events.h            |   3 +
 tools/perf/util/tool.c                        |  20 +
 tools/perf/util/tool.h                        |   4 +-
 18 files changed, 1542 insertions(+), 6 deletions(-)
 create mode 100644 tools/lib/perf/include/perf/schedstat-cpu-v15.h
 create mode 100644 tools/lib/perf/include/perf/schedstat-cpu-v16.h
 create mode 100644 tools/lib/perf/include/perf/schedstat-domain-v15.h
 create mode 100644 tools/lib/perf/include/perf/schedstat-domain-v16.h
Signature · 1 line
2.46.0
#1 lore raw

PATCH 1/5 sched/stats: Print domain name in /proc/schedstat

From: K Prateek Nayak <[email protected]>

Currently, there does not exist a straightforward way to extract the names of the sched domains and match them to the per-cpu domain entry in /proc/schedstat other than looking at the debugfs files which are only visible after enabling "verbose" debug after commit 34320745dfc9 ("sched/debug: Put sched/domains files under the verbose flag")

Since tools like perf sched schedstat require displaying per-domain information in user friendly manner, display the names of sched domain, alongside their level in /proc/schedstat if CONFIG_SCHED_DEBUG is enabled.

Domain names also makes the /proc/schedstat data unambiguous when some of the cpus are offline. For example, on a 128 cpus AMD Zen3 machine where CPU0 and CPU64 are SMT siblings and CPU64 is offline:

Before:

    cpu0 ...
    domain0 ...
    domain1 ...
    cpu1 ...
    domain0 ...
    domain1 ...
    domain2 ...

After:

    cpu0 ...
    domain0:MC ...
    domain1:PKG ...
    cpu1 ...
    domain0:SMT ...
    domain1:MC ...
    domain2:PKG ...

schedstat version has not been updated since this change merely adds additional information to the domain name field and does not add a new field altogether.

---
 Documentation/scheduler/sched-stats.rst | 8 ++++++--
 kernel/sched/stats.c                    | 6 +++++-
 2 files changed, 11 insertions(+), 3 deletions(-)
Documentation/scheduler/sched-stats.rst +6 -2
index 7c2b16c4729d..b60a3e7bc108 100644
@@ -6,6 +6,8 @@ Version 16 of schedstats changed the order of definitions within
 'enum cpu_idle_type', which changed the order of [CPU_MAX_IDLE_TYPES]
 columns in show_schedstat(). In particular the position of CPU_IDLE
 and __CPU_NOT_IDLE changed places. The size of the array is unchanged.
+With CONFIG_SCHED_DEBUG enabled, the domain field can also print the
+name of the corresponding sched domain.
 
 Version 15 of schedstats dropped counters for some sched_yield:
 yld_exp_empty, yld_act_empty and yld_both_empty. Otherwise, it is
@@ -71,9 +73,11 @@ Domain statistics
 -----------------
 One of these is produced per domain for each cpu described. (Note that if
 CONFIG_SMP is not defined, *no* domains are utilized and these lines
-will not appear in the output.)
+will not appear in the output. [:<name>] is an optional extension to the domain
+field that prints the name of the corresponding sched domain. It can appear in
+schedstat version 16 and above, and requires CONFIG_SCHED_DEBUG.)
 
-domain<N> <cpumask> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
+domain<N>[:<name>] <cpumask> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
 
 The first field is a bit mask indicating what cpus this domain operates over.
 
kernel/sched/stats.c +5 -1
index eb0cdcd4d921..bd4ed737e894 100644
@@ -138,7 +138,11 @@ static int show_schedstat(struct seq_file *seq, void *v)
 		for_each_domain(cpu, sd) {
 			enum cpu_idle_type itype;
 
-			seq_printf(seq, "domain%d %*pb", dcount++,
+			seq_printf(seq, "domain%d", dcount++);
+#ifdef CONFIG_SCHED_DEBUG
+			seq_printf(seq, ":%s", sd->name);
+#endif
+			seq_printf(seq, " %*pb",
 				   cpumask_pr_args(sched_domain_span(sd)));
 			for (itype = 0; itype < CPU_MAX_IDLE_TYPES; itype++) {
 				seq_printf(seq, " %u %u %u %u %u %u %u %u",
Signature · 1 line
2.46.0
#2 lore raw

PATCH 2/5 perf sched stats: Add record and rawdump support

In reply to Ravi Bangoria

From: Swapnil Sapkal <[email protected]>

Define new, perf tool only, sample types and their layouts. Add logic to parse /proc/schedstat, convert it to perf sample format and save samples to perf.data file with perf sched stats record command. Also add logic to read perf.data file, interpret schedstat samples and print rawdump of samples with perf script -D.

Note that, /proc/schedstat file output is standardized with version number. The patch supports v15 but older or newer version can be added easily.

---
 tools/lib/perf/Documentation/libperf.txt      |   2 +
 tools/lib/perf/Makefile                       |   2 +-
 tools/lib/perf/include/perf/event.h           |  42 +++
 .../lib/perf/include/perf/schedstat-cpu-v15.h |  13 +
 .../perf/include/perf/schedstat-domain-v15.h  |  40 +++
 tools/perf/builtin-inject.c                   |   2 +
 tools/perf/builtin-sched.c                    | 222 +++++++++++++++-
 tools/perf/util/event.c                       |  98 +++++++
 tools/perf/util/event.h                       |   2 +
 tools/perf/util/session.c                     |  20 ++
 tools/perf/util/synthetic-events.c            | 249 ++++++++++++++++++
 tools/perf/util/synthetic-events.h            |   3 +
 tools/perf/util/tool.c                        |  20 ++
 tools/perf/util/tool.h                        |   4 +-
 14 files changed, 716 insertions(+), 3 deletions(-)
 create mode 100644 tools/lib/perf/include/perf/schedstat-cpu-v15.h
 create mode 100644 tools/lib/perf/include/perf/schedstat-domain-v15.h
tools/lib/perf/Documentation/libperf.txt +2 -0
index fcfb9499ef9c..39c78682ad2e 100644
@@ -211,6 +211,8 @@ SYNOPSIS
   struct perf_record_time_conv;
   struct perf_record_header_feature;
   struct perf_record_compressed;
+  struct perf_record_schedstat_cpu;
+  struct perf_record_schedstat_domain;
 --
 
 DESCRIPTION
tools/lib/perf/Makefile +1 -1
index 3a9b2140aa04..ebbfea891a6a 100644
@@ -187,7 +187,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
+HDRS := bpf_perf.h core.h cpumap.h threadmap.h evlist.h evsel.h event.h mmap.h schedstat-cpu-v15.h schedstat-domain-v15.h
 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
tools/lib/perf/include/perf/event.h +42 -0

60 lines not on this page · raw message

tools/lib/perf/include/perf/schedstat-cpu-v15.h new file +13 -0
new file mode 100644
index 000000000000..8e4355ee3705
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifdef CPU_FIELD
+CPU_FIELD(__u32, yld_count, v15)
+CPU_FIELD(__u32, array_exp, v15)
+CPU_FIELD(__u32, sched_count, v15)
+CPU_FIELD(__u32, sched_goidle, v15)
+CPU_FIELD(__u32, ttwu_count, v15)
+CPU_FIELD(__u32, ttwu_local, v15)
+CPU_FIELD(__u64, rq_cpu_time, v15)
+CPU_FIELD(__u64, run_delay, v15)
+CPU_FIELD(__u64, pcount, v15)
+#endif
tools/lib/perf/include/perf/schedstat-domain-v15.h new file +40 -0
new file mode 100644
index 000000000000..422e713d617a
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifdef DOMAIN_FIELD
+DOMAIN_FIELD(__u32, idle_lb_count, v15)
+DOMAIN_FIELD(__u32, idle_lb_balanced, v15)
+DOMAIN_FIELD(__u32, idle_lb_failed, v15)
+DOMAIN_FIELD(__u32, idle_lb_imbalance, v15)
+DOMAIN_FIELD(__u32, idle_lb_gained, v15)
+DOMAIN_FIELD(__u32, idle_lb_hot_gained, v15)
+DOMAIN_FIELD(__u32, idle_lb_nobusyq, v15)
+DOMAIN_FIELD(__u32, idle_lb_nobusyg, v15)
+DOMAIN_FIELD(__u32, busy_lb_count, v15)
+DOMAIN_FIELD(__u32, busy_lb_balanced, v15)
+DOMAIN_FIELD(__u32, busy_lb_failed, v15)
+DOMAIN_FIELD(__u32, busy_lb_imbalance, v15)
+DOMAIN_FIELD(__u32, busy_lb_gained, v15)
+DOMAIN_FIELD(__u32, busy_lb_hot_gained, v15)
+DOMAIN_FIELD(__u32, busy_lb_nobusyq, v15)
+DOMAIN_FIELD(__u32, busy_lb_nobusyg, v15)
+DOMAIN_FIELD(__u32, newidle_lb_count, v15)
+DOMAIN_FIELD(__u32, newidle_lb_balanced, v15)
+DOMAIN_FIELD(__u32, newidle_lb_failed, v15)
+DOMAIN_FIELD(__u32, newidle_lb_imbalance, v15)
+DOMAIN_FIELD(__u32, newidle_lb_gained, v15)
+DOMAIN_FIELD(__u32, newidle_lb_hot_gained, v15)
+DOMAIN_FIELD(__u32, newidle_lb_nobusyq, v15)
+DOMAIN_FIELD(__u32, newidle_lb_nobusyg, v15)
+DOMAIN_FIELD(__u32, alb_count, v15)
+DOMAIN_FIELD(__u32, alb_failed, v15)
+DOMAIN_FIELD(__u32, alb_pushed, v15)
+DOMAIN_FIELD(__u32, sbe_count, v15)
+DOMAIN_FIELD(__u32, sbe_balanced, v15)
+DOMAIN_FIELD(__u32, sbe_pushed, v15)
+DOMAIN_FIELD(__u32, sbf_count, v15)
+DOMAIN_FIELD(__u32, sbf_balanced, v15)
+DOMAIN_FIELD(__u32, sbf_pushed, v15)
+DOMAIN_FIELD(__u32, ttwu_wake_remote, v15)
+DOMAIN_FIELD(__u32, ttwu_move_affine, v15)
+DOMAIN_FIELD(__u32, ttwu_move_balance, v15)
+#endif /* DOMAIN_FIELD */
tools/perf/builtin-inject.c +2 -0
index d6989195a061..b6eca6e92390 100644
@@ -2530,6 +2530,8 @@ int cmd_inject(int argc, const char **argv)
 	inject.tool.finished_init	= perf_event__repipe_op2_synth;
 	inject.tool.compressed		= perf_event__repipe_op4_synth;
 	inject.tool.auxtrace		= perf_event__repipe_auxtrace;
+	inject.tool.schedstat_cpu	= perf_event__repipe_op2_synth;
+	inject.tool.schedstat_domain	= perf_event__repipe_op2_synth;
 	inject.tool.dont_split_sample_group = true;
 	inject.session = __perf_session__new(&data, &inject.tool,
 					     /*trace_event_repipe=*/inject.output.is_pipe);
tools/perf/builtin-sched.c +221 -1

266 lines not on this page · raw message

tools/perf/util/event.c +98 -0

110 lines not on this page · raw message

tools/perf/util/event.h +2 -0
index f8742e6230a5..96e7cd1d282d 100644
@@ -360,6 +360,8 @@ size_t perf_event__fprintf_cgroup(union perf_event *event, FILE *fp);
 size_t perf_event__fprintf_ksymbol(union perf_event *event, FILE *fp);
 size_t perf_event__fprintf_bpf(union perf_event *event, FILE *fp);
 size_t perf_event__fprintf_text_poke(union perf_event *event, struct machine *machine,FILE *fp);
+size_t perf_event__fprintf_schedstat_cpu(union perf_event *event, FILE *fp);
+size_t perf_event__fprintf_schedstat_domain(union perf_event *event, FILE *fp);
 size_t perf_event__fprintf(union perf_event *event, struct machine *machine, FILE *fp);
 
 int kallsyms__get_function_start(const char *kallsyms_filename,
tools/perf/util/session.c +20 -0
index dbaf07bf6c5f..a929a63e1827 100644
@@ -691,6 +691,20 @@ static void perf_event__time_conv_swap(union perf_event *event,
 	}
 }
 
+static void
+perf_event__schedstat_cpu_swap(union perf_event *event __maybe_unused,
+			       bool sample_id_all __maybe_unused)
+{
+	/* FIXME */
+}
+
+static void
+perf_event__schedstat_domain_swap(union perf_event *event __maybe_unused,
+				  bool sample_id_all __maybe_unused)
+{
+	/* FIXME */
+}
+
 typedef void (*perf_event__swap_op)(union perf_event *event,
 				    bool sample_id_all);
 
@@ -729,6 +743,8 @@ static perf_event__swap_op perf_event__swap_ops[] = {
 	[PERF_RECORD_STAT_ROUND]	  = perf_event__stat_round_swap,
 	[PERF_RECORD_EVENT_UPDATE]	  = perf_event__event_update_swap,
 	[PERF_RECORD_TIME_CONV]		  = perf_event__time_conv_swap,
+	[PERF_RECORD_SCHEDSTAT_CPU]	  = perf_event__schedstat_cpu_swap,
+	[PERF_RECORD_SCHEDSTAT_DOMAIN]	  = perf_event__schedstat_domain_swap,
 	[PERF_RECORD_HEADER_MAX]	  = NULL,
 };
 
@@ -1444,6 +1460,10 @@ static s64 perf_session__process_user_event(struct perf_session *session,
 		return err;
 	case PERF_RECORD_FINISHED_INIT:
 		return tool->finished_init(session, event);
+	case PERF_RECORD_SCHEDSTAT_CPU:
+		return tool->schedstat_cpu(session, event);
+	case PERF_RECORD_SCHEDSTAT_DOMAIN:
+		return tool->schedstat_domain(session, event);
 	default:
 		return -EINVAL;
 	}
tools/perf/util/synthetic-events.c +249 -0

252 lines not on this page · raw message

tools/perf/util/synthetic-events.h +3 -0
index b9c936b5cfeb..eab914c238df 100644
@@ -141,4 +141,7 @@ int perf_event__synthesize_for_pipe(const struct perf_tool *tool,
 				    struct perf_data *data,
 				    perf_event__handler_t process);
 
+int perf_event__synthesize_schedstat(const struct perf_tool *tool,
+				     perf_event__handler_t process,
+				     struct perf_cpu_map *user_requested_cpu);
 #endif // __PERF_SYNTHETIC_EVENTS_H
tools/perf/util/tool.c +20 -0
index 3b7f390f26eb..9f81d720735f 100644
@@ -230,6 +230,24 @@ static int perf_session__process_compressed_event_stub(struct perf_session *sess
 	return 0;
 }
 
+static int process_schedstat_cpu_stub(struct perf_session *perf_session __maybe_unused,
+				      union perf_event *event)
+{
+	if (dump_trace)
+		perf_event__fprintf_schedstat_cpu(event, stdout);
+	dump_printf(": unhandled!\n");
+	return 0;
+}
+
+static int process_schedstat_domain_stub(struct perf_session *perf_session __maybe_unused,
+					 union perf_event *event)
+{
+	if (dump_trace)
+		perf_event__fprintf_schedstat_domain(event, stdout);
+	dump_printf(": unhandled!\n");
+	return 0;
+}
+
 void perf_tool__init(struct perf_tool *tool, bool ordered_events)
 {
 	tool->ordered_events = ordered_events;
@@ -286,6 +304,8 @@ void perf_tool__init(struct perf_tool *tool, bool ordered_events)
 	tool->compressed = perf_session__process_compressed_event_stub;
 #endif
 	tool->finished_init = process_event_op2_stub;
+	tool->schedstat_cpu = process_schedstat_cpu_stub;
+	tool->schedstat_domain = process_schedstat_domain_stub;
 }
 
 bool perf_tool__compressed_is_stub(const struct perf_tool *tool)
tools/perf/util/tool.h +3 -1
index db1c7642b0d1..d289a5396b01 100644
@@ -77,7 +77,9 @@ struct perf_tool {
 			stat,
 			stat_round,
 			feature,
-			finished_init;
+			finished_init,
+			schedstat_cpu,
+			schedstat_domain;
 	event_op4	compressed;
 	event_op3	auxtrace;
 	bool		ordered_events;
Signature · 1 line
2.46.0
reviewer
#3 lore raw

Re: [PATCH 2/5] perf sched stats: Add record and rawdump support

Quoted 16 lines · Ravi Bangoria

From: Swapnil Sapkal <[email protected]>

Define new, perf tool only, sample types and their layouts. Add logic to parse /proc/schedstat, convert it to perf sample format and save samples to perf.data file with perf sched stats record command. Also add logic to read perf.data file, interpret schedstat samples and print rawdump of samples with perf script -D.

Note that, /proc/schedstat file output is standardized with version number. The patch supports v15 but older or newer version can be added easily.

---

[...]

Quoted 6 lines
tools/perf/util/synthetic-events.c +6 -0
+int perf_event__synthesize_schedstat(const struct perf_tool *tool,
+				     perf_event__handler_t process,
+				     struct perf_cpu_map *user_requested_cpus)
+{
+	union perf_event *event = NULL;
+	size_t line_len = 0;

tools/perf/util/synthetic-events.c int parse_synth_opt(char *synth) · line 2700

Quoted 10 lines
tools/perf/util/synthetic-events.c +10 -0
+	char *line = NULL;
+	char bf[BUFSIZ];
+	__u64 timestamp;
+	__u16 version;
+	struct io io;
+	int ret = -1;
+	int cpu = -1;
+	char ch;
+
+	io.fd = open("/proc/schedstat", O_RDONLY, 0);

Other parts of the tool use procfs__mountpoint() for /proc. Although it can only be in one place so it doesn't actually make a difference for this one. Probably worth it for consistency though.

tools/perf/util/synthetic-events.c int parse_synth_opt(char *synth) · line 2702

Quoted 2 lines
tools/perf/util/synthetic-events.c +2 -0
+	if (io.fd < 0) {
+		pr_err("Failed to open /proc/schedstat\n");

A hint about CONFIG_SCHEDSTAT would be useful here.

#4 lore raw

Re: [PATCH 2/5] perf sched stats: Add record and rawdump support

Hi James,

Thanks for the review.

Quoted 32 lines · James Clark
Quoted 16 lines · Ravi Bangoria

From: Swapnil Sapkal <[email protected]>

Define new, perf tool only, sample types and their layouts. Add logic to parse /proc/schedstat, convert it to perf sample format and save samples to perf.data file with perf sched stats record command. Also add logic to read perf.data file, interpret schedstat samples and print rawdump of samples with perf script -D.

Note that, /proc/schedstat file output is standardized with version number. The patch supports v15 but older or newer version can be added easily.

---

[...]

Quoted 10 lines
tools/perf/util/synthetic-events.c +10 -0
+int perf_event__synthesize_schedstat(const struct perf_tool *tool,
+                     perf_event__handler_t process,
+                     struct perf_cpu_map *user_requested_cpus)
+{
+    union perf_event *event = NULL;
+    size_t line_len = 0;
+    char *line = NULL;
+    char bf[BUFSIZ];
+    __u64 timestamp;
+    __u16 version;
Quoted 9 lines
Quoted 6 lines

+    struct io io;
+    int ret = -1;
+    int cpu = -1;
+    char ch;
+
+    io.fd = open("/proc/schedstat", O_RDONLY, 0);

Other parts of the tool use procfs__mountpoint() for /proc. Although it can only be in one place so it doesn't actually make a difference for this one. Probably worth it for consistency though.

Sure, I will update this in the next version.

Quoted 4 lines
Quoted 2 lines

+    if (io.fd < 0) {
+        pr_err("Failed to open /proc/schedstat\n");

A hint about CONFIG_SCHEDSTAT would be useful here.

Sure, I will update.

--
Thanks and Regards,
Swapnil

maintainer
#5 lore raw

Re: [PATCH 2/5] perf sched stats: Add record and rawdump support

In reply to Ravi Bangoria
Quoted 69 lines · Ravi Bangoria

From: Swapnil Sapkal <[email protected]>

Define new, perf tool only, sample types and their layouts. Add logic to parse /proc/schedstat, convert it to perf sample format and save samples to perf.data file with perf sched stats record command. Also add logic to read perf.data file, interpret schedstat samples and print rawdump of samples with perf script -D.

Note that, /proc/schedstat file output is standardized with version number. The patch supports v15 but older or newer version can be added easily.

---
 tools/lib/perf/Documentation/libperf.txt      |   2 +
 tools/lib/perf/Makefile                       |   2 +-
 tools/lib/perf/include/perf/event.h           |  42 +++
 .../lib/perf/include/perf/schedstat-cpu-v15.h |  13 +
 .../perf/include/perf/schedstat-domain-v15.h  |  40 +++
 tools/perf/builtin-inject.c                   |   2 +
 tools/perf/builtin-sched.c                    | 222 +++++++++++++++-
 tools/perf/util/event.c                       |  98 +++++++
 tools/perf/util/event.h                       |   2 +
 tools/perf/util/session.c                     |  20 ++
 tools/perf/util/synthetic-events.c            | 249 ++++++++++++++++++
 tools/perf/util/synthetic-events.h            |   3 +
 tools/perf/util/tool.c                        |  20 ++
 tools/perf/util/tool.h                        |   4 +-
 14 files changed, 716 insertions(+), 3 deletions(-)
 create mode 100644 tools/lib/perf/include/perf/schedstat-cpu-v15.h
 create mode 100644 tools/lib/perf/include/perf/schedstat-domain-v15.h
tools/lib/perf/Documentation/libperf.txt +2 -0
index fcfb9499ef9c..39c78682ad2e 100644
@@ -211,6 +211,8 @@ SYNOPSIS
   struct perf_record_time_conv;
   struct perf_record_header_feature;
   struct perf_record_compressed;
+  struct perf_record_schedstat_cpu;
+  struct perf_record_schedstat_domain;
 --
 
 DESCRIPTION
tools/lib/perf/Makefile +1 -1
index 3a9b2140aa04..ebbfea891a6a 100644
@@ -187,7 +187,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
+HDRS := bpf_perf.h core.h cpumap.h threadmap.h evlist.h evsel.h event.h mmap.h schedstat-cpu-v15.h schedstat-domain-v15.h
 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
tools/lib/perf/include/perf/event.h +1 -0
index 37bb7771d914..35be296d68d5 100644
@@ -457,6 +457,44 @@ struct perf_record_compressed {
 	char			 data[];
 };
 
+struct perf_record_schedstat_cpu_v15 {

tools/lib/perf/include/perf/event.h struct perf_record_compressed { · line 470

Quoted 10 lines
tools/lib/perf/include/perf/event.h +10 -0
+#define CPU_FIELD(_type, _name, _ver)		_type _name;
+#include "schedstat-cpu-v15.h"
+#undef CPU_FIELD
+};
+
+struct perf_record_schedstat_cpu {
+	struct perf_event_header header;
+	__u16			 version;
+	__u64			 timestamp;
+	__u32			 cpu;

Can you change the layout to minimize the paddings? Probably better to add an explicit field for unused bits.

Quoted 9 lines
tools/lib/perf/include/perf/event.h +9 -0
+	union {
+		struct perf_record_schedstat_cpu_v15 v15;
+	};
+};
+
+struct perf_record_schedstat_domain_v15 {
+#define DOMAIN_FIELD(_type, _name, _ver)	_type _name;
+#include "schedstat-domain-v15.h"
+#undef DOMAIN_FIELD

tools/lib/perf/include/perf/event.h struct perf_record_compressed { · line 489

Quoted 10 lines
tools/lib/perf/include/perf/event.h +10 -0
+};
+
+#define DOMAIN_NAME_LEN		16
+
+struct perf_record_schedstat_domain {
+	struct perf_event_header header;
+	__u16			 version;
+	__u64			 timestamp;
+	__u32			 cpu;
+	__u16			 domain;

Ditto.

Quoted 38 lines
tools/lib/perf/include/perf/event.h +12 -0
+	char			 name[DOMAIN_NAME_LEN];
+	union {
+		struct perf_record_schedstat_domain_v15 v15;
+	};
+	__u16			 nr_cpus;
+	__u8			 cpu_mask[];
+};
+
 enum perf_user_event_type { /* above any possible kernel type */
 	PERF_RECORD_USER_TYPE_START		= 64,
 	PERF_RECORD_HEADER_ATTR			= 64,
@@ -478,6 +516,8 @@ enum perf_user_event_type { /* above any possible kernel type */
 	PERF_RECORD_HEADER_FEATURE		= 80,
 	PERF_RECORD_COMPRESSED			= 81,
 	PERF_RECORD_FINISHED_INIT		= 82,
+	PERF_RECORD_SCHEDSTAT_CPU		= 83,
+	PERF_RECORD_SCHEDSTAT_DOMAIN		= 84,
 	PERF_RECORD_HEADER_MAX
 };
 
@@ -518,6 +558,8 @@ union perf_event {
 	struct perf_record_time_conv		time_conv;
 	struct perf_record_header_feature	feat;
 	struct perf_record_compressed		pack;
+	struct perf_record_schedstat_cpu	schedstat_cpu;
+	struct perf_record_schedstat_domain	schedstat_domain;
 };
 
 #endif /* __LIBPERF_EVENT_H */
tools/lib/perf/include/perf/schedstat-cpu-v15.h new file +3 -0
new file mode 100644
index 000000000000..8e4355ee3705
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifdef CPU_FIELD

tools/lib/perf/include/perf/schedstat-cpu-v15.h line 13

Quoted 10 lines
tools/lib/perf/include/perf/schedstat-cpu-v15.h new file +10 -0
+CPU_FIELD(__u32, yld_count, v15)
+CPU_FIELD(__u32, array_exp, v15)
+CPU_FIELD(__u32, sched_count, v15)
+CPU_FIELD(__u32, sched_goidle, v15)
+CPU_FIELD(__u32, ttwu_count, v15)
+CPU_FIELD(__u32, ttwu_local, v15)
+CPU_FIELD(__u64, rq_cpu_time, v15)
+CPU_FIELD(__u64, run_delay, v15)
+CPU_FIELD(__u64, pcount, v15)
+#endif

Can we have a single schedstat.h containing both CPU fields and domain fields? You might require users to define the macro always and get rid of the ifdef condition here.

Also is there any macro magic to handle the version number? I think you can have the number only (15; without 'v') and compare with input if needed..

Thanks,
Namhyung

Quoted 46 lines
tools/lib/perf/include/perf/schedstat-domain-v15.h new file +40 -0
new file mode 100644
index 000000000000..422e713d617a
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifdef DOMAIN_FIELD
+DOMAIN_FIELD(__u32, idle_lb_count, v15)
+DOMAIN_FIELD(__u32, idle_lb_balanced, v15)
+DOMAIN_FIELD(__u32, idle_lb_failed, v15)
+DOMAIN_FIELD(__u32, idle_lb_imbalance, v15)
+DOMAIN_FIELD(__u32, idle_lb_gained, v15)
+DOMAIN_FIELD(__u32, idle_lb_hot_gained, v15)
+DOMAIN_FIELD(__u32, idle_lb_nobusyq, v15)
+DOMAIN_FIELD(__u32, idle_lb_nobusyg, v15)
+DOMAIN_FIELD(__u32, busy_lb_count, v15)
+DOMAIN_FIELD(__u32, busy_lb_balanced, v15)
+DOMAIN_FIELD(__u32, busy_lb_failed, v15)
+DOMAIN_FIELD(__u32, busy_lb_imbalance, v15)
+DOMAIN_FIELD(__u32, busy_lb_gained, v15)
+DOMAIN_FIELD(__u32, busy_lb_hot_gained, v15)
+DOMAIN_FIELD(__u32, busy_lb_nobusyq, v15)
+DOMAIN_FIELD(__u32, busy_lb_nobusyg, v15)
+DOMAIN_FIELD(__u32, newidle_lb_count, v15)
+DOMAIN_FIELD(__u32, newidle_lb_balanced, v15)
+DOMAIN_FIELD(__u32, newidle_lb_failed, v15)
+DOMAIN_FIELD(__u32, newidle_lb_imbalance, v15)
+DOMAIN_FIELD(__u32, newidle_lb_gained, v15)
+DOMAIN_FIELD(__u32, newidle_lb_hot_gained, v15)
+DOMAIN_FIELD(__u32, newidle_lb_nobusyq, v15)
+DOMAIN_FIELD(__u32, newidle_lb_nobusyg, v15)
+DOMAIN_FIELD(__u32, alb_count, v15)
+DOMAIN_FIELD(__u32, alb_failed, v15)
+DOMAIN_FIELD(__u32, alb_pushed, v15)
+DOMAIN_FIELD(__u32, sbe_count, v15)
+DOMAIN_FIELD(__u32, sbe_balanced, v15)
+DOMAIN_FIELD(__u32, sbe_pushed, v15)
+DOMAIN_FIELD(__u32, sbf_count, v15)
+DOMAIN_FIELD(__u32, sbf_balanced, v15)
+DOMAIN_FIELD(__u32, sbf_pushed, v15)
+DOMAIN_FIELD(__u32, ttwu_wake_remote, v15)
+DOMAIN_FIELD(__u32, ttwu_move_affine, v15)
+DOMAIN_FIELD(__u32, ttwu_move_balance, v15)
+#endif /* DOMAIN_FIELD */
#6 lore raw

Re: [PATCH 2/5] perf sched stats: Add record and rawdump support

Hello Namhyung,

Thank you for reviewing.

Quoted 69 lines · Namhyung Kim
Quoted 68 lines · Ravi Bangoria

From: Swapnil Sapkal <[email protected]>

Define new, perf tool only, sample types and their layouts. Add logic to parse /proc/schedstat, convert it to perf sample format and save samples to perf.data file with perf sched stats record command. Also add logic to read perf.data file, interpret schedstat samples and print rawdump of samples with perf script -D.

Note that, /proc/schedstat file output is standardized with version number. The patch supports v15 but older or newer version can be added easily.

---
  tools/lib/perf/Documentation/libperf.txt      |   2 +
  tools/lib/perf/Makefile                       |   2 +-
  tools/lib/perf/include/perf/event.h           |  42 +++
  .../lib/perf/include/perf/schedstat-cpu-v15.h |  13 +
  .../perf/include/perf/schedstat-domain-v15.h  |  40 +++
  tools/perf/builtin-inject.c                   |   2 +
  tools/perf/builtin-sched.c                    | 222 +++++++++++++++-
  tools/perf/util/event.c                       |  98 +++++++
  tools/perf/util/event.h                       |   2 +
  tools/perf/util/session.c                     |  20 ++
  tools/perf/util/synthetic-events.c            | 249 ++++++++++++++++++
  tools/perf/util/synthetic-events.h            |   3 +
  tools/perf/util/tool.c                        |  20 ++
  tools/perf/util/tool.h                        |   4 +-
  14 files changed, 716 insertions(+), 3 deletions(-)

create mode 100644 tools/lib/perf/include/perf/schedstat-cpu-v15.h create mode 100644 tools/lib/perf/include/perf/schedstat-domain-v15.h

tools/lib/perf/Documentation/libperf.txt +2 -0
index fcfb9499ef9c..39c78682ad2e 100644
@@ -211,6 +211,8 @@ SYNOPSIS
    struct perf_record_time_conv;
    struct perf_record_header_feature;
    struct perf_record_compressed;
+  struct perf_record_schedstat_cpu;
+  struct perf_record_schedstat_domain;
  --
 
  DESCRIPTION
tools/lib/perf/Makefile +1 -1
index 3a9b2140aa04..ebbfea891a6a 100644
@@ -187,7 +187,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
+HDRS := bpf_perf.h core.h cpumap.h threadmap.h evlist.h evsel.h event.h mmap.h schedstat-cpu-v15.h schedstat-domain-v15.h
  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
tools/lib/perf/include/perf/event.h +0 -0
index 37bb7771d914..35be296d68d5 100644
@@ -457,6 +457,44 @@ struct perf_record_compressed {
  	char			 data[];
  };
 
Quoted 15 lines

tools/lib/perf/include/perf/event.h struct perf_record_compressed { · line 470

Quoted 11 lines
tools/lib/perf/include/perf/event.h +11 -0
+struct perf_record_schedstat_cpu_v15 {
+#define CPU_FIELD(_type, _name, _ver)		_type _name;
+#include "schedstat-cpu-v15.h"
+#undef CPU_FIELD
+};
+
+struct perf_record_schedstat_cpu {
+	struct perf_event_header header;
+	__u16			 version;
+	__u64			 timestamp;
+	__u32			 cpu;

Can you change the layout to minimize the paddings? Probably better to add an explicit field for unused bits.

Sure, I will change.

Quoted 14 lines
Quoted 14 lines
tools/lib/perf/include/perf/event.h +13 -0
+	union {
+		struct perf_record_schedstat_cpu_v15 v15;
+	};
+};
+
+struct perf_record_schedstat_domain_v15 {
+#define DOMAIN_FIELD(_type, _name, _ver)	_type _name;
+#include "schedstat-domain-v15.h"
+#undef DOMAIN_FIELD
+};
+
+#define DOMAIN_NAME_LEN		16
+
Quoted 8 lines

tools/lib/perf/include/perf/event.h struct perf_record_compressed { · line 489

Quoted 6 lines
tools/lib/perf/include/perf/event.h +6 -0
+struct perf_record_schedstat_domain {
+	struct perf_event_header header;
+	__u16			 version;
+	__u64			 timestamp;
+	__u32			 cpu;
+	__u16			 domain;

Ditto.

Ack.

Quoted 44 lines
Quoted 44 lines
tools/lib/perf/include/perf/event.h +12 -0
+	char			 name[DOMAIN_NAME_LEN];
+	union {
+		struct perf_record_schedstat_domain_v15 v15;
+	};
+	__u16			 nr_cpus;
+	__u8			 cpu_mask[];
+};
+
  enum perf_user_event_type { /* above any possible kernel type */
  	PERF_RECORD_USER_TYPE_START		= 64,
  	PERF_RECORD_HEADER_ATTR			= 64,
@@ -478,6 +516,8 @@ enum perf_user_event_type { /* above any possible kernel type */
  	PERF_RECORD_HEADER_FEATURE		= 80,
  	PERF_RECORD_COMPRESSED			= 81,
  	PERF_RECORD_FINISHED_INIT		= 82,
+	PERF_RECORD_SCHEDSTAT_CPU		= 83,
+	PERF_RECORD_SCHEDSTAT_DOMAIN		= 84,
  	PERF_RECORD_HEADER_MAX
  };
 
@@ -518,6 +558,8 @@ union perf_event {
  	struct perf_record_time_conv		time_conv;
  	struct perf_record_header_feature	feat;
  	struct perf_record_compressed		pack;
+	struct perf_record_schedstat_cpu	schedstat_cpu;
+	struct perf_record_schedstat_domain	schedstat_domain;
  };
 
  #endif /* __LIBPERF_EVENT_H */
tools/lib/perf/include/perf/schedstat-cpu-v15.h new file +8 -0
new file mode 100644
index 000000000000..8e4355ee3705
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifdef CPU_FIELD
+CPU_FIELD(__u32, yld_count, v15)
+CPU_FIELD(__u32, array_exp, v15)
+CPU_FIELD(__u32, sched_count, v15)
+CPU_FIELD(__u32, sched_goidle, v15)
+CPU_FIELD(__u32, ttwu_count, v15)
Quoted 8 lines

tools/lib/perf/include/perf/schedstat-cpu-v15.h line 13

Quoted 5 lines
tools/lib/perf/include/perf/schedstat-cpu-v15.h new file +5 -0
+CPU_FIELD(__u32, ttwu_local, v15)
+CPU_FIELD(__u64, rq_cpu_time, v15)
+CPU_FIELD(__u64, run_delay, v15)
+CPU_FIELD(__u64, pcount, v15)
+#endif

Can we have a single schedstat.h containing both CPU fields and domain fields?

Yes, I think it is possible to have a single schedstat.h for both CPU and domain fields. I will think more on this.

Quoted 3 lines

You might require users to define the macro always and get rid of the ifdef condition here.
The later patches needed this ifdef's so I kept it. If we combine both

cpu and domain fields, we will need this.

Quoted 4 lines

Also is there any macro magic to handle the version number? I think you can have the number only (15; without 'v') and compare with input if needed..

I will think more on this, if it works out cleaner I will update in the next version.

Quoted 42 lines

Thanks,
Namhyung

Quoted 38 lines
tools/lib/perf/include/perf/schedstat-domain-v15.h new file +32 -0
new file mode 100644
index 000000000000..422e713d617a
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifdef DOMAIN_FIELD
+DOMAIN_FIELD(__u32, idle_lb_count, v15)
+DOMAIN_FIELD(__u32, idle_lb_balanced, v15)
+DOMAIN_FIELD(__u32, idle_lb_failed, v15)
+DOMAIN_FIELD(__u32, idle_lb_imbalance, v15)
+DOMAIN_FIELD(__u32, idle_lb_gained, v15)
+DOMAIN_FIELD(__u32, idle_lb_hot_gained, v15)
+DOMAIN_FIELD(__u32, idle_lb_nobusyq, v15)
+DOMAIN_FIELD(__u32, idle_lb_nobusyg, v15)
+DOMAIN_FIELD(__u32, busy_lb_count, v15)
+DOMAIN_FIELD(__u32, busy_lb_balanced, v15)
+DOMAIN_FIELD(__u32, busy_lb_failed, v15)
+DOMAIN_FIELD(__u32, busy_lb_imbalance, v15)
+DOMAIN_FIELD(__u32, busy_lb_gained, v15)
+DOMAIN_FIELD(__u32, busy_lb_hot_gained, v15)
+DOMAIN_FIELD(__u32, busy_lb_nobusyq, v15)
+DOMAIN_FIELD(__u32, busy_lb_nobusyg, v15)
+DOMAIN_FIELD(__u32, newidle_lb_count, v15)
+DOMAIN_FIELD(__u32, newidle_lb_balanced, v15)
+DOMAIN_FIELD(__u32, newidle_lb_failed, v15)
+DOMAIN_FIELD(__u32, newidle_lb_imbalance, v15)
+DOMAIN_FIELD(__u32, newidle_lb_gained, v15)
+DOMAIN_FIELD(__u32, newidle_lb_hot_gained, v15)
+DOMAIN_FIELD(__u32, newidle_lb_nobusyq, v15)
+DOMAIN_FIELD(__u32, newidle_lb_nobusyg, v15)
+DOMAIN_FIELD(__u32, alb_count, v15)
+DOMAIN_FIELD(__u32, alb_failed, v15)
+DOMAIN_FIELD(__u32, alb_pushed, v15)
+DOMAIN_FIELD(__u32, sbe_count, v15)
+DOMAIN_FIELD(__u32, sbe_balanced, v15)
Quoted 8 lines

tools/lib/perf/include/perf/schedstat-domain-v15.h line 40

Quoted 8 lines
tools/lib/perf/include/perf/schedstat-domain-v15.h new file +8 -0
+DOMAIN_FIELD(__u32, sbe_pushed, v15)
+DOMAIN_FIELD(__u32, sbf_count, v15)
+DOMAIN_FIELD(__u32, sbf_balanced, v15)
+DOMAIN_FIELD(__u32, sbf_pushed, v15)
+DOMAIN_FIELD(__u32, ttwu_wake_remote, v15)
+DOMAIN_FIELD(__u32, ttwu_move_affine, v15)
+DOMAIN_FIELD(__u32, ttwu_move_balance, v15)
+#endif /* DOMAIN_FIELD */

--
Thanks and Regards,
Swapnil

#7 lore raw

PATCH 3/5 perf sched stats: Add schedstat v16 support

In reply to Ravi Bangoria

From: Swapnil Sapkal <[email protected]>

/proc/schedstat file output is standardized with version number. Add support to record and raw dump v16 version layout.

---
 tools/lib/perf/Makefile                       |  2 +-
 tools/lib/perf/include/perf/event.h           | 14 +++++++
 .../lib/perf/include/perf/schedstat-cpu-v16.h | 13 ++++++
 .../perf/include/perf/schedstat-domain-v16.h  | 40 +++++++++++++++++++
 tools/perf/util/event.c                       |  6 +++
 tools/perf/util/synthetic-events.c            |  6 +++
 6 files changed, 80 insertions(+), 1 deletion(-)
 create mode 100644 tools/lib/perf/include/perf/schedstat-cpu-v16.h
 create mode 100644 tools/lib/perf/include/perf/schedstat-domain-v16.h
tools/lib/perf/Makefile +1 -1
index ebbfea891a6a..de0f4ffd9e16 100644
@@ -187,7 +187,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-cpu-v15.h schedstat-domain-v15.h
+HDRS := bpf_perf.h core.h cpumap.h threadmap.h evlist.h evsel.h event.h mmap.h schedstat-cpu-v15.h schedstat-domain-v15.h schedstat-cpu-v16.h schedstat-domain-v16.h
 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
tools/lib/perf/include/perf/event.h +14 -0
index 35be296d68d5..c332d467c9c9 100644
@@ -463,6 +463,12 @@ struct perf_record_schedstat_cpu_v15 {
 #undef CPU_FIELD
 };
 
+struct perf_record_schedstat_cpu_v16 {
+#define CPU_FIELD(_type, _name, _ver)		_type _name;
+#include "schedstat-cpu-v16.h"
+#undef CPU_FIELD
+};
+
 struct perf_record_schedstat_cpu {
 	struct perf_event_header header;
 	__u16			 version;
@@ -470,6 +476,7 @@ struct perf_record_schedstat_cpu {
 	__u32			 cpu;
 	union {
 		struct perf_record_schedstat_cpu_v15 v15;
+		struct perf_record_schedstat_cpu_v16 v16;
 	};
 };
 
@@ -479,6 +486,12 @@ struct perf_record_schedstat_domain_v15 {
 #undef DOMAIN_FIELD
 };
 
+struct perf_record_schedstat_domain_v16 {
+#define DOMAIN_FIELD(_type, _name, _ver)	_type _name;
+#include "schedstat-domain-v16.h"
+#undef DOMAIN_FIELD
+};
+
 #define DOMAIN_NAME_LEN		16
 
 struct perf_record_schedstat_domain {
@@ -490,6 +503,7 @@ struct perf_record_schedstat_domain {
 	char			 name[DOMAIN_NAME_LEN];
 	union {
 		struct perf_record_schedstat_domain_v15 v15;
+		struct perf_record_schedstat_domain_v16 v16;
 	};
 	__u16			 nr_cpus;
 	__u8			 cpu_mask[];
tools/lib/perf/include/perf/schedstat-cpu-v16.h new file +13 -0
new file mode 100644
index 000000000000..f3a55131a05a
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifdef CPU_FIELD
+CPU_FIELD(__u32, yld_count, v16)
+CPU_FIELD(__u32, array_exp, v16)
+CPU_FIELD(__u32, sched_count, v16)
+CPU_FIELD(__u32, sched_goidle, v16)
+CPU_FIELD(__u32, ttwu_count, v16)
+CPU_FIELD(__u32, ttwu_local, v16)
+CPU_FIELD(__u64, rq_cpu_time, v16)
+CPU_FIELD(__u64, run_delay, v16)
+CPU_FIELD(__u64, pcount, v16)
+#endif /* CPU_FIELD */
tools/lib/perf/include/perf/schedstat-domain-v16.h new file +40 -0
new file mode 100644
index 000000000000..d6ef895c9d32
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifdef DOMAIN_FIELD
+DOMAIN_FIELD(__u32, busy_lb_count, v16)
+DOMAIN_FIELD(__u32, busy_lb_balanced, v16)
+DOMAIN_FIELD(__u32, busy_lb_failed, v16)
+DOMAIN_FIELD(__u32, busy_lb_imbalance, v16)
+DOMAIN_FIELD(__u32, busy_lb_gained, v16)
+DOMAIN_FIELD(__u32, busy_lb_hot_gained, v16)
+DOMAIN_FIELD(__u32, busy_lb_nobusyq, v16)
+DOMAIN_FIELD(__u32, busy_lb_nobusyg, v16)
+DOMAIN_FIELD(__u32, idle_lb_count, v16)
+DOMAIN_FIELD(__u32, idle_lb_balanced, v16)
+DOMAIN_FIELD(__u32, idle_lb_failed, v16)
+DOMAIN_FIELD(__u32, idle_lb_imbalance, v16)
+DOMAIN_FIELD(__u32, idle_lb_gained, v16)
+DOMAIN_FIELD(__u32, idle_lb_hot_gained, v16)
+DOMAIN_FIELD(__u32, idle_lb_nobusyq, v16)
+DOMAIN_FIELD(__u32, idle_lb_nobusyg, v16)
+DOMAIN_FIELD(__u32, newidle_lb_count, v16)
+DOMAIN_FIELD(__u32, newidle_lb_balanced, v16)
+DOMAIN_FIELD(__u32, newidle_lb_failed, v16)
+DOMAIN_FIELD(__u32, newidle_lb_imbalance, v16)
+DOMAIN_FIELD(__u32, newidle_lb_gained, v16)
+DOMAIN_FIELD(__u32, newidle_lb_hot_gained, v16)
+DOMAIN_FIELD(__u32, newidle_lb_nobusyq, v16)
+DOMAIN_FIELD(__u32, newidle_lb_nobusyg, v16)
+DOMAIN_FIELD(__u32, alb_count, v16)
+DOMAIN_FIELD(__u32, alb_failed, v16)
+DOMAIN_FIELD(__u32, alb_pushed, v16)
+DOMAIN_FIELD(__u32, sbe_count, v16)
+DOMAIN_FIELD(__u32, sbe_balanced, v16)
+DOMAIN_FIELD(__u32, sbe_pushed, v16)
+DOMAIN_FIELD(__u32, sbf_count, v16)
+DOMAIN_FIELD(__u32, sbf_balanced, v16)
+DOMAIN_FIELD(__u32, sbf_pushed, v16)
+DOMAIN_FIELD(__u32, ttwu_wake_remote, v16)
+DOMAIN_FIELD(__u32, ttwu_move_affine, v16)
+DOMAIN_FIELD(__u32, ttwu_move_balance, v16)
+#endif /* DOMAIN_FIELD */
tools/perf/util/event.c +6 -0
index c9bc8237e3fa..d138e4a5787c 100644
@@ -566,6 +566,9 @@ size_t perf_event__fprintf_schedstat_cpu(union perf_event *event, FILE *fp)
 	if (version == 15) {
 #include <perf/schedstat-cpu-v15.h>
 		return size;
+	} else if (version == 16) {
+#include <perf/schedstat-cpu-v16.h>
+		return size;
 	}
 #undef CPU_FIELD
 
@@ -641,6 +644,9 @@ size_t perf_event__fprintf_schedstat_domain(union perf_event *event, FILE *fp)
 	if (version == 15) {
 #include <perf/schedstat-domain-v15.h>
 		return size;
+	} else if (version == 16) {
+#include <perf/schedstat-domain-v16.h>
+		return size;
 	}
 #undef DOMAIN_FIELD
 
tools/perf/util/synthetic-events.c +6 -0
index 9d8450b6eda9..73b2492a4cde 100644
@@ -2546,6 +2546,8 @@ static union perf_event *__synthesize_schedstat_cpu(struct io *io, __u16 version
 
 	if (version == 15) {
 #include <perf/schedstat-cpu-v15.h>
+	} else if (version == 16) {
+#include <perf/schedstat-cpu-v16.h>
 	}
 #undef CPU_FIELD
 
@@ -2667,6 +2669,8 @@ static union perf_event *__synthesize_schedstat_domain(struct io *io, __u16 vers
 
 	if (version == 15) {
 #include <perf/schedstat-domain-v15.h>
+	} else if (version == 16) {
+#include <perf/schedstat-domain-v16.h>
 	}
 #undef DOMAIN_FIELD
 
@@ -2709,6 +2713,8 @@ int perf_event__synthesize_schedstat(const struct perf_tool *tool,
 
 	if (!strcmp(line, "version 15\n")) {
 		version = 15;
+	} else if (!strcmp(line, "version 16\n")) {
+		version = 16;
 	} else {
 		pr_err("Unsupported /proc/schedstat version: %s", line + 8);
 		goto out_free_line;
Signature · 1 line
2.46.0
maintainer
#8 lore raw

Re: [PATCH 3/5] perf sched stats: Add schedstat v16 support

Quoted 4 lines · Ravi Bangoria

From: Swapnil Sapkal <[email protected]>

/proc/schedstat file output is standardized with version number. Add support to record and raw dump v16 version layout.

How many difference between v15 and v16? Can we have it in the same file with a different version number?

Thanks,
Namhyung

Quoted 197 lines
---
 tools/lib/perf/Makefile                       |  2 +-
 tools/lib/perf/include/perf/event.h           | 14 +++++++
 .../lib/perf/include/perf/schedstat-cpu-v16.h | 13 ++++++
 .../perf/include/perf/schedstat-domain-v16.h  | 40 +++++++++++++++++++
 tools/perf/util/event.c                       |  6 +++
 tools/perf/util/synthetic-events.c            |  6 +++
 6 files changed, 80 insertions(+), 1 deletion(-)
 create mode 100644 tools/lib/perf/include/perf/schedstat-cpu-v16.h
 create mode 100644 tools/lib/perf/include/perf/schedstat-domain-v16.h
tools/lib/perf/Makefile +1 -1
index ebbfea891a6a..de0f4ffd9e16 100644
@@ -187,7 +187,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-cpu-v15.h schedstat-domain-v15.h
+HDRS := bpf_perf.h core.h cpumap.h threadmap.h evlist.h evsel.h event.h mmap.h schedstat-cpu-v15.h schedstat-domain-v15.h schedstat-cpu-v16.h schedstat-domain-v16.h
 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
tools/lib/perf/include/perf/event.h +14 -0
index 35be296d68d5..c332d467c9c9 100644
@@ -463,6 +463,12 @@ struct perf_record_schedstat_cpu_v15 {
 #undef CPU_FIELD
 };
 
+struct perf_record_schedstat_cpu_v16 {
+#define CPU_FIELD(_type, _name, _ver)		_type _name;
+#include "schedstat-cpu-v16.h"
+#undef CPU_FIELD
+};
+
 struct perf_record_schedstat_cpu {
 	struct perf_event_header header;
 	__u16			 version;
@@ -470,6 +476,7 @@ struct perf_record_schedstat_cpu {
 	__u32			 cpu;
 	union {
 		struct perf_record_schedstat_cpu_v15 v15;
+		struct perf_record_schedstat_cpu_v16 v16;
 	};
 };
 
@@ -479,6 +486,12 @@ struct perf_record_schedstat_domain_v15 {
 #undef DOMAIN_FIELD
 };
 
+struct perf_record_schedstat_domain_v16 {
+#define DOMAIN_FIELD(_type, _name, _ver)	_type _name;
+#include "schedstat-domain-v16.h"
+#undef DOMAIN_FIELD
+};
+
 #define DOMAIN_NAME_LEN		16
 
 struct perf_record_schedstat_domain {
@@ -490,6 +503,7 @@ struct perf_record_schedstat_domain {
 	char			 name[DOMAIN_NAME_LEN];
 	union {
 		struct perf_record_schedstat_domain_v15 v15;
+		struct perf_record_schedstat_domain_v16 v16;
 	};
 	__u16			 nr_cpus;
 	__u8			 cpu_mask[];
tools/lib/perf/include/perf/schedstat-cpu-v16.h new file +13 -0
new file mode 100644
index 000000000000..f3a55131a05a
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifdef CPU_FIELD
+CPU_FIELD(__u32, yld_count, v16)
+CPU_FIELD(__u32, array_exp, v16)
+CPU_FIELD(__u32, sched_count, v16)
+CPU_FIELD(__u32, sched_goidle, v16)
+CPU_FIELD(__u32, ttwu_count, v16)
+CPU_FIELD(__u32, ttwu_local, v16)
+CPU_FIELD(__u64, rq_cpu_time, v16)
+CPU_FIELD(__u64, run_delay, v16)
+CPU_FIELD(__u64, pcount, v16)
+#endif /* CPU_FIELD */
tools/lib/perf/include/perf/schedstat-domain-v16.h new file +40 -0
new file mode 100644
index 000000000000..d6ef895c9d32
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifdef DOMAIN_FIELD
+DOMAIN_FIELD(__u32, busy_lb_count, v16)
+DOMAIN_FIELD(__u32, busy_lb_balanced, v16)
+DOMAIN_FIELD(__u32, busy_lb_failed, v16)
+DOMAIN_FIELD(__u32, busy_lb_imbalance, v16)
+DOMAIN_FIELD(__u32, busy_lb_gained, v16)
+DOMAIN_FIELD(__u32, busy_lb_hot_gained, v16)
+DOMAIN_FIELD(__u32, busy_lb_nobusyq, v16)
+DOMAIN_FIELD(__u32, busy_lb_nobusyg, v16)
+DOMAIN_FIELD(__u32, idle_lb_count, v16)
+DOMAIN_FIELD(__u32, idle_lb_balanced, v16)
+DOMAIN_FIELD(__u32, idle_lb_failed, v16)
+DOMAIN_FIELD(__u32, idle_lb_imbalance, v16)
+DOMAIN_FIELD(__u32, idle_lb_gained, v16)
+DOMAIN_FIELD(__u32, idle_lb_hot_gained, v16)
+DOMAIN_FIELD(__u32, idle_lb_nobusyq, v16)
+DOMAIN_FIELD(__u32, idle_lb_nobusyg, v16)
+DOMAIN_FIELD(__u32, newidle_lb_count, v16)
+DOMAIN_FIELD(__u32, newidle_lb_balanced, v16)
+DOMAIN_FIELD(__u32, newidle_lb_failed, v16)
+DOMAIN_FIELD(__u32, newidle_lb_imbalance, v16)
+DOMAIN_FIELD(__u32, newidle_lb_gained, v16)
+DOMAIN_FIELD(__u32, newidle_lb_hot_gained, v16)
+DOMAIN_FIELD(__u32, newidle_lb_nobusyq, v16)
+DOMAIN_FIELD(__u32, newidle_lb_nobusyg, v16)
+DOMAIN_FIELD(__u32, alb_count, v16)
+DOMAIN_FIELD(__u32, alb_failed, v16)
+DOMAIN_FIELD(__u32, alb_pushed, v16)
+DOMAIN_FIELD(__u32, sbe_count, v16)
+DOMAIN_FIELD(__u32, sbe_balanced, v16)
+DOMAIN_FIELD(__u32, sbe_pushed, v16)
+DOMAIN_FIELD(__u32, sbf_count, v16)
+DOMAIN_FIELD(__u32, sbf_balanced, v16)
+DOMAIN_FIELD(__u32, sbf_pushed, v16)
+DOMAIN_FIELD(__u32, ttwu_wake_remote, v16)
+DOMAIN_FIELD(__u32, ttwu_move_affine, v16)
+DOMAIN_FIELD(__u32, ttwu_move_balance, v16)
+#endif /* DOMAIN_FIELD */
tools/perf/util/event.c +6 -0
index c9bc8237e3fa..d138e4a5787c 100644
@@ -566,6 +566,9 @@ size_t perf_event__fprintf_schedstat_cpu(union perf_event *event, FILE *fp)
 	if (version == 15) {
 #include <perf/schedstat-cpu-v15.h>
 		return size;
+	} else if (version == 16) {
+#include <perf/schedstat-cpu-v16.h>
+		return size;
 	}
 #undef CPU_FIELD
 
@@ -641,6 +644,9 @@ size_t perf_event__fprintf_schedstat_domain(union perf_event *event, FILE *fp)
 	if (version == 15) {
 #include <perf/schedstat-domain-v15.h>
 		return size;
+	} else if (version == 16) {
+#include <perf/schedstat-domain-v16.h>
+		return size;
 	}
 #undef DOMAIN_FIELD
 
tools/perf/util/synthetic-events.c +6 -0
index 9d8450b6eda9..73b2492a4cde 100644
@@ -2546,6 +2546,8 @@ static union perf_event *__synthesize_schedstat_cpu(struct io *io, __u16 version
 
 	if (version == 15) {
 #include <perf/schedstat-cpu-v15.h>
+	} else if (version == 16) {
+#include <perf/schedstat-cpu-v16.h>
 	}
 #undef CPU_FIELD
 
@@ -2667,6 +2669,8 @@ static union perf_event *__synthesize_schedstat_domain(struct io *io, __u16 vers
 
 	if (version == 15) {
 #include <perf/schedstat-domain-v15.h>
+	} else if (version == 16) {
+#include <perf/schedstat-domain-v16.h>
 	}
 #undef DOMAIN_FIELD
 
@@ -2709,6 +2713,8 @@ int perf_event__synthesize_schedstat(const struct perf_tool *tool,
 
 	if (!strcmp(line, "version 15\n")) {
 		version = 15;
+	} else if (!strcmp(line, "version 16\n")) {
+		version = 16;
 	} else {
 		pr_err("Unsupported /proc/schedstat version: %s", line + 8);
 		goto out_free_line;
Signature · 1 line
2.46.0
#9 lore raw

Re: [PATCH 3/5] perf sched stats: Add schedstat v16 support

Hello Namhyung,

Quoted 8 lines · Namhyung Kim
Quoted 4 lines · Ravi Bangoria

From: Swapnil Sapkal <[email protected]>

/proc/schedstat file output is standardized with version number. Add support to record and raw dump v16 version layout.

How many difference between v15 and v16? Can we have it in the same file with a different version number?

There is difference in ordering in domain fields between v15 and v16, busy and idle load balancing fields are interchanged. Furthermore if new fields are added, the parser breaks and maintaning a separate header file seemed cleaner. It will be difficult to define the perf structs, if the fields are present in same header file.
If you any suggestion to handle this, I am all ears.

--
Thanks and Regards,
Swapnil

Quoted 201 lines

Thanks,
Namhyung

Quoted 197 lines
---
  tools/lib/perf/Makefile                       |  2 +-
  tools/lib/perf/include/perf/event.h           | 14 +++++++
  .../lib/perf/include/perf/schedstat-cpu-v16.h | 13 ++++++
  .../perf/include/perf/schedstat-domain-v16.h  | 40 +++++++++++++++++++
  tools/perf/util/event.c                       |  6 +++
  tools/perf/util/synthetic-events.c            |  6 +++
  6 files changed, 80 insertions(+), 1 deletion(-)

create mode 100644 tools/lib/perf/include/perf/schedstat-cpu-v16.h create mode 100644 tools/lib/perf/include/perf/schedstat-domain-v16.h

tools/lib/perf/Makefile +1 -1
index ebbfea891a6a..de0f4ffd9e16 100644
@@ -187,7 +187,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-cpu-v15.h schedstat-domain-v15.h
+HDRS := bpf_perf.h core.h cpumap.h threadmap.h evlist.h evsel.h event.h mmap.h schedstat-cpu-v15.h schedstat-domain-v15.h schedstat-cpu-v16.h schedstat-domain-v16.h
  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
tools/lib/perf/include/perf/event.h +14 -0
index 35be296d68d5..c332d467c9c9 100644
@@ -463,6 +463,12 @@ struct perf_record_schedstat_cpu_v15 {
  #undef CPU_FIELD
  };
 
+struct perf_record_schedstat_cpu_v16 {
+#define CPU_FIELD(_type, _name, _ver)		_type _name;
+#include "schedstat-cpu-v16.h"
+#undef CPU_FIELD
+};
+
  struct perf_record_schedstat_cpu {
  	struct perf_event_header header;
  	__u16			 version;
@@ -470,6 +476,7 @@ struct perf_record_schedstat_cpu {
  	__u32			 cpu;
  	union {
  		struct perf_record_schedstat_cpu_v15 v15;
+		struct perf_record_schedstat_cpu_v16 v16;
  	};
  };
 
@@ -479,6 +486,12 @@ struct perf_record_schedstat_domain_v15 {
  #undef DOMAIN_FIELD
  };
 
+struct perf_record_schedstat_domain_v16 {
+#define DOMAIN_FIELD(_type, _name, _ver)	_type _name;
+#include "schedstat-domain-v16.h"
+#undef DOMAIN_FIELD
+};
+
  #define DOMAIN_NAME_LEN		16
 
  struct perf_record_schedstat_domain {
@@ -490,6 +503,7 @@ struct perf_record_schedstat_domain {
  	char			 name[DOMAIN_NAME_LEN];
  	union {
  		struct perf_record_schedstat_domain_v15 v15;
+		struct perf_record_schedstat_domain_v16 v16;
  	};
  	__u16			 nr_cpus;
  	__u8			 cpu_mask[];
tools/lib/perf/include/perf/schedstat-cpu-v16.h new file +13 -0
new file mode 100644
index 000000000000..f3a55131a05a
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifdef CPU_FIELD
+CPU_FIELD(__u32, yld_count, v16)
+CPU_FIELD(__u32, array_exp, v16)
+CPU_FIELD(__u32, sched_count, v16)
+CPU_FIELD(__u32, sched_goidle, v16)
+CPU_FIELD(__u32, ttwu_count, v16)
+CPU_FIELD(__u32, ttwu_local, v16)
+CPU_FIELD(__u64, rq_cpu_time, v16)
+CPU_FIELD(__u64, run_delay, v16)
+CPU_FIELD(__u64, pcount, v16)
+#endif /* CPU_FIELD */
tools/lib/perf/include/perf/schedstat-domain-v16.h new file +40 -0
new file mode 100644
index 000000000000..d6ef895c9d32
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifdef DOMAIN_FIELD
+DOMAIN_FIELD(__u32, busy_lb_count, v16)
+DOMAIN_FIELD(__u32, busy_lb_balanced, v16)
+DOMAIN_FIELD(__u32, busy_lb_failed, v16)
+DOMAIN_FIELD(__u32, busy_lb_imbalance, v16)
+DOMAIN_FIELD(__u32, busy_lb_gained, v16)
+DOMAIN_FIELD(__u32, busy_lb_hot_gained, v16)
+DOMAIN_FIELD(__u32, busy_lb_nobusyq, v16)
+DOMAIN_FIELD(__u32, busy_lb_nobusyg, v16)
+DOMAIN_FIELD(__u32, idle_lb_count, v16)
+DOMAIN_FIELD(__u32, idle_lb_balanced, v16)
+DOMAIN_FIELD(__u32, idle_lb_failed, v16)
+DOMAIN_FIELD(__u32, idle_lb_imbalance, v16)
+DOMAIN_FIELD(__u32, idle_lb_gained, v16)
+DOMAIN_FIELD(__u32, idle_lb_hot_gained, v16)
+DOMAIN_FIELD(__u32, idle_lb_nobusyq, v16)
+DOMAIN_FIELD(__u32, idle_lb_nobusyg, v16)
+DOMAIN_FIELD(__u32, newidle_lb_count, v16)
+DOMAIN_FIELD(__u32, newidle_lb_balanced, v16)
+DOMAIN_FIELD(__u32, newidle_lb_failed, v16)
+DOMAIN_FIELD(__u32, newidle_lb_imbalance, v16)
+DOMAIN_FIELD(__u32, newidle_lb_gained, v16)
+DOMAIN_FIELD(__u32, newidle_lb_hot_gained, v16)
+DOMAIN_FIELD(__u32, newidle_lb_nobusyq, v16)
+DOMAIN_FIELD(__u32, newidle_lb_nobusyg, v16)
+DOMAIN_FIELD(__u32, alb_count, v16)
+DOMAIN_FIELD(__u32, alb_failed, v16)
+DOMAIN_FIELD(__u32, alb_pushed, v16)
+DOMAIN_FIELD(__u32, sbe_count, v16)
+DOMAIN_FIELD(__u32, sbe_balanced, v16)
+DOMAIN_FIELD(__u32, sbe_pushed, v16)
+DOMAIN_FIELD(__u32, sbf_count, v16)
+DOMAIN_FIELD(__u32, sbf_balanced, v16)
+DOMAIN_FIELD(__u32, sbf_pushed, v16)
+DOMAIN_FIELD(__u32, ttwu_wake_remote, v16)
+DOMAIN_FIELD(__u32, ttwu_move_affine, v16)
+DOMAIN_FIELD(__u32, ttwu_move_balance, v16)
+#endif /* DOMAIN_FIELD */
tools/perf/util/event.c +6 -0
index c9bc8237e3fa..d138e4a5787c 100644
@@ -566,6 +566,9 @@ size_t perf_event__fprintf_schedstat_cpu(union perf_event *event, FILE *fp)
  	if (version == 15) {
  #include <perf/schedstat-cpu-v15.h>
  		return size;
+	} else if (version == 16) {
+#include <perf/schedstat-cpu-v16.h>
+		return size;
  	}
  #undef CPU_FIELD
 
@@ -641,6 +644,9 @@ size_t perf_event__fprintf_schedstat_domain(union perf_event *event, FILE *fp)
  	if (version == 15) {
  #include <perf/schedstat-domain-v15.h>
  		return size;
+	} else if (version == 16) {
+#include <perf/schedstat-domain-v16.h>
+		return size;
  	}
  #undef DOMAIN_FIELD
 
tools/perf/util/synthetic-events.c +6 -0
index 9d8450b6eda9..73b2492a4cde 100644
@@ -2546,6 +2546,8 @@ static union perf_event *__synthesize_schedstat_cpu(struct io *io, __u16 version
 
  	if (version == 15) {
  #include <perf/schedstat-cpu-v15.h>
+	} else if (version == 16) {
+#include <perf/schedstat-cpu-v16.h>
  	}
  #undef CPU_FIELD
 
@@ -2667,6 +2669,8 @@ static union perf_event *__synthesize_schedstat_domain(struct io *io, __u16 vers
 
  	if (version == 15) {
  #include <perf/schedstat-domain-v15.h>
+	} else if (version == 16) {
+#include <perf/schedstat-domain-v16.h>
  	}
  #undef DOMAIN_FIELD
 
@@ -2709,6 +2713,8 @@ int perf_event__synthesize_schedstat(const struct perf_tool *tool,
 
  	if (!strcmp(line, "version 15\n")) {
  		version = 15;
+	} else if (!strcmp(line, "version 16\n")) {
+		version = 16;
  	} else {
  		pr_err("Unsupported /proc/schedstat version: %s", line + 8);
  		goto out_free_line;
Signature · 1 line
2.46.0
#10 lore raw

PATCH 4/5 perf sched stats: Add support for report subcommand

In reply to Ravi Bangoria

From: Swapnil Sapkal <[email protected]>

perf sched stats record captures two sets of samples. For workload profile, first set right before workload starts and second set after workload finishes. For the systemwide profile, first set at the beginning of profile and second set on receiving SIGINT signal.

Add perf sched stats report subcommand that will read both the set of samples, get the diff and render a final report. Final report prints scheduler stat at cpu granularity as well as sched domain granularity.

Example usage:

  # perf sched stats record
  # perf sched stats report
---
 tools/lib/perf/include/perf/event.h           |   8 +-
 .../lib/perf/include/perf/schedstat-cpu-v15.h |  27 +-
 .../lib/perf/include/perf/schedstat-cpu-v16.h |  27 +-
 .../perf/include/perf/schedstat-domain-v15.h  | 153 ++++--
 .../perf/include/perf/schedstat-domain-v16.h  | 153 ++++--
 tools/perf/builtin-sched.c                    | 475 +++++++++++++++++-
 tools/perf/util/event.c                       |   4 +-
 tools/perf/util/synthetic-events.c            |   4 +-
 8 files changed, 751 insertions(+), 100 deletions(-)
tools/lib/perf/include/perf/event.h +4 -4
index c332d467c9c9..dca03b585766 100644
@@ -458,13 +458,13 @@ struct perf_record_compressed {
 };
 
 struct perf_record_schedstat_cpu_v15 {
-#define CPU_FIELD(_type, _name, _ver)		_type _name;
+#define CPU_FIELD(_type, _name, _desc, _format, _is_pct, _pct_of, _ver)	_type _name;
 #include "schedstat-cpu-v15.h"
 #undef CPU_FIELD
 };
 
 struct perf_record_schedstat_cpu_v16 {
-#define CPU_FIELD(_type, _name, _ver)		_type _name;
+#define CPU_FIELD(_type, _name, _desc, _format, _is_pct, _pct_of, _ver)	_type _name;
 #include "schedstat-cpu-v16.h"
 #undef CPU_FIELD
 };
@@ -481,13 +481,13 @@ struct perf_record_schedstat_cpu {
 };
 
 struct perf_record_schedstat_domain_v15 {
-#define DOMAIN_FIELD(_type, _name, _ver)	_type _name;
+#define DOMAIN_FIELD(_type, _name, _desc, _format, _is_jiffies, _ver)	_type _name;
 #include "schedstat-domain-v15.h"
 #undef DOMAIN_FIELD
 };
 
 struct perf_record_schedstat_domain_v16 {
-#define DOMAIN_FIELD(_type, _name, _ver)	_type _name;
+#define DOMAIN_FIELD(_type, _name, _desc, _format, _is_jiffies, _ver)	_type _name;
 #include "schedstat-domain-v16.h"
 #undef DOMAIN_FIELD
 };
tools/lib/perf/include/perf/schedstat-cpu-v15.h +18 -9
index 8e4355ee3705..f1d7f8363f39 100644
@@ -1,13 +1,22 @@
 /* SPDX-License-Identifier: GPL-2.0 */
 
 #ifdef CPU_FIELD
-CPU_FIELD(__u32, yld_count, v15)
-CPU_FIELD(__u32, array_exp, v15)
-CPU_FIELD(__u32, sched_count, v15)
-CPU_FIELD(__u32, sched_goidle, v15)
-CPU_FIELD(__u32, ttwu_count, v15)
-CPU_FIELD(__u32, ttwu_local, v15)
-CPU_FIELD(__u64, rq_cpu_time, v15)
-CPU_FIELD(__u64, run_delay, v15)
-CPU_FIELD(__u64, pcount, v15)
+CPU_FIELD(__u32, yld_count, "sched_yield() count",
+	  "%11u", false, yld_count, v15)
+CPU_FIELD(__u32, array_exp, "Legacy counter can be ignored",
+	  "%11u", false, array_exp, v15)
+CPU_FIELD(__u32, sched_count, "schedule() called",
+	  "%11u", false, sched_count, v15)
+CPU_FIELD(__u32, sched_goidle, "schedule() left the processor idle",
+	  "%11u", true, sched_count, v15)
+CPU_FIELD(__u32, ttwu_count, "try_to_wake_up() was called",
+	  "%11u", false, ttwu_count, v15)
+CPU_FIELD(__u32, ttwu_local, "try_to_wake_up() was called to wake up the local cpu",
+	  "%11u", true, ttwu_count, v15)
+CPU_FIELD(__u64, rq_cpu_time, "total runtime by tasks on this processor (in jiffies)",
+	  "%11llu", false, rq_cpu_time, v15)
+CPU_FIELD(__u64, run_delay, "total waittime by tasks on this processor (in jiffies)",
+	  "%11llu", true, rq_cpu_time, v15)
+CPU_FIELD(__u64, pcount, "total timeslices run on this cpu",
+	  "%11llu", false, pcount, v15)
 #endif
tools/lib/perf/include/perf/schedstat-cpu-v16.h +18 -9
index f3a55131a05a..ac58d68ec661 100644
@@ -1,13 +1,22 @@
 /* SPDX-License-Identifier: GPL-2.0 */
 
 #ifdef CPU_FIELD
-CPU_FIELD(__u32, yld_count, v16)
-CPU_FIELD(__u32, array_exp, v16)
-CPU_FIELD(__u32, sched_count, v16)
-CPU_FIELD(__u32, sched_goidle, v16)
-CPU_FIELD(__u32, ttwu_count, v16)
-CPU_FIELD(__u32, ttwu_local, v16)
-CPU_FIELD(__u64, rq_cpu_time, v16)
-CPU_FIELD(__u64, run_delay, v16)
-CPU_FIELD(__u64, pcount, v16)
+CPU_FIELD(__u32, yld_count, "sched_yield() count",
+	  "%11u", false, yld_count, v16)
+CPU_FIELD(__u32, array_exp, "Legacy counter can be ignored",
+	  "%11u", false, array_exp, v16)
+CPU_FIELD(__u32, sched_count, "schedule() called",
+	  "%11u", false, sched_count, v16)
+CPU_FIELD(__u32, sched_goidle, "schedule() left the processor idle",
+	  "%11u", true, sched_count, v16)
+CPU_FIELD(__u32, ttwu_count, "try_to_wake_up() was called",
+	  "%11u", false, ttwu_count, v16)
+CPU_FIELD(__u32, ttwu_local, "try_to_wake_up() was called to wake up the local cpu",
+	  "%11u", true, ttwu_count, v16)
+CPU_FIELD(__u64, rq_cpu_time, "total runtime by tasks on this processor (in jiffies)",
+	  "%11llu", false, rq_cpu_time, v16)
+CPU_FIELD(__u64, run_delay, "total waittime by tasks on this processor (in jiffies)",
+	  "%11llu", true, rq_cpu_time, v16)
+CPU_FIELD(__u64, pcount, "total timeslices run on this cpu",
+	  "%11llu", false, pcount, v16)
 #endif /* CPU_FIELD */
tools/lib/perf/include/perf/schedstat-domain-v15.h +117 -36

157 lines not on this page · raw message

tools/lib/perf/include/perf/schedstat-domain-v16.h +117 -36

157 lines not on this page · raw message

tools/perf/builtin-sched.c +473 -2

505 lines not on this page · raw message

tools/perf/util/event.c +2 -2
index d138e4a5787c..0f14fe225be0 100644
@@ -560,7 +560,7 @@ size_t perf_event__fprintf_schedstat_cpu(union perf_event *event, FILE *fp)
 
 	size = fprintf(fp, "\ncpu%u ", cs->cpu);
 
-#define CPU_FIELD(_type, _name, _ver)						\
+#define CPU_FIELD(_type, _name, _desc, _format, _is_pct, _pct_of, _ver)		\
 	size += fprintf(fp, "%" PRIu64 " ", (unsigned long)cs->_ver._name);	\
 
 	if (version == 15) {
@@ -638,7 +638,7 @@ size_t perf_event__fprintf_schedstat_domain(union perf_event *event, FILE *fp)
 	size += fprintf(fp, "%s ", cpu_mask);
 	free(cpu_mask);
 
-#define DOMAIN_FIELD(_type, _name, _ver)					\
+#define DOMAIN_FIELD(_type, _name, _desc, _format, _is_jiffies, _ver)		\
 	size += fprintf(fp, "%" PRIu64 " ", (unsigned long)ds->_ver._name);	\
 
 	if (version == 15) {
tools/perf/util/synthetic-events.c +2 -2
index 73b2492a4cde..24f9cb95d07d 100644
@@ -2535,7 +2535,7 @@ static union perf_event *__synthesize_schedstat_cpu(struct io *io, __u16 version
 	if (io__get_dec(io, (__u64 *)&cs->cpu) != ' ')
 		goto out_cpu;
 
-#define CPU_FIELD(_type, _name, _ver)					\
+#define CPU_FIELD(_type, _name, _desc, _format, _is_pct, _pct_of, _ver)	\
 	do {								\
 		__u64 _tmp;						\
 		ch = io__get_dec(io, &_tmp);				\
@@ -2658,7 +2658,7 @@ static union perf_event *__synthesize_schedstat_domain(struct io *io, __u16 vers
 	free(d_name);
 	free(cpu_mask);
 
-#define DOMAIN_FIELD(_type, _name, _ver)				\
+#define DOMAIN_FIELD(_type, _name, _desc, _format, _is_jiffies, _ver)	\
 	do {								\
 		__u64 _tmp;						\
 		ch = io__get_dec(io, &_tmp);				\
Signature · 1 line
2.46.0
#11 lore raw

PATCH 5/5 perf sched stats: Add support for live mode

In reply to Ravi Bangoria

From: Swapnil Sapkal <[email protected]>

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 -- sleep 10
---
 tools/perf/builtin-sched.c | 87 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 86 insertions(+), 1 deletion(-)
tools/perf/builtin-sched.c +86 -1
index cd465644fce5..e888ae763eac 100644
@@ -4319,6 +4319,91 @@ 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(NULL, event);
+}
+
+static int perf_sched__schedstat_live(struct perf_sched *sched,
+				      int argc, const char **argv)
+{
+	struct evlist *evlist;
+	struct target *target;
+	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.
+	 */
+	target = zalloc(sizeof(struct target));
+	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_target;
+	}
+
+	if (cpu_list) {
+		user_requested_cpus = perf_cpu_map__new(cpu_list);
+		if (!user_requested_cpus)
+			goto out_target;
+	}
+
+	err = perf_event__synthesize_schedstat(&(sched->tool),
+					       process_synthesized_event_live,
+					       user_requested_cpus);
+	if (err < 0)
+		goto out_target;
+
+	err = enable_sched_schedstats(&reset);
+	if (err < 0)
+		goto out_target;
+
+	if (argc)
+		evlist__start_workload(evlist);
+
+	/* wait for signal */
+	pause();
+
+	if (reset) {
+		err = disable_sched_schedstat();
+		if (err < 0)
+			goto out_target;
+	}
+
+	err = perf_event__synthesize_schedstat(&(sched->tool),
+					       process_synthesized_event_live,
+					       user_requested_cpus);
+	if (err)
+		goto out_target;
+
+	setup_pager();
+	show_schedstat_data();
+	free_schedstat();
+out_target:
+	free(target);
+	return err;
+}
+
 static bool schedstat_events_exposed(void)
 {
 	/*
@@ -4640,7 +4725,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);
 	}
Signature · 1 line
2.46.0
reviewer Tested-by on the v1 series
#12 lore raw
In reply to Ravi Bangoria
Quoted 122 lines · Ravi Bangoria

MOTIVATION
----------

Existing perf sched is quite exhaustive and provides lot of insights into scheduler behavior but it quickly becomes impractical to use for long running or scheduler intensive workload. For ex, perf sched record has ~7.77% overhead on hackbench (with 25 groups each running 700K loops on a 2-socket 128 Cores 256 Threads 3rd Generation EPYC Server), and it generates huge 56G perf.data for which perf takes ~137 mins to prepare and write it to disk [1].

Unlike perf sched record, which hooks onto set of scheduler tracepoints and generates samples on a tracepoint hit, perf sched stats record takes snapshot of the /proc/schedstat file before and after the workload, i.e. there is almost zero interference on workload run. Also, it takes very minimal time to parse /proc/schedstat, convert it into perf samples and save those samples into perf.data file. Result perf.data file is much smaller. So, overall perf sched stats record is much more light weight compare to perf sched record.

We, internally at AMD, have been using this (a variant of this, known as "sched-scoreboard"[2]) and found it to be very useful to analyse impact of any scheduler code changes[3][4].

Please note that, this is not a replacement of perf sched record/report. The intended users of the new tool are scheduler developers, not regular users.

USAGE
-----

   # perf sched stats record
   # perf sched stats report

Note: Although perf sched stats tool supports workload profiling syntax (i.e. -- <workload> ), the recorded profile is still systemwide since the /proc/schedstat is a systemwide file.

HOW TO INTERPRET THE REPORT
---------------------------

The perf sched stats report starts with total time profiling was active in terms of jiffies:

   ----------------------------------------------------------------------------------------------------
   Time elapsed (in jiffies)                                   :       24537
   ----------------------------------------------------------------------------------------------------

Next is CPU scheduling statistics. These are simple diffs of /proc/schedstat CPU lines along with description. The report also prints % relative to base stat.

In the example below, schedule() left the CPU0 idle 98.19% of the time. 16.54% of total try_to_wake_up() was to wakeup local CPU. And, the total waittime by tasks on CPU0 is 0.49% of the total runtime by tasks on the same CPU.

----------------------------------------------------------------------------------------------------
CPU 0
----------------------------------------------------------------------------------------------------

   sched_yield() count                                         :           0
   Legacy counter can be ignored                               :           0
   schedule() called                                           :       17138
   schedule() left the processor idle                          :       16827 ( 98.19% )
   try_to_wake_up() was called                                 :         508
   try_to_wake_up() was called to wake up the local cpu        :          84 ( 16.54% )
   total runtime by tasks on this processor (in jiffies)       :  2408959243
   total waittime by tasks on this processor (in jiffies)      :    11731825 ( 0.49% )
   total timeslices run on this cpu                            :         311

----------------------------------------------------------------------------------------------------

Next is load balancing statistics. For each of the sched domains (eg: SMT, MC, DIE...), the scheduler computes statistics under the following three categories:

1) Idle Load Balance: Load balancing performed on behalf of a long idling CPU by some other CPU.
2) Busy Load Balance: Load balancing performed when the CPU was busy.
3) New Idle Balance : Load balancing performed when a CPU just became idle.

Under each of these three categories, sched stats report provides different load balancing statistics. Along with direct stats, the report also contains derived metrics prefixed with *. Example:

----------------------------------------------------------------------------------------------------
CPU 0 DOMAIN SMT CPUS <0, 64>
----------------------------------------- <Category idle> ------------------------------------------

   load_balance() count on cpu idle                                 :          50   $      490.74 $
   load_balance() found balanced on cpu idle                        :          42   $      584.21 $
   load_balance() move task failed on cpu idle                      :           8   $     3067.12 $
   imbalance sum on cpu idle                                        :           8
   pull_task() count on cpu idle                                    :           0
   pull_task() when target task was cache-hot on cpu idle           :           0
   load_balance() failed to find busier queue on cpu idle           :           0   $        0.00 $
   load_balance() failed to find busier group on cpu idle           :          42   $      584.21 $
   *load_balance() success count on cpu idle                        :           0
   *avg task pulled per successful lb attempt (cpu idle)            :        0.00
   ----------------------------------------- <Category busy> ------------------------------------------
   load_balance() count on cpu busy                                 :           2   $    12268.50 $
   load_balance() found balanced on cpu busy                        :           2   $    12268.50 $
   load_balance() move task failed on cpu busy                      :           0   $        0.00 $
   imbalance sum on cpu busy                                        :           0
   pull_task() count on cpu busy                                    :           0
   pull_task() when target task was cache-hot on cpu busy           :           0
   load_balance() failed to find busier queue on cpu busy           :           0   $        0.00 $
   load_balance() failed to find busier group on cpu busy           :           1   $    24537.00 $
   *load_balance() success count on cpu busy                        :           0
   *avg task pulled per successful lb attempt (cpu busy)            :        0.00
   ---------------------------------------- <Category newidle> ----------------------------------------
   load_balance() count on cpu newly idle                           :         427   $       57.46 $
   load_balance() found balanced on cpu newly idle                  :         382   $       64.23 $
   load_balance() move task failed on cpu newly idle                :          45   $      545.27 $
   imbalance sum on cpu newly idle                                  :          48
   pull_task() count on cpu newly idle                              :           0
   pull_task() when target task was cache-hot on cpu newly idle     :           0
   load_balance() failed to find busier queue on cpu newly idle     :           0   $        0.00 $
   load_balance() failed to find busier group on cpu newly idle     :         382   $       64.23 $
   *load_balance() success count on cpu newly idle                  :           0
   *avg task pulled per successful lb attempt (cpu newly idle)      :        0.00

----------------------------------------------------------------------------------------------------

Quoted 7 lines

Consider following line:

load_balance() found balanced on cpu newly idle : 382 $ 64.23 $

While profiling was active, the load-balancer found 382 times the load needs to be balanced on a newly idle CPU 0. Following value encapsulated inside $ is average jiffies between two events (24537 / 382 = 64.23).

This explanation of the $ fields is quite buried. Is there a way of making it clearer with a column header in the report? I think even if it was documented in the man pages it might not be that useful.

There are also other jiffies fields that don't use $. Maybe if it was like this it could be semi self documenting:

----------------------------------------------------------------------
Time elapsed (in jiffies) : $ 24537 $
----------------------------------------------------------------------

------------------<Category newidle> ---------------------------------
load_balance() count on cpu newly idle : 427 $ 57.46 avg $
----------------------------------------------------------------------

Other than that:

#13 lore raw

Hi James,

Quoted 137 lines · James Clark
Quoted 134 lines · Ravi Bangoria

MOTIVATION
----------

Existing perf sched is quite exhaustive and provides lot of insights into scheduler behavior but it quickly becomes impractical to use for long running or scheduler intensive workload. For ex, perf sched record has ~7.77% overhead on hackbench (with 25 groups each running 700K loops on a 2-socket 128 Cores 256 Threads 3rd Generation EPYC Server), and it generates huge 56G perf.data for which perf takes ~137 mins to prepare and write it to disk [1].

Unlike perf sched record, which hooks onto set of scheduler tracepoints and generates samples on a tracepoint hit, perf sched stats record takes snapshot of the /proc/schedstat file before and after the workload, i.e. there is almost zero interference on workload run. Also, it takes very minimal time to parse /proc/schedstat, convert it into perf samples and save those samples into perf.data file. Result perf.data file is much smaller. So, overall perf sched stats record is much more light weight compare to perf sched record.

We, internally at AMD, have been using this (a variant of this, known as "sched-scoreboard"[2]) and found it to be very useful to analyse impact of any scheduler code changes[3][4].

Please note that, this is not a replacement of perf sched record/report. The intended users of the new tool are scheduler developers, not regular users.

USAGE
-----

   # perf sched stats record
   # perf sched stats report

Note: Although perf sched stats tool supports workload profiling syntax (i.e. -- <workload> ), the recorded profile is still systemwide since the /proc/schedstat is a systemwide file.

HOW TO INTERPRET THE REPORT
---------------------------

The perf sched stats report starts with total time profiling was active in terms of jiffies:

----------------------------------------------------------------------------------------------------
   Time elapsed (in jiffies)                                   : 24537

----------------------------------------------------------------------------------------------------

Next is CPU scheduling statistics. These are simple diffs of /proc/schedstat CPU lines along with description. The report also prints % relative to base stat.

In the example below, schedule() left the CPU0 idle 98.19% of the time. 16.54% of total try_to_wake_up() was to wakeup local CPU. And, the total waittime by tasks on CPU0 is 0.49% of the total runtime by tasks on the same CPU.

----------------------------------------------------------------------------------------------------
   CPU 0

----------------------------------------------------------------------------------------------------
   sched_yield() count :           0
   Legacy counter can be ignored :           0
   schedule() called                                           : 17138
   schedule() left the processor idle                          : 16827 ( 98.19% )
   try_to_wake_up() was called :         508
   try_to_wake_up() was called to wake up the local cpu :          84 ( 16.54% )
   total runtime by tasks on this processor (in jiffies)       : 2408959243
   total waittime by tasks on this processor (in jiffies)      : 11731825 ( 0.49% )
   total timeslices run on this cpu :         311

----------------------------------------------------------------------------------------------------

Next is load balancing statistics. For each of the sched domains (eg: SMT, MC, DIE...), the scheduler computes statistics under the following three categories:

   1) Idle Load Balance: Load balancing performed on behalf of a long idling CPU by some other CPU.
   2) Busy Load Balance: Load balancing performed when the CPU was busy.
   3) New Idle Balance : Load balancing performed when a CPU just became idle.

Under each of these three categories, sched stats report provides different load balancing statistics. Along with direct stats, the report also contains derived metrics prefixed with *. Example:

----------------------------------------------------------------------------------------------------
   CPU 0 DOMAIN SMT CPUS <0, 64> ----------------------------------------- <Category idle>
------------------------------------------

   load_balance() count on cpu idle                                 :          50   $      490.74 $
   load_balance() found balanced on cpu idle                        :          42   $      584.21 $
   load_balance() move task failed on cpu idle                      :           8   $     3067.12 $
   imbalance sum on cpu idle                                        :           8
   pull_task() count on cpu idle                                    :           0
   pull_task() when target task was cache-hot on cpu idle           :           0
   load_balance() failed to find busier queue on cpu idle           :           0   $        0.00 $
   load_balance() failed to find busier group on cpu idle           :          42   $      584.21 $
   *load_balance() success count on cpu idle                        :           0
   *avg task pulled per successful lb attempt (cpu idle)            :        0.00
   ----------------------------------------- <Category busy> 
------------------------------------------
   load_balance() count on cpu busy                                 :           2   $    12268.50 $
   load_balance() found balanced on cpu busy                        :           2   $    12268.50 $
   load_balance() move task failed on cpu busy                      :           0   $        0.00 $
   imbalance sum on cpu busy                                        :           0
   pull_task() count on cpu busy                                    :           0
   pull_task() when target task was cache-hot on cpu busy           :           0
   load_balance() failed to find busier queue on cpu busy           :           0   $        0.00 $
   load_balance() failed to find busier group on cpu busy           :           1   $    24537.00 $
   *load_balance() success count on cpu busy                        :           0
   *avg task pulled per successful lb attempt (cpu busy)            :        0.00
   ---------------------------------------- <Category newidle> 
----------------------------------------
   load_balance() count on cpu newly idle                           :         427   $       57.46 $
   load_balance() found balanced on cpu newly idle                  :         382   $       64.23 $
   load_balance() move task failed on cpu newly idle                :          45   $      545.27 $
   imbalance sum on cpu newly idle                                  :          48
   pull_task() count on cpu newly idle                              :           0
   pull_task() when target task was cache-hot on cpu newly idle     :           0
   load_balance() failed to find busier queue on cpu newly idle     :           0   $        0.00 $
   load_balance() failed to find busier group on cpu newly idle     :         382   $       64.23 $
   *load_balance() success count on cpu newly idle                  :           0
   *avg task pulled per successful lb attempt (cpu newly idle)      :        0.00

----------------------------------------------------------------------------------------------------

Consider following line:

Quoted 8 lines
Quoted 5 lines

   load_balance() found balanced on cpu newly idle :         382    $      64.23 $

While profiling was active, the load-balancer found 382 times the load needs to be balanced on a newly idle CPU 0. Following value encapsulated inside $ is average jiffies between two events (24537 / 382 = 64.23).

This explanation of the $ fields is quite buried. Is there a way of making it clearer with a column header in the report? I think even if it was documented in the man pages it might not be that useful.

Thank you for the suggestion. I will add a header in the report to explain what each column values are representing.

Quoted 6 lines

There are also other jiffies fields that don't use $. Maybe if it was like this it could be semi self documenting:

----------------------------------------------------------------------
    Time elapsed (in jiffies)               :        $  24537        $
 ----------------------------------------------------------------------

Quoted 8 lines

------------------<Category newidle> ---------------------------------
  load_balance() count on cpu newly idle    :   427  $     57.46 avg $
----------------------------------------------------------------------

Other than that:

Ack.

--
Thanks and Regards,
Swapnil

#14 lore raw
In reply to Ravi Bangoria

Hi Ravi,

Quoted 11 lines · Ravi Bangoria

MOTIVATION
----------

Existing perf sched is quite exhaustive and provides lot of insights into scheduler behavior but it quickly becomes impractical to use for long running or scheduler intensive workload. For ex, perf sched record has ~7.77% overhead on hackbench (with 25 groups each running 700K loops on a 2-socket 128 Cores 256 Threads 3rd Generation EPYC Server), and it generates huge 56G perf.data for which perf takes ~137 mins to prepare and write it to disk [1].

Quoted 6 lines

Unlike perf sched record, which hooks onto set of scheduler tracepoints and generates samples on a tracepoint hit, perf sched stats record takes snapshot of the /proc/schedstat file before and after the workload, i.e. there is almost zero interference on workload run. Also, it takes very minimal time to parse /proc/schedstat, convert it into perf samples and save those samples into perf.data file. Result perf.data file is much

per.data file is empty after the record.

Error:
The perf.data data has no samples!

Thanks and Regards
Madadi Vineeth Reddy

Quoted 10 lines

smaller. So, overall perf sched stats record is much more light weight compare to perf sched record.

We, internally at AMD, have been using this (a variant of this, known as "sched-scoreboard"[2]) and found it to be very useful to analyse impact of any scheduler code changes[3][4].

Please note that, this is not a replacement of perf sched record/report. The intended users of the new tool are scheduler developers, not regular users.

#15 lore raw

Hi Vineeth,

Thank you for testing the series.

Quoted 21 lines · Madadi Vineeth Reddy

Hi Ravi,

Quoted 11 lines · Ravi Bangoria

MOTIVATION
----------

Existing perf sched is quite exhaustive and provides lot of insights into scheduler behavior but it quickly becomes impractical to use for long running or scheduler intensive workload. For ex, perf sched record has ~7.77% overhead on hackbench (with 25 groups each running 700K loops on a 2-socket 128 Cores 256 Threads 3rd Generation EPYC Server), and it generates huge 56G perf.data for which perf takes ~137 mins to prepare and write it to disk [1].

Quoted 6 lines

Unlike perf sched record, which hooks onto set of scheduler tracepoints and generates samples on a tracepoint hit, perf sched stats record takes snapshot of the /proc/schedstat file before and after the workload, i.e. there is almost zero interference on workload run. Also, it takes very minimal time to parse /proc/schedstat, convert it into perf samples and save those samples into perf.data file. Result perf.data file is much

Quoted 4 lines

per.data file is empty after the record.

Error:
The perf.data data has no samples!

I am not able to reproduce this error on my system. Can you please share /proc/schedstat file from your system? What was the base kernel you applied this on?

--
Thanks And Regards,
Swapnil

Quoted 15 lines

Thanks and Regards
Madadi Vineeth Reddy

Quoted 10 lines

smaller. So, overall perf sched stats record is much more light weight compare to perf sched record.

We, internally at AMD, have been using this (a variant of this, known as "sched-scoreboard"[2]) and found it to be very useful to analyse impact of any scheduler code changes[3][4].

Please note that, this is not a replacement of perf sched record/report. The intended users of the new tool are scheduler developers, not regular users.

#16 lore raw
In reply to Madadi Vineeth Reddy

Hi Vineeth,

Thank you for testing the series.

Quoted 21 lines · Madadi Vineeth Reddy

Hi Ravi,

Quoted 11 lines · Ravi Bangoria

MOTIVATION
----------

Existing perf sched is quite exhaustive and provides lot of insights into scheduler behavior but it quickly becomes impractical to use for long running or scheduler intensive workload. For ex, perf sched record has ~7.77% overhead on hackbench (with 25 groups each running 700K loops on a 2-socket 128 Cores 256 Threads 3rd Generation EPYC Server), and it generates huge 56G perf.data for which perf takes ~137 mins to prepare and write it to disk [1].

Quoted 6 lines

Unlike perf sched record, which hooks onto set of scheduler tracepoints and generates samples on a tracepoint hit, perf sched stats record takes snapshot of the /proc/schedstat file before and after the workload, i.e. there is almost zero interference on workload run. Also, it takes very minimal time to parse /proc/schedstat, convert it into perf samples and save those samples into perf.data file. Result perf.data file is much

Quoted 4 lines

per.data file is empty after the record.

Error:
The perf.data data has no samples!

I am not able to reproduce this error on my system. Can you please share /proc/schedstat file from your system? What was the base kernel you applied this on?

--
Thanks And Regards,
Swapnil

Quoted 15 lines

Thanks and Regards
Madadi Vineeth Reddy

Quoted 10 lines

smaller. So, overall perf sched stats record is much more light weight compare to perf sched record.

We, internally at AMD, have been using this (a variant of this, known as "sched-scoreboard"[2]) and found it to be very useful to analyse impact of any scheduler code changes[3][4].

Please note that, this is not a replacement of perf sched record/report. The intended users of the new tool are scheduler developers, not regular users.