public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>,
	linux-kernel@vger.kernel.org, David Ahern <dsahern@gmail.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@gmail.com>,
	Paul Mackerras <paulus@samba.org>,
	Stephane Eranian <eranian@google.com>
Subject: [PATCH 4/4] perf tools: Prefer to use a cpu-wide event for probing CLOEXEC
Date: Tue, 12 Aug 2014 18:04:31 +0300	[thread overview]
Message-ID: <1407855871-15024-5-git-send-email-adrian.hunter@intel.com> (raw)
In-Reply-To: <1407855871-15024-1-git-send-email-adrian.hunter@intel.com>

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


  parent reply	other threads:[~2014-08-12 15:06 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Adrian Hunter [this message]
2014-08-14  8:45   ` [tip:perf/core] perf tools: Prefer to use a cpu-wide event for probing CLOEXEC 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1407855871-15024-5-git-send-email-adrian.hunter@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=acme@kernel.org \
    --cc=dsahern@gmail.com \
    --cc=eranian@google.com \
    --cc=fweisbec@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=namhyung@gmail.com \
    --cc=paulus@samba.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox