Commit graph

380 commits

Author SHA1 Message Date
Priyanka Advani (xWF)
0fa49253a4 Revert "libprocessgroup: Combine all 3 ActivateControllers imple..."
Revert submission 3212512

Reason for revert: Droidmonitor created revert due to b/372273614. Will be verifying through ABTD before submission.

Reverted changes: /q/submissionid:3212512

Change-Id: I3dadc0b7bccfe28bb067a93df2acf2c3ea0f9920
2024-10-08 18:54:40 +00:00
T.J. Mercier
5161033f66 libprocessgroup: Combine all 3 ActivateControllers implementations into one
Remove this code duplication and use just one interface.

Bug: 349105928
Change-Id: Id8c7186d9665e9087a654f5781b7593b06349160
2024-10-03 17:01:34 +00:00
T.J. Mercier
c31c5a75c8 libprocessgroup: Remove ACgroupController_getMaxActivationDepth
This was targeted for API 36 which doesn't exist yet, so this was never
released. Now that libprocessgroup does not use the libcgrouprc
interfaces, this can be removed.

Bug: 349105928
Bug: 359609093
Change-Id: I2ea466c9e8bc54bf9178fa74b45e88f26d3e4c69
2024-10-03 17:01:34 +00:00
T.J. Mercier
9d84103bdd libprocessgroup: Remove dependency on libcgrouprc
Read cgroup descriptors ourselves instead of going through the LLNDK
interface which performs the same thing.

Bug: 349105928
Change-Id: I94625ffd0d884d619eb3449e63a305ad5e1d77e3
2024-10-03 17:01:34 +00:00
T.J. Mercier
ae4ce8ccc5 libprocessgroup: Remove cgroup.rc file
The cgroup.rc file was introduced in 192aee782 ("libprocessgroup: Add
support for task profiles") back with the initial support for task
profiles. It was intended to optimize performance associated with cgroup
operations. However over time, supporting this file led to making
libprocessgroup code more complicated (such as the cgrouprc LLNDK
interface), and the file ended up getting mmaped into nearly every
process on Android even though only a handful of them actually use it.
Replacing this file with reading and parsing of cgroup information on
demand allows us to simplify and shrink libprocessgroup, and eliminates
thousands of unused mappings without negatively affecting boot time or
other performance metrics.

Bug: 349105928
Test: Verified with memcg v2 and MaxActivationDepth 1 on Cuttlefish, Raven, and Mokey
Change-Id: Ic3f01fdf7fda89a56ab80657e1cf4573156273e6
2024-10-03 17:01:34 +00:00
T.J. Mercier
981664df08 libprocessgroup: Remove schedtune support
Schedtune was an out of tree cgroup controller present in Android
kernels up to 4.19. It was replaced with uclamp and the cpu controller.
Now that 4.19 is EOL and unsupported, and schedtune is not present in
any supported Android kernels, remove the userspace support for
schedtune.

Bug: 362504801
Change-Id: If8baaf1a616984c5dbaac1bbd03e23ad001bc29c
2024-10-02 14:47:45 +00:00
Jerry Chang
2f84febec1 Merge "Add input event profile to mitigate input latency of input threads" into main 2024-09-18 10:36:32 +00:00
Jerry Chang
72b0186a38 Add input event profile to mitigate input latency of input threads
Bug: 347122505
Test: manual dump Perfetto

Change-Id: I224fa31a7358fcd32dfb1c3fa9dec35101e97163
2024-09-18 08:18:42 +00:00
Rick Yiu
a726c8c28c Add a new policy for for foreground of multi-window
Add SP_FOREGROUND_MW.

Bug: 200769420
Test: build pass
Change-Id: I203ebb2cbe0409b7bee8542ad276cd4e96c8eacb
2024-08-15 01:33:11 +00:00
Rick Yiu
673e6bb089 Create a new group for foreground of multi-window
In multi-window mode, currently the focused window will be top-app,
and others will be foreground. However, the cpu resource we assign to
typical foreground group may not meet the performance need of those
windows. Therefore, create a new group for them so that we could
distinguish their performance need.

Bug: 200769420
Test: group created
Change-Id: I84c61f9ed4d167e156dafb7a816b6482e80a8523
2024-08-15 01:29:48 +00:00
T.J. Mercier
ae0b290387 libprocessgroup: Convert libprocessgroup_util to static library
To avoid duplicate symbol linker error and prep for addition of json
descriptor reading and activation functions in upcoming changes.

Bug: 349105928
Test: m
Change-Id: I5cd663d6007ef330b872b8cf8ed046ee68b6d736
2024-08-12 21:15:09 +00:00
T.J. Mercier
7c94e5b25c libprocessgroup: Remove unused CgroupMap::SetupCgroups declaration
SetupCgroups was moved from CgroupMap in libprocessgroup to SetupCgroup
in libprocessgroup_setup, but the old declaration was not removed.

Fixes: 6f9ce2e548 ("libprocessgroup: Move CgroupSetupCgroups() to libprocessgroup_setup")
Test: m
Change-Id: I9f85000392b59a105bb202fae277a5582449822a
2024-08-09 18:35:29 +00:00
T.J. Mercier
9c53c803e1 libprocessgroup: Rename files a_cgroup_controller.cpp, a_cgroup_file.cpp
These are for ACgroupController and ACgroupFile, but share a filename
with libcgrouprc_format's CgroupController which can be confusing.

Bug: 349105928
Test: m
Change-Id: Idb270068169b71b0a33101407ddbb5a38cc8d469
2024-08-09 18:35:29 +00:00
T.J. Mercier
fcb8666eed libprocessgroup: Rename CgroupController -> CgroupControllerWrapper
So that the name is not overloaded with libcgrouprc_format's
CgroupController, which can be confusing.

Bug: 349105928
Test: m
Change-Id: I39df9814c500de68fd20139e661363ba51ea3543
2024-08-09 18:35:29 +00:00
Treehugger Robot
59a11e37aa Merge "Revert^2 "Move StagedRollbackTest from postsubmit to presubmit"" into main 2024-06-27 20:02:24 +00:00
T.J. Mercier
36e2a44710 Revert^2 "Move StagedRollbackTest from postsubmit to presubmit"
This reverts commit 104d3cc4b9.

Reason for revert: change from presubmit to presubmit-large
Bug: 349693967

Change-Id: I47ea41162aea0140bc460521d0638ce9ca8a96a3
2024-06-27 01:59:14 +00:00
T.J. Mercier
95a9a432be Merge "Revert "Move StagedRollbackTest from postsubmit to presubmit"" into main 2024-06-27 01:57:58 +00:00
Pechetty Sravani
104d3cc4b9 Revert "Move StagedRollbackTest from postsubmit to presubmit"
This reverts commit 0509c71cc4.

Reason for revert: Droidmonitor triggered revert due to Test breakage in b/349693967. Will be verifying through ABTD before submission.

Change-Id: I66a706b8b4f9bf802f7ea1a6b50bb4847b915c92
2024-06-27 01:49:59 +00:00
Treehugger Robot
40fd5beb0d Merge "Move StagedRollbackTest from postsubmit to presubmit" into main 2024-06-27 00:46:30 +00:00
T.J. Mercier
0509c71cc4 Move StagedRollbackTest from postsubmit to presubmit
Bug: 324596460
Change-Id: Iad7bfd7cb56f0c16366a9aa61b9466545ee4c661
2024-06-26 23:09:03 +00:00
T.J. Mercier
28b37f2704 libprocessgroup: Add MaxActivationDepth
Cgroup v2 controllers can be enabled in a subtree of the shared
hierarchy. That allows users to limit the number of cgroups with a
controller enabled to less than the total number of cgroups. [1]

There are costs for each cgroup. Kernel memory is used for each cgroup,
plus additional memory for each active controller in each cgroup. Some
kernel operations scale with the number of cgroups (with a given
controller enabled), so it can be desirable to minimize the number of
cgroups with that controller enabled.

This change allows each v2 controller configuration to specify a maximum
activation depth, past which the controller will not be activated deeper
in the Android cgroup v2 hierarchy. The hierarchy root is defined as
depth 0. MaxActivationDepth is the field name for this purpose for
controllers in the Controllers array under Cgroups2 in cgroups.json.

Here are two examples:

"MaxActivationDepth": 1
This will activate the controller in every per-application cgroup, but
not in the per-process cgroups below.

/sys/fs/cgroup                depth=0  active=true  (controller listed in cgroup.subtree_control)
/sys/fs/cgroup/uid_0          depth=1  active=true  (controller NOT listed in cgroup.subtree_control)
/sys/fs/cgroup/uid_0/pid_100  depth=2  active=false (controller NOT listed in cgroup.subtree_control)

This can also be used with
PRODUCT_CGROUP_V2_SYS_APP_ISOLATION_ENABLED := true.

"MaxActivationDepth": 1
This will activate the controller only at the app / system level, but
not in per-application cgroups below. This results in a total of only
3 cgroups with the controller enabled (root, apps, system).

/sys/fs/cgroup                         depth=0  active=true  (controller listed in cgroup.subtree_control)
/sys/fs/cgroup/apps                    depth=1  active=true  (controller NOT listed in cgroup.subtree_control)
/sys/fs/cgroup/apps/uid_10000          depth=2  active=false (controller NOT listed in cgroup.subtree_control)
/sys/fs/cgroup/apps/uid_10000/pid_100  depth=3  active=false (controller NOT listed in cgroup.subtree_control)

[1] https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html#enabling-and-disabling

Bug: 346584259
Test: Cuttlefish with memcg v2
Change-Id: I62109ea935261c51fc30b2054c4d28d0360f7985
2024-06-18 15:50:21 +00:00
T.J. Mercier
54bfde03e1 libprocessgroup: Remove unused includes; add missing ones
No functional changes.

Bug: 346584259
Test: m
Change-Id: I68fa51f86b6baaa34fb2cdfdc16a4d1ff61e1e5f
2024-06-11 18:24:34 +00:00
T.J. Mercier
10826481ba libprocessgroup: Don't delegate to default constructor
Manually calling a defaulted default constructor from a another
constructor is superfluous, and can increase code size if the default
constructor is not otherwise used. There's nothing to delegate, so
remove the call.

Bug: 346584259
Test: m
Change-Id: Ia16aa041fdee7434587cf90645d7f95cba4e0d10
2024-06-11 18:24:23 +00:00
T.J. Mercier
df67107ac4 libprocessgroup: Use default member initializers
... instead of direct initialization in the default constructor
implementation. This allows us to just explicitly default the
constructor and provide no implementation.

Initialize class variables in the header and remove no-op constructor
to simplify code.

Bug: 346584259
Test: m
Change-Id: Iba57f5cfbf8e4d5d18ce178d39f8bcd2d76c8aaa
2024-06-11 18:23:58 +00:00
Kiyoung Kim
110308e5ab Merge "Remove VNDK definition(s)" into main 2024-05-23 00:38:19 +00:00
Treehugger Robot
b45c8ad05b Merge changes Ie74b9c27,If2224475 into main
* changes:
  libprocessgroup: Check validity of uid and pid arguments for createProcessGroup
  Revert "libprocessgroup: Check validity of uid and pid arguments"
2024-04-18 19:09:18 +00:00
T.J. Mercier
7d9d171e4e libprocessgroup: Check validity of uid and pid arguments for createProcessGroup
killProcessGroup already checks for validity of the uid and pid input
arguments. Also add this checking to createProcessGroup.

Bug: 333261173
Change-Id: Ie74b9c2716978cb5eb434af12e27945e29af876e
2024-04-18 16:18:22 +00:00
T.J. Mercier
29e30f25b4 Revert "libprocessgroup: Check validity of uid and pid arguments"
This reverts commit 5a3c3f7ccf.

Don't SIGABRT for invalid requests.

Bug: 333261173
Change-Id: If22244753b43529ed17c315b3732af371827e774
2024-04-18 16:17:48 +00:00
T.J. Mercier
1cfa2c4111 Add build flag to split the cgroup v2 hierarchy into apps/system
This flag adds "apps" and "system" cgroups underneath the v2 hierarchy
root. Cgroups with UIDs < 10000 (AID_APP_START) will be placed
under "system" and others will be placed under "apps". UIDs under 10000
are reserved for core Android subsystems. This allows us to
apply different cgroup controls collectively to system processes and
normal applications.

Bug: 327480673
Change-Id: I40837dee27a59691f81fef48e66a86c5eacda892
2024-04-08 21:15:48 +00:00
T.J. Mercier
f8901767e6 Add build flag to force memcg to the v2 cgroup hierarchy
This flag prevents memcg from being mounted as a v1 hierarchy, even if
cgroups.json specifies it should be mounted as v1. It will activate
memcg in the v2 hierarchy even if cgroups.json does not specify that it
should be activated in the v2 hierarchy.

The cgroup_disable=memory kernel command line argument will still
prevent memcg from being activated, as this forced memcg controller
is marked as optional.

Bug: 327480673
Change-Id: Iad2491dd0c1576156ee2346928d041d85af890f0
2024-04-08 21:15:48 +00:00
T.J. Mercier
d1e048f956 Use ConvertUid{Pid}ToPath for all path generation
Consolidate into a single implementation.

Test: m
Change-Id: I0fc52db2d4b2973a74bad24c0a5f77384a559cee
2024-04-08 21:15:48 +00:00
T.J. Mercier
44eb705480 Fix unused params and remove unneeded cflags
We already get -Wall and -Werror from the build system, and we do not
want/need -Wexit-time-destructors since it prevents local statics with
non-trivial destructors.

Test: m
Change-Id: I8283bf223404d6c253861d3888c1b720c099386e
2024-04-08 21:15:48 +00:00
Kiyoung Kim
ad8cf52c4c Remove VNDK definition(s)
As of VNDK deprecation, any libraries that defines vndk is no longer
valid anymore. This change removes all VNDK definition(s) from modules
which was VNDK. Any former VNDK-SP libraries will be marked as double-loadable,
so it can keep be able to be referenced by LLNDK libraries.

Bug: 328994089
Test: AOSP CF build succeeded
Change-Id: I1662f16e5e446bb28167b0bb278cd63997267d2a
2024-03-15 08:19:44 +00:00
Treehugger Robot
ff239bb0fc Merge "Add test mapping" into main 2024-02-08 18:30:25 +00:00
T.J. Mercier
c902df07b0 Add test mapping
Bug: 315371696
Change-Id: If8448e703cc5accde11bcdccf7585ef6779f59b0
2024-02-08 16:57:43 +00:00
T.J. Mercier
96b0065ebf Merge changes I6e95870e,Ibcef6b73,I302ce3c2 into main
* changes:
  libprocessgroup: Use pid_t consistently for TIDs
  libprocessgroup: Use pid_t consistently for PIDs
  libprocessgroup: Use uid_t consistently for UIDs
2024-01-29 21:28:12 +00:00
Treehugger Robot
761db93167 Merge changes from topic "b314861914" into main
* changes:
  Revert "Migrate the blkio controller to the v2 cgroup hierarchy"
  Revert "task_profiles.json: Set io.prio.class"
2024-01-26 15:38:44 +00:00
Randall Huang
d0ce4ca33c Revert "Migrate the blkio controller to the v2 cgroup hierarchy"
This reverts commit f99ca8aeb1.

Reason for revert: b/2768906

Change-Id: I9ce259a2c96e9f8dd8c7598204c35922b56f7a0a
2024-01-26 03:54:47 +00:00
Randall Huang
9e38fe5299 Revert "task_profiles.json: Set io.prio.class"
This reverts commit 9bba87244d.

Reason for revert: b/314861914

Change-Id: I566c4fa98e4d1bd8701086c2b5e34802ee0a89fb
2024-01-26 03:51:54 +00:00
T.J. Mercier
1c007996b3 libprocessgroup: Use pid_t consistently for TIDs
Test: m
Change-Id: I6e95870e6c5855bfe03be3be8f7a8884147bc15d
2024-01-25 16:35:30 +00:00
T.J. Mercier
d6fb2259f6 libprocessgroup: Use pid_t consistently for PIDs
Test: m
Change-Id: Ibcef6b73a8fd3088c88b822a6b33d005595488b2
2024-01-24 23:42:39 +00:00
T.J. Mercier
a757eb856e libprocessgroup: Use uid_t consistently for UIDs
Found with -Wsign-conversion.

Test: m
Change-Id: I302ce3c2ffdd533fe45e98c5c7edbb442db46ae4
2024-01-24 22:48:25 +00:00
T.J. Mercier
a103630b5c libprocessgroup: Use cgroup.kill
By using cgroup.kill we don't need to read cgroup.procs at all for
SIGKILLs, which is more efficient and should help reduce CPU contention
and cgroup lock contention. Fallback to cgroup.procs if we encounter an
error trying to use cgroup.kill, but if cgroup.kill fails it's likely
that cgroup.procs will too.

Bug: 239829790
Test: atest StagedRollbackTest:com.android.tests.rollback.host.StagedRollbackTest#testNativeWatchdogTriggersRebootlessApexRollback
Change-Id: I9da67efd00af49b7b4b502fb742c1095d5c7b9e9
2023-12-14 21:52:13 +00:00
T.J. Mercier
4928b6ef57 Reapply "libprocessgroup: Poll on cgroup.events"
This reverts commit a72332f953.

This change was originally reverted due to a bug in the child commit
which caused process group kills not to occur when using cgroup.kill.
Now that has been fixed, bring back this change with the fixed child.

Bug: 301871933
Change-Id: Ia6c74d9b67a8c88aec4812ac4655646934e0d189
2023-12-14 21:49:14 +00:00
T.J. Mercier
b73d41c50b Merge changes from topic "revert-2819069-LYZVLDOFQA" into main
* changes:
  Revert "libprocessgroup: Poll on cgroup.events"
  Revert "libprocessgroup: Use cgroup.kill"
2023-12-08 01:50:41 +00:00
Android Culprit Assistant
a72332f953 Revert "libprocessgroup: Poll on cgroup.events"
This revert was created by Android Culprit Assistant. The culprit was identified in the following culprit search session (http://go/aca-get/91da3c52-9b76-498b-bdbd-a9de7d7ff53b).

Change-Id: I996c595bee9acc15aedaf0a912f67fa027f33cd0
2023-12-08 01:48:25 +00:00
Android Culprit Assistant
c0ce178640 Revert "libprocessgroup: Use cgroup.kill"
This revert was created by Android Culprit Assistant. The culprit was identified in the following culprit search session (http://go/aca-get/91da3c52-9b76-498b-bdbd-a9de7d7ff53b).

Change-Id: I459265b9c9117d6006c1223947a202505d24c08f
2023-12-08 01:48:30 +00:00
Treehugger Robot
1b44b8c6d6 Merge changes from topic "cgroup.events" into main
* changes:
  libprocessgroup: Use cgroup.kill
  libprocessgroup: Poll on cgroup.events
2023-12-07 19:40:11 +00:00
T.J. Mercier
38b8bb1e4a libprocessgroup: Use cgroup.kill
By using cgroup.kill we don't need to read cgroup.procs at all for
SIGKILLs, which is more efficient and should help reduce CPU contention
and cgroup lock contention. Fallback to cgroup.procs if we encounter an
error trying to use cgroup.kill, but if cgroup.kill fails it's likely
that cgroup.procs will too.

Bug: 239829790
Change-Id: I44706faccfb7c4611b512a3642b913f06d30c1dc
2023-12-07 00:12:07 +00:00
T.J. Mercier
3b5bb3a364 libprocessgroup: Poll on cgroup.events
In killProcessGroup we currently read cgroup.procs to find processes to
kill, send them kill signals until cgroup.procs is empty, then remove
the cgroup directory. The cgroup cannot be removed until all processes
are dead, otherwise we'll get an EBUSY error from the kernel.

There is a race in the kernel where cgroup.procs can read empty even
though the cgroup is pinned by processes which are still exiting, and
can't be removed yet. [1]

Let's use the populated field of cgroup.events instead of an empty
cgroup.procs file to determine when the cgroup is removable. In
addition to functioning like we expect, this is more efficient because
we can poll on cgroup.events instead of retrying kills and rereading
cgroup.procs every 5ms which should help reduce CPU contention and
cgroup lock contention.

It's still possible that it takes longer for a cgroup to become
unpopulated than our timeout allows, in which case we will fail to
remove the cgroup and leak kernel memory. But this change should help
reduce the probability of that happening.

[1] https://lore.kernel.org/all/CABdmKX3SOXpcK85a7cx3iXrwUj=i1yXqEz9i9zNkx8mB=ZXQ8A@mail.gmail.com/

Bug: 301871933
Change-Id: If7dcfb331f47e06994c9ac85ed08bbcce18cdad7
2023-12-07 00:12:00 +00:00