psutil icon indicating copy to clipboard operation
psutil copied to clipboard

[OS] Why the function of cpu_freq() always getting the cpu default freq?

Open ElinLiu0 opened this issue 3 years ago • 1 comments

Summary

  • OS: Windows11 Home
  • Architecture: 64bit
  • Psutil version: 5.8.0
  • Python version: 3.9.7(Base on Conda)
  • Type: BugIssuses

Description

Yeah,pretty confusing that i wanna using Flask and Psutil to make a monitor system,and yet the cpu_freq() functions seems doesnt work to detect freq? image

But in fact is:my cpu turboing very well. image So how should i fix that or otherwise is bottom layer issuses?

ElinLiu0 avatar Mar 10 '22 03:03 ElinLiu0

Seems it's hardcoded that way:

def cpu_freq():
    """Return CPU frequency.
    On Windows per-cpu frequency is not supported.
    """
    curr, max_ = cext.cpu_freq()
    min_ = 0.0
    return [_common.scpufreq(float(curr), min_, float(max_))]

In the implementation the call to GetNTPowerInformation() returns a ncpu-sized array of PROCESSOR_POWER_INFORMATION structures but only the first one is fetched. (Note: on systems with more than 64 logical processor groups this only returns the values for one group.)

I recall going down this road and think perhaps I saw that the frequencies were all the same here so this code may be acknowledging the API limitation.

A better source of processor frequency information is the performance counters: Processor Information\% of Maximum Frequency returns a value 0 to 100 that can be multiplied by max freq (and divided by 100) to calculate it.

dbwiddis avatar Mar 11 '22 22:03 dbwiddis

Close this issuse due to unknow reasons

ElinLiu0 avatar Feb 07 '23 12:02 ElinLiu0