0

I need to find out which cores are disabled on a CPU. How can I do this in C/C++ way? I know that reading CAPID6 register is one of the ways, but I am not sure about how to get it done. Is there any system calls or tricks that I need to be aware of?

My OS is Ubuntu. I have Xeon Skylake CPU. I can see if a particular core is offline or online by checking /sys/devices/system/cpu/cpu*/online to see if the file contains 0 or 1 which means offline or online respectively.

And also I checked link below:

https://community.intel.com/t5/Software-Tuning-Performance/Understanding-PCICFG-space-information/td-p/1138820

And I understood John McCalpin's answer, but again, I am looking for a C/C++ way of doing this.

Nate Eldredge
  • 48,811
  • 6
  • 54
  • 82
avernus
  • 304
  • 1
  • 4
  • 15
  • 2
    You're talking about a hardware register on a PCI device. Reading it is a privileged operation, you can't do it directly from userspace code. You will have to get this information from the kernel, and opening and parsing the `/sys` files seems to me like as good a way as any. There is nothing stopping you from doing this from C/C++ (`fopen / fscanf / fclose`, etc). – Nate Eldredge Feb 25 '21 at 20:15
  • 1
    I guess you can use something like `ioperm(2)` to get permission to read and write those ports, but still it seems like more trouble, and not particularly a "more C/C++ way". – Nate Eldredge Feb 25 '21 at 20:16

1 Answers1

1

The supported way to do it on Linux is simply to read those same files. You can open them with fopen, read with fscanf, etc.

user253751
  • 57,427
  • 7
  • 48
  • 90