Reputation: 2635
Is there a linux kernel function that would return me
Please feel free to suggest any userspace counterparts as well.
Upvotes: 0
Views: 915
Reputation: 12347
See macros in include/linux/cpumask.h:
num_online_cpus()
num_possible_cpus()
num_present_cpus()
num_active_cpus()
From user-mode, you can get some of the info from /proc/cpuinfo but in theory the set of online cores can change from instant to instant so there's no interface that provides this info. You could also examine /sys/class/cpuid/.
You could try to set your process affinity in such a way that it includes only 1 processor (at a time) and see if it worked. This would tell you whether a given processor is online at the moment (but again that info could change at any instant).
Upvotes: 2