devutils/ATFQ/book ATFQ git

Part II · Your system

18. CPU

hub

What your processor is, how busy it is, and who keeps it busy.

On your machine

alice@laptopexample
$ atfq cpu
  CPU       11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz · 8 logical CPUs
  Load      1.25, 0.90, 0.62 over 1, 5 and 15 minutes, for 8 CPUs
  Tasks     2 running right now, 1043 in all
  Governor  powersave

An example: Alice's laptop, one of the test machines. In your terminal, this block shows your own machine, read live.

Commands

nproc
number of CPUs you can use
lscpu
model, cores, threads and caches
uptime
load average over 1, 5 and 15 minutes 18.1
top
busiest processes; press 1 for one line per CPU
mpstat -P ALL 1
usage of each CPU every second (package sysstat)

Paths

/proc/cpuinfo
one block per logical CPU
/proc/loadavg
load average and task counts
/sys/devices/system/cpu/
online CPUs, frequency, governor

Cards

  1. 18.1Load averageLoad average: the number of tasks running or waiting for a CPU, plus those waiting on disk (D state), averaged over 1, 5 and 15 minutes.

Also about this

  1. 1.2How the kernel shares the CPUsThere are more tasks wanting a CPU than CPUs, so the scheduler gives each a short turn, then switches: a context switch.
  2. 1.4Interrupts: how devices get attentionA device that needs the CPU (a packet arrived, a disk finished, a key was pressed) raises an interrupt: the CPU stops what it's doing and runs the kernel's handler for that device.
  3. 2.2Cores, threads and socketsA core is a complete processor. A chip (package, or socket) holds several; a server board can hold several chips.
  4. 2.3CPU caches: why memory layout mattersRAM is about 100 times slower than the CPU's own registers. Small, fast memories in the chip keep recent data close: L1 (tens of KiB per core, a few cycles), L2 (MiB, about a dozen cycles), L3 (shared, tens of cycles).
  5. 2.4Clock speed, turbo and power savingA CPU's speed changes all the time: it climbs when there's work, drops when idle, and goes above its base frequency (turbo) while power and heat allow.
  6. 16.3nice and prioritiesNiceness goes from -20 (greedy) to 19 (polite). The default is 0.