手动分配CPU核
taskset -p f 1574
pid 1574's current affinity mask: 5
pid 1574's new affinity mask: f
taskset -c
busybox 不支持
cat /proc/cpuinfo
Processor : ARMv7 Processor rev 5 (v7l)
processor : 0
BogoMIPS : 5714.28
processor : 1
BogoMIPS : 5714.28
processor : 2
BogoMIPS : 5714.28
processor : 3
BogoMIPS : 5714.28
Features : swp half thumb fastmult vfp edsp thumbee neon vfpv3 tls vfpv4 idiva idivt
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xc07
CPU revision : 5
Hardware : sun8i
Revision : 0000
Serial : 2925032c2044fffff18f
系统调用
#include <sched.h>
// 设置进程号为pid的进程运行在mask所设定的CPU上
// 第二个参数cpusetsize是mask所指定的数的长度,我们通常设定为sizeof(cpu_set_t)
// 如果pid的值为0,则表示指定的是当前进程
int sched_setaffinity(pid_t pid, size_t cpusetsize, cpu_set_t *mask);
int sched_getaffinity(pid_t pid, size_t cpusetsize, cpu_set_t *mask);
sched_setaffinity系统调用
CPU 使用率
busybox mpstat -P ALL
init.rc中的设置
# this ensures that the cpusets are present and usable, but the device's
# init.rc must actually set the correct cpus
mkdir /dev/cpuset/foreground
write /dev/cpuset/foreground/cpus 0
write /dev/cpuset/foreground/mems 0
mkdir /dev/cpuset/foreground/boost
write /dev/cpuset/foreground/boost/cpus 0
write /dev/cpuset/foreground/boost/mems 0
mkdir /dev/cpuset/background
write /dev/cpuset/background/cpus 0
write /dev/cpuset/background/mems 0
# system-background is for system tasks that should only run on
# little cores, not on bigs
# to be used only by init, so don't change system-bg permissions
mkdir /dev/cpuset/system-background
write /dev/cpuset/system-background/cpus 0
write /dev/cpuset/system-background/mems 0
# change permissions for all cpusets we'll touch at runtime
chown system system /dev/cpuset
chown system system /dev/cpuset/foreground
chown system system /dev/cpuset/foreground/boost
chown system system /dev/cpuset/background
chown system system /dev/cpuset/tasks
chown system system /dev/cpuset/foreground/tasks
chown system system /dev/cpuset/foreground/boost/tasks
chown system system /dev/cpuset/background/tasks
chmod 0664 /dev/cpuset/foreground/tasks
chmod 0664 /dev/cpuset/foreground/boost/tasks
chmod 0664 /dev/cpuset/background/tasks
chmod 0664 /dev/cpuset/tasks
调频
ondemand:按需调频,最大最小频率之间自动调整
interactive:类似“ondemand”,主要来说就是升频率快,降频慢。
来源:CSDN
作者:gbmaotai
链接:https://blog.csdn.net/gbmaotai/article/details/103453706