Skip to content

Commit

Permalink
Added runtime kernel version check
Browse files Browse the repository at this point in the history
  • Loading branch information
robehn committed Feb 13, 2024
1 parent b356fee commit b0bd0f6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/hotspot/os/linux/os_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
#endif

// put OS-includes here
# include <ctype.h>
# include <stdlib.h>
# include <sys/types.h>
# include <sys/mman.h>
# include <sys/stat.h>
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/os/linux/os_linux.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 13 additions & 1 deletion src/hotspot/os/linux/systemMemoryBarrier_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit b0bd0f6

Please sign in to comment.