Skip to content

Cpu usage semantics#61

Open
homm wants to merge 5 commits into
vladkens:mainfrom
homm:cpu-usage-semantics
Open

Cpu usage semantics#61
homm wants to merge 5 commits into
vladkens:mainfrom
homm:cpu-usage-semantics

Conversation

@homm
Copy link
Copy Markdown

@homm homm commented Apr 29, 2026

This PR ports the frequency/usage calculation fixes from #59.

Summary

It changes how usage tuples are calculated:

  • sampled CPU/GPU usage is now based on IOReport active residency ratio, not scaled by frequency;
  • CPU cluster frequency is reported as the highest active core frequency in the sample;
  • CPU cluster usage is normalized to that reported peak active frequency;
  • idle CPU clusters now remain 0 MHz / 0% instead of being forced to the minimum DVFS frequency.

The JSON shape is unchanged: ecpu_usage, pcpu_usage, and gpu_usage are still [freq_mhz, usage].

Why

In the previous implementation, calc_freq scaled usage by avg_freq / max_freq, and the result was exposed through fields such as pcpu_usage:

usage = active_residency / total_residency * avg_freq / max_freq

That mixes occupancy with frequency. Under Low Power Mode, thermal limits, or any workload where frequency and occupancy diverge, a fully busy core can look partially idle just because it is not running at the theoretical maximum frequency.

Issue #46 correctly pointed out that the reported value was misleading. The problem was likely not that one CPU cluster was being dropped, but that the metric itself under-reported occupancy by folding frequency into usage.

This PR first computes usage from residency, then aggregates CPU cluster values as a compact "effective load at shown active frequency" summary.

Examples

All examples use a 10-core P-cluster with min_freq = 1250 MHz and max_freq = 4500 MHz.

All idle

  10 cores: 0% @ 0 MHz
Old TUI: P-CPU 0.0% @ 1250 MHz
New TUI: P-CPU 0.0% @ 0 MHz

Why: if the cluster has no active residency in the sample window, there is no observed active frequency to report.

One active core

  1 core: 100% @ 3600 MHz
  9 cores: 0% @ 0 MHz
Old TUI: P-CPU 8.0% @ 1250 MHz (freq = max(3600 / 10, 1250))
New TUI: P-CPU 10.0% @ 3600 MHz

Why: one of ten cores is fully occupied, and the active work is running at 3600 MHz.

One active core, idle cores still report frequency

  1 core: 100% @ 3600 MHz
  4 cores: 0% @ 3600 MHz
  5 cores: 0% @ 0 MHz
Old TUI: P-CPU 8.0% @ 1800 MHz
New TUI: P-CPU 10.0% @ 3600 MHz

Why: idle cores may still carry a reported frequency, but the cluster summary should describe active work.

One peak core plus low-frequency active cores

  1 core: 100% @ 3600 MHz
  4 cores: 80% @ 1000 MHz
  5 cores: 0% @ 0 MHz
Old TUI: P-CPU 15.1% @ 1250 MHz (freq = max((3600 + 1000 * 4) / 10, 1250))
New TUI: P-CPU 18.9% @ 3600 MHz

Why: the summary keeps the observed peak active frequency visible, while lower-frequency work contributes proportionally less to effective load at that frequency.

All cores fully active under frequency limits

  10 cores: 100% @ 2500 MHz
Old TUI: P-CPU 55.6% @ 2500 MHz
New TUI: P-CPU 100.0% @ 2500 MHz

Why: the cluster is fully occupied. A lower frequency caused by thermal or power limits should not make fully busy cores look idle.

homm and others added 5 commits April 29, 2026 12:01
Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Codex <codex@openai.com>
@homm homm mentioned this pull request May 5, 2026
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.

1 participant