Commit 1023109
authored
Add amd64 CPU topology tree enumeration (#179)
* Add amd64 CPU topology tree enumeration
Add a topology tree with a fixed hierarchy System → Package → Group →
Core → Thread, where a Group is a last-level-cache (L3) sharing domain —
an AMD CCX/CCD or an Intel LLC tile. Cores carry their type
(performance/efficiency) and every level answers aggregate queries over
what's below it (NumCores, NumThreads, CoresByType, TotalCache) without
double-counting shared caches, so e.g. sys.TotalCache(3, Unified) is the
total L3 across all CCDs.
- New topology sub-package: pure types + query methods + a tree String();
no dependencies of its own.
- CPUID parsing/assembly stays in package cpuid: x2APIC decomposition from
leaves 0x1F/0x0B, cache sharing from 0x04/0x8000001D, hybrid core type
from 0x1A, AMD node id and SMT from 0x8000001E.
- CPU.Topology(): cheap single-core snapshot (default, no thread pinning).
ScanTopology(): opt-in exact per-core walk that pins to each CPU
(linux/amd64, windows/amd64 via x/sys, already a dependency), falling
back to the snapshot with ErrTopologyScanUnavailable elsewhere and on
non-x86.
- cmd/cpuid: add -topology to print the tree and cache totals.
- Tests replay every recorded per-logical-CPU CPUID dump and validate the
built tree against the dumps' Package/Core/Thread ground-truth headers;
internal/samplecpu supplies a fixture for the unit tests and examples.
Example:
```
λ cpuid -topology
System: AMD (scanned) — 1 package(s), 16 core(s), 32 thread(s)
Package #0
Group #0 [L3 32MB]
Core #0 (Performance) threads: 0, 1 [L1d 48KB L1i 32KB L2 1MB]
Core #1 (Performance) threads: 2, 3 [L1d 48KB L1i 32KB L2 1MB]
Core #2 (Performance) threads: 4, 5 [L1d 48KB L1i 32KB L2 1MB]
Core #3 (Performance) threads: 6, 7 [L1d 48KB L1i 32KB L2 1MB]
Core #4 (Performance) threads: 8, 9 [L1d 48KB L1i 32KB L2 1MB]
Core #5 (Performance) threads: 10, 11 [L1d 48KB L1i 32KB L2 1MB]
Core #6 (Performance) threads: 12, 13 [L1d 48KB L1i 32KB L2 1MB]
Core #7 (Performance) threads: 14, 15 [L1d 48KB L1i 32KB L2 1MB]
Group #1 [L3 32MB]
Core #8 (Performance) threads: 16, 17 [L1d 48KB L1i 32KB L2 1MB]
Core #9 (Performance) threads: 18, 19 [L1d 48KB L1i 32KB L2 1MB]
Core #10 (Performance) threads: 20, 21 [L1d 48KB L1i 32KB L2 1MB]
Core #11 (Performance) threads: 22, 23 [L1d 48KB L1i 32KB L2 1MB]
Core #12 (Performance) threads: 24, 25 [L1d 48KB L1i 32KB L2 1MB]
Core #13 (Performance) threads: 26, 27 [L1d 48KB L1i 32KB L2 1MB]
Core #14 (Performance) threads: 28, 29 [L1d 48KB L1i 32KB L2 1MB]
Core #15 (Performance) threads: 30, 31 [L1d 48KB L1i 32KB L2 1MB]
Total cache: L1D 768KB, L1I 512KB, L2 16MB, L3 64MB
```
* Add sample cpu
* Fix feedback
* Apply fix1 parent 4e17f59 commit 1023109
12 files changed
Lines changed: 1547 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
41 | 58 | | |
42 | 59 | | |
43 | 60 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
479 | 479 | | |
480 | 480 | | |
481 | 481 | | |
| 482 | + | |
482 | 483 | | |
483 | 484 | | |
484 | 485 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
0 commit comments