devutils/ATFQ/book ATFQ git

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, top and the load average count.
lscpu | grep -E '^(CPU\(s\)|Thread|Core|Socket)'
nproc                # CPUs this process may use

On your machine

alice@laptopexample
$ 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

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.

Commands
nproc lscpu
Paths
/sys/devices/system/cpu/
See also
18. CPU
1.2 How the kernel shares the CPUs
2.3 CPU caches: why memory layout matters
3.2 NUMA: when some memory is closer