Reading lscpu, line by line
Video 026 of 140 in Virtualization Foundations, in the unit “CPUs: sockets, cores, threads and caches”. 3:37, with English and Hindi audio.
One command describes a server's processor. It is called lscpu, and it prints one fact per line. Read from top to bottom, the lines build a picture of the chip, from its family down to its threads. This article walks through an example host, explains each group of lines, shows how the counts multiply into the CPU total, and points out the mistakes that are easy to make when reading them.
What you will learn
- Architecture and Vendor ID name the chip family and its maker.
- Sockets times cores per socket times threads per core gives the logical CPU count.
- A thread count of two means hyper-threading is on.
- The NUMA lines show which CPUs sit with which memory.
The top lines: the chip family and its maker
Architecture tells you the family of instructions. In the example, it reads x86_64, so the chip is an x86-64 chip. The CPU op-mode line says the chip runs both 32-bit and 64-bit programs. Vendor ID names the maker: GenuineIntel means Intel, and AuthenticAMD means AMD.
The counting lines, and how they multiply
- CPU(s): the total of logical CPUs, the number the operating system schedules work on.
- Thread(s) per core: how many logical CPUs each core shows. Two means hyper-threading is on.
- Core(s) per socket: the real cores in each chip.
- Socket(s): the chips on the board.
Multiply the last three. In the example, two sockets, times twenty-four cores, times two threads, gives ninety-six. That is the CPU total on the first line.
Note: The most common mistake is to read CPU(s) as a count of cores. It counts threads too, so split it into sockets, cores and threads first.
The NUMA lines: which CPUs sit with which memory
NUMA stands for non-uniform memory access. Some memory sits near one group of CPUs and far from another. The NUMA lines group the CPUs with their memory, and the number of NUMA nodes usually matches the number of sockets.
lscpu | grep -E 'Socket|NUMA'The numbers after the colon are CPU numbers. Each node's list includes both threads of its cores.
A mistake to avoid inside a virtual machine
Inside a virtual machine, lscpu shows the layout that the hypervisor, the software that runs the machine, chose for it. That is not the real host's layout. So write down the sockets, cores, threads and NUMA nodes of every host, as you read them from the host itself.
Read the lscpu output of your host
You need a Linux terminal on the host you want to read. You will print the full lscpu output, then filter it for the socket and NUMA lines.
Print the full description of the processor, one fact per line. Read it from the top down: the family, the counts, then the NUMA lines.
lscpuWhat you should see: Lines such as Architecture: x86_64, Thread(s) per core, Core(s) per socket and Socket(s). The example host shows Virtualization: VT-x.
Filter the output for the socket and NUMA lines, to see which CPUs sit with which memory.
lscpu | grep -E 'Socket|NUMA'What you should see: The socket count and the NUMA node count, then one CPU list for each NUMA node.
Terms
- Logical CPU
- One processing unit that the operating system can schedule work on, which may be a whole core or one thread of a core.
- NUMA
- Non-uniform memory access: some memory sits near one group of CPUs and farther from another.
- Socket
- The slot on a motherboard that holds one processor chip.
Check yourself
How do you get the CPU total from the counting lines?
Multiply the sockets, the cores per socket and the threads per core. Two sockets, twenty-four cores and two threads each give ninety-six.
What does Thread(s) per core: 2 mean?
Each core shows two logical CPUs, which means hyper-threading is on.
Why should you not read lscpu inside a virtual machine as the host's layout?
The virtual machine shows the layout the hypervisor chose for it, which may differ from the real host.
Previous: CPU feature flags: what the chip can do. Next: User mode and kernel mode.