Ubuntu 服务器查询 CPU 核心数的方法
以下是常用的几种方法来查看 Ubuntu 服务器的 CPU 核心信息:
方法一:使用 lscpu(推荐)
命令:
lscpu
说明:
- `CPU(s)`:逻辑核心数量(含超线程)
- `Core(s) per socket`:每个物理 CPU 的核心数
- `Socket(s)`:物理 CPU 数量
# lscpu
Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Address sizes: 45 bits physical, 48 bits virtual Byte Order: Little Endian
CPU(s): 4 On-line CPU(s) list: 0-3
Vendor ID: GenuineIntel Model name: Intel(R) Xeon(R) Platinum 8260 CPU @ 2.40GHz CPU family: 6 Model: 85 Thread(s) per core: 1 Core(s) per socket: 1 Socket(s): 4 Stepping: 7 BogoMIPS: 4788.74 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc cpuid tsc_known_freq pni pclmu lqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid avx512f avx512dq rdseed adx smap clflushopt clwb avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves arat pku ospke avx512_vnni md_clear flush_l1d arch_capabilities
Virtualization features: Hypervisor vendor: VMware Virtualization type: full
Caches (sum of all): L1d: 128 KiB (4 instances) L1i: 128 KiB (4 instances) L2: 4 MiB (4 instances) L3: 143 MiB (4 instances)
NUMA: NUMA node(s): 1 NUMA node0 CPU(s): 0-3
Vulnerabilities: Gather data sampling: Unknown: Dependent on hypervisor status Itlb multihit: KVM: Mitigation: VMX unsupported L1tf: Not affected Mds: Not affected Meltdown: Not affected Mmio stale data: Vulnerable: Clear CPU buffers attempted, no microcode; SMT Host state unknown Reg file data sampling: Not affected Retbleed: Mitigation; Enhanced IBRS Spec rstack overflow: Not affected Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization Spectre v2: Mitigation; Enhanced / Automatic IBRS; IBPB conditional; RSB filling; PBRSB-eIBRS SW sequence; BHI SW loop, KVM SW loop Srbds: Not affected Tsx async abort: Not affected
|
1. 基本信息
总逻辑核心数
|
4
|
总物理核心数
|
4(1 核 x 4 socket)
|
每个核心线程数
|
1(未启用超线程)
|
虚拟环境
|
VMware 全虚拟化
|
CPU 型号
|
Intel(R) Xeon(R) Platinum 8260 CPU @ 2.40GHz
|
2. 详细说明
从 lscpu 输出可以看出,该服务器被分配了 4 个逻辑核心(vCPU)。
每个 Socket 对应一个核心,总共 4 个 Socket,因此系统视角上有 4 个物理核心。
超线程未启用(每个核心仅支持一个线程)。
当前运行在 VMware 虚拟化环境中,具体物理 CPU 型号为 Intel Xeon Platinum 8260。
方法二:使用 nproc
命令:
nproc
说明:
- 直接输出当前系统中可用的逻辑核心数。
方法三:查看 /proc/cpuinfo
命令:
grep -c ^processor /proc/cpuinfo
说明:
- 统计“processor”行数,每一行代表一个逻辑核心。
命令(查看每个 Socket 的核心数):
lscpu | grep 'Core(s) per socket'
# grep -c ^processor /proc/cpuinfo
4
|
方法四:结合 lscpu 输出分析物理拓扑结构
命令:
lscpu
说明:
- 可用于分析是否启用超线程、物理核心数量、虚拟化环境、缓存等详细信息。
~# lscpu
Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Address sizes: 45 bits physical, 48 bits virtual Byte Order: Little Endian
CPU(s): 4 On-line CPU(s) list: 0-3
Vendor ID: GenuineIntel Model name: Intel(R) Xeon(R) Platinum 8260 CPU @ 2.40GHz CPU family: 6 Model: 85 Thread(s) per core: 1 Core(s) per socket: 1 Socket(s): 4 Stepping: 7 BogoMIPS: 4788.74 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc cpuid tsc_known_freq pni pclmu lqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid avx512f avx512dq rdseed adx smap clflushopt clwb avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves arat pku ospke avx512_vnni md_clear flush_l1d arch_capabilities
Virtualization features: Hypervisor vendor: VMware Virtualization type: full
Caches (sum of all): L1d: 128 KiB (4 instances) L1i: 128 KiB (4 instances) L2: 4 MiB (4 instances) L3: 143 MiB (4 instances)
NUMA: NUMA node(s): 1 NUMA node0 CPU(s): 0-3
Vulnerabilities: Gather data sampling: Unknown: Dependent on hypervisor status Itlb multihit: KVM: Mitigation: VMX unsupported L1tf: Not affected Mds: Not affected Meltdown: Not affected Mmio stale data: Vulnerable: Clear CPU buffers attempted, no microcode; SMT Host state unknown Reg file data sampling: Not affected Retbleed: Mitigation; Enhanced IBRS Spec rstack overflow: Not affected Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization Spectre v2: Mitigation; Enhanced / Automatic IBRS; IBPB conditional; RSB filling; PBRSB-eIBRS SW sequence; BHI SW loop, KVM SW loop Srbds: Not affected Tsx async abort: Not affected
|