文章目录
- 一、CPU 处理器分类
- 1、根据物理属性分类 ( SMT、MC、SoC )
- 2、Linux 内核中 CPU 分类
- 二、Linux 内核源码中的 CPU 状态源码
一、CPU 处理器分类
1、根据物理属性分类 ( SMT、MC、SoC )
根据 CPU 的物理属性 , 可以将 CPU 分为如下几类 :
- SMT : 全称 " Simultaneous Multithreading " , 同时多线程 , 又称为 " 超线程 " , 一个物理核心 , 可以有
个执行线程 , 使用相同的 CPU 资源 , 共享 L1 Cache 缓存 ;
- MC : Multicore 多核 , 每个物理核心 独享一个 L1 Cache 缓存 ;
- SoC : System on Chip , 系统级芯片 ;
2、Linux 内核中 CPU 分类
Linux 内核中 , 对 CPU 处理器的分类 :
- CONFIG_SCHED_SMT : 对应 SMT 芯片 , " 超线程 " , 一个物理核心 , 可以有
个执行线程 , 使用相同的 CPU 资源 , 共享 L1 Cache 缓存 ;
- CONFIG_SCHED_MC : 对应 MC 多核芯片 , 每个物理核心 独享一个 L1 Cache 缓存 ;
- DIE : 对应 SoC 芯片 ;
二、Linux 内核源码中的 CPU 状态源码
Linux 内核中 , 通过 bitmap 管理 CPU 处理器 , 并且在 Linux 源码中的 linux-5.6.18includelinuxcpumask.h
头文件源码中 , 定义了 CPU 的四种状态 :
- cpu_possible_mask : 表示系统中 可以执行的 CPU 核心个数 , 可执行指的是现在可以运行 以及 将来某个时间段可以运行 ;
- cpu_online_mask : 表示当前系统中 有多少个正在运行的 CPU 核心个数 ;
- cpu_present_mask : 表示当前系统中 有多少个具备 online 条件的 CPU 核心个数 , 不一定都处于 online 状态 ;
- cpu_active_mask : 表示当前系统中 有多少个活跃的 CPU 核心 ;
/*
* The following particular system cpumasks and operations manage
* possible, present, active and online cpus.
*
* cpu_possible_mask- has bit 'cpu' set iff cpu is populatable
* cpu_present_mask - has bit 'cpu' set iff cpu is populated
* cpu_online_mask - has bit 'cpu' set iff cpu available to scheduler
* cpu_active_mask - has bit 'cpu' set iff cpu available to migration
*
* If !CONFIG_HOTPLUG_CPU, present == possible, and active == online.
*
* The cpu_possible_mask is fixed at boot time, as the set of CPU id's
* that it is possible might ever be plugged in at anytime during the
* life of that system boot. The cpu_present_mask is dynamic(*),
* representing which CPUs are currently plugged in. And
* cpu_online_mask is the dynamic subset of cpu_present_mask,
* indicating those CPUs available for scheduling.
*
* If HOTPLUG is enabled, then cpu_possible_mask is forced to have
* all NR_CPUS bits set, otherwise it is just the set of CPUs that
* ACPI reports present at boot.
*
* If HOTPLUG is enabled, then cpu_present_mask varies dynamically,
* depending on what ACPI reports as currently plugged in, otherwise
* cpu_present_mask is just a copy of cpu_possible_mask.
*
* (*) Well, cpu_present_mask is dynamic in the hotplug case. If not
* hotplug, it's a copy of cpu_possible_mask, hence fixed at boot.
*
* Subtleties:
* 1) UP arch's (NR_CPUS == 1, CONFIG_SMP not defined) hardcode
* assumption that their single CPU is online. The UP
* cpu_{online,possible,present}_masks are placebos. Changing them
* will have no useful affect on the following num_*_cpus()
* and cpu_*() macros in the UP case. This ugliness is a UP
* optimization - don't waste any instructions or memory references
* asking if you're online or how many CPUs there are if there is
* only one CPU.
*/
extern struct cpumask __cpu_possible_mask;
extern struct cpumask __cpu_online_mask;
extern struct cpumask __cpu_present_mask;
extern struct cpumask __cpu_active_mask;
#define cpu_possible_mask ((const struct cpumask *)&__cpu_possible_mask)
#define cpu_online_mask ((const struct cpumask *)&__cpu_online_mask)
#define cpu_present_mask ((const struct cpumask *)&__cpu_present_mask)
#define cpu_active_mask ((const struct cpumask *)&__cpu_active_mask)