L Lawliet
L Lawliet

Reputation: 2635

linux kernel functions to get installed cores and active cores

Is there a linux kernel function that would return me

  1. Total number of physical cores available
  2. Total number of active cores (online cores) available

Please feel free to suggest any userspace counterparts as well.

Upvotes: 0

Views: 915

Answers (1)

Gil Hamilton
Gil Hamilton

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

Related Questions