< prev index next >

src/hotspot/os/bsd/os_bsd.cpp

Print this page




  34 #include "interpreter/interpreter.hpp"
  35 #include "logging/log.hpp"
  36 #include "logging/logStream.hpp"
  37 #include "memory/allocation.inline.hpp"
  38 #include "memory/filemap.hpp"
  39 #include "oops/oop.inline.hpp"
  40 #include "os_bsd.inline.hpp"
  41 #include "os_posix.inline.hpp"
  42 #include "os_share_bsd.hpp"
  43 #include "prims/jniFastGetField.hpp"
  44 #include "prims/jvm_misc.hpp"
  45 #include "runtime/arguments.hpp"
  46 #include "runtime/atomic.hpp"
  47 #include "runtime/extendedPC.hpp"
  48 #include "runtime/globals.hpp"
  49 #include "runtime/interfaceSupport.inline.hpp"
  50 #include "runtime/java.hpp"
  51 #include "runtime/javaCalls.hpp"
  52 #include "runtime/mutexLocker.hpp"
  53 #include "runtime/objectMonitor.hpp"
  54 #include "runtime/orderAccess.hpp"
  55 #include "runtime/osThread.hpp"
  56 #include "runtime/perfMemory.hpp"
  57 #include "runtime/semaphore.hpp"
  58 #include "runtime/sharedRuntime.hpp"
  59 #include "runtime/statSampler.hpp"
  60 #include "runtime/stubRoutines.hpp"
  61 #include "runtime/thread.inline.hpp"
  62 #include "runtime/threadCritical.hpp"
  63 #include "runtime/timer.hpp"
  64 #include "services/attachListener.hpp"
  65 #include "services/memTracker.hpp"
  66 #include "services/runtimeService.hpp"
  67 #include "utilities/align.hpp"
  68 #include "utilities/decoder.hpp"
  69 #include "utilities/defaultStream.hpp"
  70 #include "utilities/events.hpp"
  71 #include "utilities/growableArray.hpp"
  72 #include "utilities/vmError.hpp"
  73 
  74 // put OS-includes here


3192   }
3193 }
3194 
3195 int os::active_processor_count() {
3196   // User has overridden the number of active processors
3197   if (ActiveProcessorCount > 0) {
3198     log_trace(os)("active_processor_count: "
3199                   "active processor count set by user : %d",
3200                   ActiveProcessorCount);
3201     return ActiveProcessorCount;
3202   }
3203 
3204   return _processor_count;
3205 }
3206 
3207 #ifdef __APPLE__
3208 static volatile int* volatile apic_to_processor_mapping = NULL;
3209 static volatile int next_processor_id = 0;
3210 
3211 static inline volatile int* get_apic_to_processor_mapping() {
3212   volatile int* mapping = OrderAccess::load_acquire(&apic_to_processor_mapping);
3213   if (mapping == NULL) {
3214     // Calculate possible number space for APIC ids. This space is not necessarily
3215     // in the range [0, number_of_processors).
3216     uint total_bits = 0;
3217     for (uint i = 0;; ++i) {
3218       uint eax = 0xb; // Query topology leaf
3219       uint ebx;
3220       uint ecx = i;
3221       uint edx;
3222 
3223       __asm__ ("cpuid\n\t" : "+a" (eax), "+b" (ebx), "+c" (ecx), "+d" (edx) : );
3224 
3225       uint level_type = (ecx >> 8) & 0xFF;
3226       if (level_type == 0) {
3227         // Invalid level; end of topology
3228         break;
3229       }
3230       uint level_apic_id_shift = eax & ((1u << 5) - 1);
3231       total_bits += level_apic_id_shift;
3232     }
3233 
3234     uint max_apic_ids = 1u << total_bits;
3235     mapping = NEW_C_HEAP_ARRAY(int, max_apic_ids, mtInternal);
3236 
3237     for (uint i = 0; i < max_apic_ids; ++i) {
3238       mapping[i] = -1;
3239     }
3240 
3241     if (!Atomic::replace_if_null(mapping, &apic_to_processor_mapping)) {
3242       FREE_C_HEAP_ARRAY(int, mapping);
3243       mapping = OrderAccess::load_acquire(&apic_to_processor_mapping);
3244     }
3245   }
3246 
3247   return mapping;
3248 }
3249 
3250 uint os::processor_id() {
3251   volatile int* mapping = get_apic_to_processor_mapping();
3252 
3253   uint eax = 0xb;
3254   uint ebx;
3255   uint ecx = 0;
3256   uint edx;
3257 
3258   __asm__ ("cpuid\n\t" : "+a" (eax), "+b" (ebx), "+c" (ecx), "+d" (edx) : );
3259 
3260   // Map from APIC id to a unique logical processor ID in the expected
3261   // [0, num_processors) range.
3262 
3263   uint apic_id = edx;




  34 #include "interpreter/interpreter.hpp"
  35 #include "logging/log.hpp"
  36 #include "logging/logStream.hpp"
  37 #include "memory/allocation.inline.hpp"
  38 #include "memory/filemap.hpp"
  39 #include "oops/oop.inline.hpp"
  40 #include "os_bsd.inline.hpp"
  41 #include "os_posix.inline.hpp"
  42 #include "os_share_bsd.hpp"
  43 #include "prims/jniFastGetField.hpp"
  44 #include "prims/jvm_misc.hpp"
  45 #include "runtime/arguments.hpp"
  46 #include "runtime/atomic.hpp"
  47 #include "runtime/extendedPC.hpp"
  48 #include "runtime/globals.hpp"
  49 #include "runtime/interfaceSupport.inline.hpp"
  50 #include "runtime/java.hpp"
  51 #include "runtime/javaCalls.hpp"
  52 #include "runtime/mutexLocker.hpp"
  53 #include "runtime/objectMonitor.hpp"

  54 #include "runtime/osThread.hpp"
  55 #include "runtime/perfMemory.hpp"
  56 #include "runtime/semaphore.hpp"
  57 #include "runtime/sharedRuntime.hpp"
  58 #include "runtime/statSampler.hpp"
  59 #include "runtime/stubRoutines.hpp"
  60 #include "runtime/thread.inline.hpp"
  61 #include "runtime/threadCritical.hpp"
  62 #include "runtime/timer.hpp"
  63 #include "services/attachListener.hpp"
  64 #include "services/memTracker.hpp"
  65 #include "services/runtimeService.hpp"
  66 #include "utilities/align.hpp"
  67 #include "utilities/decoder.hpp"
  68 #include "utilities/defaultStream.hpp"
  69 #include "utilities/events.hpp"
  70 #include "utilities/growableArray.hpp"
  71 #include "utilities/vmError.hpp"
  72 
  73 // put OS-includes here


3191   }
3192 }
3193 
3194 int os::active_processor_count() {
3195   // User has overridden the number of active processors
3196   if (ActiveProcessorCount > 0) {
3197     log_trace(os)("active_processor_count: "
3198                   "active processor count set by user : %d",
3199                   ActiveProcessorCount);
3200     return ActiveProcessorCount;
3201   }
3202 
3203   return _processor_count;
3204 }
3205 
3206 #ifdef __APPLE__
3207 static volatile int* volatile apic_to_processor_mapping = NULL;
3208 static volatile int next_processor_id = 0;
3209 
3210 static inline volatile int* get_apic_to_processor_mapping() {
3211   volatile int* mapping = Atomic::load_acquire(&apic_to_processor_mapping);
3212   if (mapping == NULL) {
3213     // Calculate possible number space for APIC ids. This space is not necessarily
3214     // in the range [0, number_of_processors).
3215     uint total_bits = 0;
3216     for (uint i = 0;; ++i) {
3217       uint eax = 0xb; // Query topology leaf
3218       uint ebx;
3219       uint ecx = i;
3220       uint edx;
3221 
3222       __asm__ ("cpuid\n\t" : "+a" (eax), "+b" (ebx), "+c" (ecx), "+d" (edx) : );
3223 
3224       uint level_type = (ecx >> 8) & 0xFF;
3225       if (level_type == 0) {
3226         // Invalid level; end of topology
3227         break;
3228       }
3229       uint level_apic_id_shift = eax & ((1u << 5) - 1);
3230       total_bits += level_apic_id_shift;
3231     }
3232 
3233     uint max_apic_ids = 1u << total_bits;
3234     mapping = NEW_C_HEAP_ARRAY(int, max_apic_ids, mtInternal);
3235 
3236     for (uint i = 0; i < max_apic_ids; ++i) {
3237       mapping[i] = -1;
3238     }
3239 
3240     if (!Atomic::replace_if_null(mapping, &apic_to_processor_mapping)) {
3241       FREE_C_HEAP_ARRAY(int, mapping);
3242       mapping = Atomic::load_acquire(&apic_to_processor_mapping);
3243     }
3244   }
3245 
3246   return mapping;
3247 }
3248 
3249 uint os::processor_id() {
3250   volatile int* mapping = get_apic_to_processor_mapping();
3251 
3252   uint eax = 0xb;
3253   uint ebx;
3254   uint ecx = 0;
3255   uint edx;
3256 
3257   __asm__ ("cpuid\n\t" : "+a" (eax), "+b" (ebx), "+c" (ecx), "+d" (edx) : );
3258 
3259   // Map from APIC id to a unique logical processor ID in the expected
3260   // [0, num_processors) range.
3261 
3262   uint apic_id = edx;


< prev index next >