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

 

 

进程与cpu 绑定需要做四件事:

 

 

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

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

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

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

 

 

一、把指定cpucpu 平衡算法剔除,机器启动后,用户进程自动不会在指定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 表示该中断请求在cpu0cpu1 上运行,

 

三、 把指定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 表示运行在cpu0cpu1 上。

 

 

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

 

 

注:

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

2taskset  可以用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

 

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值