diff options
| -rw-r--r-- | vm/Thread.c | 67 | ||||
| -rw-r--r-- | vm/Thread.h | 9 | ||||
| -rw-r--r-- | vm/alloc/Heap.c | 6 |
3 files changed, 8 insertions, 74 deletions
diff --git a/vm/Thread.c b/vm/Thread.c index 7a8fc0244..be3e95229 100644 --- a/vm/Thread.c +++ b/vm/Thread.c @@ -30,6 +30,8 @@ #include <errno.h> #include <fcntl.h> +#include <cutils/sched_policy.h> + #if defined(HAVE_PRCTL) #include <sys/prctl.h> #endif @@ -3062,67 +3064,6 @@ static const int kNiceValues[10] = { }; /* - * Change the scheduler cgroup of the current thread. - * - * Returns 0 on success. - */ -static int dvmChangeThreadSchedulerGroup(const char *cgroup) -{ -#ifdef HAVE_ANDROID_OS - int fd; - char path[255]; - - snprintf(path, sizeof(path), "/dev/cpuctl/%s/tasks", (cgroup ? cgroup :"")); - - if ((fd = open(path, O_WRONLY)) < 0) { - int err = errno; -#if ENABLE_CGROUP_ERR_LOGGING - LOGW("Unable to open %s (%s)\n", path, strerror(err)); -#endif - return -err; - } - - if (write(fd, "0", 1) < 0) { - int err = errno; -#if ENABLE_CGROUP_ERR_LOGGING - LOGW("Unable to move tid %d to cgroup %s (%s)\n", - dvmThreadSelf()->systemTid, - (cgroup ? cgroup : "<default>"), strerror(err)); -#endif - close(fd); - return -err; - } - close(fd); - - return 0; - -#else // HAVE_ANDROID_OS - return 0; -#endif -} - -/* - * Change the scheduling policy of the current thread - */ -void dvmChangeThreadSchedulerPolicy(SchedPolicy policy) -{ - if (gDvm.kernelGroupScheduling) { - const char *grp = NULL; - - if (policy == SP_BACKGROUND) { - grp = "bg_non_interactive"; - } - - dvmChangeThreadSchedulerGroup(grp); - } else { - struct sched_param param; - param.sched_priority = 0; - sched_setscheduler(dvmGetSysThreadId(), - (policy == SP_BACKGROUND) ? 5 : 0, ¶m); - } -} - -/* * Change the priority of a system thread to match that of the Thread object. * * We map a priority value from 1-10 to Linux "nice" values, where lower @@ -3140,9 +3081,9 @@ void dvmChangeThreadPriority(Thread* thread, int newPriority) newNice = kNiceValues[newPriority-1]; if (newNice >= ANDROID_PRIORITY_BACKGROUND) { - dvmChangeThreadSchedulerPolicy(SP_BACKGROUND); + set_sched_policy(dvmGetSysThreadId(), SP_BACKGROUND); } else if (getpriority(PRIO_PROCESS, pid) >= ANDROID_PRIORITY_BACKGROUND) { - dvmChangeThreadSchedulerPolicy(SP_FOREGROUND); + set_sched_policy(dvmGetSysThreadId(), SP_FOREGROUND); } if (setpriority(PRIO_PROCESS, pid, newNice) != 0) { diff --git a/vm/Thread.h b/vm/Thread.h index a829319ec..1bb531409 100644 --- a/vm/Thread.h +++ b/vm/Thread.h @@ -22,8 +22,6 @@ #include "jni.h" -#include <utils/threads.h> /* Need SchedPolicy */ - #if defined(CHECK_MUTEX) && !defined(__USE_UNIX98) /* glibc lacks this unless you #define __USE_UNIX98 */ int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type); @@ -421,13 +419,6 @@ INLINE JNIEnv* dvmGetThreadJNIEnv(Thread* self) { return self->jniEnv; } INLINE void dvmSetThreadJNIEnv(Thread* self, JNIEnv* env) { self->jniEnv = env;} /* - * Change the scheduling policy of the current process. - * This is mapped onto whatever underlying scheme the kernel - * supports (cgroups/scheduler policies/wombats/etc) - */ -void dvmChangeThreadSchedulerPolicy(SchedPolicy policy); - -/* * Update the priority value of the underlying pthread. */ void dvmChangeThreadPriority(Thread* thread, int newPriority); diff --git a/vm/alloc/Heap.c b/vm/alloc/Heap.c index 0d625b4b8..17d6a5cb1 100644 --- a/vm/alloc/Heap.c +++ b/vm/alloc/Heap.c @@ -27,6 +27,8 @@ #include "utils/threads.h" // need Android thread priorities #define kInvalidPriority 10000 +#include <cutils/sched_policy.h> + #include <sys/time.h> #include <sys/resource.h> #include <limits.h> @@ -783,7 +785,7 @@ void dvmCollectGarbageInternal(bool collectSoftReferences) */ if (priorityResult >= ANDROID_PRIORITY_BACKGROUND) { - dvmChangeThreadSchedulerPolicy(SP_FOREGROUND); + set_sched_policy(dvmGetSysThreadId(), SP_FOREGROUND); } if (setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_NORMAL) != 0) { @@ -1036,7 +1038,7 @@ void dvmCollectGarbageInternal(bool collectSoftReferences) } if (oldThreadPriority >= ANDROID_PRIORITY_BACKGROUND) { - dvmChangeThreadSchedulerPolicy(SP_BACKGROUND); + set_sched_policy(dvmGetSysThreadId(), SP_BACKGROUND); } } gcElapsedTime = (dvmGetRelativeTimeUsec() - gcHeap->gcStartTime) / 1000; |
