< prev index next >
src/os/linux/vm/os_linux.cpp
Print this page
*** 4769,4778 ****
--- 4769,4797 ----
if (!linux_mprotect((char *)_polling_page, Linux::page_size(), PROT_READ)) {
fatal("Could not enable polling page");
}
}
+ // older glibc versions don't have this macro (which expands to
+ // an optimized bit-counting function) so we have to roll our own
+ #ifndef CPU_COUNT
+
+ static int _cpu_count(const cpu_set_t* cpus) {
+ int count = 0;
+ // only look up to the number of configured processors
+ for (int i = 0; i < os::processor_count(); i++) {
+ if (CPU_ISSET(i, cpus)) {
+ count++;
+ }
+ }
+ return count;
+ }
+
+ #define CPU_COUNT(cpus) _cpu_count(cpus)
+
+ #endif // CPU_COUNT
+
// Get the current number of available processors for this process.
// This value can change at any time during a process's lifetime.
// sched_getaffinity gives an accurate answer as it accounts for cpusets.
// If it appears there may be more than 1024 processors then we do a
// dynamic check - see 6515172 for details.
*** 4784,4793 ****
--- 4803,4815 ----
int cpus_size = sizeof(cpu_set_t);
int configured_cpus = processor_count(); // upper bound on available cpus
int cpu_count = 0;
+ // old build platforms may not support dynamic cpu sets
+ #ifdef CPU_ALLOC
+
// To enable easy testing of the dynamic path on different platforms we
// introduce a diagnostic flag: UseCpuAllocPath
if (configured_cpus >= CPU_SETSIZE || UseCpuAllocPath) {
// kernel may use a mask bigger than cpu_set_t
log_trace(os)("active_processor_count: using dynamic path %s"
*** 4812,4821 ****
--- 4834,4851 ----
}
else {
log_trace(os)("active_processor_count: using static path - configured processors: %d",
configured_cpus);
}
+ #else // CPU_ALLOC
+
+ #define CPU_COUNT_S(size, cpus) -1
+ #define CPU_FREE(cpus)
+
+ log_trace(os)("active_processor_count: only static path available - configured processors: %d",
+ configured_cpus);
+ #endif // CPU_ALLOC
// pid 0 means the current thread - which we have to assume represents the process
if (sched_getaffinity(0, cpus_size, cpus_p) == 0) {
if (cpus_p != &cpus) {
cpu_count = CPU_COUNT_S(cpus_size, cpus_p);
< prev index next >