Skip to content

Commit 667fb71

Browse files
Andy YuAndroid (Google) Code Review
authored andcommitted
Merge "Implement NDK createSessionUsingConfig API" into main
2 parents 78a03d1 + fa8eb01 commit 667fb71

2 files changed

Lines changed: 145 additions & 4 deletions

File tree

include/android/performance_hint.h

Lines changed: 135 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,25 @@ typedef struct AWorkDuration AWorkDuration;
110110
*/
111111
typedef struct APerformanceHintManager APerformanceHintManager;
112112

113+
/**
114+
* An opaque type representing a handle to a performance hint session creation configuration.
115+
* It is consumed by {@link APerformanceHint_createSessionUsingConfig}.
116+
*
117+
* A session creation config encapsulates the required information for a session.
118+
* Additionally, the caller can set various settings for the session,
119+
* to be passed during creation, streamlining the session setup process.
120+
*
121+
* The caller may reuse this object and modify the settings in it
122+
* to create additional sessions.
123+
*
124+
*/
125+
typedef struct ASessionCreationConfig ASessionCreationConfig;
126+
113127
/**
114128
* An opaque type representing a handle to a performance hint session.
115129
* A session can only be acquired from a {@link APerformanceHintManager}
116-
* with {@link APerformanceHint_createSession}. It must be
130+
* with {@link APerformanceHint_createSession}
131+
* or {@link APerformanceHint_createSessionUsingConfig}. It must be
117132
* freed with {@link APerformanceHint_closeSession} after use.
118133
*
119134
* A Session represents a group of threads with an inter-related workload such that hints for
@@ -153,13 +168,27 @@ APerformanceHintManager* _Nullable APerformanceHint_getManager()
153168
* @param size The size of the list of threadIds.
154169
* @param initialTargetWorkDurationNanos The target duration in nanoseconds for the new session.
155170
* This must be positive if using the work duration API, or 0 otherwise.
156-
* @return APerformanceHintManager instance on success, nullptr on failure.
171+
* @return APerformanceHintSession pointer on success, nullptr on failure.
157172
*/
158173
APerformanceHintSession* _Nullable APerformanceHint_createSession(
159174
APerformanceHintManager* _Nonnull manager,
160175
const int32_t* _Nonnull threadIds, size_t size,
161176
int64_t initialTargetWorkDurationNanos) __INTRODUCED_IN(__ANDROID_API_T__);
162177

178+
/**
179+
* Creates a session for the given set of threads that are graphics pipeline threads
180+
* and set their initial target work duration.
181+
*
182+
* @param manager The performance hint manager instance.
183+
* @param config The configuration struct containing required information
184+
* to create a session.
185+
* @return APerformanceHintSession pointer on success, nullptr on failure.
186+
*/
187+
APerformanceHintSession* _Nullable APerformanceHint_createSessionUsingConfig(
188+
APerformanceHintManager* _Nonnull manager,
189+
ASessionCreationConfig* _Nonnull config)
190+
__INTRODUCED_IN(36);
191+
163192
/**
164193
* Get preferred update rate information for this device.
165194
*
@@ -169,6 +198,15 @@ APerformanceHintSession* _Nullable APerformanceHint_createSession(
169198
int64_t APerformanceHint_getPreferredUpdateRateNanos(
170199
APerformanceHintManager* _Nonnull manager) __INTRODUCED_IN(__ANDROID_API_T__);
171200

201+
/**
202+
* Get maximum number of graphics pipieline threads per-app for this device.
203+
*
204+
* @param manager The performance hint manager instance.
205+
* @return the maximum number of graphics pipeline threads supported by device.
206+
*/
207+
int APerformanceHint_getMaxGraphicsPipelineThreadsCount(
208+
APerformanceHintManager* _Nonnull manager) __INTRODUCED_IN(36);
209+
172210
/**
173211
* Updates this session's target duration for each cycle of work.
174212
*
@@ -320,12 +358,12 @@ int APerformanceHint_notifyWorkloadReset(
320358
* call {@link AWorkDuration_release()} to destroy {@link AWorkDuration} and release all resources
321359
* associated with it.
322360
*
323-
* @return AWorkDuration on success and nullptr otherwise.
361+
* @return AWorkDuration pointer.
324362
*/
325363
AWorkDuration* _Nonnull AWorkDuration_create() __INTRODUCED_IN(__ANDROID_API_V__);
326364

327365
/**
328-
* Destroys {@link AWorkDuration} and free all resources associated to it.
366+
* Destroys a {@link AWorkDuration} and frees all resources associated with it.
329367
*
330368
* @param aWorkDuration The {@link AWorkDuration} created by calling {@link AWorkDuration_create()}
331369
*/
@@ -388,6 +426,99 @@ void AWorkDuration_setActualGpuDurationNanos(AWorkDuration* _Nonnull aWorkDurati
388426
APerformanceHintSession* _Nonnull APerformanceHint_borrowSessionFromJava(
389427
JNIEnv* _Nonnull env, jobject _Nonnull sessionObj) __INTRODUCED_IN(36);
390428

429+
/*
430+
* Creates a new ASessionCreationConfig.
431+
*
432+
* When the client finishes using {@link ASessionCreationConfig}, it should
433+
* call {@link ASessionCreationConfig_release()} to destroy
434+
* {@link ASessionCreationConfig} and release all resources
435+
* associated with it.
436+
*
437+
* @return ASessionCreationConfig pointer.
438+
*/
439+
ASessionCreationConfig* _Nonnull ASessionCreationConfig_create()
440+
__INTRODUCED_IN(36);
441+
442+
443+
/**
444+
* Destroys a {@link ASessionCreationConfig} and frees all
445+
* resources associated with it.
446+
*
447+
* @param config The {@link ASessionCreationConfig}
448+
* created by calling {@link ASessionCreationConfig_create()}.
449+
*/
450+
void ASessionCreationConfig_release(
451+
ASessionCreationConfig* _Nonnull config) __INTRODUCED_IN(36);
452+
453+
/**
454+
* Sets the tids to be associated with the session to be created.
455+
*
456+
* @param config The {@link ASessionCreationConfig}
457+
* created by calling {@link ASessionCreationConfig_create()}
458+
* @param tids The list of tids to be associated with this session. They must be part of
459+
* this process' thread group.
460+
* @param size The size of the list of tids.
461+
*
462+
* @return 0 on success.
463+
* EINVAL if invalid array pointer or the value of size
464+
*/
465+
int ASessionCreationConfig_setTids(
466+
ASessionCreationConfig* _Nonnull config,
467+
const pid_t* _Nonnull tids, size_t size) __INTRODUCED_IN(36);
468+
469+
/**
470+
* Sets the initial target work duration in nanoseconds for the session to be created.
471+
*
472+
* @param config The {@link ASessionCreationConfig}
473+
* created by calling {@link ASessionCreationConfig_create()}.
474+
* @param targetWorkDurationNanos The parameter to specify a target duration
475+
* in nanoseconds for the new session; this value must be positive to use
476+
* the work duration API.
477+
*
478+
* @return 0 on success.
479+
* ENOTSUP if unsupported
480+
* EINVAL if invalid value
481+
*/
482+
int ASessionCreationConfig_setTargetWorkDurationNanos(
483+
ASessionCreationConfig* _Nonnull config,
484+
int64_t targetWorkDurationNanos) __INTRODUCED_IN(36);
485+
486+
/**
487+
* Sets whether power efficiency mode will be enabled for the session.
488+
* This tells the session that these threads can be
489+
* safely scheduled to prefer power efficiency over performance.
490+
*
491+
* @param config The {@link ASessionCreationConfig}
492+
* created by calling {@link ASessionCreationConfig_create()}.
493+
* @param enabled Whether power efficiency mode will be enabled.
494+
*
495+
* @return 0 on success.
496+
* ENOTSUP if unsupported
497+
* EINVAL if invalid pointer to creation config
498+
*/
499+
int ASessionCreationConfig_setPreferPowerEfficiency(
500+
ASessionCreationConfig* _Nonnull config, bool enabled) __INTRODUCED_IN(36);
501+
502+
/**
503+
* Sessions setting this hint are expected to time the critical path of
504+
* graphics pipeline from end to end, with the total work duration
505+
* representing the time from the start of frame production until the
506+
* buffer is fully finished drawing.
507+
*
508+
* It should include any threads on the critical path of that pipeline,
509+
* up to a limit accessible from {@link getMaxGraphicsPipelineThreadsCount()}.
510+
*
511+
* @param config The {@link ASessionCreationConfig}
512+
* created by calling {@link ASessionCreationConfig_create()}.
513+
* @param enabled Whether this session manages a graphics pipeline's critical path.
514+
*
515+
* @return 0 on success.
516+
* ENOTSUP if unsupported
517+
* EINVAL if invalid pointer to creation config or maximum threads for graphics
518+
pipeline is reached.
519+
*/
520+
int ASessionCreationConfig_setGraphicsPipeline(
521+
ASessionCreationConfig* _Nonnull confi, bool enabled) __INTRODUCED_IN(36);
391522

392523
__END_DECLS
393524

include/private/performance_hint_private.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ int APerformanceHint_getThreadIds(APerformanceHintSession* session,
108108
APerformanceHintSession* APerformanceHint_createSessionInternal(APerformanceHintManager* manager,
109109
const int32_t* threadIds, size_t size,
110110
int64_t initialTargetWorkDurationNanos, SessionTag tag);
111+
/**
112+
* Creates a session using ASessionCreationConfig
113+
*/
114+
APerformanceHintSession* APerformanceHint_createSessionUsingConfigInternal(
115+
APerformanceHintManager* manager, ASessionCreationConfig* sessionCreationConfig,
116+
SessionTag tag);
111117

112118
/**
113119
* Creates a session from the Java SDK implementation
@@ -137,6 +143,10 @@ void APerformanceHint_getRateLimiterPropertiesForTesting(
137143
*/
138144
void APerformanceHint_setUseNewLoadHintBehaviorForTesting(bool newBehavior);
139145

146+
/*
147+
* Forces the graphics pipeline flag to be enabled or disabled, for testing only.
148+
*/
149+
void APerformanceHint_setUseGraphicsPipelineForTesting(bool enabled);
140150

141151
__END_DECLS
142152

0 commit comments

Comments
 (0)