linux 系统内可以通过sysfs 文件系统查看/sys/devices/system/cpu目录内当前所使用的cpu详细信息,不仅可以查到单核cpu,还可以查看多核cpu以及NUMA系统内的cpu信息,还可以查看每个cpu包含的cache详细信息,以便对代码进行进一步优化。

/sys/devices/system/cpu

该目录是cpu详细信息根目录(特别要注意说明的时此时cpu 并不是我们通常意义上的物理cpu 而是逻辑cpu即一个线程相当于一个cpu,有些cpu core可以同时支持2个线程并行那么该cpu core就相当于拥有两个逻辑cpu即一个物理cpu core同时支持两个线程并发执行):

  • /sys/devices/system/cpu/cpu<id>为命名的目录,代表该cpu有多少个cpu核数,每个cpu核有一个相对应的cpu<id>目录,代表每个cpu核的单独详细信息都在该对应的cpu核目录内,其中id从0开始依次到最大cpu 核。
  • /sys/devices/system/cpu/isolated,  显示当前系统是否有cpu被设置为单独隔离(通过设置cpu ioslated,系统在进程调度时是不能将进程调度到隔离的cpu上进行执行,除非是有特殊进程强制指定,cpu 隔离是在系统启动时通过cmdline设置的,例如设置cpu2为单独隔离,

linux bootvmlinuz{kernel-version} root=UUID=.... quite splash isolcpus=2

  • cpu隔离具体详细资料可以查看:CPU Isolation & CPU affinity In Linux,/sys/devices/system/cpu/isolated文件只读,在系统启动阶段进行配置
  • /sys/devices/system/cpu/kernel_max: 内核可以使用的cpu 最大索引,该文件只读。
  • /sys/devices/system/cpu/microcode:linux cpu微码microcode更新机制,可以通过echo 1 > /sys/devices/system/cpu/microcode/reload 开启加载 /lib/firmware/intel-ucode 目录下的microcode来更新,具体详细解释可以查看内核microcode文档说明:microcode.rst - Documentation/x86/microcode.rst - Linux source code (v5.14.9) - Bootlin,
  • /sys/devices/system/cpu/modalias:   cpu modalias文件 主要是cpu硬件返回给kernel的硬件相关信息,关于modalias 文件描述如下:

a modalias file simply exposes the information that a given piece of hardware already tells the kernel.

  • /sys/devices/system/cpu/offline:没有上线的cpu(没有上线原因主要有被热插拔下线或者超过了系统允许的配置即kernel_max:

cpus that are not online because they have been HOTPLUGGED off or exceed the limit of cpus allowed by the kernel configuration

  • /sys/devices/system/cpu/online: 上线的cpu核数:

cpus that are online and being scheduled

  • /sys/devices/system/cpu/possible: 可以使用的cpu最多的数量,即能够上线的最大数量:

cpus that are online and being scheduled

  • /sys/devices/system/cpu/power: 当前系统cpu总的电源管理
  • /sys/devices/system/cpu/present:已经被系统识别的cpu
  • /sys/devices/system/cpu/smt: SMT(control symmetric multi  threading)相关配置
  • /sys/devices/system/cpu/uevent: cpu uvent
  • /sys/devices/system/cpu/vulnerabilities:cpu 漏洞相关

以上是/sys/devices/system/cpu目录内的主要内容说明,下面是使用机器目录下相关信息:

/sys/devices/system/cpu/cpu<id>

cpu<id>目录下主要显示每个cpu核的相关信息,

/sys/devices/system/cpu/cpu<id>/acpi_cppc

主要是描述从acpi中读取到的cppc(Collaborative Processor Performance Control)协作处理器性能,该目录内都是只读文件,内容都是从acpi中读取出来,主要包含以下几个文件:

  • /sys/devices/system/cpu/cpu<id>/acpi_cppc/feedback_ctrs:主要包括一个引起计数reference和性能计数器

Includes both Reference and delivered performance counter. Reference counter ticks up proportional to processor's reference performance

  • /sys/devices/system/cpu/cpu<id>/acpi_cppc/highest_perf: 该处理器最高理论性能:
  • /sys/devices/system/cpu/cpu<id>/acpi_cppc/lowest_perf :该处理器最低性能
  • /sys/devices/system/cpu/cpu<id>/acpi_cppc/lowest_freq: 该处理器最低性能lowest_perf对应的最低频率,单位为(in MHZ)
  • /sys/devices/system/cpu/cpu<id>/acpi_cppc/lowest_nonlinear_perf:处理器非线性节能对应的最低性能
  • /sys/devices/system/cpu/cpu<id>/acpi_cppc/nominal_perf:处理器最高持续性能即最高性能能持续多久
  • /sys/devices/system/cpu/cpu<id>/acpi_cppc/nominal_freq:nominal_perf 对应的频率
  • /sys/devices/system/cpu/cpu<id>/acpi_cppc/reference_perf:引用计数器性能级别
  • /sys/devices/system/cpu/cpu<id>/acpi_cppc/wraparound_time:反馈计数器最短时间。

上述性能指标主要是从ACPI中读取,从ACPI文档中可以看到上述各个字段详细描述:

/sys/devices/system/cpu/cpu<id>/cache

该目录主要是描述每个cpu 拥有的cache详细信息,在对代码优化过程中经常需要用到cache的详细信息,以下是使用的机器上cache目录信息:

hzk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache$ ls -l
total 0
drwxr-xr-x 2 root root    0 10月  7 14:57 index0
drwxr-xr-x 2 root root    0 10月  7 14:54 index1
drwxr-xr-x 2 root root    0 10月  7 14:54 index2
drwxr-xr-x 2 root root    0 10月  7 14:57 index3
-rw-r--r-- 1 root root 4096 10月  7 19:11 uevent

在cache目录下首先看到该目录下有一系列index为前缀的目录,分别为index0、index1、index2、index3表明该cpu0内有4个cache,每个cache详细信息分别位于index<n>目录内,进一步查看每个cache:

index0 目录下cache信息如下:

zk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache/index0$ ls -l
total 0
-r--r--r-- 1 root root 4096 10月  7 19:17 coherency_line_size
-r--r--r-- 1 root root 4096 10月  7 19:17 id
-r--r--r-- 1 root root 4096 10月  7 19:17 level
-r--r--r-- 1 root root 4096 10月  7 19:17 number_of_sets
-r--r--r-- 1 root root 4096 10月  7 19:17 physical_line_partition
-r--r--r-- 1 root root 4096 10月  7 19:17 shared_cpu_list
-r--r--r-- 1 root root 4096 10月  7 14:57 shared_cpu_map
-r--r--r-- 1 root root 4096 10月  7 19:17 size
-r--r--r-- 1 root root 4096 10月  7 19:17 type
-rw-r--r-- 1 root root 4096 10月  7 19:17 uevent
-r--r--r-- 1 root root 4096 10月  7 19:17 ways_of_associativity

每个cache index目录内都有如上几个文件,每个文件只可读,因为应用程序一般不操作具体cache,交由内核和硬件进行cache数据一致性同步:

  • /sys/devices/system/cpu/cpu<id>/cache/index<n>/coherency_line_size: cache line大小
  • /sys/devices/system/cpu/cpu<id>/cache/index<n>/id: cache id
  • /sys/devices/system/cpu/cpu<id>/cache/index<n>/level: cache 级别 即分别属于L1、L2和L3哪个级别
  • /sys/devices/system/cpu/cpu<id>/cache/index<n>/number_of_sets: 每路(way)内的cache sets数目
  • /sys/devices/system/cpu/cpu<id>/cache/index<n>/physical_line_partition:一个tag 对应几个cache line
  • /sys/devices/system/cpu/cpu<id>/cache/index<n>/shared_cpu_list: 该cache 被几个cpu 所共享或者可以使用该cache的cpu
  • /sys/devices/system/cpu/cpu<id>/cache/index<n>/shared_cpu_map: 该cache被几个cpu所共享使用,并将其转换成map形式
  • /sys/devices/system/cpu/cpu<id>/cache/index<n >/size: 该cache 大小 ,其大小= number_of_set *way_of_associativity* coherency_line_size
  • /sys/devices/system/cpu/cpu<id>/cache/index<n >/way: 该cache类型:主要分配Data(数据cache)、Instruction(指令cache)、Unifed(统一cache即被同时用作数据cache和指令cache,不区分数据和指令,一般为L2或L3)
  • /sys/devices/system/cpu/cpu<id>/cache/index<n >/uevent: uevent 事件
  • /sys/devices/system/cpu/cpu<id>/cache/index<n >/ways_of_associativity: 该cace ways数目

以下分别是本人使用的机器cpu1下的cahe  index0、index1,index 2,index3 cache说明:

index0 cache, 级别为:

hzk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache/index0$ cat ./level
1

index 0 cache 级别为L1 cache, cache 类型为:

hzk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache/index0$ cat ./type
Data

类型为Data,即用作数据cache,大小 size, way 和sets 分别为:

hzk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache/index0$ cat ./size
32K
hzk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache/index0$ cat ./coherency_line_size
64
hzk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache/index0$ cat ./number_of_sets
64
hzk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache/index0$ cat ./ways_of_associativity
8
hzk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache/index0$

index 0 cache size 大小为 32K, cache line 为64, sets为64, ways为8,则也可以计算出cache 大小为=64*64*8=32768=32K

下面继续查看该cache被那些cpu所使用:

hzk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache/index0$ cat shared_cpu_list
1,13
hzk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache/index0$ cat shared_cpu_map
00002002
hzk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache/index0$ 

可以看到该cache被 cpu1 和cpu 13使用,而00002002为 将cpu id转换成对应的bit 位形式。

同样方法查看index 1 的cache情况:

zk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache/index1$ cat level
1
hzk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache/index1$ cat size
32K
hzk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache/index1$ cat type
Instruction
hzk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache/index1$ cat coherency_line_size
64
hzk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache/index1$ cat number_of_sets
64
hzk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache/index1$ cat ways_of_associativity
8
hzk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache/index1$ cat shared_cpu_list
1,13
hzk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache/index1$ cat shared_cpu_map
00002002
hzk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache/index1$

可以看到cpu 1的index 1 cache为L1 cache 用作指令cache, 大小为32K, cache line 为64,sets为64, ways为8, 被cpu1 和cpu 13使用

进一步查看index 2 cache情况:

hzk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache/index2$ cat size
512K
hzk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache/index2$ cat level
2
hzk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache/index2$ cat type
Unified
hzk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache/index2$ cat number_of_sets
1024
hzk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache/index2$ cat coherency_line_size
64
hzk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache/index2$ cat ways_of_associativity
8
hzk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache/index2$ cat shared_cpu_list
1,13
hzk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache/index2$ cat shared_cpu_map
00002002
hzk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache/index2$ 

index 2 cache为 unified cace 为L2 cache ,大小为512K 即既可以用作数据cache又可以用作指令cache,被cpu1和cpu 13使用

index 3 cache情况如下:

zk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache/index3$ cat level
3
hzk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache/index3$ cat type
Unified
hzk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache/index3$ cat size
16384K
hzk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache/index3$ cat number_of_sets
16384
hzk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache/index3$ cat coherency_line_size
64
hzk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache/index3$ cat ways_of_associativity
16
hzk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache/index3$ cat shared_cpu_list
0-2,12-14
hzk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache/index3$ cat shared_cpu_map
00007007
hzk@hzk-X570-AORUS-PRO-WIFI:/sys/devices/system/cpu/cpu1/cache/index3$

index 3为L3 cache , 大小为16384K,被0,1,2以及 12,13,14 cpu所使用即被6个cpu使用。

通过信息可以分析出使用的cpu L1、L2及L3 cache 分部情况:

 所使用的机器每两个cpu共享L1和L2 cache, 每6个cpu共享一个 L3cache ,其中上述cpu 概念指的是逻辑cpu概念相当于线程即 两个线程共享相同的 L1和L2cache,而真正的一个cpu 物理核同时支持两个线程并发。

/sys/devices/system/cpu/cpu<id>/topology

主要描述cpu在整个系统cpu拓扑关系图,主要由以下文件:

  • core_cpus:当前cpu所处的cpu core包含的cpu数目,map形式
  • core_cpus_list: 当前cpu所处的cpu core包含的cpu数目
  • core_id:cpu id
  • core_siblings:前所有可见的cpu core
  • core_siblings_list: 当前所有可见的cpu core
  • die_cpus:在一个物理封装内的cpu 数目 map形式
  • die_cpu_list:在一个物理封装内的cpu 数目
  • die_id: 封装的die id
  • package_cpus:物理封装的所有cpu map形式
  • package_cpu_list: 物理封装的所有cpu
  • physical_package_id:处于的物理封装 id 即第几个物理封装
  • thread_sibling:当前cpu所处的cpu core内的所有cpu /线程 map形式
  • thread_sibling_list:当前cpu所处的cpu core内的所有cpu /线程

参考资料

A full task-isolation mode for the kernel [LWN.net]

https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-devices-system-cpu

Cpu微码补丁microcode和linux内核的microcode更新机制

microcode.rst - Documentation/x86/microcode.rst - Linux source code (v5.14.9) - Bootlin

Modalias - ArchWiki

https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-devices-system-cpu

IBM Docs

Collaborative Processor Performance Control (CPPC) — The Linux Kernel documentation

linux 系统内如何查看当前CPU详细信息相关推荐

  1. linux cpu参数,Linux查看CPU详细信息

    1.查看CPU详细信息 在Linux服务器上查看CPU详细信息: cat /proc/cpuinfo 输出结果: processor : 0 vendor_id : GenuineIntel cpu ...

  2. 【mac】MAC电脑下查看CPU详细信息

    Date: 2018.9.30 1.MAC电脑(Mac OSX系统)下查看CPU详细信息 sysctl machdep.cpu 2.Linux系统下查看CPU详细信息 cat /proc/cpuinf ...

  3. 查看Windows服务器的CPU详细信息

    查看Windows服务器的CPU详细信息 让我们来看看Win32_Processor类的几个关键属性: AddressWidth On a 32-bit operating system, the v ...

  4. linux查看镜像的详细信息,docker inspect命令查看镜像详细信息

    # docker inspect ubuntu:18.04 // 查看镜像的详细信息[ {"Id": "sha256:d131e0fa2585a7efbfb187f70d ...

  5. 【Linux下Ubuntu查看电脑cpu和显卡型号信息】

    Linux下Ubuntu查看电脑cpu和显卡型号信息 查看cpu型号终端命令 cat /proc/cpuinfo 输出的model name : 后边即为型号信息 查看显卡型号终端命令 lspci | ...

  6. linux下查看运行进程详细信息

    通过ps及top命令查看进程信息时,只能查到相对路径,查不到的进程的详细信息,如绝对路径等.这时,我们需要通过以下的方法来查看进程的详细信息: Linux在启动一个进程时,系统会在/proc下创建一个 ...

  7. php获取linux是几核的,linux下怎么查看机器cpu是几核的

    linux下怎么查看机器cpu是几核的? linux下查看机器是cpu是几核的 几个cpumore /proc/cpuinfo |grep "physical id"|uniq|w ...

  8. 如何查看电脑显卡详细信息以及nvidia-smi各参数介绍

    主要分为两个部分: 如何查看电脑显卡详细信息 nvidia-smi各参数介绍 1. 如何查看电脑显卡详细信息 不论是windows系统还是linux,打开命令行,输入 nvidia-smi 即可. w ...

  9. 点石互动--石头之:在Google中查看链接的详细信息

    点石互动   highdiy 发表于 03月 14, 2007 在Google网站管理员中心提供详细的反相链接信息后,使得以前许多不得不注册个Yahoo! SiteExplorer帐号以查询网站反相链 ...

最新文章

  1. FFmpeg常用命令总结
  2. 函数的重载与 泛型(generic)有什么不同?
  3. oracle学习-存储过程返回一个值,和返回一个结果集
  4. (转)ASP.NET-关于Container dataitem 与 eval方法介绍
  5. HDU 2515 Yanghee 的算术【找规律】
  6. 深入浅出vc dll动态链接库
  7. echarts 仪表盘 文字位置_方法 | 用notion打造个人仪表盘
  8. Spark基础学习笔记07:搭建Spark HA集群
  9. 如果你是壁纸控,高清图片这里找!
  10. 思科和华为/H3C命令对比表
  11. 1、Keepalived及VRRP原理介绍
  12. linux下编译C++程序无法链接Mysql的问题
  13. java map转xml 工具类_xml和map互转工具类
  14. cifar10数据集_pytorch入门(四)-数据
  15. 华为机试HJ5:进制转换
  16. JavaScript 模拟重载
  17. CSS中怎么让DIV水平居中
  18. 如何:使用 DataAnnotations 特性验证模型数据+MetadataType的使用,MVC的Model层数据验证 指定要与数据模型类关联的元数据类
  19. 电脑修改服务器时间怎么改,修改服务器时间_如何修改服务器时间 做到同步?...
  20. 考研政治---马克思主义基本原理概论---认识论

热门文章

  1. 再谈迭代器,生成器,yield,及和类的使用
  2. 微软Kubernetes服务AKS开发正式版空间服务
  3. 云计算概况及第一个Azure程序
  4. 论信息化投标低于1元中标值吗?
  5. 那些相似的CRM之间究竟有无区别
  6. Android NDK调试出错Unknown Application ABI, Unable to detect application ABI#39;s的解决方式...
  7. “企业知识产权管理与预警”培训活动在省技术产权交易市场成功举办
  8. 为了防止程序重排序,慎用volatile
  9. openldap 中文乱码问题
  10. 《转》Java字符串驻留池