Commit graph

143 commits

Author SHA1 Message Date
Justin Yun
feef4d390f Add product_available to product available modules
vendor_available modules were available to product modules.
However, not all vendor_available modules are required to be
available to product modules. Some modules want to be available only
to product modules but not vendor modules.

To cover the requirement, we separate product_available from
vendor_available.
vendor_available will not provide product available module.

Rename libcutils/include_vndk to libcutils/include_outside_system as
it provides the headers to the modules outside the system partition
including /product.

Bug: 150902910
Test: build
Change-Id: I791b5a6a1dc99442065debfce6fa0f54a335fcea
2020-12-04 09:59:20 +09:00
Marco Ballesio
1414a0d4d8 libprocessgroup: move freezer to uid/pid hierarchy
Migrate the freezer controller as an attribute for the uid/pid hierarchy

Bug: 168907513
Test: manually verified that the freezer behavior was as expected after
applying the enablers in ActivityManager

Signed-off-by: Marco Ballesio <balejs@google.com>
Change-Id: Ica2c4bfd20190fb2f2dc0a530eb47e1a8427c522
2020-12-03 22:00:33 +00:00
Suren Baghdasaryan
756a60459c libprocessgroup: Change per-API level task profiles to override the diffs
Current per-API level task profiles replace the latest task profiles
rather than overriding the diffs. This poses an issue when a new
feature is added which is applicable to older devices as well we
have to change all per-API level profiles. Change the per-API task
profile support to load the latest task profiles first and then override
with per-API task profiles, similar to how vendor task profiles override
system task profiles. This minimizes the changes we need to do to the
per-API level task profiles going forward and is more consistent with
how vendor task profiles work.

Bug: 170507876
Test: boot with per-API task profiles
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: I08cc4b374cede7363cf96a30ac96971d49bb7847
2020-12-03 19:39:31 +00:00
Wei Wang
673b6d47bc Merge changes I13c9660a,I41745e7b,I0e6722b8
* changes:
  init.rc: correct the obsolete comment
  Add system-background cpu group
  init.rc: create camera-deamon stune cgroup
2020-12-03 18:57:25 +00:00
Marco Ballesio
4d45b59f80 libprocessgroup: uid/pid hierarchy for cgroup v2
Enable the uid/pid hierarchy for all groups when using cgroup v2. Mount
the hierarchy under the cgroup v2 root. Make sure that all files under
the hierarchy are accessible by the system user.

Test: booted the device, tested the freezer cgroup, manually verified
the working of the freezer from logs and by checking statuses of
processes.

Bug: 168907513
Test: Booted the device, verified no regressions on process group access
Change-Id: I73f3e767d377902af6e12facb503b9136fb39e08
2020-12-02 09:51:42 -08:00
Wei Wang
ab87979a00 Add system-background cpu group
Add system-background cgroup hierarchy for uclamp and cpu bandwidth
tuning.

Bug: 170507876
Bug: 171740453
Test: boot and check cgroup
Change-Id: I41745e7b3ac5c1d7ea7dd77f5db39c6895047446
2020-12-01 19:46:02 -08:00
Suren Baghdasaryan
35221b5338 libprocessgroup: Support per-API level task profiles
When task profiles changes happen, devices released under older API
levels might have to use the same profiles as before. This might be
due to for missing kernel features or some other reasons. Add support
for per-API task profiles to accommodate this scenario. With this
mechanism when ro.product.first_api_level is non-empty, the system
looks for /system/etc/profiles/task_profiles_<api level>.json file
and uses it if it exists. If ro.product.first_api_level is not defined
or per-API task profiles file does not exist the system falls back to
the default /system/etc/profiles/task_profiles.json file.
As before, these task profiles can be competely overwritten using
/vendor/etc/task_profiles.json if needed.

Bug: 172066799
Test: boot with per-API task profiles
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: I1671b341b3a0fb5e99d0b0788315c61088326b09
2020-11-23 22:08:41 +00:00
Wei Wang
b90e23efc7 task_profiles.json: use system subgroup for NormalPerformance
Put tasks into a subgroup so that we can set things up e.g. soft cpu
bandwidth and/or uclamp.

Bug: 170507876
Bug: 171740453
Test: boot and check cgroup
Change-Id: Iaeb081bc4f214aa23eb281e0c28a81ea581bb4d1
2020-11-20 10:54:55 -08:00
Rick Yiu
b4a3f080e6 Merge "libprocessgroup: Support write to file feature" 2020-11-04 04:54:42 +00:00
Rick Yiu
bc1ad9671a libprocessgroup: Support write to file feature
There may be some use cases that it needs to write string to a
file. This patch support write "Value" to "FilePath", where
both parameters could use special string "<uid>" and "<pid>" to
represent actual uid and pid.

Bug: 170507963
Test: function works
Change-Id: I543846f523518a9bcb3dd1b3437163a1b3157d95
2020-11-03 20:56:48 +08:00
Yifan Hong
92836b2e95 Merge changes from topic "toybox_vendor_ramdisk"
* changes:
  Add shell_and_utilities_vendor_ramdisk
  Make libraries {vendor_,}ramdisk_available.
2020-11-02 18:33:33 +00:00
Rick Yiu
32809d8231 Merge changes from topic "aosp_use_uclamp"
* changes:
  init: Add cpu controller hierarchy to use utilclamp controller
  libprocessgroup: Replace stune with utilclamp profiles
2020-10-30 07:12:32 +00:00
Suren Baghdasaryan
1b53c2496d libprocessgroup: Replace stune with utilclamp profiles
Replace schedtune out-of-tree controller's usage in the performance
profiles with utilclamp controller. Stop mounting schedtune controller.

Bug: 170507876
Test: cpuctl groups worked
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: Ib7fa6c902581398587c75414845c2ff6c8bdb005
2020-10-29 16:21:09 +00:00
Yifan Hong
67c71a1b4f libprocessgroup_headers: make vendor_ramdisk_available.
Test: pass
Bug: 156098440
Change-Id: I4d66c3e0aa2bbc972d2d6fe16dec95a45bfb2889
2020-10-28 10:57:51 -07:00
Yifan Hong
89d1c19ca0 Make libraries {vendor_,}ramdisk_available.
Test: pass
Bug: 156098440
Change-Id: I07bb2fdc5113a5113b648795a1f60c09f20e12f1
2020-10-28 10:57:51 -07:00
Colin Cross
6a2b16693c Make the connection between implementation and llndk_library explicit
Instead of assuming a module with the .llndk suffix exists, add an
llndk_stubs property to every cc_library module that has a
corresponding llndk_library.  Also rename the llndk_library to have
an explicit .llndk suffix.

Bug: 170784825
Test: no changes to build.ninja (excluding comments) or Android-${TARGET_PRODUCT}.mk
Change-Id: Ifba79a1ae64a67a9d7393dac2fb012cd8af8e149
2020-10-19 13:38:05 -07:00
Dan Shi
67b7dd570f Remove vts10 related configs
Bug: 169582597
Test: build
Change-Id: I38e1e0f8e32b86ab14b905d040c1c62245a1a9e3
2020-10-06 13:52:44 -07:00
Marco Ballesio
43050baa7f libprocessgroup: json prototype for cgroups v2
cgroups v2 support introduces new fields in the json format. Adapt the
proto file accordingly

Bug: 154548692
Test: atest libprocessgroup_proto_test --
Change-Id: I40f8757a8f4e6a0b839caa7faa976dfebf3aac98
2020-08-20 15:53:48 -07:00
Marco Ballesio
1c755e22c8 libprocessgroup: switch freezer to cgroup v2
remove cgroup v1 freezer entries from init.rc, add a new cgroup v2
controller and modify plists to properly interact with it.

Bug: 154548692
Test: manually verified the the cgroup v1 freezer controller isn't
created and a new controller for cgroup v2 is created under the correct
sysfs directory.

Change-Id: I1b811300ade486f88fdbd157255a7f37750cc54d
2020-08-20 15:11:41 -07:00
Marco Ballesio
76eca5b4c1 freezer: allow dynamic changes to freezer.state
create new profiles to allowing thawing and freezing back the freezer
cgroup

Bug: 151225245
Test: Manually verified that using the SetTaskProfiles method on the
profiles thaws and freezes back the freezer cgroup.

Change-Id: I7f3e193ebe79b49c1f6ac52b6138ff4ec26fc570
2020-08-19 13:18:28 -07:00
Suren Baghdasaryan
81b9f0b763 libprocessgroup: Allow vendor profile attributes to override system ones
In the current implementation vendor profile attributes do not override
system ones and instead generate a warning. Fix that by overriding existing
attribute if a new definition is found.

Bug: 160318642
Test: add vendor attributes and confirm no warnings
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: I71a2ee4d4b3c585e7c9a01b791e973390d409cbc
2020-07-01 20:44:24 +00:00
Marco Ballesio
f16f9417b0 libprocessgroup: support for cgroup v2 hierarchy
for a first implementation the cgroup v2 freezer controller will be used in a
way similar to cgroup v1, that is a single child group will hold all frozen
processes. Some adjustments are needed for the new structure.

- Add support for cgroup v2 syntax under procfs.
- Separate creation of a directory with ownership/mode changes to allow changes
    after mounting the cgroup kernfs root.
- Allow the creation of sub-groups under a cgroup v2 hierarchy.

Bug: 154548692
Test: manually verified that a proper cgroup v2 hierarchy is created and
accessible

Change-Id: I9af59e8214acaead3f520a94c95e75394c0df948
2020-06-10 09:14:00 -07:00
Yifan Hong
2572f23af8 vts_processgroup_validate_test: make deps static
Test: pass
Fixes: 155959743
Change-Id: I730526955a40ae00a97f487e423a00c743f75d53
2020-05-07 12:41:45 -07:00
Treehugger Robot
f9273c2aa3 Merge "processgroup: Set min_sdk_version" 2020-05-04 15:52:39 +00:00
Suren Baghdasaryan
8c604e8615 task_profiles.json: add a new task profile used by camera HAL
Add new CameraServicePerformance task profile used by camera HAL.

Bug: 155419956
Test: confirm profile applies correctly
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: I21cf942eca279a5ad4c1ff75c735560954f4ebc1
2020-05-01 01:05:42 +00:00
Dan Shi
63a07aafcf Add vts_processgroup_validate_test to vts suite
Bug: 154727600
Test: atest vts_processgroup_validate_test
Change-Id: I53bd4f9fd097878deaa77159feb2d48f66c464d1
Merged-In: I53bd4f9fd097878deaa77159feb2d48f66c464d1
2020-04-28 09:58:14 -07:00
Jooyung Han
4f55f3efd3 processgroup: Set min_sdk_version
Modules contributing mainline modules (APK/APEX) should set
min_sdk_version as well as apex_available.

For now setting min_sdk_version doesn't change build outputs.
But build-time checks will be added soon.

Bug: 152655956
Test: m
Change-Id: Idaa27ce24cc13d13145eaef85a08b9033922c7bc
2020-04-23 23:53:19 +09:00
Jiyong Park
e3d371e319 Set apex_available property
The marked library(ies) were available to the APEXes via the
hand-written whitelist in build/soong/apex/apex.go. Trying to remove the
whitelist by adding apex_available property to the Android.bp of the
libraries.

Bug: 150999716
Test: m
Change-Id: Id08058f3105463558c6c82298344a33af0efb2d3
2020-04-08 22:37:42 +09:00
Dan Willemsen
a8f188f011 Convert vts configs to Android.bp
Test: treehugger
Change-Id: Ibe8ed03555ac78ee38be6511eb4169cddfcd3555
2020-03-07 21:21:33 -08:00
Suren Baghdasaryan
911109c414 libprocessgroup: Prevent SetProcessProfiles from using cached fd
Because we cache file descriptors associated with cgroup "tasks" file it
should not be used with SetProcessProfiles API which operates on entire
processes rather than tasks. Change SetProcessProfiles API to prevent
cache fd usage, modify ExecuteForProcess to not attempt to use cached
fd. Also fix unconditional calls to EnableResourceCaching from
ExecuteForTask which should be called only when SetTaskProfiles is used
with use_fd_cache set to true.

Bug: 149524788
Change-Id: I880efaf8217a4dd7ccfbb4fb167b2295cefc057a
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2020-02-14 01:42:11 +00:00
Quentin Perret
20b2f1e0ab task_profiles.json: Fix uclamp attribute
task_profiles.json currently uses attributes of a defunct version of
uclamp, which was used for testing.

Let's use the attributes that actually got merged upstream instead.

Bug: 143710295
Change-Id: Ic6a14f52e14efeefc91f6e6bf580c15e2eded82e
Signed-off-by: Quentin Perret <qperret@google.com>
2020-02-04 13:10:31 +00:00
Suren Baghdasaryan
cee468fb79 Revive ACgroupController_getFlags LLNDK function to detect missing cgroups
ACgroupController_getFlags was reverted due to LLNDK breakage, however
it allows detection of cgroups that failed to mount in a more efficient
way. Revive the function as a weakly linked symbol to allow for it to
be missing in case older LLNDK library is being used with the new
system software. This effectively reverts the commit
aa1d54f0cc "Remove ACgroupController_getFlags to fix API breakage"'
except it declares ACgroupController_getFlags function as weak and
targets it for API level 30. If LLNKD library does not contain
ACgroupController_getFlags the behavior falls back to the current
way of identifying cgroups that failed to mount.

Test: build and verify correct operation with a missing cgroup
Change-Id: I9158ef53aba97972d41d71dd3396ac43796a7004
Merged-In: I9158ef53aba97972d41d71dd3396ac43796a7004
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2020-01-29 17:24:06 +00:00
Suren Baghdasaryan
8438595f21 libprocessgroup: Prevent aggregate profiles from referencing stale ones
Currently when vendor overrides a profile the profile object is being
replaced with a new one. However the old profile might have been
referenced by an aggregate profile and with such profile replacement
the aggregate profile is left referencing a stale object. Fix this by
replacing the content of the old profile with the content from the new
one instead of replacing the object itself.

Bug: 148311066
Test: override profiles referenced in aggregate profile and verify
Test: correct replacement
Change-Id: Iabddbf3580455e5263fedad6665cf52fb323e50a
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2020-01-27 21:07:27 +00:00
Quentin Perret
64811b7b13 libprocessgroup: ensure schedboost_enabled is true with uclamp
In the current state, schedboost_enabled() is true if and only if
schedtune is in use. As a result, all tests conditioned by
schedboost_enabled() will be skipped on devices using uclamp since it is
and extension of the CPU controller.

Fix this by making schedboost_enabled() return true if either schedtune
or the CPU controller is enabled.

Bug: 44953631
Change-Id: Idaadf252c9cf411a176180ab8988d559ca8a1332
Signed-off-by: Quentin Perret <qperret@google.com>
2020-01-27 11:04:03 +00:00
Tom Cherry
d89ed132a0 init: always kill oneshot services' process groups.
~2007 a change was added that would allow oneshot services to
daemonize by not killing their process group.  This was a hack at the
time, and should certainly not be needed now.  I've resisted removing
the behavior however, as it hadn't caused any issues.

Recently, it was detected that the cgroups that these processes belong
to, would exist forever and therefore leak memory.  Instead of simply
removing the cgroups when empty, this provides a good opportunity to
do the right thing and fix this behavior once and for all.

The new (correct) behavior only happens for devices with vendor images
built for Android R or later.  Init will log a warning to dmesg when
it detects this difference in behavior has occurred.

Bug: 144545923
Test: boot CF/Coral and see no difference in behavior.
Test: boot CF with a service that daemonizes and see the warning.
Change-Id: I333a2e25a541ec0114ac50ab8ae7f1ea3f055447
2019-11-19 15:13:17 -08:00
Marco Ballesio
726a68cb40 Add support for freezer cgroup
Adds the freezer cgroup to process groups

Change-Id: Ib7a8dbe776ff156ff3827b9a659365384f3e6ac8
Bug: 143308662
Test: manual - frozen processes aren't scheduled for execution until
unfrozen
2019-11-13 20:21:07 +00:00
Haibo Huang
cf8a5b0e0e Fix build with new googletest
The new googletest requires prefix to be non-empty.

Exempt-From-Owner-Approval: fix test
Change-Id: Ic039cb657b455919e429a3ec2107893b1734e8a1
2019-11-10 04:08:25 +00:00
Wei Wang
ee2f260223 sched_policy: add get_cpuset/sched_policy_profile_name
Expose API to return name of task profile for cpuset/sched policy so
that libprocessgroup clients using SetTaskProfiles directly don't have
to maintain the mapping. This reduces the risk of inconsistency and saves
memory.

Bug: 139521784
Test: atest libcutils_test:SchedPolicy
Change-Id: I414312a038613913fb6a827bdcefceb3dec21264
2019-10-14 20:03:06 -07:00
Rick Yiu
0b211fa8b3 libprocessgroup: add support to set aggregate profiles
To support setting multiple profiles with one call. The json format
is as below example.

  "AggregateProfiles": [
    ...
    {
      "Name": "SCHED_SP_BACKGROUND",
      "Profiles": [ "HighEnergySaving", "LowIoPriority", "TimerSlackHigh" ]
    },
    ...
  }

Bug: 139521784
Test: SetProfile works as expected
Change-Id: Ibe14ed57d5169cafcbcbbdb054df3ed171a2f6a2
2019-09-30 08:35:28 +00:00
Tom Cherry
73f5b65ed4 Add surenb@ to libprocessgroup OWNERS
Test: n/a

Change-Id: Ia671384e4202f618d0ae08bc33f0ca8bbd9e53c1
2019-09-17 08:50:04 -07:00
Wei Wang
73e355409a Let blkio cgroup follow sched_policy
This reverts commit e8678cf883.

With b/131214885 resolved, we should reland the change for bg sched group.
If a thread explicitly calls set_sched_policy to set a thread to background, it should not be latency sensitive.

This would help background I/O impacting foreground I/O e.g. b/65727988

Test: build and boot
Bug: 140209629
Change-Id: I218db084fb733cad57af8a5eae926818a6a2cdb8
2019-08-29 03:51:32 +00:00
Suren Baghdasaryan
25eb1bfadf Fix IsUsable to check for each controller separately
CgroupController::IsUsable is using a global static variable to store the
existence of the controller. That means the first controller existence
check would affect all other controllers. Fix this by making this variable
to be a member of CgroupController class so that each controller can check
for its existence independently of other controllers.

Fixes: aa1d54f0cc ("Remove ACgroupController_getFlags to fix API breakage")
Bug: 136020193
Test: adb shell cat /proc/$pid/task/*/cgroup" prints "cpuset:/top-app"
Test: for new launched activity process
Change-Id: I4741a9126ea494122d5b2b1a0c4d7252bff6025c
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-06-26 11:35:11 -07:00
Riddle Hsu
a6abd821d5 Allow to drop existing fd cache of cgroup path
A process can give up the permission to set cgroup. If we still
keep the fd that was cached before losing the permission, when
the process sets scheduling group, it will write to the cached
fd without checking if is accessible and lead to sepolicy denied.

Bug: 123043091
Test: Build and boot.
Test: A new process from zygote set cgroup and drop fd cache, and
      then specializes to app domain. There is no sepolicy denied
      when the process creates new thread.
      (android::thread_data_t::trampoline)

Change-Id: I285ee91424ea965ea9c670fc0f6662948e3e2ce5
2019-06-18 15:53:53 +08:00
Treehugger Robot
ad6f656be2 Merge "Remove ACgroupController_getFlags to fix API breakage" 2019-06-18 01:26:31 +00:00
Steven Moreland
b495b0d403 libprocessgroup: move native_bridge_support
To avoid merge conflict.

Bug: 135293492
Bug: 135298384
Test: N/A
Change-Id: I034b989c7e0f8a477b29ef7ca40bba8f2dc929e5
2019-06-17 12:48:06 -07:00
Suren Baghdasaryan
338260a467 Remove ACgroupController_getFlags to fix API breakage
Since ACgroupController_getFlags was introduced after LLNDK freeze it
causes media crashes due to missing symbol. Remove the new function and
re-implement cgroup controller detection to not require flags field but
instead check for its existence on the first access.

Bug: 135049992
Test: libcutils_test with and without CONFIG_CPUSETS enabled
Change-Id: I0220d6a926884dc22a7424d7d0a980c379c6f4eb
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-06-17 16:46:23 +00:00
mtk16036
53f79e6861 race condition in libprocessgroup
while enable fdsan (file descriptor sanitizer),
fdsan report use-after-close error after boot complete (sedom).

Because, in SetCgroupAction::EnableResourceCaching() currently has a data race against all the
use fd_ functions like SetCgroupAction::ExecuteForProcess(uid_t uid, pid_t pid) etc.

ThreadA                                     | ThreadB
-------------------------------------------------------------------------------------------------
in SetCgroupAction::EnableResourceCaching() | in SetCgroupAction::ExecuteForProcess(...)
-------------------------------------------------------------------------------------------------
                                            | in SetCgroupAction::AddTidToCgroup(int tid, int fd)
-------------------------------------------------------------------------------------------------
fd_ = std::move(fd); /*modified fd_ value*/ |
-------------------------------------------------------------------------------------------------
                                            | write(fd)  /* crash here, fd is closed by ThreadA*/
-------------------------------------------------------------------------------------------------

So, add mutex lock to protect fd_ data race.

Bug: 134120826
Test: auto test, run the adb reboot test 100 times and no fdsan error report on libprocessgroup
Change-Id: Iccf2f705e030f79324f1164509e715dc5be825de
2019-06-11 10:52:25 -07:00
Suren Baghdasaryan
fa7a05fe5f libprocessgroup: add flags to indicate when a controller failed to mount
Controllers listed in cgroups.json file might fail to mount if kernel is
not configured to support them. We need a way to indicate whether a
controller was successfully mounted and is usable to avoid logging errors
and warnings when a controller that failed to mount is being used. Add
flags bitmask to cgrouprc controller descriptor and use a bit to indicate
that controller is successfully mounted. Modify cpusets_enabled() and
schedboost_enabled() functions to use this bit and report the actual
availability of the controller.

Bug: 124080437
Test: libcutils_test with cpuset and schedtune controllers disabled
Change-Id: I770cc39fe50465146e3205aacf77dc3c56923c5d
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-05-21 10:03:21 -07:00
dimitry
49c1f6efea Enable native_bridge_support for libprocessgroup
Android build system added support for building translated binaries
used on natively bridged targets (arm on x86 for example).

However in order to avoid building unnecessary binaries and libraries
for such architectures most modules do not support native bridge by default.

All needed modules have to explicitly indicate if they may be used as part
of translated binary build.

This change enabled native bridge support for libprocessgroup modules
needed by libutils greylisted library (available for apps targeting
Android version < N).

Bug: http://b/77159578
Test: make
Change-Id: I8d6f33e95e9f7424f5fa12f6fbabafa1d6c37413
2019-05-16 14:19:09 +02:00
Vic Yang
d167cb2958 Static link libjsoncpp in libprocessgroup
The majority of libjsoncpp use is due to libprocessgroup.  Static
linking reduces relocations required at runtime as well as compacts the
pages dirtied by relocations.  On a 32-bit system, where this matters
the most, this reduces 8KB of dirty pages per libprocessgroup load.
Overall, the dirty page reduction on 32-bit cuttlefish is ~500KB.

Bug: 132275636
Test: Boot on cuttlefish.  Calculate total amount of dirty memory used
      for libprocessgroup and libjsoncpp.
Change-Id: I1135bb45a3764f96a4a3a47c98fbcdee3913c988
(cherry picked from commit b562e68503)
2019-05-08 20:29:44 -07:00