summaryrefslogtreecommitdiffstats
path: root/core/jni
diff options
context:
space:
mode:
authorGlenn Kasten <gkasten@google.com>2012-04-23 17:11:55 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-04-23 17:11:55 -0700
commit2427a4c49ec88638393d329b88162f1e709ba0e5 (patch)
tree60ef3f405f7c27e08d73ca2efbf66ecdd2072448 /core/jni
parenta8d6ddee98e09a68030f4226b94f631e3b4c83c1 (diff)
parentf1b56449f58963e4f0473d5e26961f68c31759f4 (diff)
downloadframeworks_base-2427a4c49ec88638393d329b88162f1e709ba0e5.zip
frameworks_base-2427a4c49ec88638393d329b88162f1e709ba0e5.tar.gz
frameworks_base-2427a4c49ec88638393d329b88162f1e709ba0e5.tar.bz2
Merge "Scheduling group cleanup"
Diffstat (limited to 'core/jni')
-rw-r--r--core/jni/android_util_Process.cpp40
1 files changed, 27 insertions, 13 deletions
diff --git a/core/jni/android_util_Process.cpp b/core/jni/android_util_Process.cpp
index 41cc203..93be342 100644
--- a/core/jni/android_util_Process.cpp
+++ b/core/jni/android_util_Process.cpp
@@ -21,6 +21,7 @@
#include <binder/IPCThreadState.h>
#include <binder/ProcessState.h>
#include <binder/IServiceManager.h>
+#include <cutils/sched_policy.h>
#include <utils/String8.h>
#include <utils/Vector.h>
@@ -49,6 +50,8 @@ Mutex gKeyCreateMutex;
static pthread_key_t gBgKey = -1;
#endif
+// For both of these, err should be in the errno range (positive), not a status_t (negative)
+
static void signalExceptionForPriorityError(JNIEnv* env, int err)
{
switch (err) {
@@ -168,27 +171,36 @@ jint android_os_Process_getGidForName(JNIEnv* env, jobject clazz, jstring name)
return -1;
}
-void android_os_Process_setThreadGroup(JNIEnv* env, jobject clazz, int pid, jint grp)
+void android_os_Process_setThreadGroup(JNIEnv* env, jobject clazz, int tid, jint grp)
{
- int res = androidSetThreadSchedulingGroup(pid, grp);
+ ALOGV("%s tid=%d grp=%d", __func__, tid, grp);
+ SchedPolicy sp = (SchedPolicy) grp;
+ int res = set_sched_policy(tid, sp);
if (res != NO_ERROR) {
- signalExceptionForGroupError(env, res == BAD_VALUE ? EINVAL : errno);
- return;
+ signalExceptionForGroupError(env, -res);
}
}
void android_os_Process_setProcessGroup(JNIEnv* env, jobject clazz, int pid, jint grp)
{
+ ALOGV("%s pid=%d grp=%d", __func__, pid, grp);
DIR *d;
FILE *fp;
char proc_path[255];
struct dirent *de;
- if (grp > ANDROID_TGROUP_MAX || grp < 0) {
+ if ((grp == SP_FOREGROUND) || (grp > SP_MAX)) {
signalExceptionForGroupError(env, EINVAL);
return;
}
+ bool isDefault = false;
+ if (grp < 0) {
+ grp = SP_FOREGROUND;
+ isDefault = true;
+ }
+ SchedPolicy sp = (SchedPolicy) grp;
+
#if POLICY_DEBUG
char cmdline[32];
int fd;
@@ -203,7 +215,7 @@ void android_os_Process_setProcessGroup(JNIEnv* env, jobject clazz, int pid, jin
close(fd);
}
- if (grp == ANDROID_TGROUP_BG_NONINTERACT) {
+ if (sp == SP_BACKGROUND) {
ALOGD("setProcessGroup: vvv pid %d (%s)", pid, cmdline);
} else {
ALOGD("setProcessGroup: ^^^ pid %d (%s)", pid, cmdline);
@@ -230,16 +242,18 @@ void android_os_Process_setProcessGroup(JNIEnv* env, jobject clazz, int pid, jin
continue;
}
- t_pri = getpriority(PRIO_PROCESS, t_pid);
+ if (isDefault) {
+ t_pri = getpriority(PRIO_PROCESS, t_pid);
- if (grp == ANDROID_TGROUP_DEFAULT &&
- t_pri >= ANDROID_PRIORITY_BACKGROUND) {
- // This task wants to stay at background
- continue;
+ if (t_pri >= ANDROID_PRIORITY_BACKGROUND) {
+ // This task wants to stay at background
+ continue;
+ }
}
- if (androidSetThreadSchedulingGroup(t_pid, grp) != NO_ERROR) {
- signalExceptionForGroupError(env, errno);
+ int err = set_sched_policy(t_pid, sp);
+ if (err != NO_ERROR) {
+ signalExceptionForGroupError(env, -err);
break;
}
}