Skip to content

Commit 8636df9

Browse files
committed
Merge tag 'perf-tools-for-v6.1-2-2022-10-16' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux
Pull more perf tools updates from Arnaldo Carvalho de Melo: - Use BPF CO-RE (Compile Once, Run Everywhere) to support old kernels when using bperf (perf BPF based counters) with cgroups. - Support HiSilicon PCIe Performance Monitoring Unit (PMU), that monitors bandwidth, latency, bus utilization and buffer occupancy. Documented in Documentation/admin-guide/perf/hisi-pcie-pmu.rst. - User space tasks can migrate between CPUs, so when tracing selected CPUs, system-wide sideband is still needed, fix it in the setup of Intel PT on hybrid systems. - Fix metricgroups title message in 'perf list', it should state that the metrics groups are to be used with the '-M' option, not '-e'. - Sync the msr-index.h copy with the kernel sources, adding support for using "AMD64_TSC_RATIO" in filter expressions in 'perf trace' as well as decoding it when printing the MSR tracepoint arguments. - Fix program header size and alignment when generating a JIT ELF in 'perf inject'. - Add multiple new Intel PT 'perf test' entries, including a jitdump one. - Fix the 'perf test' entries for 'perf stat' CSV and JSON output when running on PowerPC due to an invalid topology number in that arch. - Fix the 'perf test' for arm_coresight failures on the ARM Juno system. - Fix the 'perf test' attr entry for PERF_FORMAT_LOST, adding this option to the or expression expected in the intercepted perf_event_open() syscall. - Add missing condition flags ('hs', 'lo', 'vc', 'vs') for arm64 in the 'perf annotate' asm parser. - Fix 'perf mem record -C' option processing, it was being chopped up when preparing the underlying 'perf record -e mem-events' and thus being ignored, requiring using '-- -C CPUs' as a workaround. - Improvements and tidy ups for 'perf test' shell infra. - Fix Intel PT information printing segfault in uClibc, where a NULL format was being passed to fprintf. * tag 'perf-tools-for-v6.1-2-2022-10-16' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux: (23 commits) tools arch x86: Sync the msr-index.h copy with the kernel sources perf auxtrace arm64: Add support for parsing HiSilicon PCIe Trace packet perf auxtrace arm64: Add support for HiSilicon PCIe Tune and Trace device driver perf auxtrace arm: Refactor event list iteration in auxtrace_record__init() perf tests stat+json_output: Include sanity check for topology perf tests stat+csv_output: Include sanity check for topology perf intel-pt: Fix system_wide dummy event for hybrid perf intel-pt: Fix segfault in intel_pt_print_info() with uClibc perf test: Fix attr tests for PERF_FORMAT_LOST perf test: test_intel_pt.sh: Add 9 tests perf inject: Fix GEN_ELF_TEXT_OFFSET for jit perf test: test_intel_pt.sh: Add jitdump test perf test: test_intel_pt.sh: Tidy some alignment perf test: test_intel_pt.sh: Print a message when skipping kernel tracing perf test: test_intel_pt.sh: Tidy some perf record options perf test: test_intel_pt.sh: Fix return checking again perf: Skip and warn on unknown format 'configN' attrs perf list: Fix metricgroups title message perf mem: Fix -C option behavior for perf mem record perf annotate: Add missing condition flags for arm64 ...
2 parents 2df7660 + a3a3656 commit 8636df9

36 files changed

+1265
-71
lines changed

tools/arch/x86/include/asm/msr-index.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@
155155
* Return Stack Buffer Predictions.
156156
*/
157157

158+
#define ARCH_CAP_XAPIC_DISABLE BIT(21) /*
159+
* IA32_XAPIC_DISABLE_STATUS MSR
160+
* supported
161+
*/
162+
158163
#define MSR_IA32_FLUSH_CMD 0x0000010b
159164
#define L1D_FLUSH BIT(0) /*
160165
* Writeback and invalidate the
@@ -585,6 +590,9 @@
585590
#define MSR_AMD64_PERF_CNTR_GLOBAL_CTL 0xc0000301
586591
#define MSR_AMD64_PERF_CNTR_GLOBAL_STATUS_CLR 0xc0000302
587592

593+
/* AMD Last Branch Record MSRs */
594+
#define MSR_AMD64_LBR_SELECT 0xc000010e
595+
588596
/* Fam 17h MSRs */
589597
#define MSR_F17H_IRPERF 0xc00000e9
590598

@@ -756,6 +764,8 @@
756764
#define MSR_AMD_DBG_EXTN_CFG 0xc000010f
757765
#define MSR_AMD_SAMP_BR_FROM 0xc0010300
758766

767+
#define DBG_EXTN_CFG_LBRV2EN BIT_ULL(6)
768+
759769
#define MSR_IA32_MPERF 0x000000e7
760770
#define MSR_IA32_APERF 0x000000e8
761771

@@ -1054,4 +1064,12 @@
10541064
#define MSR_IA32_HW_FEEDBACK_PTR 0x17d0
10551065
#define MSR_IA32_HW_FEEDBACK_CONFIG 0x17d1
10561066

1067+
/* x2APIC locked status */
1068+
#define MSR_IA32_XAPIC_DISABLE_STATUS 0xBD
1069+
#define LEGACY_XAPIC_DISABLED BIT(0) /*
1070+
* x2APIC mode is locked and
1071+
* disabling x2APIC will cause
1072+
* a #GP
1073+
*/
1074+
10571075
#endif /* _ASM_X86_MSR_INDEX_H */

tools/lib/perf/include/perf/event.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <linux/types.h>
77
#include <linux/limits.h>
88
#include <linux/bpf.h>
9-
#include <linux/compiler.h>
109
#include <sys/types.h> /* pid_t */
1110

1211
#define event_contains(obj, mem) ((obj).header.size > offsetof(typeof(obj), mem))
@@ -207,7 +206,7 @@ struct perf_record_range_cpu_map {
207206
__u16 end_cpu;
208207
};
209208

210-
struct __packed perf_record_cpu_map_data {
209+
struct perf_record_cpu_map_data {
211210
__u16 type;
212211
union {
213212
/* Used when type == PERF_CPU_MAP__CPUS. */
@@ -219,7 +218,7 @@ struct __packed perf_record_cpu_map_data {
219218
/* Used when type == PERF_CPU_MAP__RANGE_CPUS. */
220219
struct perf_record_range_cpu_map range_cpu_data;
221220
};
222-
};
221+
} __attribute__((packed));
223222

224223
#pragma GCC diagnostic pop
225224

tools/perf/arch/arm/util/auxtrace.c

Lines changed: 97 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@
44
* Author: Mathieu Poirier <[email protected]>
55
*/
66

7+
#include <dirent.h>
78
#include <stdbool.h>
89
#include <linux/coresight-pmu.h>
910
#include <linux/zalloc.h>
11+
#include <api/fs/fs.h>
1012

1113
#include "../../../util/auxtrace.h"
1214
#include "../../../util/debug.h"
1315
#include "../../../util/evlist.h"
1416
#include "../../../util/pmu.h"
1517
#include "cs-etm.h"
1618
#include "arm-spe.h"
19+
#include "hisi-ptt.h"
1720

1821
static struct perf_pmu **find_all_arm_spe_pmus(int *nr_spes, int *err)
1922
{
@@ -50,42 +53,114 @@ static struct perf_pmu **find_all_arm_spe_pmus(int *nr_spes, int *err)
5053
return arm_spe_pmus;
5154
}
5255

56+
static struct perf_pmu **find_all_hisi_ptt_pmus(int *nr_ptts, int *err)
57+
{
58+
const char *sysfs = sysfs__mountpoint();
59+
struct perf_pmu **hisi_ptt_pmus = NULL;
60+
struct dirent *dent;
61+
char path[PATH_MAX];
62+
DIR *dir = NULL;
63+
int idx = 0;
64+
65+
snprintf(path, PATH_MAX, "%s" EVENT_SOURCE_DEVICE_PATH, sysfs);
66+
dir = opendir(path);
67+
if (!dir) {
68+
pr_err("can't read directory '%s'\n", EVENT_SOURCE_DEVICE_PATH);
69+
*err = -EINVAL;
70+
return NULL;
71+
}
72+
73+
while ((dent = readdir(dir))) {
74+
if (strstr(dent->d_name, HISI_PTT_PMU_NAME))
75+
(*nr_ptts)++;
76+
}
77+
78+
if (!(*nr_ptts))
79+
goto out;
80+
81+
hisi_ptt_pmus = zalloc(sizeof(struct perf_pmu *) * (*nr_ptts));
82+
if (!hisi_ptt_pmus) {
83+
pr_err("hisi_ptt alloc failed\n");
84+
*err = -ENOMEM;
85+
goto out;
86+
}
87+
88+
rewinddir(dir);
89+
while ((dent = readdir(dir))) {
90+
if (strstr(dent->d_name, HISI_PTT_PMU_NAME) && idx < *nr_ptts) {
91+
hisi_ptt_pmus[idx] = perf_pmu__find(dent->d_name);
92+
if (hisi_ptt_pmus[idx])
93+
idx++;
94+
}
95+
}
96+
97+
out:
98+
closedir(dir);
99+
return hisi_ptt_pmus;
100+
}
101+
102+
static struct perf_pmu *find_pmu_for_event(struct perf_pmu **pmus,
103+
int pmu_nr, struct evsel *evsel)
104+
{
105+
int i;
106+
107+
if (!pmus)
108+
return NULL;
109+
110+
for (i = 0; i < pmu_nr; i++) {
111+
if (evsel->core.attr.type == pmus[i]->type)
112+
return pmus[i];
113+
}
114+
115+
return NULL;
116+
}
117+
53118
struct auxtrace_record
54119
*auxtrace_record__init(struct evlist *evlist, int *err)
55120
{
56-
struct perf_pmu *cs_etm_pmu;
121+
struct perf_pmu *cs_etm_pmu = NULL;
122+
struct perf_pmu **arm_spe_pmus = NULL;
123+
struct perf_pmu **hisi_ptt_pmus = NULL;
57124
struct evsel *evsel;
58-
bool found_etm = false;
125+
struct perf_pmu *found_etm = NULL;
59126
struct perf_pmu *found_spe = NULL;
60-
struct perf_pmu **arm_spe_pmus = NULL;
127+
struct perf_pmu *found_ptt = NULL;
128+
int auxtrace_event_cnt = 0;
61129
int nr_spes = 0;
62-
int i = 0;
130+
int nr_ptts = 0;
63131

64132
if (!evlist)
65133
return NULL;
66134

67135
cs_etm_pmu = perf_pmu__find(CORESIGHT_ETM_PMU_NAME);
68136
arm_spe_pmus = find_all_arm_spe_pmus(&nr_spes, err);
137+
hisi_ptt_pmus = find_all_hisi_ptt_pmus(&nr_ptts, err);
69138

70139
evlist__for_each_entry(evlist, evsel) {
71-
if (cs_etm_pmu &&
72-
evsel->core.attr.type == cs_etm_pmu->type)
73-
found_etm = true;
74-
75-
if (!nr_spes || found_spe)
76-
continue;
77-
78-
for (i = 0; i < nr_spes; i++) {
79-
if (evsel->core.attr.type == arm_spe_pmus[i]->type) {
80-
found_spe = arm_spe_pmus[i];
81-
break;
82-
}
83-
}
140+
if (cs_etm_pmu && !found_etm)
141+
found_etm = find_pmu_for_event(&cs_etm_pmu, 1, evsel);
142+
143+
if (arm_spe_pmus && !found_spe)
144+
found_spe = find_pmu_for_event(arm_spe_pmus, nr_spes, evsel);
145+
146+
if (hisi_ptt_pmus && !found_ptt)
147+
found_ptt = find_pmu_for_event(hisi_ptt_pmus, nr_ptts, evsel);
84148
}
149+
85150
free(arm_spe_pmus);
151+
free(hisi_ptt_pmus);
152+
153+
if (found_etm)
154+
auxtrace_event_cnt++;
86155

87-
if (found_etm && found_spe) {
88-
pr_err("Concurrent ARM Coresight ETM and SPE operation not currently supported\n");
156+
if (found_spe)
157+
auxtrace_event_cnt++;
158+
159+
if (found_ptt)
160+
auxtrace_event_cnt++;
161+
162+
if (auxtrace_event_cnt > 1) {
163+
pr_err("Concurrent AUX trace operation not currently supported\n");
89164
*err = -EOPNOTSUPP;
90165
return NULL;
91166
}
@@ -96,6 +171,9 @@ struct auxtrace_record
96171
#if defined(__aarch64__)
97172
if (found_spe)
98173
return arm_spe_recording_init(err, found_spe);
174+
175+
if (found_ptt)
176+
return hisi_ptt_recording_init(err, found_ptt);
99177
#endif
100178

101179
/*

tools/perf/arch/arm/util/pmu.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/string.h>
1111

1212
#include "arm-spe.h"
13+
#include "hisi-ptt.h"
1314
#include "../../../util/pmu.h"
1415

1516
struct perf_event_attr
@@ -22,6 +23,8 @@ struct perf_event_attr
2223
#if defined(__aarch64__)
2324
} else if (strstarts(pmu->name, ARM_SPE_PMU_NAME)) {
2425
return arm_spe_pmu_default_config(pmu);
26+
} else if (strstarts(pmu->name, HISI_PTT_PMU_NAME)) {
27+
pmu->selectable = true;
2528
#endif
2629
}
2730

tools/perf/arch/arm64/annotate/instructions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ static int arm64__annotate_init(struct arch *arch, char *cpuid __maybe_unused)
102102
if (err)
103103
goto out_free_arm;
104104
/* b, b.cond, br, cbz/cbnz, tbz/tbnz */
105-
err = regcomp(&arm->jump_insn, "^[ct]?br?\\.?(cc|cs|eq|ge|gt|hi|le|ls|lt|mi|ne|pl)?n?z?$",
105+
err = regcomp(&arm->jump_insn, "^[ct]?br?\\.?(cc|cs|eq|ge|gt|hi|hs|le|lo|ls|lt|mi|ne|pl|vc|vs)?n?z?$",
106106
REG_EXTENDED);
107107
if (err)
108108
goto out_free_call;

tools/perf/arch/arm64/util/Build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ perf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
1111
perf-$(CONFIG_AUXTRACE) += ../../arm/util/pmu.o \
1212
../../arm/util/auxtrace.o \
1313
../../arm/util/cs-etm.o \
14-
arm-spe.o mem-events.o
14+
arm-spe.o mem-events.o hisi-ptt.o

0 commit comments

Comments
 (0)