Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f1347d33 authored by Jorim Jaggi's avatar Jorim Jaggi
Browse files

Only promote remote animator to top sched group during animation

When running remote animation or SystemUI has requested top
priority (for example. when notifacition shade is open on top of
application), make sure to let it have exclusive top sched group
access. This reduces contention between app and entity running
remote animation as remote animator process gets exclusive access
to certain CPUs.

Test: Manual inspection of trace
Test: asit/perf/appstartup_non_hermetic_cyclic_dropcache_test
Bug: 157407136
Change-Id: I1bc495a1c536656f277a8e4aefc72f88d596c97a
parent 88e86e64
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -1710,6 +1710,12 @@ public class ActivityManagerService extends IActivityManager.Stub
     */
    @Nullable ContentCaptureManagerInternal mContentCaptureService;
    /**
     * Set of {@link ProcessRecord} that have either {@link ProcessRecord#hasTopUi()} or
     * {@link ProcessRecord#runningRemoteAnimation} set to {@code true}.
     */
    final ArraySet<ProcessRecord> mTopUiOrRunningRemoteAnimApps = new ArraySet<>();
    final class UiHandler extends Handler {
        public UiHandler() {
            super(com.android.server.UiThread.get().getLooper(), null, true);
@@ -14738,6 +14744,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        mProcessesToGc.remove(app);
        mPendingPssProcesses.remove(app);
        mTopUiOrRunningRemoteAnimApps.remove(app);
        ProcessList.abortNextPssTime(app.procStateMemTracker);
        // Dismiss any open dialogs.
@@ -18526,6 +18533,22 @@ public class ActivityManagerService extends IActivityManager.Stub
        return proc;
    }
    /**
     * @return {@code true} if {@link #mTopUiOrRunningRemoteAnimApps} set contains {@code app} or when there are no apps
     *         in this list, an false otherwise.
     */
    boolean containsTopUiOrRunningRemoteAnimOrEmptyLocked(ProcessRecord app) {
        return mTopUiOrRunningRemoteAnimApps.isEmpty() || mTopUiOrRunningRemoteAnimApps.contains(app);
    }
    void addTopUiOrRunningRemoteAnim(ProcessRecord app) {
        mTopUiOrRunningRemoteAnimApps.add(app);
    }
    void removeTopUiOrRunningRemoteAnim(ProcessRecord app) {
        mTopUiOrRunningRemoteAnimApps.remove(app);
    }
    @Override
    public boolean dumpHeap(String process, int userId, boolean managed, boolean mallocInfo,
            boolean runGc, String path, ParcelFileDescriptor fd, RemoteCallback finishCallback) {
+24 −5
Original line number Diff line number Diff line
@@ -1151,8 +1151,17 @@ public final class OomAdjuster {
            // is currently showing UI.
            app.systemNoUi = true;
            if (app == topApp) {
                app.systemNoUi = false;
                // If specific system app has set ProcessRecord.mHasTopUi or is running a remote
                // animation (ProcessRecord.runningRemoteAnimation), this will prevent topApp
                // to use SCHED_GROUP_TOP_APP to ensure process with mHasTopUi will have exclusive
                // access to configured cores.
                if (mService.containsTopUiOrRunningRemoteAnimOrEmptyLocked(app)) {
                    app.setCurrentSchedulingGroup(ProcessList.SCHED_GROUP_TOP_APP);
                } else {
                    app.setCurrentSchedulingGroup(ProcessList.SCHED_GROUP_DEFAULT);
                }
                app.systemNoUi = false;

                app.adjType = "pers-top-activity";
            } else if (app.hasTopUi()) {
                // sched group/proc state adjustment is below
@@ -1193,10 +1202,20 @@ public final class OomAdjuster {

        boolean foregroundActivities = false;
        if (PROCESS_STATE_CUR_TOP == PROCESS_STATE_TOP && app == topApp) {
            // The last app on the list is the foreground app.

            // If specific system app has set ProcessRecord.mHasTopUi or is running a remote
            // animation (ProcessRecord.runningRemoteAnimation), this will prevent topApp
            // to use SCHED_GROUP_TOP_APP to ensure process with mHasTopUi will have exclusive
            // access to configured cores.
            if (mService.containsTopUiOrRunningRemoteAnimOrEmptyLocked(app)) {
                adj = ProcessList.FOREGROUND_APP_ADJ;
                schedGroup = ProcessList.SCHED_GROUP_TOP_APP;
                app.adjType = "top-activity";
            } else {
                adj = ProcessList.FOREGROUND_APP_ADJ;
                schedGroup = ProcessList.SCHED_GROUP_DEFAULT;
                app.adjType = "top-activity-behind-topui";
            }
            foregroundActivities = true;
            procState = PROCESS_STATE_CUR_TOP;
            if (DEBUG_OOM_ADJ_REASON || logUid == appUid) {
+10 −0
Original line number Diff line number Diff line
@@ -1268,6 +1268,7 @@ class ProcessRecord implements WindowProcessListener {
    void setHasTopUi(boolean hasTopUi) {
        mHasTopUi = hasTopUi;
        mWindowProcessController.setHasTopUi(hasTopUi);
        updateTopUiOrRunningRemoteAnim();
    }

    boolean hasTopUi() {
@@ -1518,10 +1519,19 @@ class ProcessRecord implements WindowProcessListener {
                Slog.i(TAG, "Setting runningRemoteAnimation=" + runningRemoteAnimation
                        + " for pid=" + pid);
            }
            updateTopUiOrRunningRemoteAnim();
            mService.updateOomAdjLocked(this, true, OomAdjuster.OOM_ADJ_REASON_UI_VISIBILITY);
        }
    }

    void updateTopUiOrRunningRemoteAnim() {
        if (runningRemoteAnimation || hasTopUi()) {
            mService.addTopUiOrRunningRemoteAnim(this);
        } else {
            mService.removeTopUiOrRunningRemoteAnim(this);
        }
    }

    public long getInputDispatchingTimeout() {
        return mWindowProcessController.getInputDispatchingTimeout();
    }
+17 −0
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ import static com.android.server.am.ProcessList.VISIBLE_APP_ADJ;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.AdditionalAnswers.answer;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.anyLong;
@@ -170,6 +171,7 @@ public class MockingOomAdjusterTests {
                mock(OomAdjProfiler.class));
        doReturn(new ActivityManagerService.ProcessChangeItem()).when(sService)
                .enqueueProcessChangeItemLocked(anyInt(), anyInt());
        doReturn(true).when(sService).containsTopUiOrRunningRemoteAnimOrEmptyLocked(any());
        sService.mOomAdjuster = new OomAdjuster(sService, sService.mProcessList,
                mock(ActiveUids.class));
        sService.mOomAdjuster.mAdjSeq = 10000;
@@ -264,6 +266,21 @@ public class MockingOomAdjusterTests {
        assertProcStates(app, PROCESS_STATE_TOP_SLEEPING, VISIBLE_APP_ADJ, SCHED_GROUP_TOP_APP);
    }

    @SuppressWarnings("GuardedBy")
    @Test
    public void testUpdateOomAdj_DoOne_TopApp_PreemptedByTopUi() {
        ProcessRecord app = spy(makeDefaultProcessRecord(MOCKAPP_PID, MOCKAPP_UID,
                MOCKAPP_PROCESSNAME, MOCKAPP_PACKAGENAME, true));
        doReturn(PROCESS_STATE_TOP).when(sService.mAtmInternal).getTopProcessState();
        doReturn(app).when(sService).getTopAppLocked();
        doReturn(false).when(sService).containsTopUiOrRunningRemoteAnimOrEmptyLocked(eq(app));
        sService.mWakefulness = PowerManagerInternal.WAKEFULNESS_AWAKE;
        sService.mOomAdjuster.updateOomAdjLocked(app, false, OomAdjuster.OOM_ADJ_REASON_NONE);
        doReturn(null).when(sService).getTopAppLocked();

        assertProcStates(app, PROCESS_STATE_TOP, FOREGROUND_APP_ADJ, SCHED_GROUP_DEFAULT);
    }

    @SuppressWarnings("GuardedBy")
    @Test
    public void testUpdateOomAdj_DoOne_RunningInstrumentation() {