[Openmp-commits] [PATCH] D26001: Use getpagesize() instead of PAGE_SIZE macro when KMP_OS_LINUX is true

Victor Campos via Openmp-commits openmp-commits at lists.llvm.org
Wed Oct 26 11:13:23 PDT 2016


vhscampos created this revision.
vhscampos added reviewers: jcownie, jlpeyton.
vhscampos added a subscriber: openmp-commits.

Following the TODO comment in kmp_alloc.cpp line 1723, I replaced the usage of said macro (in kmp_runtime.c) by a call to getpagesize() when KMP_OS_LINUX is true.


https://reviews.llvm.org/D26001

Files:
  runtime/src/kmp_alloc.c
  runtime/src/kmp_runtime.c


Index: runtime/src/kmp_runtime.c
===================================================================
--- runtime/src/kmp_runtime.c
+++ runtime/src/kmp_runtime.c
@@ -347,8 +347,14 @@
                     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) );
+#if KMP_OS_LINUX
+                    const int page_size = getpagesize();
+#else
+                    const int page_size = PAGE_SIZE;
+#endif
+
+                    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 +366,17 @@
                         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
                 }
Index: runtime/src/kmp_alloc.c
===================================================================
--- runtime/src/kmp_alloc.c
+++ runtime/src/kmp_alloc.c
@@ -1720,11 +1720,10 @@
 {
   void *adr, *aadr;
 #if KMP_OS_LINUX
-  /* TODO: Use this function to get page size everywhere */
-  int page_size = getpagesize();
+  const int page_size = getpagesize();
 #else
   /* TODO: Find windows function to get page size and use it everywhere */
-  int page_size = PAGE_SIZE;
+  const int page_size = PAGE_SIZE;
 #endif /* KMP_OS_LINUX */
 
   adr = (void *) __kmp_thread_malloc( __kmp_get_thread(),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26001.75918.patch
Type: text/x-patch
Size: 2721 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20161026/f04ef012/attachment-0001.bin>


More information about the Openmp-commits mailing list