Skip to content

Commit 5235c9d

Browse files
AndroidMatt1Android (Google) Code Review
authored andcommitted
Merge "Revert "Revert "Add public ADPF load hints with better rate limi..."" into main
2 parents e4002e3 + 43a8bd9 commit 5235c9d

2 files changed

Lines changed: 75 additions & 1 deletion

File tree

include/android/performance_hint.h

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,23 @@
1919
*
2020
* APerformanceHint allows apps to create performance hint sessions for groups
2121
* of threads, and provide hints to the system about the workload of those threads,
22-
* to help the system more accurately allocate power for them. It is the NDK
22+
* to help the system more accurately allocate resources for them. It is the NDK
2323
* counterpart to the Java PerformanceHintManager SDK API.
2424
*
25+
* This API is intended for periodic workloads, such as frame production. Clients are
26+
* expected to create an instance of APerformanceHintManager, create a session with
27+
* that, and then set a target duration for the session. Then, they can report the actual
28+
* work duration at the end of each cycle to inform the framework about how long those
29+
* workloads are taking. The framework will then compare the actual durations to the target
30+
* duration and attempt to help the client reach a steady state under the target.
31+
*
32+
* Unlike reportActualWorkDuration, the "notify..." hints are intended to be sent in
33+
* advance of large changes in the workload, to prevent them from going over the target
34+
* when there is a sudden, unforseen change. Their effects are intended to last for only
35+
* one cycle, after which reportActualWorkDuration will have a chance to catch up.
36+
* These hints should be used judiciously, only in cases where the workload is changing
37+
* substantially. To enforce that, they are tracked using a per-app rate limiter to avoid
38+
* excessive hinting and encourage clients to be mindful about when to send them.
2539
* @{
2640
*/
2741

@@ -249,6 +263,54 @@ int APerformanceHint_reportActualWorkDuration2(
249263
APerformanceHintSession* _Nonnull session,
250264
AWorkDuration* _Nonnull workDuration) __INTRODUCED_IN(__ANDROID_API_V__);
251265

266+
/**
267+
* Informs the framework of an upcoming increase in the workload of a graphics pipeline
268+
* bound to this session. The user can specify whether the increase is expected to be
269+
* on the CPU, GPU, or both.
270+
*
271+
* Sending hints for both CPU and GPU counts as two separate hints for the purposes of the
272+
* rate limiter.
273+
*
274+
* @param cpu Indicates if the workload increase is expected to affect the CPU.
275+
* @param gpu Indicates if the workload increase is expected to affect the GPU.
276+
* @param debugName A required string used to identify this specific hint during
277+
* tracing. This debug string will only be held for the duration of the
278+
* method, and can be safely discarded after.
279+
*
280+
* @return 0 on success.
281+
* EINVAL if no hints were requested.
282+
* EBUSY if the hint was rate limited.
283+
* EPIPE if communication with the system service has failed.
284+
* ENOTSUP if the hint is not supported.
285+
*/
286+
int APerformanceHint_notifyWorkloadIncrease(
287+
APerformanceHintSession* _Nonnull session,
288+
bool cpu, bool gpu, const char* _Nonnull debugName) __INTRODUCED_IN(36);
289+
290+
/**
291+
* Informs the framework of an upcoming reset in the workload of a graphics pipeline
292+
* bound to this session, or the imminent start of a new workload. The user can specify
293+
* whether the reset is expected to affect the CPU, GPU, or both.
294+
*
295+
* Sending hints for both CPU and GPU counts as two separate hints for the purposes of the
296+
* this load tracking.
297+
*
298+
* @param cpu Indicates if the workload reset is expected to affect the CPU.
299+
* @param gpu Indicates if the workload reset is expected to affect the GPU.
300+
* @param debugName A required string used to identify this specific hint during
301+
* tracing. This debug string will only be held for the duration of the
302+
* method, and can be safely discarded after.
303+
*
304+
* @return 0 on success.
305+
* EINVAL if no hints were requested.
306+
* EBUSY if the hint was rate limited.
307+
* EPIPE if communication with the system service has failed.
308+
* ENOTSUP if the hint is not supported.
309+
*/
310+
int APerformanceHint_notifyWorkloadReset(
311+
APerformanceHintSession* _Nonnull session,
312+
bool cpu, bool gpu, const char* _Nonnull debugName) __INTRODUCED_IN(36);
313+
252314
/**
253315
* Creates a new AWorkDuration. When the client finishes using {@link AWorkDuration}, it should
254316
* call {@link AWorkDuration_release()} to destroy {@link AWorkDuration} and release all resources

include/private/performance_hint_private.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,18 @@ APerformanceHintSession* APerformanceHint_createSessionInternal(APerformanceHint
114114
*/
115115
void APerformanceHint_setUseFMQForTesting(bool enabled);
116116

117+
/**
118+
* Get the rate limiter properties for testing.
119+
*/
120+
void APerformanceHint_getRateLimiterPropertiesForTesting(
121+
int32_t* maxLoadHintsPerInterval, int64_t* loadHintInterval);
122+
123+
/*
124+
* Forces the "new load hint" flag to be disabled for testing.
125+
*/
126+
void APerformanceHint_setUseNewLoadHintBehaviorForTesting(bool newBehavior);
127+
128+
117129
__END_DECLS
118130

119131
#endif // ANDROID_PRIVATE_NATIVE_PERFORMANCE_HINT_PRIVATE_H

0 commit comments

Comments
 (0)