一、开机阶段
开机有如下阶段。抛开开机动画需要的audio、surfaceflinger等进程,大部分android程序是在/data分区加载完整以后开始加载。所以cpuset的配置可以在 post-fs-data之后。注意,init.rc的不同阶段脚本都可能覆盖前面配置的cpuset。配置好检查与预期不一致,则要配置被重置了。
- early-init
a) wait_for_coldboot_done
b) property_init
c) keychord_int
d) console_init
e) set_init_properties
-
init
-
early-fs
-
fs
-
post-fs
-
post-fs-data
f) property_service_init
g) signal_init
h) check_startup
-
early-boot
-
boot
-
service
二、配置cpuset
本例策略如下:
开机阶段:
write /dev/cpuset/top-app/cpus 0-5
write /dev/cpuset/foreground/cpus 0-5
write /dev/cpuset/system-background/cpus 0-5
write /dev/cpuset/background/cpus 4-5
开机完成后:
write /dev/cpuset/top-app/cpus 0-3
write /dev/cpuset/foreground/cpus 0-3
write /dev/cpuset/system-background/cpus 3-5
配置方法:
修改init.rc
on early-boot
write /dev/cpuset/top-app/cpus 0-5
write /dev/cpuset/foreground/cpus 0-5
write /dev/cpuset/foreground/boost/cpus 0-5
write /dev/cpuset/system-background/cpus 0-5
write /dev/cpuset/background/cpus 4-5
....
on property:sys.boot_completed=1
write /proc/sys/kernel/printk 4
# init.vendor.rc can override below at on property:sys.boot_completed if needed
write /dev/cpuset/top-app/cpus 0-3
write /dev/cpuset/foreground/cpus 0-3
write /dev/cpuset/system-background/cpus 3-5
三、配置特定进程的cpuset
# We want all cores for camera
mkdir /dev/cpuset/camera-daemon
write /dev/cpuset/camera-daemon/cpus 0-5
write /dev/cpuset/camera-daemon/mems 0
chown cameraserver cameraserver /dev/cpuset/camera-daemon
chown cameraserver cameraserver /dev/cpuset/camera-daemon/tasks
chmod 0660 /dev/cpuset/camera-daemon/tasks
四、验证方法:
在adb shell里面:
#cd /dev/cpuset/top-app
/dev/cpuset/top-app # ps -A -p `cat tasks`
可以看到top-app下活跃的进程
USER PID PPID VSZ RSS WCHAN ADDR S NAME
u0_a53 2217 378 4546160 192796 ep_poll 0 S com.fiilll.app.launcher
然后敲:
ps -o pid,psr,comm -p `pidof com.gwm.fiill.launcher`
显示的PSR就是核
PID PSR COMM
2217 1 app_process64
同样的步骤查看system-background
/dev/cpuset/system-background # ps -A -p `cat tasks`
USER PID PPID VSZ RSS WCHAN ADDR S NAME
logd 329 1 76160 56700 sigsuspend 0 S logd
system 330 1 11156 3728 binder_ioctl_write_read 0 S servicemanager
system 331 1 2126696 6756 binder_ioctl_write_read 0 S hwservicemanager
system 332 1 11872 3096 binder_ioctl_write_read 0 S vndservicemanager
system 474 1 56072 17740 binder_ioctl_write_read 0 S android.hardware.graphics.composer@2.2-service
root 729 1 9544 2400 ep_poll 0 S lmkd
system 731 1 2192692 34460 ep_poll 0 S surfaceflinger
system 735 1 11220 4420 poll_schedule_timeout 0 S name-server
statsd 897 1 23296 6648 ep_poll 0 S statsd
root 898 1 22688 5752 binder_ioctl_write_read 0 S storaged
root 906 1 38444 13552 poll_schedule_timeout 0 S dlt-daemon
system 954 1 2128968 7096 binder_ioctl_write_read 0 S gatekeeperd
root 955 1 18988 4752 binder_ioctl_write_read 0 S perfprofd
tombstoned 959 1 9232 2300 ep_poll 0 S tombstoned
由于statsd是开机完成前加载的,所以第一次cpuset可能在0-5之间
PID PSR COMM
897 0 statsd
我们以此可以判断开机时候配置的是否正常。
现在杀掉该进程重新加载:
kill -6 `pidof statsd`
再查看它的cpuset:
ps -o pid,psr,comm -p `pidof statsd`
发现cpuset已经变了
PID PSR COMM
9766 3 statsd