Boost android.anim and wm lock sections to -10 during transition
-4 is not enough if we have to compete against RT and main thread
from top app that have -10. Boost it more during app transitions
Test: Inspect systrace, make sure priorities are right, including
getting reset after the transition.
Test: Open Chrome 100x
Test: go/wm-smoke
Change-Id: Id6b060b8aafded67b4bae61b6e8960e37976b096
Fixes: 36631902
diff --git a/services/core/java/com/android/server/ThreadPriorityBooster.java b/services/core/java/com/android/server/ThreadPriorityBooster.java
index 31726ad..0dfecc0 100644
--- a/services/core/java/com/android/server/ThreadPriorityBooster.java
+++ b/services/core/java/com/android/server/ThreadPriorityBooster.java
@@ -16,14 +16,16 @@
package com.android.server;
-import android.os.Process;
+import static android.os.Process.getThreadPriority;
+import static android.os.Process.myTid;
+import static android.os.Process.setThreadPriority;
/**
* Utility class to boost threads in sections where important locks are held.
*/
public class ThreadPriorityBooster {
- private final int mBoostToPriority;
+ private volatile int mBoostToPriority;
private final int mLockGuardIndex;
private final ThreadLocal<PriorityState> mThreadState = new ThreadLocal<PriorityState>() {
@@ -38,12 +40,12 @@
}
public void boost() {
- final int tid = Process.myTid();
- final int prevPriority = Process.getThreadPriority(tid);
- PriorityState state = mThreadState.get();
+ final int tid = myTid();
+ final int prevPriority = getThreadPriority(tid);
+ final PriorityState state = mThreadState.get();
state.prevPriority = prevPriority;
if (state.regionCounter == 0 && prevPriority > mBoostToPriority) {
- Process.setThreadPriority(tid, mBoostToPriority);
+ setThreadPriority(tid, mBoostToPriority);
}
state.regionCounter++;
if (LockGuard.ENABLED) {
@@ -52,10 +54,28 @@
}
public void reset() {
- PriorityState state = mThreadState.get();
+ final PriorityState state = mThreadState.get();
state.regionCounter--;
- if (state.regionCounter == 0 && state.prevPriority > mBoostToPriority) {
- Process.setThreadPriority(Process.myTid(), state.prevPriority);
+ final int currentPriority = getThreadPriority(myTid());
+ if (state.regionCounter == 0 && state.prevPriority != currentPriority) {
+ setThreadPriority(myTid(), state.prevPriority);
+ }
+ }
+
+ /**
+ * Updates the priority we boost the threads to, and updates the current thread's priority if
+ * necessary.
+ */
+ protected void setBoostToPriority(int priority) {
+
+ // We don't care about the other threads here, as long as they see the update of this
+ // variable immediately.
+ mBoostToPriority = priority;
+ final PriorityState state = mThreadState.get();
+ final int tid = myTid();
+ final int prevPriority = getThreadPriority(tid);
+ if (state.regionCounter != 0 && prevPriority != priority) {
+ setThreadPriority(tid, priority);
}
}