Skip to content

Commit 77cb6a0

Browse files
committed
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
1 parent b90e23e commit 77cb6a0

File tree

1 file changed

+39
-10
lines changed

1 file changed

+39
-10
lines changed

rootdir/init.rc

+39-10
Original file line numberDiff line numberDiff line change
@@ -153,21 +153,56 @@ on init
153153
mkdir /dev/cpuctl/background
154154
mkdir /dev/cpuctl/top-app
155155
mkdir /dev/cpuctl/rt
156+
mkdir /dev/cpuctl/system
156157
chown system system /dev/cpuctl
157158
chown system system /dev/cpuctl/foreground
158159
chown system system /dev/cpuctl/background
159160
chown system system /dev/cpuctl/top-app
160161
chown system system /dev/cpuctl/rt
162+
chown system system /dev/cpuctl/system
161163
chown system system /dev/cpuctl/tasks
162164
chown system system /dev/cpuctl/foreground/tasks
163165
chown system system /dev/cpuctl/background/tasks
164166
chown system system /dev/cpuctl/top-app/tasks
165167
chown system system /dev/cpuctl/rt/tasks
168+
chown system system /dev/cpuctl/system/tasks
166169
chmod 0664 /dev/cpuctl/tasks
167170
chmod 0664 /dev/cpuctl/foreground/tasks
168171
chmod 0664 /dev/cpuctl/background/tasks
169172
chmod 0664 /dev/cpuctl/top-app/tasks
170173
chmod 0664 /dev/cpuctl/rt/tasks
174+
chmod 0664 /dev/cpuctl/system/tasks
175+
176+
# Create a cpu group for NNAPI HAL processes
177+
mkdir /dev/cpuctl/nnapi-hal
178+
chown system system /dev/cpuctl/nnapi-hal
179+
chown system system /dev/cpuctl/nnapi-hal/tasks
180+
chmod 0664 /dev/cpuctl/nnapi-hal/tasks
181+
write /dev/cpuctl/nnapi-hal/cpu.uclamp.min 1
182+
write /dev/cpuctl/nnapi-hal/cpu.uclamp.latency_sensitive 1
183+
184+
# Android only use global RT throttling and doesn't use CONFIG_RT_GROUP_SCHED
185+
# for RT group throttling. These values here are just to make sure RT threads
186+
# can be migrated to those groups. These settings can be removed once we migrate
187+
# to GKI kernel.
188+
write /dev/cpuctl/cpu.rt_period_us 1000000
189+
write /dev/cpuctl/cpu.rt_runtime_us 950000
190+
# Surfaceflinger is in FG group so giving it a bit more
191+
write /dev/cpuctl/foreground/cpu.rt_runtime_us 450000
192+
write /dev/cpuctl/foreground/cpu.rt_period_us 1000000
193+
write /dev/cpuctl/background/cpu.rt_runtime_us 100000
194+
write /dev/cpuctl/background/cpu.rt_period_us 1000000
195+
write /dev/cpuctl/top-app/cpu.rt_runtime_us 100000
196+
write /dev/cpuctl/top-app/cpu.rt_period_us 1000000
197+
write /dev/cpuctl/rt/cpu.rt_runtime_us 100000
198+
write /dev/cpuctl/rt/cpu.rt_period_us 1000000
199+
write /dev/cpuctl/system/cpu.rt_runtime_us 100000
200+
write /dev/cpuctl/system/cpu.rt_period_us 1000000
201+
write /dev/cpuctl/nnapi-hal/cpu.rt_runtime_us 100000
202+
write /dev/cpuctl/nnapi-hal/cpu.rt_period_us 1000000
203+
204+
# Migrate root group to system subgroup
205+
copy_per_line /dev/cpuctl/tasks /dev/cpuctl/system/tasks
171206

172207
# Create an stune group for NNAPI HAL processes
173208
mkdir /dev/stune/nnapi-hal
@@ -177,14 +212,6 @@ on init
177212
write /dev/stune/nnapi-hal/schedtune.boost 1
178213
write /dev/stune/nnapi-hal/schedtune.prefer_idle 1
179214

180-
# cpuctl hierarchy for devices using utilclamp
181-
mkdir /dev/cpuctl/nnapi-hal
182-
chown system system /dev/cpuctl/nnapi-hal
183-
chown system system /dev/cpuctl/nnapi-hal/tasks
184-
chmod 0664 /dev/cpuctl/nnapi-hal/tasks
185-
write /dev/cpuctl/nnapi-hal/cpu.uclamp.min 1
186-
write /dev/cpuctl/nnapi-hal/cpu.uclamp.latency_sensitive 1
187-
188215
# Create blkio group and apply initial settings.
189216
# This feature needs kernel to support it, and the
190217
# device's init.rc must actually set the correct values.
@@ -302,8 +329,6 @@ on init
302329
chown system system /dev/cpuctl
303330
chown system system /dev/cpuctl/tasks
304331
chmod 0666 /dev/cpuctl/tasks
305-
write /dev/cpuctl/cpu.rt_period_us 1000000
306-
write /dev/cpuctl/cpu.rt_runtime_us 950000
307332

308333
# sets up initial cpusets for ActivityManager
309334
# this ensures that the cpusets are present and usable, but the device's
@@ -1151,3 +1176,7 @@ on userspace-reboot-resume
11511176

11521177
on property:sys.boot_completed=1 && property:sys.init.userspace_reboot.in_progress=1
11531178
setprop sys.init.userspace_reboot.in_progress ""
1179+
1180+
# Migrate tasks again in case kernel threads are created during boot
1181+
on property:sys.boot_completed=1
1182+
copy_per_line /dev/cpuctl/tasks /dev/cpuctl/system/tasks

0 commit comments

Comments
 (0)