Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.
/ jdk16 Public archive

Commit

Permalink
8259765: ZGC: Handle incorrect processor id reported by the operating…
Browse files Browse the repository at this point in the history
… system

Reviewed-by: ayang, eosterlund
  • Loading branch information
pliden committed Jan 28, 2021
1 parent e28e111 commit e68eac9
Showing 1 changed file with 35 additions and 8 deletions.
43 changes: 35 additions & 8 deletions src/hotspot/os/linux/os_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4746,19 +4746,46 @@ int os::active_processor_count() {
return active_cpus;
}

static bool should_warn_invalid_processor_id() {
if (os::processor_count() == 1) {
// Don't warn if we only have one processor
return false;
}

static volatile int warn_once = 1;

if (Atomic::load(&warn_once) == 0 ||
Atomic::xchg(&warn_once, 0) == 0) {
// Don't warn more than once
return false;
}

return true;
}

uint os::processor_id() {
const int id = Linux::sched_getcpu();

#ifndef PRODUCT
if (UseDebuggerErgo1 && id >= _processor_count) {
// Some debuggers limit the processor count without limiting
// the returned processor ids. Fake the processor id.
return 0;
if (id < processor_count()) {
return (uint)id;
}

// Some environments (e.g. openvz containers and the rr debugger) incorrectly
// report a processor id that is higher than the number of processors available.
// This is problematic, for example, when implementing CPU-local data structures,
// where the processor id is used to index into an array of length processor_count().
// If this happens we return 0 here. This is is safe since we always have at least
// one processor, but it's not optimal for performance if we're actually executing
// in an environment with more than one processor.
if (should_warn_invalid_processor_id()) {
log_warning(os)("Invalid processor id reported by the operating system "
"(got processor id %d, valid processor id range is 0-%d)",
id, processor_count() - 1);
log_warning(os)("Falling back to assuming processor id is 0. "
"This could have a negative impact on performance.");
}
#endif

assert(id >= 0 && id < _processor_count, "Invalid processor id [%d]", id);
return (uint)id;
return 0;
}

void os::set_native_thread_name(const char *name) {
Expand Down

1 comment on commit e68eac9

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.