libprocessgroup: fall back to cpuset in get_sched_policy
Since vendor has a way to override the group cpu/schedtune setup, we cannot assume the group will always return valid data. This CL let get_sched_policy to fallback to cpuset if no valid data found in cpu/schedtune cgroup. In longer term, we should find a way to cache the group or app's process state in framework other than relying on reading cgroup back. Test: /data/nativetest64/libcutils_test/libcutils_test Bug: 210066228 Signed-off-by: Wei Wang <wvw@google.com> Merged-In: I8b4396365a7fc2d93e3a22746195585c140eef3c Change-Id: I8b4396365a7fc2d93e3a22746195585c140eef3c (cherry picked from commit c8c0b5415c14af56277f5e543ebff5fbba7fb7b2)
This commit is contained in:
parent
e73180f8f5
commit
77ad7c798a
1 changed files with 30 additions and 21 deletions
|
@ -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. */
|
||||
|
|
Loading…
Reference in a new issue