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

Commit 2a6b5a92 authored by Xiang Wang's avatar Xiang Wang
Browse files

Add support for calculation window size and tids

API-Coverage-Bug: 378780498
Flag: android.os.cpu_gpu_headrooms
Test: atest HeadroomTest PerformanceHintNativeTestCases \
            HintManagerServiceTest PowerHalWrapperAidlTest

Change-Id: Ib25ad89b69bbd06700b84354de6317437f1fd3bd
parent 0c2402a3
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -33479,9 +33479,14 @@ package android.os {
  @FlaggedApi("android.os.cpu_gpu_headrooms") public final class CpuHeadroomParams {
    ctor public CpuHeadroomParams();
    method public int getCalculationType();
    method @IntRange(from=android.os.CpuHeadroomParams.CPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MIN, to=android.os.CpuHeadroomParams.CPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MAX) public long getCalculationWindowMillis();
    method public void setCalculationType(int);
    method public void setCalculationWindowMillis(@IntRange(from=android.os.CpuHeadroomParams.CPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MIN, to=android.os.CpuHeadroomParams.CPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MAX) int);
    method public void setTids(@NonNull int...);
    field public static final int CPU_HEADROOM_CALCULATION_TYPE_AVERAGE = 1; // 0x1
    field public static final int CPU_HEADROOM_CALCULATION_TYPE_MIN = 0; // 0x0
    field public static final int CPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MAX = 10000; // 0x2710
    field public static final int CPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MIN = 50; // 0x32
  }
  public final class CpuUsageInfo implements android.os.Parcelable {
@@ -33734,9 +33739,13 @@ package android.os {
  @FlaggedApi("android.os.cpu_gpu_headrooms") public final class GpuHeadroomParams {
    ctor public GpuHeadroomParams();
    method public int getCalculationType();
    method @IntRange(from=android.os.GpuHeadroomParams.GPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MIN, to=android.os.GpuHeadroomParams.GPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MAX) public int getCalculationWindowMillis();
    method public void setCalculationType(int);
    method public void setCalculationWindowMillis(@IntRange(from=android.os.GpuHeadroomParams.GPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MIN, to=android.os.GpuHeadroomParams.GPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MAX) int);
    field public static final int GPU_HEADROOM_CALCULATION_TYPE_AVERAGE = 1; // 0x1
    field public static final int GPU_HEADROOM_CALCULATION_TYPE_MIN = 0; // 0x0
    field public static final int GPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MAX = 10000; // 0x2710
    field public static final int GPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MIN = 50; // 0x32
  }
  public class Handler {
+70 −0
Original line number Diff line number Diff line
@@ -18,10 +18,13 @@ package android.os;

import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.IntRange;
import android.annotation.NonNull;
import android.os.health.SystemHealthManager;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Arrays;

/**
 * Headroom request params used by {@link SystemHealthManager#getCpuHeadroom(CpuHeadroomParams)}.
@@ -53,6 +56,16 @@ public final class CpuHeadroomParams {
     */
    public static final int CPU_HEADROOM_CALCULATION_TYPE_AVERAGE = 1;

    /**
     * Minimum CPU headroom calculation window size.
     */
    public static final int CPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MIN = 50;

    /**
     * Maximum CPU headroom calculation window size.
     */
    public static final int CPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MAX = 10000;

    /**
     * Sets the headroom calculation type.
     * <p>
@@ -82,6 +95,63 @@ public final class CpuHeadroomParams {
        return validatedType;
    }

    /**
     * Sets the headroom calculation window size in milliseconds.
     * <p>
     *
     * @param windowMillis the window size in milliseconds, ranged from
     *                     [{@link #CPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MIN},
     *                     {@link #CPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MAX}]. The smaller
     *                     the value, the larger fluctuation in value should be expected. The
     *                     default value can be retrieved from the
     *                     {@link #getCalculationWindowMillis}. The device will try to use the
     *                     closest feasible window size to this param.
     * @throws IllegalArgumentException if the window size is not in allowed range.
     */
    public void setCalculationWindowMillis(
            @IntRange(from = CPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MIN, to =
                    CPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MAX) int windowMillis) {
        if (windowMillis < CPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MIN
                || windowMillis > CPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MAX) {
            throw new IllegalArgumentException("Invalid calculation window: " + windowMillis);
        }
        mInternal.calculationWindowMillis = windowMillis;
    }

    /**
     * Gets the headroom calculation window size in milliseconds.
     * <p>
     * This will return the default value chosen by the device if not set.
     */
    public @IntRange(from = CPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MIN, to =
            CPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MAX) long getCalculationWindowMillis() {
        return mInternal.calculationWindowMillis;
    }

    /**
     * Sets the thread TIDs to track.
     * <p>
     * The TIDs should belong to the same of the process that will the headroom call. And they
     * should not have different core affinity.
     * <p>
     * If not set, the headroom will be based on the PID of the process making the call.
     *
     * @param tids non-empty list of TIDs, maximum 5.
     * @throws IllegalArgumentException if the list size is not in allowed range or TID is not
     *                                  positive.
     */
    public void setTids(@NonNull int... tids) {
        if (tids.length == 0 || tids.length > 5) {
            throw new IllegalArgumentException("Invalid number of TIDs: " + tids.length);
        }
        for (int tid : tids) {
            if (tid <= 0) {
                throw new IllegalArgumentException("Invalid TID: " + tid);
            }
        }
        mInternal.tids = Arrays.copyOf(tids, tids.length);
    }

    /**
     * @hide
     */
+2 −0
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@ import android.hardware.power.CpuHeadroomParams;
@JavaDerive(equals = true, toString = true)
parcelable CpuHeadroomParamsInternal {
    boolean usesDeviceHeadroom = false;
    int[] tids;
    int calculationWindowMillis = 1000;
    CpuHeadroomParams.CalculationType calculationType = CpuHeadroomParams.CalculationType.MIN;
    CpuHeadroomParams.SelectionType selectionType = CpuHeadroomParams.SelectionType.ALL;
}
+44 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.os;

import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.IntRange;
import android.os.health.SystemHealthManager;

import java.lang.annotation.Retention;
@@ -53,6 +54,16 @@ public final class GpuHeadroomParams {
     */
    public static final int GPU_HEADROOM_CALCULATION_TYPE_AVERAGE = 1;

    /**
     * Minimum GPU headroom calculation window size.
     */
    public static final int GPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MIN = 50;

    /**
     * Maximum GPU headroom calculation window size.
     */
    public static final int GPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MAX = 10000;

    /**
     * Sets the headroom calculation type.
     * <p>
@@ -82,6 +93,39 @@ public final class GpuHeadroomParams {
        return validatedType;
    }

    /**
     * Sets the headroom calculation window size in milliseconds.
     * <p>
     *
     * @param windowMillis the window size in milliseconds, ranged from
     *                     [{@link #GPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MIN},
     *                     {@link #GPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MAX}]. The smaller
     *                     the value, the larger fluctuation in value should be expected. The
     *                     default value can be retrieved from the
     *                     {@link #getCalculationWindowMillis}. If the device will try to use the
     *                     closest feasible window size to this param.
     * @throws IllegalArgumentException if the window is invalid.
     */
    public void setCalculationWindowMillis(
            @IntRange(from = GPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MIN, to =
                    GPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MAX) int windowMillis) {
        if (windowMillis < GPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MIN
                || windowMillis > GPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MAX) {
            throw new IllegalArgumentException("Invalid calculation window: " + windowMillis);
        }
        mInternal.calculationWindowMillis = windowMillis;
    }

    /**
     * Gets the headroom calculation window size in milliseconds.
     * <p>
     * This will return the default value chosen by the device if not set.
     */
    public @IntRange(from = GPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MIN, to =
            GPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MAX) int getCalculationWindowMillis() {
        return mInternal.calculationWindowMillis;
    }

    /**
     * @hide
     */
+1 −0
Original line number Diff line number Diff line
@@ -24,5 +24,6 @@ import android.hardware.power.GpuHeadroomParams;
 */
@JavaDerive(equals = true, toString = true)
parcelable GpuHeadroomParamsInternal {
    int calculationWindowMillis = 1000;
    GpuHeadroomParams.CalculationType calculationType = GpuHeadroomParams.CalculationType.MIN;
}
Loading