{pk !== undefined && (() => {
const u = sockUse(pk), t = sockTemp(pk), w = pt?.cpu_power_pkgs_w?.[pk], open = !folded.includes(pk)
@@ -439,13 +443,13 @@ export default function Top() {
)
})()}
- {cores.map((v, i) => {
- if (pk !== undefined && (pkgs?.[i] !== pk || folded.includes(pk))) return null
- const t = coreTemp(i)
+ {(pk !== undefined && folded.includes(pk) ? [] : cpus).map((i, n) => {
+ // n is the thread's number under its own CPU, i the kernel's for the whole machine
+ const t = coreTemp(i), v = cores[i] ?? 0
return (
- C{i}
- {braille(recent.get(`cpu.core.${i}.usage`) ?? [], 9)}
+ C{n}
+ {braille(recent.get(`cpu.core.${i}.usage`) ?? [], 9)}
{Math.round(v)}%
{anyTemp && <>{t !== undefined && }{t !== undefined ? `${Math.round(t)}°C` : ''}>}
diff --git a/web/src/sockets.ts b/web/src/sockets.ts
new file mode 100644
index 0000000..df5eaf2
--- /dev/null
+++ b/web/src/sockets.ts
@@ -0,0 +1,17 @@
+// Which threads belong to which CPU, on a machine with more than one.
+//
+// The kernel numbers every thread of the machine in one run, and on a two-socket board with
+// hyper-threading it deals them out a socket at a time and then goes round again: cpu 0–9 are
+// CPU 1's cores, 10–19 CPU 2's, 20–29 the second threads of CPU 1's, 30–39 of CPU 2's. Listed
+// under its CPU by that number, a 20-thread processor reads "C0…C9, C20…C29" and the one
+// beside it "C10…C19, C30…C39" — neither looks like twenty of anything. So each CPU's threads
+// are counted from 0 under it, in the kernel's order, the way a one-socket machine's are: the
+// first half are its cores, the second half their second threads.
+//
+// `pkgs[i]` is the socket logical CPU `i` is on. The answer is, for each socket (ascending),
+// the logical CPUs on it (ascending); a thread's number under its CPU is its place in that list.
+export function socketThreads(pkgs: number[]): { pkg: number; cpus: number[] }[] {
+ const by = new Map()
+ pkgs.forEach((pk, i) => { const l = by.get(pk); if (l) l.push(i); else by.set(pk, [i]) })
+ return [...by.entries()].sort((a, b) => a[0] - b[0]).map(([pkg, cpus]) => ({ pkg, cpus }))
+}