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

Commit 8edd1b3a authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Cache all headrooms result in server" into main

parents 5bc0cc3a 095285da
Loading
Loading
Loading
Loading
+10 −22
Original line number Diff line number Diff line
@@ -1594,13 +1594,10 @@ public final class HintManagerService extends SystemService {
                }
                halParams.tids = params.tids;
            }
            if (halParams.calculationWindowMillis
                    == mDefaultCpuHeadroomCalculationWindowMillis) {
            synchronized (mCpuHeadroomLock) {
                final CpuHeadroomResult res = mCpuHeadroomCache.get(halParams);
                if (res != null) return res;
            }
            }
            final boolean shouldCheckUserModeCpuTime =
                    mEnforceCpuHeadroomUserModeCpuTimeCheck
                            || (UserHandle.getAppId(uid) != Process.SYSTEM_UID
@@ -1622,12 +1619,9 @@ public final class HintManagerService extends SystemService {
                    Slog.wtf(TAG, "CPU headroom from Power HAL is invalid");
                    return null;
                }
                if (halParams.calculationWindowMillis
                        == mDefaultCpuHeadroomCalculationWindowMillis) {
                synchronized (mCpuHeadroomLock) {
                    mCpuHeadroomCache.add(halParams, result);
                }
                }
                if (shouldCheckUserModeCpuTime) {
                    synchronized (mCpuHeadroomLock) {
                        mUidToLastUserModeJiffies.put(uid, mLastCpuUserModeJiffies);
@@ -1737,13 +1731,10 @@ public final class HintManagerService extends SystemService {
            final GpuHeadroomParams halParams = new GpuHeadroomParams();
            halParams.calculationType = params.calculationType;
            halParams.calculationWindowMillis = params.calculationWindowMillis;
            if (halParams.calculationWindowMillis
                    == mDefaultGpuHeadroomCalculationWindowMillis) {
            synchronized (mGpuHeadroomLock) {
                final GpuHeadroomResult res = mGpuHeadroomCache.get(halParams);
                if (res != null) return res;
            }
            }
            // return from HAL directly
            try {
                final GpuHeadroomResult headroom = mPowerHal.getGpuHeadroom(halParams);
@@ -1751,12 +1742,9 @@ public final class HintManagerService extends SystemService {
                    Slog.wtf(TAG, "GPU headroom from Power HAL is invalid");
                    return null;
                }
                if (halParams.calculationWindowMillis
                        == mDefaultGpuHeadroomCalculationWindowMillis) {
                synchronized (mGpuHeadroomLock) {
                    mGpuHeadroomCache.add(halParams, headroom);
                }
                }
                return headroom;
            } catch (RemoteException e) {
                Slog.e(TAG, "Failed to get GPU headroom from Power HAL", e);
+4 −17
Original line number Diff line number Diff line
@@ -1411,7 +1411,6 @@ public class HintManagerServiceTest {
        halParams3.tids = tids;
        halParams3.calculationType = CpuHeadroomParams.CalculationType.AVERAGE;

        // this params should not be cached as the window is not default
        CpuHeadroomParamsInternal params4 = new CpuHeadroomParamsInternal();
        params4.calculationWindowMillis = 123;
        CpuHeadroomParams halParams4 = new CpuHeadroomParams();
@@ -1450,11 +1449,7 @@ public class HintManagerServiceTest {
        assertEquals(halRet2, service.getBinderServiceInstance().getCpuHeadroom(params2));
        assertEquals(halRet3, service.getBinderServiceInstance().getCpuHeadroom(params3));
        assertEquals(halRet4, service.getBinderServiceInstance().getCpuHeadroom(params4));
        verify(mIPowerMock, times(1)).getCpuHeadroom(any());
        verify(mIPowerMock, times(0)).getCpuHeadroom(eq(halParams1));
        verify(mIPowerMock, times(0)).getCpuHeadroom(eq(halParams2));
        verify(mIPowerMock, times(0)).getCpuHeadroom(eq(halParams3));
        verify(mIPowerMock, times(1)).getCpuHeadroom(eq(halParams4));
        verify(mIPowerMock, times(0)).getCpuHeadroom(any());

        // after 500ms more it should be served with cache
        Thread.sleep(500);
@@ -1463,11 +1458,7 @@ public class HintManagerServiceTest {
        assertEquals(halRet2, service.getBinderServiceInstance().getCpuHeadroom(params2));
        assertEquals(halRet3, service.getBinderServiceInstance().getCpuHeadroom(params3));
        assertEquals(halRet4, service.getBinderServiceInstance().getCpuHeadroom(params4));
        verify(mIPowerMock, times(1)).getCpuHeadroom(any());
        verify(mIPowerMock, times(0)).getCpuHeadroom(eq(halParams1));
        verify(mIPowerMock, times(0)).getCpuHeadroom(eq(halParams2));
        verify(mIPowerMock, times(0)).getCpuHeadroom(eq(halParams3));
        verify(mIPowerMock, times(1)).getCpuHeadroom(eq(halParams4));
        verify(mIPowerMock, times(0)).getCpuHeadroom(any());

        // after 1+ seconds it should be served from HAL as it exceeds 1000 millis interval
        Thread.sleep(600);
@@ -1574,18 +1565,14 @@ public class HintManagerServiceTest {
        clearInvocations(mIPowerMock);
        assertEquals(halRet1, service.getBinderServiceInstance().getGpuHeadroom(params1));
        assertEquals(halRet2, service.getBinderServiceInstance().getGpuHeadroom(params2));
        verify(mIPowerMock, times(1)).getGpuHeadroom(any());
        verify(mIPowerMock, times(0)).getGpuHeadroom(eq(halParams1));
        verify(mIPowerMock, times(1)).getGpuHeadroom(eq(halParams2));
        verify(mIPowerMock, times(0)).getGpuHeadroom(any());

        // after 500ms it should be served with cache
        Thread.sleep(500);
        clearInvocations(mIPowerMock);
        assertEquals(halRet1, service.getBinderServiceInstance().getGpuHeadroom(params1));
        assertEquals(halRet2, service.getBinderServiceInstance().getGpuHeadroom(params2));
        verify(mIPowerMock, times(1)).getGpuHeadroom(any());
        verify(mIPowerMock, times(0)).getGpuHeadroom(eq(halParams1));
        verify(mIPowerMock, times(1)).getGpuHeadroom(eq(halParams2));
        verify(mIPowerMock, times(0)).getGpuHeadroom(any());

        // after 1+ seconds it should be served from HAL as it exceeds 1000 millis interval
        Thread.sleep(600);