From: Adrian Hunter <adrian.hunter@intel.com>
To: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>,
Ingo Molnar <mingo@redhat.com>,
linux-kernel@vger.kernel.org, David Ahern <dsahern@gmail.com>,
Frederic Weisbecker <fweisbec@gmail.com>,
Jiri Olsa <jolsa@redhat.com>, Mike Galbraith <efault@gmx.de>,
Namhyung Kim <namhyung@gmail.com>,
Paul Mackerras <paulus@samba.org>,
Stephane Eranian <eranian@google.com>
Subject: [PATCH 1/2] perf tools: Fix next_pow2_l()
Date: Fri, 13 Dec 2013 10:53:35 +0200 [thread overview]
Message-ID: <1386924816-24402-2-git-send-email-adrian.hunter@intel.com> (raw)
In-Reply-To: <1386924816-24402-1-git-send-email-adrian.hunter@intel.com>
My implementation of next_pow2_l() was incorrect.
e.g.
perf record -m4296015872 uname
rounding mmap pages size to 17592186044416 bytes (4294967296 pages)
Invalid argument for --mmap_pages/-m
Notice that the next power-of-2 value 4294967296 is
less than the option value 4296015872.
Change to using __builtin_clzl() and prevent the
shift being equal to the width of the operand.
Also __builtin_clzl(x) is undefined if x is 0,
so adjust the condition to preclude that
possibility. Now:
perf record -m4296015872 uname
rounding mmap pages size to 35184372088832 bytes (8589934592 pages)
Invalid argument for --mmap_pages/-m
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
tools/perf/util/util.h | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index a1eea3e..ae609fe 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -284,13 +284,14 @@ static inline unsigned next_pow2(unsigned x)
static inline unsigned long next_pow2_l(unsigned long x)
{
-#if BITS_PER_LONG == 64
- if (x <= (1UL << 31))
- return next_pow2(x);
- return (unsigned long)next_pow2(x >> 32) << 32;
-#else
- return next_pow2(x);
-#endif
+ int leading_zeros;
+
+ if (x < 2)
+ return 1;
+ leading_zeros = __builtin_clzl(x - 1);
+ if (!leading_zeros)
+ return 0;
+ return 1UL << (BITS_PER_LONG - leading_zeros);
}
size_t hex_width(u64 v);
--
1.7.11.7
next prev parent reply other threads:[~2013-12-13 8:53 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-13 8:53 [PATCH 0/2] perf tools: Fix next_pow2_l() Adrian Hunter
2013-12-13 8:53 ` Adrian Hunter [this message]
2013-12-13 14:46 ` [PATCH 1/2] " Arnaldo Carvalho de Melo
2013-12-13 8:53 ` [PATCH 2/2] perf tools: Remove unused next_pow2() and rename next_pow2_l() Adrian Hunter
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=1386924816-24402-2-git-send-email-adrian.hunter@intel.com \
--to=adrian.hunter@intel.com \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@ghostprotocols.net \
--cc=dsahern@gmail.com \
--cc=efault@gmx.de \
--cc=eranian@google.com \
--cc=fweisbec@gmail.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@gmail.com \
--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.