Skip to content

Commit

Permalink
Parse kernel versions alone
Browse files Browse the repository at this point in the history
  • Loading branch information
limingliu-ampere committed Apr 9, 2024
1 parent 73da715 commit 98d65b2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
28 changes: 17 additions & 11 deletions src/hotspot/os/linux/os_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ pthread_t os::Linux::_main_thread;
bool os::Linux::_supports_fast_thread_cpu_time = false;
const char * os::Linux::_libc_version = nullptr;
const char * os::Linux::_libpthread_version = nullptr;
long os::Linux::_release_major = -1;
long os::Linux::_release_minor = -1;

bool os::Linux::_thp_requested{false};

#ifdef __GLIBC__
Expand Down Expand Up @@ -368,7 +367,7 @@ static void next_line(FILE *f) {
} while (c != '\n' && c != EOF);
}

void os::Linux::version_init() {
void os::Linux::kernel_version(long* major, long* minor) {
struct utsname buffer;
int ret = uname(&buffer);
if (ret != 0) {
Expand All @@ -377,11 +376,11 @@ void os::Linux::version_init() {
}

char* walker = buffer.release;
long* set_v = &_release_major;
while (_release_minor == -1 && walker != nullptr) {
long* set_v = major;
while (*minor == -1 && walker != nullptr) {
if (isdigit(walker[0])) {
*set_v = strtol(walker, &walker, 10);
set_v = &_release_minor;
set_v = minor;
} else {
++walker;
}
Expand Down Expand Up @@ -4546,8 +4545,6 @@ void os::init(void) {

check_pax();

Linux::version_init();

os::Posix::init();
}

Expand Down Expand Up @@ -4829,10 +4826,19 @@ jint os::init_2(void) {
// Some downstream kernels recognize MADV_POPULATE_WRITE_value as another
// advice, so the check of versions is required here.
// See https://github.com/oracle/linux-uek/issues/23
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));
}

long major = -1, minor = -1;
bool supportMadvPopulateWrite =
(Linux::_release_major > 5 ||
(Linux::_release_major == 5 && Linux::_release_minor >= 14)) &&
(::madvise(0, 0, MADV_POPULATE_WRITE) == 0);
(ret == 0 &&
(sscanf(buffer.release, "%ld.%ld", &major, &minor) == 2) &&
(major > 5 || (major == 5 && minor >= 14)) &&
(::madvise(0, 0, MADV_POPULATE_WRITE) == 0));
if (!supportMadvPopulateWrite) {
if (!FLAG_IS_DEFAULT(UseMadvPopulateWrite)) {
warning("Platform does not support MADV_POPULATE_WRITE, "
Expand Down
9 changes: 1 addition & 8 deletions src/hotspot/os/linux/os_linux.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ class os::Linux {
static const char *_libc_version;
static const char *_libpthread_version;

static long _release_major;
static long _release_minor;

static bool _supports_fast_thread_cpu_time;

static GrowableArray<int>* _cpu_to_node;
Expand All @@ -69,7 +66,6 @@ class os::Linux {
static int commit_memory_impl(char* addr, size_t bytes,
size_t alignment_hint, bool exec);

static void version_init();
static void set_libc_version(const char *s) { _libc_version = s; }
static void set_libpthread_version(const char *s) { _libpthread_version = s; }

Expand Down Expand Up @@ -97,10 +93,7 @@ class os::Linux {
bool has_steal_ticks;
};

static void kernel_version(long* major, long* minor) {
*major = _release_major;
*minor = _release_minor;
}
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);
Expand Down

0 comments on commit 98d65b2

Please sign in to comment.