init.rc: migrate tasks from root cpu cgroup to a subgroup

Migrate tasks from root group to a subgroup would help us to put soft
cpu bandwidth control correctly. There are few tasks now failed to
migrate due to PF_NO_SETAFFINITY which is the default kernel behavior
which we are not overriding at this moment.

This CL also fixed an issue that most of RT thread lost RT attribute
when kernel with CONFIG_RT_GROUP_SCHED enabled, as the subgroup would be
initialized with 0 RT runtime by default. CONFIG_RT_GROUP_SCHED is not
enabled in GKI kernels but there could be devices with
CONFIG_RT_GROUP_SCHED enabled, so setting some budget for those devices
to make they can still function. OEM can either set proper budget by
themselves or remove CONFIG_RT_GROUP_SCHED completely.

Bug: 171740453
Test: boot and check cgroup
Change-Id: I83babad2751c61d844d03383cb0af09e7513b8e9
This commit is contained in:
Wei Wang 2020-11-18 16:04:08 -08:00
parent b90e23efc7
commit 77cb6a0015
1 changed files with 39 additions and 10 deletions

View File

@ -153,21 +153,56 @@ on init
mkdir /dev/cpuctl/background
mkdir /dev/cpuctl/top-app
mkdir /dev/cpuctl/rt
mkdir /dev/cpuctl/system
chown system system /dev/cpuctl
chown system system /dev/cpuctl/foreground
chown system system /dev/cpuctl/background
chown system system /dev/cpuctl/top-app
chown system system /dev/cpuctl/rt
chown system system /dev/cpuctl/system
chown system system /dev/cpuctl/tasks
chown system system /dev/cpuctl/foreground/tasks
chown system system /dev/cpuctl/background/tasks
chown system system /dev/cpuctl/top-app/tasks
chown system system /dev/cpuctl/rt/tasks
chown system system /dev/cpuctl/system/tasks
chmod 0664 /dev/cpuctl/tasks
chmod 0664 /dev/cpuctl/foreground/tasks
chmod 0664 /dev/cpuctl/background/tasks
chmod 0664 /dev/cpuctl/top-app/tasks
chmod 0664 /dev/cpuctl/rt/tasks
chmod 0664 /dev/cpuctl/system/tasks
# Create a cpu group for NNAPI HAL processes
mkdir /dev/cpuctl/nnapi-hal
chown system system /dev/cpuctl/nnapi-hal
chown system system /dev/cpuctl/nnapi-hal/tasks
chmod 0664 /dev/cpuctl/nnapi-hal/tasks
write /dev/cpuctl/nnapi-hal/cpu.uclamp.min 1
write /dev/cpuctl/nnapi-hal/cpu.uclamp.latency_sensitive 1
# Android only use global RT throttling and doesn't use CONFIG_RT_GROUP_SCHED
# for RT group throttling. These values here are just to make sure RT threads
# can be migrated to those groups. These settings can be removed once we migrate
# to GKI kernel.
write /dev/cpuctl/cpu.rt_period_us 1000000
write /dev/cpuctl/cpu.rt_runtime_us 950000
# Surfaceflinger is in FG group so giving it a bit more
write /dev/cpuctl/foreground/cpu.rt_runtime_us 450000
write /dev/cpuctl/foreground/cpu.rt_period_us 1000000
write /dev/cpuctl/background/cpu.rt_runtime_us 100000
write /dev/cpuctl/background/cpu.rt_period_us 1000000
write /dev/cpuctl/top-app/cpu.rt_runtime_us 100000
write /dev/cpuctl/top-app/cpu.rt_period_us 1000000
write /dev/cpuctl/rt/cpu.rt_runtime_us 100000
write /dev/cpuctl/rt/cpu.rt_period_us 1000000
write /dev/cpuctl/system/cpu.rt_runtime_us 100000
write /dev/cpuctl/system/cpu.rt_period_us 1000000
write /dev/cpuctl/nnapi-hal/cpu.rt_runtime_us 100000
write /dev/cpuctl/nnapi-hal/cpu.rt_period_us 1000000
# Migrate root group to system subgroup
copy_per_line /dev/cpuctl/tasks /dev/cpuctl/system/tasks
# Create an stune group for NNAPI HAL processes
mkdir /dev/stune/nnapi-hal
@ -177,14 +212,6 @@ on init
write /dev/stune/nnapi-hal/schedtune.boost 1
write /dev/stune/nnapi-hal/schedtune.prefer_idle 1
# cpuctl hierarchy for devices using utilclamp
mkdir /dev/cpuctl/nnapi-hal
chown system system /dev/cpuctl/nnapi-hal
chown system system /dev/cpuctl/nnapi-hal/tasks
chmod 0664 /dev/cpuctl/nnapi-hal/tasks
write /dev/cpuctl/nnapi-hal/cpu.uclamp.min 1
write /dev/cpuctl/nnapi-hal/cpu.uclamp.latency_sensitive 1
# Create blkio group and apply initial settings.
# This feature needs kernel to support it, and the
# device's init.rc must actually set the correct values.
@ -302,8 +329,6 @@ on init
chown system system /dev/cpuctl
chown system system /dev/cpuctl/tasks
chmod 0666 /dev/cpuctl/tasks
write /dev/cpuctl/cpu.rt_period_us 1000000
write /dev/cpuctl/cpu.rt_runtime_us 950000
# sets up initial cpusets for ActivityManager
# this ensures that the cpusets are present and usable, but the device's
@ -1151,3 +1176,7 @@ on userspace-reboot-resume
on property:sys.boot_completed=1 && property:sys.init.userspace_reboot.in_progress=1
setprop sys.init.userspace_reboot.in_progress ""
# Migrate tasks again in case kernel threads are created during boot
on property:sys.boot_completed=1
copy_per_line /dev/cpuctl/tasks /dev/cpuctl/system/tasks