xref: /aosp_15_r20/frameworks/native/include/android/performance_hint.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17  /**
18  * @defgroup APerformanceHint Performance Hint Manager
19  *
20  * APerformanceHint allows apps to create performance hint sessions for groups
21  * of threads, and provide hints to the system about the workload of those threads,
22  * to help the system more accurately allocate resources for them. It is the NDK
23  * counterpart to the Java PerformanceHintManager SDK API.
24  *
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.
39  * @{
40  */
41 
42 /**
43  * @file performance_hint.h
44  * @brief API for creating and managing a hint session.
45  */
46 
47 
48 #ifndef ANDROID_NATIVE_PERFORMANCE_HINT_H
49 #define ANDROID_NATIVE_PERFORMANCE_HINT_H
50 
51 #include <sys/cdefs.h>
52 #include <jni.h>
53 
54 /******************************************************************
55  *
56  * IMPORTANT NOTICE:
57  *
58  *   This file is part of Android's set of stable system headers
59  *   exposed by the Android NDK (Native Development Kit).
60  *
61  *   Third-party source AND binary code relies on the definitions
62  *   here to be FROZEN ON ALL UPCOMING PLATFORM RELEASES.
63  *
64  *   - DO NOT MODIFY ENUMS (EXCEPT IF YOU ADD NEW 32-BIT VALUES)
65  *   - DO NOT MODIFY CONSTANTS OR FUNCTIONAL MACROS
66  *   - DO NOT CHANGE THE SIGNATURE OF FUNCTIONS IN ANY WAY
67  *   - DO NOT CHANGE THE LAYOUT OR SIZE OF STRUCTURES
68  */
69 
70 #include <stdbool.h>
71 #include <stdint.h>
72 #include <unistd.h>
73 
74 __BEGIN_DECLS
75 
76 struct APerformanceHintManager;
77 struct APerformanceHintSession;
78 struct AWorkDuration;
79 struct ANativeWindow;
80 struct ASurfaceControl;
81 
82 /**
83  * {@link AWorkDuration} is an opaque type that represents the breakdown of the
84  * actual workload duration in each component internally.
85  *
86  * A new {@link AWorkDuration} can be obtained using
87  * {@link AWorkDuration_create()}, when the client finishes using
88  * {@link AWorkDuration}, {@link AWorkDuration_release()} must be
89  * called to destroy and free up the resources associated with
90  * {@link AWorkDuration}.
91  *
92  * This file provides a set of functions to allow clients to set the measured
93  * work duration of each component on {@link AWorkDuration}.
94  *
95  * - AWorkDuration_setWorkPeriodStartTimestampNanos()
96  * - AWorkDuration_setActualTotalDurationNanos()
97  * - AWorkDuration_setActualCpuDurationNanos()
98  * - AWorkDuration_setActualGpuDurationNanos()
99  */
100 typedef struct AWorkDuration AWorkDuration;
101 
102 /**
103  * An opaque type representing a handle to a performance hint manager.
104  *
105  * To use:<ul>
106  *    <li>Obtain the performance hint manager instance by calling
107  *        {@link APerformanceHint_getManager} function.</li>
108  *    <li>Create an {@link APerformanceHintSession} with
109  *        {@link APerformanceHint_createSession}.</li>
110  *    <li>Get the preferred update rate in nanoseconds with
111  *        {@link APerformanceHint_getPreferredUpdateRateNanos}.</li>
112  */
113 typedef struct APerformanceHintManager APerformanceHintManager;
114 
115 /**
116  * An opaque type representing a handle to a performance hint session creation configuration.
117  * It is consumed by {@link APerformanceHint_createSessionUsingConfig}.
118  *
119  * A session creation config encapsulates the required information for a session.
120  * Additionally, the caller can set various settings for the session,
121  * to be passed during creation, streamlining the session setup process.
122  *
123  * The caller may reuse this object and modify the settings in it
124  * to create additional sessions.
125  *
126  */
127 typedef struct ASessionCreationConfig ASessionCreationConfig;
128 
129 /**
130  * An opaque type representing a handle to a performance hint session.
131  * A session can only be acquired from a {@link APerformanceHintManager}
132  * with {@link APerformanceHint_createSession}
133  * or {@link APerformanceHint_createSessionUsingConfig}. It must be
134  * freed with {@link APerformanceHint_closeSession} after use.
135  *
136  * A Session represents a group of threads with an inter-related workload such that hints for
137  * their performance should be considered as a unit. The threads in a given session should be
138  * long-lived and not created or destroyed dynamically.
139  *
140  * The work duration API can be used with periodic workloads to dynamically adjust thread
141  * performance and keep the work on schedule while optimizing the available power budget.
142  * When using the work duration API, the starting target duration should be specified
143  * while creating the session, and can later be adjusted with
144  * {@link APerformanceHint_updateTargetWorkDuration}. While using the work duration
145  * API, the client is expected to call {@link APerformanceHint_reportActualWorkDuration} each
146  * cycle to report the actual time taken to complete to the system.
147  *
148  * Note, methods of {@link APerformanceHintSession_*} are not thread safe so callers must
149  * ensure thread safety.
150  *
151  * All timings should be from `std::chrono::steady_clock` or `clock_gettime(CLOCK_MONOTONIC, ...)`
152  */
153 typedef struct APerformanceHintSession APerformanceHintSession;
154 
155 typedef struct ANativeWindow ANativeWindow;
156 typedef struct ASurfaceControl ASurfaceControl;
157 
158 /**
159   * Acquire an instance of the performance hint manager.
160   *
161   * @return APerformanceHintManager instance on success, nullptr on failure.
162   */
163 APerformanceHintManager* _Nullable APerformanceHint_getManager()
164                          __INTRODUCED_IN(__ANDROID_API_T__);
165 
166 /**
167  * Creates a session for the given set of threads and sets their initial target work
168  * duration.
169  *
170  * @param manager The performance hint manager instance.
171  * @param threadIds The list of threads to be associated with this session. They must be part of
172  *     this process' thread group.
173  * @param size The size of the list of threadIds.
174  * @param initialTargetWorkDurationNanos The target duration in nanoseconds for the new session.
175  *     This must be positive if using the work duration API, or 0 otherwise.
176  * @return APerformanceHintSession pointer on success, nullptr on failure.
177  */
178 APerformanceHintSession* _Nullable APerformanceHint_createSession(
179         APerformanceHintManager* _Nonnull manager,
180         const int32_t* _Nonnull threadIds, size_t size,
181         int64_t initialTargetWorkDurationNanos) __INTRODUCED_IN(__ANDROID_API_T__);
182 
183 /**
184  * Creates a session for the given set of threads that are graphics pipeline threads
185  * and set their initial target work duration.
186  *
187  * @param manager The performance hint manager instance.
188  * @param config The configuration struct containing required information
189  *        to create a session.
190  * @return APerformanceHintSession pointer on success, nullptr on failure.
191  */
192 APerformanceHintSession* _Nullable APerformanceHint_createSessionUsingConfig(
193         APerformanceHintManager* _Nonnull manager,
194         ASessionCreationConfig* _Nonnull config)
195         __INTRODUCED_IN(36);
196 
197 /**
198  * Get preferred update rate information for this device.
199  *
200  * @param manager The performance hint manager instance.
201  * @return the preferred update rate supported by device software.
202  */
203 int64_t APerformanceHint_getPreferredUpdateRateNanos(
204         APerformanceHintManager* _Nonnull manager) __INTRODUCED_IN(__ANDROID_API_T__);
205 
206 /**
207  * Get maximum number of graphics pipieline threads per-app for this device.
208  *
209  * @param manager The performance hint manager instance.
210  * @return the maximum number of graphics pipeline threads supported by device.
211  */
212  int APerformanceHint_getMaxGraphicsPipelineThreadsCount(
213         APerformanceHintManager* _Nonnull manager) __INTRODUCED_IN(36);
214 
215 /**
216  * Updates this session's target duration for each cycle of work.
217  *
218  * @param session The performance hint session instance to update.
219  * @param targetDurationNanos The new desired duration in nanoseconds. This must be positive.
220  * @return 0 on success.
221  *         EINVAL if targetDurationNanos is not positive.
222  *         EPIPE if communication with the system service has failed.
223  */
224 int APerformanceHint_updateTargetWorkDuration(
225         APerformanceHintSession* _Nonnull session,
226         int64_t targetDurationNanos) __INTRODUCED_IN(__ANDROID_API_T__);
227 
228 /**
229  * Reports the actual duration for the last cycle of work.
230  *
231  * The system will attempt to adjust the scheduling and performance of the
232  * threads within the thread group to bring the actual duration close to the target duration.
233  *
234  * @param session The performance hint session instance to update.
235  * @param actualDurationNanos The duration of time the thread group took to complete its last
236  *     task in nanoseconds. This must be positive.
237  * @return 0 on success.
238  *         EINVAL if actualDurationNanos is not positive.
239  *         EPIPE if communication with the system service has failed.
240  */
241 int APerformanceHint_reportActualWorkDuration(
242         APerformanceHintSession* _Nonnull session,
243         int64_t actualDurationNanos) __INTRODUCED_IN(__ANDROID_API_T__);
244 
245 /**
246  * Release the performance hint manager pointer acquired via
247  * {@link APerformanceHint_createSession}.
248  *
249  * This cannot be used to close a Java PerformanceHintManager.Session, as its
250  * lifecycle is tied to the object in the SDK.
251  *
252  * @param session The performance hint session instance to release.
253  */
254 void APerformanceHint_closeSession(
255         APerformanceHintSession* _Nonnull session) __INTRODUCED_IN(__ANDROID_API_T__);
256 
257 /**
258  * Set a list of threads to the performance hint session. This operation will replace
259  * the current list of threads with the given list of threads.
260  *
261  * @param session The performance hint session instance to update.
262  * @param threadIds The list of threads to be associated with this session. They must be part of
263  *     this app's thread group.
264  * @param size The size of the list of threadIds.
265  * @return 0 on success.
266  *         EINVAL if the list of thread ids is empty or if any of the thread ids are not part of
267                the thread group.
268  *         EPIPE if communication with the system service has failed.
269  *         EPERM if any thread id doesn't belong to the application.
270  */
271 int APerformanceHint_setThreads(
272         APerformanceHintSession* _Nonnull session,
273         const pid_t* _Nonnull threadIds,
274         size_t size) __INTRODUCED_IN(__ANDROID_API_U__);
275 
276 /**
277  * This tells the session that these threads can be
278  * safely scheduled to prefer power efficiency over performance.
279  *
280  * @param session The performance hint session instance to update.
281  * @param enabled The flag which sets whether this session will use power-efficient scheduling.
282  * @return 0 on success.
283  *         EPIPE if communication with the system service has failed.
284  */
285 int APerformanceHint_setPreferPowerEfficiency(
286         APerformanceHintSession* _Nonnull session,
287         bool enabled) __INTRODUCED_IN(__ANDROID_API_V__);
288 
289 /**
290  * Reports the durations for the last cycle of work.
291  *
292  * The system will attempt to adjust the scheduling and performance of the
293  * threads within the thread group to bring the actual duration close to the target duration.
294  *
295  * @param session The {@link APerformanceHintSession} instance to update.
296  * @param workDuration The {@link AWorkDuration} structure of times the thread group took to
297  *     complete its last task in nanoseconds breaking down into different components.
298  *
299  *     The work period start timestamp and actual total duration must be greater than zero.
300  *
301  *     The actual CPU and GPU durations must be greater than or equal to zero, and at least one
302  *     of them must be greater than zero. When one of them is equal to zero, it means that type
303  *     of work was not measured for this workload.
304  *
305  * @return 0 on success.
306  *         EINVAL if any duration is an invalid number.
307  *         EPIPE if communication with the system service has failed.
308  */
309 int APerformanceHint_reportActualWorkDuration2(
310         APerformanceHintSession* _Nonnull session,
311         AWorkDuration* _Nonnull workDuration) __INTRODUCED_IN(__ANDROID_API_V__);
312 
313 /**
314  * Informs the framework of an upcoming increase in the workload of a graphics pipeline
315  * bound to this session. The user can specify whether the increase is expected to be
316  * on the CPU, GPU, or both.
317  *
318  * Sending hints for both CPU and GPU counts as two separate hints for the purposes of the
319  * rate limiter.
320  *
321  * @param cpu Indicates if the workload increase is expected to affect the CPU.
322  * @param gpu Indicates if the workload increase is expected to affect the GPU.
323  * @param debugName A required string used to identify this specific hint during
324  *        tracing. This debug string will only be held for the duration of the
325  *        method, and can be safely discarded after.
326  *
327  * @return 0 on success.
328  *         EINVAL if no hints were requested.
329  *         EBUSY if the hint was rate limited.
330  *         EPIPE if communication with the system service has failed.
331  *         ENOTSUP if the hint is not supported.
332  */
333 int APerformanceHint_notifyWorkloadIncrease(
334         APerformanceHintSession* _Nonnull session,
335         bool cpu, bool gpu, const char* _Nonnull debugName) __INTRODUCED_IN(36);
336 
337 /**
338  * Informs the framework of an upcoming reset in the workload of a graphics pipeline
339  * bound to this session, or the imminent start of a new workload. The user can specify
340  * whether the reset is expected to affect the CPU, GPU, or both.
341  *
342  * Sending hints for both CPU and GPU counts as two separate hints for the purposes of the
343  * this load tracking.
344  *
345  * @param cpu Indicates if the workload reset is expected to affect the CPU.
346  * @param gpu Indicates if the workload reset is expected to affect the GPU.
347  * @param debugName A required string used to identify this specific hint during
348  *        tracing. This debug string will only be held for the duration of the
349  *        method, and can be safely discarded after.
350  *
351  * @return 0 on success.
352  *         EINVAL if no hints were requested.
353  *         EBUSY if the hint was rate limited.
354  *         EPIPE if communication with the system service has failed.
355  *         ENOTSUP if the hint is not supported.
356  */
357 int APerformanceHint_notifyWorkloadReset(
358         APerformanceHintSession* _Nonnull session,
359         bool cpu, bool gpu, const char* _Nonnull debugName) __INTRODUCED_IN(36);
360 
361 /**
362  * Informs the framework of an upcoming one-off expensive frame for a graphics pipeline
363  * bound to this session. This frame will be treated as not representative of the workload as a
364  * whole, and it will be discarded the purposes of load tracking. The user can specify
365  * whether the workload spike is expected to be on the CPU, GPU, or both.
366  *
367  * Sending hints for both CPU and GPU counts as two separate hints for the purposes of the
368  * rate limiter.
369  *
370  * @param cpu Indicates if the workload spike is expected to affect the CPU.
371  * @param gpu Indicates if the workload spike is expected to affect the GPU.
372  * @param debugName A required string used to identify this specific hint during
373  *        tracing. This debug string will only be held for the duration of the
374  *        method, and can be safely discarded after.
375  *
376  * @return 0 on success.
377  *         EINVAL if no hints were requested.
378  *         EBUSY if the hint was rate limited.
379  *         EPIPE if communication with the system service has failed.
380  *         ENOTSUP if the hint is not supported.
381  */
382 int APerformanceHint_notifyWorkloadSpike(
383         APerformanceHintSession* _Nonnull session,
384         bool cpu, bool gpu, const char* _Nonnull debugName) __INTRODUCED_IN(36);
385 
386 /**
387  * Associates a session with any {@link ASurfaceControl} or {@link ANativeWindow}
388  * instances managed by this session.
389  *
390  * This method is primarily intended for sessions that manage the timing of an entire
391  * graphics pipeline end-to-end, such as those using the
392  * {@link ASessionCreationConfig_setGraphicsPipeline} API. However, any session directly
393  * or indirectly managing a graphics pipeline should still associate themselves with
394  * directly relevant ASurfaceControl or ANativeWindow instances for better optimization.
395  *
396  * To see any benefit from this method, the client must make sure they are updating the framerate
397  * of attached surfaces using methods such as {@link ANativeWindow_setFrameRate}, or by updating
398  * any associated ASurfaceControls with transactions that have {ASurfaceTransaction_setFrameRate}.
399  *
400  * @param session The {@link APerformanceHintSession} instance to update.
401  * @param nativeWindows A pointer to a list of ANativeWindows associated with this session.
402  *        nullptr can be passed to indicate there are no associated ANativeWindows.
403  * @param nativeWindowsSize The number of ANativeWindows in the list.
404  * @param surfaceControls A pointer to a list of ASurfaceControls associated with this session.
405  *        nullptr can be passed to indicate there are no associated ASurfaceControls.
406  * @param surfaceControlsSize The number of ASurfaceControls in the list.
407  *
408  * @return 0 on success.
409  *         EPIPE if communication has failed.
410  *         ENOTSUP if unsupported.
411  *         EINVAL if invalid or empty arguments passed.
412  */
413 
414 int APerformanceHint_setNativeSurfaces(APerformanceHintSession* _Nonnull session,
415         ANativeWindow* _Nonnull* _Nullable nativeWindows, int nativeWindowsSize,
416         ASurfaceControl* _Nonnull* _Nullable surfaceControls, int surfaceControlsSize)
417         __INTRODUCED_IN(36);
418 
419 /**
420  * Creates a new AWorkDuration. When the client finishes using {@link AWorkDuration}, it should
421  * call {@link AWorkDuration_release()} to destroy {@link AWorkDuration} and release all resources
422  * associated with it.
423  *
424  * @return AWorkDuration pointer.
425  */
426 AWorkDuration* _Nonnull AWorkDuration_create() __INTRODUCED_IN(__ANDROID_API_V__);
427 
428 /**
429  * Destroys a {@link AWorkDuration} and frees all resources associated with it.
430  *
431  * @param aWorkDuration The {@link AWorkDuration} created by calling {@link AWorkDuration_create()}
432  */
433 void AWorkDuration_release(AWorkDuration* _Nonnull aWorkDuration)
434      __INTRODUCED_IN(__ANDROID_API_V__);
435 
436 /**
437  * Sets the work period start timestamp in nanoseconds.
438  *
439  * @param aWorkDuration The {@link AWorkDuration} created by calling {@link AWorkDuration_create()}
440  * @param workPeriodStartTimestampNanos The work period start timestamp in nanoseconds based on
441  *        CLOCK_MONOTONIC about when the work starts. This timestamp must be greater than zero.
442  */
443 void AWorkDuration_setWorkPeriodStartTimestampNanos(AWorkDuration* _Nonnull aWorkDuration,
444         int64_t workPeriodStartTimestampNanos) __INTRODUCED_IN(__ANDROID_API_V__);
445 
446 /**
447  * Sets the actual total work duration in nanoseconds.
448  *
449  * @param aWorkDuration The {@link AWorkDuration} created by calling {@link AWorkDuration_create()}
450  * @param actualTotalDurationNanos The actual total work duration in nanoseconds. This number must
451  *        be greater than zero.
452  */
453 void AWorkDuration_setActualTotalDurationNanos(AWorkDuration* _Nonnull aWorkDuration,
454         int64_t actualTotalDurationNanos) __INTRODUCED_IN(__ANDROID_API_V__);
455 
456 /**
457  * Sets the actual CPU work duration in nanoseconds.
458  *
459  * @param aWorkDuration The {@link AWorkDuration} created by calling {@link AWorkDuration_create()}
460  * @param actualCpuDurationNanos The actual CPU work duration in nanoseconds. This number must be
461  *        greater than or equal to zero. If it is equal to zero, that means the CPU was not
462  *        measured.
463  */
464 void AWorkDuration_setActualCpuDurationNanos(AWorkDuration* _Nonnull aWorkDuration,
465         int64_t actualCpuDurationNanos) __INTRODUCED_IN(__ANDROID_API_V__);
466 
467 /**
468  * Sets the actual GPU work duration in nanoseconds.
469  *
470  * @param aWorkDuration The {@link AWorkDuration} created by calling {@link AWorkDuration_create()}.
471  * @param actualGpuDurationNanos The actual GPU work duration in nanoseconds, the number must be
472  *        greater than or equal to zero. If it is equal to zero, that means the GPU was not
473  *        measured.
474  */
475 void AWorkDuration_setActualGpuDurationNanos(AWorkDuration* _Nonnull aWorkDuration,
476         int64_t actualGpuDurationNanos) __INTRODUCED_IN(__ANDROID_API_V__);
477 
478 /**
479  * Return the APerformanceHintSession wrapped by a Java PerformanceHintManager.Session object.
480  *
481  * The Java session maintains ownership over the wrapped native session, so it cannot be
482  * closed using {@link APerformanceHint_closeSession}.
483  *
484  * @param env The Java environment where the PerformanceHintManager.Session lives.
485  * @param sessionObj The Java Session to unwrap.
486  *
487  * @return A pointer to the APerformanceHintManager that backs the Java Session.
488  */
489 APerformanceHintSession* _Nonnull APerformanceHint_borrowSessionFromJava(
490         JNIEnv* _Nonnull env, jobject _Nonnull sessionObj) __INTRODUCED_IN(36);
491 
492 /*
493  * Creates a new ASessionCreationConfig.
494  *
495  * When the client finishes using {@link ASessionCreationConfig}, it should
496  * call {@link ASessionCreationConfig_release()} to destroy
497  * {@link ASessionCreationConfig} and release all resources
498  * associated with it.
499  *
500  * @return ASessionCreationConfig pointer.
501  */
502 ASessionCreationConfig* _Nonnull ASessionCreationConfig_create()
503                 __INTRODUCED_IN(36);
504 
505 
506 /**
507  * Destroys a {@link ASessionCreationConfig} and frees all
508  * resources associated with it.
509  *
510  * @param config The {@link ASessionCreationConfig}
511  *        created by calling {@link ASessionCreationConfig_create()}.
512  */
513 void ASessionCreationConfig_release(
514                 ASessionCreationConfig* _Nonnull config) __INTRODUCED_IN(36);
515 
516 /**
517  * Sets the tids to be associated with the session to be created.
518  *
519  * @param config The {@link ASessionCreationConfig}
520  *        created by calling {@link ASessionCreationConfig_create()}
521  * @param tids The list of tids to be associated with this session. They must be part of
522  *        this process' thread group.
523  * @param size The size of the list of tids.
524  *
525  * @return 0 on success.
526  *         EINVAL if invalid array pointer or the value of size
527  */
528 int ASessionCreationConfig_setTids(
529         ASessionCreationConfig* _Nonnull config,
530         const pid_t* _Nonnull tids, size_t size)  __INTRODUCED_IN(36);
531 
532 /**
533  * Sets the initial target work duration in nanoseconds for the session to be created.
534  *
535  * @param config The {@link ASessionCreationConfig}
536  *        created by calling {@link ASessionCreationConfig_create()}.
537  * @param targetWorkDurationNanos The parameter to specify a target duration
538  *        in nanoseconds for the new session; this value must be positive to use
539  *        the work duration API.
540  *
541  * @return 0 on success.
542  *         ENOTSUP if unsupported
543  *         EINVAL if invalid value
544  */
545 int ASessionCreationConfig_setTargetWorkDurationNanos(
546         ASessionCreationConfig* _Nonnull config,
547         int64_t targetWorkDurationNanos)  __INTRODUCED_IN(36);
548 
549 /**
550  * Sets whether power efficiency mode will be enabled for the session.
551  * This tells the session that these threads can be
552  * safely scheduled to prefer power efficiency over performance.
553  *
554  * @param config The {@link ASessionCreationConfig}
555  *        created by calling {@link ASessionCreationConfig_create()}.
556  * @param enabled Whether power efficiency mode will be enabled.
557  *
558  * @return 0 on success.
559  *         ENOTSUP if unsupported
560  *         EINVAL if invalid pointer to creation config
561  */
562 int ASessionCreationConfig_setPreferPowerEfficiency(
563         ASessionCreationConfig* _Nonnull config, bool enabled)  __INTRODUCED_IN(36);
564 
565 /**
566  * Sessions setting this hint are expected to time the critical path of
567  * graphics pipeline from end to end, with the total work duration
568  * representing the time from the start of frame production until the
569  * buffer is fully finished drawing.
570  *
571  * It should include any threads on the critical path of that pipeline,
572  * up to a limit accessible from {@link getMaxGraphicsPipelineThreadsCount()}.
573  *
574  * @param config The {@link ASessionCreationConfig}
575  *        created by calling {@link ASessionCreationConfig_create()}.
576  * @param enabled Whether this session manages a graphics pipeline's critical path.
577  *
578  * @return 0 on success.
579  *         ENOTSUP if unsupported
580  *         EINVAL if invalid pointer to creation config or maximum threads for graphics
581                   pipeline is reached.
582  */
583 int ASessionCreationConfig_setGraphicsPipeline(
584         ASessionCreationConfig* _Nonnull config, bool enabled)  __INTRODUCED_IN(36);
585 
586 /**
587  * Associates a session with any {@link ASurfaceControl} or {@link ANativeWindow}
588  * instances managed by this session. See {@link APerformanceHint_setNativeSurfaces}
589  * for more details.
590  *
591  * @param config The {@link ASessionCreationConfig}
592  *        created by calling {@link ASessionCreationConfig_create()}.
593  * @param nativeWindows A pointer to a list of ANativeWindows associated with this session.
594  *        nullptr can be passed to indicate there are no associated ANativeWindows.
595  * @param nativeWindowsSize The number of ANativeWindows in the list.
596  * @param surfaceControls A pointer to a list of ASurfaceControls associated with this session.
597  *        nullptr can be passed to indicate there are no associated ASurfaceControls.
598  * @param surfaceControlsSize The number of ASurfaceControls in the list.
599  *
600  * @return 0 on success.
601  *         ENOTSUP if unsupported.
602  *         EINVAL if invalid or empty arguments passed.
603  */
604 int ASessionCreationConfig_setNativeSurfaces(
605         ASessionCreationConfig* _Nonnull config,
606         ANativeWindow* _Nonnull* _Nullable nativeWindows, int nativeWindowsSize,
607         ASurfaceControl* _Nonnull* _Nullable surfaceControls, int surfaceControlsSize)
608         __INTRODUCED_IN(36);
609 
610 /**
611  * Enable automatic timing mode for sessions using the GRAPHICS_PIPELINE API with an attached
612  * surface. In this mode, sessions do not need to report actual durations and only need
613  * to keep their thread list up-to-date, set a native surface, call
614  * {@link ASessionCreationConfig_setGraphicsPipeline()} to signal that the session is in
615  * "graphics pipeline" mode, and then set whether automatic timing is desired for the
616  * CPU, GPU, or both, using this method.
617  *
618  * It is still be beneficial to set an accurate target time, as this may help determine
619  * timing information for some workloads where there is less information available from
620  * the framework, such as games. Additionally, reported CPU durations will be ignored
621  * while automatic CPU timing is enabled, and similarly GPU durations will be ignored
622  * when automatic GPU timing is enabled. When both are enabled, the entire
623  * reportActualWorkDuration call will be ignored, and the session will be managed
624  * completely automatically.
625  *
626  * This mode will not work unless the client makes sure they are updating the framerate
627  * of attached surfaces with methods such as {@link ANativeWindow_setFrameRate}, or updating
628  * any associated ASurfaceControls with transactions that have {ASurfaceTransaction_setFrameRate}.
629  *
630  * @param config The {@link ASessionCreationConfig}
631  *        created by calling {@link ASessionCreationConfig_create()}.
632  * @param cpu Whether to enable automatic timing for the CPU for this session.
633  * @param gpu Whether to enable automatic timing for the GPU for this session.
634  *
635  * @return 0 on success.
636  *         ENOTSUP if unsupported.
637  */
638 int ASessionCreationConfig_setUseAutoTiming(
639         ASessionCreationConfig* _Nonnull config,
640         bool cpu, bool gpu)
641         __INTRODUCED_IN(36);
642 
643 __END_DECLS
644 
645 #endif // ANDROID_NATIVE_PERFORMANCE_HINT_H
646 
647 /** @} */
648