[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <tip-33c2dcfdfe7f114cc656bcb4c839f5939d5e60ba@git.kernel.org>
Date: Tue, 12 Nov 2013 13:57:24 -0800
From: tip-bot for David Ahern <tipbot@...or.com>
To: linux-tip-commits@...r.kernel.org
Cc: acme@...hat.com, linux-kernel@...r.kernel.org, hpa@...or.com,
mingo@...nel.org, jolsa@...hat.com, dsahern@...il.com,
adrian.hunter@...el.com, tglx@...utronix.de
Subject: [tip:perf/urgent] perf evlist: Refactor mmap_pages parsing
Commit-ID: 33c2dcfdfe7f114cc656bcb4c839f5939d5e60ba
Gitweb: http://git.kernel.org/tip/33c2dcfdfe7f114cc656bcb4c839f5939d5e60ba
Author: David Ahern <dsahern@...il.com>
AuthorDate: Tue, 12 Nov 2013 07:46:55 -0700
Committer: Arnaldo Carvalho de Melo <acme@...hat.com>
CommitDate: Tue, 12 Nov 2013 16:33:22 -0300
perf evlist: Refactor mmap_pages parsing
Logic will be re-used for the out-pages argument for mmap based writes
in perf-record.
Signed-off-by: David Ahern <dsahern@...il.com>
Cc: Adrian Hunter <adrian.hunter@...el.com>
Cc: Ingo Molnar <mingo@...nel.org>
Cc: Jiri Olsa <jolsa@...hat.com>
Link: http://lkml.kernel.org/r/1384267617-3446-4-git-send-email-dsahern@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@...hat.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 fb4727d..cb19044 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;
}
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists