aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorDavid Ahern <dsahern@gmail.com>2013-11-12 09:46:55 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2013-11-12 14:33:22 -0500
commit33c2dcfdfe7f114cc656bcb4c839f5939d5e60ba (patch)
tree6d485107f5eede0d1573f72ff443d286ea3172a9 /tools
parent9639837e95db90d056f4683c911717921519320e (diff)
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@gmail.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jiri Olsa <jolsa@redhat.com> Link: http://lkml.kernel.org/r/1384267617-3446-4-git-send-email-dsahern@gmail.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/util/evlist.c39
1 files 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)
705 return (pages + 1) * page_size; 705 return (pages + 1) * page_size;
706} 706}
707 707
708int perf_evlist__parse_mmap_pages(const struct option *opt, const char *str, 708static long parse_pages_arg(const char *str, unsigned long min,
709 int unset __maybe_unused) 709 unsigned long max)
710{ 710{
711 unsigned int *mmap_pages = opt->value;
712 unsigned long pages, val; 711 unsigned long pages, val;
713 static struct parse_tag tags[] = { 712 static struct parse_tag tags[] = {
714 { .tag = 'B', .mult = 1 }, 713 { .tag = 'B', .mult = 1 },
@@ -719,7 +718,7 @@ int perf_evlist__parse_mmap_pages(const struct option *opt, const char *str,
719 }; 718 };
720 719
721 if (str == NULL) 720 if (str == NULL)
722 return -1; 721 return -EINVAL;
723 722
724 val = parse_tag_value(str, tags); 723 val = parse_tag_value(str, tags);
725 if (val != (unsigned long) -1) { 724 if (val != (unsigned long) -1) {
@@ -729,20 +728,38 @@ int perf_evlist__parse_mmap_pages(const struct option *opt, const char *str,
729 /* we got pages count value */ 728 /* we got pages count value */
730 char *eptr; 729 char *eptr;
731 pages = strtoul(str, &eptr, 10); 730 pages = strtoul(str, &eptr, 10);
732 if (*eptr != '\0') { 731 if (*eptr != '\0')
733 pr_err("failed to parse --mmap_pages/-m value\n"); 732 return -EINVAL;
734 return -1;
735 }
736 } 733 }
737 734
738 if (pages < (1UL << 31) && !is_power_of_2(pages)) { 735 if ((pages == 0) && (min == 0)) {
736 /* leave number of pages at 0 */
737 } else if (pages < (1UL << 31) && !is_power_of_2(pages)) {
738 /* round pages up to next power of 2 */
739 pages = next_pow2(pages); 739 pages = next_pow2(pages);
740 pr_info("rounding mmap pages size to %lu bytes (%lu pages)\n", 740 pr_info("rounding mmap pages size to %lu bytes (%lu pages)\n",
741 pages * page_size, pages); 741 pages * page_size, pages);
742 } 742 }
743 743
744 if (pages > UINT_MAX || pages > SIZE_MAX / page_size) { 744 if (pages > max)
745 pr_err("--mmap_pages/-m value too big\n"); 745 return -EINVAL;
746
747 return pages;
748}
749
750int perf_evlist__parse_mmap_pages(const struct option *opt, const char *str,
751 int unset __maybe_unused)
752{
753 unsigned int *mmap_pages = opt->value;
754 unsigned long max = UINT_MAX;
755 long pages;
756
757 if (max < SIZE_MAX / page_size)
758 max = SIZE_MAX / page_size;
759
760 pages = parse_pages_arg(str, 1, max);
761 if (pages < 0) {
762 pr_err("Invalid argument for --mmap_pages/-m\n");
746 return -1; 763 return -1;
747 } 764 }
748 765