question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CurrentClockSpeed isn't correctly calculated on Windows.

See original GitHub issue

Library 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.

  1. Use a computer with a processor that scales its performance based on load. This is a critical element in reproducing this issue.
  2. Run Windows 11. (More likely than not Win8+ will be fine)

Example processor: 12th Gen Intel® Core™ i7-12700H

Steps

  1. Place your CPU under heavy load.
  2. Go to Device Manager and observe your CPU speed. (In my case it reads roughly 3.4-3.5GHz)
  3. 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:closed
  • Created 6 months ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jason-c-danielscommented, Mar 12, 2023

You’re awesome!

1reaction
Jinjinovcommented, Mar 12, 2023

Thank you for testing it! Here is the NuGet:

https://www.nuget.org/packages/Hardware.Info/10.1.1.1

Read more comments on GitHub >

github_iconTop Results From Across the Web

HOW TO SEE REAL TIME CLOCK SPEED OF MY CPU
THE TASK MANAGER IS SHOWING INCORRECT CLOCK SPEED OF CPU AS IT SHOWS CONSTANT ... I WANT CORRECT REAL TIME CLOCK SPEED OF...
Read more >
Annoyed that reported CPU speed is still wrong
Windows lazy programming assumed a BCLK of 100 MHz to calculate the max speed. ... I believe the 2.87 GHz is the current...
Read more >
C#: How to find the CPU's CURRENT Clock Speed?
On the WMI object the MaxClockSpeed property gives you the maximum speed of the core, which should be constant.
Read more >
Why the cpu frequency shows differently in Win10 task ...
I'd stick with CPU-Z for measuring CPU frequency as it's calculation algorithm is much better.
Read more >
Here's Why Your CPU Clock Frequency Keeps Changing
Your CPU's clock speeds might be changing due to performance settings, overclocking, or heat mitigation failures. You can fix these issues by ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found