lscpu
Overview
The lscpu
command displays detailed information about the CPU architecture, including processor type, cores, threads, cache sizes, and various CPU features.
Syntax
lscpu [options]
Common Options
Option | Description |
---|---|
-a |
Include offline CPUs |
-b |
Online CPUs only |
-c |
Compatible format |
-e |
Extended readable format |
-p |
Parsable format |
-s directory |
Use specific sysfs directory |
-x |
Include hex and binary flags |
-y |
Show physical IDs |
Key Information Displayed
Field | Description |
---|---|
Architecture | CPU architecture (x86_64, ARM, etc.) |
CPU op-mode(s) | 32-bit, 64-bit |
Byte Order | Little Endian, Big Endian |
CPU(s) | Total number of logical CPUs |
Thread(s) per core | Hyperthreading info |
Core(s) per socket | Physical cores per CPU |
Socket(s) | Number of CPU sockets |
Model name | CPU brand and model |
CPU MHz | Current frequency |
CPU max MHz | Maximum frequency |
CPU min MHz | Minimum frequency |
Cache sizes | L1, L2, L3 cache information |
Key Use Cases
- System inventory
- Performance analysis
- Virtualization planning
- Hardware compatibility checks
- System monitoring setup
Examples with Explanations
Example 1: Basic CPU Information
lscpu
Shows complete CPU information in human-readable format
Example 2: Parsable Format
lscpu -p
Outputs CPU information in comma-separated format for scripting
Example 3: Extended Format
lscpu -e
Shows extended information including NUMA topology
Understanding CPU Topology
Key relationships: - Socket: Physical CPU package - Core: Physical processing unit - Thread: Logical processing unit (with hyperthreading) - NUMA Node: Memory locality group
Calculation:
Total CPUs = Sockets × Cores per socket × Threads per core
Common Usage Patterns
Check CPU count:
lscpu | grep "CPU(s):"
Get CPU model:
lscpu | grep "Model name"
Check virtualization support:
lscpu | grep Virtualization
Performance Analysis
Information useful for performance: - Cache sizes (L1, L2, L3) - CPU frequency ranges - Thread/core ratios - NUMA topology - CPU flags and features
Scripting Examples
Extract CPU count:
CPU_COUNT=$(lscpu | grep "^CPU(s):" | awk '{print $2}')
Check architecture:
ARCH=$(lscpu | grep "Architecture:" | awk '{print $2}')
Get CPU model:
MODEL=$(lscpu | grep "Model name:" | cut -d':' -f2 | xargs)
Parsable Output Format
Using -p
option provides CSV-like output:
# CPU,Core,Socket,Node,,L1d,L1i,L2,L3
0,0,0,0,,32K,32K,256K,8192K
1,1,0,0,,32K,32K,256K,8192K
Additional Resources
Best Practices
- Use parsable format for scripts
- Check virtualization capabilities
- Monitor CPU frequency scaling
- Understand NUMA topology for optimization
- Verify CPU features for software requirements
Virtualization Information
CPU virtualization features: - VT-x/AMD-V: Hardware virtualization - VT-d/AMD-Vi: I/O virtualization - EPT/NPT: Extended/Nested page tables
Check support:
lscpu | grep -E "(vmx|svm)"
NUMA Topology
For multi-socket systems:
lscpu | grep NUMA
Shows: - NUMA node count - CPU-to-node mapping - Memory locality information
CPU Flags and Features
Important flags: - sse, sse2, sse3: SIMD instructions - aes: AES encryption support - avx, avx2: Advanced vector extensions - rdrand: Hardware random number generator
Frequency Information
Modern CPUs show: - Base frequency - Maximum turbo frequency - Current frequency - Scaling governor information
Integration Examples
System monitoring:
echo "CPU: $(lscpu | grep 'Model name' | cut -d':' -f2 | xargs)"
Performance tuning:
CORES=$(lscpu | grep "Core(s) per socket" | awk '{print $4}') make -j$CORES
Capacity planning:
lscpu -p | grep -v "^#" | wc -l
Troubleshooting
- Missing CPU information
- Incorrect core counts
- Frequency scaling issues
- Virtualization detection problems
- NUMA topology confusion
Output Filtering
Get specific information:
lscpu | grep -i cache
Extract numeric values:
lscpu | grep "CPU(s):" | grep -o '[0-9]*'
Format for reports:
lscpu | grep -E "(Architecture|CPU\(s\)|Model name)"