src/os/linux/vm/os_linux.cpp

changeset 3024
7c2653aefc46
parent 3023
a20e6e447d3d
child 3085
3cd0157e1d4d
     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) {

mercurial