aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/evlist.c
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@redhat.com>2013-09-01 06:36:12 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2013-10-09 10:24:10 -0400
commit994a1f78b191df0c9d6caca3f3afb03e247aff26 (patch)
tree387ca6391f946bbbca73a579105ee0bc2ba76ad8 /tools/perf/util/evlist.c
parentf37376cd721a539ac398cbb7718b72fce83cd49b (diff)
perf tools: Check mmap pages value early
Move the check of the mmap_pages value to the options parsing time, so we could rely on this value on other parts of code. Related changes come in the next patches. Also changes perf_evlist::mmap_len to proper size_t type. Signed-off-by: Jiri Olsa <jolsa@redhat.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/r/1378031796-17892-2-git-send-email-jolsa@redhat.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/evlist.c')
-rw-r--r--tools/perf/util/evlist.c46
1 files changed, 37 insertions, 9 deletions
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index f9f77bee0b1b..4283f49ca0ab 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -18,6 +18,7 @@
18#include <unistd.h> 18#include <unistd.h>
19 19
20#include "parse-events.h" 20#include "parse-events.h"
21#include "parse-options.h"
21 22
22#include <sys/mman.h> 23#include <sys/mman.h>
23 24
@@ -672,6 +673,40 @@ out_unmap:
672 return -1; 673 return -1;
673} 674}
674 675
676static size_t perf_evlist__mmap_size(unsigned long pages)
677{
678 /* 512 kiB: default amount of unprivileged mlocked memory */
679 if (pages == UINT_MAX)
680 pages = (512 * 1024) / page_size;
681 else if (!is_power_of_2(pages))
682 return 0;
683
684 return (pages + 1) * page_size;
685}
686
687int perf_evlist__parse_mmap_pages(const struct option *opt, const char *str,
688 int unset __maybe_unused)
689{
690 unsigned int pages, *mmap_pages = opt->value;
691 size_t size;
692 char *eptr;
693
694 pages = strtoul(str, &eptr, 10);
695 if (*eptr != '\0') {
696 pr_err("failed to parse --mmap_pages/-m value\n");
697 return -1;
698 }
699
700 size = perf_evlist__mmap_size(pages);
701 if (!size) {
702 pr_err("--mmap_pages/-m value must be a power of two.");
703 return -1;
704 }
705
706 *mmap_pages = pages;
707 return 0;
708}
709
675/** perf_evlist__mmap - Create per cpu maps to receive events 710/** perf_evlist__mmap - Create per cpu maps to receive events
676 * 711 *
677 * @evlist - list of events 712 * @evlist - list of events
@@ -695,14 +730,6 @@ int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages,
695 const struct thread_map *threads = evlist->threads; 730 const struct thread_map *threads = evlist->threads;
696 int prot = PROT_READ | (overwrite ? 0 : PROT_WRITE), mask; 731 int prot = PROT_READ | (overwrite ? 0 : PROT_WRITE), mask;
697 732
698 /* 512 kiB: default amount of unprivileged mlocked memory */
699 if (pages == UINT_MAX)
700 pages = (512 * 1024) / page_size;
701 else if (!is_power_of_2(pages))
702 return -EINVAL;
703
704 mask = pages * page_size - 1;
705
706 if (evlist->mmap == NULL && perf_evlist__alloc_mmap(evlist) < 0) 733 if (evlist->mmap == NULL && perf_evlist__alloc_mmap(evlist) < 0)
707 return -ENOMEM; 734 return -ENOMEM;
708 735
@@ -710,7 +737,8 @@ int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages,
710 return -ENOMEM; 737 return -ENOMEM;
711 738
712 evlist->overwrite = overwrite; 739 evlist->overwrite = overwrite;
713 evlist->mmap_len = (pages + 1) * page_size; 740 evlist->mmap_len = perf_evlist__mmap_size(pages);
741 mask = evlist->mmap_len - page_size - 1;
714 742
715 list_for_each_entry(evsel, &evlist->entries, node) { 743 list_for_each_entry(evsel, &evlist->entries, node) {
716 if ((evsel->attr.read_format & PERF_FORMAT_ID) && 744 if ((evsel->attr.read_format & PERF_FORMAT_ID) &&