public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Robert Richter <rric@kernel.org>
To: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Borislav Petkov <bp@alien8.de>, Jiri Olsa <jolsa@redhat.com>,
	linux-kernel@vger.kernel.org,
	Robert Richter <robert.richter@calxeda.com>
Subject: [PATCH 4/4] perf tools: Retry mapping buffers readonly on EACCES
Date: Fri, 31 May 2013 11:16:25 +0200	[thread overview]
Message-ID: <1369991785-10499-5-git-send-email-rric@kernel.org> (raw)
In-Reply-To: <1369991785-10499-1-git-send-email-rric@kernel.org>

From: Robert Richter <robert.richter@calxeda.com>

Persistent event buffers may only be mmapped readonly. Thus, retry
mapping it readonly if mmap returns EACCES after trying to mmap
writable.

Signed-off-by: Robert Richter <robert.richter@calxeda.com>
---
 tools/perf/builtin-record.c | 7 ++++++-
 tools/perf/builtin-top.c    | 8 ++++++--
 tools/perf/perf.h           | 1 +
 3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index cdf58ec..916776d 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -255,7 +255,12 @@ try_again:
 		goto out;
 	}
 
-	if (perf_evlist__mmap(evlist, opts->mmap_pages, false) < 0) {
+try_again2:
+	if (perf_evlist__mmap(evlist, opts->mmap_pages, opts->mmap_ro) < 0) {
+		if (!opts->mmap_ro && errno == EACCES) {
+			opts->mmap_ro = true;
+			goto try_again2;
+		}
 		if (errno == EPERM) {
 			pr_err("Permission error mapping pages.\n"
 			       "Consider increasing "
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 67bdb9f..2a5757d 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -899,8 +899,12 @@ try_again:
 			goto out_err;
 		}
 	}
-
-	if (perf_evlist__mmap(evlist, opts->mmap_pages, false) < 0) {
+try_again2:
+	if (perf_evlist__mmap(evlist, opts->mmap_pages, opts->mmap_ro) < 0) {
+		if (!opts->mmap_ro && errno == EACCES) {
+			opts->mmap_ro = true;
+			goto try_again2;
+		}
 		ui__error("Failed to mmap with %d (%s)\n",
 			    errno, strerror(errno));
 		goto out_err;
diff --git a/tools/perf/perf.h b/tools/perf/perf.h
index 32bd102..41acea3 100644
--- a/tools/perf/perf.h
+++ b/tools/perf/perf.h
@@ -221,6 +221,7 @@ struct perf_record_opts {
 	bool	     sample_weight;
 	bool	     sample_time;
 	bool	     period;
+	bool	     mmap_ro;
 	unsigned int freq;
 	unsigned int mmap_pages;
 	unsigned int user_freq;
-- 
1.8.1.1


  parent reply	other threads:[~2013-05-31  9:17 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-31  9:16 [PATCH 0/4] perf tools: Persistent events, changes for perf tool integration Robert Richter
2013-05-31  9:16 ` [PATCH 1/4] perf tools: Rename flex conditions to avoid name conflicts Robert Richter
2013-05-31  9:16 ` [PATCH 2/4] perf tools: Modify event parser to update event attribute by index Robert Richter
2013-05-31  9:16 ` [PATCH 3/4] perf tools: Add attr<num> syntax to event parser Robert Richter
2013-06-03 13:54   ` Jiri Olsa
2013-06-07 14:17     ` Robert Richter
2013-05-31  9:16 ` Robert Richter [this message]
2013-06-14  2:08   ` [PATCH 4/4] perf tools: Retry mapping buffers readonly on EACCES Namhyung Kim
2013-06-14  7:29     ` Robert Richter
2013-05-31 12:07 ` [PATCH 0/4] perf tools: Persistent events, changes for perf tool integration Ingo Molnar
2013-05-31 12:24   ` Borislav Petkov
2013-05-31 12:48     ` Ingo Molnar
2013-05-31 13:44       ` Robert Richter
2013-05-31 15:31       ` Borislav Petkov

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=1369991785-10499-5-git-send-email-rric@kernel.org \
    --to=rric@kernel.org \
    --cc=acme@ghostprotocols.net \
    --cc=bp@alien8.de \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=robert.richter@calxeda.com \
    /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