From: Robert Richter <rric@kernel.org>
To: Arnaldo Carvalho de Melo <acme@infradead.org>
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@kernel.org>, Borislav Petkov <bp@alien8.de>,
Jiri Olsa <jolsa@redhat.com>,
linux-kernel@vger.kernel.org,
Robert Richter <robert.richter@linaro.org>,
Robert Richter <rric@kernel.org>
Subject: [PATCH resent 4/4] perf tools: Retry mapping buffers readonly on EACCES
Date: Thu, 22 Aug 2013 16:44:05 +0200 [thread overview]
Message-ID: <1377182645-12922-5-git-send-email-rric@kernel.org> (raw)
In-Reply-To: <1377182645-12922-1-git-send-email-rric@kernel.org>
From: Robert Richter <robert.richter@linaro.org>
Persistent event buffers may only be mmapped readonly. Thus, retry
mapping it readonly if mmap returns EACCES after trying to mmap
writable.
[ namhyung: Don't write to readonly mmap'ed buffers. ]
Signed-off-by: Robert Richter <robert.richter@linaro.org>
Signed-off-by: Robert Richter <rric@kernel.org>
---
tools/perf/builtin-record.c | 11 ++++++++---
tools/perf/builtin-top.c | 8 ++++++--
tools/perf/perf.h | 1 +
3 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index a41ac415..f3f7483 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -152,8 +152,8 @@ static int perf_record__mmap_read(struct perf_record *rec,
}
md->prev = old;
- perf_mmap__write_tail(md, old);
-
+ if (!rec->opts.mmap_ro)
+ perf_mmap__write_tail(md, old);
out:
return rc;
}
@@ -226,7 +226,12 @@ static int perf_record__open(struct perf_record *rec)
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 e37521f..bef7b1d 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -894,8 +894,12 @@ static int perf_top__start_counters(struct perf_top *top)
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 cf20187..dca43c72 100644
--- a/tools/perf/perf.h
+++ b/tools/perf/perf.h
@@ -224,6 +224,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.3.2
prev parent reply other threads:[~2013-08-22 14:44 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-22 14:44 [PATCH resent 0/4] perf tools: Persistent events, changes for perf tool integration Robert Richter
2013-08-22 14:44 ` [PATCH resent 1/4] perf tools: Rename flex conditions to avoid name conflicts Robert Richter
2013-08-22 14:44 ` [PATCH resent 2/4] perf tools: Modify event parser to update event attribute by index Robert Richter
2013-08-22 14:44 ` [PATCH resent 3/4] perf tools: Add attr<num> syntax to event parser Robert Richter
2013-08-22 14:44 ` Robert Richter [this message]
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=1377182645-12922-5-git-send-email-rric@kernel.org \
--to=rric@kernel.org \
--cc=acme@infradead.org \
--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@linaro.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;
as well as URLs for NNTP newsgroup(s).