基本概念html
如何知道Linux系统有多少核心和处理器node
1.使用nproc命令api
使用nproc命令能够查看所拥有的CPU逻辑核总数。此种方法为最简单和最短的方法,由于它是coreutils 的一部分而被普遍扩展:缓存
~$ nproc --all 48
2.使用lscpu命令服务器
lscpu从sysfs和/proc/cpuinfo中收集cpu体系结构信息,命令的输出比较易读 。该命令显示的信息包括,插槽数、CPU数量、线程数 (thread)、物理核心数(core),还有 Non-Uniform Memory Access (NUMA) 节点数、缓存等。架构
命令输出结果中,存在以下计算公式: CPU(s)=socket*Core*Threadsocket
以下为四路24核48线程示例,其中CPU为AMD Opteron 6234 ,标准主频为2.4GHZ。CPU插槽个数为4;单个CPU物理核数为6;单个CPU逻辑核心数为12。ide
~$ lscpu Architecture: x86_64 #架构,这里指64位处理器 CPU op-mode(s): 32-bit, 64-bit #运行方式 Byte Order: Little Endian #字节顺序,这里指小端法 CPU(s): 48 #服务器上CPU的逻辑核总数 On-line CPU(s) list: 0-47 #服务器上在线的CPU逻辑核总数(有时由于CPU过热可能会暂停某些CPU) Thread(s) per core: 2 #每一个物理核超线程数(大于1则为超线程) Core(s) per socket: 6 #每一个插槽的物理核数(每颗CPU物理核数) Socket(s): 4 #服务器上CPU插槽数 (通常为CPU总数) NUMA node(s): 8 #非统一内存访问节点 Vendor ID: AuthenticAMD #cpu厂商ID CPU family: 21 #CPU系列 Model: 1 #CPU型号编号 Model name: AMD Opteron 6234 @ 2.40GHz #CPU型号名称 Stepping: 2 #步进 CPU MHz: 2400.66 #cpu主频 BogoMIPS: 4799.42 Hypervisor vendor: AMD-V #虚拟化架构 Virtualization type: full #cpu支持的虚拟化技术 L1d cache: 16K #一级缓存,dcahce用于缓存数据 L1i cache: 64K #一级缓存,icahce用于缓存指令 L2 cache: 2408K #二级缓存 L3 cache: 6144K #三级缓存,缓存速度上 L1 > L2 > L3 > DDR(内存,理论速度几十g每秒)
NUMA node0 CPU(s): 0,4,8,12,16,20 #逻辑CPU和NUMA节点映射
NUMA node1 CPU(s): 24,18,32,36,40,44
NUMA node2 CPU(s): 1,5,9,13,17,21
NUMA node3 CPU(s): 25,29,33,37,41,45
NUMA node4 CPU(s): 2,6,10,14,18,22
NUMA node5 CPU(s): 26,30,34,38,42,46
NUMA node6 CPU(s): 27,31,35,39,43,47
NUMA node7 CPU(s): 3,7,11,15,19,23
以下为单路12核24线程示例,以下为至强处理器E5系列CPU,型号为Xeon E5-2680 v3 ,标准主频为2.5GHZ。CPU插槽个数为1;单个CPU物理核数为12,单个CPU逻辑核心数为24。工具
~$ lscpu Architecture: x86_64 #架构,这里指64位处理器 CPU op-mode(s): 32-bit, 64-bit #运行方式 Byte Order: Little Endian #字节顺序,这里指小端法 CPU(s): 24 #服务器上CPU的逻辑核总数 On-line CPU(s) list: 0-23 #服务器上在线的CPU逻辑核总数(有时由于CPU过热可能会暂停某些CPU) Thread(s) per core: 2 #每一个物理核超线程数(大于1则为超线程) Core(s) per socket: 12 #每一个插槽的物理核数(每颗CPU物理核数) Socket(s): 1 #服务器上CPU插槽数 (CPU总数) NUMA node(s): 1 #非统一内存访问节点 Vendor ID: GenuineIntel #cpu厂商ID CPU family: 6 #CPU系列 Model: 63 #CPU型号编号 Model name: Intel(R) Xeon(R) CPU E5-2680 v3 @ 2.50GHz #CPU型号名称 Stepping: 2 #步进 CPU MHz: 2494.222 #cpu主频 BogoMIPS: 4988.44 Hypervisor vendor: KVM #虚拟化架构 Virtualization type: full #cpu支持的虚拟化技术 L1d cache: 32K #一级缓存,dcahce用于缓存数据 L1i cache: 32K #一级缓存,icahce用于缓存指令 L2 cache: 256K #二级缓存 L3 cache: 30720K #三级缓存,缓存速度上 L1 > L2 > L3 > DDR(内存,理论速度几十g每秒) NUMA node0 CPU(s): 0,......(省略)
3.查看/proc/cpuinfo文件ui
在Linux系统中,提供了proc文件系统显示系统的软硬件信息。若是想了解系统中CPU的提供商和相关配置信息,则能够经过/proc/cpuinfo文件获得。
基于不一样指令集的CPU产生的/proc/cpuinfo文件不同,基于X86指令集CPU的/proc/cpuinfo文件包含关键内容以下:
以以下双路16核32线程为例,其中CPU为Intel(R) Xeon(R) E5-2697 v3,标准主频2.6GHz。CPU个数为2;单个CPU物理核数为8;单个CPU逻辑核数为16;支持超频且已开启。
查看当前系统逻辑核总数 ~$ cat /proc/cpuinfo| grep -i "processor"| wc -l 32 查看当前系统CPU数量(必须先sort后uniq) ~$ cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l 2 查看单个CPU的物理核数量 ~$ cat /proc/cpuinfo| grep "cpu cores"| uniq cpu cores : 8 查看单个CPU的逻辑核数量(线程数) cat /proc/cpuinfo | grep -i "siblings"| uniq siblings : 16 查看是否支持超线程(显示ht则表示支持超线程) cat /proc/cpuinfo | grep -i "flag" |grep -wo "ht"|uniq ht 查看是否开启超线程(cpu cores和siblings一致表示没有超线程) cat /proc/cpuinfo | grep -e "cpu cores" -e "siblings" | sort | uniq cpu cores :8 siblings :16 查看CPU型号 cat /proc/cpuinfo|grep -i "model name"| uniq Intel(R) Xeon(R) CPU E5-2697 v3 @ 2.60GHz
以下为双路8核8线程系统示例,其中CPU为Intel(R) Xeon(R) X5355,标准主频2.66GHz。CPU个数为2;单个CPU物理核数为4;单个CPU逻辑核数为4;支持超频但未开启。
processor : 0 #系统中逻辑核的惟一标识。 vendor_id : GenuineIntel #CPU制造商 cpu famil : 6 #CPU产品系列代号 model : 15 #CPU属于其系列中的哪一代的代号 model name : Intel(R) Xeon(R) CPU X5355 @ 2.66GHz #当前逻辑核所属CPU型号和标准主频。 stepping : 7 #CPU属于制做更新版本 cpu MHz : 2666.766 #CPU的实际使用主频 cache size : 4096 KB #CPU二级缓存大小 physical id : 0 #当前逻辑核所属CPU惟一标识。系统中一个CPU对应惟一一个physical id。 siblings : 4 #当前逻辑核所属CPU的逻辑核数量 core id : 0 #当前逻辑核所属的物理核在CPU中的标识ID。同一个CPU的同一个物理核模拟的逻辑核core id相同。 cpu cores : 4 #当前逻辑核所属CPU的物理核数量 fpu : yes #是否具备浮点运算单元(Floating Point Unit) fpu_exception: yes #是否支持浮点计算异常 cpuid level : 10 #执行cpuid指令前,eax寄存器中的值,根据不一样的值cpuid指令会返回不一样的内容 wp : yes #代表当前CPU是否在内核态支持对用户空间的写保护(Write Protection) flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall lm constant_tsc pni monitor ds_cpl vmx est tm2 cx16 xtpr dca lahf_lm #当前CPU支持的功能(若是含有ht表示支持超频) bogomips : 5338.26 #在系统内核启动时粗略测算的CPU速度(Million Instructions Per Second) clflush size : 64 #每次刷新缓存的大小单位 cache_alignment : 64 #缓存地址对齐单位 address sizes : 36 bits physical, 48 bits virtual #可访问地址空间位数 power management: #对能源管理的支持
processor : 1
...(省略)
参考:/proc/cpuinfo 文件分析(查看CPU信息)
4.使用dmidecode工具
dmidecode 用于获取主机的硬件信息,一般是在不打开计算机机箱的状况下使用该命令来查找硬件详细信息,可是咱们须要root权限。关键信息以下:
以下为双路16核32线程系统示例,其中CPU为Intel(R) Xeon(R) E5-2620 v4,标准主频2.10GHz。CPU个数为2;单个CPU物理核数为8;单个CPU逻辑核数为16;支持超频且已经开启。
[root@localhost ~]$ dmidecode -t 4 # dmidecode 2.12-dmifs SMBIOS 3.0 present. # SMBIOS implementations newer than version 2.8 are not # fully supported by this version of dmidecode. Handle 0x006C, DMI type 4, 48 bytes Processor Information Socket Designation: SOCKET 0 Flags: FPU (Floating-point unit on-chip) ...(省略) HTT (Multi-threading) TM (Thermal monitor supported) PBE (Pending break enabled) Version: Intel(R) Xeon(R) CPU E5-2620 v4 @ 2.10GHz Current Speed: 2100 MHz Core Count: 8 Core Enabled: 8 Thread Count: 16 Handle 0x0070, DMI type 4, 48 bytes Processor Information Socket Designation: SOCKET 1 Flags: FPU (Floating-point unit on-chip) ...(省略) HTT (Multi-threading) TM (Thermal monitor supported) PBE (Pending break enabled) Version: Intel(R) Xeon(R) CPU E5-2620 v4 @ 2.10GHz Current Speed: 2100 MHz Core Count: 8 Core Enabled: 8 Thread Count: 16