8321075: RISC-V: UseSystemMemoryBarrier lacking proper OS support

Reviewed-by: fyang, yadongwang, luhenry
This commit is contained in:
Robbin Ehn 2024-02-21 08:58:19 +00:00
parent 04d43c435d
commit 68eb5a1df5
3 changed files with 40 additions and 1 deletions

@ -85,6 +85,8 @@
#endif
// put OS-includes here
# include <ctype.h>
# include <stdlib.h>
# include <sys/types.h>
# include <sys/mman.h>
# include <sys/stat.h>
@ -342,6 +344,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;

@ -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;

@ -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.9.
long major, minor;
os::Linux::kernel_version(&major, &minor);
if (!(major > 6 || (major == 6 && minor >= 9))) {
log_info(os)("Linux kernel %ld.%ld does 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");