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

Commit 70de085b authored by Peiyong Lin's avatar Peiyong Lin
Browse files

[Reland] Add API support for GPU work duration report in ADPF.

Previously we introduced the reportActualWorkDuration API without
specifying the work duration for each components, this patch introduces
a separate API that allows clients to send work duration with each
component to allow fine grained scheduling strategy.

Bug: b/284324521
Test: atest PerformanceHintNativeTestCases
Test: atest PerformanceHintManagerTest
Test: atest HintManagerServiceTest
Change-Id: I7c6712267dc90ca2ce9b2cc54c640820343f6931
parent a8d03d7b
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -33159,6 +33159,7 @@ package android.os {
  public static class PerformanceHintManager.Session implements java.io.Closeable {
    method public void close();
    method public void reportActualWorkDuration(long);
    method @FlaggedApi("android.os.adpf_gpu_report_actual_work_duration") public void reportActualWorkDuration(@NonNull android.os.WorkDuration);
    method @FlaggedApi("android.os.adpf_prefer_power_efficiency") public void setPreferPowerEfficiency(boolean);
    method public void setThreads(@NonNull int[]);
    method public void updateTargetWorkDuration(long);
@@ -33501,6 +33502,7 @@ package android.os {
    method public static boolean setCurrentTimeMillis(long);
    method public static void sleep(long);
    method public static long uptimeMillis();
    method @FlaggedApi("android.os.adpf_gpu_report_actual_work_duration") public static long uptimeNanos();
  }
  public class TestLooperManager {
@@ -33766,6 +33768,22 @@ package android.os {
    method @RequiresPermission(android.Manifest.permission.VIBRATE) public final void vibrate(@NonNull android.os.CombinedVibration, @Nullable android.os.VibrationAttributes);
  }
  @FlaggedApi("android.os.adpf_gpu_report_actual_work_duration") public final class WorkDuration implements android.os.Parcelable {
    ctor public WorkDuration();
    ctor public WorkDuration(long, long, long, long);
    method public int describeContents();
    method public long getActualCpuDurationNanos();
    method public long getActualGpuDurationNanos();
    method public long getActualTotalDurationNanos();
    method public long getWorkPeriodStartTimestampNanos();
    method public void setActualCpuDurationNanos(long);
    method public void setActualGpuDurationNanos(long);
    method public void setActualTotalDurationNanos(long);
    method public void setWorkPeriodStartTimestampNanos(long);
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.os.WorkDuration> CREATOR;
  }
  public class WorkSource implements android.os.Parcelable {
    ctor public WorkSource();
    ctor public WorkSource(android.os.WorkSource);
+3 −0
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@

package android.os;

import android.os.WorkDuration;

/** {@hide} */
oneway interface IHintSession {
    void updateTargetWorkDuration(long targetDurationNanos);
@@ -24,4 +26,5 @@ oneway interface IHintSession {
    void close();
    void sendHint(int hint);
    void setMode(int mode, boolean enabled);
    void reportActualWorkDuration2(in WorkDuration[] workDurations);
}
+38 −1
Original line number Diff line number Diff line
@@ -103,7 +103,7 @@ public final class PerformanceHintManager {
     * Any call in this class will change its internal data, so you must do your own thread
     * safety to protect from racing.
     *
     * All timings should be in {@link SystemClock#elapsedRealtimeNanos()}.
     * All timings should be in {@link SystemClock#uptimeNanos()}.
     */
    public static class Session implements Closeable {
        private long mNativeSessionPtr;
@@ -269,6 +269,40 @@ public final class PerformanceHintManager {
        public @Nullable int[] getThreadIds() {
            return nativeGetThreadIds(mNativeSessionPtr);
        }

        /**
         * Reports the work duration for the last cycle of work.
         *
         * The system will attempt to adjust the core placement of the threads within the thread
         * group and/or the frequency of the core on which they are run to bring the actual duration
         * 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.
         */
        @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.");
            }
            if (workDuration.mActualTotalDurationNanos <= 0) {
                throw new IllegalArgumentException("the actual total duration should be positive.");
            }
            if (workDuration.mActualCpuDurationNanos <= 0) {
                throw new IllegalArgumentException("the actual CPU duration should be positive.");
            }
            if (workDuration.mActualGpuDurationNanos < 0) {
                throw new IllegalArgumentException(
                    "the actual GPU duration should be non negative.");
            }
            nativeReportActualWorkDuration(mNativeSessionPtr,
                    workDuration.mWorkPeriodStartTimestampNanos,
                    workDuration.mActualTotalDurationNanos,
                    workDuration.mActualCpuDurationNanos, workDuration.mActualGpuDurationNanos);
        }
    }

    private static native long nativeAcquireManager();
@@ -285,4 +319,7 @@ public final class PerformanceHintManager {
    private static native void nativeSetThreads(long nativeSessionPtr, int[] tids);
    private static native void nativeSetPreferPowerEfficiency(long nativeSessionPtr,
            boolean enabled);
    private static native void nativeReportActualWorkDuration(long nativeSessionPtr,
            long workPeriodStartTimestampNanos, long actualTotalDurationNanos,
            long actualCpuDurationNanos, long actualGpuDurationNanos);
}
+2 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.os;

import android.annotation.FlaggedApi;
import android.annotation.NonNull;
import android.app.IAlarmManager;
import android.app.time.UnixEpochTime;
@@ -205,8 +206,8 @@ public final class SystemClock {
     * Returns nanoseconds since boot, not counting time spent in deep sleep.
     *
     * @return nanoseconds of non-sleep uptime since boot.
     * @hide
     */
    @FlaggedApi(Flags.FLAG_ADPF_GPU_REPORT_ACTUAL_WORK_DURATION)
    @CriticalNative
    @android.ravenwood.annotation.RavenwoodReplace
    public static native long uptimeNanos();
+19 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.os;

parcelable WorkDuration cpp_header "android/WorkDuration.h";
 No newline at end of file
Loading