Merge "libprocessgroup: fall back to cpuset in get_sched_policy" am: a5247158fb

Original change: https://android-review.googlesource.com/c/platform/system/core/+/1922859

Change-Id: I6a3c8a688761eef51fa2c5ec40e48bf8afeb21b6
This commit is contained in:
Wei Wang 2021-12-16 20:44:35 +00:00 committed by Automerger Merge Worker
commit 9a576bfca7

View file

@ -165,27 +165,7 @@ static int getCGroupSubsys(int tid, const char* subsys, std::string& subgroup) {
return 0;
}
int get_sched_policy(int tid, SchedPolicy* policy) {
if (tid == 0) {
tid = GetThreadId();
}
std::string group;
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;
}
}
if (group.empty() && cpusets_enabled()) {
if (getCGroupSubsys(tid, "cpuset", group) < 0) {
LOG(ERROR) << "Failed to find cpuset cgroup for tid " << tid;
return -1;
}
}
// TODO: replace hardcoded directories
static int get_sched_policy_from_group(const std::string& group, SchedPolicy* policy) {
if (group.empty()) {
*policy = SP_FOREGROUND;
} else if (group == "foreground") {
@ -205,6 +185,35 @@ int get_sched_policy(int tid, SchedPolicy* policy) {
return 0;
}
int get_sched_policy(int tid, SchedPolicy* policy) {
if (tid == 0) {
tid = GetThreadId();
}
std::string group;
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;
}
// Wipe invalid group to fallback to cpuset
if (!group.empty()) {
if (get_sched_policy_from_group(group, policy) < 0) {
group.clear();
} else {
return 0;
}
}
}
if (cpusets_enabled() && getCGroupSubsys(tid, "cpuset", group) < 0) {
LOG(ERROR) << "Failed to find cpuset cgroup for tid " << tid;
return -1;
}
return get_sched_policy_from_group(group, policy);
}
#else
/* Stubs for non-Android targets. */