All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] perf evsel amd: Fix IBS error message
@ 2023-06-26 10:39 Ravi Bangoria
  2023-06-26 10:42 ` Ravi Bangoria
  2023-06-26 23:04 ` Namhyung Kim
  0 siblings, 2 replies; 4+ messages in thread
From: Ravi Bangoria @ 2023-06-26 10:39 UTC (permalink / raw)
  To: acme
  Cc: ravi.bangoria, peterz, irogers, jolsa, namhyung, adrian.hunter,
	linux-perf-users, linux-kernel, sandipan.das, ananth.narayan,
	santosh.shukla

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 with
  exclude_{kernel|user|hv|idle|host|guest}=0.

Signed-off-by: Ravi Bangoria <ravi.bangoria@amd.com>
---
v1: https://lore.kernel.org/r/20230621062359.201-1-ravi.bangoria@amd.com
v1->v2:
  - Check all exclude_* flags not just exclude_kernel
  - Move AMD specific checks under tools/perf/arch/x86/

 tools/perf/arch/x86/util/evsel.c | 25 +++++++++++++++++++++++++
 tools/perf/util/evsel.c          | 30 +++++++++---------------------
 tools/perf/util/evsel.h          |  1 +
 3 files changed, 35 insertions(+), 21 deletions(-)

diff --git a/tools/perf/arch/x86/util/evsel.c b/tools/perf/arch/x86/util/evsel.c
index 512c2d885d24..9a7141c5a4ea 100644
--- a/tools/perf/arch/x86/util/evsel.c
+++ b/tools/perf/arch/x86/util/evsel.c
@@ -102,3 +102,28 @@ void arch__post_evsel_config(struct evsel *evsel, struct perf_event_attr *attr)
 		}
 	}
 }
+
+int arch_evsel__open_strerror(struct evsel *evsel, char *msg, size_t size)
+{
+	if (!x86__is_amd_cpu())
+		return 0;
+
+	if (!evsel->core.attr.precise_ip &&
+	    !(evsel->pmu_name && !strncmp(evsel->pmu_name, "ibs", 3)))
+		return 0;
+
+	/* More verbose IBS errors. */
+	if (evsel->core.attr.exclude_kernel || evsel->core.attr.exclude_user ||
+	    evsel->core.attr.exclude_hv || evsel->core.attr.exclude_idle ||
+	    evsel->core.attr.exclude_host || evsel->core.attr.exclude_guest) {
+		return scnprintf(msg, size, "AMD IBS doesn't support privilege filtering. Try "
+				 "again with exclude_{kernel|user|hv|idle|host|guest}=0.");
+	}
+
+	if (!evsel->core.attr.sample_period) {
+		return scnprintf(msg, size, "AMD IBS doesn't support counting mode. Try "
+				 "again with sample_{period|freq} with non-zero value.");
+	}
+
+	return 0;
+}
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index f607b5bddc76..762e2b2634a5 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -2924,25 +2924,19 @@ static bool find_process(const char *name)
 	return ret ? false : true;
 }
 
-static bool is_amd(const char *arch, const char *cpuid)
+int __weak arch_evsel__open_strerror(struct evsel *evsel __maybe_unused,
+				     char *msg __maybe_unused,
+				     size_t size __maybe_unused)
 {
-	return arch && !strcmp("x86", arch) && cpuid && strstarts(cpuid, "AuthenticAMD");
-}
-
-static bool is_amd_ibs(struct evsel *evsel)
-{
-	return evsel->core.attr.precise_ip
-	    || (evsel->pmu_name && !strncmp(evsel->pmu_name, "ibs", 3));
+	return 0;
 }
 
 int evsel__open_strerror(struct evsel *evsel, struct target *target,
 			 int err, char *msg, size_t size)
 {
-	struct perf_env *env = evsel__env(evsel);
-	const char *arch = perf_env__arch(env);
-	const char *cpuid = perf_env__cpuid(env);
 	char sbuf[STRERR_BUFSIZE];
 	int printed = 0, enforced = 0;
+	int ret;
 
 	switch (err) {
 	case EPERM:
@@ -3044,16 +3038,6 @@ int evsel__open_strerror(struct evsel *evsel, struct target *target,
 			return scnprintf(msg, size,
 	"Invalid event (%s) in per-thread mode, enable system wide with '-a'.",
 					evsel__name(evsel));
-		if (is_amd(arch, cpuid)) {
-			if (is_amd_ibs(evsel)) {
-				if (evsel->core.attr.exclude_kernel)
-					return scnprintf(msg, size,
-	"AMD IBS can't exclude kernel events.  Try running at a higher privilege level.");
-				if (!evsel->core.system_wide)
-					return scnprintf(msg, size,
-	"AMD IBS may only be available in system-wide/per-cpu mode.  Try using -a, or -C and workload affinity");
-			}
-		}
 
 		break;
 	case ENODATA:
@@ -3063,6 +3047,10 @@ int evsel__open_strerror(struct evsel *evsel, struct target *target,
 		break;
 	}
 
+	ret = arch_evsel__open_strerror(evsel, msg, size);
+	if (ret)
+		return ret;
+
 	return scnprintf(msg, size,
 	"The sys_perf_event_open() syscall returned with %d (%s) for event (%s).\n"
 	"/bin/dmesg | grep -i perf may provide additional information.\n",
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 9f06d6cd5379..848534ec74fa 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -311,6 +311,7 @@ void evsel__set_sample_id(struct evsel *evsel, bool use_sample_identifier);
 
 void arch_evsel__set_sample_weight(struct evsel *evsel);
 void arch__post_evsel_config(struct evsel *evsel, struct perf_event_attr *attr);
+int arch_evsel__open_strerror(struct evsel *evsel, char *msg, size_t size);
 
 int evsel__set_filter(struct evsel *evsel, const char *filter);
 int evsel__append_tp_filter(struct evsel *evsel, const char *filter);
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] perf evsel amd: Fix IBS error message
  2023-06-26 10:39 [PATCH v2] perf evsel amd: Fix IBS error message Ravi Bangoria
@ 2023-06-26 10:42 ` Ravi Bangoria
  2023-06-26 23:04 ` Namhyung Kim
  1 sibling, 0 replies; 4+ messages in thread
From: Ravi Bangoria @ 2023-06-26 10:42 UTC (permalink / raw)
  To: acme
  Cc: peterz, irogers, jolsa, namhyung, adrian.hunter,
	linux-perf-users, linux-kernel, sandipan.das, ananth.narayan,
	santosh.shukla, Ravi Bangoria

On 26-Jun-23 4:09 PM, Ravi Bangoria wrote:
> 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 with
>   exclude_{kernel|user|hv|idle|host|guest}=0.

[1] https://git.kernel.org/torvalds/c/30093056f7b2

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] perf evsel amd: Fix IBS error message
  2023-06-26 10:39 [PATCH v2] perf evsel amd: Fix IBS error message Ravi Bangoria
  2023-06-26 10:42 ` Ravi Bangoria
@ 2023-06-26 23:04 ` Namhyung Kim
  2023-06-28  4:49   ` Ravi Bangoria
  1 sibling, 1 reply; 4+ messages in thread
From: Namhyung Kim @ 2023-06-26 23:04 UTC (permalink / raw)
  To: Ravi Bangoria
  Cc: acme, peterz, irogers, jolsa, adrian.hunter, linux-perf-users,
	linux-kernel, sandipan.das, ananth.narayan, santosh.shukla

Hi Ravi,

On Mon, Jun 26, 2023 at 3:40 AM Ravi Bangoria <ravi.bangoria@amd.com> wrote:
>
> 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 with
>   exclude_{kernel|user|hv|idle|host|guest}=0.

Can we have more user-friendly messages like below?

 "Try again without the privilege modifiers like 'k' at the end."

>
> Signed-off-by: Ravi Bangoria <ravi.bangoria@amd.com>
> ---
> v1: https://lore.kernel.org/r/20230621062359.201-1-ravi.bangoria@amd.com
> v1->v2:
>   - Check all exclude_* flags not just exclude_kernel
>   - Move AMD specific checks under tools/perf/arch/x86/
>
>  tools/perf/arch/x86/util/evsel.c | 25 +++++++++++++++++++++++++
>  tools/perf/util/evsel.c          | 30 +++++++++---------------------
>  tools/perf/util/evsel.h          |  1 +
>  3 files changed, 35 insertions(+), 21 deletions(-)
>
> diff --git a/tools/perf/arch/x86/util/evsel.c b/tools/perf/arch/x86/util/evsel.c
> index 512c2d885d24..9a7141c5a4ea 100644
> --- a/tools/perf/arch/x86/util/evsel.c
> +++ b/tools/perf/arch/x86/util/evsel.c
> @@ -102,3 +102,28 @@ void arch__post_evsel_config(struct evsel *evsel, struct perf_event_attr *attr)
>                 }
>         }
>  }
> +
> +int arch_evsel__open_strerror(struct evsel *evsel, char *msg, size_t size)
> +{
> +       if (!x86__is_amd_cpu())
> +               return 0;
> +
> +       if (!evsel->core.attr.precise_ip &&
> +           !(evsel->pmu_name && !strncmp(evsel->pmu_name, "ibs", 3)))
> +               return 0;
> +
> +       /* More verbose IBS errors. */
> +       if (evsel->core.attr.exclude_kernel || evsel->core.attr.exclude_user ||
> +           evsel->core.attr.exclude_hv || evsel->core.attr.exclude_idle ||
> +           evsel->core.attr.exclude_host || evsel->core.attr.exclude_guest) {
> +               return scnprintf(msg, size, "AMD IBS doesn't support privilege filtering. Try "
> +                                "again with exclude_{kernel|user|hv|idle|host|guest}=0.");
> +       }
> +
> +       if (!evsel->core.attr.sample_period) {
> +               return scnprintf(msg, size, "AMD IBS doesn't support counting mode. Try "
> +                                "again with sample_{period|freq} with non-zero value.");

Is this for perf stat?   We don't allow zero period for perf record.

  $ perf record -F 0 true
  frequency and count are zero, aborting

Then maybe it can say: "IBS doesn't support perf stat, Use perf record."

Thanks,
Namhyung


> +       }
> +
> +       return 0;
> +}
> diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
> index f607b5bddc76..762e2b2634a5 100644
> --- a/tools/perf/util/evsel.c
> +++ b/tools/perf/util/evsel.c
> @@ -2924,25 +2924,19 @@ static bool find_process(const char *name)
>         return ret ? false : true;
>  }
>
> -static bool is_amd(const char *arch, const char *cpuid)
> +int __weak arch_evsel__open_strerror(struct evsel *evsel __maybe_unused,
> +                                    char *msg __maybe_unused,
> +                                    size_t size __maybe_unused)
>  {
> -       return arch && !strcmp("x86", arch) && cpuid && strstarts(cpuid, "AuthenticAMD");
> -}
> -
> -static bool is_amd_ibs(struct evsel *evsel)
> -{
> -       return evsel->core.attr.precise_ip
> -           || (evsel->pmu_name && !strncmp(evsel->pmu_name, "ibs", 3));
> +       return 0;
>  }
>
>  int evsel__open_strerror(struct evsel *evsel, struct target *target,
>                          int err, char *msg, size_t size)
>  {
> -       struct perf_env *env = evsel__env(evsel);
> -       const char *arch = perf_env__arch(env);
> -       const char *cpuid = perf_env__cpuid(env);
>         char sbuf[STRERR_BUFSIZE];
>         int printed = 0, enforced = 0;
> +       int ret;
>
>         switch (err) {
>         case EPERM:
> @@ -3044,16 +3038,6 @@ int evsel__open_strerror(struct evsel *evsel, struct target *target,
>                         return scnprintf(msg, size,
>         "Invalid event (%s) in per-thread mode, enable system wide with '-a'.",
>                                         evsel__name(evsel));
> -               if (is_amd(arch, cpuid)) {
> -                       if (is_amd_ibs(evsel)) {
> -                               if (evsel->core.attr.exclude_kernel)
> -                                       return scnprintf(msg, size,
> -       "AMD IBS can't exclude kernel events.  Try running at a higher privilege level.");
> -                               if (!evsel->core.system_wide)
> -                                       return scnprintf(msg, size,
> -       "AMD IBS may only be available in system-wide/per-cpu mode.  Try using -a, or -C and workload affinity");
> -                       }
> -               }
>
>                 break;
>         case ENODATA:
> @@ -3063,6 +3047,10 @@ int evsel__open_strerror(struct evsel *evsel, struct target *target,
>                 break;
>         }
>
> +       ret = arch_evsel__open_strerror(evsel, msg, size);
> +       if (ret)
> +               return ret;
> +
>         return scnprintf(msg, size,
>         "The sys_perf_event_open() syscall returned with %d (%s) for event (%s).\n"
>         "/bin/dmesg | grep -i perf may provide additional information.\n",
> diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
> index 9f06d6cd5379..848534ec74fa 100644
> --- a/tools/perf/util/evsel.h
> +++ b/tools/perf/util/evsel.h
> @@ -311,6 +311,7 @@ void evsel__set_sample_id(struct evsel *evsel, bool use_sample_identifier);
>
>  void arch_evsel__set_sample_weight(struct evsel *evsel);
>  void arch__post_evsel_config(struct evsel *evsel, struct perf_event_attr *attr);
> +int arch_evsel__open_strerror(struct evsel *evsel, char *msg, size_t size);
>
>  int evsel__set_filter(struct evsel *evsel, const char *filter);
>  int evsel__append_tp_filter(struct evsel *evsel, const char *filter);
> --
> 2.41.0
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] perf evsel amd: Fix IBS error message
  2023-06-26 23:04 ` Namhyung Kim
@ 2023-06-28  4:49   ` Ravi Bangoria
  0 siblings, 0 replies; 4+ messages in thread
From: Ravi Bangoria @ 2023-06-28  4:49 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: acme, peterz, irogers, jolsa, adrian.hunter, linux-perf-users,
	linux-kernel, sandipan.das, ananth.narayan, santosh.shukla,
	Ravi Bangoria

On 27-Jun-23 4:34 AM, Namhyung Kim wrote:
> Hi Ravi,
> 
> On Mon, Jun 26, 2023 at 3:40 AM Ravi Bangoria <ravi.bangoria@amd.com> wrote:
>>
>> 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 with
>>   exclude_{kernel|user|hv|idle|host|guest}=0.
> 
> Can we have more user-friendly messages like below?
> 
>  "Try again without the privilege modifiers like 'k' at the end."
Sure.

> 
>>
>> Signed-off-by: Ravi Bangoria <ravi.bangoria@amd.com>
>> ---
>> v1: https://lore.kernel.org/r/20230621062359.201-1-ravi.bangoria@amd.com
>> v1->v2:
>>   - Check all exclude_* flags not just exclude_kernel
>>   - Move AMD specific checks under tools/perf/arch/x86/
>>
>>  tools/perf/arch/x86/util/evsel.c | 25 +++++++++++++++++++++++++
>>  tools/perf/util/evsel.c          | 30 +++++++++---------------------
>>  tools/perf/util/evsel.h          |  1 +
>>  3 files changed, 35 insertions(+), 21 deletions(-)
>>
>> diff --git a/tools/perf/arch/x86/util/evsel.c b/tools/perf/arch/x86/util/evsel.c
>> index 512c2d885d24..9a7141c5a4ea 100644
>> --- a/tools/perf/arch/x86/util/evsel.c
>> +++ b/tools/perf/arch/x86/util/evsel.c
>> @@ -102,3 +102,28 @@ void arch__post_evsel_config(struct evsel *evsel, struct perf_event_attr *attr)
>>                 }
>>         }
>>  }
>> +
>> +int arch_evsel__open_strerror(struct evsel *evsel, char *msg, size_t size)
>> +{
>> +       if (!x86__is_amd_cpu())
>> +               return 0;
>> +
>> +       if (!evsel->core.attr.precise_ip &&
>> +           !(evsel->pmu_name && !strncmp(evsel->pmu_name, "ibs", 3)))
>> +               return 0;
>> +
>> +       /* More verbose IBS errors. */
>> +       if (evsel->core.attr.exclude_kernel || evsel->core.attr.exclude_user ||
>> +           evsel->core.attr.exclude_hv || evsel->core.attr.exclude_idle ||
>> +           evsel->core.attr.exclude_host || evsel->core.attr.exclude_guest) {
>> +               return scnprintf(msg, size, "AMD IBS doesn't support privilege filtering. Try "
>> +                                "again with exclude_{kernel|user|hv|idle|host|guest}=0.");
>> +       }
>> +
>> +       if (!evsel->core.attr.sample_period) {
>> +               return scnprintf(msg, size, "AMD IBS doesn't support counting mode. Try "
>> +                                "again with sample_{period|freq} with non-zero value.");
> 
> Is this for perf stat?   We don't allow zero period for perf record.
> 
>   $ perf record -F 0 true
>   frequency and count are zero, aborting
> 
> Then maybe it can say: "IBS doesn't support perf stat, Use perf record."

Ok. Let me skip this since generic code is already covering it.

Thanks,
Ravi

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-06-28  7:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-26 10:39 [PATCH v2] perf evsel amd: Fix IBS error message Ravi Bangoria
2023-06-26 10:42 ` Ravi Bangoria
2023-06-26 23:04 ` Namhyung Kim
2023-06-28  4:49   ` Ravi Bangoria

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.