-
-
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
Speed up cpu_frequncy() on Linux systems (#1851). #1852
Conversation
db8c08a
to
5e7d22f
Compare
Can you please make a review @giampaolo ? |
Would this work?
|
Ahh, we need to verify that |
The numbers give the actual CPU frequency, they are just encoded in hex for whatever reason. |
Hello there. I re-read the original issue. As a quick recap (correct me if I'm wrong), the problem as per #1851 (comment) is this: if we have 128 CPUs, that means we'll have to read I tried this PR with 8 CPUs, and it's slower:
What's the speedup with your patch + 128 CPUs? |
Also: is |
Micro optimization in reference to #1852 and #1851. Use glob.glob(), which internally relies on os.scandir() in order to list /sys/devices/system/cpu/cpufreq files. In doing so, we avoid os.path.exists() for each CPU, which internally uses os.stat(). Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
Hello. Thanks for reply.
No, reading min a max frequencies from
The benefit of
Heh :) Note these values quite close to each other (and very small), if I'm corrent it's On my BEFORE my patch:
after my patch:
That's 30x faster and I get the same speed for
About
|
OK, I'm convinced. =)
Other than that (minor change):
|
The current frequency (and AFAIK the only supported one) is available on Sparc, it's just in a different format. |
Is there a way to pre-emptively know if you're on SPARC? |
The sysfs files do not exist at least on my machines. You can either call |
59a0629
to
b101d24
Compare
All right, I assumed that. About the SPARC issue, I simply first parse |
b101d24
to
c0d1494
Compare
The change is about using /proc/cpuinfo when available. It provides cached values for frequencies and one can fill up minimum and maximum frequency from /sys/devices/system/cpu/cpufreq/policy/* sub-system (which is fast). Fixes giampaolo#1851.
c0d1494
to
0c7b2d4
Compare
@DerDakon what's the output of |
>>> os.uname()
posix.uname_result(sysname='Linux', nodename='castor', release='5.10.3-gentoo-sparc64', version='#1 SMP Wed Dec 30 12:57:02 CET 2020', machine='sparc64') |
The change is about using /proc/cpuinfo when available. It provides
cached values for frequencies and one can fill up minimum and maximum
frequency from /sys/devices/system/cpu/cpufreq/policy/* sub-system
(which is fast).
Fixes #1851.