Commit graph

285 commits

Author SHA1 Message Date
Inseob Kim
005596742b Merge "libprocessgroup: fix boot time performance regression" am: e89ee18b9b am: 12f447e607 am: ab4821d3f2
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2467504

Change-Id: Ic391acf818e48a074984186c208085b7426cb0a7
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-03-03 19:39:18 +00:00
Suren Baghdasaryan
4f7cc8c345 libprocessgroup: fix boot time performance regression
The way processes are accounted in DoKillProcessGroupOnce has been
changed recently, which affects retries in KillProcessGroup. More specifically, initialPid was not counted before and would not
cause a retry with 5ms sleep.
Restore previous behavior to avoid boot time regressions.

Bug: 271198843
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: Ibc1bdd855898688a4a03806671e6ac31570aedf9
2023-03-03 00:11:13 +00:00
Krzysztof Kosiński
20d6ea1482 Merge "Fix invalid uses of PLOG." am: 0f90ba64bd am: 0cc793ef16 am: eea6ab5f87
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2462673

Change-Id: I959b195fd244d49fea64f1faf55714fa2bfef37e
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-03-02 02:39:15 +00:00
Krzysztof Kosiński
0f90ba64bd Merge "Fix invalid uses of PLOG." 2023-03-02 00:52:20 +00:00
Krzysztof Kosiński
0310ec4b55 Fix invalid uses of PLOG.
PLOG reports the value of errno. These four PLOG statements are
after functions that are not syscalls, leading to confusing logs
such as "Failed to apply Foo task profile: Success".

Bug: 271196526
Test: N/A
Change-Id: Iede5274d1ceebabec8432527112291ba63dca090
2023-03-01 04:17:57 +00:00
Suren Baghdasaryan
fb598fd2c0 Merge "Kill its process group even if the given process is already dead" am: 763593e395 am: 2038ed868b am: f38b8818e9
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2459289

Change-Id: I22ddd859726d5a33a2f4bbc8e7fd1f12ba7cc2db
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-02-28 21:46:48 +00:00
Jing Ji
304c0f1c14 Kill its process group even if the given process is already dead
So the child processes in the process group won't be orphaned
when we decide to kill the process group of a given process but
find it's already dead.

Bug: 266633286
Test: atest MicrodroidDemoApp
Change-Id: Ib6f45b992566f0ab5cf152463c95294a306dd736
2023-02-27 22:01:34 -08:00
Bart Van Assche
7fabf57e12 Merge "libprocessgroup: Proceed if activation of an optional controller fails" am: 05c7e3c0c2 am: 850bac57b9 am: 7191e510d0
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2424613

Change-Id: I77c9be65b68b576129434a560c1a08eeac292f35
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-02-13 21:09:20 +00:00
Treehugger Robot
bbaebfc37c Merge "libprocessgroup: Rework SetupCgroup()" am: d35f56b199 am: 7e1218646c am: 5ff1e5353d
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2424612

Change-Id: I268c38efe1bef2ffe00a2df5cfd59ec022e03e2a
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-02-11 02:50:52 +00:00
Bart Van Assche
b0947e008a libprocessgroup: Proceed if activation of an optional controller fails
Not all Android kernels support all the cgroup controllers mentioned in
task_profiles.json and/or cgroups.json. Support such kernels by ignoring
certain cgroup activation failures.

Bug: 213617178
Change-Id: I90c0bd959f8a6484c4f2fbc895845e073527271e
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2023-02-10 15:02:44 -08:00
Bart Van Assche
1ec6ec4f57 libprocessgroup: Rework SetupCgroup()
Improve the readability of this function by splitting it.

This CL includes the following behavior changes:
- If changing the directory owner and/or mode fails for /sys/fs/cgroup,
  this is considered as a fatal error instead of something that should
  only fail if "Optional" has not been set.
- If mounting the v2 cgroup controller fails, this is considered as an
  error.
- Activating/mounting a cgroup controller only fails if the controller
  has not been marked as optional.

Bug: 213617178
Change-Id: If6908dfdbcb2e1c9637ab4ac8a7625f0a17dc9e0
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2023-02-10 14:18:38 -08:00
Bart Van Assche
ea625ac782 Merge "libprocessgroup: Introduce a local variable in CgroupMap::ActivateControllers()" am: d9098252c6 am: 79b8448729 am: f4c72869d9
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2424611

Change-Id: Ib54a66acb42d6ad60784acd16f9c1b93f6db42be
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-02-09 23:12:18 +00:00
Bart Van Assche
17c84b9ffb libprocessgroup: Introduce a local variable in CgroupMap::ActivateControllers()
This CL prepares for introducing an additional flag test.

Bug: 213617178
Change-Id: Ia74c1990792b5839f76498de2cac0008ed92040f
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2023-02-09 13:26:17 -08:00
Treehugger Robot
8f53906a49 Merge "Fix the cgroup v2 thread path" am: 22e18082d1 am: e2a1fda11e am: 44e70ba2cd
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2378989

Change-Id: I42e86a9b247f92b13dcb4dc7a98f230365fecbf9
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-01-10 03:24:08 +00:00
Bart Van Assche
0e8e4f87fd Fix the cgroup v2 thread path
The name for the file with thread IDs is "tasks" in the v1 hierarchy and
"cgroup.threads" in the v2 hierarchy.

References:
* https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v1/cgroups.html
* https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html

Bug: 213617178
Fixes: 82b72a5667 ("libprocessgroup: Add support for task profiles")
Change-Id: I87d67edeb12803cb83486be8f1b1b56a3f275a9d
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2023-01-09 14:40:51 -08:00
Jooyung Han
dce88493ae Merge "Revert "Migrate the blkio controller to the v2 cgroup hierarchy"" am: ddfa08b98b am: 2929e71d77 am: 9506593c41
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2378329

Change-Id: I10037b6d396270ef069e80ecc03a2b0e9a22338c
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-01-06 12:13:15 +00:00
Jooyung Han
c7a6fe684c Revert "Migrate the blkio controller to the v2 cgroup hierarchy"
Revert submission 2218645-blkio-cgroup-v2

Reason for revert: 260143932, 264620181

Reverted changes: /q/submissionid:2218645-blkio-cgroup-v2

Change-Id: I8bf1592cd5f7234f28094fe80341c37d42fa609b
2023-01-06 06:20:54 +00:00
Bart Van Assche
ac3c9a3768 Merge "Migrate the blkio controller to the v2 cgroup hierarchy" am: 515c924312 am: e5f17e6c63 am: 728ce1b08a
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2218645

Change-Id: I21d7cfa4645f6756f8bb0087f527843b67e99212
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-01-06 02:01:04 +00:00
Bart Van Assche
16350a3001 Merge "task_profiles.json: Convert tabs into spaces" am: de7851c2d3 am: cc883cfdd3 am: 30668fbd36
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2375996

Change-Id: Ice3af831549eb9feef41b6591409644a1dc42750
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-01-05 22:43:05 +00:00
Bart Van Assche
5400ae2440 Migrate the blkio controller to the v2 cgroup hierarchy
There are multiple use cases in Android for which background writes need
to be controlled via the cgroup mechanism. The cgroup mechanism can only
control background writes if both the blkio and memcg controllers are
mounted in the v2 cgroup hierarchy. Hence this patch that migrates the
blkio controller from the v1 to the v2 cgroup hierarchy.

This patch increases the TOTAL_BOOT_TIME for devices with a 4.19 kernel
(redfin) from 18.9 s to 20 s. This patch does not affect the boot time
for devices with a 5.10 or 5.15 kernel.

This patch increases the time spent in CgroupMap::ActivateControllers()
by 25 microseconds in Cuttlefish on an x86-64 CPU.
CgroupMap::ActivateControllers() is called by Service::Start().

Bug: 213617178
Test: Cuttlefish and various phones
Change-Id: I490740e1c9ee4f7bb5bb7afba721a083f952c8f2
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2023-01-05 13:07:00 -08:00
Bart Van Assche
6ad747ac2d task_profiles.json: Convert tabs into spaces
Commit 9c0fcbb0f7 ("libprocessgroup: Add I/O scheduler attributes to
task_profiles.json") accidentally introduced tabs in task_profiles.json.
Convert these tabs into spaces.

Bug: 213617178
Change-Id: I7ac59dbd40aa3da295646792e35b8275fbb97991
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2023-01-05 13:03:47 -08:00
Inseob Kim
f642317435 Merge "Don't retry kill if cgroups isn't available" am: eb3912ea73 am: 0d7762d31f am: 7f8277118c
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2352942

Change-Id: Iad7e547403621a5c33d915a579b3bfe9f28894ac
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-12-27 03:30:49 +00:00
Inseob Kim
eb3912ea73 Merge "Don't retry kill if cgroups isn't available" 2022-12-27 01:48:37 +00:00
Bart Van Assche
76498c5f67 Merge "Updating Attributes on task_profiles.json" am: 91bc6d30dd am: ab4683b3d2 am: 479f4986f9
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2365175

Change-Id: Ic6dd3706507676963c8eb4dc2f1477585f74d47a
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-12-26 02:42:12 +00:00
Bart Van Assche
91bc6d30dd Merge "Updating Attributes on task_profiles.json" 2022-12-26 01:31:14 +00:00
Carlos Galo
92153fb955 Updating Attributes on task_profiles.json
Adjusting attributes that correspond to the `blkio`(v1)/`io`(v2) controller. The migration of the `blkio` v1 controller to v2 requires renaming it to `io`, therefore we want to update the `File` field to point to `blkio` file and `FileV2` to point to `io` file.

Test: Verified with cuttlefish that this works with the `io` controller migration by cherry-picking aosp/2218645
Bug: 263269364
Bug: 213617178
Change-Id: I0aacfc6d74e3eec61ebb2ce443b04c792392aa9e
2022-12-22 00:53:00 +00:00
Carlos Galo
456a4066f8 Merge "Updating owners of libprocessgroup" am: ce318e8818 am: 9b2d8d218a am: 7a7d614d7a
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2359681

Change-Id: I495cd314fd256095440557e6507b68d4fa4a4d29
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-12-16 02:02:13 +00:00
Carlos Galo
ce318e8818 Merge "Updating owners of libprocessgroup" 2022-12-16 00:02:01 +00:00
Carlos Galo
8ceaf0c636 Updating owners of libprocessgroup
Adding tjmercier@google.com and carlosgalo@google.com, and removing
ccross@google.com, in the OWNERS file. Adding buganizer component to
OWNERS.

Bug: 262738363
Test: N/A
Change-Id: I7f8cdc513232b46eb341f3c98f64dfb1d9bd9d7a
2022-12-15 19:12:33 +00:00
Inseob Kim
110cd77b30 Don't retry kill if cgroups isn't available
It makes no sense, because there are no cgroup procs file.

Bug: 257264124
Test: atest MicrodroidBenchmarkApp
Change-Id: I4e3a118d2237afc46aa8fbcbad055afb7d56f464
2022-12-15 15:29:38 +09:00
Jiakai Zhang
70d34f01a3 Merge changes I52e778d1,I33f4d1d2
* changes:
  Rename "Dex2OatBootBackground" to "Dex2OatBackground".
  Add task profile "Dex2OatBackground".
2022-12-12 17:37:42 +00:00
Jiakai Zhang
180a51d6f3 Rename "Dex2OatBootBackground" to "Dex2OatBackground".
Bug: 261557677
Change-Id: I52e778d13cffcae4212acb05ef2bd62b827fbaf3
Test: Presubmit
Merged-In: I52e778d13cffcae4212acb05ef2bd62b827fbaf3
(cherry picked from commit 473f03bfd9)
2022-12-12 16:28:11 +00:00
Jiakai Zhang
38e9373a4b Add task profile "Dex2OatBackground".
Bug: 261557677
Test: Presubmit
Change-Id: I33f4d1d2270da82cf90a772ef52b450bcecafec2
Merged-In: I33f4d1d2270da82cf90a772ef52b450bcecafec2
(cherry picked from commit ecfbf9c6f4)
2022-12-12 16:27:15 +00:00
TreeHugger Robot
3ece2dbcb1 Merge "Rename "Dex2OatBootBackground" to "Dex2OatBackground"." 2022-12-12 16:02:08 +00:00
Treehugger Robot
4b960f5ce0 Merge "Kill services even when cgroups is disabled" am: 5c3e24816d am: 18a41fbf65 am: 916f52d74d
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2305473

Change-Id: I19814da1b59fc2d82949f992d1b03caf44d4dd11
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-12-12 03:11:13 +00:00
Inseob Kim
a049a9928b Kill services even when cgroups is disabled
process_cgroup_empty_ is used to indicate that a service is already
killed or not. If cgroup support lacks, services cannot be killed
because process_cgroup_empty_ is always true.

This change fixes it by not assigning process_cgroup_empty_ as true.
Instead, make KillProcessGroup send signals even when cgroup is
disabled. Also DoKillProcessGroupOnce() is updated so it returns a number of killed processes, excluding already dead processes. This behavior agrees with its name (DoKillProcessOnce), and it prevents regression upon missing cgroups, because kill(-pgid) will always
"succeed" so KillProcessGroup will loop even when all processes are
already dead.

Bug: 257264124
Test: boot microdroid, see services are terminated
Change-Id: I19abf19ff1b70c666cd6f12d0a12956765174aaa
2022-12-12 01:19:26 +00:00
Jiakai Zhang
473f03bfd9 Rename "Dex2OatBootBackground" to "Dex2OatBackground".
Bug: 261557677
Change-Id: I52e778d13cffcae4212acb05ef2bd62b827fbaf3
Test: Presubmit
Ignore-AOSP-First: Will cherry-pick as soon as the CL is merged.
2022-12-09 23:51:03 +00:00
Jiakai Zhang
ecfbf9c6f4 Add task profile "Dex2OatBackground".
Bug: 261557677
Test: Presubmit
Ignore-AOSP-First: Will cherry-pick as soon as the CL is merged.
Change-Id: I33f4d1d2270da82cf90a772ef52b450bcecafec2
2022-12-06 15:51:38 +00:00
Nikita Ioffe
20e253b40c Merge "init: skip cgroup/task_profiles configuration if cgroups are disabled" am: 537ab23872 am: 9bd7375aab am: e28c9185fb
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2263261

Change-Id: I0f74ba4e9b9ce878a8a7cb79d0c0c99170c8dc8b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-10-24 09:09:43 +00:00
Nikita Ioffe
c2b1654c11 init: skip cgroup/task_profiles configuration if cgroups are disabled
We are planning to remove cgroups from the Micrdroid kernel, since the
entire VM belongs exclusively to a single owner, and is in the control
of the cgroups on the host side.

This patch expoxes CgroupAvailable API from libprocessgroup, and changes
init to query the CgroupAvailable API before doing any
cgroups/task_profiles related work.

Bug: 239367015
Test: run MicrodroidDemoApp
Test: atest --test-mapping packages/modules/Virtualization:avf-presubmit
Change-Id: I82787141cd2a7f9309a4e9b24acbd92ca21c145b
2022-10-21 13:14:23 +01:00
Treehugger Robot
f0b7d34133 Merge "libprocessgroup: Improve error messages" am: 29752d276e am: 0ad558c55a am: b4048a5693
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2252953

Change-Id: I6a18fd7a93f9f7c7f198e07851be0d40032c4bfc
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-10-13 17:51:24 +00:00
Bart Van Assche
7a952617f6 libprocessgroup: Improve error messages
Change two PLOG() statements into LOG() statements since PLOG() should
only be used if errno has been set. Make it easier to find the code that
logs an error message.

Bug: 213617178
Signed-off-by: Bart Van Assche <bvanassche@google.com>
Change-Id: I73443f3adb7d7ba3fc0d39a55777f0b132529fbd
2022-10-12 13:48:52 -07:00
T.J. Mercier
c41a6348b3 Merge "Revert "Revert "libprocessgroup: Add support for SetUserProfiles""" 2022-10-05 16:11:22 +00:00
T.J. Mercier
673da5b972 Revert "Revert "libprocessgroup: Add support for SetUserProfiles""
This reverts commit aee11b0a3d.

This change was originally reverted because its only user was reverted
under b/243096961 at ag/19679188. We bring it back now with a fixed user.

Bug: 236708592
Bug: 148425913
Ignore-AOSP-First: Topic with AMS changes which is developed on git_master

Change-Id: I2a8ae0d9faabe7950b758a09870d128889be4d0a
2022-09-27 17:42:19 +00:00
Jiyong Park
eb7ec7b9e8 Annotate symbols correctly
Currently, tagging a symbol with #apex (# systemapi or # llndk) is not
required when the symbol is in a non-NDK library. However, this is
considered dangerous because such a symbol will automatically be
promoted to NDK APIs when the library is promoted to an NDK library.
When that happens, the native API council won't be able to notice the
promotion because promoting a non-NDK library into an NDK library
doesn't require an update of the map.txt file, but Android.bp only.

To prevent that, we should mandate those tags for Mainline APIs
regardless of whether the library the API belongs to is an NDK library
or not.

Upcoming changes in build/soong will enforce this. This change is to
prepare for the enforcement.

Note that this is a build-time only change. There's no behavior change
at runtime.

Bug: 184712170
Test: m
Change-Id: I769c5318e0cfd092f2f2b368f1a860065c79818f
2022-09-26 22:14:43 +09:00
Bart Van Assche
9c0fcbb0f7 libprocessgroup: Add I/O scheduler attributes to task_profiles.json
The differences between the v1 and v2 hierarchies are as follows:
* Different mountpoints. In Android the blkio v1 hierarchy has
  /dev/blkio as top directory while the v2 hierarchy has /sys/fs/cgroup
  as top directory.
* Different directory structure. In Android there are two directories in
  the v1 blkio hierarchy (. and background) while in the v2 hierarchy
  there is one subdirectory per process and per task.
* Different controller names. The name of the blkio controller in the v1
  hierarchy is "blkio" while it is "io" in the v2 hierarchy.
* In the v1 hierarchy the NormalIoPriority policy is applied at process
  creation time but that policy is not applied at process creation time
  if the blkio controller exists in the v2 hierarchy.

Prepare for migration of the blkio controller to the v2 hierarchy by
adding the blkio v2 attributes in task_profiles.json. All these
attributes have been marked as optional because:
* The "io" controller does not exist in the v1 hierarchy.
* Which attributes can be applied depends on the I/O scheduler that has
  been selected (CFQ, BFQ, ...).

This patch causes the following warnings to appear in the logs of
devices that mount the blkio controller in the v1 hierarchy:
 W libprocessgroup: Controller io is not found
 W libprocessgroup: Controller io is not found
 W libprocessgroup: Controller io is not found
 W libprocessgroup: SetAttribute: unknown attribute: CfqGroupIdle
 W libprocessgroup: SetAttribute: unknown attribute: CfqWeight
 W libprocessgroup: SetAttribute: unknown attribute: BfqWeight

This patch restores a subset of aosp/1962326 and prepares for the
migration of the blkcg controller to the cgroup v2 hierarchy.

Bug: 213617178
Change-Id: Ia7b117bc777239b416e2ac268308e634b018144d
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-08-25 14:01:01 -07:00
Bart Van Assche
f32c4ecebb libprocessgroup: Provide SetProcessProfiles() and SetTaskProfiles() alternatives
Provide alternative versions that do not force callers to create
std::string objects. This patch has the intended side-effect that all
callers that pass a {string} initializer list to the 'profiles' argument
now call an std::initializer_list<> overload instead of the const
std::vector<std::string>& overload.

Additionally, add std::function<> arguments instead of calling
ExecuteForProcess() or ExecuteForTask() directly to make it easier to
write unit tests for SetTaskProfiles() and SetProcessProfiles().

Bug: 213617178
Change-Id: Ica61e944a66a17178ee43a113b8ca082f7eb834b
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-08-19 07:06:30 -07:00
Bart Van Assche
d0b8ce2115 libprocessgroup: Make GetProfile() and GetAttribute() more efficient
Do not force callers to create an std::string object. This patch
implements the following advice from go/totw/1: "Google’s preferred
option for accepting such string parameters is through a string_view."
Use std::less<> as comparison type to prevent that std::string_view
objects have to be converted into std::string objects for lookups in
std::map<>.

Bug: 213617178
Change-Id: I08125a02220a8c003d9202a7e177be776c3b9829
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-08-19 07:06:30 -07:00
Bart Van Assche
a823bee9d3 libprocessgroup: Switch from gnu++-17 to gnu++-20
This change enables headers like <span>. Inside the <span> header file
file the following guard makes its functionality unavailable when
building with std=gnu++-17:

 #if _LIBCPP_STD_VER > 17
 [ ... ]
 #endif

Bug: 213617178
Change-Id: I5c40708ea196ab112990b5ca6fae9370b75f8752
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-08-18 12:34:21 -07:00
Bart Van Assche
ccaac4ad21 libprocessgroup: Fix a log message
Fix the function name in a log message inside CgroupSetup().

Bug: 213617178
Change-Id: I897c831f5e53093df2664e0e8ceefadf9a89369c
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-08-08 11:07:02 -07:00