[PATCH] log2.h: Define order_base_2() macro for convenience.

Previous thread: NFSv4 broken in -mm (MMOM "10-Nov-2007 22:46") by Erez Zadok on Saturday, November 10, 2007 - 8:32 pm. (1 message)

Next thread: [RFC: 2.6 patch] MAINTAINERS: remove the MTRR entry by Adrian Bunk on Saturday, November 10, 2007 - 11:48 pm. (1 message)
From: Robert P. J. Day
Date: Saturday, November 10, 2007 - 8:53 pm

Given a number of places in the tree that need to calculate this value
explicitly, might as well just create a macro for it.

Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>

---

  run-time tested for the first several values.  note that this macro
is defined strictly in terms of rounding *up* -- i've seen no places
in the tree that require this expression to be rounded down, so i'm
not drawing that distinction.

diff --git a/include/linux/log2.h b/include/linux/log2.h
index c8cf5e8..ed121c0 100644
--- a/include/linux/log2.h
+++ b/include/linux/log2.h
@@ -190,4 +190,20 @@ unsigned long __rounddown_pow_of_two(unsigned long n)
 	__rounddown_pow_of_two(n)		\
  )

+/**
+ * order_base_2 - calculate the (rounded up) base 2 order of the argument
+ * @n - parameter
+ *
+ * The first few values calculated by this routine:
+ *  ob2(0) = 0
+ *  ob2(1) = 0
+ *  ob2(2) = 1
+ *  ob2(3) = 2
+ *  ob2(4) = 2
+ *  ob2(5) = 3
+ *  ... and so on.
+ */
+
+#define order_base_2(n) ilog2(roundup_pow_of_two(n))
+
 #endif /* _LINUX_LOG2_H */

-- 
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA

http://crashcourse.ca
========================================================================
-

From: Randy Dunlap
Date: Sunday, November 11, 2007 - 11:28 am

* @n: argument


---
~Randy
-

From: Robert P. J. Day
Date: Monday, November 12, 2007 - 12:27 am

ah, yes, fix coming shortly.

rday
-

Previous thread: NFSv4 broken in -mm (MMOM "10-Nov-2007 22:46") by Erez Zadok on Saturday, November 10, 2007 - 8:32 pm. (1 message)

Next thread: [RFC: 2.6 patch] MAINTAINERS: remove the MTRR entry by Adrian Bunk on Saturday, November 10, 2007 - 11:48 pm. (1 message)