Skip to content

Fix the NetBSD processor frequency recursion on non-x86 machines - #3812

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:netbsd-cpu-freq-recursion
Oct 15, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:netbsd-cpu-freq-recursion

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

On NetBSD machines without machdep.tsc_freq, such as ARM, NetBsdCentralProcessor.queryCurrentFreq fell back to queryMaxFreq. The inherited queryMaxFreq reads getCurrentFreq, which calls queryCurrentFreq again. Reading the current or maximum frequency, or the processor identifier, therefore ended in a StackOverflowError, and each pass started a sysctl process. The full SystemInfoTest report crashed in all three configurations.

Both lookups now share one helper that tries these sources in order:

  1. machdep.tsc_freq, which exists on x86 only.
  2. The frequency in the processor name, such as "@ 2.10GHz".
  3. machdep.dmi.processor-frequency, the only source on ARM. On the test machine it reads "2000 MHz".

If none gives a value, the result is -1. The parsing has a unit test.

Testing

  • I ran the full gate locally. It passed with 0 test failures.
  • I tested on cfarm428, a NetBSD 10.1 evbarm aarch64 KVM guest, with JNA without its native library, JNA with it, and FFM. In all three, the report runs to the end and shows 2 GHz for the vendor, maximum and current frequencies.
  • Not tested: the x86 path. It is unchanged apart from moving into the shared helper.

This came out of a survey comparing OSHI's NetBSD report against the operating system's own tools. The survey's other findings will follow as separate PRs.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed processor information lookups on NetBSD systems without a TSC frequency setting, including ARM systems, so they no longer overflow the stack.
    • Processor frequency is now read from the CPU name when available, with the SMBIOS frequency used as a fallback.

NetBsdCentralProcessor.queryCurrentFreq fell back to queryMaxFreq when
machdep.tsc_freq was absent, but the inherited queryMaxFreq reads
getCurrentFreq, which calls queryCurrentFreq again. On machines without
machdep.tsc_freq, such as ARM, any read of the current or maximum
frequency, or of the processor identifier, ended in a StackOverflowError,
starting a sysctl process on every pass.

Both now share one lookup: machdep.tsc_freq, then the frequency in the
processor name, then machdep.dmi.processor-frequency, the only source on
ARM. Verified on a NetBSD 10.1 aarch64 VM with the JNA (with and without
the native library) and FFM implementations: 2 GHz, no crash.
@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2557d0f7-6944-4c3e-b181-94cb148727b5
📥 Commits

Reviewing files that changed from the base of the PR and between 36294e6 and 171d629.

📒 Files selected for processing: 3
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessor.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessorTest.java

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

⏰ Context from checks skipped due to timeout: 12
  • GitHub Check: Test JDK 25, FreeBSD
  • GitHub Check: Test JDK 25, OpenBSD
  • GitHub Check: Test JDK 25, NetBSD
  • GitHub Check: Test JDK 25, OpenIndiana
  • GitHub Check: Lint (Spotless, Checkstyle)
  • GitHub Check: Test JDK 25, windows-latest
  • GitHub Check: Test JDK 26, ubuntu-latest
  • GitHub Check: Test JDK 25, ubuntu-latest
  • GitHub Check: Error Prone
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Lint (ForbiddenAPIs, Javadoc, SLF4J)
  • GitHub Check: Analyze (java)
🧰 Additional context used
📚 Code guidelines: 2
AGENTS.md — auto-discovered
CONTRIBUTING.md — auto-discovered
📓 Path-based instructions: 2
Source excerpt: **Banned APIs** (`config/forbidden-apis.txt` and friends, enforced by `forbiddenapis:check`): `oshi-common` may not reference `com.sun.jna.**`, `java.lang.foreign.**`, or any `System.load`/`loadLibrary`.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • oshi-common/src/test/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessorTest.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessor.java
Applicability reference: AGENTS.md: # AGENTS.md Instructions for AI coding agents working in the OSHI repository.

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Files:

  • CHANGELOG.md
🔇 Additional comments: 3
oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessor.java: 1

50-50: LGTM!

Also applies to: 56-56, 66-67, 69-75, 77-84, 94-96

oshi-common/src/test/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessorTest.java: 1

73-80: LGTM!

CHANGELOG.md: 1

21-21: LGTM!

📝 Walkthrough

NetBSD processor ID and current-frequency queries now share CPU-name and frequency lookup helpers. When machdep.tsc_freq is unavailable or non-positive, the code parses a frequency from the CPU name and then falls back to the DMI processor-frequency value.

Changes: NetBSD processor frequency fallback

Layer / File(s) Summary
Frequency lookup and validation
oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessor.java, oshi-common/src/test/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessorTest.java, CHANGELOG.md
Processor ID and current-frequency queries use shared CPU-name and frequency helpers. The lookup uses a positive TSC frequency or parses the CPU name, then falls back to DMI frequency. Tests cover GHz parsing, MHz fallback, and an empty fallback. The changelog records the NetBSD stack overflow fix.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 171d6

No actionable issue is established for the NetBSD frequency fallback; the change is mergeable after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 2 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: fixing recursive processor-frequency lookup on non-x86 NetBSD systems.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 2 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

A rabbit checks the CPU name,
Then finds the frequency in its frame.
If TSC is absent from view,
DMI can help it through.
The stack stays calm; the tests agree.

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

@codecov

codecov Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 69.23077% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.83%. Comparing base (36294e6) to head (171d629).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...n/platform/unix/netbsd/NetBsdCentralProcessor.java 69.23% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3812      +/-   ##
============================================
- Coverage     80.86%   80.83%   -0.04%     
- Complexity      652      654       +2     
============================================
  Files           725      725              
  Lines         26021    26021              
  Branches       4422     4421       -1     
============================================
- Hits          21043    21033      -10     
- Misses         2763     2773      +10     
  Partials       2215     2215              
Flag Coverage Δ
freebsd 37.13% <15.38%> (+0.01%) ⬆️
linux 41.17% <15.38%> (+0.01%) ⬆️
macos 42.29% <15.38%> (-0.04%) ⬇️
netbsd 36.41% <69.23%> (+0.01%) ⬆️
openbsd 37.01% <15.38%> (+<0.01%) ⬆️
solaris 38.27% <15.38%> (-0.02%) ⬇️
windows 48.57% <15.38%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dbwiddis
dbwiddis merged commit 7e4e5e6 into oshi:master Oct 15, 2026
20 checks passed
@dbwiddis
dbwiddis deleted the netbsd-cpu-freq-recursion branch October 15, 2026 04:40
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