Skip to contentSkip to conversation

TPEBS counting mode support

RFC PATCH Superseded [email protected] 2 participants 17 messages Jun 24, 2024 – Jul 2, 2024 perf events

v14 of 18 Superseded Latest is v18 →

lore
Share & tools
lore
#0 lore raw

v14 cover TPEBS counting mode support

From: Weilin Wang <[email protected]>

Changes in v14:
- Fix the python import test failure. We cannot support PYTHON_PERF because it will trigger a chain of dependency issues if we add intel-tpebs.c to it. So, only enable tpebs functions in evsel and evlist when PYTHON_PERF is not defined.
- Fix shellcheck warning for the tpebs test.

Changes in v13:
- Add document for the command line option and fix build error in non-x86_64.
- Update example with non-zero retire_latency value when tpebs recording is enabled.
- Add tpebs_stop() back to tpebs_set_evsel() because in hybrid platform, when the forked perf record is not killed, the reader thread does not get any sampled data from the PIPE. As a result, tpebs_set_evesel() will always return zero on retire_latency values. This does not happen on my test GNR machine. Since -I is not supported yet, I think we should add tpebs_stop() to ensure correctness for now. More investigation is required here when we work on supporting -I mode.
- Rebase code on top of perf-tools-next.

Changes in v12:
- Update MTL metric JSON file to include E-Core TMA3.6 changes.
- Update comments and code for better code quality. Keep tpebs_start() and tpebs_delete() at evsel level for now and add comments on these functions with more details about potential future changes. Remove tpebs_stop() call from tpebs_set_evsel(). Simplify the tpebs_start() and tpebs_stop()/tpebs_delete() interfaces. Also fixed the bugs on not freed "new" pointer and the incorrect variable value assignment to val instead of counter->val.

Changes in v11:
- Make retire_latency evsels not opened for counting. This works correctly now with the code Namhyung suggested that adjusting group read size when retire_latency evsels included in the group.
- Update retire_latency value assignment using rint() to reduce precision loss while keeping code generic.
- Fix the build error caused by not used variable in the test.

Other changes in v10:
- Change perf record fork from perf stat to evsel. All the major operations like tpebs start, stop, read_evsel should directly work through evsel.
- Make intel-tpebs x86_64 only. This change is cross-compiled to arm64.
- Put tpebs code to intel-tepbs and simplify intel-tpebs APIs to minimum number
of functions and variables. Update funtion name and variable names to use consistent prefix. Also improve error handling.
- Integrate code patch from Ian for the :R parser.
- Update MTL metrics to TMA 4.8.

V9: https://lore.kernel.org/all/[email protected]/

Changes in v9:
- Update the retire_latency result print and metric calculation method. Plugin
the value to evsel so that no special code is required.
- Update --control:fifo to use pipe instead of named pipe.
- Add test for TPEBS counting mode.
- Update Document with more details.

Changes in v8:
- In this revision, the code is updated to base on Ian's patch on R modifier
parser https://lore.kernel.org/lkml/[email protected]/
After this change, there is no special code required for R modifier in metricgroup.c and metricgroup.h files.

Caveat of this change:
Ideally, we will need to add special handling to skip counting events with R
modifier in evsel. Currently, this is not implemented so the event with :R will be both counted and sampled. Usually, in a metric formula that uses retire_latency, it would already require to count the event. As a result, we will endup count the same event twice. This should be able to be handled properly when we finalize our design on evsel R modifier support.

- Move TPEBS specific code out from main perf stat code to separate files in
util/intel-tpebs.c and util/intel-tpebs.h. [Namhyung]
- Use --control:fifo to ack perf stat from forked perf record instead of sleep(2) [Namhyung]
- Add introductions about TPEBS and R modifier in Documents. [Namhyung]

Changes in v7:
- Update code and comments for better code quality [Namhyung]
- Add a separate commit for perf data [Namhyung]
- Update retire latency print function to improve alignment [Namhyung]

Changes in v6:
- Update code and add comments for better code quality [Namhyung]
- Remove the added fd var and directly pass the opened fd to data.file.fd [Namhyung]
- Add kill() to stop perf record when perf stat exists early [Namhyung]
- Add command opt check to ensure only start perf record when -a/-C given [Namhyung]
- Squash commits [Namhyung]

Changes in v5:
- Update code and add comments for better code quality [Ian]

Changes in v4:
- Remove uncessary debug print and update code and comments for better
readability and quality [Namhyung]
- Update mtl metric json file with consistent TmaL1 and TopdownL1 metricgroup

Changes in v3:
- Remove ':' when event name has '@' [Ian]
- Use 'R' as the modifier instead of "retire_latency" [Ian]

Changes in v2:
- Add MTL metric file
- Add more descriptions and example to the patch [Arnaldo]

Here is an example of running perf stat to collect a metric that uses retire_latency value of event MEM_INST_RETIRED.STLB_HIT_STORES on a MTL system.

In this simple example, there is no MEM_INST_RETIRED.STLB_HIT_STORES sample. Therefore, the MEM_INST_RETIRED.STLB_HIT_STORES:p count and retire_latency value are all 0.

./perf stat -M tma_dtlb_store -a -- sleep 1

[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.000 MB - ]

Performance counter stats for 'system wide':

       181,047,168      cpu_core/TOPDOWN.SLOTS/          #      0.6 %  tma_dtlb_store
         3,195,608      cpu_core/topdown-retiring/
        40,156,649      cpu_core/topdown-mem-bound/
         3,550,925      cpu_core/topdown-bad-spec/
       117,571,818      cpu_core/topdown-fe-bound/
        57,118,087      cpu_core/topdown-be-bound/
            69,179      cpu_core/EXE_ACTIVITY.BOUND_ON_STORES/
             4,582      cpu_core/MEM_INST_RETIRED.STLB_HIT_STORES/
        30,183,104      cpu_core/CPU_CLK_UNHALTED.DISTRIBUTED/
        30,556,790      cpu_core/CPU_CLK_UNHALTED.THREAD/
           168,486      cpu_core/DTLB_STORE_MISSES.WALK_ACTIVE/

0.00 MEM_INST_RETIRED.STLB_HIT_STORES:p 0 0

1.003105924 seconds time elapsed

v1:
TPEBS is one of the features provided by the next generation of Intel PMU. Please refer to Section 8.4.1 of "Intel® Architecture Instruction Set Extensions Programming Reference" [1] for more details about this feature.

This set of patches supports TPEBS in counting mode. The code works in the following way: it forks a perf record process from perf stat when retire_latency of one or more events are used in a metric formula. Perf stat would send a SIGTERM signal to perf record before it needs the retire latency value for metric calculation. Perf stat will then process sample data to extract the retire latency data for metric calculations. Currently, the code uses the arithmetic average of retire latency values.

[1] https://www.intel.com/content/www/us/en/content-details/812218/intel-architecture-instruction-set-extensions-programming-reference.html?wapkw=future%20features

Ian Rogers (1):
perf parse-events: Add a retirement latency modifier

Weilin Wang (7):
perf data: Allow to use given fd in data->file.fd
perf stat: Fork and launch perf record when perf stat needs to get
retire latency value for a metric.
perf stat: Plugin retire_lat value from sampled data to evsel perf vendor events intel: Add MTL metric json files perf stat: Add command line option for enabling tpebs recording perf Document: Add TPEBS to Documents
perf test: Add test for Intel TPEBS counting mode

 tools/perf/Documentation/perf-list.txt        |    1 +
 tools/perf/Documentation/perf-stat.txt        |    8 +
 tools/perf/Documentation/topdown.txt          |   30 +
 tools/perf/arch/x86/util/evlist.c             |    6 +
 tools/perf/builtin-stat.c                     |    8 +
 .../arch/x86/meteorlake/metricgroups.json     |  142 +
 .../arch/x86/meteorlake/mtl-metrics.json      | 2535 +++++++++++++++++
 .../perf/tests/shell/test_stat_intel_tpebs.sh |   18 +
 tools/perf/util/Build                         |    1 +
 tools/perf/util/data.c                        |    7 +-
 tools/perf/util/evlist.c                      |    4 +
 tools/perf/util/evsel.c                       |   91 +-
 tools/perf/util/evsel.h                       |    6 +
 tools/perf/util/intel-tpebs.c                 |  407 +++
 tools/perf/util/intel-tpebs.h                 |   35 +
 tools/perf/util/parse-events.c                |    2 +
 tools/perf/util/parse-events.h                |    1 +
 tools/perf/util/parse-events.l                |    3 +-
 18 files changed, 3301 insertions(+), 4 deletions(-)
 create mode 100644 tools/perf/pmu-events/arch/x86/meteorlake/metricgroups.json
 create mode 100644 tools/perf/pmu-events/arch/x86/meteorlake/mtl-metrics.json
 create mode 100755 tools/perf/tests/shell/test_stat_intel_tpebs.sh
 create mode 100644 tools/perf/util/intel-tpebs.c
 create mode 100644 tools/perf/util/intel-tpebs.h

--
2.43.0

#1 lore raw

RFC PATCH v14 1/8 perf parse-events: Add a retirement latency modifier

From: Ian Rogers <[email protected]>

Retirement latency is a separate sampled count used on newer Intel CPUs.

---
 tools/perf/util/evsel.h        | 1 +
 tools/perf/util/parse-events.c | 2 ++
 tools/perf/util/parse-events.h | 1 +
 tools/perf/util/parse-events.l | 3 ++-
 4 files changed, 6 insertions(+), 1 deletion(-)
tools/perf/util/evsel.h +1 -0
index 80b5f6dd868e..14f777b9e03e 100644
@@ -98,6 +98,7 @@ struct evsel {
 		bool			bpf_counter;
 		bool			use_config_name;
 		bool			skippable;
+		bool			retire_lat;
 		int			bpf_fd;
 		struct bpf_object	*bpf_obj;
 		struct list_head	config_terms;
tools/perf/util/parse-events.c +2 -0
index 321586fb5556..fab01ba54e34 100644
@@ -1811,6 +1811,8 @@ static int parse_events__modifier_list(struct parse_events_state *parse_state,
 			evsel->weak_group = true;
 		if (mod.bpf)
 			evsel->bpf_counter = true;
+		if (mod.retire_lat)
+			evsel->retire_lat = true;
 	}
 	return 0;
 }
tools/perf/util/parse-events.h +1 -0
index e13de2c8b706..b735cd9e0acf 100644
@@ -203,6 +203,7 @@ struct parse_events_modifier {
 	bool hypervisor : 1;	/* 'h' */
 	bool guest : 1;		/* 'G' */
 	bool host : 1;		/* 'H' */
+	bool retire_lat : 1;	/* 'R' */
 };
 
 int parse_events__modifier_event(struct parse_events_state *parse_state, void *loc,
tools/perf/util/parse-events.l +2 -1
index 16045c383ada..5a0bcd7f166a 100644
@@ -209,6 +209,7 @@ static int modifiers(struct parse_events_state *parse_state, yyscan_t scanner)
 		CASE('W', weak);
 		CASE('e', exclusive);
 		CASE('b', bpf);
+		CASE('R', retire_lat);
 		default:
 			return PE_ERROR;
 		}
@@ -250,7 +251,7 @@ drv_cfg_term	[a-zA-Z0-9_\.]+(=[a-zA-Z0-9_*?\.:]+)?
  * If you add a modifier you need to update check_modifier().
  * Also, the letters in modifier_event must not be in modifier_bp.
  */
-modifier_event	[ukhpPGHSDIWeb]{1,15}
+modifier_event	[ukhpPGHSDIWebR]{1,16}
 modifier_bp	[rwx]{1,3}
 lc_type 	(L1-dcache|l1-d|l1d|L1-data|L1-icache|l1-i|l1i|L1-instruction|LLC|L2|dTLB|d-tlb|Data-TLB|iTLB|i-tlb|Instruction-TLB|branch|branches|bpu|btb|bpc|node)
 lc_op_result	(load|loads|read|store|stores|write|prefetch|prefetches|speculative-read|speculative-load|refs|Reference|ops|access|misses|miss)
Signature · 1 line
2.43.0
#2 lore raw

RFC PATCH v14 2/8 perf data: Allow to use given fd in data->file.fd

In reply to [email protected]

From: Weilin Wang <[email protected]>

When in PIPE mode, allow to use fd dynamically opened and asigned to data->file.fd instead of STDIN_FILENO or STDOUT_FILENO.

---
 tools/perf/util/data.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
tools/perf/util/data.c +6 -1
index 08c4bfbd817f..98661ede2a73 100644
@@ -204,7 +204,12 @@ static bool check_pipe(struct perf_data *data)
 				data->file.fd = fd;
 				data->use_stdio = false;
 			}
-		} else {
+
+		/*
+		 * When is_pipe and data->file.fd is given, use given fd
+		 * instead of STDIN_FILENO or STDOUT_FILENO
+		 */
+		} else if (data->file.fd <= 0) {
 			data->file.fd = fd;
 		}
 	}
Signature · 1 line
2.43.0
#3 lore raw

RFC PATCH v14 3/8 perf stat: Fork and launch perf record when perf stat needs to get retire latency value for a metric.

In reply to [email protected]

From: Weilin Wang <[email protected]>

When retire_latency value is used in a metric formula, evsel would fork a perf record process with "-e" and "-W" options. Perf record will collect required retire_latency values in parallel while perf stat is collecting counting values.

At the point of time that perf stat stops counting, evsel would stop perf record by sending sigterm signal to perf record process. Sampled data will be process to get retire latency value. Another thread is required to synchronize between perf stat and perf record when we pass data through pipe.

Retire_latency evsel is not opened for perf stat so that there is no counter wasted on it. This commit includes code suggested by Namhyung to adjust reading size for groups that include retire_latency evsels.

---
 tools/perf/builtin-stat.c     |   4 +
 tools/perf/util/Build         |   1 +
 tools/perf/util/evlist.c      |   4 +
 tools/perf/util/evsel.c       |  70 +++++-
 tools/perf/util/intel-tpebs.c | 407 ++++++++++++++++++++++++++++++++++
 tools/perf/util/intel-tpebs.h |  35 +++
 6 files changed, 519 insertions(+), 2 deletions(-)
 create mode 100644 tools/perf/util/intel-tpebs.c
 create mode 100644 tools/perf/util/intel-tpebs.h
tools/perf/builtin-stat.c +4 -0
index 661832756a24..68125bd75b37 100644
@@ -70,6 +70,7 @@
 #include "util/bpf_counter.h"
 #include "util/iostat.h"
 #include "util/util.h"
+#include "util/intel-tpebs.h"
 #include "asm/bug.h"
 
 #include <linux/time64.h>
@@ -683,6 +684,9 @@ static enum counter_recovery stat_handle_error(struct evsel *counter)
 
 	if (child_pid != -1)
 		kill(child_pid, SIGTERM);
+
+	tpebs_delete();
+
 	return COUNTER_FATAL;
 }
 
tools/perf/util/Build +1 -0
index da64efd8718f..26ef80641f9f 100644
@@ -154,6 +154,7 @@ perf-y += clockid.o
 perf-y += list_sort.o
 perf-y += mutex.o
 perf-y += sharded_mutex.o
+perf-$(CONFIG_X86_64) += intel-tpebs.o
 
 perf-$(CONFIG_LIBBPF) += bpf_map.o
 perf-$(CONFIG_PERF_BPF_SKEL) += bpf_counter.o
tools/perf/util/evlist.c +4 -0
index 3a719edafc7a..394ea7634b95 100644
@@ -33,6 +33,7 @@
 #include "util/bpf-filter.h"
 #include "util/stat.h"
 #include "util/util.h"
+#include "util/intel-tpebs.h"
 #include <signal.h>
 #include <unistd.h>
 #include <sched.h>
@@ -179,6 +180,9 @@ void evlist__delete(struct evlist *evlist)
 	if (evlist == NULL)
 		return;
 
+#ifndef PYTHON_PERF
+	tpebs_delete();
+#endif
 	evlist__free_stats(evlist);
 	evlist__munmap(evlist);
 	evlist__close(evlist);
tools/perf/util/evsel.c +68 -2

106 lines not on this page · raw message

tools/perf/util/intel-tpebs.c new file +407 -0

407 lines not on this page · raw message

tools/perf/util/intel-tpebs.h new file +35 -0
new file mode 100644
index 000000000000..766b3fbd79f1
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * intel_tpebs.h: Intel TEPBS support
+ */
+#ifndef INCLUDE__PERF_INTEL_TPEBS_H__
+#define INCLUDE__PERF_INTEL_TPEBS_H__
+
+#include "stat.h"
+#include "evsel.h"
+
+#ifdef HAVE_ARCH_X86_64_SUPPORT
+
+extern bool tpebs_recording;
+int tpebs_start(struct evlist *evsel_list);
+void tpebs_delete(void);
+int tpebs_set_evsel(struct evsel *evsel, int cpu_map_idx, int thread);
+
+#else
+
+static inline int tpebs_start(struct evlist *evsel_list __maybe_unused)
+{
+	return 0;
+}
+
+static inline void tpebs_delete(void) {};
+
+static inline int tpebs_set_evsel(struct evsel *evsel  __maybe_unused,
+				int cpu_map_idx  __maybe_unused,
+				int thread  __maybe_unused)
+{
+	return 0;
+}
+
+#endif
+#endif
Signature · 1 line
2.43.0
#4 lore raw

RFC PATCH v14 4/8 perf stat: Plugin retire_lat value from sampled data to evsel

In reply to [email protected]

From: Weilin Wang <[email protected]>

In current :R parsing implementation, the parser would recognize events with retire_latency modifier and insert them into the evlist like a normal event. Ideally, we need to avoid counting these events.

In this commit, at the time when a retire_latency evsel is read, set the retire latency value processed from the sampled data to count value. This sampled retire latency value will be used for metric calculation and final event count print out. No special metric calculation and event print out code required for retire_latency events.

---
 tools/perf/arch/x86/util/evlist.c |  6 ++++++
 tools/perf/util/evsel.c           | 21 +++++++++++++++++++++
 tools/perf/util/evsel.h           |  5 +++++
 3 files changed, 32 insertions(+)
tools/perf/arch/x86/util/evlist.c +6 -0
index b1ce0c52d88d..cebdd483149e 100644
@@ -89,6 +89,12 @@ int arch_evlist__cmp(const struct evsel *lhs, const struct evsel *rhs)
 			return 1;
 	}
 
+	/* Retire latency event should not be group leader*/
+	if (lhs->retire_lat && !rhs->retire_lat)
+		return 1;
+	if (!lhs->retire_lat && rhs->retire_lat)
+		return -1;
+
 	/* Default ordering by insertion index. */
 	return lhs->core.idx - rhs->core.idx;
 }
tools/perf/util/evsel.c +21 -0
index 06dcaa36c3f3..f7791879b661 100644
@@ -58,6 +58,7 @@
 #include <internal/xyarray.h>
 #include <internal/lib.h>
 #include <internal/threadmap.h>
+#include "util/intel-tpebs.h"
 
 #include <linux/ctype.h>
 
@@ -1532,6 +1533,13 @@ static int evsel__read_one(struct evsel *evsel, int cpu_map_idx, int thread)
 	return perf_evsel__read(&evsel->core, cpu_map_idx, thread, count);
 }
 
+#ifndef PYTHON_PERF
+static int evsel__read_retire_lat(struct evsel *evsel, int cpu_map_idx, int thread)
+{
+	return tpebs_set_evsel(evsel, cpu_map_idx, thread);
+}
+#endif
+
 static void evsel__set_count(struct evsel *counter, int cpu_map_idx, int thread,
 			     u64 val, u64 ena, u64 run, u64 lost)
 {
@@ -1539,6 +1547,14 @@ static void evsel__set_count(struct evsel *counter, int cpu_map_idx, int thread,
 
 	count = perf_counts(counter->counts, cpu_map_idx, thread);
 
+#ifndef PYTHON_PERF
+	if (counter->retire_lat) {
+		evsel__read_retire_lat(counter, cpu_map_idx, thread);
+		perf_counts__set_loaded(counter->counts, cpu_map_idx, thread, true);
+		return;
+	}
+#endif
+
 	count->val    = val;
 	count->ena    = ena;
 	count->run    = run;
@@ -1831,6 +1847,11 @@ int evsel__read_counter(struct evsel *evsel, int cpu_map_idx, int thread)
 	if (evsel__is_tool(evsel))
 		return evsel__read_tool(evsel, cpu_map_idx, thread);
 
+#ifndef PYTHON_PERF
+	if (evsel__is_retire_lat(evsel))
+		return evsel__read_retire_lat(evsel, cpu_map_idx, thread);
+#endif
+
 	if (evsel->core.attr.read_format & PERF_FORMAT_GROUP)
 		return evsel__read_group(evsel, cpu_map_idx, thread);
 
tools/perf/util/evsel.h +5 -0
index 14f777b9e03e..a5da4b03bb1c 100644
@@ -311,6 +311,11 @@ static inline bool evsel__is_tool(const struct evsel *evsel)
 	return evsel->tool_event != PERF_TOOL_NONE;
 }
 
+static inline bool evsel__is_retire_lat(const struct evsel *evsel)
+{
+	return evsel->retire_lat;
+}
+
 const char *evsel__group_name(struct evsel *evsel);
 int evsel__group_desc(struct evsel *evsel, char *buf, size_t size);
 
Signature · 1 line
2.43.0
#5 lore raw

RFC PATCH v14 5/8 perf vendor events intel: Add MTL metric json files

In reply to [email protected]

From: Weilin Wang <[email protected]>

Add MTL metric json file for TMA4.8. Some of the metrics' formulas use TPEBS retire_latency in MTL.

This also includes lated E-Core TMA3.6 changes.

---
 .../arch/x86/meteorlake/metricgroups.json     |  142 +
 .../arch/x86/meteorlake/mtl-metrics.json      | 2535 +++++++++++++++++
 2 files changed, 2677 insertions(+)
 create mode 100644 tools/perf/pmu-events/arch/x86/meteorlake/metricgroups.json
 create mode 100644 tools/perf/pmu-events/arch/x86/meteorlake/mtl-metrics.json
tools/perf/pmu-events/arch/x86/meteorlake/metricgroups.json new file +142 -0
new file mode 100644
index 000000000000..b54a5fc0861f
@@ -0,0 +1,142 @@
+{
+    "Backend": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "Bad": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "BadSpec": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "BigFootprint": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "BrMispredicts": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "Branches": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "BvBC": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "BvBO": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "BvCB": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "BvFB": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "BvIO": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "BvMB": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "BvML": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "BvMP": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "BvMS": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "BvMT": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "BvOB": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "BvUW": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "C0Wait": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "CacheHits": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "CacheMisses": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "CodeGen": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "Compute": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "Cor": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "DSB": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "DSBmiss": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "DataSharing": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "Fed": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "FetchBW": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "FetchLat": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "Flops": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "FpScalar": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "FpVector": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "Frontend": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "HPC": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "IcMiss": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "Ifetch": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "InsType": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "IntVector": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "L2Evicts": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "LSD": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "Load_Store_Miss": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "MachineClears": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "Machine_Clears": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "Mem": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "MemOffcore": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "Mem_Exec": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "MemoryBW": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "MemoryBound": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "MemoryLat": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "MemoryTLB": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "Memory_BW": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "Memory_Lat": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "MicroSeq": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "OS": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "Offcore": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "PGO": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "Pipeline": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "PortsUtil": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "Power": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "Prefetches": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "Ret": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "Retire": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "SMT": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "Server": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "Snoop": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "SoC": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "Summary": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "TmaL1": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "TmaL2": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "TmaL3mem": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "TopdownL1": "Metrics for top-down breakdown at level 1",
+    "TopdownL2": "Metrics for top-down breakdown at level 2",
+    "TopdownL3": "Metrics for top-down breakdown at level 3",
+    "TopdownL4": "Metrics for top-down breakdown at level 4",
+    "TopdownL5": "Metrics for top-down breakdown at level 5",
+    "TopdownL6": "Metrics for top-down breakdown at level 6",
+    "load_store_bound": "Grouping from Top-down Microarchitecture Analysis Metrics spreadsheet",
+    "tma_L1_group": "Metrics for top-down breakdown at level 1",
+    "tma_L2_group": "Metrics for top-down breakdown at level 2",
+    "tma_L3_group": "Metrics for top-down breakdown at level 3",
+    "tma_L4_group": "Metrics for top-down breakdown at level 4",
+    "tma_L5_group": "Metrics for top-down breakdown at level 5",
+    "tma_L6_group": "Metrics for top-down breakdown at level 6",
+    "tma_alu_op_utilization_group": "Metrics contributing to tma_alu_op_utilization category",
+    "tma_assists_group": "Metrics contributing to tma_assists category",
+    "tma_backend_bound_group": "Metrics contributing to tma_backend_bound category",
+    "tma_bad_speculation_group": "Metrics contributing to tma_bad_speculation category",
+    "tma_branch_mispredicts_group": "Metrics contributing to tma_branch_mispredicts category",
+    "tma_branch_resteers_group": "Metrics contributing to tma_branch_resteers category",
+    "tma_core_bound_group": "Metrics contributing to tma_core_bound category",
+    "tma_dram_bound_group": "Metrics contributing to tma_dram_bound category",
+    "tma_dtlb_load_group": "Metrics contributing to tma_dtlb_load category",
+    "tma_dtlb_store_group": "Metrics contributing to tma_dtlb_store category",
+    "tma_fetch_bandwidth_group": "Metrics contributing to tma_fetch_bandwidth category",
+    "tma_fetch_latency_group": "Metrics contributing to tma_fetch_latency category",
+    "tma_fp_arith_group": "Metrics contributing to tma_fp_arith category",
+    "tma_fp_vector_group": "Metrics contributing to tma_fp_vector category",
+    "tma_frontend_bound_group": "Metrics contributing to tma_frontend_bound category",
+    "tma_heavy_operations_group": "Metrics contributing to tma_heavy_operations category",
+    "tma_ifetch_bandwidth_group": "Metrics contributing to tma_ifetch_bandwidth category",
+    "tma_ifetch_latency_group": "Metrics contributing to tma_ifetch_latency category",
+    "tma_int_operations_group": "Metrics contributing to tma_int_operations category",
+    "tma_issue2P": "Metrics related by the issue $issue2P",
+    "tma_issueBM": "Metrics related by the issue $issueBM",
+    "tma_issueBW": "Metrics related by the issue $issueBW",
+    "tma_issueComp": "Metrics related by the issue $issueComp",
+    "tma_issueD0": "Metrics related by the issue $issueD0",
+    "tma_issueFB": "Metrics related by the issue $issueFB",
+    "tma_issueFL": "Metrics related by the issue $issueFL",
+    "tma_issueL1": "Metrics related by the issue $issueL1",
+    "tma_issueLat": "Metrics related by the issue $issueLat",
+    "tma_issueMC": "Metrics related by the issue $issueMC",
+    "tma_issueMS": "Metrics related by the issue $issueMS",
+    "tma_issueMV": "Metrics related by the issue $issueMV",
+    "tma_issueRFO": "Metrics related by the issue $issueRFO",
+    "tma_issueSL": "Metrics related by the issue $issueSL",
+    "tma_issueSO": "Metrics related by the issue $issueSO",
+    "tma_issueSmSt": "Metrics related by the issue $issueSmSt",
+    "tma_issueSpSt": "Metrics related by the issue $issueSpSt",
+    "tma_issueSyncxn": "Metrics related by the issue $issueSyncxn",
+    "tma_issueTLB": "Metrics related by the issue $issueTLB",
+    "tma_l1_bound_group": "Metrics contributing to tma_l1_bound category",
+    "tma_l3_bound_group": "Metrics contributing to tma_l3_bound category",
+    "tma_light_operations_group": "Metrics contributing to tma_light_operations category",
+    "tma_load_op_utilization_group": "Metrics contributing to tma_load_op_utilization category",
+    "tma_machine_clears_group": "Metrics contributing to tma_machine_clears category",
+    "tma_mem_latency_group": "Metrics contributing to tma_mem_latency category",
+    "tma_memory_bound_group": "Metrics contributing to tma_memory_bound category",
+    "tma_microcode_sequencer_group": "Metrics contributing to tma_microcode_sequencer category",
+    "tma_mite_group": "Metrics contributing to tma_mite category",
+    "tma_other_light_ops_group": "Metrics contributing to tma_other_light_ops category",
+    "tma_ports_utilization_group": "Metrics contributing to tma_ports_utilization category",
+    "tma_ports_utilized_0_group": "Metrics contributing to tma_ports_utilized_0 category",
+    "tma_ports_utilized_3m_group": "Metrics contributing to tma_ports_utilized_3m category",
+    "tma_resource_bound_group": "Metrics contributing to tma_resource_bound category",
+    "tma_retiring_group": "Metrics contributing to tma_retiring category",
+    "tma_serializing_operation_group": "Metrics contributing to tma_serializing_operation category",
+    "tma_store_bound_group": "Metrics contributing to tma_store_bound category",
+    "tma_store_op_utilization_group": "Metrics contributing to tma_store_op_utilization category"
+}
tools/perf/pmu-events/arch/x86/meteorlake/mtl-metrics.json new file +2535 -0

2,535 lines not on this page · raw message

Signature · 1 line
2.43.0
#6 lore raw

RFC PATCH v14 6/8 perf stat: Add command line option for enabling tpebs recording

In reply to [email protected]

From: Weilin Wang <[email protected]>

With this command line option, tpebs recording is turned off in perf stat on default. It will only be turned on when this option is given in perf stat command.

Exampe with --enable-tpebs-recording:

perf stat -M tma_split_loads -C1-4 --enable-tpebs-recording sleep 1

[ perf record: Woken up 2 times to write data ]
[ perf record: Captured and wrote 0.044 MB - ]

Performance counter stats for 'CPU(s) 1-4':

    53,259,156,071      cpu_core/TOPDOWN.SLOTS/          #      1.6 %  tma_split_loads          (50.00%)
    15,867,565,250      cpu_core/topdown-retiring/                                              (50.00%)
    15,655,580,731      cpu_core/topdown-mem-bound/                                             (50.00%)
    11,738,022,218      cpu_core/topdown-bad-spec/                                              (50.00%)
     6,151,265,424      cpu_core/topdown-fe-bound/                                              (50.00%)
    20,445,917,581      cpu_core/topdown-be-bound/                                              (50.00%)
     6,925,098,013      cpu_core/L1D_PEND_MISS.PENDING/                                         (50.00%)
     3,838,653,421      cpu_core/MEMORY_ACTIVITY.STALLS_L1D_MISS/                                        (50.00%)
     4,797,059,783      cpu_core/EXE_ACTIVITY.BOUND_ON_LOADS/                                        (50.00%)
    11,931,916,714      cpu_core/CPU_CLK_UNHALTED.THREAD/                                        (50.00%)
       102,576,164      cpu_core/MEM_LOAD_COMPLETED.L1_MISS_ANY/                                        (50.00%)
        64,071,854      cpu_core/MEM_INST_RETIRED.SPLIT_LOADS/                                        (50.00%)
                 3      cpu_core/MEM_INST_RETIRED.SPLIT_LOADS/R
       1.003049679 seconds time elapsed

Exampe without --enable-tpebs-recording:

perf stat -M tma_contested_accesses -C1 sleep 1

Performance counter stats for 'CPU(s) 1':

        50,203,891      cpu_core/TOPDOWN.SLOTS/          #      0.0 %  tma_contested_accesses   (63.60%)
        10,040,777      cpu_core/topdown-retiring/                                              (63.60%)
         6,890,729      cpu_core/topdown-mem-bound/                                             (63.60%)
         2,756,463      cpu_core/topdown-bad-spec/                                              (63.60%)
        10,828,288      cpu_core/topdown-fe-bound/                                              (63.60%)
        28,350,432      cpu_core/topdown-be-bound/                                              (63.60%)
                98      cpu_core/OCR.DEMAND_DATA_RD.L3_HIT.SNOOP_HITM/                                        (63.70%)
           577,520      cpu_core/MEMORY_ACTIVITY.STALLS_L2_MISS/                                        (54.62%)
           313,339      cpu_core/MEMORY_ACTIVITY.STALLS_L3_MISS/                                        (54.62%)
            14,155      cpu_core/MEM_LOAD_RETIRED.L1_MISS/                                        (45.54%)
                 0      cpu_core/OCR.DEMAND_DATA_RD.L3_HIT.SNOOP_HIT_WITH_FWD/                                        (36.30%)
         8,468,077      cpu_core/CPU_CLK_UNHALTED.THREAD/                                        (45.38%)
               198      cpu_core/MEM_LOAD_L3_HIT_RETIRED.XSNP_MISS/                                        (45.38%)
             8,324      cpu_core/MEM_LOAD_RETIRED.FB_HIT/                                        (45.38%)
     3,388,031,520      TSC
        23,226,785      cpu_core/CPU_CLK_UNHALTED.REF_TSC/                                        (54.46%)
                80      cpu_core/MEM_LOAD_L3_HIT_RETIRED.XSNP_FWD/                                        (54.46%)
                 0      cpu_core/MEM_LOAD_L3_HIT_RETIRED.XSNP_FWD/R
                 0      cpu_core/MEM_LOAD_L3_HIT_RETIRED.XSNP_MISS/R
     1,006,816,667 ns   duration_time
       1.002537737 seconds time elapsed
---
 tools/perf/Documentation/perf-stat.txt | 8 ++++++++
 tools/perf/builtin-stat.c              | 4 ++++
 2 files changed, 12 insertions(+)
tools/perf/Documentation/perf-stat.txt +8 -0
index 29756a87ab6f..f4cde834811d 100644
@@ -498,6 +498,14 @@ To interpret the results it is usually needed to know on which
 CPUs the workload runs on. If needed the CPUs can be forced using
 taskset.
 
+--enable-tpebs-recording::
+Enable automatic sampling on Intel TPEBS retire_latency events (event with :R
+modifier). Without this option, perf would not capture dynamic retire_latency
+at runtime. Currently, a zero value is assigned to the retire_latency event when
+this option is not set. The TPEBS hardware feature starts from Intel Granite
+Rapids microarchitecture. This option only exists in X86_64 and is meaningful on
+Intel platforms with TPEBS feature.
+
 --td-level::
 Print the top-down statistics that equal the input level. It allows
 users to print the interested top-down metrics level instead of the
tools/perf/builtin-stat.c +4 -0
index 68125bd75b37..7111c96e68ab 100644
@@ -2475,6 +2475,10 @@ int cmd_stat(int argc, const char **argv)
 			"disable adding events for the metric threshold calculation"),
 		OPT_BOOLEAN(0, "topdown", &topdown_run,
 			"measure top-down statistics"),
+#ifdef HAVE_ARCH_X86_64_SUPPORT
+		OPT_BOOLEAN(0, "enable-tpebs-recording", &tpebs_recording,
+			"enable recording for tpebs when retire_latency required"),
+#endif
 		OPT_UINTEGER(0, "td-level", &stat_config.topdown_level,
 			"Set the metrics level for the top-down statistics (0: max level)"),
 		OPT_BOOLEAN(0, "smi-cost", &smi_cost,
Signature · 1 line
2.43.0
maintainer
#7 lore raw

Re: [RFC PATCH v14 6/8] perf stat: Add command line option for enabling tpebs recording

Hello Weilin,

Quoted 7 lines · On Mon, Jun 24, 2024 at 06:20:22PM -0400, [email protected] wrote:

From: Weilin Wang <[email protected]>

With this command line option, tpebs recording is turned off in perf stat on default. It will only be turned on when this option is given in perf stat command.

Exampe with --enable-tpebs-recording:

I prefer shorter names, how about --enable-tpebs or --record-tpebs, or maybe just --tpebs ?

Thanks,
Namhyung

Quoted 96 lines

perf stat -M tma_split_loads -C1-4 --enable-tpebs-recording sleep 1

[ perf record: Woken up 2 times to write data ]
[ perf record: Captured and wrote 0.044 MB - ]

Performance counter stats for 'CPU(s) 1-4':

    53,259,156,071      cpu_core/TOPDOWN.SLOTS/          #      1.6 %  tma_split_loads          (50.00%)
    15,867,565,250      cpu_core/topdown-retiring/                                              (50.00%)
    15,655,580,731      cpu_core/topdown-mem-bound/                                             (50.00%)
    11,738,022,218      cpu_core/topdown-bad-spec/                                              (50.00%)
     6,151,265,424      cpu_core/topdown-fe-bound/                                              (50.00%)
    20,445,917,581      cpu_core/topdown-be-bound/                                              (50.00%)
     6,925,098,013      cpu_core/L1D_PEND_MISS.PENDING/                                         (50.00%)
     3,838,653,421      cpu_core/MEMORY_ACTIVITY.STALLS_L1D_MISS/                                        (50.00%)
     4,797,059,783      cpu_core/EXE_ACTIVITY.BOUND_ON_LOADS/                                        (50.00%)
    11,931,916,714      cpu_core/CPU_CLK_UNHALTED.THREAD/                                        (50.00%)
       102,576,164      cpu_core/MEM_LOAD_COMPLETED.L1_MISS_ANY/                                        (50.00%)
        64,071,854      cpu_core/MEM_INST_RETIRED.SPLIT_LOADS/                                        (50.00%)
                 3      cpu_core/MEM_INST_RETIRED.SPLIT_LOADS/R
       1.003049679 seconds time elapsed

Exampe without --enable-tpebs-recording:

perf stat -M tma_contested_accesses -C1 sleep 1

Performance counter stats for 'CPU(s) 1':

        50,203,891      cpu_core/TOPDOWN.SLOTS/          #      0.0 %  tma_contested_accesses   (63.60%)
        10,040,777      cpu_core/topdown-retiring/                                              (63.60%)
         6,890,729      cpu_core/topdown-mem-bound/                                             (63.60%)
         2,756,463      cpu_core/topdown-bad-spec/                                              (63.60%)
        10,828,288      cpu_core/topdown-fe-bound/                                              (63.60%)
        28,350,432      cpu_core/topdown-be-bound/                                              (63.60%)
                98      cpu_core/OCR.DEMAND_DATA_RD.L3_HIT.SNOOP_HITM/                                        (63.70%)
           577,520      cpu_core/MEMORY_ACTIVITY.STALLS_L2_MISS/                                        (54.62%)
           313,339      cpu_core/MEMORY_ACTIVITY.STALLS_L3_MISS/                                        (54.62%)
            14,155      cpu_core/MEM_LOAD_RETIRED.L1_MISS/                                        (45.54%)
                 0      cpu_core/OCR.DEMAND_DATA_RD.L3_HIT.SNOOP_HIT_WITH_FWD/                                        (36.30%)
         8,468,077      cpu_core/CPU_CLK_UNHALTED.THREAD/                                        (45.38%)
               198      cpu_core/MEM_LOAD_L3_HIT_RETIRED.XSNP_MISS/                                        (45.38%)
             8,324      cpu_core/MEM_LOAD_RETIRED.FB_HIT/                                        (45.38%)
     3,388,031,520      TSC
        23,226,785      cpu_core/CPU_CLK_UNHALTED.REF_TSC/                                        (54.46%)
                80      cpu_core/MEM_LOAD_L3_HIT_RETIRED.XSNP_FWD/                                        (54.46%)
                 0      cpu_core/MEM_LOAD_L3_HIT_RETIRED.XSNP_FWD/R
                 0      cpu_core/MEM_LOAD_L3_HIT_RETIRED.XSNP_MISS/R
     1,006,816,667 ns   duration_time
       1.002537737 seconds time elapsed
---
 tools/perf/Documentation/perf-stat.txt | 8 ++++++++
 tools/perf/builtin-stat.c              | 4 ++++
 2 files changed, 12 insertions(+)
tools/perf/Documentation/perf-stat.txt +8 -0
index 29756a87ab6f..f4cde834811d 100644
@@ -498,6 +498,14 @@ To interpret the results it is usually needed to know on which
 CPUs the workload runs on. If needed the CPUs can be forced using
 taskset.
 
+--enable-tpebs-recording::
+Enable automatic sampling on Intel TPEBS retire_latency events (event with :R
+modifier). Without this option, perf would not capture dynamic retire_latency
+at runtime. Currently, a zero value is assigned to the retire_latency event when
+this option is not set. The TPEBS hardware feature starts from Intel Granite
+Rapids microarchitecture. This option only exists in X86_64 and is meaningful on
+Intel platforms with TPEBS feature.
+
 --td-level::
 Print the top-down statistics that equal the input level. It allows
 users to print the interested top-down metrics level instead of the
tools/perf/builtin-stat.c +4 -0
index 68125bd75b37..7111c96e68ab 100644
@@ -2475,6 +2475,10 @@ int cmd_stat(int argc, const char **argv)
 			"disable adding events for the metric threshold calculation"),
 		OPT_BOOLEAN(0, "topdown", &topdown_run,
 			"measure top-down statistics"),
+#ifdef HAVE_ARCH_X86_64_SUPPORT
+		OPT_BOOLEAN(0, "enable-tpebs-recording", &tpebs_recording,
+			"enable recording for tpebs when retire_latency required"),
+#endif
 		OPT_UINTEGER(0, "td-level", &stat_config.topdown_level,
 			"Set the metrics level for the top-down statistics (0: max level)"),
 		OPT_BOOLEAN(0, "smi-cost", &smi_cost,
Signature · 1 line
2.43.0
#8 lore raw

RE: [RFC PATCH v14 6/8] perf stat: Add command line option for enabling tpebs recording

Quoted 22 lines

-----Original Message-----
From: Namhyung Kim <[email protected]>
Sent: Wednesday, June 26, 2024 10:56 AM
To: Wang, Weilin <[email protected]>
Cc: Ian Rogers <[email protected]>; Arnaldo Carvalho de Melo <[email protected]>; Peter Zijlstra <[email protected]>; Ingo Molnar <[email protected]>; Alexander Shishkin <[email protected]>; Jiri Olsa <[email protected]>; Hunter, Adrian <[email protected]>; Kan Liang <[email protected]>; [email protected]; [email protected]; Taylor, Perry <[email protected]>; Alt, Samantha <[email protected]>; Biggers, Caleb <[email protected]>
Subject: Re: [RFC PATCH v14 6/8] perf stat: Add command line option for enabling tpebs recording

Hello Weilin,

Quoted 2 lines · On Mon, Jun 24, 2024 at 06:20:22PM -0400, [email protected] wrote:

From: Weilin Wang <[email protected]>

Quoted 8 lines
Quoted 5 lines

With this command line option, tpebs recording is turned off in perf stat on default. It will only be turned on when this option is given in perf stat command.

Exampe with --enable-tpebs-recording:

I prefer shorter names, how about --enable-tpebs or --record-tpebs, or maybe just --tpebs ?

Hi Namhyung,

The name --record-tpebs sounds good. I can update the code to use this one.

Thanks,
Weilin

Quoted 139 lines

Thanks,
Namhyung

Quoted 9 lines

perf stat -M tma_split_loads -C1-4 --enable-tpebs-recording sleep 1

[ perf record: Woken up 2 times to write data ]
[ perf record: Captured and wrote 0.044 MB - ]

Performance counter stats for 'CPU(s) 1-4':

    53,259,156,071      cpu_core/TOPDOWN.SLOTS/          #      1.6 %

tma_split_loads (50.00%)

Quoted 1 line
    15,867,565,250      cpu_core/topdown-retiring/

(50.00%)

Quoted 1 line
    15,655,580,731      cpu_core/topdown-mem-bound/

(50.00%)

Quoted 1 line
    11,738,022,218      cpu_core/topdown-bad-spec/

(50.00%)

Quoted 1 line
     6,151,265,424      cpu_core/topdown-fe-bound/

(50.00%)

Quoted 1 line
    20,445,917,581      cpu_core/topdown-be-bound/

(50.00%)

Quoted 1 line
     6,925,098,013      cpu_core/L1D_PEND_MISS.PENDING/

(50.00%)

Quoted 1 line
     3,838,653,421      cpu_core/MEMORY_ACTIVITY.STALLS_L1D_MISS/

(50.00%)

Quoted 1 line
     4,797,059,783      cpu_core/EXE_ACTIVITY.BOUND_ON_LOADS/

(50.00%)

Quoted 1 line
    11,931,916,714      cpu_core/CPU_CLK_UNHALTED.THREAD/

(50.00%)

Quoted 1 line
       102,576,164      cpu_core/MEM_LOAD_COMPLETED.L1_MISS_ANY/

(50.00%)

Quoted 1 line
        64,071,854      cpu_core/MEM_INST_RETIRED.SPLIT_LOADS/

(50.00%)

Quoted 11 lines
                 3      cpu_core/MEM_INST_RETIRED.SPLIT_LOADS/R

       1.003049679 seconds time elapsed

Exampe without --enable-tpebs-recording:

perf stat -M tma_contested_accesses -C1 sleep 1

Performance counter stats for 'CPU(s) 1':

        50,203,891      cpu_core/TOPDOWN.SLOTS/          #      0.0 %

tma_contested_accesses (63.60%)

Quoted 1 line
        10,040,777      cpu_core/topdown-retiring/

(63.60%)

Quoted 1 line
         6,890,729      cpu_core/topdown-mem-bound/

(63.60%)

Quoted 1 line
         2,756,463      cpu_core/topdown-bad-spec/

(63.60%)

Quoted 1 line
        10,828,288      cpu_core/topdown-fe-bound/

(63.60%)

Quoted 1 line
        28,350,432      cpu_core/topdown-be-bound/

(63.60%)

Quoted 1 line

98 cpu_core/OCR.DEMAND_DATA_RD.L3_HIT.SNOOP_HITM/

(63.70%)

Quoted 1 line
           577,520      cpu_core/MEMORY_ACTIVITY.STALLS_L2_MISS/

(54.62%)

Quoted 1 line
           313,339      cpu_core/MEMORY_ACTIVITY.STALLS_L3_MISS/

(54.62%)

Quoted 1 line
            14,155      cpu_core/MEM_LOAD_RETIRED.L1_MISS/

(45.54%)

Quoted 1 line
                 0

cpu_core/OCR.DEMAND_DATA_RD.L3_HIT.SNOOP_HIT_WITH_FWD/ (36.30%)

Quoted 1 line
         8,468,077      cpu_core/CPU_CLK_UNHALTED.THREAD/

(45.38%)

Quoted 1 line

198 cpu_core/MEM_LOAD_L3_HIT_RETIRED.XSNP_MISS/

(45.38%)

Quoted 1 line
             8,324      cpu_core/MEM_LOAD_RETIRED.FB_HIT/

(45.38%)

Quoted 2 lines
     3,388,031,520      TSC
        23,226,785      cpu_core/CPU_CLK_UNHALTED.REF_TSC/

(54.46%)

Quoted 1 line

80 cpu_core/MEM_LOAD_L3_HIT_RETIRED.XSNP_FWD/

(54.46%)

Quoted 6 lines
                 0      cpu_core/MEM_LOAD_L3_HIT_RETIRED.XSNP_FWD/R
                 0      cpu_core/MEM_LOAD_L3_HIT_RETIRED.XSNP_MISS/R
     1,006,816,667 ns   duration_time
       1.002537737 seconds time elapsed

Review

Quoted 7 lines
---
 tools/perf/Documentation/perf-stat.txt | 8 ++++++++
 tools/perf/builtin-stat.c              | 4 ++++
 2 files changed, 12 insertions(+)
(quoted diff) +0 -0

b/tools/perf/Documentation/perf-stat.txt

tools/perf/Documentation/perf-stat.txt To interpret the results it is usually needed to

Quoted 4 lines

index 29756a87ab6f..f4cde834811d 100644

tools/perf/Documentation/perf-stat.txt +0 -0
@@ -498,6 +498,14 @@ To interpret the results it is usually needed to

know on which

tools/perf/Documentation/perf-stat.txt To interpret the results it is usually needed to know on which

Quoted 5 lines
tools/perf/Documentation/perf-stat.txt +2 -0
 CPUs the workload runs on. If needed the CPUs can be forced using
 taskset.
 
+--enable-tpebs-recording::
+Enable automatic sampling on Intel TPEBS retire_latency events (event

with :R

tools/perf/Documentation/perf-stat.txt To interpret the results it is usually needed to · line 503

Quoted 1 line
tools/perf/Documentation/perf-stat.txt +1 -0
+modifier). Without this option, perf would not capture dynamic

retire_latency

tools/perf/Documentation/perf-stat.txt To interpret the results it is usually needed to · line 504

Quoted 1 line
tools/perf/Documentation/perf-stat.txt +1 -0
+at runtime. Currently, a zero value is assigned to the retire_latency event

when

tools/perf/Documentation/perf-stat.txt To interpret the results it is usually needed to · line 506

Quoted 2 lines
tools/perf/Documentation/perf-stat.txt +2 -0
+this option is not set. The TPEBS hardware feature starts from Intel Granite
+Rapids microarchitecture. This option only exists in X86_64 and is

meaningful on

tools/perf/builtin-stat.c int cmd_stat(int argc, const char **argv) · line 2475

Quoted 11 lines
tools/perf/Documentation/perf-stat.txt +2 -0
+Intel platforms with TPEBS feature.
+
 --td-level::
 Print the top-down statistics that equal the input level. It allows
 users to print the interested top-down metrics level instead of the
tools/perf/builtin-stat.c +0 -0
index 68125bd75b37..7111c96e68ab 100644
@@ -2475,6 +2475,10 @@ int cmd_stat(int argc, const char **argv)
 			"disable adding events for the metric threshold

calculation"),

tools/perf/builtin-stat.c int cmd_stat(int argc, const char **argv)

Quoted 4 lines
tools/perf/builtin-stat.c +2 -0
 		OPT_BOOLEAN(0, "topdown", &topdown_run,
 			"measure top-down statistics"),
+#ifdef HAVE_ARCH_X86_64_SUPPORT
+		OPT_BOOLEAN(0, "enable-tpebs-recording",

&tpebs_recording,

tools/perf/builtin-stat.c int cmd_stat(int argc, const char **argv) · line 2480

Quoted 1 line
tools/perf/builtin-stat.c +1 -0
+			"enable recording for tpebs when retire_latency

required"),

tools/perf/builtin-stat.c int cmd_stat(int argc, const char **argv)

Quoted 3 lines
tools/perf/builtin-stat.c +1 -0
+#endif
 		OPT_UINTEGER(0, "td-level", &stat_config.topdown_level,
 			"Set the metrics level for the top-down statistics (0:

max level)"),

Quoted 4 lines
tools/perf/builtin-stat.c +0 -1
 		OPT_BOOLEAN(0, "smi-cost", &smi_cost,
--

2.43.0

#9 lore raw

RFC PATCH v14 7/8 perf Document: Add TPEBS to Documents

In reply to [email protected]

From: Weilin Wang <[email protected]>

TPEBS is a new feature Intel PMU from Granite Rapids microarchitecture. It will be used in new TMA releases. Adding related introduction to documents while adding new code to support it in perf stat.

---
 tools/perf/Documentation/perf-list.txt |  1 +
 tools/perf/Documentation/topdown.txt   | 30 ++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)
tools/perf/Documentation/perf-list.txt +1 -0
index 6bf2468f59d3..dea005410ec0 100644
@@ -72,6 +72,7 @@ counted. The following modifiers exist:
  W - group is weak and will fallback to non-group if not schedulable,
  e - group or event are exclusive and do not share the PMU
  b - use BPF aggregration (see perf stat --bpf-counters)
+ R - retire latency value of the event
 
 The 'p' modifier can be used for specifying how precise the instruction
 address should be. The 'p' modifier can be specified multiple times:
tools/perf/Documentation/topdown.txt +30 -0
index ae0aee86844f..98e5503552f5 100644
@@ -325,6 +325,36 @@ other four level 2 metrics by subtracting corresponding metrics as below.
     Fetch_Bandwidth = Frontend_Bound - Fetch_Latency
     Core_Bound = Backend_Bound - Memory_Bound
 
+TPEBS in TopDown
+================
+
+TPEBS (Timed PEBS) is one of the new Intel PMU features provided since Granite
+Rapids microarchitecture. The TPEBS feature adds a 16 bit retire_latency field
+in the Basic Info group of the PEBS record. It records the Core cycles since the
+retirement of the previous instruction to the retirement of current instruction.
+Please refer to Section 8.4.1 of "Intel® Architecture Instruction Set Extensions
+Programming Reference" for more details about this feature. Because this feature
+extends PEBS record, sampling with weight option is required to get the
+retire_latency value.
+
+	perf record -e event_name -W ...
+
+In the most recent release of TMA, the metrics begin to use event retire_latency
+values in some of the metrics’ formulas on processors that support TPEBS feature.
+For previous generations that do not support TPEBS, the values are static and
+predefined per processor family by the hardware architects. Due to the diversity
+of workloads in execution environments, retire_latency values measured at real
+time are more accurate. Therefore, new TMA metrics that use TPEBS will provide
+more accurate performance analysis results.
+
+To support TPEBS in TMA metrics, a new modifier :R on event is added. Perf would
+capture retire_latency value of required events(event with :R in metric formula)
+with perf record. The retire_latency value would be used in metric calculation.
+Currently, this feature is supported through perf stat
+
+	perf stat -M metric_name --enable-tpebs-recording ...
+
+
 
 [1] https://software.intel.com/en-us/top-down-microarchitecture-analysis-method-win
 [2] https://sites.google.com/site/analysismethods/yasin-pubs
Signature · 1 line
2.43.0
#10 lore raw

RFC PATCH v14 8/8 perf test: Add test for Intel TPEBS counting mode

In reply to [email protected]

From: Weilin Wang <[email protected]>

Intel TPEBS sampling mode is supported through perf record. The counting mode code uses perf record to capture retire_latency value and use it in metric calculation. This test checks the counting mode code.

---
 .../perf/tests/shell/test_stat_intel_tpebs.sh  | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
 create mode 100755 tools/perf/tests/shell/test_stat_intel_tpebs.sh
tools/perf/tests/shell/test_stat_intel_tpebs.sh new file +18 -0
new file mode 100755
index 000000000000..220b830eac61
@@ -0,0 +1,18 @@
+#!/bin/bash
+# test Intel TPEBS counting mode
+# SPDX-License-Identifier: GPL-2.0
+
+set e
+
+# Use this event for testing because it should exist in all platforms
+e=cache-misses:R
+
+# Without this cmd option, default value or zero is returned
+echo "Testing without --enable-tpebs-recording"
+result=$(perf stat -e "$e" true 2>&1)
+[[ "$result" =~ $e ]] || exit 1
+
+# In platforms that do not support TPEBS, it should execute without error.
+echo "Testing with --enable-tpebs-recording"
+result=$(perf stat -e "$e" --enable-tpebs-recording -a sleep 0.01 2>&1)
+[[ "$result" =~ "perf record" && "$result" =~ $e ]] || exit 1
Signature · 1 line
2.43.0
maintainer
#11 lore raw
In reply to [email protected]
Quoted 7 lines · On Mon, Jun 24, 2024 at 06:20:16PM -0400, [email protected] wrote:

From: Weilin Wang <[email protected]>

Changes in v14:
- Fix the python import test failure. We cannot support PYTHON_PERF because it will trigger a chain of dependency issues if we add intel-tpebs.c to it. So, only enable tpebs functions in evsel and evlist when PYTHON_PERF is not defined.

I think it's easier if we have Ian's python build cleanup first.

https://lore.kernel.org/linux-perf-users/[email protected]

Let me take a look at it..

Thanks,
Namhyung

Quoted 185 lines

- Fix shellcheck warning for the tpebs test.

Changes in v13:
- Add document for the command line option and fix build error in non-x86_64.
- Update example with non-zero retire_latency value when tpebs recording is enabled.
- Add tpebs_stop() back to tpebs_set_evsel() because in hybrid platform, when the forked perf record is not killed, the reader thread does not get any sampled data from the PIPE. As a result, tpebs_set_evesel() will always return zero on retire_latency values. This does not happen on my test GNR machine. Since -I is not supported yet, I think we should add tpebs_stop() to ensure correctness for now. More investigation is required here when we work on supporting -I mode.
- Rebase code on top of perf-tools-next.

Changes in v12:
- Update MTL metric JSON file to include E-Core TMA3.6 changes.
- Update comments and code for better code quality. Keep tpebs_start() and tpebs_delete() at evsel level for now and add comments on these functions with more details about potential future changes. Remove tpebs_stop() call from tpebs_set_evsel(). Simplify the tpebs_start() and tpebs_stop()/tpebs_delete() interfaces. Also fixed the bugs on not freed "new" pointer and the incorrect variable value assignment to val instead of counter->val.

Changes in v11:
- Make retire_latency evsels not opened for counting. This works correctly now with the code Namhyung suggested that adjusting group read size when retire_latency evsels included in the group.
- Update retire_latency value assignment using rint() to reduce precision loss while keeping code generic.
- Fix the build error caused by not used variable in the test.

Other changes in v10:
- Change perf record fork from perf stat to evsel. All the major operations like tpebs start, stop, read_evsel should directly work through evsel.
- Make intel-tpebs x86_64 only. This change is cross-compiled to arm64.
- Put tpebs code to intel-tepbs and simplify intel-tpebs APIs to minimum number
of functions and variables. Update funtion name and variable names to use consistent prefix. Also improve error handling.
- Integrate code patch from Ian for the :R parser.
- Update MTL metrics to TMA 4.8.

V9: https://lore.kernel.org/all/[email protected]/

Changes in v9:
- Update the retire_latency result print and metric calculation method. Plugin
the value to evsel so that no special code is required.
- Update --control:fifo to use pipe instead of named pipe.
- Add test for TPEBS counting mode.
- Update Document with more details.

Changes in v8:
- In this revision, the code is updated to base on Ian's patch on R modifier
parser https://lore.kernel.org/lkml/[email protected]/
After this change, there is no special code required for R modifier in metricgroup.c and metricgroup.h files.

Caveat of this change:
Ideally, we will need to add special handling to skip counting events with R
modifier in evsel. Currently, this is not implemented so the event with :R will be both counted and sampled. Usually, in a metric formula that uses retire_latency, it would already require to count the event. As a result, we will endup count the same event twice. This should be able to be handled properly when we finalize our design on evsel R modifier support.

- Move TPEBS specific code out from main perf stat code to separate files in
util/intel-tpebs.c and util/intel-tpebs.h. [Namhyung]
- Use --control:fifo to ack perf stat from forked perf record instead of sleep(2) [Namhyung]
- Add introductions about TPEBS and R modifier in Documents. [Namhyung]

Changes in v7:
- Update code and comments for better code quality [Namhyung]
- Add a separate commit for perf data [Namhyung]
- Update retire latency print function to improve alignment [Namhyung]

Changes in v6:
- Update code and add comments for better code quality [Namhyung]
- Remove the added fd var and directly pass the opened fd to data.file.fd [Namhyung]
- Add kill() to stop perf record when perf stat exists early [Namhyung]
- Add command opt check to ensure only start perf record when -a/-C given [Namhyung]
- Squash commits [Namhyung]

Changes in v5:
- Update code and add comments for better code quality [Ian]

Changes in v4:
- Remove uncessary debug print and update code and comments for better
readability and quality [Namhyung]
- Update mtl metric json file with consistent TmaL1 and TopdownL1 metricgroup

Changes in v3:
- Remove ':' when event name has '@' [Ian]
- Use 'R' as the modifier instead of "retire_latency" [Ian]

Changes in v2:
- Add MTL metric file
- Add more descriptions and example to the patch [Arnaldo]

Here is an example of running perf stat to collect a metric that uses retire_latency value of event MEM_INST_RETIRED.STLB_HIT_STORES on a MTL system.

In this simple example, there is no MEM_INST_RETIRED.STLB_HIT_STORES sample. Therefore, the MEM_INST_RETIRED.STLB_HIT_STORES:p count and retire_latency value are all 0.

./perf stat -M tma_dtlb_store -a -- sleep 1

[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.000 MB - ]

Performance counter stats for 'system wide':

       181,047,168      cpu_core/TOPDOWN.SLOTS/          #      0.6 %  tma_dtlb_store
         3,195,608      cpu_core/topdown-retiring/
        40,156,649      cpu_core/topdown-mem-bound/
         3,550,925      cpu_core/topdown-bad-spec/
       117,571,818      cpu_core/topdown-fe-bound/
        57,118,087      cpu_core/topdown-be-bound/
            69,179      cpu_core/EXE_ACTIVITY.BOUND_ON_STORES/
             4,582      cpu_core/MEM_INST_RETIRED.STLB_HIT_STORES/
        30,183,104      cpu_core/CPU_CLK_UNHALTED.DISTRIBUTED/
        30,556,790      cpu_core/CPU_CLK_UNHALTED.THREAD/
           168,486      cpu_core/DTLB_STORE_MISSES.WALK_ACTIVE/

0.00 MEM_INST_RETIRED.STLB_HIT_STORES:p 0 0

1.003105924 seconds time elapsed

v1:
TPEBS is one of the features provided by the next generation of Intel PMU. Please refer to Section 8.4.1 of "Intel® Architecture Instruction Set Extensions Programming Reference" [1] for more details about this feature.

This set of patches supports TPEBS in counting mode. The code works in the following way: it forks a perf record process from perf stat when retire_latency of one or more events are used in a metric formula. Perf stat would send a SIGTERM signal to perf record before it needs the retire latency value for metric calculation. Perf stat will then process sample data to extract the retire latency data for metric calculations. Currently, the code uses the arithmetic average of retire latency values.

[1] https://www.intel.com/content/www/us/en/content-details/812218/intel-architecture-instruction-set-extensions-programming-reference.html?wapkw=future%20features

Ian Rogers (1):
perf parse-events: Add a retirement latency modifier

Weilin Wang (7):
perf data: Allow to use given fd in data->file.fd
perf stat: Fork and launch perf record when perf stat needs to get
retire latency value for a metric.
perf stat: Plugin retire_lat value from sampled data to evsel perf vendor events intel: Add MTL metric json files perf stat: Add command line option for enabling tpebs recording perf Document: Add TPEBS to Documents
perf test: Add test for Intel TPEBS counting mode

 tools/perf/Documentation/perf-list.txt        |    1 +
 tools/perf/Documentation/perf-stat.txt        |    8 +
 tools/perf/Documentation/topdown.txt          |   30 +
 tools/perf/arch/x86/util/evlist.c             |    6 +
 tools/perf/builtin-stat.c                     |    8 +
 .../arch/x86/meteorlake/metricgroups.json     |  142 +
 .../arch/x86/meteorlake/mtl-metrics.json      | 2535 +++++++++++++++++
 .../perf/tests/shell/test_stat_intel_tpebs.sh |   18 +
 tools/perf/util/Build                         |    1 +
 tools/perf/util/data.c                        |    7 +-
 tools/perf/util/evlist.c                      |    4 +
 tools/perf/util/evsel.c                       |   91 +-
 tools/perf/util/evsel.h                       |    6 +
 tools/perf/util/intel-tpebs.c                 |  407 +++
 tools/perf/util/intel-tpebs.h                 |   35 +
 tools/perf/util/parse-events.c                |    2 +
 tools/perf/util/parse-events.h                |    1 +
 tools/perf/util/parse-events.l                |    3 +-
 18 files changed, 3301 insertions(+), 4 deletions(-)
 create mode 100644 tools/perf/pmu-events/arch/x86/meteorlake/metricgroups.json
 create mode 100644 tools/perf/pmu-events/arch/x86/meteorlake/mtl-metrics.json
 create mode 100755 tools/perf/tests/shell/test_stat_intel_tpebs.sh
 create mode 100644 tools/perf/util/intel-tpebs.c
 create mode 100644 tools/perf/util/intel-tpebs.h

--
2.43.0

#12 lore raw
Quoted 26 lines

-----Original Message-----
From: Namhyung Kim <[email protected]>
Sent: Wednesday, June 26, 2024 10:59 AM
To: Wang, Weilin <[email protected]>
Cc: Ian Rogers <[email protected]>; Arnaldo Carvalho de Melo <[email protected]>; Peter Zijlstra <[email protected]>; Ingo Molnar <[email protected]>; Alexander Shishkin <[email protected]>; Jiri Olsa <[email protected]>; Hunter, Adrian <[email protected]>; Kan Liang <[email protected]>; [email protected]; [email protected]; Taylor, Perry <[email protected]>; Alt, Samantha <[email protected]>; Biggers, Caleb <[email protected]>
Subject: Re: [RFC PATCH v14 0/8] TPEBS counting mode support

Quoted 4 lines · On Mon, Jun 24, 2024 at 06:20:16PM -0400, [email protected] wrote:

From: Weilin Wang <[email protected]>

Changes in v14:
- Fix the python import test failure. We cannot support PYTHON_PERF

because it

Quoted 3 lines

will trigger a chain of dependency issues if we add intel-tpebs.c to it. So, only enable tpebs functions in evsel and evlist when PYTHON_PERF is not defined.

Quoted 6 lines

I think it's easier if we have Ian's python build cleanup first.

https://lore.kernel.org/linux-perf-users/20240625214117.953777-1-
[email protected]

Let me take a look at it..

Ok, I will hold the cmd option name update until we conclude on this one. Thanks a lot!

Thanks,
Weilin

Quoted 219 lines

Thanks,
Namhyung

Quoted 4 lines

- Fix shellcheck warning for the tpebs test.

Changes in v13:
- Add document for the command line option and fix build error in non-

x86_64.

Quoted 1 line

- Update example with non-zero retire_latency value when tpebs recording

is

Quoted 2 lines

enabled.
- Add tpebs_stop() back to tpebs_set_evsel() because in hybrid platform,

when

Quoted 2 lines

the forked perf record is not killed, the reader thread does not get any sampled data from the PIPE. As a result, tpebs_set_evesel() will always

return

Quoted 1 line

zero on retire_latency values. This does not happen on my test GNR

machine.

Quoted 9 lines

Since -I is not supported yet, I think we should add tpebs_stop() to ensure correctness for now. More investigation is required here when we work on supporting -I mode.
- Rebase code on top of perf-tools-next.

Changes in v12:
- Update MTL metric JSON file to include E-Core TMA3.6 changes.
- Update comments and code for better code quality. Keep tpebs_start() and tpebs_delete() at evsel level for now and add comments on these functions

with

Quoted 2 lines

more details about potential future changes. Remove tpebs_stop() call from tpebs_set_evsel(). Simplify the tpebs_start() and

tpebs_stop()/tpebs_delete()

Quoted 5 lines

interfaces. Also fixed the bugs on not freed "new" pointer and the incorrect variable value assignment to val instead of counter->val.

Changes in v11:
- Make retire_latency evsels not opened for counting. This works correctly

now

Quoted 11 lines

with the code Namhyung suggested that adjusting group read size when retire_latency evsels included in the group.
- Update retire_latency value assignment using rint() to reduce precision loss while keeping code generic.
- Fix the build error caused by not used variable in the test.

Other changes in v10:
- Change perf record fork from perf stat to evsel. All the major operations like tpebs start, stop, read_evsel should directly work through evsel.
- Make intel-tpebs x86_64 only. This change is cross-compiled to arm64.
- Put tpebs code to intel-tepbs and simplify intel-tpebs APIs to minimum

number

Quoted 6 lines

of functions and variables. Update funtion name and variable names to use consistent prefix. Also improve error handling.
- Integrate code patch from Ian for the :R parser.
- Update MTL metrics to TMA 4.8.

V9: https://lore.kernel.org/all/20240521173952.3397644-1-

[email protected]/

Quoted 3 lines

Changes in v9:
- Update the retire_latency result print and metric calculation method.

Plugin

Quoted 8 lines

the value to evsel so that no special code is required.
- Update --control:fifo to use pipe instead of named pipe.
- Add test for TPEBS counting mode.
- Update Document with more details.

Changes in v8:
- In this revision, the code is updated to base on Ian's patch on R modifier
parser https://lore.kernel.org/lkml/20240428053616.1125891-3-

[email protected]/

Quoted 7 lines

After this change, there is no special code required for R modifier in metricgroup.c and metricgroup.h files.

Caveat of this change:
Ideally, we will need to add special handling to skip counting events with R
modifier in evsel. Currently, this is not implemented so the event with :R will be both counted and sampled. Usually, in a metric formula that uses

retire_latency,

Quoted 1 line

it would already require to count the event. As a result, we will endup count

the

Quoted 1 line

same event twice. This should be able to be handled properly when we

finalize our

Quoted 5 lines

design on evsel R modifier support.

- Move TPEBS specific code out from main perf stat code to separate files in
util/intel-tpebs.c and util/intel-tpebs.h. [Namhyung]
- Use --control:fifo to ack perf stat from forked perf record instead of

sleep(2) [Namhyung]

Quoted 11 lines

- Add introductions about TPEBS and R modifier in Documents. [Namhyung]

Changes in v7:
- Update code and comments for better code quality [Namhyung]
- Add a separate commit for perf data [Namhyung]
- Update retire latency print function to improve alignment [Namhyung]

Changes in v6:
- Update code and add comments for better code quality [Namhyung]
- Remove the added fd var and directly pass the opened fd to data.file.fd

[Namhyung]

Quoted 2 lines

- Add kill() to stop perf record when perf stat exists early [Namhyung]
- Add command opt check to ensure only start perf record when -a/-C given

[Namhyung]

Quoted 9 lines

- Squash commits [Namhyung]

Changes in v5:
- Update code and add comments for better code quality [Ian]

Changes in v4:
- Remove uncessary debug print and update code and comments for better
readability and quality [Namhyung]
- Update mtl metric json file with consistent TmaL1 and TopdownL1

metricgroup

Quoted 11 lines

Changes in v3:
- Remove ':' when event name has '@' [Ian]
- Use 'R' as the modifier instead of "retire_latency" [Ian]

Changes in v2:
- Add MTL metric file
- Add more descriptions and example to the patch [Arnaldo]

Here is an example of running perf stat to collect a metric that uses retire_latency value of event MEM_INST_RETIRED.STLB_HIT_STORES on a

MTL system.

Quoted 2 lines

In this simple example, there is no MEM_INST_RETIRED.STLB_HIT_STORES

sample.

Quoted 1 line

Therefore, the MEM_INST_RETIRED.STLB_HIT_STORES:p count and

retire_latency value

Quoted 10 lines

are all 0.

./perf stat -M tma_dtlb_store -a -- sleep 1

[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.000 MB - ]

Performance counter stats for 'system wide':

       181,047,168      cpu_core/TOPDOWN.SLOTS/          #      0.6 %

tma_dtlb_store

Quoted 10 lines
         3,195,608      cpu_core/topdown-retiring/
        40,156,649      cpu_core/topdown-mem-bound/
         3,550,925      cpu_core/topdown-bad-spec/
       117,571,818      cpu_core/topdown-fe-bound/
        57,118,087      cpu_core/topdown-be-bound/
            69,179      cpu_core/EXE_ACTIVITY.BOUND_ON_STORES/
             4,582      cpu_core/MEM_INST_RETIRED.STLB_HIT_STORES/
        30,183,104      cpu_core/CPU_CLK_UNHALTED.DISTRIBUTED/
        30,556,790      cpu_core/CPU_CLK_UNHALTED.THREAD/
           168,486      cpu_core/DTLB_STORE_MISSES.WALK_ACTIVE/
Quoted 7 lines

0.00 MEM_INST_RETIRED.STLB_HIT_STORES:p 0 0

1.003105924 seconds time elapsed

v1:
TPEBS is one of the features provided by the next generation of Intel PMU. Please refer to Section 8.4.1 of "Intel® Architecture Instruction Set

Extensions

Quoted 4 lines

Programming Reference" [1] for more details about this feature.

This set of patches supports TPEBS in counting mode. The code works in the following way: it forks a perf record process from perf stat when

retire_latency

Quoted 7 lines

of one or more events are used in a metric formula. Perf stat would send a SIGTERM signal to perf record before it needs the retire latency value for metric calculation. Perf stat will then process sample data to extract the retire latency data for metric calculations. Currently, the code uses the arithmetic average of retire latency values.

[1] https://www.intel.com/content/www/us/en/content-

details/812218/intel-architecture-instruction-set-extensions-programming- reference.html?wapkw=future%20features

Quoted 27 lines

Ian Rogers (1):
perf parse-events: Add a retirement latency modifier

Weilin Wang (7):
perf data: Allow to use given fd in data->file.fd
perf stat: Fork and launch perf record when perf stat needs to get
retire latency value for a metric.
perf stat: Plugin retire_lat value from sampled data to evsel perf vendor events intel: Add MTL metric json files perf stat: Add command line option for enabling tpebs recording perf Document: Add TPEBS to Documents
perf test: Add test for Intel TPEBS counting mode

 tools/perf/Documentation/perf-list.txt        |    1 +
 tools/perf/Documentation/perf-stat.txt        |    8 +
 tools/perf/Documentation/topdown.txt          |   30 +
 tools/perf/arch/x86/util/evlist.c             |    6 +
 tools/perf/builtin-stat.c                     |    8 +
 .../arch/x86/meteorlake/metricgroups.json     |  142 +
 .../arch/x86/meteorlake/mtl-metrics.json      | 2535 +++++++++++++++++
 .../perf/tests/shell/test_stat_intel_tpebs.sh |   18 +
 tools/perf/util/Build                         |    1 +
 tools/perf/util/data.c                        |    7 +-
 tools/perf/util/evlist.c                      |    4 +
 tools/perf/util/evsel.c                       |   91 +-
Quoted 8 lines
 tools/perf/util/evsel.h                       |    6 +
 tools/perf/util/intel-tpebs.c                 |  407 +++
 tools/perf/util/intel-tpebs.h                 |   35 +
 tools/perf/util/parse-events.c                |    2 +
 tools/perf/util/parse-events.h                |    1 +
 tools/perf/util/parse-events.l                |    3 +-
 18 files changed, 3301 insertions(+), 4 deletions(-)
 create mode 100644 tools/perf/pmu-

events/arch/x86/meteorlake/metricgroups.json

Quoted 1 line
 create mode 100644 tools/perf/pmu-events/arch/x86/meteorlake/mtl-

metrics.json

Quoted 7 lines
 create mode 100755 tools/perf/tests/shell/test_stat_intel_tpebs.sh
 create mode 100644 tools/perf/util/intel-tpebs.c
 create mode 100644 tools/perf/util/intel-tpebs.h

--
2.43.0

maintainer
#13 lore raw
Quoted 28 lines · Weilin
Quoted 28 lines

-----Original Message-----
From: Namhyung Kim <[email protected]>
Sent: Wednesday, June 26, 2024 10:59 AM
To: Wang, Weilin <[email protected]>
Cc: Ian Rogers <[email protected]>; Arnaldo Carvalho de Melo <[email protected]>; Peter Zijlstra <[email protected]>; Ingo Molnar <[email protected]>; Alexander Shishkin <[email protected]>; Jiri Olsa <[email protected]>; Hunter, Adrian <[email protected]>; Kan Liang <[email protected]>; [email protected]; [email protected]; Taylor, Perry <[email protected]>; Alt, Samantha <[email protected]>; Biggers, Caleb <[email protected]>
Subject: Re: [RFC PATCH v14 0/8] TPEBS counting mode support

Quoted 4 lines · On Mon, Jun 24, 2024 at 06:20:16PM -0400, [email protected] wrote:

From: Weilin Wang <[email protected]>

Changes in v14:
- Fix the python import test failure. We cannot support PYTHON_PERF

because it

Quoted 3 lines

will trigger a chain of dependency issues if we add intel-tpebs.c to it. So, only enable tpebs functions in evsel and evlist when PYTHON_PERF is not defined.

I think it's easier if we have Ian's python build cleanup first.

Quoted 7 lines
Quoted 4 lines

https://lore.kernel.org/linux-perf-users/20240625214117.953777-1-
[email protected]

Let me take a look at it..

Ok, I will hold the cmd option name update until we conclude on this one. Thanks a lot!

Please take a look at the current perf-tools-next branch.

Thanks,
Namhyung

#14 lore raw
Quoted 51 lines

-----Original Message-----
From: Namhyung Kim <[email protected]>
Sent: Thursday, June 27, 2024 1:32 PM
To: Wang, Weilin <[email protected]>
Cc: Ian Rogers <[email protected]>; Arnaldo Carvalho de Melo <[email protected]>; Peter Zijlstra <[email protected]>; Ingo Molnar <[email protected]>; Alexander Shishkin <[email protected]>; Jiri Olsa <[email protected]>; Hunter, Adrian <[email protected]>; Kan Liang <[email protected]>; [email protected]; [email protected]; Taylor, Perry <[email protected]>; Alt, Samantha <[email protected]>; Biggers, Caleb <[email protected]>
Subject: Re: [RFC PATCH v14 0/8] TPEBS counting mode support

Quoted 12 lines · Weilin
Quoted 12 lines

-----Original Message-----
From: Namhyung Kim <[email protected]>
Sent: Wednesday, June 26, 2024 10:59 AM
To: Wang, Weilin <[email protected]>
Cc: Ian Rogers <[email protected]>; Arnaldo Carvalho de Melo <[email protected]>; Peter Zijlstra <[email protected]>; Ingo Molnar <[email protected]>; Alexander Shishkin <[email protected]>; Jiri Olsa <[email protected]>; Hunter, Adrian <[email protected]>; Kan Liang <[email protected]>; [email protected]; [email protected]; Taylor,

Perry

Quoted 1 line
Quoted 1 line

<[email protected]>; Alt, Samantha <[email protected]>;

Biggers,

Quoted 4 lines
Quoted 4 lines

Caleb <[email protected]>
Subject: Re: [RFC PATCH v14 0/8] TPEBS counting mode support

On Mon, Jun 24, 2024 at 06:20:16PM -0400, [email protected]

Quoted 14 lines · wrote:
Quoted 14 lines
Quoted 4 lines

From: Weilin Wang <[email protected]>

Changes in v14:
- Fix the python import test failure. We cannot support PYTHON_PERF

because it

Quoted 3 lines

will trigger a chain of dependency issues if we add intel-tpebs.c to it. So, only enable tpebs functions in evsel and evlist when PYTHON_PERF is not defined.

I think it's easier if we have Ian's python build cleanup first.

https://lore.kernel.org/linux-perf-users/20240625214117.953777-1-
[email protected]

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Let me take a look at it..

Ok, I will hold the cmd option name update until we conclude on this one. Thanks a lot!

Please take a look at the current perf-tools-next branch.

Hi Namhyung,

The python import test works correctly with the latest perf-tools-next branch without the change I added in v14. I will send a new version that reverts this change and update the command line option. Is there any other changes you'd like me to add?

Thanks,
Weilin

Quoted 4 lines

Thanks,
Namhyung

#15 lore raw
Quoted 79 lines

-----Original Message-----
From: Wang, Weilin
Sent: Saturday, June 29, 2024 10:13 PM
To: Namhyung Kim <[email protected]>
Cc: Ian Rogers <[email protected]>; Arnaldo Carvalho de Melo <[email protected]>; Peter Zijlstra <[email protected]>; Ingo Molnar <[email protected]>; Alexander Shishkin <[email protected]>; Jiri Olsa <[email protected]>; Hunter, Adrian <[email protected]>; Kan Liang <[email protected]>; [email protected]; [email protected]; Taylor, Perry <[email protected]>; Alt, Samantha <[email protected]>; Biggers, Caleb <[email protected]>
Subject: RE: [RFC PATCH v14 0/8] TPEBS counting mode support

Quoted 11 lines

-----Original Message-----
From: Namhyung Kim <[email protected]>
Sent: Thursday, June 27, 2024 1:32 PM
To: Wang, Weilin <[email protected]>
Cc: Ian Rogers <[email protected]>; Arnaldo Carvalho de Melo <[email protected]>; Peter Zijlstra <[email protected]>; Ingo Molnar <[email protected]>; Alexander Shishkin <[email protected]>; Jiri Olsa <[email protected]>; Hunter, Adrian <[email protected]>; Kan Liang <[email protected]>; [email protected]; [email protected]; Taylor, Perry <[email protected]>; Alt, Samantha <[email protected]>;

Biggers,

Quoted 14 lines

Caleb <[email protected]>
Subject: Re: [RFC PATCH v14 0/8] TPEBS counting mode support

Quoted 10 lines · Weilin
Quoted 10 lines

-----Original Message-----
From: Namhyung Kim <[email protected]>
Sent: Wednesday, June 26, 2024 10:59 AM
To: Wang, Weilin <[email protected]>
Cc: Ian Rogers <[email protected]>; Arnaldo Carvalho de Melo <[email protected]>; Peter Zijlstra <[email protected]>; Ingo Molnar <[email protected]>; Alexander Shishkin <[email protected]>; Jiri Olsa <[email protected]>;

Hunter,

Quoted 1 line
Quoted 1 line
Quoted 1 line

Adrian <[email protected]>; Kan Liang

<[email protected]>;

Quoted 15 lines
Quoted 1 line
Quoted 1 line

[email protected]; [email protected]; Taylor,

Perry

Quoted 1 line
Quoted 1 line

<[email protected]>; Alt, Samantha <[email protected]>;

Biggers,

Quoted 4 lines
Quoted 4 lines

Caleb <[email protected]>
Subject: Re: [RFC PATCH v14 0/8] TPEBS counting mode support

On Mon, Jun 24, 2024 at 06:20:16PM -0400, [email protected]

Quoted 6 lines · wrote:
Quoted 6 lines
Quoted 4 lines

From: Weilin Wang <[email protected]>

Changes in v14:
- Fix the python import test failure. We cannot support PYTHON_PERF

because it

Quoted 1 line

will trigger a chain of dependency issues if we add intel-tpebs.c to it.

So,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

only enable tpebs functions in evsel and evlist when PYTHON_PERF is

not

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 1 line

defined.

I think it's easier if we have Ian's python build cleanup first.

https://lore.kernel.org/linux-perf-users/20240625214117.953777-1-
[email protected]

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Let me take a look at it..

Ok, I will hold the cmd option name update until we conclude on this one. Thanks a lot!

Please take a look at the current perf-tools-next branch.

Quoted 7 lines

Hi Namhyung,

The python import test works correctly with the latest perf-tools-next branch without the change I added in v14. I will send a new version that reverts this change and update the command line option. Is there any other changes you'd
like me to add?

Hi Namhyung,

I'm planning to submit the new version before Wednesday. Please let me know if you have any new comment on this.

Thanks,
Weilin

Quoted 8 lines

Thanks,
Weilin

Quoted 4 lines

Thanks,
Namhyung

maintainer
#16 lore raw

Hello Weilin,

Quoted 88 lines · Weilin
Quoted 80 lines

-----Original Message-----
From: Wang, Weilin
Sent: Saturday, June 29, 2024 10:13 PM
To: Namhyung Kim <[email protected]>
Cc: Ian Rogers <[email protected]>; Arnaldo Carvalho de Melo <[email protected]>; Peter Zijlstra <[email protected]>; Ingo Molnar <[email protected]>; Alexander Shishkin <[email protected]>; Jiri Olsa <[email protected]>; Hunter, Adrian <[email protected]>; Kan Liang <[email protected]>; [email protected]; [email protected]; Taylor, Perry <[email protected]>; Alt, Samantha <[email protected]>; Biggers, Caleb <[email protected]>
Subject: RE: [RFC PATCH v14 0/8] TPEBS counting mode support

Quoted 11 lines

-----Original Message-----
From: Namhyung Kim <[email protected]>
Sent: Thursday, June 27, 2024 1:32 PM
To: Wang, Weilin <[email protected]>
Cc: Ian Rogers <[email protected]>; Arnaldo Carvalho de Melo <[email protected]>; Peter Zijlstra <[email protected]>; Ingo Molnar <[email protected]>; Alexander Shishkin <[email protected]>; Jiri Olsa <[email protected]>; Hunter, Adrian <[email protected]>; Kan Liang <[email protected]>; [email protected]; [email protected]; Taylor, Perry <[email protected]>; Alt, Samantha <[email protected]>;

Biggers,

Quoted 14 lines

Caleb <[email protected]>
Subject: Re: [RFC PATCH v14 0/8] TPEBS counting mode support

Quoted 10 lines · Weilin
Quoted 10 lines

-----Original Message-----
From: Namhyung Kim <[email protected]>
Sent: Wednesday, June 26, 2024 10:59 AM
To: Wang, Weilin <[email protected]>
Cc: Ian Rogers <[email protected]>; Arnaldo Carvalho de Melo <[email protected]>; Peter Zijlstra <[email protected]>; Ingo Molnar <[email protected]>; Alexander Shishkin <[email protected]>; Jiri Olsa <[email protected]>;

Hunter,

Quoted 1 line
Quoted 1 line
Quoted 1 line

Adrian <[email protected]>; Kan Liang

<[email protected]>;

Quoted 15 lines
Quoted 1 line
Quoted 1 line

[email protected]; [email protected]; Taylor,

Perry

Quoted 1 line
Quoted 1 line

<[email protected]>; Alt, Samantha <[email protected]>;

Biggers,

Quoted 4 lines
Quoted 4 lines

Caleb <[email protected]>
Subject: Re: [RFC PATCH v14 0/8] TPEBS counting mode support

On Mon, Jun 24, 2024 at 06:20:16PM -0400, [email protected]

Quoted 6 lines · wrote:
Quoted 6 lines
Quoted 4 lines

From: Weilin Wang <[email protected]>

Changes in v14:
- Fix the python import test failure. We cannot support PYTHON_PERF

because it

Quoted 1 line

will trigger a chain of dependency issues if we add intel-tpebs.c to it.

So,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

only enable tpebs functions in evsel and evlist when PYTHON_PERF is

not

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 1 line

defined.

I think it's easier if we have Ian's python build cleanup first.

https://lore.kernel.org/linux-perf-users/20240625214117.953777-1-
[email protected]

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Let me take a look at it..

Ok, I will hold the cmd option name update until we conclude on this one. Thanks a lot!

Please take a look at the current perf-tools-next branch.

Quoted 7 lines

Hi Namhyung,

The python import test works correctly with the latest perf-tools-next branch without the change I added in v14. I will send a new version that reverts this change and update the command line option. Is there any other changes you'd
like me to add?

Quoted 4 lines

Hi Namhyung,

I'm planning to submit the new version before Wednesday. Please let me know if you have any new comment on this.

Yep, I think it's ok unless it introduces new test failures.

Thanks,
Namhyung