r/linux_programming • u/bizwig • Jan 13 '21
How do I programmatically determine CPU information?
Things like
- cpu and core counts
- distinguishing cores from cpus (hyperthreads)
- determining which cpus, if any, are hyperthread pairs on the same core
- determining which cores share a socket
- 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
View all comments
Show parent comment
1
u/soullessroentgenium Jan 14 '21
So, very much not an expert in this area, but this problem seems to occur outside the process at the high-performance message passing or system administration level (particularly where non-uniform memory access, NUMA, is involved), rather than at the programmatic/standard library level. For the former, you're looking at frameworks like OpenMPI, or nova for OpenStack. For the later part, you want to look at CPU pinning and affinity and memory allocation in systemd and cgroups.