Skip to contentSkip to conversation

perf stat: force error in fallback on :k events

PATCH Superseded Ian Rogers 2 participants 5 messages Apr 13, 2020 – Apr 14, 2020 perf events

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

PATCH 1/1 perf stat: force error in fallback on :k events

From: Stephane Eranian <[email protected]>

When it is not possible for a non-privilege perf command to monitor at the kernel level (:k), the fallback code forces a :u. That works if the event was previously monitoring both levels. But if the event was already constrained to kernel only, then it does not make sense to restrict it to user only.
Given the code works by exclusion, a kernel only event would have:
attr->exclude_user = 1
The fallback code would add:
attr->exclude_kernel = 1;

In the end the end would not monitor in either the user level or kernel level. In other words, it would count nothing.

An event programmed to monitor kernel only cannot be switched to user only without seriously warning the user.

This patch forces an error in this case to make it clear the request cannot really be satisfied.

---
 tools/perf/util/evsel.c | 7 +++++++
 1 file changed, 7 insertions(+)
tools/perf/util/evsel.c +7 -0
index d23db6755f51..d1e8862b86ce 100644
@@ -2446,6 +2446,13 @@ bool perf_evsel__fallback(struct evsel *evsel, int err,
 		char *new_name;
 		const char *sep = ":";
 
+		if (evsel->core.attr.exclude_user) {
+			scnprintf(msg, msgsize,
+"kernel.perf_event_paranoid=%d, event set to exclude user, so cannot also exclude kernel",
+				paranoid);
+			return false;
+		}
+
 		/* Is there already the separator in the name. */
 		if (strchr(name, '/') ||
 		    strchr(name, ':'))
Signature · 1 line
2.26.0.110.g2183baf09c-goog
#1 lore raw
Quoted 32 lines · Ian Rogers

From: Stephane Eranian <[email protected]>

When it is not possible for a non-privilege perf command to monitor at the kernel level (:k), the fallback code forces a :u. That works if the event was previously monitoring both levels. But if the event was already constrained to kernel only, then it does not make sense to restrict it to user only.
Given the code works by exclusion, a kernel only event would have:
attr->exclude_user = 1
The fallback code would add:
attr->exclude_kernel = 1;

In the end the end would not monitor in either the user level or kernel level. In other words, it would count nothing.

An event programmed to monitor kernel only cannot be switched to user only without seriously warning the user.

This patch forces an error in this case to make it clear the request cannot really be satisfied.

---
 tools/perf/util/evsel.c | 7 +++++++
 1 file changed, 7 insertions(+)
tools/perf/util/evsel.c +0 -0
index d23db6755f51..d1e8862b86ce 100644

tools/perf/util/evsel.c bool perf_evsel__fallback(struct evsel *evsel, int err, · line 2453

Quoted 8 lines
tools/perf/util/evsel.c +5 -0
@@ -2446,6 +2446,13 @@ bool perf_evsel__fallback(struct evsel *evsel, int err,
 		char *new_name;
 		const char *sep = ":";
 
+		if (evsel->core.attr.exclude_user) {
+			scnprintf(msg, msgsize,
+"kernel.perf_event_paranoid=%d, event set to exclude user, so cannot also exclude kernel",
+				paranoid);
+			return false;

I'm not able to get this error printed, it seems to be overwritten by perf_evsel__open_strerror call

please include perf example with the new output

thanks,
jirka

Quoted 8 lines
tools/perf/util/evsel.c +2 -0
+		}
+
 		/* Is there already the separator in the name. */
 		if (strchr(name, '/') ||
 		    strchr(name, ':'))
Signature · 1 line
2.26.0.110.g2183baf09c-goog
author reviewer
#2 lore raw
Quoted 46 lines · Jiri Olsa
Quoted 32 lines · Ian Rogers

From: Stephane Eranian <[email protected]>

When it is not possible for a non-privilege perf command to monitor at the kernel level (:k), the fallback code forces a :u. That works if the event was previously monitoring both levels. But if the event was already constrained to kernel only, then it does not make sense to restrict it to user only.
Given the code works by exclusion, a kernel only event would have:
attr->exclude_user = 1
The fallback code would add:
attr->exclude_kernel = 1;

In the end the end would not monitor in either the user level or kernel level. In other words, it would count nothing.

An event programmed to monitor kernel only cannot be switched to user only without seriously warning the user.

This patch forces an error in this case to make it clear the request cannot really be satisfied.

---
 tools/perf/util/evsel.c | 7 +++++++
 1 file changed, 7 insertions(+)
tools/perf/util/evsel.c +0 -0
index d23db6755f51..d1e8862b86ce 100644

tools/perf/util/evsel.c bool perf_evsel__fallback(struct evsel *evsel, int err, · line 2453

Quoted 8 lines
tools/perf/util/evsel.c +5 -0
@@ -2446,6 +2446,13 @@ bool perf_evsel__fallback(struct evsel *evsel, int err,
              char *new_name;
              const char *sep = ":";
 
+             if (evsel->core.attr.exclude_user) {
+                     scnprintf(msg, msgsize,
+"kernel.perf_event_paranoid=%d, event set to exclude user, so cannot also exclude kernel",
+                             paranoid);
+                     return false;

I'm not able to get this error printed, it seems to be overwritten by perf_evsel__open_strerror call

Quoted 1 line

please include perf example with the new output

Agreed, it is possible the change builtin-top/sched/record so that on error the msg is checked and dumped in verbose mode. I think it is also fine to just remove the scnprintf. Do you have a preference?

Thanks,
Ian

Quoted 12 lines

thanks,
jirka

Quoted 8 lines
tools/perf/util/evsel.c +2 -1
+             }
+
              /* Is there already the separator in the name. */
              if (strchr(name, '/') ||
                  strchr(name, ':'))
--

2.26.0.110.g2183baf09c-goog

#3 lore raw
Quoted 47 lines · Ian Rogers
Quoted 46 lines · Jiri Olsa
Quoted 32 lines · Ian Rogers

From: Stephane Eranian <[email protected]>

When it is not possible for a non-privilege perf command to monitor at the kernel level (:k), the fallback code forces a :u. That works if the event was previously monitoring both levels. But if the event was already constrained to kernel only, then it does not make sense to restrict it to user only.
Given the code works by exclusion, a kernel only event would have:
attr->exclude_user = 1
The fallback code would add:
attr->exclude_kernel = 1;

In the end the end would not monitor in either the user level or kernel level. In other words, it would count nothing.

An event programmed to monitor kernel only cannot be switched to user only without seriously warning the user.

This patch forces an error in this case to make it clear the request cannot really be satisfied.

---
 tools/perf/util/evsel.c | 7 +++++++
 1 file changed, 7 insertions(+)
tools/perf/util/evsel.c +0 -0
index d23db6755f51..d1e8862b86ce 100644

tools/perf/util/evsel.c bool perf_evsel__fallback(struct evsel *evsel, int err, · line 2453

Quoted 8 lines
tools/perf/util/evsel.c +5 -0
@@ -2446,6 +2446,13 @@ bool perf_evsel__fallback(struct evsel *evsel, int err,
              char *new_name;
              const char *sep = ":";
 
+             if (evsel->core.attr.exclude_user) {
+                     scnprintf(msg, msgsize,
+"kernel.perf_event_paranoid=%d, event set to exclude user, so cannot also exclude kernel",
+                             paranoid);
+                     return false;

I'm not able to get this error printed, it seems to be overwritten by perf_evsel__open_strerror call

Quoted 5 lines
Quoted 1 line

please include perf example with the new output

Agreed, it is possible the change builtin-top/sched/record so that on error the msg is checked and dumped in verbose mode. I think it is also fine to just remove the scnprintf. Do you have a preference?

not sure ;-) but let's make sure we don't remove some expected output

jirka

Quoted 17 lines

Thanks,
Ian

Quoted 12 lines

thanks,
jirka

Quoted 8 lines
tools/perf/util/evsel.c +2 -1
+             }
+
              /* Is there already the separator in the name. */
              if (strchr(name, '/') ||
                  strchr(name, ':'))
--

2.26.0.110.g2183baf09c-goog

author reviewer
#4 lore raw
Quoted 51 lines · Jiri Olsa
Quoted 49 lines · Ian Rogers
Quoted 47 lines · Jiri Olsa
Quoted 32 lines · Ian Rogers

From: Stephane Eranian <[email protected]>

When it is not possible for a non-privilege perf command to monitor at the kernel level (:k), the fallback code forces a :u. That works if the event was previously monitoring both levels. But if the event was already constrained to kernel only, then it does not make sense to restrict it to user only.
Given the code works by exclusion, a kernel only event would have:
attr->exclude_user = 1
The fallback code would add:
attr->exclude_kernel = 1;

In the end the end would not monitor in either the user level or kernel level. In other words, it would count nothing.

An event programmed to monitor kernel only cannot be switched to user only without seriously warning the user.

This patch forces an error in this case to make it clear the request cannot really be satisfied.

---
 tools/perf/util/evsel.c | 7 +++++++
 1 file changed, 7 insertions(+)
tools/perf/util/evsel.c +0 -0
index d23db6755f51..d1e8862b86ce 100644

tools/perf/util/evsel.c bool perf_evsel__fallback(struct evsel *evsel, int err, · line 2453

Quoted 8 lines
tools/perf/util/evsel.c +5 -0
@@ -2446,6 +2446,13 @@ bool perf_evsel__fallback(struct evsel *evsel, int err,
              char *new_name;
              const char *sep = ":";
 
+             if (evsel->core.attr.exclude_user) {
+                     scnprintf(msg, msgsize,
+"kernel.perf_event_paranoid=%d, event set to exclude user, so cannot also exclude kernel",
+                             paranoid);
+                     return false;

I'm not able to get this error printed, it seems to be overwritten by perf_evsel__open_strerror call

please include perf example with the new output

Quoted 7 lines
Quoted 3 lines

Agreed, it is possible the change builtin-top/sched/record so that on error the msg is checked and dumped in verbose mode. I think it is also fine to just remove the scnprintf. Do you have a preference?

not sure ;-) but let's make sure we don't remove some expected output

jirka

I went the easier route as I don't think the new error message adds anything over the perf_evsel__open_strerror message. v2 is here:
https://lore.kernel.org/lkml/[email protected]/T/#u

Thanks,
Ian

Quoted 18 lines
Quoted 17 lines

Thanks,
Ian

Quoted 12 lines

thanks,
jirka

Quoted 8 lines
tools/perf/util/evsel.c +2 -1
+             }
+
              /* Is there already the separator in the name. */
              if (strchr(name, '/') ||
                  strchr(name, ':'))
--

2.26.0.110.g2183baf09c-goog