#Bash 的 lscpu 命令
lscpu [OPTION]... [DEVICE]...
功能
列出 CPU 信息。
类型
可执行文件(/usr/bin/lscpu),属于 util-linux。
参数
OPTION选项:-a,--all- 显示所有 CPU;必须和--extended或--parse一起使用-B,--bytes- 使用字节作为单位-b,--online- 仅显示在线的 CPU;必须和--extended或--parse一起使用-C,--caches[=list]- 显示 CPU 缓存信息,可用通过list指定输出的列名列表(以逗号分隔)-c,--offline- 仅显示离线的 CPI;必须和--extended或--parse一起使用--hierarchic[=when]- 在摘要输出中使用子小节-e,--extended[=list]- 以易于理解的格式输出,可用通过list指定输出的列名列表(以逗号分隔)-J,--json- 以 JSON 格式输出-p,--parse[=list]- 优化命令输出以便于解析,可用通过list指定输出的列名列表(以逗号分隔)-s,--sysroot directory- 指定根目录为directory,可用于查看来自其它系统的 udev 信息-x,--hex- 使用十六进制掩码表示 CPU 集-y,--physical- 显示所有包含拓扑元素的列的物理 ID--output-all- 显示所有可用的列--help- 显示当前帮助--version- 显示版本
DEVICE- 要查看的设备列表,默认为查看所有设备
#列名
#-e 和 -p 选项可用的列名
| 列名 | 说明 |
|---|---|
| BOGOMIPS | CPU 速度的粗略策略 |
| CPU | 逻辑 CPU 编号 |
| CORE | 逻辑核心编号 |
| SOCKET | 逻辑插槽编号 |
| CLUSTER | 逻辑簇编号 |
| NODE | 逻辑非一致性内存访问(NUMA)编号 |
| BOOK | 逻辑书本(包含多个 NUMA)编号 |
| DRAWER | 逻辑抽屉(包含多个 Book)编号 |
| CACHE | CPU 之间如何共享缓存 |
| POLARIZATION | 虚拟硬件上的 CPU 调度模式 |
| ADDRESS | CPU 的物理地址 |
| CONFIGURED | 虚拟机管理程序(Hypervisor)是否已经分配 CPU |
| ONLINE | Linux 当前是否使用 CPU |
| MHZ | CPU 当前频率(MHz) |
| SCALMHZ% | CPU 频率缩放百分比 |
| MAXMHZ | CPU 最高频率(MHz) |
| MINMHZ | CPU 最低频率(MHz) |
| MODELNAME | CPU 型号名称 |
#-C 选项可用的列名
| 列名 | 说明 |
|---|---|
| ALL-SIZE | 所有系统缓存的大小 |
| LEVEL | 缓存级别 |
| NAME | 缓存名称 |
| ONE-SIZE | 一个缓存的大小 |
| TYPE | 缓存类型 |
| WAYS | 缓存的关联 |
| ALLOC-POLICY | 缓存的分配策略 |
| WRITE-POLICY | 缓存的写策略 |
| PHY-LINE | 每个缓存标配对应的对应的物理缓存行数 |
| SETS | 缓存中集合的数量 |
| COHERENCY-SIZE | 从内存传输到缓存的最小数据量 |
#示例
$ lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Address sizes: 43 bits physical, 48 bits virtual
Byte Order: Little Endian
CPU(s): 8
On-line CPU(s) list: 0-7
Vendor ID: AuthenticAMD
Model name: AMD Ryzen 5 3400G with Radeon Vega Graphics
CPU family: 23
Model: 24
Thread(s) per core: 2
Core(s) per socket: 4
Socket(s): 1
Stepping: 1
Frequency boost: enabled
CPU(s) scaling MHz: 36%
CPU max MHz: 3700.0000
CPU min MHz: 1400.0000
BogoMIPS: 7385.99
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid a
perfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw skinit wdt tce t
opoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb hw_pstate ssbd ibpb vmmcall fsgsbase bmi1 avx2 smep bmi2 rdseed adx smap clflushopt sha_ni xsaveopt xsavec xgetbv1 clzero irperf xsaveerptr arat
npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif overflow_recov succor smca sev sev_es ibpb_exit_to_user
Virtualization features:
Virtualization: AMD-V
Caches (sum of all):
L1d: 128 KiB (4 instances)
L1i: 256 KiB (4 instances)
L2: 2 MiB (4 instances)
L3: 4 MiB (1 instance)
NUMA:
NUMA node(s): 1
NUMA node0 CPU(s): 0-7
Vulnerabilities:
Gather data sampling: Not affected
Itlb multihit: Not affected
L1tf: Not affected
Mds: Not affected
Meltdown: Not affected
Mmio stale data: Not affected
Reg file data sampling: Not affected
Retbleed: Mitigation; untrained return thunk; SMT vulnerable
Spec rstack overflow: Mitigation; Safe RET
Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Spectre v2: Mitigation; Retpolines; IBPB conditional; STIBP disabled; RSB filling; PBRSB-eIBRS Not affected; BHI Not affected
Srbds: Not affected
Tsx async abort: Not affected
#推荐阅读
#手册
LSCPU(1) User Commands LSCPU(1)
NAME
lscpu - display information about the CPU architecture
SYNOPSIS
lscpu [options]
DESCRIPTION
lscpu gathers CPU architecture information from sysfs, /proc/cpuinfo
and any applicable architecture-specific libraries (e.g. librtas on
Powerpc). The command output can be optimized for parsing or for easy
readability by humans. The information includes, for example, the
number of CPUs, threads, cores, sockets, and Non-Uniform Memory Access
(NUMA) nodes. There is also information about the CPU caches and cache
sharing, family, model, bogoMIPS, byte order, and stepping.
The default output formatting on terminal is subject to change and
maybe optimized for better readability. The output for non-terminals
(e.g., pipes) is never affected by this optimization and it is always
in "Field: data\n" format. Use for example "lscpu | less" to see the
default output without optimizations.
In virtualized environments, the CPU architecture information displayed
reflects the configuration of the guest operating system which is
typically different from the physical (host) system. On architectures
that support retrieving physical topology information, lscpu also
displays the number of physical sockets, chips, cores in the host
system.
Options that result in an output table have a list argument. Use this
argument to customize the command output. Specify a comma-separated
list of column labels to limit the output table to only the specified
columns, arranged in the specified order. See COLUMNS for a list of
valid column labels. The column labels are not case sensitive.
Not all columns are supported on all architectures. If an unsupported
column is specified, lscpu prints the column but does not provide any
data for it.
The cache sizes are reported as summary from all CPUs. The versions
before v2.34 reported per-core sizes, but this output was confusing due
to complicated CPUs topology and the way how caches are shared between
CPUs. For more details about caches see --cache. Since version v2.37
lscpu follows cache IDs as provided by Linux kernel and it does not
always start from zero.
OPTIONS
-a, --all
Include lines for online and offline CPUs in the output (default
for -e). This option may only be specified together with option -e
or -p.
-B, --bytes
Print the sizes in bytes rather than in a human-readable format.
By default, the unit, sizes are expressed in, is byte, and unit
prefixes are in power of 2^10 (1024). Abbreviations of symbols are
exhibited truncated in order to reach a better readability, by
exhibiting alone the first letter of them; examples: "1 KiB" and "1
MiB" are respectively exhibited as "1 K" and "1 M", then omitting
on purpose the mention "iB", which is part of these abbreviations.
-b, --online
Limit the output to online CPUs (default for -p). This option may
only be specified together with option -e or -p.
-C, --caches[=list]
Display details about CPU caches. For details about available
information see --help output.
If the list argument is omitted, all columns for which data is
available are included in the command output.
When specifying the list argument, the string of option, equal sign
(=), and list must not contain any blanks or other whitespace.
Examples: -C=NAME,ONE-SIZE or --caches=NAME,ONE-SIZE.
The default list of columns may be extended if list is specified in
the format +list (e.g., lscpu -C=+ALLOC-POLICY).
-c, --offline
Limit the output to offline CPUs. This option may only be specified
together with option -e or -p.
--hierarchic[=when]
Use subsections in summary output. For backward compatibility, the
default is to use subsections only when output on a terminal and
flattened output on a non-terminal. The optional argument when can
be never, always or auto. If the when argument is omitted, it
defaults to "always".
-e, --extended[=list]
Display the CPU information in human-readable format.
If the list argument is omitted, the default columns are included
in the command output. The default output is subject to change.
When specifying the list argument, the string of option, equal sign
(=), and list must not contain any blanks or other whitespace.
Examples: '-e=cpu,node' or '--extended=cpu,node'.
The default list of columns may be extended if list is specified in
the format +list (e.g., lscpu -e=+MHZ).
-J, --json
Use JSON output format for the default summary or extended output
(see --extended). For backward compatibility, JSON output follows
the default summary behavior for non-terminals (e.g., pipes) where
subsections are missing. See also --hierarchic.
-p, --parse[=list]
Optimize the command output for easy parsing.
If the list argument is omitted, the command output is compatible
with earlier versions of lscpu. In this compatible format, two
commas are used to separate CPU cache columns. If no CPU caches are
identified the cache column is omitted. If the list argument is
used, cache columns are separated with a colon (:).
When specifying the list argument, the string of option, equal sign
(=), and list must not contain any blanks or other whitespace.
Examples: '-p=cpu,node' or '--parse=cpu,node'.
The default list of columns may be extended if list is specified in
the format +list (e.g., lscpu -p=+MHZ).
-s, --sysroot directory
Gather CPU data for a Linux instance other than the instance from
which the lscpu command is issued. The specified directory is the
system root of the Linux instance to be inspected.
-x, --hex
Use hexadecimal masks for CPU sets (for example "ff"). The default
is to print the sets in list format (for example 0,1). Note that
before version 2.30 the mask has been printed with 0x prefix.
-y, --physical
Display physical IDs for all columns with topology elements (core,
socket, etc.). Other than logical IDs, which are assigned by lscpu,
physical IDs are platform-specific values that are provided by the
kernel. Physical IDs are not necessarily unique and they might not
be arranged sequentially. If the kernel could not retrieve a
physical ID for an element lscpu prints the dash (-) character.
The CPU logical numbers are not affected by this option.
--output-all
Output all available columns. This option must be combined with
either --extended, --parse or --caches.
BUGS
The basic overview of CPU family, model, etc. is always based on the
first CPU only.
Sometimes in Xen Dom0 the kernel reports wrong data.
On virtual hardware the number of cores per socket, etc. can be wrong.
AUTHORS
Cai Qian <qcai@redhat.com>, Karel Zak <kzak@redhat.com>, Heiko Carstens
<heiko.carstens@de.ibm.com>
SEE ALSO
chcpu(8)
REPORTING BUGS
For bug reports, use the issue tracker at
https://github.com/util-linux/util-linux/issues.
AVAILABILITY
The lscpu command is part of the util-linux package which can be
downloaded from Linux Kernel Archive
<https://www.kernel.org/pub/linux/utils/util-linux/>.
util-linux 2.39.3 2023-11-21 LSCPU(1)