mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-17 17:44:40 +02:00
8259765: ZGC: Handle incorrect processor id reported by the operating system
Reviewed-by: ayang, eosterlund
This commit is contained in:
parent
e28e11119d
commit
e68eac9c36
1 changed files with 35 additions and 8 deletions
|
@ -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;
|
||||
}
|
||||
#endif
|
||||
|
||||
assert(id >= 0 && id < _processor_count, "Invalid processor id [%d]", id);
|
||||
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.");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void os::set_native_thread_name(const char *name) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue