SMP IRQ Affinity
转:非常有用的方法,调式神器
SMP IRQ Affinity
Background:
Whenever a piece of hardware, such as disk controller or ethernet
card,
needs attention from the CPU, it throws an
interrupt. The interrupt tells
the CPU that something has happened and that the CPU should drop
what
it's doing to handle the event. In order to
prevent mutliple devices from
sending the same interrupts, the IRQ system was established where
each device
in a computer system is assigned its own special IRQ so that its
interrupts
are unique.
Starting with the 2.4 kernel, Linux has gained the ability to
assign certain
IRQs to specific processors (or groups of
processors). This is known
as SMP IRQ affinity, and it allows you control how your system will
respond
to various hardware events. It allows you to
restrict or repartition
the work load that you server must do so that it can more
efficiently do
it's job.
Obviously, in order for this to work, you will need a system that
has more
than one processor (SMP). You will also need to
be running a 2.4 or higher
kernel.
Some brief and very bare information on SMP IRQ affinity is
provided in
the kernel source tree of the 2.4 kernel in the file:
/usr/src/linux-2.4/Documentation/IRQ-affinity.txt
How to use it:
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.
The first order of business is to figure out what IRQ a device is
using.
This information is available in the /proc/interrupts
file. Here's a sample:
[root@archimedes /proc]# cat /proc/interrupts
CPU0
CPU1
CPU2
CPU3
0:
4865302
5084964
4917705
5017077
IO-APIC-edge timer
1:
132
108
159
113
IO-APIC-edge keyboard
2:
0
0
0
0
XT-PIC cascade
8:
0
1
0
0
IO-APIC-edge rtc
10:
0
0
0
0
IO-APIC-level usb-ohci
14:
0
0
1
1
IO-APIC-edge ide0
24:
87298
86066
86012
86626
IO-APIC-level aic7xxx
31:
93707
106211
107988
93329
IO-APIC-level eth0
NMI:
0
0
0
0
LOC:
19883500
19883555
19883441 19883424
ERR:
0
MIS:
0
As you can see, this is a 4 processor machine.
The first column (unlabelled)
lists the IRQs used on the system. The rows with
letters (ie, "NMI", "LOC")
are parts of other drivers used on the system and aren't really
accessible
to us, so we'll just ignore them.
The second through fifth columns (labelled CPU0-CPU3) show the
number of times
the corresponding process has handled an interrupt from that
particular IRQ.
For example, all of the CPUs have handled roughly the same number
of interrupts
for IRQ 24 (around 86,000 with CPU0 handling a little over
87,000).
The sixth column lists whether or not the device driver associated
with the
interrupt supports IO-APIC (see
/usr/src/linux/Documentation/i386/IO-APIC.txt
for more information). The only reason to look at
this value is that
SMP affinity will only work for IO-APIC enabled device
drivers. For
example, we will not be able to change the affinity for the
"cascade"
driver (IRQ 2) because it doesn't support IO-APIC.
Finally, the seventh and last column lists the driver or device
that is
associated with the interrupt. In the above
example, our ethernet card
(eth0) is using IRQ 31, and our SCSI controller (aic7xxx) is using
IRQ 24.
The first and last columns are really the only ones we're
interested in here.
For the rest of this example, I'm going to assume that we want to
adjust
the SMP affinity for th SCSI controller (IRQ 24).
Now that we've got the IRQ, we can change the processor
affinity. To
do this, we'll go into the /proc/irq/24/ directory, and see what
the
affinity is currently set to:
[root@archimedes Documentation]# cat
/proc/irq/24/smp_affinity
ffffffff
This is a bitmask that represents which processors any interrupts
on IRQ
24 should be routed to. Each field in the bit
mask corresponds to a processor.
The number held in the "smp_affinity" file is presented in
hexadecimal format,
so in order to manipulate it properly we will need to convert our
bit patterns
from binary to hex before setting them in the proc file.
Each of the "f"s above represents a group of 4 CPUs, with the
rightmost
group being the least significant. For the
purposes of our discussion,
we're going to limit ourselves to only the first 4 CPUs (although
we can
address up to 32).
In short, this means you only have to worry about the rightmost "f"
and you
can assume everything else is a "0" (ie, our bitmask is
"0000000f").
"f" is the hexadecimal represenatation for the decimal number 15
(fifteen)
and the binary pattern of "1111". Each of the
places in the binary pattern
corresponds to a CPU in the server, which means we can use the
following
chart to represent the CPU bit patterns:
Binary
Hex
CPU
0
0001
1
CPU
1
0010
2
CPU
2
0100
4
CPU
3
1000
8
By combining these bit patterns (basically, just adding the Hex
values), we
can address more than one processor at a
time. For example, if I
wanted
to talk to both CPU0 and CPU2 at the same time, the result
is:
Binary
Hex
CPU
0
0001
1
+ CPU
2
0100
4
-----------------------
both
0101
5
If I want to address all four of the processors at once, then the
result is:
Binary
Hex
CPU
0
0001
1
CPU
1
0010
2
CPU
2
0100
4
+ CPU
3
1000
8
-----------------------
both
1111
f
(Remember that we use the letters "a" through "f" to represent the
numbers
"10" to "15" in hex notation).
Given that, we now know that if we have a four processor system, we
can
assign any of 15 different CPU combinations to an IRQ (it would be
16, but
it isn't legal to assign an IRQ affinity of "0" to any IRQ... if
you try,
Linux will just ignore your attempt).
So. Now we get to the fun part.
Remember in our /proc/interrupts listing
above that all four of our CPUs had handled the close to the same
amount of
interrupts for our SCSI card? We now have the
tools needed to limit managing
the SCSI card to just one processor and leave the other three free
to
concentrate on doing other
tasks. Let's assume that we
want to dedicate
our first CPU (CPU0) to handling the SCSI controller
interrupts. To do this,
we would simply run the following command:
[root@archimedes /proc]# echo 1 >
/proc/irq/24/smp_affinity
[root@archimedes /proc]# cat /proc/irq/24/smp_affinity
00000001
Now, let's test it out and see what happens:
[root@archimedes /proc]# cd /tmp/
[root@archimedes /tmp]# tar -zcf test.tgz
/usr/src/linux-2.4.2
tar: Removing leading `/' from member names
[root@archimedes /tmp]# tar -zxf test.tgz
&& rm -rf usr/
[root@archimedes /tmp]# tar -zxf test.tgz
&& rm -rf usr/
[root@archimedes /tmp]# tar -zxf test.tgz
&& rm -rf usr/
[root@archimedes /tmp]# tar -zxf test.tgz
&& rm -rf usr/
[root@archimedes /tmp]# tar -zxf test.tgz
&& rm -rf usr/
[root@archimedes /tmp]# cat /proc/interrupts | grep 24:
24:
99719
86067
86012
86627
IO-APIC-level aic7xxx
Compare that to the previous run without having the IRQ bound to
CPU0:
24:
87298
86066
86012
86626
IO-APIC-level aic7xxx
All of the interrupts from the disk controller are now handled
exclusively
by the first CPU (CPU0), which means that our other 3 proccessors
are free
to do other stuff now.
Finally, it should be pointed out that if you decide you no longer
want
SMP affinity and would rather have the system revert back to the
old set up,
then you can simply do:
[root@archimedes /tmp]# cat /proc/irq/prof_cpu_mask
>/proc/irq/24/smp_affinity
This will reset the "smp_affinity" file to use all "f"s, and will
return to
the load sharing arrangement that we saw earlier.
What can I use it for?
- "balance" out multiple NICs in a multi-processor
machine. By tying a single
NIC to a single CPU, you should be able to scale
the amount of traffic
your server can handle nicely.
- database servers (or servers with lots of disk storage) that also
have
heavy network loads can dedicate a CPU to their
disk controller and assign
another to deal with the NIC to help improve
response times.
Can I do this with processes?
At this time, no.
SMP IRQ Affinity的更多相关文章
- Linux 多核下绑定硬件中断到不同 CPU(IRQ Affinity) 转
硬件中断发生频繁,是件很消耗 CPU 资源的事情,在多核 CPU 条件下如果有办法把大量硬件中断分配给不同的 CPU (core) 处理显然能很好的平衡性能.现在的服务器上动不动就是多 CPU 多核. ...
- 软中断与硬中断 & 中断抢占 中断嵌套
参考了这篇文章:http://blog.csdn.net/zhangskd/article/details/21992933 从本质上来讲,中断是一种电信号,当设备有某种事件发生时,它就会产生中断,通 ...
- Linux系统针对网卡中断的优化处理
摘要: 中断: 当网卡接收到数据包后,会触发硬中断,通知CPU来收包.硬中断是一个CPU和网卡交互的过程.这其实会消耗CPU资源.特别是在使用速度极快的万兆网卡 之后,大量的网络交互使得CPU很大一部 ...
- linux 多进程绑定问题
硬件中断发生频繁,是件很消耗 CPU 资源的事情,在多核 CPU 条件下如果有办法把大量硬件中断分配给不同的 CPU (core) 处理显然能很好的平衡性能.现在的服务器上动不动就是多 CPU 多核. ...
- linux 硬件中断调节
什么是中断 中断interrupts是指硬件主动的来告诉CPU去做某些事情.比如网卡收到数据后可能主动的告诉CPU来处理自己接受到的数据,键盘有了按键输入后会主动告知CPU来读取输入. 硬件主动的打扰 ...
- 扩展Linux网络栈
扩展Linux网络栈 来自Linux内核文档.之前看过这篇文章,一直好奇,问什么一条网络流会固定在一个CPU上进行处理,本文档可以解决这个疑问.为了更好地理解本文章中的功能,将这篇文章穿插入内. 简介 ...
- 【原创】X86下ipipe接管中断/异常
目录 X86 ipipe接管中断/异常 一.回顾 二.X86 linux异常中断处理 1. 中断门及IDT 2. 初始化门描述符 2.1 早期异常处理 2.2 start_kernel中的异常向量初始 ...
- Linux kernel的中断子系统之(三):IRQ number和中断描述符
返回目录:<ARM-Linux中断系统>. 总结: 二描述了中断处理示意图,以及关中断.开中断,和IRQ number重要概念. 三介绍了三个重要的结构体,irq_desc.irq_dat ...
- linux kernel的中断子系统之(三):IRQ number和中断描述符【转】
转自:http://www.wowotech.net/linux_kenrel/interrupt_descriptor.html 一.前言 本文主要围绕IRQ number和中断描述符(interr ...
随机推荐
- java引用数据类型(类)
1 引用数据类型分类 类的类型分两种 1)Java提供好的类,如Scanner类,Random类等,这些已存在的类中包含了很多的方法与属性,可供开发者使用.(类的变量是属性) 2)开发者自己创建的类, ...
- guacamole 0.9.13安装与配置
以下命令很多都需要管理权限,建议使用管理员账号执行,遇到问题可以留言. Guacamole官网文档介绍翻译:http://www.cnblogs.com/ji-yun/p/5657709.html 1 ...
- 64位Windows系统下32位应用程序连接MySql
1.首先得安装“Connector/ODBC”,就是Mysql的ODBC驱动,这个是与应用程序相关的,而不是与操作系统相关的,也就是说,不管你的系统是x64还是x86,只要你的应用程序是x86的那么, ...
- selenium-Python之上传文件
对于web 页面的上传功能实现一般有一下两种方式 普通上传:普通的附件上传是将本地文件的路径作为一个值放在input标签中,通过form表单将这个值提交给服务器 插件上传:一般是指基于flash.ja ...
- 记录下关于SQL server1433端口监听不了的问题
CMD命令netstat -an |findstr 1433,即使在防火墙的入站规则里添加了1433端口的访问,发现1433的端口还是监听不了. 搞了老半天,最终调整了MSSQESERVER的协议下的 ...
- 关于日志造成的频繁的IO
记录日志可能消耗大量的IO [Q] 每次写入都是一个IO操作 即使是同一个文件 两次写入也要打开两次IO操作 [F] 设想有这样一个扩展 把php中要记录的日志 用文件名 和 内容的方式记录在内存中 ...
- c#中的里氏转换和Java中强制类型转换在多态中的应用
在c#中: 注意: 子类并没有继承父类的构造函数,而是会默认调用父类那个无参数的构造函数. 如果一个子类继承了一个父类,那么这个子类除了可以使用自己的成员外,还可以使用从父类那里继承过来的成员.但是父 ...
- c++作业:使用函数调用的方法,实现求两个整数中大的数的程序。
#include <iostream> using namespace std; int main(){ //从键盘接收两个整数,保存在变量num1和num2中 cout<<& ...
- [转载] bp神经网络推导
https://blog.csdn.net/fanxin_i/article/details/80212906 看了这么多就这个推的清楚,转嘞
- STL 之 sort 函数使用方法
关于Sort Sort函数是C++ STL(Standard Template Library / 标准函数库) <algorithm>头文件中的一个排序函数,作用是将一系列数进行排序,因 ...