CurrentClockSpeed isn't correctly calculated on Windows.
See original GitHub issueLibrary version
10.1.1
OS & OS version
Windows 11, latest as of 2023-03-11
Describe the bug
cpu.CurrentClockSpeed
is incorrect on some processors. Those processors scale performance based on load. Under high load it is lower than the actual clock speed. Under light load it is higher than the actual clock speed. In fact it always the same as cpu.MaxClockSpeed
.
Context
Modern CPUs can scale their performance. The code for this library only uses WMI queries. WMI does not appear to account for this fact.
The correct calculation for those sorts of CPUs is to scale the maximum CPU speed returned by the current WMI query being done by the Windows Performance Counter: \Processor Information(_Total)% Processor Performance
This SO question has the correct calculation in the answer.
To Reproduce
Physical Environment.
- Use a computer with a processor that scales its performance based on load. This is a critical element in reproducing this issue.
- Run Windows 11. (More likely than not Win8+ will be fine)
Example processor: 12th Gen Intel® Core™ i7-12700H
Steps
- Place your CPU under heavy load.
- Go to Device Manager and observe your CPU speed. (In my case it reads roughly 3.4-3.5GHz)
- Run
HardwareInfo.RefreshCPUList()
while under heavy load.
Expected Result
When my CPU, which is 2.3Ghz, is at 150% ProcessorPerformance
I should get 3450 for cpu.CurrentClockSpeed
.
Actual Result
cpu.CurrentClockSpeed
reads 2300.
As for this: If you don't provide C# code to reproduce the problem, the issue will be closed.
Since this is hardware specific, and I’ve pinpointed the root cause, the correct calculation, and an StackOverflow article with code you should be able to all but copy and paste from, you should have all the information you need to proceed, for Windows. Hardware may be a different story. I don’t know about Macs or Linux.
So, please make an exception. You will need to get the right hardware… or someone with it willing to run the code and report findings… I’m willing to be that guinea pig.
Issue Analytics
- State:
- Created 6 months ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
You’re awesome!
Thank you for testing it! Here is the NuGet:
https://www.nuget.org/packages/Hardware.Info/10.1.1.1