如何查找物理cpu,cpu核心和逻辑cpu的数量
环境
- Red Hat Enterprise Linux 4
- Red Hat Enterprise Linux 5
- Red Hat Enterprise Linux 6
- Red Hat Enterprise Linux 7
问题
- x86 / x86_64系统上的物理CPU,CPU内核和逻辑CPU之间有什么区别?
- 如何从RHEL操作系统获取可用处理器列表?
决议
物理CPU数量
下面的命令将显示一个系统有多少活动的物理处理器。例如:如果这个数字是2,则可以打开系统机箱,用手删除2个物理处理器。
$ grep physical.id /proc/cpuinfo | sort -u | wc -l
2
每个CPU的核心数
在具有多核处理器的系统上,下面的命令应该报告每个物理处理器的CPU内核数量(尽管在极少数情况下可能不会)。例如:如果这个数字是4,而物理CPU是2,那么这2个物理处理器中的每个都有4个CPU内核,总共有8个内核。
$ grep cpu.cores /proc/cpuinfo | sort -u
cpu cores : 4
逻辑处理器数量
最后这个命令将显示Linux内核所看到的“逻辑”处理器的总数。这个数字通常是三个统计数据中最重要的。它是处理器的有效数量——就操作系统而言,这是能够在任何给定微秒内工作的不同cpu的数量。示例:继续上面的示例场景,下面看到的数字可以是16而不是8。简单地说,如果这个命令显示的数字与CPU内核的总数不同,这是因为在CPU上启用了超线程,从而进一步划分了每个内核(在本例中,分为两个可用的“线程”)。
$ grep processor /proc/cpuinfo | wc -l
16
许可?
为了确定RHEL许可原因的cpu数量,上面的第一个命令就足够了;但是,要进行更多的讨论,请咨询 如何确定系统上的CPU插槽数
如果购买的许可根据插槽(已填充或未填充),处理器或内核的数量而变化的第三方软件,请与软件供应商联系,以确切了解它们如何计算CPU数量。
工具
注意,Red Hat Enterprise Linux 6和7附带了lscpu命令,该命令可以打印出系统处理器的简单可读摘要。此外,在RHEL6中,hwloc包是可用的(RHEL7附带它)——hwloc包括lstopo命令,以及各种hwloc-*命令。
在RHEL6之前,直接检查/proc/cpuinfo(如上所述)或使用x86info或dmidecode命令(同名rpm)都能查到相同的信息。
其他第三方选项没有提供担保:xsos(由本文的原始作者开发)和lshw(可在EPEL中获得)。
- 对于任何版本的Red Hat Enterprise Linux:本文附带的BASH脚本都会解析/proc/cpuinfo,以打印如下所示的易于阅读的摘要。(注意,它没有提供任何保证或官方支持。)
$ cpu
128 logical processors (64 CPU cores)
8 Intel Xeon CPU X7560 @ 2.27GHz (flags: constant_tsc,ht,lm,pae,vmx)
└─16 threads / 8 cores each1 #!/bin/bash
2 #
3 # This simple script uses /proc/cpuinfo (or filename of your choosing) to print
4 # a succinct summary about a system's processors.
5 # Other useful utilities (some only available in RHEL6 or EPEL):
6 # x86info, dmidecode, lscpu, cpuid, lshw, lstopo, xsos
7 #
8 # Originally uploaded to redhat.com by Ryan Sawhill <rsaw@redhat.com>, Sep 2012; Updated Jan 2013
9 # This code is from xsos, which can do so much more <http://github.com/ryran/xsos>
10 #
11
12 # Get input
13 if [[ -r $1 && -f $1 ]]; then
14 # If passed a readable file, use that
15 cpuinfo=$1
16 else
17 # Otherwise, use /proc/cpuinfo
18 cpuinfo=/proc/cpuinfo
19 fi
20
21 # Get model of cpu
22 model_cpu=$(awk -F: '/^model name/{print $2; exit}' <"$cpuinfo")
23
24 # If no model detected (e.g. on Itanium), try to use vendor+family
25 [[ -z $model_cpu ]] && {
26 vendor=$(awk -F: '/^vendor /{print $2; exit}' <"$cpuinfo")
27 family=$(awk -F: '/^family /{print $2; exit}' <"$cpuinfo")
28 model_cpu="$vendor$family"
29 }
30
31 # Clean up cpu model string
32 model_cpu=$(sed -e 's,(R),,g' -e 's,(TM),,g' -e 's, *, ,g' -e 's,^ ,,' <<<"$model_cpu")
33
34 # Get number of logical processors
35 num_cpu=$(awk '/^processor/{n++} END{print n}' <"$cpuinfo")
36
37 # Get number of physical processors
38 num_cpu_phys=$(grep '^physical id' <"$cpuinfo" | sort -u | wc -l)
39
40 # If "physical id" not found, we cannot make any assumptions (Virtualization--)
41 # But still, multiplying by 0 in some crazy corner case is bad, so set it to 1
42 # If num of physical *was* detected, add it to the beginning of the model string
43 [[ $num_cpu_phys == 0 ]] && num_cpu_phys=1 || model_cpu="$num_cpu_phys $model_cpu"
44
45 # If number of logical != number of physical, try to get info on cores & threads
46 if [[ $num_cpu != $num_cpu_phys ]]; then
47
48 # Detect number of threads (logical) per cpu
49 num_threads_per_cpu=$(awk '/^siblings/{print $3; exit}' <"$cpuinfo")
50
51 # Two possibile ways to detect number of cores
52 cpu_cores=$(awk '/^cpu cores/{print $4; exit}' <"$cpuinfo")
53 core_id=$(grep '^core id' <"$cpuinfo" | sort -u | wc -l)
54
55 # The first is the most accurate, if it works
56 if [[ -n $cpu_cores ]]; then
57 num_cores_per_cpu=$cpu_cores
58
59 # If "cpu cores" doesn't work, "core id" method might (e.g. Itanium)
60 elif [[ $core_id -gt 0 ]]; then
61 num_cores_per_cpu=$core_id
62 fi
63
64 # If found info on cores, setup core variables for printing
65 if [[ -n $num_cores_per_cpu ]]; then
66 cores1="($((num_cpu_phys*num_cores_per_cpu)) CPU cores)"
67 cores2=" / $num_cores_per_cpu cores"
68 # If didn't find info on cores, assume single-core cpu(s)
69 else
70 cores2=" / 1 core"
71 fi
72
73 # If found siblings (threads), setup the variable for the final line
74 [[ -n $num_threads_per_cpu ]] &&
75 coresNthreads="\n└─$num_threads_per_cpu threads${cores2} each"
76 fi
77
78 # Check important cpu flags
79 # pae=physical address extensions * lm=64-bit * vmx=Intel hw-virt * svm=AMD hw-virt
80 # ht=hyper-threading * aes=AES-NI * constant_tsc=Constant Time Stamp Counter
81 cpu_flags=$(egrep -o "pae|lm|vmx|svm|ht|aes|constant_tsc" <"$cpuinfo" | sort -u | sed ':a;N;$!ba;s/\n/,/g')
82 [[ -n $cpu_flags ]] && cpu_flags="(flags: $cpu_flags)"
83
84 # Check kernel version; print warning if Xen
85 [[ $(uname -r) =~ xen ]] && {
86 echo "Warning: kernel for localhost detected as $(uname -r)"
87 echo "With Xen, CPU layout in /proc/cpuinfo will be inaccurate; consult dmidecode"
88 }
89
90 # Print out the deets
91 echo -e "${num_cpu} logical processors ${cores1}"
92 echo -e "${model_cpu} ${cpu_flags} ${coresNthreads}"cpu.sh
如何查找物理cpu,cpu核心和逻辑cpu的数量的更多相关文章
- linux下查看cpu物理个数、核数、逻辑cpu数
一.首先要明确物理cpu个数.核数.逻辑cpu数的概念 1.物理cpu数:主板上实际插入的cpu数量,可以数不重复的 physical id 有几个(physical id) 2.cpu核数:单块CP ...
- linux查询操作系统信息,CPU物理个数,CPU核心数,逻辑CPU数,内存信息查询,硬盘信息查询
目录 一.前言 二.关于服务器基本配置 2.1 操作系统基本配置查询 2.2 CPU基本配置查询 2.3 内存基本配置查询 2.4 硬盘基本配置查询 一.前言 当我们接手了一台或者几台服务器的时候 ...
- CPU | 物理 CPU vs 逻辑 CPU vs 核心 vs 线程 vs Socket
当我们试着通过 Linux 命令 nproc 和 lscpu 了解一台计算机 CPU 级的架构和性能时,我们总会发现无法正确地理解相应的结果,因为我们会被好几个术语搞混淆:物理 CPU.逻辑 CPU. ...
- Linux下区分物理CPU、逻辑CPU和CPU核数
㈠ 概念 ① 物理CPU 实际Server中插槽上的CPU个数 物理cpu数量,可以数不重复的 p ...
- 物理CPU 逻辑CPU 核数
一.概念 ① 物理CPU 实际Server中插槽上的CPU个数 物理cpu数量,可以数不重复的 physical id 有几个 ② 逻辑CPU ③ CPU核数 一块CPU上面能处理数据的芯片组的数量 ...
- 转://Linux下区分物理CPU、逻辑CPU和CPU核数
㈠ 概念 ① 物理CPU 实际Server中插槽上的CPU个数 物理cpu数量,可以数不重复的 p ...
- linux下查看物理CPU个数、核数、逻辑CPU个数
cat /proc/cpuinfo中的信息 processor 逻辑处理器的id.physical id 物理封装的处理器的id.core id 每个核心的id.cpu cores 位于相同物理封装的 ...
- linux判断物理CPU,逻辑CPU和CPU核数
① 物理CPU 实际Server中插槽上的CPU个数 物理cpu数量,可以数不重复的 physical id 有几个 ② 逻辑CPU Linux用户对 /proc/cpuinfo 这个文件肯定不陌生. ...
- Linux查看物理CPU个数、核数、逻辑CPU个数
# 总核数 = 物理CPU个数 X 每颗物理CPU的核数 # 总逻辑CPU数 = 物理CPU个数 X 每颗物理CPU的核数 X 超线程数 # 查看物理CPU个数 cat /proc/cpuinfo| ...
随机推荐
- PHP导入导出csv文件 Summer-CSV
2017年11月9日09:25:56 根据项目实践总结的一个类文件, mac/win下没乱码 简体中文 默认从gb2312转到utf-8 https://gitee.com/myDcool/PHP-C ...
- char、nchar、varchar、nvarchar 的区别
char.varchar.nchar.nvarchar为数据库中常用的字符类型,使用上要综合考虑空间利用率与存取速度.它们的区别如下: 实例解析: 定义char[9].varchar[9].nchar ...
- 【原创】大数据基础之Flume(2)Sink代码解析
flume sink核心类结构 1 核心接口Sink org.apache.flume.Sink /** * <p>Requests the sink to attempt to cons ...
- java按照关键字指定的key删除redis(支持模糊删除)
pom依赖: <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</a ...
- ifconfig和ping
命令: ifconfig 对应英文: configure a network interface 作用: 查看 / 配置计算机当前的网卡配置信息 安装: sudo apt install net-to ...
- 腾讯云CVM之间配置免密钥登录
背景: 1客户A和B俩台主机之间需要实现免密钥登录,已绑定腾讯云申请的密钥对 系统:centos7.3 A:192.168.0.100 B:192.168.0.84 A主机的私钥文件:aaa B主机的 ...
- 【进阶2-3期】JavaScript深入之闭包面试题解
这是我在公众号(高级前端进阶)看到的文章,现在做笔记 https://github.com/yygmind/blog/issues/19 作用域指的是一个变量和函数的作用范围,JS中函数内声明的所有变 ...
- restful中的分页
普通分页 普通分页类似于Django中的分页 源码 class PageNumberPagination(BasePagination): """ A simple pa ...
- java-pdf转word
注:原文来至 < java-pdf转word > 一: java Pdf 文字 转 Word 废话不说,直接上图 很简单的用法:1.new个PDFBox对象2.调用pdfToDoc() ...
- Android 基础 二 四大组件 Activity
Activity Intent IntentFilter 一理论概述 一. Activity 用来提供一个能让用户操作并与之交互的界面. 1.1 启动 startActivity(Intent int ...