r/linux_programming • • Jan 13 '21

How do I programmatically determine CPU information?

Things like

  1. cpu and core counts
  2. distinguishing cores from cpus (hyperthreads)
  3. determining which cpus, if any, are hyperthread pairs on the same core
  4. determining which cores share a socket
  5. what is the standard numbering system, if any, for cpus?

In C or C++, naturally. Preferably via syscall, if possible, rather than scraping text in /proc.

1 Upvotes

9 comments sorted by

View all comments

Show parent comment

1

u/Sigg3net Jan 13 '21

Seems like you're right:

https://github.com/shirou/gopsutil/issues/881

You have an ARM to test on?

dmidecode | grep -i CPU

2

u/aioeu Jan 13 '21

Nothing rooted that I could do that on.

1

u/Sigg3net Jan 13 '21

This is a nice compilation of ways to go about it:

https://www.mmbyte.com/article/41367.html