linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf, tools: Fall weak group back even for EBADF
@ 2017-09-05 21:13 Andi Kleen
  2017-09-06 11:52 ` Jiri Olsa
  2017-09-22 16:37 ` [tip:perf/core] perf stat: " tip-bot for Andi Kleen
  0 siblings, 2 replies; 3+ messages in thread
From: Andi Kleen @ 2017-09-05 21:13 UTC (permalink / raw)
  To: acme; +Cc: jolsa, linux-kernel, Andi Kleen

From: Andi Kleen <ak@linux.intel.com>

It's not possible to run a package event and a per cpu event in
the same group. This is used by some of the power metrics.
They work correctly when not using a group.

Normally weak groups should handle that, but in this case EBADF
is returned instead of the normal EINVAL.

strace -e perf_event_open ./perf stat -v -e '{cstate_pkg/c2-residency/,msr/tsc/}:W' -a sleep 1
Using CPUID GenuineIntel-6-3E
perf_event_open({type=0x17 /* PERF_TYPE_??? */, size=PERF_ATTR_SIZE_VER5, config=0, ...}, -1, 0, -1, PERF_FLAG_FD_CLOEXEC) = -1 EINVAL (Invalid argument)
perf_event_open({type=0x17 /* PERF_TYPE_??? */, size=PERF_ATTR_SIZE_VER5, config=0, ...}, -1, 0, -1, 0) = -1 EINVAL (Invalid argument)
perf_event_open({type=0x17 /* PERF_TYPE_??? */, size=PERF_ATTR_SIZE_VER5, config=0, ...}, -1, 0, -1, 0) = -1 EINVAL (Invalid argument)
perf_event_open({type=0x17 /* PERF_TYPE_??? */, size=PERF_ATTR_SIZE_VER5, config=0, ...}, -1, 0, -1, 0) = -1 EINVAL (Invalid argument)
perf_event_open({type=0x17 /* PERF_TYPE_??? */, size=PERF_ATTR_SIZE_VER5, config=0, ...}, -1, 0, -1, 0) = 3
perf_event_open({type=0x7 /* PERF_TYPE_??? */, size=PERF_ATTR_SIZE_VER5, config=0, ...}, -1, 0, 3, 0) = 4
perf_event_open({type=0x7 /* PERF_TYPE_??? */, size=PERF_ATTR_SIZE_VER5, config=0, ...}, -1, 1, 0, 0) = -1 EBADF (Bad file descriptor)

and perf errors out.

Make weak groups trigger a fall back for EBADF too. Then this case works correctly:

$ ./perf stat -v -e '{cstate_pkg/c2-residency/,msr/tsc/}:W' -a sleep 1
Using CPUID GenuineIntel-6-3E
Weak group for cstate_pkg/c2-residency//2 failed
cstate_pkg/c2-residency/: 476709882 1000598460 1000598460
msr/tsc/: 39625837911 12007369110 12007369110

 Performance counter stats for 'system wide':

       476,709,882      cstate_pkg/c2-residency/
    39,625,837,911      msr/tsc/

       1.000697588 seconds time elapsed

This fixes perf stat -M Power ...

$ ./perf stat -M Power --metric-only -a sleep 1

 Performance counter stats for 'system wide':

Turbo_Utilization    C3_Core_Residency    C6_Core_Residency    C7_Core_Residency    C2_Pkg_Residency     C3_Pkg_Residency     C6_Pkg_Residency     C7_Pkg_Residency
     1.0                 0.7                30.0                 0.0                 0.9                 0.1                 0.4                 0.0

       1.001240740 seconds time elapsed

Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
 tools/perf/builtin-stat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 60206a1e03aa..1929f92c824b 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -656,7 +656,7 @@ static int __run_perf_stat(int argc, const char **argv)
 		if (create_perf_stat_counter(counter) < 0) {
 
 			/* Weak group failed. Reset the group. */
-			if (errno == EINVAL &&
+			if ((errno == EINVAL || errno == EBADF) &&
 			    counter->leader != counter &&
 			    counter->weak_group) {
 				counter = reset_weak_group(counter);
-- 
2.9.5

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

* Re: [PATCH] perf, tools: Fall weak group back even for EBADF
  2017-09-05 21:13 [PATCH] perf, tools: Fall weak group back even for EBADF Andi Kleen
@ 2017-09-06 11:52 ` Jiri Olsa
  2017-09-22 16:37 ` [tip:perf/core] perf stat: " tip-bot for Andi Kleen
  1 sibling, 0 replies; 3+ messages in thread
From: Jiri Olsa @ 2017-09-06 11:52 UTC (permalink / raw)
  To: Andi Kleen; +Cc: acme, jolsa, linux-kernel, Andi Kleen

On Tue, Sep 05, 2017 at 02:13:24PM -0700, Andi Kleen wrote:
> From: Andi Kleen <ak@linux.intel.com>
> 
> It's not possible to run a package event and a per cpu event in
> the same group. This is used by some of the power metrics.
> They work correctly when not using a group.
> 
> Normally weak groups should handle that, but in this case EBADF
> is returned instead of the normal EINVAL.
> 
> strace -e perf_event_open ./perf stat -v -e '{cstate_pkg/c2-residency/,msr/tsc/}:W' -a sleep 1
> Using CPUID GenuineIntel-6-3E
> perf_event_open({type=0x17 /* PERF_TYPE_??? */, size=PERF_ATTR_SIZE_VER5, config=0, ...}, -1, 0, -1, PERF_FLAG_FD_CLOEXEC) = -1 EINVAL (Invalid argument)
> perf_event_open({type=0x17 /* PERF_TYPE_??? */, size=PERF_ATTR_SIZE_VER5, config=0, ...}, -1, 0, -1, 0) = -1 EINVAL (Invalid argument)
> perf_event_open({type=0x17 /* PERF_TYPE_??? */, size=PERF_ATTR_SIZE_VER5, config=0, ...}, -1, 0, -1, 0) = -1 EINVAL (Invalid argument)
> perf_event_open({type=0x17 /* PERF_TYPE_??? */, size=PERF_ATTR_SIZE_VER5, config=0, ...}, -1, 0, -1, 0) = -1 EINVAL (Invalid argument)
> perf_event_open({type=0x17 /* PERF_TYPE_??? */, size=PERF_ATTR_SIZE_VER5, config=0, ...}, -1, 0, -1, 0) = 3
> perf_event_open({type=0x7 /* PERF_TYPE_??? */, size=PERF_ATTR_SIZE_VER5, config=0, ...}, -1, 0, 3, 0) = 4
> perf_event_open({type=0x7 /* PERF_TYPE_??? */, size=PERF_ATTR_SIZE_VER5, config=0, ...}, -1, 1, 0, 0) = -1 EBADF (Bad file descriptor)
> 
> and perf errors out.
> 
> Make weak groups trigger a fall back for EBADF too. Then this case works correctly:
> 
> $ ./perf stat -v -e '{cstate_pkg/c2-residency/,msr/tsc/}:W' -a sleep 1
> Using CPUID GenuineIntel-6-3E
> Weak group for cstate_pkg/c2-residency//2 failed
> cstate_pkg/c2-residency/: 476709882 1000598460 1000598460
> msr/tsc/: 39625837911 12007369110 12007369110
> 
>  Performance counter stats for 'system wide':
> 
>        476,709,882      cstate_pkg/c2-residency/
>     39,625,837,911      msr/tsc/
> 
>        1.000697588 seconds time elapsed
> 
> This fixes perf stat -M Power ...
> 
> $ ./perf stat -M Power --metric-only -a sleep 1
> 
>  Performance counter stats for 'system wide':
> 
> Turbo_Utilization    C3_Core_Residency    C6_Core_Residency    C7_Core_Residency    C2_Pkg_Residency     C3_Pkg_Residency     C6_Pkg_Residency     C7_Pkg_Residency
>      1.0                 0.7                30.0                 0.0                 0.9                 0.1                 0.4                 0.0
> 
>        1.001240740 seconds time elapsed
> 
> Signed-off-by: Andi Kleen <ak@linux.intel.com>

seems ok me

Acked-by: Jiri Olsa <jolsa@kernel.org>

thanks,
jirka

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

* [tip:perf/core] perf stat: Fall weak group back even for EBADF
  2017-09-05 21:13 [PATCH] perf, tools: Fall weak group back even for EBADF Andi Kleen
  2017-09-06 11:52 ` Jiri Olsa
@ 2017-09-22 16:37 ` tip-bot for Andi Kleen
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Andi Kleen @ 2017-09-22 16:37 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: hpa, acme, ak, tglx, mingo, jolsa, linux-kernel

Commit-ID:  35c1980eb3d1acb3cac11c38252339399dca77e3
Gitweb:     http://git.kernel.org/tip/35c1980eb3d1acb3cac11c38252339399dca77e3
Author:     Andi Kleen <ak@linux.intel.com>
AuthorDate: Tue, 5 Sep 2017 14:13:24 -0700
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 13 Sep 2017 09:49:16 -0300

perf stat: Fall weak group back even for EBADF

It's not possible to run a package event and a per cpu event in the same
group. This is used by some of the power metrics.  They work correctly
when not using a group.

Normally weak groups should handle that, but in this case EBADF is
returned instead of the normal EINVAL.

  $ strace -e perf_event_open ./perf stat -v -e '{cstate_pkg/c2-residency/,msr/tsc/}:W' -a sleep 1
  Using CPUID GenuineIntel-6-3E
  perf_event_open({type=0x17 /* PERF_TYPE_??? */, size=PERF_ATTR_SIZE_VER5, config=0, ...}, -1, 0, -1, PERF_FLAG_FD_CLOEXEC) = -1 EINVAL (Invalid argument)
  perf_event_open({type=0x17 /* PERF_TYPE_??? */, size=PERF_ATTR_SIZE_VER5, config=0, ...}, -1, 0, -1, 0) = -1 EINVAL (Invalid argument)
  perf_event_open({type=0x17 /* PERF_TYPE_??? */, size=PERF_ATTR_SIZE_VER5, config=0, ...}, -1, 0, -1, 0) = -1 EINVAL (Invalid argument)
  perf_event_open({type=0x17 /* PERF_TYPE_??? */, size=PERF_ATTR_SIZE_VER5, config=0, ...}, -1, 0, -1, 0) = -1 EINVAL (Invalid argument)
  perf_event_open({type=0x17 /* PERF_TYPE_??? */, size=PERF_ATTR_SIZE_VER5, config=0, ...}, -1, 0, -1, 0) = 3
  perf_event_open({type=0x7 /* PERF_TYPE_??? */, size=PERF_ATTR_SIZE_VER5, config=0, ...}, -1, 0, 3, 0) = 4
  perf_event_open({type=0x7 /* PERF_TYPE_??? */, size=PERF_ATTR_SIZE_VER5, config=0, ...}, -1, 1, 0, 0) = -1 EBADF (Bad file descriptor)

and perf errors out.

Make weak groups trigger a fall back for EBADF too. Then this case works correctly:

  $ perf stat -v -e '{cstate_pkg/c2-residency/,msr/tsc/}:W' -a sleep 1
  Using CPUID GenuineIntel-6-3E
  Weak group for cstate_pkg/c2-residency//2 failed
  cstate_pkg/c2-residency/: 476709882 1000598460 1000598460
  msr/tsc/: 39625837911 12007369110 12007369110

   Performance counter stats for 'system wide':

         476,709,882      cstate_pkg/c2-residency/
      39,625,837,911      msr/tsc/

         1.000697588 seconds time elapsed

  This fixes perf stat -M Power ...

  $ perf stat -M Power --metric-only -a sleep 1

   Performance counter stats for 'system wide':

  Turbo_Utilization  C3_Core_Residency  C6_Core_Residency C7_Core_Residency  C2_Pkg_Residency   C3_Pkg_Residency  C6_Pkg_Residency  C7_Pkg_Residency
       1.0                 0.7                30.0               0.0               0.9                 0.1               0.4                 0.0

         1.001240740 seconds time elapsed

Signed-off-by: Andi Kleen <ak@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Link: http://lkml.kernel.org/r/20170905211324.32427-1-andi@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-stat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 88f1d5f..dd52541 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -656,7 +656,7 @@ try_again:
 		if (create_perf_stat_counter(counter) < 0) {
 
 			/* Weak group failed. Reset the group. */
-			if (errno == EINVAL &&
+			if ((errno == EINVAL || errno == EBADF) &&
 			    counter->leader != counter &&
 			    counter->weak_group) {
 				counter = perf_evsel__reset_weak_group(counter);

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

end of thread, other threads:[~2017-09-22 16:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-05 21:13 [PATCH] perf, tools: Fall weak group back even for EBADF Andi Kleen
2017-09-06 11:52 ` Jiri Olsa
2017-09-22 16:37 ` [tip:perf/core] perf stat: " tip-bot for Andi Kleen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).