Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8259765: ZGC: Handle incorrect processor id reported by the operating…
… system

Reviewed-by: ayang, eosterlund
  • Loading branch information
pliden committed Jan 28, 2021
1 parent e28e111 commit e68eac9c36ac6afaf711f7fd60dab4be5a31bf86
Showing with 35 additions and 8 deletions.
  1. +35 −8 src/hotspot/os/linux/os_linux.cpp
@@ -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) {

1 comment on commit e68eac9

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on e68eac9 Jan 28, 2021

Please sign in to comment.