@IT·互联网

Linux lscpu 命令使用详解

2025-05-12  本文已影响0人  青枫教学

简介

lscpuLinux 中的一个命令行工具,它通过读取 /proc/cpuinfosysfs 来显示详细的 CPU 架构信息,包括架构、核心数、线程数、缓存、NUMA 节点等。

基础使用

lscpu

显示 CPU 架构的摘要

示例

Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                8
On-line CPU(s) list:   0-7
Thread(s) per core:    2
Core(s) per socket:    4
Socket(s):             1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 158
Model name:            Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
Stepping:              9
CPU MHz:               2808.002
BogoMIPS:              5616.00
Virtualization:        VT-x
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              6144K
NUMA node0 CPU(s):     0-7

输出字段详解

通用信息

核心与线程

CPU 型号与性能

缓存

虚拟化与特性

常用选项

示例用法

查看逻辑 CPU 布局(CPU-核心-插槽)

lscpu -e

查看 CPU 核心数

lscpu | grep 'Core(s) per socket'

以 JSON 格式显示脚本

lscpu --json | jq .

检查 CPU 限制

lscpu | grep MHz

检查 CPU 的扩展频率(对于性能调整或节能很重要)

快速查找 CPU 供应商/型号

lscpu | grep -E 'Vendor|Model name'

查看逻辑 CPU 数量

slscpu | grep "CPU(s):" | head -n 1

检查是否启用超线程

lscpu | grep "Thread(s) per core"
# 输出为 2 表示启用超线程,1 表示未启用

查看 NUMA 节点分布

lscpu | grep -i numa
numactl --hardware  # 更详细的 NUMA 信息

获取 CPU 型号

lscpu | grep "Model name"

用于脚本解析的输出

lscpu -p | grep -v '^#'  # 过滤注释行
# 输出格式:CPU,CORE,SOCKET,NODE,...

CPU 拓扑结构图示

lscpu -e 输出

CPU NODE SOCKET CORE L1d:L1i:L2:L3 ONLINE MAXMHZ MINMHZ
0   0    0      0    0:0:0:0      yes    4000   400
1   0    0      0    0:0:0:0      yes    4000   400
2   0    0      1    1:1:1:0      yes    4000   400
3   0    0      1    1:1:1:0      yes    4000   400
4   0    0      2    2:2:2:0      yes    4000   400
5   0    0      2    2:2:2:0      yes    4000   400
6   0    0      3    3:3:3:0      yes    4000   400
7   0    0      3    3:3:3:0      yes    4000   400

图形拓扑图

Socket 0
└── Core 0
    ├── CPU 0 (Logical thread 1)
    └── CPU 1 (Logical thread 2)
└── Core 1
    ├── CPU 2
    └── CPU 3
└── Core 2
    ├── CPU 4
    └── CPU 5
└── Core 3
    ├── CPU 6
    └── CPU 7

字段解释

上一篇 下一篇

猜你喜欢

热点阅读