Skip to content

Average CPU core frequency instead of harmonic mean - #546

Open
vjr wants to merge 1 commit into
mainfrom
vishal/fix-cpu-frequency
Open

vjr wants to merge 1 commit into
mainfrom
vishal/fix-cpu-frequency

Conversation

@vjr

@vjr vjr commented Sep 14, 2026

Copy link
Copy Markdown
Member

Simplify and also avoid potential divide-by-zero in the catch block.

Also avoid potential divide-by-zero in the catch block.
@vjr vjr self-assigned this Sep 14, 2026
@vjr
vjr requested review from a team and stsdc September 14, 2026 06:14
@stsdc

stsdc commented Sep 14, 2026

Copy link
Copy Markdown
Member

The harmonic mean was proposed here: #336

@vjr

vjr commented Sep 14, 2026

Copy link
Copy Markdown
Member Author

The harmonic mean was proposed here: #336

Hi @stsdc yes I see that issue was due to older code simply taking the max speed of the core with the highest speed and not averaging all the speedds, hence the issue reported as showing the max turbo of that person's CPU.

This PR uses simple average instead of harmonic mean because it appears to be closer to other tools like the btop cli tool and the CPU-x gui app, the latter was showing slightly lower speeds in general.

Also, avoids a potential divide-by-zero crash here: https://github.com/elementary/monitor/pull/546/changes#diff-0581d222df89dbc56e8440881a1559dbd77f83589c29aed3968cdb0f5b769f34L156

Looks like a worthwhile change, what do you think?

@jeremypw

jeremypw commented Sep 14, 2026

Copy link
Copy Markdown

I think you need to ask yourself what are you trying to convey by this number? The average calculated as here is equivalent to answering the question "If all the cpus where running at the same frequency, what frequency would give the same current overall work rate?". This ignores the fact that some cpu cycles that are wasted of course.

The harmonic average answers (as an intermediate step) the question "what is the average length of time each processor takes to do the same amount of work?" which, in my opinion, does not make sense if some cpus are not working and leads to possible division by zero. You could fix this by ignoring cpus that are not working.

You could also ask "if a single cpu were running all the cpu cycles how fast would it be running?" but the result might mislead.

@vjr

vjr commented Sep 15, 2026

Copy link
Copy Markdown
Member Author

@jeremypw of course this PR is to tweak the cpu frequency (hertz speed) displayed - there is also the existing untouched cpu utilisation (percentage usage) for each core.

example scenario(s) - you might have a heavy single-threaded app which uses just one core to its fullest, so the existing utilisation will show 100% on one core while the others might be near-zero regardless of the core frequency which can differ (say 2 Ghz or 5 Ghz) for the same cpu/computer based on whether the user has configured their computer BIOS/OS to run the cpu on low-power/efficient mode, balanced or performance/overclocked mode, if you see what i'm trying to convey?

@stsdc was my explanation about this PR clear enough, about that issue report you linked?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants