Commit 41d0d933 authored by Nelson Elhage's avatar Nelson Elhage Committed by Arnaldo Carvalho de Melo

perf: builtin-record: Document and check that mmap_pages must be a power of two.

Now that we automatically point users at it, let's provide them some
guidance so that they hopefully don't just get mysterious EINVAL's
from the kernel.

Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1324301972-22740-4-git-send-email-nelhage@nelhage.comSigned-off-by: default avatarNelson Elhage <nelhage@nelhage.com>
[ committer note: Made it work after 50a682ce ]
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 18e60939
...@@ -89,7 +89,7 @@ OPTIONS ...@@ -89,7 +89,7 @@ OPTIONS
-m:: -m::
--mmap-pages=:: --mmap-pages=::
Number of mmap data pages. Number of mmap data pages. Must be a power of two.
-g:: -g::
--call-graph:: --call-graph::
......
...@@ -279,6 +279,9 @@ static void perf_record__open(struct perf_record *rec) ...@@ -279,6 +279,9 @@ static void perf_record__open(struct perf_record *rec)
"/proc/sys/kernel/perf_event_mlock_kb,\n" "/proc/sys/kernel/perf_event_mlock_kb,\n"
"or try again with a smaller value of -m/--mmap_pages.\n" "or try again with a smaller value of -m/--mmap_pages.\n"
"(current value: %d)\n", opts->mmap_pages); "(current value: %d)\n", opts->mmap_pages);
else if (!is_power_of_2(opts->mmap_pages))
die("--mmap_pages/-m value must be a power of two.");
die("failed to mmap with %d (%s)\n", errno, strerror(errno)); die("failed to mmap with %d (%s)\n", errno, strerror(errno));
} }
......
...@@ -563,6 +563,8 @@ int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages, ...@@ -563,6 +563,8 @@ int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages,
/* 512 kiB: default amount of unprivileged mlocked memory */ /* 512 kiB: default amount of unprivileged mlocked memory */
if (pages == UINT_MAX) if (pages == UINT_MAX)
pages = (512 * 1024) / page_size; pages = (512 * 1024) / page_size;
else if (!is_power_of_2(pages))
return -EINVAL;
mask = pages * page_size - 1; mask = pages * page_size - 1;
......
...@@ -245,4 +245,15 @@ int readn(int fd, void *buf, size_t size); ...@@ -245,4 +245,15 @@ int readn(int fd, void *buf, size_t size);
#define _STR(x) #x #define _STR(x) #x
#define STR(x) _STR(x) #define STR(x) _STR(x)
/*
* Determine whether some value is a power of two, where zero is
* *not* considered a power of two.
*/
static inline __attribute__((const))
bool is_power_of_2(unsigned long n)
{
return (n != 0 && ((n & (n - 1)) == 0));
}
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment