-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MacOS] psutil.cpu_freq() broken on Apple M1 #1892
Comments
Mmm... is
It's OK, no worries. |
None are present.
|
For a possible solution see #975 pointing to https://stackoverflow.com/a/14355710/376587 (use |
|
Fixed by #1895. |
psutil still uses |
Oh you're right. I misread #1892 (comment). |
The problem is that on my virtualized macOS I get this: HW_CPU_FREQ: 2590000000 ...so it appears they are 2 different things. |
Same happening in Ubuntu 20.04 |
This is my first time posting in the psutil repo, but I have been trying to figure out how to pull the current CPU frequency on Apple Silicon for a few months now, and I've finally managed to create a script that can do that. In case anyone wants to take a look at it, the entire project is here, but this is the important part. Good day 👍 |
I see this wasn't really fixed in #1895 – I'm still getting: >>> psutil.__version__
5.9.0
>>> psutil.cpu_freq()
FileNotFoundError: [Errno 2] No such file or directory (originated from sysctl(HW_CPU_FREQ)) on M1 (MBP 2021, OS 12.2.1). Let me know how I could help with testing! |
I just took a grand tour of almost every GitHub issue regarding this, and think I've cracked this nut. This comment pointing to the clockrate.hz field is relevant, but the problem is what to multiply it by. The answer appears to be the time base frequency. On M1s, sysctl hw.tbfrequency returns 24,000,000 which when multiplied by 100 Hz gives the expected 2.4 GHz. However, that sysctl is not reliable on Intel hardware: on my Intel chip I get 1,000,000,000. This would obviously need testing by anyone with an M1 (or M2?) but I think the general logic should be:
|
@dbwiddis FYI I went down this rabbit hole in https://github.com/shirou/gopsutil/pull/999/files |
Indeed, and yours was one of the ones I visited in my grand tour, but I wasn't sure why you gave up on it; in the example given (a Hackintosh VM) the However, that said, I think I'm back to agreeing with you that it can't be done. There are ample
Time base frequency 0x016e3600 = 24,000,000 which disproves my proposal.... it's just the useless default. However, clock-frequency DOES work: But clock-frequency isn't reliable. Those same numbers on an M1:
So, yeah. Hardcoding 2.4 GHz seems to be the thing to do. |
macOS arm64 does not support cpu_freq: issue giampaolo#1892 Signed-off-by: mayeut <[email protected]>
macOS arm64 does not support cpu_freq: issue giampaolo#1892 Signed-off-by: mayeut <[email protected]>
macOS arm64 does not support cpu_freq: issue giampaolo#1892 Signed-off-by: mayeut <[email protected]>
macOS arm64 does not support cpu_freq: issue giampaolo#1892 Signed-off-by: mayeut <[email protected]>
macOS arm64 does not support cpu_freq: issue giampaolo#1892 Signed-off-by: mayeut <[email protected]>
macOS arm64 does not support cpu_freq: issue giampaolo#1892 Signed-off-by: mayeut <[email protected]>
macOS arm64 does not support cpu_freq: issue giampaolo#1892 Signed-off-by: mayeut <[email protected]>
Still facing this issue with M2 Max and psutil 5.9.4
|
Same on 5.9.4 on an M1 Pro with Ventura 13.2.1
|
@giampaolo I have seen this issue fixed in other OSS projects. For example, On my machine, this leads a max frequency of 3.5Ghz which matches what I see in |
Sure, please go for it!
I would say
|
For reference here's a simple C version we use for Go |
And here's a Java/JNA based solution based on this Issue/thread: |
Apple SoC returns empty string after querying the cpu frequency using sysctl, this information however, can still be extracted from the IOKit registry. This PR adds a new method that is specific to Apple ARM architecture. Fixes giampaolo#1892
Apple SoC returns empty string after querying the cpu frequency using sysctl, this information however, can still be extracted from the IOKit registry. This PR adds a new method that is specific to Apple ARM architecture. Fixes giampaolo#1892 Signed-off-by: Oliver Tome <[email protected]>
Apple SoC returns empty string after querying the cpu frequency using sysctl, this information however, can still be extracted from the IOKit registry. This PR adds a new method that is specific to Apple ARM architecture. Fixes giampaolo#1892 Signed-off-by: Oliver T <[email protected]>
I'm also interested by thix fix, as on M1, without that, no way it seems to use BabyAGI :-) (https://github.com/oliveirabruno01/babyagi-asi) ✘ py[babyagi-asi] ~/c/babyagi-asi main python babyagi.py
Traceback (most recent call last):
File "/Users/xxx/Code/babyagi-asi/babyagi.py", line 1, in <module>
import openai, prompts, consts, pinecone, os, subprocess, tiktoken, json
File "/Users/xxx/Code/babyagi-asi/prompts.py", line 9, in <module>
I am running on a {platform.system()} {platform.architecture()[0]} system with {round(psutil.virtual_memory().total / (1024 ** 3), 2)} GB RAM and a {psutil.cpu_freq().current/1000 if psutil.cpu_freq() else "unknown"} GHz CPU. I am using OpenAI API. I must remember to use '|' instead of '&&' or '&' in my commands if using windows' cmd or pws.
File "/Users/xxx/Library/Python/3.9/lib/python/site-packages/psutil/__init__.py", line 1864, in cpu_freq
ret = _psplatform.cpu_freq()
File "/Users/xxx/Library/Python/3.9/lib/python/site-packages/psutil/_psosx.py", line 179, in cpu_freq
curr, min_, max_ = cext.cpu_freq()
FileNotFoundError: [Errno 2] No such file or directory (originated from sysctl(HW_CPU_FREQ)) However this works: in the requirements.txt file, replace the line with that dependency, e.g
with
then |
Summary
Description
Sorry that I couldn't provide some of the info in the template as I don't own an Apple M1 device, but it is highly suspected that calling
psutil.cpu_freq()
on Apple M1 is failing as thehw.cpufrequency
sysctl call (used here) was removed on this arch (can be checked withsysctl hw.cpufrequency
on any Apple M1 device, while it is working on amd64).See shirou/gopsutil#999 and shirou/gopsutil#1000
In shirou/gopsutil#999 a fix was suggested but I couldn't confirm it.
psutil user-base is probably bigger than gopsutil's so I hope this will help both projects find a solution or confirm @shoenig fix in his PR.
The text was updated successfully, but these errors were encountered: