diff --git a/src/hotspot/os/linux/os_linux.cpp b/src/hotspot/os/linux/os_linux.cpp index f02ca95be5593..dfca6083a549b 100644 --- a/src/hotspot/os/linux/os_linux.cpp +++ b/src/hotspot/os/linux/os_linux.cpp @@ -86,6 +86,8 @@ #endif // put OS-includes here +# include +# include # include # include # include @@ -343,6 +345,29 @@ static void next_line(FILE *f) { } while (c != '\n' && c != EOF); } +void os::Linux::kernel_version(long* major, long* minor) { + *major = -1; + *minor = -1; + + struct utsname buffer; + int ret = uname(&buffer); + if (ret != 0) { + log_warning(os)("uname(2) failed to get kernel version: %s", os::errno_name(ret)); + return; + } + + char* walker = buffer.release; + long* set_v = major; + while (*minor == -1 && walker != nullptr) { + if (isdigit(walker[0])) { + *set_v = strtol(walker, &walker, 10); + set_v = minor; + } else { + ++walker; + } + } +} + bool os::Linux::get_tick_information(CPUPerfTicks* pticks, int which_logical_cpu) { FILE* fh; uint64_t userTicks, niceTicks, systemTicks, idleTicks; diff --git a/src/hotspot/os/linux/os_linux.hpp b/src/hotspot/os/linux/os_linux.hpp index 4b2ccf8e370db..6b902e8280244 100644 --- a/src/hotspot/os/linux/os_linux.hpp +++ b/src/hotspot/os/linux/os_linux.hpp @@ -93,6 +93,8 @@ class os::Linux { bool has_steal_ticks; }; + static void kernel_version(long* major, long* minor); + // which_logical_cpu=-1 returns accumulated ticks for all cpus. static bool get_tick_information(CPUPerfTicks* pticks, int which_logical_cpu); static bool _stack_is_executable; diff --git a/src/hotspot/os/linux/systemMemoryBarrier_linux.cpp b/src/hotspot/os/linux/systemMemoryBarrier_linux.cpp index 446449a40e094..6a11529dd7d9e 100644 --- a/src/hotspot/os/linux/systemMemoryBarrier_linux.cpp +++ b/src/hotspot/os/linux/systemMemoryBarrier_linux.cpp @@ -24,7 +24,7 @@ #include "precompiled.hpp" #include "logging/log.hpp" -#include "runtime/os.hpp" +#include "os_linux.hpp" #include "utilities/debug.hpp" #include "utilities/systemMemoryBarrier.hpp" @@ -61,6 +61,18 @@ static long membarrier(int cmd, unsigned int flags, int cpu_id) { } bool LinuxSystemMemoryBarrier::initialize() { +#if defined(RISCV) +// RISCV port was introduced in kernel 4.4. +// 4.4 also made membar private expedited mandatory. +// But RISCV actually don't support it until 6.8. + long major, minor; + os::Linux::kernel_version(&major, &minor); + if (!(major >= 6 && minor >= 8)) { + log_info(os)("Linux kernel %ld.%ld do not support MEMBARRIER PRIVATE_EXPEDITED on RISC-V.", + major, minor); + return false; + } +#endif long ret = membarrier(MEMBARRIER_CMD_QUERY, 0, 0); if (ret < 0) { log_info(os)("MEMBARRIER_CMD_QUERY unsupported");