Skip to content

Commit 41d0d93

Browse files
nelhageacmel
authored andcommitted
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.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>
1 parent 18e6093 commit 41d0d93

4 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎tools/perf/Documentation/perf-record.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ OPTIONS
8989

9090
-m::
9191
--mmap-pages=::
92-
Number of mmap data pages.
92+
Number of mmap data pages. Must be a power of two.
9393

9494
-g::
9595
--call-graph::

‎tools/perf/builtin-record.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,9 @@ static void perf_record__open(struct perf_record *rec)
279279
"/proc/sys/kernel/perf_event_mlock_kb,\n"
280280
"or try again with a smaller value of -m/--mmap_pages.\n"
281281
"(current value: %d)\n", opts->mmap_pages);
282+
else if (!is_power_of_2(opts->mmap_pages))
283+
die("--mmap_pages/-m value must be a power of two.");
284+
282285
die("failed to mmap with %d (%s)\n", errno, strerror(errno));
283286
}
284287

‎tools/perf/util/evlist.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,8 @@ int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages,
563563
/* 512 kiB: default amount of unprivileged mlocked memory */
564564
if (pages == UINT_MAX)
565565
pages = (512 * 1024) / page_size;
566+
else if (!is_power_of_2(pages))
567+
return -EINVAL;
566568

567569
mask = pages * page_size - 1;
568570

‎tools/perf/util/util.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,4 +245,15 @@ int readn(int fd, void *buf, size_t size);
245245
#define _STR(x) #x
246246
#define STR(x) _STR(x)
247247

248+
/*
249+
* Determine whether some value is a power of two, where zero is
250+
* *not* considered a power of two.
251+
*/
252+
253+
static inline __attribute__((const))
254+
bool is_power_of_2(unsigned long n)
255+
{
256+
return (n != 0 && ((n & (n - 1)) == 0));
257+
}
258+
248259
#endif

0 commit comments

Comments
 (0)