Skip to contentSkip to conversation

perf,tools: error out unsupported group leader immediately for perf stat

PATCH In review [email protected] 3 participants 5 messages Jun 11, 2015 – Jun 12, 2015 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf,tools: error out unsupported group leader immediately for perf stat

From: Kan Liang <[email protected]>

perf stat ignores the unsupported event and continue to count supported event. But if the unsupported event is group leader, perf tool will crash. After applying this patch, the unsupported group leader will error out immediately.

Without this patch:

$ perf stat -x, -e '{node-prefetch-refs,cycles}' --  sleep 1
perf: util/evsel.c:1009: get_group_fd: Assertion `!(fd == -1)' failed.
Aborted (core dumped)

With this patch:

$ perf stat -x, -e '{node-prefetch-refs,cycles}' --  sleep 1
Error:
The node-prefetch-refs event is not supported.
---
 tools/perf/builtin-stat.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/builtin-stat.c +4 -1
index ff3d258..b24ecee 100644
@@ -549,7 +549,10 @@ static int __run_perf_stat(int argc, const char **argv)
 					ui__warning("%s event is not supported by the kernel.\n",
 						    perf_evsel__name(counter));
 				counter->supported = false;
-				continue;
+
+				if ((counter->leader != counter) ||
+				    !(counter->leader->nr_members > 1))
+					continue;
 			}
 
 			perf_evsel__open_strerror(counter, &target,
Signature · 1 line
1.8.3.1
#1 lore raw

Em Thu, Jun 11, 2015 at 02:32:40AM -0400, [email protected] escreveu:

Quoted 6 lines

perf stat ignores the unsupported event and continue to count supported event. But if the unsupported event is group leader, perf tool will crash. After applying this patch, the unsupported group leader will error out immediately.

Without this patch:

Quoted 8 lines
$ perf stat -x, -e '{node-prefetch-refs,cycles}' --  sleep 1
perf: util/evsel.c:1009: get_group_fd: Assertion `!(fd == -1)' failed.
Aborted (core dumped)

With this patch:

$ perf stat -x, -e '{node-prefetch-refs,cycles}' --  sleep 1
Error:
The node-prefetch-refs event is not supported.

I get something different, maybe I am missing a patch?

With this patch:

[acme@zoo linux]$ perf stat -x, -e '{node-prefetch-refs,cycles}' -- sleep 1 Error:
The sys_perf_event_open() syscall returned with 22 (Invalid argument) for event (node-prefetch-refs).
/bin/dmesg may provide additional information.
No CONFIG_PERF_EVENTS=y kernel support configured?
[acme@zoo linux]$

Applying it anyway, as it avoids a core dump and the message, albeit not optimal, points to a problem with that event.

Have you tried this with other tools, like perf record?

- Arnaldo

author
#2 lore raw
Quoted 22 lines

Em Thu, Jun 11, 2015 at 02:32:40AM -0400, [email protected] escreveu:

Quoted 6 lines

perf stat ignores the unsupported event and continue to count supported event. But if the unsupported event is group leader, perf tool will crash. After applying this patch, the unsupported group leader will error out immediately.

Without this patch:

Quoted 8 lines
$ perf stat -x, -e '{node-prefetch-refs,cycles}' --  sleep 1
perf: util/evsel.c:1009: get_group_fd: Assertion `!(fd == -1)' failed.
Aborted (core dumped)

With this patch:

$ perf stat -x, -e '{node-prefetch-refs,cycles}' --  sleep 1
Error:
The node-prefetch-refs event is not supported.

I get something different, maybe I am missing a patch?

With this patch:

Quoted 8 lines

[acme@zoo linux]$ perf stat -x, -e '{node-prefetch-refs,cycles}' -- sleep 1 Error:
The sys_perf_event_open() syscall returned with 22 (Invalid argument) for event (node-prefetch-refs).
/bin/dmesg may provide additional information.
No CONFIG_PERF_EVENTS=y kernel support configured?
[acme@zoo linux]$

I don't have other patches for this issue.
It looks they have different error code, ENOENT VS. EINVAL. I have no idea why.

Quoted 4 lines

Applying it anyway, as it avoids a core dump and the message, albeit not optimal, points to a problem with that event.

Have you tried this with other tools, like perf record?

Yes. Perf record and perf top will error out immediately if any unsupported event found. So they don't have such issue.

Thanks,
Kan

Quoted 2 lines

- Arnaldo

#3 lore raw

Em Thu, Jun 11, 2015 at 02:26:47PM +0000, Liang, Kan escreveu:

Quoted 17 lines
Quoted 8 lines

Em Thu, Jun 11, 2015 at 02:32:40AM -0400, [email protected] escreveu:

Quoted 4 lines

With this patch:

$ perf stat -x, -e '{node-prefetch-refs,cycles}' --  sleep 1
Error:
The node-prefetch-refs event is not supported.

I get something different, maybe I am missing a patch?

Quoted 8 lines

With this patch:

[acme@zoo linux]$ perf stat -x, -e '{node-prefetch-refs,cycles}' -- sleep 1 Error:
The sys_perf_event_open() syscall returned with 22 (Invalid argument) for event (node-prefetch-refs).
/bin/dmesg may provide additional information.
No CONFIG_PERF_EVENTS=y kernel support configured?

Quoted 3 lines

I don't have other patches for this issue.
It looks they have different error code, ENOENT VS. EINVAL. I have no idea why.

Well, here I have:

[acme@zoo ~]$ uname -a
Linux zoo.ghostprotocols.net 3.19.7-200.fc21.x86_64 #1 SMP Thu May 7 22:00:21 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

I am rebooting now, due to an unrelated reason, to 4.1.0-rc5+, lets see if this explains this discrepancy...

Quoted 7 lines
Quoted 4 lines

Applying it anyway, as it avoids a core dump and the message, albeit not optimal, points to a problem with that event.

Have you tried this with other tools, like perf record?

Yes. Perf record and perf top will error out immediately if any unsupported event found. So they don't have such issue.

Ok, need to revisit the event setup code again and remove the code duplication once and for all :-\

- Arnaldo

#4 lore raw

[tip:perf/core] perf stat: Error out unsupported group leader immediately

In reply to [email protected]
perf stat: Error out unsupported group leader immediately
Commit-ID:  cb5ef60067c11cc8887122f6f168c21941c5d624
Gitweb:     http://git.kernel.org/tip/cb5ef60067c11cc8887122f6f168c21941c5d624
Author:     Kan Liang <[email protected]>
AuthorDate: Thu, 11 Jun 2015 02:32:40 -0400
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 11 Jun 2015 11:07:40 -0300

perf stat: Error out unsupported group leader immediately

perf stat ignores the unsupported event and continue to count supported event. But if the unsupported event is group leader, perf tool will crash. After applying this patch, the unsupported group leader will error out immediately.

Without this patch:

  $ perf stat -x, -e '{node-prefetch-refs,cycles}' --  sleep 1
  perf: util/evsel.c:1009: get_group_fd: Assertion `!(fd == -1)' failed.
  Aborted (core dumped)

With this patch:

  $ perf stat -x, -e '{node-prefetch-refs,cycles}' --  sleep 1
  Error:
  The node-prefetch-refs event is not supported.

Commiter note: Here I got a different output, but no core dump:

[acme@zoo linux]$ perf stat -x, -e '{node-prefetch-refs,cycles}' -- sleep 1 Error:
The sys_perf_event_open() syscall returned with 22 (Invalid argument) for event (node-prefetch-refs).
/bin/dmesg may provide additional information.
No CONFIG_PERF_EVENTS=y kernel support configured?

---
 tools/perf/builtin-stat.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/builtin-stat.c +4 -1
index ff3d258..b24ecee 100644
@@ -549,7 +549,10 @@ static int __run_perf_stat(int argc, const char **argv)
 					ui__warning("%s event is not supported by the kernel.\n",
 						    perf_evsel__name(counter));
 				counter->supported = false;
-				continue;
+
+				if ((counter->leader != counter) ||
+				    !(counter->leader->nr_members > 1))
+					continue;
 			}
 
 			perf_evsel__open_strerror(counter, &target,