Fri, 05 Aug 2011 16:50:14 -0700
7060836: RHEL 5.5 and 5.6 should support UseNUMA
Summary: Add a wrapper for sched_getcpu() for systems where libc lacks it
Reviewed-by: ysr
Contributed-by: Andrew John Hughes <ahughes@redhat.com>
src/os/linux/vm/os_linux.cpp | file | annotate | diff | comparison | revisions | |
src/os/linux/vm/os_linux.hpp | file | annotate | diff | comparison | revisions |
1.1 --- a/src/os/linux/vm/os_linux.cpp Fri Aug 05 16:44:01 2011 -0700 1.2 +++ b/src/os/linux/vm/os_linux.cpp Fri Aug 05 16:50:14 2011 -0700 1.3 @@ -125,6 +125,10 @@ 1.4 # include <inttypes.h> 1.5 # include <sys/ioctl.h> 1.6 1.7 +#ifdef AMD64 1.8 +#include <asm/vsyscall.h> 1.9 +#endif 1.10 + 1.11 #define MAX_PATH (2 * K) 1.12 1.13 // for timer info max values which include all bits 1.14 @@ -2578,6 +2582,22 @@ 1.15 return end; 1.16 } 1.17 1.18 + 1.19 +int os::Linux::sched_getcpu_syscall(void) { 1.20 + unsigned int cpu; 1.21 + int retval = -1; 1.22 + 1.23 +#if defined(IA32) 1.24 + retval = syscall(SYS_getcpu, &cpu, NULL, NULL); 1.25 +#elif defined(AMD64) 1.26 + typedef long (*vgetcpu_t)(unsigned int *cpu, unsigned int *node, unsigned long *tcache); 1.27 + vgetcpu_t vgetcpu = (vgetcpu_t)VSYSCALL_ADDR(__NR_vgetcpu); 1.28 + retval = vgetcpu(&cpu, NULL, NULL); 1.29 +#endif 1.30 + 1.31 + return (retval == -1) ? retval : cpu; 1.32 +} 1.33 + 1.34 // Something to do with the numa-aware allocator needs these symbols 1.35 extern "C" JNIEXPORT void numa_warn(int number, char *where, ...) { } 1.36 extern "C" JNIEXPORT void numa_error(char *where) { } 1.37 @@ -2601,6 +2621,10 @@ 1.38 set_sched_getcpu(CAST_TO_FN_PTR(sched_getcpu_func_t, 1.39 dlsym(RTLD_DEFAULT, "sched_getcpu"))); 1.40 1.41 + // If it's not, try a direct syscall. 1.42 + if (sched_getcpu() == -1) 1.43 + set_sched_getcpu(CAST_TO_FN_PTR(sched_getcpu_func_t, (void*)&sched_getcpu_syscall)); 1.44 + 1.45 if (sched_getcpu() != -1) { // Does it work? 1.46 void *handle = dlopen("libnuma.so.1", RTLD_LAZY); 1.47 if (handle != NULL) {
2.1 --- a/src/os/linux/vm/os_linux.hpp Fri Aug 05 16:44:01 2011 -0700 2.2 +++ b/src/os/linux/vm/os_linux.hpp Fri Aug 05 16:50:14 2011 -0700 2.3 @@ -263,6 +263,7 @@ 2.4 static void set_numa_tonode_memory(numa_tonode_memory_func_t func) { _numa_tonode_memory = func; } 2.5 static void set_numa_interleave_memory(numa_interleave_memory_func_t func) { _numa_interleave_memory = func; } 2.6 static void set_numa_all_nodes(unsigned long* ptr) { _numa_all_nodes = ptr; } 2.7 + static int sched_getcpu_syscall(void); 2.8 public: 2.9 static int sched_getcpu() { return _sched_getcpu != NULL ? _sched_getcpu() : -1; } 2.10 static int numa_node_to_cpus(int node, unsigned long *buffer, int bufferlen) {