linux内核中的个性时钟nohz与hres
原创
一、引言
Linux内核的时钟管理是操作系统核心功能之一,它负责处理与时间相关的各种任务。在多核处理器上,为了节约性能和降低能耗,Linux内核引入了nohz和hres两个特性,它们能够针对不同的场景提供灵活的时钟管理策略。
二、nohz特性
nohz(No-HZ)特性是Linux内核为了缩减CPU空闲状态下的功耗而引入的。在传统的CPU空闲模式下,CPU会周期性地检查是否有任务需要执行,即使没有任务,CPU也会进行一些操作,这会促使不必要的能耗。nohz通过将CPU置于一种深度睡眠状态,只有在有任务需要执行时才唤醒CPU,从而缩减能耗。
nohz特性首要包括以下几个部分:
- nohz_full:在系统负载较低时,所有CPU核心都进入深度睡眠状态。
- nohz_idle:在系统负载较低且没有中断出现时,部分CPU核心进入深度睡眠状态。
- nohz_off:禁用nohz特性,CPU核心按照传统行为工作。
下面是一个易懂的nohz特性的配置示例:
# cat /proc/cpuinfo | grep -E 'nohz|online'
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 62
model name : Intel(R) Xeon(R) CPU E5-2680 v4 @ 2.40GHz
stepping : 4
microcode : 0x4000083
cpu MHz : 2399.999
cache size : 15360 KB
physical id : 0
siblings : 8
core id : 0
cpu cores : 1
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 20
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic mmx fxsr sse sse2 ssx nx pdpe1gb rdtscp lm constant_tsc pni monitor ds_cpl vmx smx est tm2 ssse3 sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdpid lahf_lm cpuid_fault xsaveopt
bogomips : 4799.99
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management:
flags : tsc死钟 tsc禁止扩大 nohz
features : tsc直接同步
三、hres特性
hres(High Resolution Scheduling)特性是为了节约CPU空闲状态下的时钟精度而引入的。在传统的CPU空闲模式下,时钟中断的频率较低,促使时钟精度不高,这对于需要高精度时间测量的应用来说是一个问题。hres通过节约时钟中断的频率,节约了时钟的精度。
hres特性首要包括以下几个部分:
- hres_full:在系统负载较低时,所有CPU核心都启用高分辨率时钟。
- hres_idle:在系统负载较低且没有中断出现时,部分CPU核心启用高分辨率时钟。
- hres_off:禁用hres特性,使用传统时钟。
下面是一个易懂的hres特性的配置示例:
# cat /proc/cpuinfo | grep -E 'hres|online'
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 62
model name : Intel(R) Xeon(R) CPU E5-2680 v4 @ 2.40GHz
stepping : 4
microcode : 0x4000083
cpu MHz : 2399.999
cache size : 15360 KB
physical id : 0