1401 // won't be a problem.
1402 struct timespec res;
1403 struct timespec tp;
1404 if (clock_getres_func (CLOCK_MONOTONIC, &res) == 0 &&
1405 clock_gettime_func(CLOCK_MONOTONIC, &tp) == 0) {
1406 // yes, monotonic clock is supported
1407 _clock_gettime = clock_gettime_func;
1408 return;
1409 } else {
1410 // close librt if there is no monotonic clock
1411 dlclose(handle);
1412 }
1413 }
1414 }
1415 warning("No monotonic clock was available - timed services may " \
1416 "be adversely affected if the time-of-day clock changes");
1417 }
1418
1419 #ifndef SYS_clock_getres
1420
1421 #if defined(IA32) || defined(AMD64)
1422 #define SYS_clock_getres IA32_ONLY(266) AMD64_ONLY(229)
1423 #define sys_clock_getres(x,y) ::syscall(SYS_clock_getres, x, y)
1424 #else
1425 #warning "SYS_clock_getres not defined for this platform, disabling fast_thread_cpu_time"
1426 #define sys_clock_getres(x,y) -1
1427 #endif
1428
1429 #else
1430 #define sys_clock_getres(x,y) ::syscall(SYS_clock_getres, x, y)
1431 #endif
1432
1433 void os::Linux::fast_thread_clock_init() {
1434 if (!UseLinuxPosixThreadCPUClocks) {
1435 return;
1436 }
1437 clockid_t clockid;
1438 struct timespec tp;
1439 int (*pthread_getcpuclockid_func)(pthread_t, clockid_t *) =
1440 (int(*)(pthread_t, clockid_t *)) dlsym(RTLD_DEFAULT, "pthread_getcpuclockid");
1441
1442 // Switch to using fast clocks for thread cpu time if
1993 #elif (defined __powerpc__)
1994 static Elf32_Half running_arch_code=EM_PPC;
1995 #elif (defined ARM)
1996 static Elf32_Half running_arch_code=EM_ARM;
1997 #elif (defined S390)
1998 static Elf32_Half running_arch_code=EM_S390;
1999 #elif (defined ALPHA)
2000 static Elf32_Half running_arch_code=EM_ALPHA;
2001 #elif (defined MIPSEL)
2002 static Elf32_Half running_arch_code=EM_MIPS_RS3_LE;
2003 #elif (defined PARISC)
2004 static Elf32_Half running_arch_code=EM_PARISC;
2005 #elif (defined MIPS)
2006 static Elf32_Half running_arch_code=EM_MIPS;
2007 #elif (defined M68K)
2008 static Elf32_Half running_arch_code=EM_68K;
2009 #elif (defined AARCH64)
2010 static Elf32_Half running_arch_code=EM_AARCH64;
2011 #else
2012 #error Method os::dll_load requires that one of following is defined:\
2013 IA32, AMD64, IA64, __sparc, __powerpc__, ARM, S390, ALPHA, MIPS, MIPSEL, PARISC, M68K
2014 #endif
2015
2016 // Identify compatability class for VM's architecture and library's architecture
2017 // Obtain string descriptions for architectures
2018
2019 arch_t lib_arch={elf_head.e_machine,0,elf_head.e_ident[EI_CLASS], elf_head.e_ident[EI_DATA], NULL};
2020 int running_arch_index=-1;
2021
2022 for (unsigned int i=0 ; i < ARRAY_SIZE(arch_array) ; i++ ) {
2023 if (running_arch_code == arch_array[i].code) {
2024 running_arch_index = i;
2025 }
2026 if (lib_arch.code == arch_array[i].code) {
2027 lib_arch.compat_class = arch_array[i].compat_class;
2028 lib_arch.name = arch_array[i].name;
2029 }
2030 }
2031
2032 assert(running_arch_index != -1,
2033 "Didn't find running architecture code (running_arch_code) in arch_array");
2932 if (Linux::isnode_in_configured_nodes(node)) {
2933 ids[i++] = node;
2934 }
2935 }
2936 return i;
2937 }
2938
2939 bool os::get_page_info(char *start, page_info* info) {
2940 return false;
2941 }
2942
2943 char *os::scan_pages(char *start, char* end, page_info* page_expected, page_info* page_found) {
2944 return end;
2945 }
2946
2947
2948 int os::Linux::sched_getcpu_syscall(void) {
2949 unsigned int cpu = 0;
2950 int retval = -1;
2951
2952 #if defined(IA32)
2953 # ifndef SYS_getcpu
2954 # define SYS_getcpu 318
2955 # endif
2956 retval = syscall(SYS_getcpu, &cpu, NULL, NULL);
2957 #elif defined(AMD64)
2958 // Unfortunately we have to bring all these macros here from vsyscall.h
2959 // to be able to compile on old linuxes.
2960 # define __NR_vgetcpu 2
2961 # define VSYSCALL_START (-10UL << 20)
2962 # define VSYSCALL_SIZE 1024
2963 # define VSYSCALL_ADDR(vsyscall_nr) (VSYSCALL_START+VSYSCALL_SIZE*(vsyscall_nr))
2964 typedef long (*vgetcpu_t)(unsigned int *cpu, unsigned int *node, unsigned long *tcache);
2965 vgetcpu_t vgetcpu = (vgetcpu_t)VSYSCALL_ADDR(__NR_vgetcpu);
2966 retval = vgetcpu(&cpu, NULL, NULL);
2967 #endif
2968
2969 return (retval == -1) ? retval : cpu;
2970 }
2971
2972 // Something to do with the numa-aware allocator needs these symbols
2973 extern "C" JNIEXPORT void numa_warn(int number, char *where, ...) { }
2974 extern "C" JNIEXPORT void numa_error(char *where) { }
2975 extern "C" JNIEXPORT int fork1() { return fork(); }
2976
2977 // Handle request to load libnuma symbol version 1.1 (API v1). If it fails
2978 // load symbol from base version instead.
2979 void* os::Linux::libnuma_dlsym(void* handle, const char *name) {
2980 void *f = dlvsym(handle, name, "libnuma_1.1");
2981 if (f == NULL) {
2982 f = dlsym(handle, name);
2983 }
2984 return f;
2985 }
2986
3500 static size_t _large_page_size = 0;
3501
3502 size_t os::Linux::find_large_page_size() {
3503 size_t large_page_size = 0;
3504
3505 // large_page_size on Linux is used to round up heap size. x86 uses either
3506 // 2M or 4M page, depending on whether PAE (Physical Address Extensions)
3507 // mode is enabled. AMD64/EM64T uses 2M page in 64bit mode. IA64 can use
3508 // page as large as 256M.
3509 //
3510 // Here we try to figure out page size by parsing /proc/meminfo and looking
3511 // for a line with the following format:
3512 // Hugepagesize: 2048 kB
3513 //
3514 // If we can't determine the value (e.g. /proc is not mounted, or the text
3515 // format has been changed), we'll use the largest page size supported by
3516 // the processor.
3517
3518 #ifndef ZERO
3519 large_page_size = IA32_ONLY(4 * M) AMD64_ONLY(2 * M) IA64_ONLY(256 * M) SPARC_ONLY(4 * M)
3520 ARM_ONLY(2 * M) PPC_ONLY(4 * M);
3521 #endif // ZERO
3522
3523 FILE *fp = fopen("/proc/meminfo", "r");
3524 if (fp) {
3525 while (!feof(fp)) {
3526 int x = 0;
3527 char buf[16];
3528 if (fscanf(fp, "Hugepagesize: %d", &x) == 1) {
3529 if (x && fgets(buf, sizeof(buf), fp) && strcmp(buf, " kB\n") == 0) {
3530 large_page_size = x * K;
3531 break;
3532 }
3533 } else {
3534 // skip to next line
3535 for (;;) {
3536 int ch = fgetc(fp);
3537 if (ch == EOF || ch == (int)'\n') break;
3538 }
3539 }
3540 }
|
1401 // won't be a problem.
1402 struct timespec res;
1403 struct timespec tp;
1404 if (clock_getres_func (CLOCK_MONOTONIC, &res) == 0 &&
1405 clock_gettime_func(CLOCK_MONOTONIC, &tp) == 0) {
1406 // yes, monotonic clock is supported
1407 _clock_gettime = clock_gettime_func;
1408 return;
1409 } else {
1410 // close librt if there is no monotonic clock
1411 dlclose(handle);
1412 }
1413 }
1414 }
1415 warning("No monotonic clock was available - timed services may " \
1416 "be adversely affected if the time-of-day clock changes");
1417 }
1418
1419 #ifndef SYS_clock_getres
1420
1421 #if defined(IA32) || defined(AMD64) || defined(AARCH64)
1422 #define SYS_clock_getres IA32_ONLY(266) AMD64_ONLY(229) AARCH64_ONLY(114)
1423 #define sys_clock_getres(x,y) ::syscall(SYS_clock_getres, x, y)
1424 #else
1425 #warning "SYS_clock_getres not defined for this platform, disabling fast_thread_cpu_time"
1426 #define sys_clock_getres(x,y) -1
1427 #endif
1428
1429 #else
1430 #define sys_clock_getres(x,y) ::syscall(SYS_clock_getres, x, y)
1431 #endif
1432
1433 void os::Linux::fast_thread_clock_init() {
1434 if (!UseLinuxPosixThreadCPUClocks) {
1435 return;
1436 }
1437 clockid_t clockid;
1438 struct timespec tp;
1439 int (*pthread_getcpuclockid_func)(pthread_t, clockid_t *) =
1440 (int(*)(pthread_t, clockid_t *)) dlsym(RTLD_DEFAULT, "pthread_getcpuclockid");
1441
1442 // Switch to using fast clocks for thread cpu time if
1993 #elif (defined __powerpc__)
1994 static Elf32_Half running_arch_code=EM_PPC;
1995 #elif (defined ARM)
1996 static Elf32_Half running_arch_code=EM_ARM;
1997 #elif (defined S390)
1998 static Elf32_Half running_arch_code=EM_S390;
1999 #elif (defined ALPHA)
2000 static Elf32_Half running_arch_code=EM_ALPHA;
2001 #elif (defined MIPSEL)
2002 static Elf32_Half running_arch_code=EM_MIPS_RS3_LE;
2003 #elif (defined PARISC)
2004 static Elf32_Half running_arch_code=EM_PARISC;
2005 #elif (defined MIPS)
2006 static Elf32_Half running_arch_code=EM_MIPS;
2007 #elif (defined M68K)
2008 static Elf32_Half running_arch_code=EM_68K;
2009 #elif (defined AARCH64)
2010 static Elf32_Half running_arch_code=EM_AARCH64;
2011 #else
2012 #error Method os::dll_load requires that one of following is defined:\
2013 IA32, AMD64, IA64, __sparc, __powerpc__, ARM, S390, ALPHA, MIPS, MIPSEL, PARISC, M68K, AARCH64
2014 #endif
2015
2016 // Identify compatability class for VM's architecture and library's architecture
2017 // Obtain string descriptions for architectures
2018
2019 arch_t lib_arch={elf_head.e_machine,0,elf_head.e_ident[EI_CLASS], elf_head.e_ident[EI_DATA], NULL};
2020 int running_arch_index=-1;
2021
2022 for (unsigned int i=0 ; i < ARRAY_SIZE(arch_array) ; i++ ) {
2023 if (running_arch_code == arch_array[i].code) {
2024 running_arch_index = i;
2025 }
2026 if (lib_arch.code == arch_array[i].code) {
2027 lib_arch.compat_class = arch_array[i].compat_class;
2028 lib_arch.name = arch_array[i].name;
2029 }
2030 }
2031
2032 assert(running_arch_index != -1,
2033 "Didn't find running architecture code (running_arch_code) in arch_array");
2932 if (Linux::isnode_in_configured_nodes(node)) {
2933 ids[i++] = node;
2934 }
2935 }
2936 return i;
2937 }
2938
2939 bool os::get_page_info(char *start, page_info* info) {
2940 return false;
2941 }
2942
2943 char *os::scan_pages(char *start, char* end, page_info* page_expected, page_info* page_found) {
2944 return end;
2945 }
2946
2947
2948 int os::Linux::sched_getcpu_syscall(void) {
2949 unsigned int cpu = 0;
2950 int retval = -1;
2951
2952 #if defined(AMD64)
2953 // Unfortunately we have to bring all these macros here from vsyscall.h
2954 // to be able to compile on old linuxes.
2955 # define __NR_vgetcpu 2
2956 # define VSYSCALL_START (-10UL << 20)
2957 # define VSYSCALL_SIZE 1024
2958 # define VSYSCALL_ADDR(vsyscall_nr) (VSYSCALL_START+VSYSCALL_SIZE*(vsyscall_nr))
2959 typedef long (*vgetcpu_t)(unsigned int *cpu, unsigned int *node, unsigned long *tcache);
2960 vgetcpu_t vgetcpu = (vgetcpu_t)VSYSCALL_ADDR(__NR_vgetcpu);
2961 retval = vgetcpu(&cpu, NULL, NULL);
2962 #elif defined(IA32) || defined(AARCH64)
2963 # ifndef SYS_getcpu
2964 # define SYS_getcpu AARCH64_ONLY(168) IA32_ONLY(318)
2965 # endif
2966 retval = syscall(SYS_getcpu, &cpu, NULL, NULL);
2967 #endif
2968
2969 return (retval == -1) ? retval : cpu;
2970 }
2971
2972 // Something to do with the numa-aware allocator needs these symbols
2973 extern "C" JNIEXPORT void numa_warn(int number, char *where, ...) { }
2974 extern "C" JNIEXPORT void numa_error(char *where) { }
2975 extern "C" JNIEXPORT int fork1() { return fork(); }
2976
2977 // Handle request to load libnuma symbol version 1.1 (API v1). If it fails
2978 // load symbol from base version instead.
2979 void* os::Linux::libnuma_dlsym(void* handle, const char *name) {
2980 void *f = dlvsym(handle, name, "libnuma_1.1");
2981 if (f == NULL) {
2982 f = dlsym(handle, name);
2983 }
2984 return f;
2985 }
2986
3500 static size_t _large_page_size = 0;
3501
3502 size_t os::Linux::find_large_page_size() {
3503 size_t large_page_size = 0;
3504
3505 // large_page_size on Linux is used to round up heap size. x86 uses either
3506 // 2M or 4M page, depending on whether PAE (Physical Address Extensions)
3507 // mode is enabled. AMD64/EM64T uses 2M page in 64bit mode. IA64 can use
3508 // page as large as 256M.
3509 //
3510 // Here we try to figure out page size by parsing /proc/meminfo and looking
3511 // for a line with the following format:
3512 // Hugepagesize: 2048 kB
3513 //
3514 // If we can't determine the value (e.g. /proc is not mounted, or the text
3515 // format has been changed), we'll use the largest page size supported by
3516 // the processor.
3517
3518 #ifndef ZERO
3519 large_page_size = IA32_ONLY(4 * M) AMD64_ONLY(2 * M) IA64_ONLY(256 * M) SPARC_ONLY(4 * M)
3520 ARM_ONLY(2 * M) PPC_ONLY(4 * M) AARCH64_ONLY(2 * M);
3521 #endif // ZERO
3522
3523 FILE *fp = fopen("/proc/meminfo", "r");
3524 if (fp) {
3525 while (!feof(fp)) {
3526 int x = 0;
3527 char buf[16];
3528 if (fscanf(fp, "Hugepagesize: %d", &x) == 1) {
3529 if (x && fgets(buf, sizeof(buf), fp) && strcmp(buf, " kB\n") == 0) {
3530 large_page_size = x * K;
3531 break;
3532 }
3533 } else {
3534 // skip to next line
3535 for (;;) {
3536 int ch = fgetc(fp);
3537 if (ch == EOF || ch == (int)'\n') break;
3538 }
3539 }
3540 }
|