Bump the version of the library to 1.2 for the visibility of the slice
functions. Use the slice functions in the brk_near_huge test, now that
they are visible. Also fix a corner-case bug in the functions. If the
address passed in is already aligned for the end function, we currently
return the end of the previous slice. This is a problem with the
ALIGN_UP (and ALIGN) macros in general, I think. We don't want to
subtract one from the passed in address (alternatively, callers could
add one to the request, but that seems silly). Fix this.
Tested with a dummy app on x86_64 and all major cases (aligned,
unaligned, 2^{wordsize}-1) give the correct results:
test_addr = 0, slice_start = 0, slice_end = 0x1fffff
test_addr = 0x400000, slice_start = 0x400000, slice_end = 0x5fffff
test_addr = 0x5fffff, slice_start = 0x400000, slice_end = 0x5fffff
test_addr = 0x100000000, slice_start = 0x100000000, slice_end = 0x1001fffff
test_addr = 0xffffffffffffffff, slice_start = 0xffffffffffe00000, slice_end =
0xffffffffffffffff
Signed-off-by: Nishanth Aravamudan <[EMAIL PROTECTED]>
---
hugeutils.c | 4 ++++
libhugetlbfs_internal.h | 2 +-
tests/brk_near_huge.c | 30 ++++++------------------------
tests/hugetests.h | 3 +--
version.lds | 6 ++++++
5 files changed, 18 insertions(+), 27 deletions(-)
diff --git a/hugeutils.c b/hugeutils.c
index 418312e..72b5095 100644
--- a/hugeutils.c
+++ b/hugeutils.c
@@ -138,6 +138,8 @@ unsigned long hugetlbfs_slice_start(unsigned long addr) {
return ALIGN_DOWN(addr, SLICE_HIGH_SIZE);
#elif defined(__powerpc__)
return ALIGN_DOWN(addr, SLICE_LOW_SIZE);
+#elif defined(__ia64__)
+ return 0x8000000000000000UL;
#else
return ALIGN_DOWN(addr, gethugepagesize());
#endif
@@ -151,6 +153,8 @@ unsigned long hugetlbfs_slice_end(unsigned long addr) {
return ALIGN_UP(addr, SLICE_HIGH_SIZE) - 1;
#elif defined(__powerpc__)
return ALIGN_UP(addr, SLICE_LOW_SIZE) - 1;
+#elif defined(__ia64__)
+ return 0xFFFFFFFFFFFFFFFFUL;
#else
return ALIGN_UP(addr, gethugepagesize()) - 1;
#endif
diff --git a/libhugetlbfs_internal.h b/libhugetlbfs_internal.h
index beaa35a..6d6fa1b 100644
--- a/libhugetlbfs_internal.h
+++ b/libhugetlbfs_internal.h
@@ -26,7 +26,7 @@
#define stringify_1(x) #x
#define stringify(x) stringify_1(x)
-#define ALIGN_UP(x, a) (((x) + (a) - 1) & ~((a) - 1))
+#define ALIGN_UP(x, a) (((x) + (a)) & ~((a) - 1))
#define ALIGN_DOWN(x, a) ((x) & ~((a) - 1))
#define ALIGN(x,a) ALIGN_UP(x,a)
diff --git a/tests/brk_near_huge.c b/tests/brk_near_huge.c
index 11ec0cf..6e75e8c 100644
--- a/tests/brk_near_huge.c
+++ b/tests/brk_near_huge.c
@@ -36,33 +36,15 @@
* to oopses or other badness.
*/
-/* Possibly these functions should go in the library itself.. */
-#ifdef __powerpc64__
void *next_chunk(void *addr)
{
- if ((unsigned long)addr < 0x100000000UL)
- /* 256M segments below 4G */
- return PALIGN(addr, 0x10000000UL);
- else
- /* 1TB segments above */
- return PALIGN(addr, 0x10000000000UL);
+ if ((unsigned long)addr ==
+ hugetlbfs_slice_start((unsigned long)addr)) {
+ return addr;
+ } else {
+ return (void *)hugetlbfs_slice_end((unsigned long)addr) + 1UL;
+ }
}
-#elif defined(__powerpc__)
-void *next_chunk(void *addr)
-{
- return PALIGN(addr, 0x10000000UL);
-}
-#elif defined(__ia64__)
-void *next_chunk(void *addr)
-{
- return PALIGN(addr, 0x8000000000000000UL);
-}
-#else
-void *next_chunk(void *addr)
-{
- return PALIGN(addr, gethugepagesize());
-}
-#endif
int main(int argc, char *argv[])
{
diff --git a/tests/hugetests.h b/tests/hugetests.h
index 6eebc63..f0cf9be 100644
--- a/tests/hugetests.h
+++ b/tests/hugetests.h
@@ -34,8 +34,7 @@ void test_init(int argc, char *argv[]);
int test_addr_huge(void *p);
ino_t get_addr_inode(void *p);
-#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
-#define PALIGN(p, a) ((void *)ALIGN((unsigned long)(p), (a)))
+#define ALIGN(x, a) (((x) + (a)) & ~((a) - 1))
#ifndef barrier
# ifdef mb
diff --git a/version.lds b/version.lds
index d64d516..0acdd28 100644
--- a/version.lds
+++ b/version.lds
@@ -7,3 +7,9 @@ VERS_1.0 {
local:
*;
};
+
+VERS_1.2 {
+ global:
+ hugetlbfs_slice_start;
+ hugetlbfs_slice_end;
+} VERS_1.0;
--
Nishanth Aravamudan <[EMAIL PROTECTED]>
IBM Linux Technology Center
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Libhugetlbfs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel