Skip to content

Commit 43a8bd9

Browse files
AndroidMatt1Android (Google) Code Review
authored andcommitted
Revert "Revert "Add public ADPF load hints with better rate limi..."
Revert submission 30360907-revert-29997970-load_hints-VOSJCKDBUL Reason for revert: because the patch is fine, actually Reverted changes: /q/submissionid:30360907-revert-29997970-load_hints-VOSJCKDBUL Change-Id: I7395b8224c5d2cda2aa02b63e11c9575fbe0db23
1 parent 147f08c commit 43a8bd9

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

@@ -250,6 +264,54 @@ int APerformanceHint_reportActualWorkDuration2(
250264
APerformanceHintSession* _Nonnull session,
251265
AWorkDuration* _Nonnull workDuration) __INTRODUCED_IN(__ANDROID_API_V__);
252266

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