Loading core/java/android/window/flags/windowing_frontend.aconfig +8 −0 Original line number Diff line number Diff line Loading @@ -127,6 +127,14 @@ flag { is_fixed_read_only: true } flag { name: "fifo_priority_for_major_ui_processes" namespace: "windowing_frontend" description: "Use realtime priority for SystemUI and launcher" bug: "288140556" is_fixed_read_only: true } flag { name: "insets_decoupled_configuration" namespace: "windowing_frontend" Loading services/core/java/com/android/server/am/ActivityManagerService.java +66 −1 Original line number Diff line number Diff line Loading @@ -725,6 +725,9 @@ public class ActivityManagerService extends IActivityManager.Stub // Whether we should use SCHED_FIFO for UI and RenderThreads. final boolean mUseFifoUiScheduling; /** Whether some specified important processes are allowed to use FIFO priority. */ boolean mAllowSpecifiedFifoScheduling = true; @GuardedBy("this") private final SparseArray<IUnsafeIntentStrictModeCallback> mStrictModeCallbacks = new SparseArray<>(); Loading Loading @@ -1048,6 +1051,10 @@ public class ActivityManagerService extends IActivityManager.Stub @GuardedBy("this") final SparseArray<ImportanceToken> mImportantProcesses = new SparseArray<ImportanceToken>(); /** The processes that are allowed to use SCHED_FIFO prorioty. */ @GuardedBy("mProcLock") final ArrayList<ProcessRecord> mSpecifiedFifoProcesses = new ArrayList<>(); /** * List of records for processes that someone had tried to start before the * system was ready. We don't start them at that point, but ensure they Loading Loading @@ -8244,6 +8251,27 @@ public class ActivityManagerService extends IActivityManager.Stub return false; } /** * Switches the priority between SCHED_FIFO and SCHED_OTHER for the main thread and render * thread of the given process. */ @GuardedBy("mProcLock") static void setFifoPriority(@NonNull ProcessRecord app, boolean enable) { final int pid = app.getPid(); final int renderThreadTid = app.getRenderThreadTid(); if (enable) { scheduleAsFifoPriority(pid, true /* suppressLogs */); if (renderThreadTid != 0) { scheduleAsFifoPriority(renderThreadTid, true /* suppressLogs */); } } else { scheduleAsRegularPriority(pid, true /* suppressLogs */); if (renderThreadTid != 0) { scheduleAsRegularPriority(renderThreadTid, true /* suppressLogs */); } } } @Override public void setRenderThread(int tid) { synchronized (mProcLock) { Loading @@ -8269,7 +8297,7 @@ public class ActivityManagerService extends IActivityManager.Stub // promote to FIFO now if (proc.mState.getCurrentSchedulingGroup() == ProcessList.SCHED_GROUP_TOP_APP) { if (DEBUG_OOM_ADJ) Slog.d("UI_FIFO", "Promoting " + tid + "out of band"); if (mUseFifoUiScheduling) { if (proc.useFifoUiScheduling()) { setThreadScheduler(proc.getRenderThreadTid(), SCHED_FIFO | SCHED_RESET_ON_FORK, 1); } else { Loading Loading @@ -11306,6 +11334,9 @@ public class ActivityManagerService extends IActivityManager.Stub if (mAlwaysFinishActivities) { pw.println(" mAlwaysFinishActivities=" + mAlwaysFinishActivities); } if (mAllowSpecifiedFifoScheduling) { pw.println(" mAllowSpecifiedFifoScheduling=true"); } if (dumpAll) { pw.println(" Total persistent processes: " + numPers); pw.println(" mProcessesReady=" + mProcessesReady Loading Loading @@ -17374,6 +17405,12 @@ public class ActivityManagerService extends IActivityManager.Stub } } } if (com.android.window.flags.Flags.fifoPriorityForMajorUiProcesses()) { synchronized (mProcLock) { adjustFifoProcessesIfNeeded(uid, !active /* allowFifo */); } } } final boolean isCameraActiveForUid(@UserIdInt int uid) { Loading @@ -17382,6 +17419,34 @@ public class ActivityManagerService extends IActivityManager.Stub } } /** * This is called when the given uid is using camera. If the uid has top process state, then * cancel the FIFO priority of the high priority processes. */ @VisibleForTesting @GuardedBy("mProcLock") void adjustFifoProcessesIfNeeded(int preemptiveUid, boolean allowSpecifiedFifo) { if (allowSpecifiedFifo == mAllowSpecifiedFifoScheduling) { return; } if (!allowSpecifiedFifo) { final UidRecord uidRec = mProcessList.mActiveUids.get(preemptiveUid); if (uidRec == null || uidRec.getCurProcState() > PROCESS_STATE_TOP) { // To avoid frequent switching by background camera usages, e.g. face unlock, // face detection (auto rotation), screen attention (keep screen on). return; } } mAllowSpecifiedFifoScheduling = allowSpecifiedFifo; for (int i = mSpecifiedFifoProcesses.size() - 1; i >= 0; i--) { final ProcessRecord proc = mSpecifiedFifoProcesses.get(i); if (proc.mState.getSetSchedGroup() != ProcessList.SCHED_GROUP_TOP_APP) { continue; } setFifoPriority(proc, allowSpecifiedFifo /* enable */); } } @GuardedBy("this") final void doStopUidLocked(int uid, final UidRecord uidRec) { mServices.stopInBackgroundLocked(uid); services/core/java/com/android/server/am/OomAdjuster.java +7 −33 Original line number Diff line number Diff line Loading @@ -72,7 +72,6 @@ import static android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYB import static android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE; import static android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_PHONE_CALL; import static android.media.audio.Flags.roForegroundAudioControl; import static android.os.Process.SCHED_OTHER; import static android.os.Process.THREAD_GROUP_BACKGROUND; import static android.os.Process.THREAD_GROUP_DEFAULT; import static android.os.Process.THREAD_GROUP_RESTRICTED; Loading @@ -81,7 +80,6 @@ import static android.os.Process.THREAD_PRIORITY_DISPLAY; import static android.os.Process.THREAD_PRIORITY_TOP_APP_BOOST; import static android.os.Process.setProcessGroup; import static android.os.Process.setThreadPriority; import static android.os.Process.setThreadScheduler; import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ALL; import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_BACKUP; Loading Loading @@ -3315,22 +3313,10 @@ public class OomAdjuster { // do nothing if we already switched to RT if (oldSchedGroup != SCHED_GROUP_TOP_APP) { app.getWindowProcessController().onTopProcChanged(); if (mService.mUseFifoUiScheduling) { if (app.useFifoUiScheduling()) { // Switch UI pipeline for app to SCHED_FIFO state.setSavedPriority(Process.getThreadPriority(app.getPid())); mService.scheduleAsFifoPriority(app.getPid(), true); if (renderThreadTid != 0) { mService.scheduleAsFifoPriority(renderThreadTid, /* suppressLogs */true); if (DEBUG_OOM_ADJ) { Slog.d("UI_FIFO", "Set RenderThread (TID " + renderThreadTid + ") to FIFO"); } } else { if (DEBUG_OOM_ADJ) { Slog.d("UI_FIFO", "Not setting RenderThread TID"); } } ActivityManagerService.setFifoPriority(app, true /* enable */); } else { // Boost priority for top app UI and render threads setThreadPriority(app.getPid(), THREAD_PRIORITY_TOP_APP_BOOST); Loading @@ -3347,22 +3333,10 @@ public class OomAdjuster { } else if (oldSchedGroup == SCHED_GROUP_TOP_APP && curSchedGroup != SCHED_GROUP_TOP_APP) { app.getWindowProcessController().onTopProcChanged(); if (mService.mUseFifoUiScheduling) { try { if (app.useFifoUiScheduling()) { // Reset UI pipeline to SCHED_OTHER setThreadScheduler(app.getPid(), SCHED_OTHER, 0); ActivityManagerService.setFifoPriority(app, false /* enable */); setThreadPriority(app.getPid(), state.getSavedPriority()); if (renderThreadTid != 0) { setThreadScheduler(renderThreadTid, SCHED_OTHER, 0); } } catch (IllegalArgumentException e) { Slog.w(TAG, "Failed to set scheduling policy, thread does not exist:\n" + e); } catch (SecurityException e) { Slog.w(TAG, "Failed to set scheduling policy, not allowed:\n" + e); } } else { // Reset priority for top app UI and render threads setThreadPriority(app.getPid(), 0); Loading Loading @@ -3557,7 +3531,7 @@ public class OomAdjuster { // {@link SCHED_GROUP_TOP_APP}. We don't check render thread because it // is not ready when attaching. app.getWindowProcessController().onTopProcChanged(); if (mService.mUseFifoUiScheduling) { if (app.useFifoUiScheduling()) { mService.scheduleAsFifoPriority(app.getPid(), true); } else { setThreadPriority(app.getPid(), THREAD_PRIORITY_TOP_APP_BOOST); Loading services/core/java/com/android/server/am/ProcessRecord.java +13 −0 Original line number Diff line number Diff line Loading @@ -745,6 +745,9 @@ class ProcessRecord implements WindowProcessListener { mOnewayThread = thread; } mWindowProcessController.setThread(thread); if (mWindowProcessController.useFifoUiScheduling()) { mService.mSpecifiedFifoProcesses.add(this); } } @GuardedBy({"mService", "mProcLock"}) Loading @@ -752,9 +755,19 @@ class ProcessRecord implements WindowProcessListener { mThread = null; mOnewayThread = null; mWindowProcessController.setThread(null); if (mWindowProcessController.useFifoUiScheduling()) { mService.mSpecifiedFifoProcesses.remove(this); } mProfile.onProcessInactive(tracker); } @GuardedBy(anyOf = {"mService", "mProcLock"}) boolean useFifoUiScheduling() { return mService.mUseFifoUiScheduling || (mService.mAllowSpecifiedFifoScheduling && mWindowProcessController.useFifoUiScheduling()); } @GuardedBy("mService") int getDyingPid() { return mDyingPid; Loading services/core/java/com/android/server/wm/WindowProcessController.java +16 −0 Original line number Diff line number Diff line Loading @@ -202,6 +202,12 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio // Whether this process has ever started a service with the BIND_INPUT_METHOD permission. private volatile boolean mHasImeService; /** * Whether this process can use realtime prioirity (SCHED_FIFO) for its UI and render threads * when this process is SCHED_GROUP_TOP_APP. */ private final boolean mUseFifoUiScheduling; /** Whether {@link #mActivities} is not empty. */ private volatile boolean mHasActivities; /** All activities running in the process (exclude destroying). */ Loading Loading @@ -340,6 +346,8 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio // TODO(b/151161907): Remove after support for display-independent (raw) SysUi configs. mIsActivityConfigOverrideAllowed = false; } mUseFifoUiScheduling = com.android.window.flags.Flags.fifoPriorityForMajorUiProcesses() && (isSysUiPackage || mAtm.isCallerRecents(uid)); mCanUseSystemGrammaticalGender = mAtm.mGrammaticalManagerInternal != null && mAtm.mGrammaticalManagerInternal.canGetSystemGrammaticalGender(mUid, Loading Loading @@ -1901,6 +1909,11 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio } } /** Returns {@code true} if the process prefers to use fifo scheduling. */ public boolean useFifoUiScheduling() { return mUseFifoUiScheduling; } @HotPath(caller = HotPath.OOM_ADJUSTMENT) public void onTopProcChanged() { if (mAtm.mVrController.isInterestingToSchedGroup()) { Loading Loading @@ -2078,6 +2091,9 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio } pw.println(); } if (mUseFifoUiScheduling) { pw.println(prefix + " mUseFifoUiScheduling=true"); } final int stateFlags = mActivityStateFlags; if (stateFlags != ACTIVITY_STATE_FLAG_MASK_MIN_TASK_LAYER) { Loading Loading
core/java/android/window/flags/windowing_frontend.aconfig +8 −0 Original line number Diff line number Diff line Loading @@ -127,6 +127,14 @@ flag { is_fixed_read_only: true } flag { name: "fifo_priority_for_major_ui_processes" namespace: "windowing_frontend" description: "Use realtime priority for SystemUI and launcher" bug: "288140556" is_fixed_read_only: true } flag { name: "insets_decoupled_configuration" namespace: "windowing_frontend" Loading
services/core/java/com/android/server/am/ActivityManagerService.java +66 −1 Original line number Diff line number Diff line Loading @@ -725,6 +725,9 @@ public class ActivityManagerService extends IActivityManager.Stub // Whether we should use SCHED_FIFO for UI and RenderThreads. final boolean mUseFifoUiScheduling; /** Whether some specified important processes are allowed to use FIFO priority. */ boolean mAllowSpecifiedFifoScheduling = true; @GuardedBy("this") private final SparseArray<IUnsafeIntentStrictModeCallback> mStrictModeCallbacks = new SparseArray<>(); Loading Loading @@ -1048,6 +1051,10 @@ public class ActivityManagerService extends IActivityManager.Stub @GuardedBy("this") final SparseArray<ImportanceToken> mImportantProcesses = new SparseArray<ImportanceToken>(); /** The processes that are allowed to use SCHED_FIFO prorioty. */ @GuardedBy("mProcLock") final ArrayList<ProcessRecord> mSpecifiedFifoProcesses = new ArrayList<>(); /** * List of records for processes that someone had tried to start before the * system was ready. We don't start them at that point, but ensure they Loading Loading @@ -8244,6 +8251,27 @@ public class ActivityManagerService extends IActivityManager.Stub return false; } /** * Switches the priority between SCHED_FIFO and SCHED_OTHER for the main thread and render * thread of the given process. */ @GuardedBy("mProcLock") static void setFifoPriority(@NonNull ProcessRecord app, boolean enable) { final int pid = app.getPid(); final int renderThreadTid = app.getRenderThreadTid(); if (enable) { scheduleAsFifoPriority(pid, true /* suppressLogs */); if (renderThreadTid != 0) { scheduleAsFifoPriority(renderThreadTid, true /* suppressLogs */); } } else { scheduleAsRegularPriority(pid, true /* suppressLogs */); if (renderThreadTid != 0) { scheduleAsRegularPriority(renderThreadTid, true /* suppressLogs */); } } } @Override public void setRenderThread(int tid) { synchronized (mProcLock) { Loading @@ -8269,7 +8297,7 @@ public class ActivityManagerService extends IActivityManager.Stub // promote to FIFO now if (proc.mState.getCurrentSchedulingGroup() == ProcessList.SCHED_GROUP_TOP_APP) { if (DEBUG_OOM_ADJ) Slog.d("UI_FIFO", "Promoting " + tid + "out of band"); if (mUseFifoUiScheduling) { if (proc.useFifoUiScheduling()) { setThreadScheduler(proc.getRenderThreadTid(), SCHED_FIFO | SCHED_RESET_ON_FORK, 1); } else { Loading Loading @@ -11306,6 +11334,9 @@ public class ActivityManagerService extends IActivityManager.Stub if (mAlwaysFinishActivities) { pw.println(" mAlwaysFinishActivities=" + mAlwaysFinishActivities); } if (mAllowSpecifiedFifoScheduling) { pw.println(" mAllowSpecifiedFifoScheduling=true"); } if (dumpAll) { pw.println(" Total persistent processes: " + numPers); pw.println(" mProcessesReady=" + mProcessesReady Loading Loading @@ -17374,6 +17405,12 @@ public class ActivityManagerService extends IActivityManager.Stub } } } if (com.android.window.flags.Flags.fifoPriorityForMajorUiProcesses()) { synchronized (mProcLock) { adjustFifoProcessesIfNeeded(uid, !active /* allowFifo */); } } } final boolean isCameraActiveForUid(@UserIdInt int uid) { Loading @@ -17382,6 +17419,34 @@ public class ActivityManagerService extends IActivityManager.Stub } } /** * This is called when the given uid is using camera. If the uid has top process state, then * cancel the FIFO priority of the high priority processes. */ @VisibleForTesting @GuardedBy("mProcLock") void adjustFifoProcessesIfNeeded(int preemptiveUid, boolean allowSpecifiedFifo) { if (allowSpecifiedFifo == mAllowSpecifiedFifoScheduling) { return; } if (!allowSpecifiedFifo) { final UidRecord uidRec = mProcessList.mActiveUids.get(preemptiveUid); if (uidRec == null || uidRec.getCurProcState() > PROCESS_STATE_TOP) { // To avoid frequent switching by background camera usages, e.g. face unlock, // face detection (auto rotation), screen attention (keep screen on). return; } } mAllowSpecifiedFifoScheduling = allowSpecifiedFifo; for (int i = mSpecifiedFifoProcesses.size() - 1; i >= 0; i--) { final ProcessRecord proc = mSpecifiedFifoProcesses.get(i); if (proc.mState.getSetSchedGroup() != ProcessList.SCHED_GROUP_TOP_APP) { continue; } setFifoPriority(proc, allowSpecifiedFifo /* enable */); } } @GuardedBy("this") final void doStopUidLocked(int uid, final UidRecord uidRec) { mServices.stopInBackgroundLocked(uid);
services/core/java/com/android/server/am/OomAdjuster.java +7 −33 Original line number Diff line number Diff line Loading @@ -72,7 +72,6 @@ import static android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYB import static android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE; import static android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_PHONE_CALL; import static android.media.audio.Flags.roForegroundAudioControl; import static android.os.Process.SCHED_OTHER; import static android.os.Process.THREAD_GROUP_BACKGROUND; import static android.os.Process.THREAD_GROUP_DEFAULT; import static android.os.Process.THREAD_GROUP_RESTRICTED; Loading @@ -81,7 +80,6 @@ import static android.os.Process.THREAD_PRIORITY_DISPLAY; import static android.os.Process.THREAD_PRIORITY_TOP_APP_BOOST; import static android.os.Process.setProcessGroup; import static android.os.Process.setThreadPriority; import static android.os.Process.setThreadScheduler; import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ALL; import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_BACKUP; Loading Loading @@ -3315,22 +3313,10 @@ public class OomAdjuster { // do nothing if we already switched to RT if (oldSchedGroup != SCHED_GROUP_TOP_APP) { app.getWindowProcessController().onTopProcChanged(); if (mService.mUseFifoUiScheduling) { if (app.useFifoUiScheduling()) { // Switch UI pipeline for app to SCHED_FIFO state.setSavedPriority(Process.getThreadPriority(app.getPid())); mService.scheduleAsFifoPriority(app.getPid(), true); if (renderThreadTid != 0) { mService.scheduleAsFifoPriority(renderThreadTid, /* suppressLogs */true); if (DEBUG_OOM_ADJ) { Slog.d("UI_FIFO", "Set RenderThread (TID " + renderThreadTid + ") to FIFO"); } } else { if (DEBUG_OOM_ADJ) { Slog.d("UI_FIFO", "Not setting RenderThread TID"); } } ActivityManagerService.setFifoPriority(app, true /* enable */); } else { // Boost priority for top app UI and render threads setThreadPriority(app.getPid(), THREAD_PRIORITY_TOP_APP_BOOST); Loading @@ -3347,22 +3333,10 @@ public class OomAdjuster { } else if (oldSchedGroup == SCHED_GROUP_TOP_APP && curSchedGroup != SCHED_GROUP_TOP_APP) { app.getWindowProcessController().onTopProcChanged(); if (mService.mUseFifoUiScheduling) { try { if (app.useFifoUiScheduling()) { // Reset UI pipeline to SCHED_OTHER setThreadScheduler(app.getPid(), SCHED_OTHER, 0); ActivityManagerService.setFifoPriority(app, false /* enable */); setThreadPriority(app.getPid(), state.getSavedPriority()); if (renderThreadTid != 0) { setThreadScheduler(renderThreadTid, SCHED_OTHER, 0); } } catch (IllegalArgumentException e) { Slog.w(TAG, "Failed to set scheduling policy, thread does not exist:\n" + e); } catch (SecurityException e) { Slog.w(TAG, "Failed to set scheduling policy, not allowed:\n" + e); } } else { // Reset priority for top app UI and render threads setThreadPriority(app.getPid(), 0); Loading Loading @@ -3557,7 +3531,7 @@ public class OomAdjuster { // {@link SCHED_GROUP_TOP_APP}. We don't check render thread because it // is not ready when attaching. app.getWindowProcessController().onTopProcChanged(); if (mService.mUseFifoUiScheduling) { if (app.useFifoUiScheduling()) { mService.scheduleAsFifoPriority(app.getPid(), true); } else { setThreadPriority(app.getPid(), THREAD_PRIORITY_TOP_APP_BOOST); Loading
services/core/java/com/android/server/am/ProcessRecord.java +13 −0 Original line number Diff line number Diff line Loading @@ -745,6 +745,9 @@ class ProcessRecord implements WindowProcessListener { mOnewayThread = thread; } mWindowProcessController.setThread(thread); if (mWindowProcessController.useFifoUiScheduling()) { mService.mSpecifiedFifoProcesses.add(this); } } @GuardedBy({"mService", "mProcLock"}) Loading @@ -752,9 +755,19 @@ class ProcessRecord implements WindowProcessListener { mThread = null; mOnewayThread = null; mWindowProcessController.setThread(null); if (mWindowProcessController.useFifoUiScheduling()) { mService.mSpecifiedFifoProcesses.remove(this); } mProfile.onProcessInactive(tracker); } @GuardedBy(anyOf = {"mService", "mProcLock"}) boolean useFifoUiScheduling() { return mService.mUseFifoUiScheduling || (mService.mAllowSpecifiedFifoScheduling && mWindowProcessController.useFifoUiScheduling()); } @GuardedBy("mService") int getDyingPid() { return mDyingPid; Loading
services/core/java/com/android/server/wm/WindowProcessController.java +16 −0 Original line number Diff line number Diff line Loading @@ -202,6 +202,12 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio // Whether this process has ever started a service with the BIND_INPUT_METHOD permission. private volatile boolean mHasImeService; /** * Whether this process can use realtime prioirity (SCHED_FIFO) for its UI and render threads * when this process is SCHED_GROUP_TOP_APP. */ private final boolean mUseFifoUiScheduling; /** Whether {@link #mActivities} is not empty. */ private volatile boolean mHasActivities; /** All activities running in the process (exclude destroying). */ Loading Loading @@ -340,6 +346,8 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio // TODO(b/151161907): Remove after support for display-independent (raw) SysUi configs. mIsActivityConfigOverrideAllowed = false; } mUseFifoUiScheduling = com.android.window.flags.Flags.fifoPriorityForMajorUiProcesses() && (isSysUiPackage || mAtm.isCallerRecents(uid)); mCanUseSystemGrammaticalGender = mAtm.mGrammaticalManagerInternal != null && mAtm.mGrammaticalManagerInternal.canGetSystemGrammaticalGender(mUid, Loading Loading @@ -1901,6 +1909,11 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio } } /** Returns {@code true} if the process prefers to use fifo scheduling. */ public boolean useFifoUiScheduling() { return mUseFifoUiScheduling; } @HotPath(caller = HotPath.OOM_ADJUSTMENT) public void onTopProcChanged() { if (mAtm.mVrController.isInterestingToSchedGroup()) { Loading Loading @@ -2078,6 +2091,9 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio } pw.println(); } if (mUseFifoUiScheduling) { pw.println(prefix + " mUseFifoUiScheduling=true"); } final int stateFlags = mActivityStateFlags; if (stateFlags != ACTIVITY_STATE_FLAG_MASK_MIN_TASK_LAYER) { Loading