0

I'm trying to get the idle residency of the CPU in macOS (C-State C0 residency on x86 unsure on arm64). I am aware you can find this info by running something like sudo powermetrics -i1 -n1 -s cpu_power | grep residency in the terminal, but I need a way to pull this info using C, C++, Objective-C, or even Assembly...especially in a way that doesn't need admin privileges.

All I can find regarding this topic is this: Time each CPU core spends in C0 power state, but the answers are not the clearest. Please help!

PersonDudeGuy
  • 113
  • 1
  • 4
  • 1
    Does [this](https://stackoverflow.com/questions/20471920/how-to-get-total-cpu-idle-time-in-objective-c-c-on-os-x) somehow your answer? – sajjad rezaei Jan 17 '22 at 23:21
  • hey @sajjadrezaei! Thanks for the link, it's very useful, but unfortunately seems to be for retrieving the CPUs idle _usage_ rather than idle _residency_... – PersonDudeGuy Jan 18 '22 at 15:20

1 Answers1

0

The powermetrics tool use private API to do this: IOReportStateGetResidency

You could try to import it and with some reversing use yourself too:

https://github.com/samdmarshall/OSXPrivateSDK/blob/master/PrivateSDK10.10.sparse.sdk/usr/local/include/IOReport.h

https://opensource.apple.com/source/PowerManagement/PowerManagement-637.1.2/pmset/pmset.c

Other than that, there is an example of direct usage of mwait asm, but it is for kernel mode (you will need to write a kext to try to run it on macos):

https://rayanfam.com/topics/using-intels-streaming-simd-extensions-3-monitormwait-as-a-kernel-debugging-trick/

I know nothing about is it possible to do this without being root or not, and since the API is private - this is for you to research.

Arthur Bulakaiev
  • 1,207
  • 8
  • 17