Skip to content

darwin: Fetch CPU frequency via sysctl (hw.cpufrequency) - #2091

Open
badger200 wants to merge 1 commit into
htop-dev:mainfrom
badger200:fix-darwin-cpu-frequency
Open

darwin: Fetch CPU frequency via sysctl (hw.cpufrequency)#2091
badger200 wants to merge 1 commit into
htop-dev:mainfrom
badger200:fix-darwin-cpu-frequency

Conversation

@badger200

Copy link
Copy Markdown

Fixed setting Show CPU Frequency checkbox so it works now instead of displaying <N/A>.
Assisted-by: Antigravity ai@google.com

Signed-off-by: badger200 <badger200@users.noreply.github.com>
Assisted-by: Antigravity <ai@google.com>
@coderabbitai

coderabbitai Bot commented Aug 28, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: bdc0275d-d5c9-4ed9-91dd-8a98a2c3d47f

📥 Commits

Reviewing files that changed from the base of the PR and between 19fc8c1 and 4f99595.

📒 Files selected for processing (1)
  • darwin/Platform.c

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

Darwin CPU sampling now includes the sysctl API and reads hw.cpufrequency with a fallback to hw.cpufrequency_max. Successful values convert from Hz to MHz. Disabled display or failed queries store NAN. CPU aggregation averages valid frequencies and stores NAN when no valid values exist.

Suggested reviewers: ravi-arnan

Poem

Darwin asks the silicon,
Frequencies answer in hertz,
Megahertz fill the samples,
Missing values become NAN,
Valid readings join the mean,
And CPUs hum in balance.

Merge Risk: ⚪ Minimal · up to 4f995

This localized Darwin change enables CPU-frequency display through read-only system metadata lookup without changing interfaces, permissions, persistent state, or deployment behavior. No actionable merge-blocking risk remains beyond normal checks and review.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@fasterit fasterit added the MacOS 🍏 MacOS / Darwin related issues label Aug 29, 2026
Comment thread darwin/Platform.c
size_t len = sizeof(cpufreq);
if (sysctlbyname("hw.cpufrequency", &cpufreq, &len, NULL, 0) == 0 && cpufreq > 0) {
frequency = (double)cpufreq / 1E6;
} else if (sysctlbyname("hw.cpufrequency_max", &cpufreq, &len, NULL, 0) == 0 && cpufreq > 0) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is len guaranteed to be unchanged when the first of these two sysctls fails?

Comment thread darwin/Platform.c
if (mtr->host->settings->showCPUFrequency) {
uint64_t cpufreq = 0;
size_t len = sizeof(cpufreq);
if (sysctlbyname("hw.cpufrequency", &cpufreq, &len, NULL, 0) == 0 && cpufreq > 0) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the per-core frequency? Because I don't see, where it follow's up on the cpu argument provided to this function.

@BenBE BenBE added the enhancement Extension or improvement to existing feature label Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Extension or improvement to existing feature MacOS 🍏 MacOS / Darwin related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants