8203227: Introduce os::processor_id() for Linux and Solaris
Reviewed-by: dholmes, rehn
This commit is contained in:
parent
ab469d40fc
commit
dface12e6d
@ -2872,6 +2872,10 @@ void os::Linux::sched_getcpu_init() {
|
||||
set_sched_getcpu(CAST_TO_FN_PTR(sched_getcpu_func_t,
|
||||
(void*)&sched_getcpu_syscall));
|
||||
}
|
||||
|
||||
if (sched_getcpu() == -1) {
|
||||
vm_exit_during_initialization("getcpu(2) system call not supported by kernel");
|
||||
}
|
||||
}
|
||||
|
||||
// Something to do with the numa-aware allocator needs these symbols
|
||||
@ -5229,6 +5233,12 @@ int os::active_processor_count() {
|
||||
return active_cpus;
|
||||
}
|
||||
|
||||
uint os::processor_id() {
|
||||
const int id = Linux::sched_getcpu();
|
||||
assert(id >= 0 && id < _processor_count, "Invalid processor id");
|
||||
return (uint)id;
|
||||
}
|
||||
|
||||
void os::set_native_thread_name(const char *name) {
|
||||
if (Linux::_pthread_setname_np) {
|
||||
char buf [16]; // according to glibc manpage, 16 chars incl. '/0'
|
||||
|
@ -291,6 +291,12 @@ void os::Solaris::initialize_system_info() {
|
||||
(julong)sysconf(_SC_PAGESIZE);
|
||||
}
|
||||
|
||||
uint os::processor_id() {
|
||||
const processorid_t id = ::getcpuid();
|
||||
assert(id >= 0 && id < _processor_count, "Invalid processor id");
|
||||
return (uint)id;
|
||||
}
|
||||
|
||||
int os::active_processor_count() {
|
||||
// User has overridden the number of active processors
|
||||
if (ActiveProcessorCount > 0) {
|
||||
|
@ -233,6 +233,10 @@ class os: AllStatic {
|
||||
static bool has_allocatable_memory_limit(julong* limit);
|
||||
static bool is_server_class_machine();
|
||||
|
||||
// Returns the id of the processor on which the calling thread is currently executing.
|
||||
// The returned value is guaranteed to be between 0 and (os::processor_count() - 1).
|
||||
static uint processor_id();
|
||||
|
||||
// number of CPUs
|
||||
static int processor_count() {
|
||||
return _processor_count;
|
||||
|
Loading…
Reference in New Issue
Block a user