diff options
| author | 2024-12-26 13:58:47 -0800 | |
|---|---|---|
| committer | 2024-12-26 13:58:47 -0800 | |
| commit | 095285da4ab8442303e82b301091765c19225b62 (patch) | |
| tree | 45b827810b8aa2372b4263f8215831cfa7483845 | |
| parent | 2022fc79e31d1815d0b635fec0d9c8ac053cd58b (diff) | |
Cache all headrooms result in server
Bug: 346604998
Change-Id: Iaab90be4afe9217d15b0eec182d7badad16b8f8c
Flag: android.os.cpu_gpu_headrooms
Test: atest HintManagerServiceTest
| -rw-r--r-- | services/core/java/com/android/server/power/hint/HintManagerService.java | 32 | ||||
| -rw-r--r-- | services/tests/performancehinttests/src/com/android/server/power/hint/HintManagerServiceTest.java | 21 |
2 files changed, 14 insertions, 39 deletions
diff --git a/services/core/java/com/android/server/power/hint/HintManagerService.java b/services/core/java/com/android/server/power/hint/HintManagerService.java index c4e4c422688d..1726f0da9cbe 100644 --- a/services/core/java/com/android/server/power/hint/HintManagerService.java +++ b/services/core/java/com/android/server/power/hint/HintManagerService.java @@ -1594,12 +1594,9 @@ 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; - } + synchronized (mCpuHeadroomLock) { + final CpuHeadroomResult res = mCpuHeadroomCache.get(halParams); + if (res != null) return res; } final boolean shouldCheckUserModeCpuTime = mEnforceCpuHeadroomUserModeCpuTimeCheck @@ -1622,11 +1619,8 @@ 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); - } + synchronized (mCpuHeadroomLock) { + mCpuHeadroomCache.add(halParams, result); } if (shouldCheckUserModeCpuTime) { synchronized (mCpuHeadroomLock) { @@ -1737,12 +1731,9 @@ 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; - } + synchronized (mGpuHeadroomLock) { + final GpuHeadroomResult res = mGpuHeadroomCache.get(halParams); + if (res != null) return res; } // return from HAL directly try { @@ -1751,11 +1742,8 @@ 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); - } + synchronized (mGpuHeadroomLock) { + mGpuHeadroomCache.add(halParams, headroom); } return headroom; } catch (RemoteException e) { diff --git a/services/tests/performancehinttests/src/com/android/server/power/hint/HintManagerServiceTest.java b/services/tests/performancehinttests/src/com/android/server/power/hint/HintManagerServiceTest.java index bd15bd058fcc..cd94c0f6e245 100644 --- a/services/tests/performancehinttests/src/com/android/server/power/hint/HintManagerServiceTest.java +++ b/services/tests/performancehinttests/src/com/android/server/power/hint/HintManagerServiceTest.java @@ -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); |