perf: builtin-record: Document and check that mmap_pages must be a power of two.
authorNelson Elhage <nelhage@nelhage.com>
Mon, 19 Dec 2011 13:39:32 +0000 (08:39 -0500)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 23 Dec 2011 18:53:58 +0000 (16:53 -0200)
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.com
Signed-off-by: Nelson Elhage <nelhage@nelhage.com>
[ committer note: Made it work after 50a682c ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/Documentation/perf-record.txt
tools/perf/builtin-record.c
tools/perf/util/evlist.c
tools/perf/util/util.h

index 5a520f8252956cd66dd5c3321be04200e3519846..2937f7e14bb74908e7d753dc9480055430c2d3b0 100644 (file)
@@ -89,7 +89,7 @@ OPTIONS
 
 -m::
 --mmap-pages=::
-       Number of mmap data pages.
+       Number of mmap data pages. Must be a power of two.
 
 -g::
 --call-graph::
index 56bb4476e3ba09b24253321cde35deeb62f3c5c0..e873ae2dd54c06eb848b79d7d2c0eb49d4420e35 100644 (file)
@@ -279,6 +279,9 @@ try_again:
                            "/proc/sys/kernel/perf_event_mlock_kb,\n"
                            "or try again with a smaller value of -m/--mmap_pages.\n"
                            "(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));
        }
 
index 963d63dde457bba5a32211c086064e0a045e7f8a..fa1837088ca880ca5968709326e94f22fa436db4 100644 (file)
@@ -563,6 +563,8 @@ int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages,
         /* 512 kiB: default amount of unprivileged mlocked memory */
         if (pages == UINT_MAX)
                 pages = (512 * 1024) / page_size;
+       else if (!is_power_of_2(pages))
+               return -EINVAL;
 
        mask = pages * page_size - 1;
 
index 0128906bac88d258e9e100aeabae5abd462e465b..37be34dff7983c2834b051bc8cc3347ab213383b 100644 (file)
@@ -245,4 +245,15 @@ int readn(int fd, void *buf, size_t size);
 #define _STR(x) #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