8181319: Make os::Linux::sched_getcpu() available even when UseNUMA is false
authorpliden
Wed, 31 May 2017 13:17:00 +0200
changeset 46512 1ba5728eda0d
parent 46511 4a5b7a2dd783
child 46513 c61eea516a0a
8181319: Make os::Linux::sched_getcpu() available even when UseNUMA is false Reviewed-by: dholmes, rehn
hotspot/src/os/linux/vm/os_linux.cpp
hotspot/src/os/linux/vm/os_linux.hpp
--- a/hotspot/src/os/linux/vm/os_linux.cpp	Thu Jun 01 02:21:18 2017 +0000
+++ b/hotspot/src/os/linux/vm/os_linux.cpp	Wed May 31 13:17:00 2017 +0200
@@ -2815,6 +2815,18 @@
   return (retval == -1) ? retval : cpu;
 }
 
+void os::Linux::sched_getcpu_init() {
+  // sched_getcpu() should be in libc.
+  set_sched_getcpu(CAST_TO_FN_PTR(sched_getcpu_func_t,
+                                  dlsym(RTLD_DEFAULT, "sched_getcpu")));
+
+  // If it's not, try a direct syscall.
+  if (sched_getcpu() == -1) {
+    set_sched_getcpu(CAST_TO_FN_PTR(sched_getcpu_func_t,
+                                    (void*)&sched_getcpu_syscall));
+  }
+}
+
 // Something to do with the numa-aware allocator needs these symbols
 extern "C" JNIEXPORT void numa_warn(int number, char *where, ...) { }
 extern "C" JNIEXPORT void numa_error(char *where) { }
@@ -2836,17 +2848,7 @@
 }
 
 bool os::Linux::libnuma_init() {
-  // sched_getcpu() should be in libc.
-  set_sched_getcpu(CAST_TO_FN_PTR(sched_getcpu_func_t,
-                                  dlsym(RTLD_DEFAULT, "sched_getcpu")));
-
-  // If it's not, try a direct syscall.
-  if (sched_getcpu() == -1) {
-    set_sched_getcpu(CAST_TO_FN_PTR(sched_getcpu_func_t,
-                                    (void*)&sched_getcpu_syscall));
-  }
-
-  if (sched_getcpu() != -1) { // Does it work?
+  if (sched_getcpu() != -1) { // Requires sched_getcpu() support
     void *handle = dlopen("libnuma.so.1", RTLD_LAZY);
     if (handle != NULL) {
       set_numa_node_to_cpus(CAST_TO_FN_PTR(numa_node_to_cpus_func_t,
@@ -4875,6 +4877,7 @@
 #endif
 
   Linux::libpthread_init();
+  Linux::sched_getcpu_init();
   log_info(os)("HotSpot is running with %s, %s",
                Linux::glibc_version(), Linux::libpthread_version());
 
--- a/hotspot/src/os/linux/vm/os_linux.hpp	Thu Jun 01 02:21:18 2017 +0000
+++ b/hotspot/src/os/linux/vm/os_linux.hpp	Wed May 31 13:17:00 2017 +0200
@@ -170,6 +170,7 @@
   static const char *libpthread_version()     { return _libpthread_version; }
 
   static void libpthread_init();
+  static void sched_getcpu_init();
   static bool libnuma_init();
   static void* libnuma_dlsym(void* handle, const char* name);
   // libnuma v2 (libnuma_1.2) symbols