All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nelson Elhage <nelhage@nelhage.com>
To: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>, Ingo Molnar <mingo@elte.hu>,
	Arnaldo Carvalho de Melo <acme@ghostprotocols.net>,
	linux-kernel@vger.kernel.org, Nelson Elhage <nelhage@nelhage.com>
Subject: [PATCH 3/3] perf: builtin-record: Document and check that mmap_pages must be a power of two.
Date: Mon, 19 Dec 2011 08:39:32 -0500	[thread overview]
Message-ID: <1324301972-22740-4-git-send-email-nelhage@nelhage.com> (raw)
In-Reply-To: <1324301972-22740-1-git-send-email-nelhage@nelhage.com>

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.

Signed-off-by: Nelson Elhage <nelhage@nelhage.com>
---
 tools/perf/Documentation/perf-record.txt |    2 +-
 tools/perf/builtin-record.c              |    3 +++
 tools/perf/util/util.h                   |   11 +++++++++++
 3 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
index 5a520f8..2937f7e 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -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::
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 45b23c1..275c78d 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -560,6 +560,9 @@ static int __cmd_record(int argc, const char **argv)
 	if (mmap_pages == UINT_MAX)
 		mmap_pages = (512 * 1024) / page_size;
 
+	if (!is_power_of_2(mmap_pages))
+		die("--mmap_pages/-m value must be a power of two.");
+
 	if (forks) {
 		child_pid = fork();
 		if (child_pid < 0) {
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 0128906..37be34d 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -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
-- 
1.7.4.41.g50b8f


  parent reply	other threads:[~2011-12-19 13:40 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-19 13:39 [PATCH 0/3] perf: builtin-record: Be more helpful when running up against mlock limits Nelson Elhage
2011-12-19 13:39 ` [PATCH 1/3] perf: __perf_evlist__mmap: Fix errno value on failed map Nelson Elhage
2011-12-19 15:33   ` Namhyung Kim
2011-12-19 16:29     ` Arnaldo Carvalho de Melo
2011-12-20 17:55     ` Arnaldo Carvalho de Melo
2011-12-21  8:43   ` [tip:perf/core] perf evlist: Fix errno value reporting on failed mmap tip-bot for Nelson Elhage
2011-12-19 13:39 ` [PATCH 2/3] perf: builtin-record: Provide advice if mmap'ing fails with EPERM Nelson Elhage
2011-12-29 20:50   ` [tip:perf/core] perf: builtin-record: Provide advice if mmap' ing " tip-bot for Nelson Elhage
2011-12-19 13:39 ` Nelson Elhage [this message]
2011-12-29 20:50   ` [tip:perf/core] perf: builtin-record: Document and check that mmap_pages must be a power of two tip-bot for Nelson Elhage

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1324301972-22740-4-git-send-email-nelhage@nelhage.com \
    --to=nelhage@nelhage.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@ghostprotocols.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=paulus@samba.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.