diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2014-12-16 13:19:23 -0300 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2014-12-17 11:58:15 -0300 |
commit | bd1857948e7667313f9a7bee9b2492c0848174a6 (patch) | |
tree | e8d7afe207191f7f5808fa0f5ba62990d1435dc6 /tools | |
parent | 1be300f4cc1ddf975f158b4ab2f880854b29306b (diff) |
tools: Adopt roundup_pow_of_two
To replace equivalent code used in the mmap_pages command line
parameter handling in tools/perf.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-i44zs02xt4zexfxywpklo7km@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/include/linux/log2.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/tools/include/linux/log2.h b/tools/include/linux/log2.h index 990b138362d..41446668ccc 100644 --- a/tools/include/linux/log2.h +++ b/tools/include/linux/log2.h @@ -48,6 +48,15 @@ bool is_power_of_2(unsigned long n) } /* + * round up to nearest power of two + */ +static inline __attribute__((const)) +unsigned long __roundup_pow_of_two(unsigned long n) +{ + return 1UL << fls_long(n - 1); +} + +/* * round down to nearest power of two */ static inline __attribute__((const)) @@ -141,6 +150,22 @@ unsigned long __rounddown_pow_of_two(unsigned long n) __ilog2_u64(n) \ ) +/** + * roundup_pow_of_two - round the given value up to nearest power of two + * @n - parameter + * + * round the given value up to the nearest power of two + * - the result is undefined when n == 0 + * - this can be used to initialise global variables from constant data + */ +#define roundup_pow_of_two(n) \ +( \ + __builtin_constant_p(n) ? ( \ + (n == 1) ? 1 : \ + (1UL << (ilog2((n) - 1) + 1)) \ + ) : \ + __roundup_pow_of_two(n) \ + ) /** * rounddown_pow_of_two - round the given value down to nearest power of two |