OSDN Git Service

dalvik: Switch to common cutils sched_policy api
authorSan Mehat <san@google.com>
Sat, 12 Sep 2009 17:10:13 +0000 (10:10 -0700)
committerSan Mehat <san@google.com>
Sat, 12 Sep 2009 17:48:02 +0000 (10:48 -0700)
Signed-off-by: San Mehat <san@google.com>
vm/Thread.c
vm/Thread.h
vm/alloc/Heap.c

index 7a8fc02..be3e952 100644 (file)
@@ -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, &param);
-    }
-}
-
-/*
  * 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) {
index a829319..1bb5314 100644 (file)
@@ -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);
index 0d625b4..17d6a5c 100644 (file)
@@ -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;