Skip to content

✨ Add machine.cpu resource with correct socket/core reporting#6946

Merged
tas50 merged 3 commits intomainfrom
fix/machine-cpu-resource
Mar 18, 2026
Merged

✨ Add machine.cpu resource with correct socket/core reporting#6946
tas50 merged 3 commits intomainfrom
fix/machine-cpu-resource

Conversation

@tas50
Copy link
Copy Markdown
Member

@tas50 tas50 commented Mar 17, 2026

Summary

  • Add machine.cpu resource with fields: manufacturer, model, processorCount, cores
  • processorCount reports physical CPU packages (sockets), not logical threads
  • cores reports physical CPU cores
  • Set @defaults("manufacturer model processorCount cores") for clean default output
  • Normalize manufacturer names: GenuineIntelIntel, AuthenticAMDAMD via shared normalizeManufacturer() helper
  • Platform support:
    • Linux/proc/cpuinfo with physical_id/core_id deduplication
    • macOSsysctl (brand string + hw.physicalcpu)
    • WindowsWin32_Processor via PowerShell
    • FreeBSDsysctl (hw.model + kern.smp.cores)
    • AIXprtconf for model + lsdev -Cc processor for physical core count
    • Solarispsrinfo -pv for sockets, cores, and model

Test plan

  • Unit tests for Linux x64 Intel (2-socket, GenuineIntel → Intel)
  • Unit tests for Linux AMD (AuthenticAMD → AMD)
  • Unit tests for Linux ARM (fallback: 1 socket, cores from processor count)
  • Unit tests for macOS Apple Silicon (manufacturer extraction, 1 socket)
  • Unit tests for macOS Intel (manufacturer extraction, 1 socket)
  • Unit tests for FreeBSD (sysctl-based, manufacturer from model string)
  • Unit tests for AIX (lsdev physical cores vs prtconf logical)
  • Unit tests for Solaris (2-socket Xeon, psrinfo parsing)
  • Interactive verification: mql run local -c "machine.cpu{*}"

🤖 Generated with Claude Code

processorCount now reports physical CPU packages (sockets) instead of
logical thread count. Manufacturer names are normalized (GenuineIntel →
Intel, Apple prefix stripped from model on macOS).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@mondoo-code-review mondoo-code-review bot left a comment

Choose a reason for hiding this comment

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

New machine.cpu resource provides CPU socket/core info across Linux, macOS, and Windows.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 17, 2026

Test Results

5 485 tests  +8   5 481 ✅ +8   2m 10s ⏱️ +6s
  411 suites ±0       4 💤 ±0 
   31 files   ±0       0 ❌ ±0 

Results for commit 93d3f8a. ± Comparison against base commit b298954.

♻️ This comment has been updated with latest results.

Copy link
Copy Markdown

@mondoo-code-review mondoo-code-review bot left a comment

Choose a reason for hiding this comment

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

Adds FreeBSD/AIX CPU detection and normalizes AMD manufacturer string with good test coverage.

@tas50 tas50 force-pushed the fix/machine-cpu-resource branch from 68c5e9b to 92cb623 Compare March 17, 2026 01:31
Copy link
Copy Markdown

@mondoo-code-review mondoo-code-review bot left a comment

Choose a reason for hiding this comment

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

New machine.cpu resource correctly reports CPU socket/core information across platforms.

@tas50 tas50 force-pushed the fix/machine-cpu-resource branch from 92cb623 to 0884672 Compare March 17, 2026 01:37
- Add getCpuInfoFreeBSD using sysctl hw.model and kern.smp.cores
- Add getCpuInfoAIX using prtconf output parsing
- Extract normalizeManufacturer helper: GenuineIntel→Intel, AuthenticAMD→AMD
- Apply normalizeManufacturer to Linux and Windows paths
- Add tests for AMD Linux, FreeBSD, and AIX

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@tas50 tas50 force-pushed the fix/machine-cpu-resource branch from 0884672 to 93d3f8a Compare March 17, 2026 01:43
@tas50 tas50 added the manually-tested PR content has been manually tested against real assets label Mar 17, 2026
}

// CPU information
machine.cpu @defaults("manufacturer model processorCount cores") {
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.

I think we want machine.cpus as default as some systems can bundle multiple together. Therefore we should expose the logical cpus as /proc/cpuinfo does

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I renamed cores to coreCount so we can add a cores field in the future that includes all the individual cores

address sizes : 48 bits physical, 48 bits virtual
power management:

processor : 1
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.

I think we want to expose the every "logical CPU" as the model and vendors can differ

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That would be in the cores field in the future if we need it on arm platforms

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@tas50 tas50 merged commit 2ac2e24 into main Mar 18, 2026
21 checks passed
@tas50 tas50 deleted the fix/machine-cpu-resource branch March 18, 2026 04:39
@github-actions github-actions bot locked and limited conversation to collaborators Mar 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

manually-tested PR content has been manually tested against real assets

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants