[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[kvm-unit-tests PATCH v7 02/13] page_alloc: Introduce get_order()
From: |
Eric Auger |
Subject: |
[kvm-unit-tests PATCH v7 02/13] page_alloc: Introduce get_order() |
Date: |
Fri, 20 Mar 2020 10:24:17 +0100 |
Compute the power of 2 order of a size. Use it in
page_memalign. Other users are looming.
Signed-off-by: Eric Auger <address@hidden>
---
lib/alloc_page.c | 7 ++++++-
lib/alloc_page.h | 1 +
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/lib/alloc_page.c b/lib/alloc_page.c
index ed23638..7c8461a 100644
--- a/lib/alloc_page.c
+++ b/lib/alloc_page.c
@@ -155,7 +155,7 @@ static void *page_memalign(size_t alignment, size_t size)
if (!size)
return NULL;
- order = is_power_of_2(n) ? fls(n) : fls(n) + 1;
+ order = get_order(n);
return alloc_pages(order);
}
@@ -175,3 +175,8 @@ void page_alloc_ops_enable(void)
{
alloc_ops = &page_alloc_ops;
}
+
+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 739a91d..e6a51d2 100644
--- a/lib/alloc_page.h
+++ b/lib/alloc_page.h
@@ -15,5 +15,6 @@ void *alloc_pages(unsigned long order);
void free_page(void *page);
void free_pages(void *mem, unsigned long size);
void free_pages_by_order(void *mem, unsigned long order);
+int get_order(size_t size);
#endif
--
2.20.1
- [kvm-unit-tests PATCH v7 00/13] arm/arm64: Add ITS tests, Eric Auger, 2020/03/20
- [kvm-unit-tests PATCH v7 01/13] libcflat: Add other size defines, Eric Auger, 2020/03/20
- [kvm-unit-tests PATCH v7 02/13] page_alloc: Introduce get_order(),
Eric Auger <=
- [kvm-unit-tests PATCH v7 03/13] arm/arm64: gic: Introduce setup_irq() helper, Eric Auger, 2020/03/20
- [kvm-unit-tests PATCH v7 04/13] arm/arm64: gicv3: Add some re-distributor defines, Eric Auger, 2020/03/20
- [kvm-unit-tests PATCH v7 05/13] arm/arm64: gicv3: Set the LPI config and pending tables, Eric Auger, 2020/03/20
- [kvm-unit-tests PATCH v7 06/13] arm/arm64: ITS: Introspection tests, Eric Auger, 2020/03/20
- Re: [kvm-unit-tests PATCH v7 06/13] arm/arm64: ITS: Introspection tests, Zenghui Yu, 2020/03/30
- Re: [kvm-unit-tests PATCH v7 06/13] arm/arm64: ITS: Introspection tests, Auger Eric, 2020/03/30
- Re: [kvm-unit-tests PATCH v7 06/13] arm/arm64: ITS: Introspection tests, Andrew Jones, 2020/03/30
- Re: [kvm-unit-tests PATCH v7 06/13] arm/arm64: ITS: Introspection tests, Auger Eric, 2020/03/30
- Re: [kvm-unit-tests PATCH v7 06/13] arm/arm64: ITS: Introspection tests, Andrew Jones, 2020/03/30
- Re: [kvm-unit-tests PATCH v7 06/13] arm/arm64: ITS: Introspection tests, Auger Eric, 2020/03/30