Merge "Revert "Use async approach to change sched policy""
This commit is contained in:
committed by
Android (Google) Code Review
commit
ae3944284d
@@ -19,18 +19,16 @@
|
||||
|
||||
// To make sure cpu_set_t is included from sched.h
|
||||
#define _GNU_SOURCE 1
|
||||
#include <android-base/properties.h>
|
||||
#include <android-base/unique_fd.h>
|
||||
#include <binder/ActivityManager.h>
|
||||
#include <utils/Log.h>
|
||||
#include <binder/IPCThreadState.h>
|
||||
#include <binder/IServiceManager.h>
|
||||
#include <utils/String8.h>
|
||||
#include <utils/Vector.h>
|
||||
#include <meminfo/procmeminfo.h>
|
||||
#include <meminfo/sysmeminfo.h>
|
||||
#include <processgroup/processgroup.h>
|
||||
#include <processgroup/sched_policy.h>
|
||||
#include <utils/Log.h>
|
||||
#include <utils/String8.h>
|
||||
#include <utils/Vector.h>
|
||||
#include <android-base/unique_fd.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
@@ -86,8 +84,6 @@ Mutex gKeyCreateMutex;
|
||||
static pthread_key_t gBgKey = -1;
|
||||
#endif
|
||||
|
||||
static bool boot_completed = false;
|
||||
|
||||
// For both of these, err should be in the errno range (positive), not a status_t (negative)
|
||||
static void signalExceptionForError(JNIEnv* env, int err, int tid) {
|
||||
switch (err) {
|
||||
@@ -584,20 +580,7 @@ void android_os_Process_setThreadPriority(JNIEnv* env, jobject clazz,
|
||||
}
|
||||
#endif
|
||||
|
||||
SchedPolicy policy;
|
||||
bool policy_changed = false;
|
||||
int rc = 0, curr_pri = getpriority(PRIO_PROCESS, pid);
|
||||
|
||||
if (pri == curr_pri) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!boot_completed) {
|
||||
boot_completed = android::base::GetBoolProperty("sys.boot_completed", false);
|
||||
}
|
||||
|
||||
// Do not change sched policy cgroup after boot complete.
|
||||
rc = androidSetThreadPriorityAndPolicy(pid, pri, !boot_completed);
|
||||
int rc = androidSetThreadPriority(pid, pri);
|
||||
if (rc != 0) {
|
||||
if (rc == INVALID_OPERATION) {
|
||||
signalExceptionForPriorityError(env, errno, pid);
|
||||
@@ -606,31 +589,6 @@ void android_os_Process_setThreadPriority(JNIEnv* env, jobject clazz,
|
||||
}
|
||||
}
|
||||
|
||||
// Only use async approach after boot complete.
|
||||
if (!boot_completed) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Change to background sched policy for the thread if setting to low priority.
|
||||
if (pri >= ANDROID_PRIORITY_BACKGROUND) {
|
||||
policy = SP_BACKGROUND;
|
||||
policy_changed = true;
|
||||
// Change to sched policy of the process if thread priority is raising from low priority.
|
||||
} else if (curr_pri >= ANDROID_PRIORITY_BACKGROUND) {
|
||||
// If we cannot get sched policy of the process, use SP_FOREGROUND as default.
|
||||
policy = SP_FOREGROUND;
|
||||
get_sched_policy(getpid(), &policy);
|
||||
policy_changed = true;
|
||||
}
|
||||
|
||||
// Sched policy will only change in above 2 cases.
|
||||
if (policy_changed) {
|
||||
ActivityManager am;
|
||||
if (!am.setSchedPolicyCgroup(pid, policy)) {
|
||||
ALOGE("am.setThreadPriority failed: tid=%d priority=%d policy=%d", pid, pri, policy);
|
||||
}
|
||||
}
|
||||
|
||||
//ALOGI("Setting priority of %" PRId32 ": %" PRId32 ", getpriority returns %d\n",
|
||||
// pid, pri, getpriority(PRIO_PROCESS, pid));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user