diff options
author | Claudio Imbrenda <imbrenda@linux.ibm.com> | 2020-07-06 18:43:23 +0200 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2020-07-06 13:03:51 -0400 |
commit | 9e801bd9d2d4b37bfad26123bcd58548adb0d82c (patch) | |
tree | 03b1c96270ec66cd257f020b44b8779fd876a055 | |
parent | 73f4b202beb399976fcd184bac1a6b7a88373581 (diff) | |
download | kvm-unit-tests-9e801bd9d2d4b37bfad26123bcd58548adb0d82c.tar.gz |
lib/alloc_page: move get_order and is_power_of_2 to a bitops.h
The functions get_order and is_power_of_2 are simple and should
probably be in a header, like similar simple functions in bitops.h
Since they concern bit manipulation, the logical place for them is in
bitops.h
Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Reviewed-by: Andrew Jones <drjones@redhat.com>
Message-Id: <20200706164324.81123-4-imbrenda@linux.ibm.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r-- | lib/alloc.c | 1 | ||||
-rw-r--r-- | lib/alloc_page.c | 5 | ||||
-rw-r--r-- | lib/alloc_page.h | 1 | ||||
-rw-r--r-- | lib/bitops.h | 10 | ||||
-rw-r--r-- | lib/libcflat.h | 5 |
5 files changed, 11 insertions, 11 deletions
diff --git a/lib/alloc.c b/lib/alloc.c index 6c89f98..9d89d24 100644 --- a/lib/alloc.c +++ b/lib/alloc.c @@ -1,4 +1,5 @@ #include "alloc.h" +#include "bitops.h" #include "asm/page.h" #include "bitops.h" diff --git a/lib/alloc_page.c b/lib/alloc_page.c index f16eaad..fa3c527 100644 --- a/lib/alloc_page.c +++ b/lib/alloc_page.c @@ -175,8 +175,3 @@ void page_alloc_ops_enable(void) { alloc_ops = &page_alloc_ops; } - -unsigned int get_order(size_t size) -{ - return is_power_of_2(size) ? fls(size) : fls(size) + 1; -} diff --git a/lib/alloc_page.h b/lib/alloc_page.h index d9aceb7..88540d1 100644 --- a/lib/alloc_page.h +++ b/lib/alloc_page.h @@ -15,6 +15,5 @@ void *alloc_pages(unsigned int order); void free_page(void *page); void free_pages(void *mem, size_t size); void free_pages_by_order(void *mem, unsigned int order); -unsigned int get_order(size_t size); #endif diff --git a/lib/bitops.h b/lib/bitops.h index b310a22..308aa86 100644 --- a/lib/bitops.h +++ b/lib/bitops.h @@ -74,4 +74,14 @@ static inline unsigned long fls(unsigned long word) } #endif +static inline bool is_power_of_2(unsigned long n) +{ + return n && !(n & (n - 1)); +} + +static inline unsigned int get_order(size_t size) +{ + return size ? fls(size) + !is_power_of_2(size) : 0; +} + #endif diff --git a/lib/libcflat.h b/lib/libcflat.h index 7092af2..ec0f58b 100644 --- a/lib/libcflat.h +++ b/lib/libcflat.h @@ -147,11 +147,6 @@ do { \ } \ } while (0) -static inline bool is_power_of_2(unsigned long n) -{ - return n && !(n & (n - 1)); -} - /* * One byte per bit, a ' between each group of 4 bits, and a null terminator. */ |