From: David Ahern <dsahern@gmail.com>
To: acme@ghostprotocols.net, linux-kernel@vger.kernel.org
Cc: mingo@kernel.org, jolsa@redhat.com,
David Ahern <dsahern@gmail.com>,
Adrian Hunter <adrian.hunter@intel.com>
Subject: [PATCH 3/5] perf tool: Refactor mmap_pages parsing
Date: Tue, 12 Nov 2013 07:46:55 -0700 [thread overview]
Message-ID: <1384267617-3446-4-git-send-email-dsahern@gmail.com> (raw)
In-Reply-To: <1384267617-3446-1-git-send-email-dsahern@gmail.com>
Logic will be re-used for the out-pages argument for mmap based
writes in perf-record.
Signed-off-by: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
---
tools/perf/util/evlist.c | 39 ++++++++++++++++++++++++++++-----------
1 file changed, 28 insertions(+), 11 deletions(-)
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index fb4727d3df85..cb19044601bb 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -705,10 +705,9 @@ static size_t perf_evlist__mmap_size(unsigned long pages)
return (pages + 1) * page_size;
}
-int perf_evlist__parse_mmap_pages(const struct option *opt, const char *str,
- int unset __maybe_unused)
+static long parse_pages_arg(const char *str, unsigned long min,
+ unsigned long max)
{
- unsigned int *mmap_pages = opt->value;
unsigned long pages, val;
static struct parse_tag tags[] = {
{ .tag = 'B', .mult = 1 },
@@ -719,7 +718,7 @@ int perf_evlist__parse_mmap_pages(const struct option *opt, const char *str,
};
if (str == NULL)
- return -1;
+ return -EINVAL;
val = parse_tag_value(str, tags);
if (val != (unsigned long) -1) {
@@ -729,20 +728,38 @@ int perf_evlist__parse_mmap_pages(const struct option *opt, const char *str,
/* we got pages count value */
char *eptr;
pages = strtoul(str, &eptr, 10);
- if (*eptr != '\0') {
- pr_err("failed to parse --mmap_pages/-m value\n");
- return -1;
- }
+ if (*eptr != '\0')
+ return -EINVAL;
}
- if (pages < (1UL << 31) && !is_power_of_2(pages)) {
+ if ((pages == 0) && (min == 0)) {
+ /* leave number of pages at 0 */
+ } else if (pages < (1UL << 31) && !is_power_of_2(pages)) {
+ /* round pages up to next power of 2 */
pages = next_pow2(pages);
pr_info("rounding mmap pages size to %lu bytes (%lu pages)\n",
pages * page_size, pages);
}
- if (pages > UINT_MAX || pages > SIZE_MAX / page_size) {
- pr_err("--mmap_pages/-m value too big\n");
+ if (pages > max)
+ return -EINVAL;
+
+ return pages;
+}
+
+int perf_evlist__parse_mmap_pages(const struct option *opt, const char *str,
+ int unset __maybe_unused)
+{
+ unsigned int *mmap_pages = opt->value;
+ unsigned long max = UINT_MAX;
+ long pages;
+
+ if (max < SIZE_MAX / page_size)
+ max = SIZE_MAX / page_size;
+
+ pages = parse_pages_arg(str, 1, max);
+ if (pages < 0) {
+ pr_err("Invalid argument for --mmap_pages/-m\n");
return -1;
}
--
1.8.3.4 (Apple Git-47)
next prev parent reply other threads:[~2013-11-12 14:47 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-12 14:46 [PATCH 0/5] perf record: mmap output file - v5 David Ahern
2013-11-12 14:46 ` [PATCH 1/5] perf record: Fix segfault with --no-mmap-pages David Ahern
2013-11-12 21:57 ` [tip:perf/urgent] " tip-bot for David Ahern
2013-11-12 14:46 ` [PATCH 2/5] perf tool: Round mmap pages to power 2 - v2 David Ahern
2013-11-12 21:57 ` [tip:perf/urgent] perf evlist: " tip-bot for David Ahern
2013-11-12 14:46 ` David Ahern [this message]
2013-11-12 21:57 ` [tip:perf/urgent] perf evlist: Refactor mmap_pages parsing tip-bot for David Ahern
2013-11-12 14:46 ` [PATCH 4/5] perf record: mmap output file - v5 David Ahern
2013-11-12 14:57 ` Peter Zijlstra
2013-11-12 15:07 ` Arnaldo Carvalho de Melo
2013-11-12 15:19 ` Peter Zijlstra
2013-11-12 15:36 ` David Ahern
2013-11-12 21:11 ` Ingo Molnar
2013-11-13 11:34 ` Peter Zijlstra
2013-11-13 11:50 ` Ingo Molnar
2013-11-13 12:16 ` Peter Zijlstra
2013-11-13 14:29 ` David Ahern
2013-11-15 16:41 ` David Ahern
2013-11-18 9:01 ` Peter Zijlstra
2013-11-18 9:40 ` Ingo Molnar
2013-11-19 0:24 ` Namhyung Kim
2013-11-19 0:34 ` David Ahern
2013-11-19 1:48 ` Namhyung Kim
2013-11-19 2:02 ` Namhyung Kim
2013-11-19 2:13 ` Namhyung Kim
2013-11-19 2:17 ` David Ahern
2013-11-19 2:30 ` Namhyung Kim
2013-11-19 2:33 ` David Ahern
2013-11-19 2:36 ` Namhyung Kim
2013-11-19 6:58 ` Ingo Molnar
2013-11-19 11:48 ` Peter Zijlstra
2013-11-19 11:49 ` Peter Zijlstra
2013-11-19 13:13 ` Ingo Molnar
2013-11-19 13:45 ` Peter Zijlstra
2013-11-19 15:31 ` Ingo Molnar
2013-11-19 16:09 ` David Ahern
2013-11-19 16:14 ` Ingo Molnar
2013-11-19 12:08 ` Peter Zijlstra
2013-11-19 6:54 ` Ingo Molnar
2013-11-12 14:46 ` [PATCH 5/5] perf record: Handle out of space failures writing data with mmap David Ahern
2013-11-12 21:19 ` Ingo Molnar
2013-11-13 14:33 ` David Ahern
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=1384267617-3446-4-git-send-email-dsahern@gmail.com \
--to=dsahern@gmail.com \
--cc=acme@ghostprotocols.net \
--cc=adrian.hunter@intel.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.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 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.