irqbalance项目的主页在这里
irqbalance用于优化中断分配,它会自动收集系统数据以分析使用模式,并依据系统负载状况将工作状态置于 Performance mode 或 Power-save mode。处于Performance mode 时,irqbalance 会将中断尽可能均匀地分发给各个 CPU core,以充分利用 CPU 多核,提升性能。
处于Power-save mode 时,irqbalance 会将中断集中分配给第一个 CPU,以保证其它空闲 CPU 的睡眠时间,降低能耗。
在RHEL发行版里这个守护程序默认是开机启用的,那如何确认它的状态呢?
# service irqbalance status
irqbalance (pid PID) is running…
然后在实践中,我们的专用的应用程序通常是绑定在特定的CPU上的,所以其实不可不需要它。如果已经被打开了,我们可以用下面的命令关闭它:
# service irqbalance stop
Stopping irqbalance: [ OK ]
或者干脆取消开机启动:
# chkconfig irqbalance off
下面我们来分析下这个irqbalance的工作原理,好准确的知道什么时候该用它,什么时候不用它。
既然irqbalance用于优化中断分配,首先我们从中断讲起,文章很长,深吸一口气,来吧!
摘抄重点:
SMP affinity is controlled by manipulating files in the /proc/irq/ directory.
In /proc/irq/ are directories that correspond to the IRQs present on your
system (not all IRQs may be available). In each of these directories is
the “smp_affinity” file, and this is where we will work our magic.
说白了就是往/proc/irq/N/smp_affinity文件写入你希望的亲缘的CPU的mask码! 关于如何手工设置中断亲缘性
接着普及下概念,我们再来看下CPU的拓扑结构,首先看下Intel CPU的各个部件之间的关系:
一个NUMA node包括一个或者多个Socket,以及与之相连的local memory。一个多核的Socket有多个Core。如果CPU支持HT,OS还会把这个Core看成 2个Logical Processor。
可以看拓扑的工具很多lscpu或者intel的cpu_topology64工具都可以
这次用之前我们新介绍的Likwid工具箱里面的likwid-topology我们可以看到:
./likwid-topology
CPU的拓扑结构是各种高性能服务器CPU亲缘性绑定必须理解的东西,有感觉了吗?
有了前面的各种基础知识和名词的铺垫,我们就可以来调查irqbalance的工作原理:
//irqbalance.c
int main(int argc, char** argv)
{
/* ... */
while (keep_going) {
sleep_approx(SLEEP_INTERVAL); //#define SLEEP_INTERVAL 10
/* ... */
clear_work_stats();
parse_proc_interrupts();
parse_proc_stat();
/* ... */
calculate_placement();
activate_mappings();
/* ... */
}
/* ... */
}
从程序的主循环可以很清楚的看到它的逻辑,在退出之前每隔10秒它做了以下的几个事情:
1. 清除统计
2. 分析中断的情况
3. 分析中断的负载情况
4. 根据负载情况计算如何平衡中断
5. 实施中断亲缘性变跟
好吧,稍微看下irqbalance如何使用的:
man irqbalance
–oneshot
Causes irqbalance to be run once, after which the daemon exits
–debug
Causes irqbalance to run in the foreground and extra debug information to be printed
在诊断模型下运行irqbalance可以给我们很多详细的信息:
#./irqbalance –oneshot –debug
喝口水,我们接着来分析下各个步骤的详细情况:
先了解下中断在CPU上的分布情况:
$cat /proc/interrupts|tr -s