* [PATCH 0/2] perf tools: Fix next_pow2_l()
@ 2013-12-13 8:53 Adrian Hunter
2013-12-13 8:53 ` [PATCH 1/2] " Adrian Hunter
2013-12-13 8:53 ` [PATCH 2/2] perf tools: Remove unused next_pow2() and rename next_pow2_l() Adrian Hunter
0 siblings, 2 replies; 4+ messages in thread
From: Adrian Hunter @ 2013-12-13 8:53 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Peter Zijlstra, Ingo Molnar, linux-kernel, David Ahern,
Frederic Weisbecker, Jiri Olsa, Mike Galbraith, Namhyung Kim,
Paul Mackerras, Stephane Eranian
Hi
My implementation of next_pow2_l() was incorrect.
Here is a fix, after which next_pow2() is unused
so I remove it and rename next_pow2_l() -> next_pow2()
Adrian Hunter (2):
perf tools: Fix next_pow2_l()
perf tools: Remove unused next_pow2() and rename next_pow2_l()
tools/perf/util/evlist.c | 2 +-
tools/perf/util/util.h | 22 ++++++++--------------
2 files changed, 9 insertions(+), 15 deletions(-)
Regards
Adrian
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] perf tools: Fix next_pow2_l()
2013-12-13 8:53 [PATCH 0/2] perf tools: Fix next_pow2_l() Adrian Hunter
@ 2013-12-13 8:53 ` Adrian Hunter
2013-12-13 14:46 ` 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
1 sibling, 1 reply; 4+ messages in thread
From: Adrian Hunter @ 2013-12-13 8:53 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Peter Zijlstra, Ingo Molnar, linux-kernel, David Ahern,
Frederic Weisbecker, Jiri Olsa, Mike Galbraith, Namhyung Kim,
Paul Mackerras, Stephane Eranian
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] perf tools: Remove unused next_pow2() and rename next_pow2_l()
2013-12-13 8:53 [PATCH 0/2] perf tools: Fix next_pow2_l() Adrian Hunter
2013-12-13 8:53 ` [PATCH 1/2] " Adrian Hunter
@ 2013-12-13 8:53 ` Adrian Hunter
1 sibling, 0 replies; 4+ messages in thread
From: Adrian Hunter @ 2013-12-13 8:53 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Peter Zijlstra, Ingo Molnar, linux-kernel, David Ahern,
Frederic Weisbecker, Jiri Olsa, Mike Galbraith, Namhyung Kim,
Paul Mackerras, Stephane Eranian
The fixed version of 'next_pow2_l()' does not call
'next_pow2()' anymore, so it is unused, so remove
it and rename 'next_pow2_l()' to 'next_pow2()'.
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
tools/perf/util/evlist.c | 2 +-
tools/perf/util/util.h | 9 +--------
2 files changed, 2 insertions(+), 9 deletions(-)
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 0b31cee..327a1a4 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -736,7 +736,7 @@ static long parse_pages_arg(const char *str, unsigned long min,
/* leave number of pages at 0 */
} else if (!is_power_of_2(pages)) {
/* round pages up to next power of 2 */
- pages = next_pow2_l(pages);
+ pages = next_pow2(pages);
if (!pages)
return -EINVAL;
pr_info("rounding mmap pages size to %lu bytes (%lu pages)\n",
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index ae609fe..3860d76 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -275,14 +275,7 @@ bool is_power_of_2(unsigned long n)
return (n != 0 && ((n & (n - 1)) == 0));
}
-static inline unsigned next_pow2(unsigned x)
-{
- if (!x)
- return 1;
- return 1ULL << (32 - __builtin_clz(x - 1));
-}
-
-static inline unsigned long next_pow2_l(unsigned long x)
+static inline unsigned long next_pow2(unsigned long x)
{
int leading_zeros;
--
1.7.11.7
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] perf tools: Fix next_pow2_l()
2013-12-13 8:53 ` [PATCH 1/2] " Adrian Hunter
@ 2013-12-13 14:46 ` Arnaldo Carvalho de Melo
0 siblings, 0 replies; 4+ messages in thread
From: Arnaldo Carvalho de Melo @ 2013-12-13 14:46 UTC (permalink / raw)
To: Adrian Hunter
Cc: Peter Zijlstra, Ingo Molnar, linux-kernel, David Ahern,
Frederic Weisbecker, Jiri Olsa, Mike Galbraith, Namhyung Kim,
Paul Mackerras, Stephane Eranian
Em Fri, Dec 13, 2013 at 10:53:35AM +0200, Adrian Hunter escreveu:
> 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:
Can we try to look first if there is an implementation for what we need
being used in the kernel sources, in include/ and then try to use, if
possible, exactly like done in kernel code?
For instance, include/linux/log2.h has roundup_pow_of_two() that seems
to be what you need, lemme check...
roundup_pow_of_two(4296015872)=8589934592
So, it yields what we need, I'll try to cook up a patch that makes us
use it, as I did in my dwarves tools in this changeset:
https://git.kernel.org/cgit/devel/pahole/pahole.git/commit/?id=e31fda3063e3c88ca0b93a9fb5e6d6e32478e36b
- Arnaldo
> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-12-13 14:46 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-13 8:53 [PATCH 0/2] perf tools: Fix next_pow2_l() Adrian Hunter
2013-12-13 8:53 ` [PATCH 1/2] " Adrian Hunter
2013-12-13 14:46 ` 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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox