Part I · How it works
2.2 Cores, threads and sockets
alsohyperthreadinghyper-threadingsmtthreads per coresocketslogical cpuslogical cpuphysical coresp-corese-coresbig.littlenproclscpucpu topologyisolcpus
TL;DR
- A core is a complete processor. A chip (package, or socket) holds several; a server board can hold several chips.
- With SMT (Intel calls it Hyper-Threading), one core runs two hardware threads. Each shows up as a CPU, but the two share the core's units: expect far less than twice the speed.
- Logical CPUs = sockets × cores × threads per core. That's what
nproc,topand the load average count.
lscpu | grep -E '^(CPU\(s\)|Thread|Core|Socket)'
nproc # CPUs this process may use
On your machine
$ atfq 2.2 CPUs 8 logical CPUs on 4 cores, up to 2 threads per core (SMT)
An example: Alice's laptop, one of the test machines. In your terminal, this block shows your own machine, read live.
Pitfalls
- A load average of 8 on "8 CPUs" that are 4 cores with SMT is a busier machine than it looks (18.1).
- In a container limited with
--cpus=2,nprocstill shows every CPU of the host: the limit is a time quota, not fewer CPUs. - Recent Intel chips mix performance (P) and efficiency (E) cores, like ARM's big.LITTLE: the same task runs at different speeds depending on where the scheduler puts it.
- Benchmarks vary between runs partly because of this: pin them with
taskset -c 2 ./bench.
Deep dive 2 questions
What does SMT actually gain?
A core has many execution units, and one thread rarely keeps them all busy: it waits for memory, or mispredicts a branch. A second thread fills the gaps. The gain is often 10 to 30 %, sometimes nothing when both threads compete for the same units or cache. Some recent Intel chips dropped it on their performance cores, and some clouds disable it, since two threads on one core can spy on each other (2.5).
Why would some CPUs be isolated?
isolcpus= on the kernel command line, or a CPU set in a cgroup, keeps
the scheduler from placing ordinary tasks there. Real-time and trading
systems, or virtual machine hosts, then pin one task to those CPUs, so
nothing interrupts it and its caches stay warm.