Revert "libprocessgroup: Remove schedtune support"

This reverts commit 981664df08.

Reason: 4.19 isn't EOL for us, hell, 4.4 isn't even.
Change-Id: I62bbfd0aa2b2262340c40a923aa02f221787f9cb
This commit is contained in:
Nolen Johnson 2025-03-10 13:28:22 -04:00
parent a00bd859bf
commit 8d3d6cbe1b
10 changed files with 588 additions and 2 deletions

View file

@ -67,6 +67,13 @@ static void AssertPolicy(SchedPolicy expected_policy) {
}
TEST(SchedPolicy, set_sched_policy) {
if (!schedboost_enabled()) {
// schedboost_enabled() (i.e. CONFIG_CGROUP_SCHEDTUNE) is optional;
// it's only needed on devices using energy-aware scheduler.
GTEST_LOG_(INFO) << "skipping test that requires CONFIG_CGROUP_SCHEDTUNE";
return;
}
ASSERT_EQ(0, set_sched_policy(0, SP_BACKGROUND));
ASSERT_EQ(0, set_cpuset_policy(0, SP_BACKGROUND));
AssertPolicy(SP_BACKGROUND);

View file

@ -29,6 +29,14 @@ extern "C" {
*/
extern bool cpusets_enabled();
/*
* Check if Linux kernel enables SCHEDTUNE feature (only available in Android
* common kernel or Linaro LSK, not in mainline Linux as of v4.9)
*
* Return value: 1 if Linux kernel CONFIG_CGROUP_SCHEDTUNE=y; 0 otherwise.
*/
extern bool schedboost_enabled();
/* Keep in sync with THREAD_GROUP_* in frameworks/base/core/java/android/os/Process.java */
typedef enum {
SP_DEFAULT = -1,

View file

@ -20,6 +20,11 @@ package {
prebuilt_etc {
name: "cgroups.json",
src: "cgroups.json",
required: [
"cgroups_28.json",
"cgroups_29.json",
"cgroups_30.json",
],
}
prebuilt_etc {
@ -29,9 +34,50 @@ prebuilt_etc {
src: "cgroups.recovery.json",
}
prebuilt_etc {
name: "cgroups_28.json",
src: "cgroups_28.json",
sub_dir: "task_profiles",
}
prebuilt_etc {
name: "cgroups_29.json",
src: "cgroups_29.json",
sub_dir: "task_profiles",
}
prebuilt_etc {
name: "cgroups_30.json",
src: "cgroups_30.json",
sub_dir: "task_profiles",
}
prebuilt_etc {
name: "task_profiles.json",
src: "task_profiles.json",
required: [
"task_profiles_28.json",
"task_profiles_29.json",
"task_profiles_30.json",
],
}
prebuilt_etc {
name: "task_profiles_28.json",
src: "task_profiles_28.json",
sub_dir: "task_profiles",
}
prebuilt_etc {
name: "task_profiles_29.json",
src: "task_profiles_29.json",
sub_dir: "task_profiles",
}
prebuilt_etc {
name: "task_profiles_30.json",
src: "task_profiles_30.json",
sub_dir: "task_profiles",
}
cc_defaults {

View file

@ -0,0 +1,11 @@
{
"Cgroups": [
{
"Controller": "schedtune",
"Path": "/dev/stune",
"Mode": "0755",
"UID": "system",
"GID": "system"
}
]
}

View file

@ -0,0 +1,11 @@
{
"Cgroups": [
{
"Controller": "schedtune",
"Path": "/dev/stune",
"Mode": "0755",
"UID": "system",
"GID": "system"
}
]
}

View file

@ -0,0 +1,12 @@
{
"Cgroups": [
{
"Controller": "schedtune",
"Path": "/dev/stune",
"Mode": "0755",
"UID": "system",
"GID": "system",
"Optional": true
}
]
}

View file

@ -0,0 +1,160 @@
{
"Attributes": [
{
"Name": "STuneBoost",
"Controller": "schedtune",
"File": "schedtune.boost"
},
{
"Name": "STunePreferIdle",
"Controller": "schedtune",
"File": "schedtune.prefer_idle"
}
],
"Profiles": [
{
"Name": "HighEnergySaving",
"Actions": [
{
"Name": "JoinCgroup",
"Params":
{
"Controller": "schedtune",
"Path": "background"
}
}
]
},
{
"Name": "NormalPerformance",
"Actions": [
{
"Name": "JoinCgroup",
"Params":
{
"Controller": "schedtune",
"Path": ""
}
}
]
},
{
"Name": "ServicePerformance",
"Actions": [
{
"Name": "JoinCgroup",
"Params":
{
"Controller": "schedtune",
"Path": "background"
}
}
]
},
{
"Name": "HighPerformance",
"Actions": [
{
"Name": "JoinCgroup",
"Params":
{
"Controller": "schedtune",
"Path": "foreground"
}
}
]
},
{
"Name": "MaxPerformance",
"Actions": [
{
"Name": "JoinCgroup",
"Params":
{
"Controller": "schedtune",
"Path": "top-app"
}
}
]
},
{
"Name": "RealtimePerformance",
"Actions": [
{
"Name": "JoinCgroup",
"Params":
{
"Controller": "schedtune",
"Path": "rt"
}
}
]
},
{
"Name": "CameraServicePerformance",
"Actions": [
{
"Name": "JoinCgroup",
"Params":
{
"Controller": "schedtune",
"Path": "camera-daemon"
}
}
]
},
{
"Name": "NNApiHALPerformance",
"Actions": [
{
"Name": "JoinCgroup",
"Params":
{
"Controller": "schedtune",
"Path": "nnapi-hal"
}
}
]
},
{
"Name": "Dex2oatPerformance",
"Actions": [
{
"Name": "JoinCgroup",
"Params":
{
"Controller": "schedtune",
"Path": "background"
}
}
]
},
{
"Name": "CpuPolicySpread",
"Actions": [
{
"Name": "SetAttribute",
"Params":
{
"Name": "STunePreferIdle",
"Value": "1"
}
}
]
},
{
"Name": "CpuPolicyPack",
"Actions": [
{
"Name": "SetAttribute",
"Params":
{
"Name": "STunePreferIdle",
"Value": "0"
}
}
]
}
]
}

View file

@ -0,0 +1,160 @@
{
"Attributes": [
{
"Name": "STuneBoost",
"Controller": "schedtune",
"File": "schedtune.boost"
},
{
"Name": "STunePreferIdle",
"Controller": "schedtune",
"File": "schedtune.prefer_idle"
}
],
"Profiles": [
{
"Name": "HighEnergySaving",
"Actions": [
{
"Name": "JoinCgroup",
"Params":
{
"Controller": "schedtune",
"Path": "background"
}
}
]
},
{
"Name": "NormalPerformance",
"Actions": [
{
"Name": "JoinCgroup",
"Params":
{
"Controller": "schedtune",
"Path": ""
}
}
]
},
{
"Name": "HighPerformance",
"Actions": [
{
"Name": "JoinCgroup",
"Params":
{
"Controller": "schedtune",
"Path": "foreground"
}
}
]
},
{
"Name": "ServicePerformance",
"Actions": [
{
"Name": "JoinCgroup",
"Params":
{
"Controller": "schedtune",
"Path": "background"
}
}
]
},
{
"Name": "MaxPerformance",
"Actions": [
{
"Name": "JoinCgroup",
"Params":
{
"Controller": "schedtune",
"Path": "top-app"
}
}
]
},
{
"Name": "RealtimePerformance",
"Actions": [
{
"Name": "JoinCgroup",
"Params":
{
"Controller": "schedtune",
"Path": "rt"
}
}
]
},
{
"Name": "CameraServicePerformance",
"Actions": [
{
"Name": "JoinCgroup",
"Params":
{
"Controller": "schedtune",
"Path": "camera-daemon"
}
}
]
},
{
"Name": "NNApiHALPerformance",
"Actions": [
{
"Name": "JoinCgroup",
"Params":
{
"Controller": "schedtune",
"Path": "nnapi-hal"
}
}
]
},
{
"Name": "Dex2oatPerformance",
"Actions": [
{
"Name": "JoinCgroup",
"Params":
{
"Controller": "schedtune",
"Path": "background"
}
}
]
},
{
"Name": "CpuPolicySpread",
"Actions": [
{
"Name": "SetAttribute",
"Params":
{
"Name": "STunePreferIdle",
"Value": "1"
}
}
]
},
{
"Name": "CpuPolicyPack",
"Actions": [
{
"Name": "SetAttribute",
"Params":
{
"Name": "STunePreferIdle",
"Value": "0"
}
}
]
}
]
}

View file

@ -0,0 +1,160 @@
{
"Attributes": [
{
"Name": "STuneBoost",
"Controller": "schedtune",
"File": "schedtune.boost"
},
{
"Name": "STunePreferIdle",
"Controller": "schedtune",
"File": "schedtune.prefer_idle"
}
],
"Profiles": [
{
"Name": "HighEnergySaving",
"Actions": [
{
"Name": "JoinCgroup",
"Params":
{
"Controller": "schedtune",
"Path": "background"
}
}
]
},
{
"Name": "NormalPerformance",
"Actions": [
{
"Name": "JoinCgroup",
"Params":
{
"Controller": "schedtune",
"Path": ""
}
}
]
},
{
"Name": "ServicePerformance",
"Actions": [
{
"Name": "JoinCgroup",
"Params":
{
"Controller": "schedtune",
"Path": "background"
}
}
]
},
{
"Name": "HighPerformance",
"Actions": [
{
"Name": "JoinCgroup",
"Params":
{
"Controller": "schedtune",
"Path": "foreground"
}
}
]
},
{
"Name": "MaxPerformance",
"Actions": [
{
"Name": "JoinCgroup",
"Params":
{
"Controller": "schedtune",
"Path": "top-app"
}
}
]
},
{
"Name": "RealtimePerformance",
"Actions": [
{
"Name": "JoinCgroup",
"Params":
{
"Controller": "schedtune",
"Path": "rt"
}
}
]
},
{
"Name": "CameraServicePerformance",
"Actions": [
{
"Name": "JoinCgroup",
"Params":
{
"Controller": "schedtune",
"Path": "camera-daemon"
}
}
]
},
{
"Name": "NNApiHALPerformance",
"Actions": [
{
"Name": "JoinCgroup",
"Params":
{
"Controller": "schedtune",
"Path": "nnapi-hal"
}
}
]
},
{
"Name": "Dex2oatPerformance",
"Actions": [
{
"Name": "JoinCgroup",
"Params":
{
"Controller": "schedtune",
"Path": "background"
}
}
]
},
{
"Name": "CpuPolicySpread",
"Actions": [
{
"Name": "SetAttribute",
"Params":
{
"Name": "STunePreferIdle",
"Value": "1"
}
}
]
},
{
"Name": "CpuPolicyPack",
"Actions": [
{
"Name": "SetAttribute",
"Params":
{
"Name": "STunePreferIdle",
"Value": "0"
}
}
]
}
]
}

View file

@ -148,10 +148,20 @@ bool cpusets_enabled() {
return enabled;
}
static bool schedtune_enabled() {
return (CgroupMap::GetInstance().FindController("schedtune").IsUsable());
}
static bool cpuctl_enabled() {
return (CgroupMap::GetInstance().FindController("cpu").IsUsable());
}
bool schedboost_enabled() {
static bool enabled = schedtune_enabled() || cpuctl_enabled();
return enabled;
}
static int getCGroupSubsys(pid_t tid, const char* subsys, std::string& subgroup) {
auto controller = CgroupMap::GetInstance().FindController(subsys);
@ -191,8 +201,9 @@ int get_sched_policy(pid_t tid, SchedPolicy* policy) {
}
std::string group;
if (cpuctl_enabled()) {
if (getCGroupSubsys(tid, "cpu", group) < 0) {
if (schedboost_enabled()) {
if ((getCGroupSubsys(tid, "schedtune", group) < 0) &&
(getCGroupSubsys(tid, "cpu", group) < 0)) {
LOG(ERROR) << "Failed to find cpu cgroup for tid " << tid;
return -1;
}