diff options
| author | 2024-02-05 18:23:17 +0000 | |
|---|---|---|
| committer | 2024-02-05 18:23:17 +0000 | |
| commit | 6fba7c5f919d9c829fb3fb89a67e9a959932fade (patch) | |
| tree | bc97a3c2f718fc552efde877e482cfeb1a2b8c8c | |
| parent | 1bbf379bc41e0f0a0411ac6a48fff5ab0a530467 (diff) | |
| parent | a115b12ebda32a0dea5f2afbb02a97d25d43c982 (diff) | |
Merge "Allow ADPF WorkDuration CPU duration to be zero" into main
6 files changed, 64 insertions, 24 deletions
diff --git a/core/java/android/os/PerformanceHintManager.java b/core/java/android/os/PerformanceHintManager.java index e6bfcd728a52..224b10d0eaca 100644 --- a/core/java/android/os/PerformanceHintManager.java +++ b/core/java/android/os/PerformanceHintManager.java @@ -313,25 +313,33 @@ public final class PerformanceHintManager { * close to the target duration. * * @param workDuration the work duration of each component. - * @throws IllegalArgumentException if work period start timestamp is not positive, or - * actual total duration is not positive, or actual CPU duration is not positive, - * or actual GPU duration is negative. + * @throws IllegalArgumentException if + * the work period start timestamp or the total duration are less than or equal to zero, + * if either the actual CPU duration or actual GPU duration is less than zero, + * or if both the CPU and GPU durations are zero. */ @FlaggedApi(Flags.FLAG_ADPF_GPU_REPORT_ACTUAL_WORK_DURATION) public void reportActualWorkDuration(@NonNull WorkDuration workDuration) { if (workDuration.mWorkPeriodStartTimestampNanos <= 0) { throw new IllegalArgumentException( - "the work period start timestamp should be positive."); + "the work period start timestamp should be greater than zero."); } if (workDuration.mActualTotalDurationNanos <= 0) { - throw new IllegalArgumentException("the actual total duration should be positive."); + throw new IllegalArgumentException( + "the actual total duration should be greater than zero."); } - if (workDuration.mActualCpuDurationNanos <= 0) { - throw new IllegalArgumentException("the actual CPU duration should be positive."); + if (workDuration.mActualCpuDurationNanos < 0) { + throw new IllegalArgumentException( + "the actual CPU duration should be greater than or equal to zero."); } if (workDuration.mActualGpuDurationNanos < 0) { throw new IllegalArgumentException( - "the actual GPU duration should be non negative."); + "the actual GPU duration should be greater than or equal to zero."); + } + if (workDuration.mActualCpuDurationNanos + workDuration.mActualGpuDurationNanos <= 0) { + throw new IllegalArgumentException( + "either the actual CPU duration or the actual GPU duration should be greater" + + "than zero."); } nativeReportActualWorkDuration(mNativeSessionPtr, workDuration.mWorkPeriodStartTimestampNanos, diff --git a/core/java/android/os/WorkDuration.java b/core/java/android/os/WorkDuration.java index 2ebcd830be29..5a54e90372fc 100644 --- a/core/java/android/os/WorkDuration.java +++ b/core/java/android/os/WorkDuration.java @@ -83,7 +83,7 @@ public final class WorkDuration implements Parcelable { public void setWorkPeriodStartTimestampNanos(long workPeriodStartTimestampNanos) { if (workPeriodStartTimestampNanos <= 0) { throw new IllegalArgumentException( - "the work period start timestamp should be positive."); + "the work period start timestamp should be greater than zero."); } mWorkPeriodStartTimestampNanos = workPeriodStartTimestampNanos; } @@ -95,7 +95,8 @@ public final class WorkDuration implements Parcelable { */ public void setActualTotalDurationNanos(long actualTotalDurationNanos) { if (actualTotalDurationNanos <= 0) { - throw new IllegalArgumentException("the actual total duration should be positive."); + throw new IllegalArgumentException( + "the actual total duration should be greater than zero."); } mActualTotalDurationNanos = actualTotalDurationNanos; } @@ -106,8 +107,9 @@ public final class WorkDuration implements Parcelable { * All timings should be in {@link SystemClock#uptimeNanos()}. */ public void setActualCpuDurationNanos(long actualCpuDurationNanos) { - if (actualCpuDurationNanos <= 0) { - throw new IllegalArgumentException("the actual CPU duration should be positive."); + if (actualCpuDurationNanos < 0) { + throw new IllegalArgumentException( + "the actual CPU duration should be greater than or equal to zero."); } mActualCpuDurationNanos = actualCpuDurationNanos; } @@ -119,7 +121,8 @@ public final class WorkDuration implements Parcelable { */ public void setActualGpuDurationNanos(long actualGpuDurationNanos) { if (actualGpuDurationNanos < 0) { - throw new IllegalArgumentException("the actual GPU duration should be non negative."); + throw new IllegalArgumentException( + "the actual GPU duration should be greater than or equal to zero."); } mActualGpuDurationNanos = actualGpuDurationNanos; } diff --git a/core/tests/coretests/src/android/os/PerformanceHintManagerTest.java b/core/tests/coretests/src/android/os/PerformanceHintManagerTest.java index a28bb69244eb..2bd563191134 100644 --- a/core/tests/coretests/src/android/os/PerformanceHintManagerTest.java +++ b/core/tests/coretests/src/android/os/PerformanceHintManagerTest.java @@ -219,6 +219,22 @@ public class PerformanceHintManagerTest { workDuration.setActualGpuDurationNanos(6); s.reportActualWorkDuration(workDuration); } + { + WorkDuration workDuration = new WorkDuration(); + workDuration.setWorkPeriodStartTimestampNanos(1); + workDuration.setActualTotalDurationNanos(14); + workDuration.setActualCpuDurationNanos(0); + workDuration.setActualGpuDurationNanos(6); + s.reportActualWorkDuration(workDuration); + } + { + WorkDuration workDuration = new WorkDuration(); + workDuration.setWorkPeriodStartTimestampNanos(1); + workDuration.setActualTotalDurationNanos(14); + workDuration.setActualCpuDurationNanos(7); + workDuration.setActualGpuDurationNanos(0); + s.reportActualWorkDuration(workDuration); + } } @Test @@ -242,7 +258,7 @@ public class PerformanceHintManagerTest { s.reportActualWorkDuration(new WorkDuration(1, 12, -1, 6, 1)); }); assertThrows(IllegalArgumentException.class, () -> { - s.reportActualWorkDuration(new WorkDuration(1, 12, 0, 6, 1)); + s.reportActualWorkDuration(new WorkDuration(1, 12, 0, 0, 1)); }); assertThrows(IllegalArgumentException.class, () -> { s.reportActualWorkDuration(new WorkDuration(1, 12, 8, -1, 1)); diff --git a/native/android/performance_hint.cpp b/native/android/performance_hint.cpp index c5729444507e..279f9d682b9f 100644 --- a/native/android/performance_hint.cpp +++ b/native/android/performance_hint.cpp @@ -484,8 +484,9 @@ int APerformanceHint_reportActualWorkDuration2(APerformanceHintSession* session, WorkDuration& workDuration = *static_cast<WorkDuration*>(workDurationPtr); VALIDATE_INT(workDuration.workPeriodStartTimestampNanos, > 0) VALIDATE_INT(workDuration.actualTotalDurationNanos, > 0) - VALIDATE_INT(workDuration.actualCpuDurationNanos, > 0) + VALIDATE_INT(workDuration.actualCpuDurationNanos, >= 0) VALIDATE_INT(workDuration.actualGpuDurationNanos, >= 0) + VALIDATE_INT(workDuration.actualGpuDurationNanos + workDuration.actualCpuDurationNanos, > 0) return session->reportActualWorkDuration(workDurationPtr); } @@ -517,7 +518,7 @@ void AWorkDuration_setActualTotalDurationNanos(AWorkDuration* aWorkDuration, void AWorkDuration_setActualCpuDurationNanos(AWorkDuration* aWorkDuration, int64_t actualCpuDurationNanos) { VALIDATE_PTR(aWorkDuration) - WARN_INT(actualCpuDurationNanos, > 0) + WARN_INT(actualCpuDurationNanos, >= 0) static_cast<WorkDuration*>(aWorkDuration)->actualCpuDurationNanos = actualCpuDurationNanos; } 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 6f754391f1ca..35717af962ef 100644 --- a/services/core/java/com/android/server/power/hint/HintManagerService.java +++ b/services/core/java/com/android/server/power/hint/HintManagerService.java @@ -691,16 +691,26 @@ public final class HintManagerService extends SystemService { TextUtils.formatSimple("Actual total duration (%d) should be greater than 0", workDuration.getActualTotalDurationNanos())); } - if (workDuration.getActualCpuDurationNanos() <= 0) { + if (workDuration.getActualCpuDurationNanos() < 0) { throw new IllegalArgumentException( - TextUtils.formatSimple("Actual CPU duration (%d) should be greater than 0", + TextUtils.formatSimple( + "Actual CPU duration (%d) should be greater than or equal to 0", workDuration.getActualCpuDurationNanos())); } if (workDuration.getActualGpuDurationNanos() < 0) { throw new IllegalArgumentException( - TextUtils.formatSimple("Actual GPU duration (%d) should be non negative", + TextUtils.formatSimple( + "Actual GPU duration (%d) should greater than or equal to 0", workDuration.getActualGpuDurationNanos())); } + if (workDuration.getActualCpuDurationNanos() + + workDuration.getActualGpuDurationNanos() <= 0) { + throw new IllegalArgumentException( + TextUtils.formatSimple( + "The actual CPU duration (%d) and the actual GPU duration (%d)" + + " should not both be 0", workDuration.getActualCpuDurationNanos(), + workDuration.getActualGpuDurationNanos())); + } } private void onProcStateChanged(boolean updateAllowed) { diff --git a/services/tests/servicestests/src/com/android/server/power/hint/HintManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/power/hint/HintManagerServiceTest.java index ffb3bce33a27..4ab9d3ecf624 100644 --- a/services/tests/servicestests/src/com/android/server/power/hint/HintManagerServiceTest.java +++ b/services/tests/servicestests/src/com/android/server/power/hint/HintManagerServiceTest.java @@ -90,10 +90,12 @@ public class HintManagerServiceTest { private static final long[] DURATIONS_ZERO = new long[] {}; private static final long[] TIMESTAMPS_ZERO = new long[] {}; private static final long[] TIMESTAMPS_TWO = new long[] {1L, 2L}; - private static final WorkDuration[] WORK_DURATIONS_THREE = new WorkDuration[] { + private static final WorkDuration[] WORK_DURATIONS_FIVE = new WorkDuration[] { new WorkDuration(1L, 11L, 8L, 4L, 1L), new WorkDuration(2L, 13L, 8L, 6L, 2L), new WorkDuration(3L, 333333333L, 8L, 333333333L, 3L), + new WorkDuration(2L, 13L, 0L, 6L, 2L), + new WorkDuration(2L, 13L, 8L, 0L, 2L), }; @Mock private Context mContext; @@ -609,9 +611,9 @@ public class HintManagerServiceTest { .createHintSession(token, SESSION_TIDS_A, DEFAULT_TARGET_DURATION); a.updateTargetWorkDuration(100L); - a.reportActualWorkDuration2(WORK_DURATIONS_THREE); + a.reportActualWorkDuration2(WORK_DURATIONS_FIVE); verify(mNativeWrapperMock, times(1)).halReportActualWorkDuration(anyLong(), - eq(WORK_DURATIONS_THREE)); + eq(WORK_DURATIONS_FIVE)); assertThrows(IllegalArgumentException.class, () -> { a.reportActualWorkDuration2(new WorkDuration[] {}); @@ -627,7 +629,7 @@ public class HintManagerServiceTest { }); assertThrows(IllegalArgumentException.class, () -> { - a.reportActualWorkDuration2(new WorkDuration[] {new WorkDuration(1L, 11L, 0L, 4L, 1L)}); + a.reportActualWorkDuration2(new WorkDuration[] {new WorkDuration(1L, 11L, 0L, 0L, 1L)}); }); assertThrows(IllegalArgumentException.class, () -> { @@ -648,7 +650,7 @@ public class HintManagerServiceTest { latch.await(); assertFalse(service.mUidObserver.isUidForeground(a.mUid)); - a.reportActualWorkDuration2(WORK_DURATIONS_THREE); + a.reportActualWorkDuration2(WORK_DURATIONS_FIVE); verify(mNativeWrapperMock, never()).halReportActualWorkDuration(anyLong(), any(), any()); } } |