Skip to content

Commit b2ad954

Browse files
Ravi Bangorianamhyung
authored andcommitted
perf evsel amd: Fix IBS error message
AMD IBS can do per-process profiling[1] and is no longer restricted to per-cpu or systemwide only. Remove stale error message. Also, checking just exclude_kernel is not sufficient since IBS does not support any privilege filters. So include all exclude_* checks. And finally, move these checks under tools/perf/arch/x86/ from generic code. Before: $ sudo ./perf record -e ibs_op//k -C 0 Error: AMD IBS may only be available in system-wide/per-cpu mode. Try using -a, or -C and workload affinity After: $ sudo ./perf record -e ibs_op//k -C 0 Error: AMD IBS doesn't support privilege filtering. Try again without the privilege modifiers (like 'k') at the end. [1] https://git.kernel.org/torvalds/c/30093056f7b2 Signed-off-by: Ravi Bangoria <[email protected]> Acked-by: Namhyung Kim <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]>
1 parent 5f06267 commit b2ad954

File tree

3 files changed

+30
-21
lines changed

3 files changed

+30
-21
lines changed

tools/perf/arch/x86/util/evsel.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,23 @@ void arch__post_evsel_config(struct evsel *evsel, struct perf_event_attr *attr)
102102
}
103103
}
104104
}
105+
106+
int arch_evsel__open_strerror(struct evsel *evsel, char *msg, size_t size)
107+
{
108+
if (!x86__is_amd_cpu())
109+
return 0;
110+
111+
if (!evsel->core.attr.precise_ip &&
112+
!(evsel->pmu_name && !strncmp(evsel->pmu_name, "ibs", 3)))
113+
return 0;
114+
115+
/* More verbose IBS errors. */
116+
if (evsel->core.attr.exclude_kernel || evsel->core.attr.exclude_user ||
117+
evsel->core.attr.exclude_hv || evsel->core.attr.exclude_idle ||
118+
evsel->core.attr.exclude_host || evsel->core.attr.exclude_guest) {
119+
return scnprintf(msg, size, "AMD IBS doesn't support privilege filtering. Try "
120+
"again without the privilege modifiers (like 'k') at the end.");
121+
}
122+
123+
return 0;
124+
}

tools/perf/util/evsel.c

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2924,25 +2924,19 @@ static bool find_process(const char *name)
29242924
return ret ? false : true;
29252925
}
29262926

2927-
static bool is_amd(const char *arch, const char *cpuid)
2927+
int __weak arch_evsel__open_strerror(struct evsel *evsel __maybe_unused,
2928+
char *msg __maybe_unused,
2929+
size_t size __maybe_unused)
29282930
{
2929-
return arch && !strcmp("x86", arch) && cpuid && strstarts(cpuid, "AuthenticAMD");
2930-
}
2931-
2932-
static bool is_amd_ibs(struct evsel *evsel)
2933-
{
2934-
return evsel->core.attr.precise_ip
2935-
|| (evsel->pmu_name && !strncmp(evsel->pmu_name, "ibs", 3));
2931+
return 0;
29362932
}
29372933

29382934
int evsel__open_strerror(struct evsel *evsel, struct target *target,
29392935
int err, char *msg, size_t size)
29402936
{
2941-
struct perf_env *env = evsel__env(evsel);
2942-
const char *arch = perf_env__arch(env);
2943-
const char *cpuid = perf_env__cpuid(env);
29442937
char sbuf[STRERR_BUFSIZE];
29452938
int printed = 0, enforced = 0;
2939+
int ret;
29462940

29472941
switch (err) {
29482942
case EPERM:
@@ -3044,16 +3038,6 @@ int evsel__open_strerror(struct evsel *evsel, struct target *target,
30443038
return scnprintf(msg, size,
30453039
"Invalid event (%s) in per-thread mode, enable system wide with '-a'.",
30463040
evsel__name(evsel));
3047-
if (is_amd(arch, cpuid)) {
3048-
if (is_amd_ibs(evsel)) {
3049-
if (evsel->core.attr.exclude_kernel)
3050-
return scnprintf(msg, size,
3051-
"AMD IBS can't exclude kernel events. Try running at a higher privilege level.");
3052-
if (!evsel->core.system_wide)
3053-
return scnprintf(msg, size,
3054-
"AMD IBS may only be available in system-wide/per-cpu mode. Try using -a, or -C and workload affinity");
3055-
}
3056-
}
30573041

30583042
break;
30593043
case ENODATA:
@@ -3063,6 +3047,10 @@ int evsel__open_strerror(struct evsel *evsel, struct target *target,
30633047
break;
30643048
}
30653049

3050+
ret = arch_evsel__open_strerror(evsel, msg, size);
3051+
if (ret)
3052+
return ret;
3053+
30663054
return scnprintf(msg, size,
30673055
"The sys_perf_event_open() syscall returned with %d (%s) for event (%s).\n"
30683056
"/bin/dmesg | grep -i perf may provide additional information.\n",

tools/perf/util/evsel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ void evsel__set_sample_id(struct evsel *evsel, bool use_sample_identifier);
311311

312312
void arch_evsel__set_sample_weight(struct evsel *evsel);
313313
void arch__post_evsel_config(struct evsel *evsel, struct perf_event_attr *attr);
314+
int arch_evsel__open_strerror(struct evsel *evsel, char *msg, size_t size);
314315

315316
int evsel__set_filter(struct evsel *evsel, const char *filter);
316317
int evsel__append_tp_filter(struct evsel *evsel, const char *filter);

0 commit comments

Comments
 (0)