giampaolo / psutil

Cross-platform lib for process and system monitoring in Python
BSD 3-Clause "New" or "Revised" License
10.31k stars 1.39k forks source link

[macOS] cpu_freq() fails on arm64 #2382

Open giampaolo opened 8 months ago

giampaolo commented 8 months ago

We recently added a macOS build for arm64 and we get a failure: https://github.com/giampaolo/psutil/actions/runs/8301314525/job/22721158479

2024-03-15T19:24:20.3697330Z ======================================================================
2024-03-15T19:24:20.3697970Z ERROR: psutil.tests.test_misc.TestMisc.test_serialization (name='cpu_freq')
2024-03-15T19:24:20.3698460Z ----------------------------------------------------------------------
2024-03-15T19:24:20.3698790Z Traceback (most recent call last):
2024-03-15T19:24:20.3708960Z   File "/Users/runner/work/psutil/psutil/psutil/tests/test_misc.py", line 292, in test_serialization
2024-03-15T19:24:20.3709580Z     ret = fun()
2024-03-15T19:24:20.3710550Z   File "/private/var/folders/1k/qq3pcbf12vb6vyblh81736p40000gn/T/cibw-run-m728_sh2/cp39-macosx_arm64/venv-test-arm64/lib/python3.9/site-packages/psutil/__init__.py", line 1913, in cpu_freq
2024-03-15T19:24:20.3711420Z     ret = _psplatform.cpu_freq()
2024-03-15T19:24:20.3712370Z   File "/private/var/folders/1k/qq3pcbf12vb6vyblh81736p40000gn/T/cibw-run-m728_sh2/cp39-macosx_arm64/venv-test-arm64/lib/python3.9/site-packages/psutil/_psosx.py", line 182, in cpu_freq
2024-03-15T19:24:20.3713240Z     curr, min_, max_ = cext.cpu_freq()
2024-03-15T19:24:20.3713680Z RuntimeError: 'pmgr' entry was not found in AppleARMIODevice service

Error originates from: https://github.com/giampaolo/psutil/blob/f51f62beef5e2ce0d64c9cb76fb7b4e9094b1864/psutil/arch/osx/cpu.c#L160-L166.

Change was introduced in https://github.com/giampaolo/psutil/pull/2222.

@snOm3ad: Any chance you can take a look?

snOm3ad commented 8 months ago

I will check further! Will also look into #2354 at the same time.

dbwiddis commented 8 months ago

I think this is a relic of the VM used by GitHub (and other CI providers) that don't include the pmgr info that on-metal hardware provides.

snOm3ad commented 8 months ago

Yeah what Daniel has pointed out in https://github.com/giampaolo/psutil/pull/2222#issuecomment-2000755602 is spot on as to why this is failing.

I just booted a VM to test this and when I tried to use powermetrics it reports the exact same error. I opened the IORegistryExplorer just for fun and indeed the pmgr property is not exposed:

image

dbwiddis commented 8 months ago

I opened the IORegistryExplorer just for fun and indeed the pmgr property is not exposed:

Any way you can explore around and see if the "voltage-states5-sram" or "voltage-states1-sram" or any "voltage-states*-sram" value exists in any key?

snOm3ad commented 8 months ago

Any way you can explore around and see if the "voltage-states5-sram" or "voltage-states1-sram" or any "voltage-states*-sram" value exists in any key?

ioreg -k 'voltage-states5-sram' -r is empty, so it's not looking very promising.

dbwiddis commented 8 months ago

any "voltage-states" at all?

I'm not sure "CPU Frequency" has any meaning for a VM, anyway. And in most cases, CPU Frequency has changed by the time you read the results. I think the appropriate response here is to ignore the error and return either 0 or some sane default.