[Openmp-commits] [openmp] r285243 - Use getpagesize() instead of PAGE_SIZE macro when KMP_OS_LINUX is true

Jonathan Peyton via Openmp-commits openmp-commits at lists.llvm.org
Wed Oct 26 14:42:48 PDT 2016


Author: jlpeyton
Date: Wed Oct 26 16:42:48 2016
New Revision: 285243

URL: http://llvm.org/viewvc/llvm-project?rev=285243&view=rev
Log:
Use getpagesize() instead of PAGE_SIZE macro when KMP_OS_LINUX is true

Patch by Victor Campos

Differential Revision: https://reviews.llvm.org/D26001

Modified:
    openmp/trunk/runtime/src/kmp_alloc.c
    openmp/trunk/runtime/src/kmp_os.h
    openmp/trunk/runtime/src/kmp_runtime.c

Modified: openmp/trunk/runtime/src/kmp_alloc.c
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/kmp_alloc.c?rev=285243&r1=285242&r2=285243&view=diff
==============================================================================
--- openmp/trunk/runtime/src/kmp_alloc.c (original)
+++ openmp/trunk/runtime/src/kmp_alloc.c Wed Oct 26 16:42:48 2016
@@ -1719,13 +1719,8 @@ void *
 __kmp_ft_page_allocate(size_t size)
 {
   void *adr, *aadr;
-#if KMP_OS_LINUX
-  /* TODO: Use this function to get page size everywhere */
-  int page_size = getpagesize();
-#else
-  /* TODO: Find windows function to get page size and use it everywhere */
-  int page_size = PAGE_SIZE;
-#endif /* KMP_OS_LINUX */
+
+  const int page_size = KMP_GET_PAGE_SIZE();
 
   adr = (void *) __kmp_thread_malloc( __kmp_get_thread(),
                                     size + page_size + KMP_PTR_SKIP);

Modified: openmp/trunk/runtime/src/kmp_os.h
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/kmp_os.h?rev=285243&r1=285242&r2=285243&view=diff
==============================================================================
--- openmp/trunk/runtime/src/kmp_os.h (original)
+++ openmp/trunk/runtime/src/kmp_os.h Wed Oct 26 16:42:48 2016
@@ -236,9 +236,18 @@ typedef double  kmp_real64;
 #endif
 
 #define PAGE_SIZE                       (0x4000)
+
+#if KMP_OS_LINUX
+#define KMP_GET_PAGE_SIZE() getpagesize()
+#else
+// TODO: find the corresponding function to getpagesize() in Windows
+// and use it whenever possible.
+#define KMP_GET_PAGE_SIZE() PAGE_SIZE
+#endif
+
 #define PAGE_ALIGNED(_addr)     ( ! ((size_t) _addr & \
-                                     (size_t)(PAGE_SIZE - 1)))
-#define ALIGN_TO_PAGE(x)   (void *)(((size_t)(x)) & ~((size_t)(PAGE_SIZE - 1)))
+                                     (size_t)(KMP_GET_PAGE_SIZE() - 1)))
+#define ALIGN_TO_PAGE(x)   (void *)(((size_t)(x)) & ~((size_t)(KMP_GET_PAGE_SIZE() - 1)))
 
 /* ---------------------- Support for cache alignment, padding, etc. -----------------*/
 

Modified: openmp/trunk/runtime/src/kmp_runtime.c
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/kmp_runtime.c?rev=285243&r1=285242&r2=285243&view=diff
==============================================================================
--- openmp/trunk/runtime/src/kmp_runtime.c (original)
+++ openmp/trunk/runtime/src/kmp_runtime.c Wed Oct 26 16:42:48 2016
@@ -347,8 +347,10 @@ __kmp_print_storage_map_gtid( int gtid,
                     int lastNode;
                     int localProc = __kmp_get_cpu_from_gtid(gtid);
 
-                    p1 = (void *)( (size_t)p1 & ~((size_t)PAGE_SIZE - 1) );
-                    p2 = (void *)( ((size_t) p2 - 1) & ~((size_t)PAGE_SIZE - 1) );
+                    const int page_size = KMP_GET_PAGE_SIZE();
+
+                    p1 = (void *)( (size_t)p1 & ~((size_t)page_size - 1) );
+                    p2 = (void *)( ((size_t) p2 - 1) & ~((size_t)page_size - 1) );
                     if(localProc >= 0)
                         __kmp_printf_no_lock("  GTID %d localNode %d\n", gtid, localProc>>1);
                     else
@@ -360,17 +362,17 @@ __kmp_print_storage_map_gtid( int gtid,
                         lastNode = node;
                         /* This loop collates adjacent pages with the same host node. */
                         do {
-                            (char*)p1 += PAGE_SIZE;
+                            (char*)p1 += page_size;
                         } while(p1 <= p2 && (node = __kmp_get_host_node(p1)) == lastNode);
                         __kmp_printf_no_lock("    %p-%p memNode %d\n", last,
                                              (char*)p1 - 1, lastNode);
                     } while(p1 <= p2);
 # else
                     __kmp_printf_no_lock("    %p-%p memNode %d\n", p1,
-                                         (char*)p1 + (PAGE_SIZE - 1), __kmp_get_host_node(p1));
+                                         (char*)p1 + (page_size - 1), __kmp_get_host_node(p1));
                     if(p1 < p2)  {
                         __kmp_printf_no_lock("    %p-%p memNode %d\n", p2,
-                                             (char*)p2 + (PAGE_SIZE - 1), __kmp_get_host_node(p2));
+                                             (char*)p2 + (page_size - 1), __kmp_get_host_node(p2));
                     }
 # endif
                 }




More information about the Openmp-commits mailing list