summaryrefslogtreecommitdiffstats
path: root/runtime
diff options
context:
space:
mode:
authorNarayan Kamath <narayan@google.com>2014-10-07 12:51:26 +0100
committerNarayan Kamath <narayan@google.com>2014-11-07 12:51:48 +0000
commita0b34518cf3f3801407624d95846f8ff90c05d25 (patch)
tree1f1df690f6018c415215792a96cb7c7ded9dd9fd /runtime
parent88af00a788002196e6f98acd3748f3f4956032bf (diff)
downloadart-a0b34518cf3f3801407624d95846f8ff90c05d25.zip
art-a0b34518cf3f3801407624d95846f8ff90c05d25.tar.gz
art-a0b34518cf3f3801407624d95846f8ff90c05d25.tar.bz2
Fix thread priorities for unstarted threads.
Calls to Thread.setPriority for unstarted threads now behave similar to dalvik. Note that there's still some inconsistent behaviour carried over from dalvik. - high priority threads from bg_non_interactive processes are not always moved to the SP_FOREGROUND cgroup. - we do not attempt to adjust the cgroup of a native thread that's attaching. Note that on android, the system_server will change the cgroups for all running threads in a process when it moves into the foreground and background. It's by design that threads in a background process can request to be moved to the foreground by setting a higher priority. bug: 17893086 (cherry picked from commit 1bd326a5e2aaff06a5bcae9cb2c42a4e8de31401) Change-Id: Iad362f7c5c8697c349f2b6d7fcba69a4e141883e
Diffstat (limited to 'runtime')
-rw-r--r--runtime/thread.cc3
-rw-r--r--runtime/thread_android.cc7
2 files changed, 10 insertions, 0 deletions
diff --git a/runtime/thread.cc b/runtime/thread.cc
index 7d24562..2c44f27 100644
--- a/runtime/thread.cc
+++ b/runtime/thread.cc
@@ -170,6 +170,9 @@ void* Thread::CreateCallback(void* arg) {
self->GetJniEnv()->DeleteGlobalRef(self->tlsPtr_.jpeer);
self->tlsPtr_.jpeer = nullptr;
self->SetThreadName(self->GetThreadName(soa)->ToModifiedUtf8().c_str());
+
+ mirror::ArtField* priorityField = soa.DecodeField(WellKnownClasses::java_lang_Thread_priority);
+ self->SetNativePriority(priorityField->GetInt(self->tlsPtr_.opeer));
Dbg::PostThreadStart(self);
// Invoke the 'run' method of our java.lang.Thread.
diff --git a/runtime/thread_android.cc b/runtime/thread_android.cc
index 73a9e54..d5db983 100644
--- a/runtime/thread_android.cc
+++ b/runtime/thread_android.cc
@@ -55,6 +55,13 @@ void Thread::SetNativePriority(int newPriority) {
int newNice = kNiceValues[newPriority-1];
pid_t tid = GetTid();
+ // TODO: b/18249098 The code below is broken. It uses getpriority() as a proxy for whether a
+ // thread is already in the SP_FOREGROUND cgroup. This is not necessarily true for background
+ // processes, where all threads are in the SP_BACKGROUND cgroup. This means that callers will
+ // have to call setPriority twice to do what they want :
+ //
+ // Thread.setPriority(Thread.MIN_PRIORITY); // no-op wrt to cgroups
+ // Thread.setPriority(Thread.MAX_PRIORITY); // will actually change cgroups.
if (newNice >= ANDROID_PRIORITY_BACKGROUND) {
set_sched_policy(tid, SP_BACKGROUND);
} else if (getpriority(PRIO_PROCESS, tid) >= ANDROID_PRIORITY_BACKGROUND) {