perf: Per-env PMUs, recorded event metrics, and perf sysinfo
[email protected]
AI reviewRe: [PATCH v1 39/41] perf sysinfo: Add sysinfo subcommand
In reply to Ian RogersThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] perf sysinfo: precise-only regs duplicated in print_pmu_json() - [Medium] perf sysinfo…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] perf sysinfo: precise-only regs duplicated in print_pmu_json()
- [Medium] perf sysinfo: cmd_sysinfo() collapses heterogeneous core PMUs
--
commit 137020466c84fe37ed29fa37c240863bb116831f
Author: Ian Rogers <[email protected]>
perf sysinfo: Add sysinfo subcommand
This commit adds the perf sysinfo subcommand to display and probe PMU and system performance monitoring capabilities on a running system or from a perf.data file, supporting both text and JSON output modes.
Quoted 6 lines
tools/perf/builtin-sysinfo.c new file +0
-0@@ -0,0 +1,2022 @@
[ ... ]
Quoted 19 lines
tools/perf/builtin-sysinfo.c new file +19
-0+static bool evsel_matches_pmu (const struct evsel *evsel, +const struct perf_pmu *pmu,bool show_all) +{ +struct perf_pmu *ev_pmu =evsel__find_pmu (evsel); +const char *ev_pmu_name; + +if (ev_pmu == pmu) +return true; + +if (ev_pmu) { +if (!show_all && !pmu->is_core && pmu->name && ev_pmu->name) { +size_t base_len =pmu_name_len_no_suffix (pmu->name); + +if (pmu_name_len_no_suffix (ev_pmu->name) == base_len && + !strncmp (pmu->name, ev_pmu->name, base_len)) +return true; + } +return false; + }
[ ... ]
Quoted 3 lines
tools/perf/builtin-sysinfo.c new file +3
-0+static void print_pmu_json (FILE *fp,const struct perf_pmu *pmu, +const struct perf_session *session,bool show_all) +{
[ ... ]
tools/perf/builtin-sysinfo.c line 783
Quoted 12 lines
tools/perf/builtin-sysinfo.c new file +12
-0+print_probed_regs (fp, &buf,"UserRegisters" , + p->user_regs_mask, p->user_regs_abi, + p->user_simd_mask, p->user_pred_mask, +/*intr=*/ false,/*json=*/ true); +print_probed_regs (fp, &buf,"IntrRegisters" , + p->intr_regs_mask, p->intr_regs_abi, + p->intr_simd_mask, p->intr_pred_mask, +/*intr=*/ true,/*json=*/ true); +print_probed_regs (fp, &buf,"IntrRegistersPreciseOnly" , + p->intr_regs_precise_mask, p->intr_regs_abi, + p->intr_simd_precise_mask, p->intr_pred_precise_mask, +/*intr=*/ true,/*json=*/ true);
[Severity: Medium]
In probe_pmu_regs_one() in tools/perf/util/pmu.c, when an interrupt register or SIMD/predicate register class can only be sampled with precise_ip > 0, its bit is set in both intr_regs_mask (or intr_simd_mask / intr_pred_mask) and intr_regs_precise_mask (or intr_simd_precise_mask / intr_pred_precise_mask).
In print_pmu_text(), the Intr registers output masks out the precise-only subsets before printing Intr registers (precise sampling only):
print_probed_regs(fp, NULL, "Intr registers", p->intr_regs_mask & ~p->intr_regs_precise_mask, p->intr_regs_abi, p->intr_simd_mask & ~p->intr_simd_precise_mask, p->intr_pred_mask & ~p->intr_pred_precise_mask, /*intr=*/true, /*json=*/false); print_probed_regs(fp, NULL, "Intr registers (precise sampling only)", p->intr_regs_precise_mask, p->intr_regs_abi, p->intr_simd_precise_mask, p->intr_pred_precise_mask, /*intr=*/true, /*json=*/false);
Should print_pmu_json() also mask out intr_regs_precise_mask, intr_simd_precise_mask, and intr_pred_precise_mask when emitting IntrRegisters, so that precise-only registers (such as x86 PEBS-only XMM registers) are not duplicated in both IntrRegisters and IntrRegistersPreciseOnly?
[ ... ]
Quoted 20 lines
tools/perf/builtin-sysinfo.c new file +20
-0+static void add_pmu_display_name (struct strlist *list,const struct perf_pmu *pmu) +{ +size_t num_inst =perf_pmu__num_duplicates (pmu); +char buf[128 ]; + +if (!pmu->name) +return ; +if (num_inst >1 ) { +size_t base_len =pmu_name_len_no_suffix (pmu->name); + +snprintf (buf,sizeof (buf),"%.*s" , (int )base_len, pmu->name); +strlist__add (list, buf); + }else { +strlist__add (list, pmu->name); + } +} + +static void print_system_summary (FILE *fp,const struct perf_session *session, +bool probed,bool leading_newline) +{
[ ... ]
Quoted 4 lines
tools/perf/builtin-sysinfo.c new file +4
-0+while ((pmu =perf_pmus__scan_skip_duplicates (pmus, pmu)) !=NULL ) { +size_t pmu_events, sysfs_ev, json_ev; + +pmu_event_counts (pmu, &pmu_events, &sysfs_ev, &json_ev);
[ ... ]
Quoted 2 lines
tools/perf/builtin-sysinfo.c new file +2
-0+int cmd_sysinfo (int argc,const char **argv) +{
[ ... ]
tools/perf/builtin-sysinfo.c line 1985
Quoted 4 lines
tools/perf/builtin-sysinfo.c new file +4
-0+while ((pmu = show_all ?perf_pmus__scan (pmus, pmu) : +perf_pmus__scan_skip_duplicates (pmus, pmu)) !=NULL ) { +if (!pmu_matches_filters (pmu, show_all, argc, argv)) +continue ;
[Severity: Medium]
On heterogeneous or big.LITTLE systems where distinct core PMUs share a base prefix before a decimal or 3+ hex-digit suffix (such as armv8_cortex_a53 and armv8_cortex_a57/a72, or armv8_pmuv3_0 and armv8_pmuv3_1), pmu_name_len_no_suffix() strips those suffixes and treats the core PMUs as duplicates.
When running without -v or -a, won't perf_pmus__scan_skip_duplicates() in cmd_sysinfo() and print_system_summary() skip all but the first core PMU, while perf_pmu__num_duplicates() in print_pmu_text(), print_pmu_json(), and add_pmu_display_name() strips the CPU suffix from the displayed core PMU name (reporting armv8_cortex or armv8_pmuv3) and counts the system as having only a single core PMU in the summary?
In addition, because evsel_matches_pmu() guards its prefix match with !pmu->is_core, recorded events belonging to the skipped core PMUs will not match the first core PMU either and will be omitted from Recorded events.
Should core PMUs be excluded from duplicate skipping and suffix stripping (similar to how pmu_deduped_name_len() in tools/perf/util/pmu.c handles pmu->is_core)?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=39
Ian Rogers
reviewerPATCH 40/41 perf docs: Add perf-sysinfo man page
In reply to Ian RogersDocument the 'perf sysinfo' subcommand and its options in Documentation/perf-sysinfo.txt and link it from Documentation/perf.txt.
--- tools/perf/Documentation/perf-sysinfo.txt | 113 ++++++++++++++++++++++ tools/perf/Documentation/perf.txt | 2 +- 2 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 tools/perf/Documentation/perf-sysinfo.txt
tools/perf/Documentation/perf-sysinfo.txt new file +113 -0
@@ -0,0 +1,113 @@ +perf-sysinfo(1) +=============== + +NAME +---- +perf-sysinfo - Display and probe PMU and system performance monitoring information + +SYNOPSIS +-------- +[verse] +'perf sysinfo' [<options>] [pmu_glob ...] + +DESCRIPTION +----------- +This command displays a summary of the performance monitoring capabilities of +the current system or a perf.data file, including core PMU features (precise +sampling, branch stack sampling, user-space counter reading, memory profiling, +and hardware AUX trace PMUs), memory and PCIe/IO interconnect bus bandwidth +monitoring support, total events and metrics, pipeline metric drill-down levels +discovered via '<metric>_group' hierarchies, and an overall system rating. + +When '-p'/'--pmus' is specified (or when PMU filter globs, '-v'/'--verbose', +'-a'/'--all', or '-j'/'--json' are given), it also displays detailed +information for each PMU, including its perf_event_attr type, kind (core, +uncore, software, auxtrace, tool, hwmon, drm), CPUs/cpumask, capabilities, +sysfs format bitfields, event counts, and memory profiling events. + +When run on a live system (without '-i'/'--input' and with probing enabled), +it also actively probes the kernel via 'perf_event_open' to determine: +- Supported modes (counting, interrupt-based sampling, branch_stack sampling) +- Supported precise sampling levels, skid semantics, and empirically measured + branch instruction skid (minimum, maximum, average instructions from the + branch and 'PERF_RECORD_MISC_EXACT_IP' ratio) at each supported precision + level: + 0 ('SAMPLE_IP' can have arbitrary skid), ':p' / 1 ('SAMPLE_IP' must have + constant skid), ':pp' / 2 ('SAMPLE_IP' requested to have 0 skid), and + ':ppp' / 3 ('SAMPLE_IP' must have 0 skid, or uses randomization to avoid + sample shadowing effects) +- Supported 'perf_event_sample_format' sample types ('ip', 'tid', 'time', + 'addr', 'read', 'callchain', 'id', 'cpu', 'period', 'stream_id', 'raw', + 'branch_stack', 'regs_user', 'stack_user', 'weight', 'data_src', + 'identifier', 'transaction', 'regs_intr', 'phys_addr', 'aux', 'cgroup', + 'data_page_size', 'code_page_size', 'weight_struct') +- Supported user and interrupt registers for 'PERF_SAMPLE_REGS_USER' and + 'PERF_SAMPLE_REGS_INTR', listing separately the interrupt registers that + can only be sampled with precise sampling (e.g. x86 XMM registers captured + by PEBS) +- Supported memory profiling events ('ldlat-loads', 'ldlat-stores', 'mem-ldst') + and their supported memory sample types ('data_src', 'addr', 'weight', etc.) +- Supported privilege/exclusion modifiers ('exclude_user', 'exclude_kernel', + 'exclude_hv', 'exclude_idle', 'exclude_host', 'exclude_guest') +- Supported execution features ('leader_sampling', 'sw_grouping', 'inherit', + 'sample_freq', 'write_backward', 'callchain', 'data_src', 'weight', + 'pinned', 'exclusive', 'format_lost', 'auto_counter_reload', + 'aux_start_paused', 'aux_pause', 'aux_resume', 'aux_sample', 'user_rdpmc', + 'user_time', 'user_time_zero', 'user_time_short') and hardware counter + bit-width ('pmc_width') when user-space counter reading is supported +- Maximum number of events in a group counted simultaneously, without + multiplexing, and for core PMUs the maximum number of general-purpose + counter events. Groups larger than this may be accepted by + 'perf_event_open' but can't be counted together + +At the end of the text output, a summary section reports overall core PMU +capabilities (including hardware AUX trace PMUs), memory and PCIe/IO +interconnect bus bandwidth monitoring support, total events and metrics, and +pipeline metric drill-down levels discovered via '<metric>_group' hierarchies. + +By default, numbered uncore PMU instances sharing a common prefix are collapsed +into a single entry showing the instance count, unless '-v'/'--verbose' is +specified. + +OPTIONS +------- +-i:: +--input=:: + Input file name to read PMU information from (e.g. perf.data). + +-f:: +--force:: + Don't complain, do it (when reading input perf.data file). + +-o:: +--output=:: + Output file name. + +-p:: +--pmus:: + Display detailed information for each PMU in addition to the system + summary. + +-j:: +--json:: + Encode PMU information as JSON. + +-a:: +--all:: +-v:: +--verbose:: + Display all PMUs including all similar PMUs with alphanumeric suffixes + instead of collapsing numbered uncore PMU instances. + +--probe:: +--no-probe:: + Enable or disable active kernel probing of PMU capabilities on the live + system (default: enabled). + +--debug:: + Enable debugging output. + +SEE ALSO +-------- +linkperf:perf-list[1], linkperf:perf-evlist[1], linkperf:perf-stat[1], +linkperf:perf-record[1]
tools/perf/Documentation/perf.txt +1 -1
@@ -92,5 +92,5 @@ linkperf:perf-help[1], linkperf:perf-inject[1], linkperf:perf-intel-pt[1], linkperf:perf-iostat[1], linkperf:perf-kallsyms[1], linkperf:perf-kmem[1], linkperf:perf-kvm[1], linkperf:perf-lock[1], linkperf:perf-mem[1], linkperf:perf-probe[1], linkperf:perf-sched[1], -linkperf:perf-script[1], linkperf:perf-test[1], +linkperf:perf-script[1], linkperf:perf-sysinfo[1], linkperf:perf-test[1], linkperf:perf-trace[1], linkperf:perf-version[1]
Signature · 1 line
2.56.0.385.gac671c819a-goog
[email protected]
AI reviewRe: [PATCH v1 40/41] perf docs: Add perf-sysinfo man page
Sashiko has reviewed this patch and found no issues.
Quoted 4 lines
Document the 'perf sysinfo' subcommand and its options in
Documentation/perf-sysinfo.txtand link it fromDocumentation/perf.txt.Signed-off-by Ian Rogers <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=40
Ian Rogers
reviewerPATCH 41/41 perf test: Add perf sysinfo shell test
In reply to Ian RogersAdd a shell test exercising default 'perf sysinfo' summary output, '--pmus' per-PMU output, '-j' JSON validation, PMU glob filtering, and '-i perf.data' inspection.
--- tools/perf/tests/shell/sysinfo.sh | 83 +++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100755 tools/perf/tests/shell/sysinfo.sh
tools/perf/tests/shell/sysinfo.sh new file +83 -0
@@ -0,0 +1,83 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# perf sysinfo tests + +set -e + +shelldir=$(dirname "$0") +. "${shelldir}"/lib/setup_python.sh + +sysinfo_output="" +perf_data="" + +cleanup() { + rm -f "${sysinfo_output}" "${perf_data}" ${perf_data:+"${perf_data}.old"} + trap - EXIT TERM INT +} + +trap_cleanup() { + cleanup + exit 1 +} +trap trap_cleanup EXIT TERM INT + +sysinfo_output=$(mktemp /tmp/__perf_test.sysinfo_output.XXXXX) +perf_data=$(mktemp /tmp/__perf_test.sysinfo.perf.data.XXXXX) + +test_sysinfo_default() { + echo "Default perf sysinfo output test" + perf sysinfo -o "${sysinfo_output}" + grep -q "^Summary:" "${sysinfo_output}" + grep -q "System rating:" "${sysinfo_output}" + perf sysinfo --pmus -o "${sysinfo_output}" + grep -q "^software (" "${sysinfo_output}" + grep -q "^Summary:" "${sysinfo_output}" + echo "Default perf sysinfo output test [Success]" +} + +test_sysinfo_json() { + echo "Json perf sysinfo output test" + perf sysinfo -j -o "${sysinfo_output}" + $PYTHON -m json.tool "${sysinfo_output}" /dev/null + echo "Json perf sysinfo output test [Success]" +} + +test_sysinfo_filter() { + echo "Filtered perf sysinfo output test" + perf sysinfo -o "${sysinfo_output}" software + grep -q "^software (" "${sysinfo_output}" + if grep -q "Modes:.*sampling" "${sysinfo_output}"; then + grep -q "Sample types:.*ip" "${sysinfo_output}" + if grep -q "Sample types:.*regs_user" "${sysinfo_output}"; then + grep -q "User registers:" "${sysinfo_output}" + fi + if grep -q "Sample types:.*regs_intr" "${sysinfo_output}"; then + grep -q "Intr registers:" "${sysinfo_output}" + fi + grep -q "Features:.*leader_sampling" "${sysinfo_output}" + grep -q "Features:.*sw_grouping" "${sysinfo_output}" + fi + echo "Filtered perf sysinfo output test [Success]" +} + +test_sysinfo_perf_data() { + echo "perf.data perf sysinfo test" + if ! perf record -e software/cpu-clock/u -o "${perf_data}" -- true 2>/dev/null; then + echo "perf.data perf sysinfo test [Skipped: perf record failed]" + return + fi + perf sysinfo -i "${perf_data}" -o "${sysinfo_output}" + grep -q "^Summary:" "${sysinfo_output}" + perf sysinfo --pmus -i "${perf_data}" -o "${sysinfo_output}" + grep -q "software" "${sysinfo_output}" + perf sysinfo -i "${perf_data}" -j -o "${sysinfo_output}" + $PYTHON -m json.tool "${sysinfo_output}" /dev/null + echo "perf.data perf sysinfo test [Success]" +} + +test_sysinfo_default +test_sysinfo_json +test_sysinfo_filter +test_sysinfo_perf_data +cleanup +exit 0
Signature · 1 line
2.56.0.385.gac671c819a-goog
[email protected]
AI reviewRe: [PATCH v1 41/41] perf test: Add perf sysinfo shell test
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] perf test: sysinfo.sh fails on archs without userspace perf_regs tables --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] perf test: sysinfo.sh fails on archs without userspace perf_regs tables --
commit a34e2e048e81b8c1a56a7440fb4b5a69103fb845
Author: Ian Rogers <[email protected]>
perf test: Add perf sysinfo shell test
This commit adds a shell test exercising default perf sysinfo summary output, --pmus per-PMU output, -j JSON validation, PMU glob filtering, and -i perf.data inspection.
Quoted 6 lines
tools/perf/tests/shell/sysinfo.sh new file +0
-0@@ -0,0 +1,83 @@
[ ... ]
tools/perf/tests/shell/sysinfo.sh line 56
Quoted 12 lines
tools/perf/tests/shell/sysinfo.sh new file +12
-0+test_sysinfo_filter() { + echo "Filtered perf sysinfo output test" + perf sysinfo -o "${sysinfo_output}" software + grep -q "^software (" "${sysinfo_output}" + if grep -q "Modes:.*sampling" "${sysinfo_output}"; then + grep -q "Sample types:.*ip" "${sysinfo_output}" + if grep -q "Sample types:.*regs_user" "${sysinfo_output}"; then + grep -q "User registers:" "${sysinfo_output}" + fi + if grep -q "Sample types:.*regs_intr" "${sysinfo_output}"; then + grep -q "Intr registers:" "${sysinfo_output}" + fi
[Severity: Medium]
Can test_sysinfo_filter() fail under set -e on architectures such as Alpha and PA-RISC where the kernel enables CONFIG_HAVE_PERF_REGS, but userspace tools/perf/util/perf_regs.c lacks register mask tables?
During PMU probing in tools/perf/util/pmu.c:probe_sample_types(), the probe falls back to bit 0 when perf_arch_reg_ip(EM_HOST) returns 0:
u64 reg_bit = BIT_ULL(perf_arch_reg_ip(EM_HOST)) ?: 1ULL;
On Alpha and PA-RISC, kernel perf_reg_validate() accepts bit 0, so PERF_SAMPLE_REGS_USER and PERF_SAMPLE_REGS_INTR succeed and print_pmu_text() outputs regs_user and regs_intr in the "Sample types:" line.
However, when tools/perf/util/pmu.c:probe_pmu_regs_one() queries the register masks:
u64 gpr_mask = intr ? perf_intr_reg_mask(EM_HOST, &dummy_abi) : perf_user_reg_mask(EM_HOST, &dummy_abi);
both perf_intr_reg_mask() and perf_user_reg_mask() in tools/perf/util/perf_regs.c return 0 for unhandled ELF machines like EM_ALPHA and EM_PARISC, leaving user_regs_mask and intr_regs_mask as 0. Then tools/perf/builtin-sysinfo.c:print_probed_regs() returns early without printing "User registers:" or "Intr registers:":
if (!mask && !simd_mask && !pred_mask) return;
Would this cause the inner grep checks for "User registers:" and "Intr registers:" in test_sysinfo_filter() to fail and abort the test on those architectures?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=41