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

Commit a115b12e authored by Matt Buckley's avatar Matt Buckley
Browse files

Allow ADPF WorkDuration CPU duration to be zero

This patch updates the checks, tests, and documentation to ensure ADPF
CPU == 0 is allowed, and instead checks to make sure that both CPU
and GPU cannot be 0 at the same time.

Bug: 323226967
Test: atest PerformanceHintManagerTest
Test: atest WorkDurationTest
Test: atest HintManagerServiceTest
Change-Id: I6aea1d6e5d445ba21af72ac8187cc1ce15ce8b05
parent ca876884
Loading
Loading
Loading
Loading
+16 −8
Original line number Diff line number Diff line
@@ -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,
+8 −5
Original line number Diff line number Diff line
@@ -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;
    }
+17 −1
Original line number Diff line number Diff line
@@ -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));
+3 −2
Original line number Diff line number Diff line
@@ -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;
}

+13 −3
Original line number Diff line number Diff line
@@ -691,14 +691,24 @@ 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()));
            }
        }
Loading