lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Date:	Wed, 17 Dec 2014 22:32:44 -0800
From:	tip-bot for Arnaldo Carvalho de Melo <tipbot@...or.com>
To:	linux-tip-commits@...r.kernel.org
Cc:	fweisbec@...il.com, mingo@...nel.org, tglx@...utronix.de,
	paulus@...ba.org, eranian@...gle.com, efault@....de, bp@...e.de,
	acme@...hat.com, jolsa@...hat.com, dzickus@...hat.com,
	peterz@...radead.org, hpa@...or.com, adrian.hunter@...el.com,
	linux-kernel@...r.kernel.org, namhyung@...nel.org,
	dsahern@...il.com
Subject: [tip:perf/urgent] tools: Adopt roundup_pow_of_two

Commit-ID:  bd1857948e7667313f9a7bee9b2492c0848174a6
Gitweb:     http://git.kernel.org/tip/bd1857948e7667313f9a7bee9b2492c0848174a6
Author:     Arnaldo Carvalho de Melo <acme@...hat.com>
AuthorDate: Tue, 16 Dec 2014 13:19:23 -0300
Committer:  Arnaldo Carvalho de Melo <acme@...hat.com>
CommitDate: Wed, 17 Dec 2014 11:58:15 -0300

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@...el.com>
Cc: Borislav Petkov <bp@...e.de>
Cc: David Ahern <dsahern@...il.com>
Cc: Don Zickus <dzickus@...hat.com>
Cc: Frederic Weisbecker <fweisbec@...il.com>
Cc: Jiri Olsa <jolsa@...hat.com>
Cc: Mike Galbraith <efault@....de>
Cc: Namhyung Kim <namhyung@...nel.org>
Cc: Paul Mackerras <paulus@...ba.org>
Cc: Peter Zijlstra <peterz@...radead.org>
Cc: Stephane Eranian <eranian@...gle.com>
Link: http://lkml.kernel.org/n/tip-i44zs02xt4zexfxywpklo7km@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@...hat.com>
---
 tools/include/linux/log2.h | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/tools/include/linux/log2.h b/tools/include/linux/log2.h
index 990b138..4144666 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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ