#include <errno.h>
#include <fcntl.h>
+#include <cutils/sched_policy.h>
+
#if defined(HAVE_PRCTL)
#include <sys/prctl.h>
#endif
};
/*
- * 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
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) {
#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);
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);
#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>
*/
if (priorityResult >= ANDROID_PRIORITY_BACKGROUND) {
- dvmChangeThreadSchedulerPolicy(SP_FOREGROUND);
+ set_sched_policy(dvmGetSysThreadId(), SP_FOREGROUND);
}
if (setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_NORMAL) != 0) {
}
if (oldThreadPriority >= ANDROID_PRIORITY_BACKGROUND) {
- dvmChangeThreadSchedulerPolicy(SP_BACKGROUND);
+ set_sched_policy(dvmGetSysThreadId(), SP_BACKGROUND);
}
}
gcElapsedTime = (dvmGetRelativeTimeUsec() - gcHeap->gcStartTime) / 1000;