环境

  • 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 each
     1 #!/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的数量的更多相关文章

  1. linux下查看cpu物理个数、核数、逻辑cpu数

    一.首先要明确物理cpu个数.核数.逻辑cpu数的概念 1.物理cpu数:主板上实际插入的cpu数量,可以数不重复的 physical id 有几个(physical id) 2.cpu核数:单块CP ...

  2. linux查询操作系统信息,CPU物理个数,CPU核心数,逻辑CPU数,内存信息查询,硬盘信息查询

    目录 一.前言 二.关于服务器基本配置 2.1 操作系统基本配置查询 2.2 CPU基本配置查询 2.3 内存基本配置查询 2.4 硬盘基本配置查询 一.前言 ​ 当我们接手了一台或者几台服务器的时候 ...

  3. CPU | 物理 CPU vs 逻辑 CPU vs 核心 vs 线程 vs Socket

    当我们试着通过 Linux 命令 nproc 和 lscpu 了解一台计算机 CPU 级的架构和性能时,我们总会发现无法正确地理解相应的结果,因为我们会被好几个术语搞混淆:物理 CPU.逻辑 CPU. ...

  4. Linux下区分物理CPU、逻辑CPU和CPU核数

    ㈠ 概念           ① 物理CPU                             实际Server中插槽上的CPU个数              物理cpu数量,可以数不重复的 p ...

  5. 物理CPU 逻辑CPU 核数

    一.概念 ① 物理CPU 实际Server中插槽上的CPU个数 物理cpu数量,可以数不重复的 physical id 有几个 ② 逻辑CPU ③ CPU核数  一块CPU上面能处理数据的芯片组的数量 ...

  6. 转://Linux下区分物理CPU、逻辑CPU和CPU核数

    ㈠ 概念           ① 物理CPU                             实际Server中插槽上的CPU个数              物理cpu数量,可以数不重复的 p ...

  7. linux下查看物理CPU个数、核数、逻辑CPU个数

    cat /proc/cpuinfo中的信息 processor 逻辑处理器的id.physical id 物理封装的处理器的id.core id 每个核心的id.cpu cores 位于相同物理封装的 ...

  8. linux判断物理CPU,逻辑CPU和CPU核数

    ① 物理CPU 实际Server中插槽上的CPU个数 物理cpu数量,可以数不重复的 physical id 有几个 ② 逻辑CPU Linux用户对 /proc/cpuinfo 这个文件肯定不陌生. ...

  9. Linux查看物理CPU个数、核数、逻辑CPU个数

    # 总核数 = 物理CPU个数 X 每颗物理CPU的核数 # 总逻辑CPU数 = 物理CPU个数 X 每颗物理CPU的核数 X 超线程数 # 查看物理CPU个数 cat /proc/cpuinfo| ...

随机推荐

  1. 004_strace工具

    strace - trace system calls and signals 一.strace工具详解 之前线上主机上8351 进程夯死导致无法获悉进程信息,监控程序使用ps 命令查看进程信息至/p ...

  2. 通过python统计nginx日志定位php网站响应慢的问题

    # 公司网站反映很慢,可能是一些页面的访问方法或者页面引起,通过程序统计nginx访问日志的页面和具体的action方法访问次数以及平均响应时间可以为程序开发的同事提供参考定位具体的代码 # 默认的n ...

  3. EasyUI tree 选中父节点子节点全部选中,选中子节点父节点不选中

    需求:EasyUI tree 选中父节点子节点全部选中,选中子节点父节点不选中 效果:   /**   * 给树增加onCheck事件,首先使用cascadeCheck:false属性禁止全选,   ...

  4. vue 上实现无缝滚动播放文字系统公告

    首先实现效果,当时的需求做的系统公告框设定一个宽度,超宽滚动播放,没超宽则静态展示,有了需求,想了下实现原理,最开始打算js更改字体内容的方式,但是想了下感觉会有点麻烦,想起之前做了表格的左侧边固定, ...

  5. Glide高级详解—缓存与解码复用

    Glide 使用简明的流式语法API,大多数情况下,可能完成图片的设置你只需要:Glide.with(activity) .load(url) .into(imageView); 默认情况下,Glid ...

  6. mongodb基类封装实例

    mongodb的基类 1 <?php 2 3 namespace BI\Service\MongoDB; 4 5 use MongoDB\Driver\BulkWrite; 6 use Mong ...

  7. 【gearman】gearmand -d 无反应解决

    背景:安装了gearman后,用指令gearmand -d启动后.输入ps -ef|grep gearmand 查找不到.说明服务并没有启动. 查看报错: gearmand -d -l gear.lo ...

  8. ERROR 1044 (42000): Access denied for user 'root'@'%' to database 'mysql'

    原因:修改数据库账号时删除了默认的localhost root,  新建了% root 但没有赋予全部权限; 解决方法: 1.关闭数据库# mysqld stop 2.在my.cnf里加入skip-g ...

  9. vue中 裁剪,预览,上传图片 的插件

    参考地址: https://github.com/dai-siki/vue-image-crop-upload

  10. node.js 的热更新

    1.安装 npm i supervisor -gd 2.运行 supervisor server.js //server.js 是你自己的服务的js文件