Part 2 of 7 · 2 min read
The machine
Think of it this way. A kitchen can have several cooks (processors), and each cook has a small private counter (a cache) next to the shared pantry (main memory). A cook finds the things used most on the private counter and walks to the pantry only for the rest. The analogy stops in one place: a real pantry is not slower to reach when many cooks use it, but main memory is.
In plain words: A core is one complete processing unit of a chip: it can run one thread of instructions at a time. A chip with several cores is a multicore processor. Some cores can also present themselves as two logical processors (hyper-threading, or simultaneous multithreading), sharing the core's units. The operating system sees each logical processor as one processor, and schedules a thread on it.
Linux shows what it found. On the test machine:
$ nproc
2
$ lscpu
CPU(s): 2
Thread(s) per core: 1
Core(s) per socket: 2
L1d cache: 96 KiB (2 instances)
L2 cache: 4 MiB (2 instances)
L3 cache: 260 MiB (1 instance)
Two logical processors, each a separate core, because there is one thread per core. Each core has its own level-1 and level-2 caches, and they share one level-3 cache and the main memory. The L1 figure of 96 KiB is the total of both cores, so each has 48 KiB. This layout, private small caches and a shared large one, is typical.
Caches are small and fast. A request for data goes first to the L1 cache, then to L2, then to L3, and last to main memory, each step slower. The caches hold data in units of cache lines, blocks of 64 bytes here (getconf LEVEL1_DCACHE_LINESIZE printed 64). Section 4 shows why this size matters for threads.
Core and logical processor
A core is an independent processing unit of a chip that executes instructions, so a multicore chip can run several threads at the same moment. A logical processor is what the operating system schedules threads on: usually one per core, or two per core when hyper-threading is on.
Example: nproc reports the number of logical processors, 2 on the test machine, where each core has a single thread.
Check yourself:
1. What does nproc report?
2. How big is a cache line on the test machine?
3. Which caches are private to a core and which are shared?