2798 #define VSYSCALL_SIZE 1024
2799 #define VSYSCALL_ADDR(vsyscall_nr) (VSYSCALL_START+VSYSCALL_SIZE*(vsyscall_nr))
2800 typedef long (*vgetcpu_t)(unsigned int *cpu, unsigned int *node, unsigned long *tcache);
2801 vgetcpu_t vgetcpu = (vgetcpu_t)VSYSCALL_ADDR(__NR_vgetcpu);
2802 retval = vgetcpu(&cpu, NULL, NULL);
2803 #endif
2804
2805 return (retval == -1) ? retval : cpu;
2806 }
2807
2808 // Something to do with the numa-aware allocator needs these symbols
2809 extern "C" JNIEXPORT void numa_warn(int number, char *where, ...) { }
2810 extern "C" JNIEXPORT void numa_error(char *where) { }
2811
2812
2813 // If we are running with libnuma version > 2, then we should
2814 // be trying to use symbols with versions 1.1
2815 // If we are running with earlier version, which did not have symbol versions,
2816 // we should use the base version.
2817 void* os::Linux::libnuma_dlsym(void* handle, const char *name) {
2818 void *f = dlvsym(handle, name, "libnuma_1.1");
2819 if (f == NULL) {
2820 f = dlsym(handle, name);
2821 }
2822 return f;
2823 }
2824
2825 bool os::Linux::libnuma_init() {
2826 // sched_getcpu() should be in libc.
2827 set_sched_getcpu(CAST_TO_FN_PTR(sched_getcpu_func_t,
2828 dlsym(RTLD_DEFAULT, "sched_getcpu")));
2829
2830 // If it's not, try a direct syscall.
2831 if (sched_getcpu() == -1) {
2832 set_sched_getcpu(CAST_TO_FN_PTR(sched_getcpu_func_t,
2833 (void*)&sched_getcpu_syscall));
2834 }
2835
2836 if (sched_getcpu() != -1) { // Does it work?
2837 void *handle = dlopen("libnuma.so.1", RTLD_LAZY);
2838 if (handle != NULL) {
2839 set_numa_node_to_cpus(CAST_TO_FN_PTR(numa_node_to_cpus_func_t,
2840 libnuma_dlsym(handle, "numa_node_to_cpus")));
2841 set_numa_max_node(CAST_TO_FN_PTR(numa_max_node_func_t,
2842 libnuma_dlsym(handle, "numa_max_node")));
|
2798 #define VSYSCALL_SIZE 1024
2799 #define VSYSCALL_ADDR(vsyscall_nr) (VSYSCALL_START+VSYSCALL_SIZE*(vsyscall_nr))
2800 typedef long (*vgetcpu_t)(unsigned int *cpu, unsigned int *node, unsigned long *tcache);
2801 vgetcpu_t vgetcpu = (vgetcpu_t)VSYSCALL_ADDR(__NR_vgetcpu);
2802 retval = vgetcpu(&cpu, NULL, NULL);
2803 #endif
2804
2805 return (retval == -1) ? retval : cpu;
2806 }
2807
2808 // Something to do with the numa-aware allocator needs these symbols
2809 extern "C" JNIEXPORT void numa_warn(int number, char *where, ...) { }
2810 extern "C" JNIEXPORT void numa_error(char *where) { }
2811
2812
2813 // If we are running with libnuma version > 2, then we should
2814 // be trying to use symbols with versions 1.1
2815 // If we are running with earlier version, which did not have symbol versions,
2816 // we should use the base version.
2817 void* os::Linux::libnuma_dlsym(void* handle, const char *name) {
2818 typedef void* (*dlvsym_func_type)(void* handle, const char* name, const char* version);
2819 static dlvsym_func_type dlvsym_func;
2820 static bool initialized = false;
2821
2822 if (!initialized) {
2823 dlvsym_func = (dlvsym_func_type)dlsym(RTLD_NEXT, "dlvsym");
2824 initialized = true;
2825 }
2826
2827 if (dlvsym_func != NULL) {
2828 void *f = dlvsym_func(handle, name, "libnuma_1.1");
2829 if (f != NULL) {
2830 return f;
2831 }
2832 }
2833
2834 return dlsym(handle, name);
2835 }
2836
2837 bool os::Linux::libnuma_init() {
2838 // sched_getcpu() should be in libc.
2839 set_sched_getcpu(CAST_TO_FN_PTR(sched_getcpu_func_t,
2840 dlsym(RTLD_DEFAULT, "sched_getcpu")));
2841
2842 // If it's not, try a direct syscall.
2843 if (sched_getcpu() == -1) {
2844 set_sched_getcpu(CAST_TO_FN_PTR(sched_getcpu_func_t,
2845 (void*)&sched_getcpu_syscall));
2846 }
2847
2848 if (sched_getcpu() != -1) { // Does it work?
2849 void *handle = dlopen("libnuma.so.1", RTLD_LAZY);
2850 if (handle != NULL) {
2851 set_numa_node_to_cpus(CAST_TO_FN_PTR(numa_node_to_cpus_func_t,
2852 libnuma_dlsym(handle, "numa_node_to_cpus")));
2853 set_numa_max_node(CAST_TO_FN_PTR(numa_max_node_func_t,
2854 libnuma_dlsym(handle, "numa_max_node")));
|