mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-19 02:24:40 +02:00
8234512: Missing pieces from JDK-8224816
Reviewed-by: rehn, pliden, kbarrett, gziemski
This commit is contained in:
parent
b10495d436
commit
8e709f03bb
1 changed files with 19 additions and 13 deletions
|
@ -3205,14 +3205,14 @@ int os::active_processor_count() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
uint os::processor_id() {
|
static volatile int* volatile apic_to_processor_mapping = NULL;
|
||||||
static volatile int* volatile apic_to_cpu_mapping = NULL;
|
static volatile int next_processor_id = 0;
|
||||||
static volatile int next_cpu_id = 0;
|
|
||||||
|
|
||||||
volatile int* mapping = OrderAccess::load_acquire(&apic_to_cpu_mapping);
|
static inline volatile int* get_apic_to_processor_mapping() {
|
||||||
|
volatile int* mapping = OrderAccess::load_acquire(&apic_to_processor_mapping);
|
||||||
if (mapping == NULL) {
|
if (mapping == NULL) {
|
||||||
// Calculate possible number space for APIC ids. This space is not necessarily
|
// Calculate possible number space for APIC ids. This space is not necessarily
|
||||||
// in the range [0, number_of_cpus).
|
// in the range [0, number_of_processors).
|
||||||
uint total_bits = 0;
|
uint total_bits = 0;
|
||||||
for (uint i = 0;; ++i) {
|
for (uint i = 0;; ++i) {
|
||||||
uint eax = 0xb; // Query topology leaf
|
uint eax = 0xb; // Query topology leaf
|
||||||
|
@ -3238,33 +3238,39 @@ uint os::processor_id() {
|
||||||
mapping[i] = -1;
|
mapping[i] = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Atomic::replace_if_null(mapping, &apic_to_cpu_mapping)) {
|
if (!Atomic::replace_if_null(mapping, &apic_to_processor_mapping)) {
|
||||||
FREE_C_HEAP_ARRAY(int, mapping);
|
FREE_C_HEAP_ARRAY(int, mapping);
|
||||||
mapping = OrderAccess::load_acquire(&apic_to_cpu_mapping);
|
mapping = OrderAccess::load_acquire(&apic_to_processor_mapping);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return mapping;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint os::processor_id() {
|
||||||
|
volatile int* mapping = get_apic_to_processor_mapping();
|
||||||
|
|
||||||
uint eax = 0xb;
|
uint eax = 0xb;
|
||||||
uint ebx;
|
uint ebx;
|
||||||
uint ecx = 0;
|
uint ecx = 0;
|
||||||
uint edx;
|
uint edx;
|
||||||
|
|
||||||
asm ("cpuid\n\t" : "+a" (eax), "+b" (ebx), "+c" (ecx), "+d" (edx) : );
|
__asm__ ("cpuid\n\t" : "+a" (eax), "+b" (ebx), "+c" (ecx), "+d" (edx) : );
|
||||||
|
|
||||||
// Map from APIC id to a unique logical processor ID in the expected
|
// Map from APIC id to a unique logical processor ID in the expected
|
||||||
// [0, num_processors) range.
|
// [0, num_processors) range.
|
||||||
|
|
||||||
uint apic_id = edx;
|
uint apic_id = edx;
|
||||||
int cpu_id = Atomic::load(&mapping[apic_id]);
|
int processor_id = Atomic::load(&mapping[apic_id]);
|
||||||
|
|
||||||
while (cpu_id < 0) {
|
while (processor_id < 0) {
|
||||||
if (Atomic::cmpxchg(-2, &mapping[apic_id], -1)) {
|
if (Atomic::cmpxchg(-2, &mapping[apic_id], -1)) {
|
||||||
Atomic::store(Atomic::add(1, &next_cpu_id) - 1, &mapping[apic_id]);
|
Atomic::store(Atomic::add(1, &next_processor_id) - 1, &mapping[apic_id]);
|
||||||
}
|
}
|
||||||
cpu_id = Atomic::load(&mapping[apic_id]);
|
processor_id = Atomic::load(&mapping[apic_id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (uint)cpu_id;
|
return (uint)processor_id;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue