Raspberry Pi下进程独占CPU的处理方法

linux内核参数isolcpus的作用是隔离一定数量的CPU,使其独立于内核的平衡调度算法,也就是说,内核本身不会将进程分配给隔离的CPU。之后,用户可以将指定的进程绑定到隔离的CPU,让进程独占CPU,并在一定程度上提高实时性能。

一,参数isolcpus的描述

在Linux内核源代码linux-4.2.1 \ Documentation \ kernel-parameters.txt中,isolcpus的作用和使用如下:

isolcpus= [KNL,SMP] Isolate CPUs from the general scheduler.

Format:

<cpu number>,...,<cpu number>

or

<cpu number>-<cpu number>

(must be a positive range in ascending order)

or a mixture

<cpu number>,...,<cpu number>-<cpu number>

This option can be used to specify one or more CPUs

to isolate from the general SMP balancing and scheduling

algorithms. You can move a process onto or off an

"isolated" CPU via the CPU affinity syscalls or cpuset.

<cpu number> begins at 0 and the maximum value is

"number of CPUs in system - 1".

二,使用isolcpus隔离cpu

Raspberry Pi 3B使用的芯片是BCM2837,其中包含4个ARM Cortex-A53 CPU。在Raspbian操作系统boot \ cmdline.txt文件的末尾添加isolcpus = 3,以隔离第四个CPU:

三,查看挂载cpu3中的进程数目与列表

:ps -eLo psr |  grep 3  | wc -l

:ps -eLo ruser,pid,ppid,lwp,psr,args | awk '{if($5==3)print$0}'

查看中断对cpu的影响:

cat /pro命令cat /proc/irq/32/smp_affinity可以看到IRQ号为32的亲和度.默认值为f,代表这个IRP能被所有CPU接受处理.

命令echo 1 >/proc/irq/32/smp_affinity把IRQ号为32的亲和度值设为1,代表这个IRP仅能被CPU0接受处理

照此,我们可以据要求任意绑定IRQ到CPU。

修改进程的绑定

使用taskset:

:taskset -p 进程pid:

F(1111)代表全部4个cpu切换,对应cpu0,cpu1,cpu2,cpu3

设置进程绑定:

:sudo taskset -pc 2 进程pid.

启动进程时绑定:

:taskset –c 2 a.out

后台启动进程自动绑定

:taskset –c 2 nohup a.out &

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值