All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] perf tools: API probing fixes
@ 2014-08-12 15:04 Adrian Hunter
  2014-08-12 15:04 ` [PATCH 1/4] perf tools: Fix CLOEXEC probe for perf_event_paranoid == 2 Adrian Hunter
                   ` (4 more replies)
  0 siblings, 5 replies; 15+ messages in thread
From: Adrian Hunter @ 2014-08-12 15:04 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Peter Zijlstra, linux-kernel, David Ahern, Frederic Weisbecker,
	Jiri Olsa, Namhyung Kim, Paul Mackerras, Stephane Eranian

Hi

Here are some fixes for API probing issues that I have run into,
and a second attempt at the jump-label problem.

Patches apply to your tmp.perf/core branch.


Adrian Hunter (4):
      perf tools: Fix CLOEXEC probe for perf_event_paranoid == 2
      perf tools: Fix one of the probe events to exclude kernel
      perf tools: Fix probing the kernel API with cpu-wide events
      perf tools: Prefer to use a cpu-wide event for probing CLOEXEC


Regards
Adrian

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

* [PATCH 1/4] perf tools: Fix CLOEXEC probe for perf_event_paranoid == 2
  2014-08-12 15:04 [PATCH 0/4] perf tools: API probing fixes Adrian Hunter
@ 2014-08-12 15:04 ` Adrian Hunter
  2014-08-13  5:33   ` Namhyung Kim
  2014-08-14  8:44   ` [tip:perf/core] " tip-bot for Adrian Hunter
  2014-08-12 15:04 ` [PATCH 2/4] perf tools: Fix one of the probe events to exclude kernel Adrian Hunter
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 15+ messages in thread
From: Adrian Hunter @ 2014-08-12 15:04 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Peter Zijlstra, linux-kernel, David Ahern, Frederic Weisbecker,
	Jiri Olsa, Namhyung Kim, Paul Mackerras, Stephane Eranian

With /proc/sys/kernel/perf_event_paranoid set to 2, the
probe of PERF_FLAG_FD_CLOEXEC would fail.  Fix by excluding
kernel profiling from the probe event.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/util/cloexec.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/util/cloexec.c b/tools/perf/util/cloexec.c
index 5073c01..000047c 100644
--- a/tools/perf/util/cloexec.c
+++ b/tools/perf/util/cloexec.c
@@ -11,6 +11,7 @@ static int perf_flag_probe(void)
 	struct perf_event_attr attr = {
 		.type = PERF_TYPE_SOFTWARE,
 		.config = PERF_COUNT_SW_CPU_CLOCK,
+		.exclude_kernel = 1,
 	};
 	int fd;
 	int err;
-- 
1.8.3.2


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

* [PATCH 2/4] perf tools: Fix one of the probe events to exclude kernel
  2014-08-12 15:04 [PATCH 0/4] perf tools: API probing fixes Adrian Hunter
  2014-08-12 15:04 ` [PATCH 1/4] perf tools: Fix CLOEXEC probe for perf_event_paranoid == 2 Adrian Hunter
@ 2014-08-12 15:04 ` Adrian Hunter
  2014-08-13  5:34   ` Namhyung Kim
  2014-08-14  8:44   ` [tip:perf/core] " tip-bot for Adrian Hunter
  2014-08-12 15:04 ` [PATCH 3/4] perf tools: Fix probing the kernel API with cpu-wide events Adrian Hunter
                   ` (2 subsequent siblings)
  4 siblings, 2 replies; 15+ messages in thread
From: Adrian Hunter @ 2014-08-12 15:04 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Peter Zijlstra, linux-kernel, David Ahern, Frederic Weisbecker,
	Jiri Olsa, Namhyung Kim, Paul Mackerras, Stephane Eranian

When probing the kernel API the kernel should be excluded
otherwise the probe will fail for users with insufficient
privilege to profile the kernel.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/util/record.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c
index 787b882..68ad2d0 100644
--- a/tools/perf/util/record.c
+++ b/tools/perf/util/record.c
@@ -47,7 +47,7 @@ out_delete:
 
 static bool perf_probe_api(setup_probe_fn_t fn)
 {
-	const char *try[] = {"cycles:u", "instructions:u", "cpu-clock", NULL};
+	const char *try[] = {"cycles:u", "instructions:u", "cpu-clock:u", NULL};
 	struct cpu_map *cpus;
 	int cpu, ret, i = 0;
 
-- 
1.8.3.2


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

* [PATCH 3/4] perf tools: Fix probing the kernel API with cpu-wide events
  2014-08-12 15:04 [PATCH 0/4] perf tools: API probing fixes Adrian Hunter
  2014-08-12 15:04 ` [PATCH 1/4] perf tools: Fix CLOEXEC probe for perf_event_paranoid == 2 Adrian Hunter
  2014-08-12 15:04 ` [PATCH 2/4] perf tools: Fix one of the probe events to exclude kernel Adrian Hunter
@ 2014-08-12 15:04 ` Adrian Hunter
  2014-08-13  5:37   ` Namhyung Kim
  2014-08-14  8:45   ` [tip:perf/core] " tip-bot for Adrian Hunter
  2014-08-12 15:04 ` [PATCH 4/4] perf tools: Prefer to use a cpu-wide event for probing CLOEXEC Adrian Hunter
  2014-08-13 11:28 ` [PATCH 0/4] perf tools: API probing fixes Jiri Olsa
  4 siblings, 2 replies; 15+ messages in thread
From: Adrian Hunter @ 2014-08-12 15:04 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Peter Zijlstra, linux-kernel, David Ahern, Frederic Weisbecker,
	Jiri Olsa, Namhyung Kim, Paul Mackerras, Stephane Eranian

Fall back to probing with the current pid if cpu-wide
probing fails.  This primarily affects the setting of
comm_exec flag when the user is un-privileged and
/proc/sys/kernel/perf_event_paranoid > 0.  The change
to comm_exec can be observed by using -vv with
perf record and a kernel that supports comm_exec.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/util/record.c | 36 +++++++++++++++++++++++++++---------
 1 file changed, 27 insertions(+), 9 deletions(-)

diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c
index 68ad2d0..cf69325 100644
--- a/tools/perf/util/record.c
+++ b/tools/perf/util/record.c
@@ -14,6 +14,7 @@ static int perf_do_probe_api(setup_probe_fn_t fn, int cpu, const char *str)
 	struct perf_evsel *evsel;
 	unsigned long flags = perf_event_open_cloexec_flag();
 	int err = -EAGAIN, fd;
+	static pid_t pid = -1;
 
 	evlist = perf_evlist__new();
 	if (!evlist)
@@ -24,14 +25,22 @@ static int perf_do_probe_api(setup_probe_fn_t fn, int cpu, const char *str)
 
 	evsel = perf_evlist__first(evlist);
 
-	fd = sys_perf_event_open(&evsel->attr, -1, cpu, -1, flags);
-	if (fd < 0)
-		goto out_delete;
+	while (1) {
+		fd = sys_perf_event_open(&evsel->attr, pid, cpu, -1, flags);
+		if (fd < 0) {
+			if (pid == -1 && errno == EACCES) {
+				pid = 0;
+				continue;
+			}
+			goto out_delete;
+		}
+		break;
+	}
 	close(fd);
 
 	fn(evsel);
 
-	fd = sys_perf_event_open(&evsel->attr, -1, cpu, -1, flags);
+	fd = sys_perf_event_open(&evsel->attr, pid, cpu, -1, flags);
 	if (fd < 0) {
 		if (errno == EINVAL)
 			err = -EINVAL;
@@ -201,6 +210,7 @@ bool perf_evlist__can_select_event(struct perf_evlist *evlist, const char *str)
 	struct perf_evsel *evsel;
 	int err, fd, cpu;
 	bool ret = false;
+	pid_t pid = -1;
 
 	temp_evlist = perf_evlist__new();
 	if (!temp_evlist)
@@ -221,12 +231,20 @@ bool perf_evlist__can_select_event(struct perf_evlist *evlist, const char *str)
 		cpu = evlist->cpus->map[0];
 	}
 
-	fd = sys_perf_event_open(&evsel->attr, -1, cpu, -1,
-				 perf_event_open_cloexec_flag());
-	if (fd >= 0) {
-		close(fd);
-		ret = true;
+	while (1) {
+		fd = sys_perf_event_open(&evsel->attr, pid, cpu, -1,
+					 perf_event_open_cloexec_flag());
+		if (fd < 0) {
+			if (pid == -1 && errno == EACCES) {
+				pid = 0;
+				continue;
+			}
+			goto out_delete;
+		}
+		break;
 	}
+	close(fd);
+	ret = true;
 
 out_delete:
 	perf_evlist__delete(temp_evlist);
-- 
1.8.3.2


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

* [PATCH 4/4] perf tools: Prefer to use a cpu-wide event for probing CLOEXEC
  2014-08-12 15:04 [PATCH 0/4] perf tools: API probing fixes Adrian Hunter
                   ` (2 preceding siblings ...)
  2014-08-12 15:04 ` [PATCH 3/4] perf tools: Fix probing the kernel API with cpu-wide events Adrian Hunter
@ 2014-08-12 15:04 ` Adrian Hunter
  2014-08-14  8:45   ` [tip:perf/core] " tip-bot for Adrian Hunter
  2014-08-13 11:28 ` [PATCH 0/4] perf tools: API probing fixes Jiri Olsa
  4 siblings, 1 reply; 15+ messages in thread
From: Adrian Hunter @ 2014-08-12 15:04 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Peter Zijlstra, linux-kernel, David Ahern, Frederic Weisbecker,
	Jiri Olsa, Namhyung Kim, Paul Mackerras, Stephane Eranian

When doing a system-wide trace with Intel PT, the jump label
set up as a result of probing CLOEXEC gets reset while the
trace is running.  That causes an Intel PT decoding error
because the object code (obtained from /proc/kcore) does
not match the running code at that point.  While we can't
expect there never to be jump label changes, we can avoid
cases that the perf tool itself creates.

The problem is avoided by first trying a cpu-wide event
(pid = -1) for probing the PERF_FLAG_FD_CLOEXEC flag and
falling back to an event for the current process (pid = 0).

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/util/cloexec.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/cloexec.c b/tools/perf/util/cloexec.c
index 000047c..4945aa5 100644
--- a/tools/perf/util/cloexec.c
+++ b/tools/perf/util/cloexec.c
@@ -1,3 +1,4 @@
+#include <sched.h>
 #include "util.h"
 #include "../perf.h"
 #include "cloexec.h"
@@ -15,10 +16,23 @@ static int perf_flag_probe(void)
 	};
 	int fd;
 	int err;
+	int cpu;
+	pid_t pid = -1;
 
-	/* check cloexec flag */
-	fd = sys_perf_event_open(&attr, 0, -1, -1,
-				 PERF_FLAG_FD_CLOEXEC);
+	cpu = sched_getcpu();
+	if (cpu < 0)
+		cpu = 0;
+
+	while (1) {
+		/* check cloexec flag */
+		fd = sys_perf_event_open(&attr, pid, cpu, -1,
+					 PERF_FLAG_FD_CLOEXEC);
+		if (fd < 0 && pid == -1 && errno == EACCES) {
+			pid = 0;
+			continue;
+		}
+		break;
+	}
 	err = errno;
 
 	if (fd >= 0) {
@@ -31,7 +45,7 @@ static int perf_flag_probe(void)
 		  err, strerror(err));
 
 	/* not supported, confirm error related to PERF_FLAG_FD_CLOEXEC */
-	fd = sys_perf_event_open(&attr, 0, -1, -1, 0);
+	fd = sys_perf_event_open(&attr, pid, cpu, -1, 0);
 	err = errno;
 
 	if (WARN_ONCE(fd < 0 && err != EBUSY,
-- 
1.8.3.2


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

* Re: [PATCH 1/4] perf tools: Fix CLOEXEC probe for perf_event_paranoid == 2
  2014-08-12 15:04 ` [PATCH 1/4] perf tools: Fix CLOEXEC probe for perf_event_paranoid == 2 Adrian Hunter
@ 2014-08-13  5:33   ` Namhyung Kim
  2014-08-14  8:44   ` [tip:perf/core] " tip-bot for Adrian Hunter
  1 sibling, 0 replies; 15+ messages in thread
From: Namhyung Kim @ 2014-08-13  5:33 UTC (permalink / raw)
  To: Adrian Hunter
  Cc: Arnaldo Carvalho de Melo, Peter Zijlstra, linux-kernel,
	David Ahern, Frederic Weisbecker, Jiri Olsa, Paul Mackerras,
	Stephane Eranian

Hi Adrian,

On Tue, 12 Aug 2014 18:04:28 +0300, Adrian Hunter wrote:
> With /proc/sys/kernel/perf_event_paranoid set to 2, the
> probe of PERF_FLAG_FD_CLOEXEC would fail.  Fix by excluding
> kernel profiling from the probe event.
>
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>

Acked-by: Namhyung Kim <namhyung@kernel.org>

Thanks,
Namhyung


> ---
>  tools/perf/util/cloexec.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/tools/perf/util/cloexec.c b/tools/perf/util/cloexec.c
> index 5073c01..000047c 100644
> --- a/tools/perf/util/cloexec.c
> +++ b/tools/perf/util/cloexec.c
> @@ -11,6 +11,7 @@ static int perf_flag_probe(void)
>  	struct perf_event_attr attr = {
>  		.type = PERF_TYPE_SOFTWARE,
>  		.config = PERF_COUNT_SW_CPU_CLOCK,
> +		.exclude_kernel = 1,
>  	};
>  	int fd;
>  	int err;

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

* Re: [PATCH 2/4] perf tools: Fix one of the probe events to exclude kernel
  2014-08-12 15:04 ` [PATCH 2/4] perf tools: Fix one of the probe events to exclude kernel Adrian Hunter
@ 2014-08-13  5:34   ` Namhyung Kim
  2014-08-14  8:44   ` [tip:perf/core] " tip-bot for Adrian Hunter
  1 sibling, 0 replies; 15+ messages in thread
From: Namhyung Kim @ 2014-08-13  5:34 UTC (permalink / raw)
  To: Adrian Hunter
  Cc: Arnaldo Carvalho de Melo, Peter Zijlstra, linux-kernel,
	David Ahern, Frederic Weisbecker, Jiri Olsa, Paul Mackerras,
	Stephane Eranian

On Tue, 12 Aug 2014 18:04:29 +0300, Adrian Hunter wrote:
> When probing the kernel API the kernel should be excluded
> otherwise the probe will fail for users with insufficient
> privilege to profile the kernel.
>
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>

Acked-by: Namhyung Kim <namhyung@kernel.org>

Thanks,
Namhyung


> ---
>  tools/perf/util/record.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c
> index 787b882..68ad2d0 100644
> --- a/tools/perf/util/record.c
> +++ b/tools/perf/util/record.c
> @@ -47,7 +47,7 @@ out_delete:
>  
>  static bool perf_probe_api(setup_probe_fn_t fn)
>  {
> -	const char *try[] = {"cycles:u", "instructions:u", "cpu-clock", NULL};
> +	const char *try[] = {"cycles:u", "instructions:u", "cpu-clock:u", NULL};
>  	struct cpu_map *cpus;
>  	int cpu, ret, i = 0;

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

* Re: [PATCH 3/4] perf tools: Fix probing the kernel API with cpu-wide events
  2014-08-12 15:04 ` [PATCH 3/4] perf tools: Fix probing the kernel API with cpu-wide events Adrian Hunter
@ 2014-08-13  5:37   ` Namhyung Kim
  2014-08-13  5:51     ` Adrian Hunter
  2014-08-14  8:45   ` [tip:perf/core] " tip-bot for Adrian Hunter
  1 sibling, 1 reply; 15+ messages in thread
From: Namhyung Kim @ 2014-08-13  5:37 UTC (permalink / raw)
  To: Adrian Hunter
  Cc: Arnaldo Carvalho de Melo, Peter Zijlstra, linux-kernel,
	David Ahern, Frederic Weisbecker, Jiri Olsa, Paul Mackerras,
	Stephane Eranian

On Tue, 12 Aug 2014 18:04:30 +0300, Adrian Hunter wrote:
> Fall back to probing with the current pid if cpu-wide
> probing fails.  This primarily affects the setting of
> comm_exec flag when the user is un-privileged and
> /proc/sys/kernel/perf_event_paranoid > 0.  The change
> to comm_exec can be observed by using -vv with
> perf record and a kernel that supports comm_exec.

Maybe I'm missing something - why not just try process-wide probing in
the first place?

Thanks,
Namhyung

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

* Re: [PATCH 3/4] perf tools: Fix probing the kernel API with cpu-wide events
  2014-08-13  5:37   ` Namhyung Kim
@ 2014-08-13  5:51     ` Adrian Hunter
  0 siblings, 0 replies; 15+ messages in thread
From: Adrian Hunter @ 2014-08-13  5:51 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Arnaldo Carvalho de Melo, Peter Zijlstra, linux-kernel,
	David Ahern, Frederic Weisbecker, Jiri Olsa, Paul Mackerras,
	Stephane Eranian

On 08/13/2014 08:37 AM, Namhyung Kim wrote:
> On Tue, 12 Aug 2014 18:04:30 +0300, Adrian Hunter wrote:
>> Fall back to probing with the current pid if cpu-wide
>> probing fails.  This primarily affects the setting of
>> comm_exec flag when the user is un-privileged and
>> /proc/sys/kernel/perf_event_paranoid > 0.  The change
>> to comm_exec can be observed by using -vv with
>> perf record and a kernel that supports comm_exec.
> 
> Maybe I'm missing something - why not just try process-wide probing in
> the first place?

Same reason as patch 4 i.e. to avoid a jump label change when doing
system-wide tracing.


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

* Re: [PATCH 0/4] perf tools: API probing fixes
  2014-08-12 15:04 [PATCH 0/4] perf tools: API probing fixes Adrian Hunter
                   ` (3 preceding siblings ...)
  2014-08-12 15:04 ` [PATCH 4/4] perf tools: Prefer to use a cpu-wide event for probing CLOEXEC Adrian Hunter
@ 2014-08-13 11:28 ` Jiri Olsa
  2014-08-13 19:22   ` Arnaldo Carvalho de Melo
  4 siblings, 1 reply; 15+ messages in thread
From: Jiri Olsa @ 2014-08-13 11:28 UTC (permalink / raw)
  To: Adrian Hunter
  Cc: Arnaldo Carvalho de Melo, Peter Zijlstra, linux-kernel,
	David Ahern, Frederic Weisbecker, Namhyung Kim, Paul Mackerras,
	Stephane Eranian

On Tue, Aug 12, 2014 at 06:04:27PM +0300, Adrian Hunter wrote:
> Hi
> 
> Here are some fixes for API probing issues that I have run into,
> and a second attempt at the jump-label problem.
> 
> Patches apply to your tmp.perf/core branch.
> 
> 
> Adrian Hunter (4):
>       perf tools: Fix CLOEXEC probe for perf_event_paranoid == 2
>       perf tools: Fix one of the probe events to exclude kernel
>       perf tools: Fix probing the kernel API with cpu-wide events
>       perf tools: Prefer to use a cpu-wide event for probing CLOEXEC

for the patchset:

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

thanks,
jirka

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

* Re: [PATCH 0/4] perf tools: API probing fixes
  2014-08-13 11:28 ` [PATCH 0/4] perf tools: API probing fixes Jiri Olsa
@ 2014-08-13 19:22   ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 15+ messages in thread
From: Arnaldo Carvalho de Melo @ 2014-08-13 19:22 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Adrian Hunter, Peter Zijlstra, linux-kernel, David Ahern,
	Frederic Weisbecker, Namhyung Kim, Paul Mackerras,
	Stephane Eranian

Em Wed, Aug 13, 2014 at 01:28:47PM +0200, Jiri Olsa escreveu:
> On Tue, Aug 12, 2014 at 06:04:27PM +0300, Adrian Hunter wrote:
> > Hi
> > 
> > Here are some fixes for API probing issues that I have run into,
> > and a second attempt at the jump-label problem.
> > 
> > Patches apply to your tmp.perf/core branch.
> > 
> > 
> > Adrian Hunter (4):
> >       perf tools: Fix CLOEXEC probe for perf_event_paranoid == 2
> >       perf tools: Fix one of the probe events to exclude kernel
> >       perf tools: Fix probing the kernel API with cpu-wide events
> >       perf tools: Prefer to use a cpu-wide event for probing CLOEXEC
> 
> for the patchset:
> 
> Acked-by: Jiri Olsa <jolsa@kernel.org>

Thanks, applied.

- Arnaldo

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

* [tip:perf/core] perf tools: Fix CLOEXEC probe for perf_event_paranoid == 2
  2014-08-12 15:04 ` [PATCH 1/4] perf tools: Fix CLOEXEC probe for perf_event_paranoid == 2 Adrian Hunter
  2014-08-13  5:33   ` Namhyung Kim
@ 2014-08-14  8:44   ` tip-bot for Adrian Hunter
  1 sibling, 0 replies; 15+ messages in thread
From: tip-bot for Adrian Hunter @ 2014-08-14  8:44 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, linux-kernel, eranian, paulus, hpa, mingo, jolsa, peterz,
	namhyung, namhyung, jolsa, fweisbec, adrian.hunter, dsahern,
	tglx

Commit-ID:  a5b0153c880c2775bf5bdd78306f0a47e860ea04
Gitweb:     http://git.kernel.org/tip/a5b0153c880c2775bf5bdd78306f0a47e860ea04
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Tue, 12 Aug 2014 18:04:28 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 13 Aug 2014 15:58:08 -0300

perf tools: Fix CLOEXEC probe for perf_event_paranoid == 2

With /proc/sys/kernel/perf_event_paranoid set to 2, the probe of
PERF_FLAG_FD_CLOEXEC would fail.  Fix by excluding kernel profiling from
the probe event.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1407855871-15024-2-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/cloexec.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/util/cloexec.c b/tools/perf/util/cloexec.c
index 5073c01..000047c 100644
--- a/tools/perf/util/cloexec.c
+++ b/tools/perf/util/cloexec.c
@@ -11,6 +11,7 @@ static int perf_flag_probe(void)
 	struct perf_event_attr attr = {
 		.type = PERF_TYPE_SOFTWARE,
 		.config = PERF_COUNT_SW_CPU_CLOCK,
+		.exclude_kernel = 1,
 	};
 	int fd;
 	int err;

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

* [tip:perf/core] perf tools: Fix one of the probe events to exclude kernel
  2014-08-12 15:04 ` [PATCH 2/4] perf tools: Fix one of the probe events to exclude kernel Adrian Hunter
  2014-08-13  5:34   ` Namhyung Kim
@ 2014-08-14  8:44   ` tip-bot for Adrian Hunter
  1 sibling, 0 replies; 15+ messages in thread
From: tip-bot for Adrian Hunter @ 2014-08-14  8:44 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, linux-kernel, eranian, paulus, hpa, mingo, jolsa, peterz,
	namhyung, namhyung, jolsa, fweisbec, adrian.hunter, dsahern,
	tglx

Commit-ID:  c6fa35659c5fae5f9aeb6874b177baeb2adbc02e
Gitweb:     http://git.kernel.org/tip/c6fa35659c5fae5f9aeb6874b177baeb2adbc02e
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Tue, 12 Aug 2014 18:04:29 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 13 Aug 2014 16:20:33 -0300

perf tools: Fix one of the probe events to exclude kernel

When probing the kernel API the kernel should be excluded otherwise the
probe will fail for users with insufficient privilege to profile the
kernel.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1407855871-15024-3-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/record.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c
index fe8079e..58267a8 100644
--- a/tools/perf/util/record.c
+++ b/tools/perf/util/record.c
@@ -47,7 +47,7 @@ out_delete:
 
 static bool perf_probe_api(setup_probe_fn_t fn)
 {
-	const char *try[] = {"cycles:u", "instructions:u", "cpu-clock", NULL};
+	const char *try[] = {"cycles:u", "instructions:u", "cpu-clock:u", NULL};
 	struct cpu_map *cpus;
 	int cpu, ret, i = 0;
 

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

* [tip:perf/core] perf tools: Fix probing the kernel API with cpu-wide events
  2014-08-12 15:04 ` [PATCH 3/4] perf tools: Fix probing the kernel API with cpu-wide events Adrian Hunter
  2014-08-13  5:37   ` Namhyung Kim
@ 2014-08-14  8:45   ` tip-bot for Adrian Hunter
  1 sibling, 0 replies; 15+ messages in thread
From: tip-bot for Adrian Hunter @ 2014-08-14  8:45 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, linux-kernel, eranian, paulus, hpa, mingo, jolsa, peterz,
	namhyung, jolsa, fweisbec, adrian.hunter, dsahern, tglx

Commit-ID:  46ec69add5df60310147ce3ce01a662053d82a1e
Gitweb:     http://git.kernel.org/tip/46ec69add5df60310147ce3ce01a662053d82a1e
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Tue, 12 Aug 2014 18:04:30 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 13 Aug 2014 16:22:06 -0300

perf tools: Fix probing the kernel API with cpu-wide events

Fall back to probing with the current pid if cpu-wide probing fails.
This primarily affects the setting of comm_exec flag when the user is
un-privileged and /proc/sys/kernel/perf_event_paranoid > 0.

The change to comm_exec can be observed by using -vv with perf record
and a kernel that supports comm_exec.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1407855871-15024-4-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/record.c | 36 +++++++++++++++++++++++++++---------
 1 file changed, 27 insertions(+), 9 deletions(-)

diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c
index 58267a8..e778afd 100644
--- a/tools/perf/util/record.c
+++ b/tools/perf/util/record.c
@@ -14,6 +14,7 @@ static int perf_do_probe_api(setup_probe_fn_t fn, int cpu, const char *str)
 	struct perf_evsel *evsel;
 	unsigned long flags = perf_event_open_cloexec_flag();
 	int err = -EAGAIN, fd;
+	static pid_t pid = -1;
 
 	evlist = perf_evlist__new();
 	if (!evlist)
@@ -24,14 +25,22 @@ static int perf_do_probe_api(setup_probe_fn_t fn, int cpu, const char *str)
 
 	evsel = perf_evlist__first(evlist);
 
-	fd = sys_perf_event_open(&evsel->attr, -1, cpu, -1, flags);
-	if (fd < 0)
-		goto out_delete;
+	while (1) {
+		fd = sys_perf_event_open(&evsel->attr, pid, cpu, -1, flags);
+		if (fd < 0) {
+			if (pid == -1 && errno == EACCES) {
+				pid = 0;
+				continue;
+			}
+			goto out_delete;
+		}
+		break;
+	}
 	close(fd);
 
 	fn(evsel);
 
-	fd = sys_perf_event_open(&evsel->attr, -1, cpu, -1, flags);
+	fd = sys_perf_event_open(&evsel->attr, pid, cpu, -1, flags);
 	if (fd < 0) {
 		if (errno == EINVAL)
 			err = -EINVAL;
@@ -201,6 +210,7 @@ bool perf_evlist__can_select_event(struct perf_evlist *evlist, const char *str)
 	struct perf_evsel *evsel;
 	int err, fd, cpu;
 	bool ret = false;
+	pid_t pid = -1;
 
 	temp_evlist = perf_evlist__new();
 	if (!temp_evlist)
@@ -221,12 +231,20 @@ bool perf_evlist__can_select_event(struct perf_evlist *evlist, const char *str)
 		cpu = evlist->cpus->map[0];
 	}
 
-	fd = sys_perf_event_open(&evsel->attr, -1, cpu, -1,
-				 perf_event_open_cloexec_flag());
-	if (fd >= 0) {
-		close(fd);
-		ret = true;
+	while (1) {
+		fd = sys_perf_event_open(&evsel->attr, pid, cpu, -1,
+					 perf_event_open_cloexec_flag());
+		if (fd < 0) {
+			if (pid == -1 && errno == EACCES) {
+				pid = 0;
+				continue;
+			}
+			goto out_delete;
+		}
+		break;
 	}
+	close(fd);
+	ret = true;
 
 out_delete:
 	perf_evlist__delete(temp_evlist);

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

* [tip:perf/core] perf tools: Prefer to use a cpu-wide event for probing CLOEXEC
  2014-08-12 15:04 ` [PATCH 4/4] perf tools: Prefer to use a cpu-wide event for probing CLOEXEC Adrian Hunter
@ 2014-08-14  8:45   ` tip-bot for Adrian Hunter
  0 siblings, 0 replies; 15+ messages in thread
From: tip-bot for Adrian Hunter @ 2014-08-14  8:45 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, linux-kernel, eranian, paulus, hpa, mingo, jolsa, peterz,
	namhyung, jolsa, fweisbec, adrian.hunter, dsahern, tglx

Commit-ID:  f6edb53c4993ffe92ce521fb449d1c146cea6ec2
Gitweb:     http://git.kernel.org/tip/f6edb53c4993ffe92ce521fb449d1c146cea6ec2
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Tue, 12 Aug 2014 18:04:31 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 13 Aug 2014 16:24:13 -0300

perf tools: Prefer to use a cpu-wide event for probing CLOEXEC

When doing a system-wide trace with Intel PT, the jump label set up as a
result of probing CLOEXEC gets reset while the trace is running.  That
causes an Intel PT decoding error because the object code (obtained from
/proc/kcore) does not match the running code at that point.  While we
can't expect there never to be jump label changes, we can avoid cases
that the perf tool itself creates.

The problem is avoided by first trying a cpu-wide event (pid = -1) for
probing the PERF_FLAG_FD_CLOEXEC flag and falling back to an event for
the current process (pid = 0).

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1407855871-15024-5-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/cloexec.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/cloexec.c b/tools/perf/util/cloexec.c
index 000047c..4945aa5 100644
--- a/tools/perf/util/cloexec.c
+++ b/tools/perf/util/cloexec.c
@@ -1,3 +1,4 @@
+#include <sched.h>
 #include "util.h"
 #include "../perf.h"
 #include "cloexec.h"
@@ -15,10 +16,23 @@ static int perf_flag_probe(void)
 	};
 	int fd;
 	int err;
+	int cpu;
+	pid_t pid = -1;
 
-	/* check cloexec flag */
-	fd = sys_perf_event_open(&attr, 0, -1, -1,
-				 PERF_FLAG_FD_CLOEXEC);
+	cpu = sched_getcpu();
+	if (cpu < 0)
+		cpu = 0;
+
+	while (1) {
+		/* check cloexec flag */
+		fd = sys_perf_event_open(&attr, pid, cpu, -1,
+					 PERF_FLAG_FD_CLOEXEC);
+		if (fd < 0 && pid == -1 && errno == EACCES) {
+			pid = 0;
+			continue;
+		}
+		break;
+	}
 	err = errno;
 
 	if (fd >= 0) {
@@ -31,7 +45,7 @@ static int perf_flag_probe(void)
 		  err, strerror(err));
 
 	/* not supported, confirm error related to PERF_FLAG_FD_CLOEXEC */
-	fd = sys_perf_event_open(&attr, 0, -1, -1, 0);
+	fd = sys_perf_event_open(&attr, pid, cpu, -1, 0);
 	err = errno;
 
 	if (WARN_ONCE(fd < 0 && err != EBUSY,

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

end of thread, other threads:[~2014-08-14  8:59 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-12 15:04 [PATCH 0/4] perf tools: API probing fixes Adrian Hunter
2014-08-12 15:04 ` [PATCH 1/4] perf tools: Fix CLOEXEC probe for perf_event_paranoid == 2 Adrian Hunter
2014-08-13  5:33   ` Namhyung Kim
2014-08-14  8:44   ` [tip:perf/core] " tip-bot for Adrian Hunter
2014-08-12 15:04 ` [PATCH 2/4] perf tools: Fix one of the probe events to exclude kernel Adrian Hunter
2014-08-13  5:34   ` Namhyung Kim
2014-08-14  8:44   ` [tip:perf/core] " tip-bot for Adrian Hunter
2014-08-12 15:04 ` [PATCH 3/4] perf tools: Fix probing the kernel API with cpu-wide events Adrian Hunter
2014-08-13  5:37   ` Namhyung Kim
2014-08-13  5:51     ` Adrian Hunter
2014-08-14  8:45   ` [tip:perf/core] " tip-bot for Adrian Hunter
2014-08-12 15:04 ` [PATCH 4/4] perf tools: Prefer to use a cpu-wide event for probing CLOEXEC Adrian Hunter
2014-08-14  8:45   ` [tip:perf/core] " tip-bot for Adrian Hunter
2014-08-13 11:28 ` [PATCH 0/4] perf tools: API probing fixes Jiri Olsa
2014-08-13 19:22   ` Arnaldo Carvalho de Melo

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.