您的位置:首页 > 其它

指定某个cpu只运行指定进程的做法

2011-01-08 00:13 162 查看
进程与cpu
绑定需要做四件事:

一、把指定cpu
从平衡算法剔除。

二、把指定cpu
上所有的中断请求搬到其他cpu


三、把指定cpu
上的所有的进程搬到其他cpu


四、把指定进程到绑定到指定cpu


一、把指定cpu
从cpu
平衡算法剔除,机器启动后,用户进程自动不会在指定cpu
上运行。
做法如下:

在/boot/grub/grub.conf
文件里的root=LABEL=/
后面添加 isolcpus=cpu
号列表

cpu
号从0
开始,多个cpu
号之间用“,”
分隔,例:isolcpus=1

或isolcpus=4,5,6

二、把指定cpu
上所有的中断请求搬到其他cpu
,做法如下:

修改/proc/irq/
中断号/smp_affinity
文件的内容。

内容00000001
表示该中断请求在cpu0
上运行,

内容00000003
表示该中断请求在cpu0
和cpu1
上运行,

三、
把指定cpu
上的所有的进程(指定进程除外)搬到其他cpu
,做法如下:

taskset -pc cpu
列表 pid.

例:taskset -pc 1 pid.

taskset -pc 1,2 pid.

taskset -pc 1-4 pid.

在这个过程中,我们主要把系统进程搬到了其他cpu
上。

查看某个进程绑定在哪个cpu
上可以执行taskset -p pid.

输出的mask
值:1
表示运行在cpu0
上,3
表示运行在cpu0
和cpu1
上。

四、把我们的指定进程搬到指定cpu
,做法参考三。

注:

1
、子进程会继承父进程的cpu
信息,分配到cpu0
和cpu1
上运行的进程产生的子进程也会被分配到cpu0
和cpu1.

2
、taskset
可以用c
函数sched_setaffinity
和 sched_getaffinity
代替

3
、查看进程当前运行在哪个cpu
上,可以执行ps -eo pid,args,psr

4、taskset --help

[root@gc13 partitionTLB]# taskset --help

taskset (util-linux 2.13-pre7)

usage: taskset [options] [mask | cpu-list] [pid | cmd [args...]

]

set or get the affinity of a process

-p, --pid operate on existing given pid

-c, --cpu-list display and specify cpus in list format

-h, --help display this help

-v, --version output version information

The default behavior is to run a new command:

taskset 03 sshd -b 1024

You can retrieve the mask of an existing task:

taskset -p 700

Or set it:

taskset -p 03 700

List format uses a comma-separated list instead of a mask:

taskset -pc 0,3,7-11 700

Ranges in list format can take a stride argument:

e.g. 0-31:2 is equivalent to mask 0x55555555
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: