blob: 37d320a6621cb559f2fc28991677d1426810a83c [file] [log] [blame]
Bo Liu406c8ab2021-11-10 19:20:40 -05001/*
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
Matt Buckleycc146422023-06-28 19:14:02 +000017 /**
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,
Matt Buckley122a1172024-10-21 12:16:36 -070022 * to help the system more accurately allocate resources for them. It is the NDK
Matt Buckleycc146422023-06-28 19:14:02 +000023 * counterpart to the Java PerformanceHintManager SDK API.
24 *
Matt Buckley122a1172024-10-21 12:16:36 -070025 * 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.
Matt Buckleycc146422023-06-28 19:14:02 +000039 * @{
40 */
41
42/**
43 * @file performance_hint.h
44 * @brief API for creating and managing a hint session.
45 */
46
47
Bo Liu406c8ab2021-11-10 19:20:40 -050048#ifndef ANDROID_NATIVE_PERFORMANCE_HINT_H
49#define ANDROID_NATIVE_PERFORMANCE_HINT_H
50
51#include <sys/cdefs.h>
Matt Buckleyfeb30df2024-11-17 01:56:15 +000052#include <jni.h>
Bo Liu406c8ab2021-11-10 19:20:40 -050053
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
Dan Albert8d4bea12024-08-01 22:31:09 +000070#include <stdbool.h>
Bo Liu406c8ab2021-11-10 19:20:40 -050071#include <stdint.h>
Peiyong Linc1041d42023-01-26 00:51:33 +000072#include <unistd.h>
Bo Liu406c8ab2021-11-10 19:20:40 -050073
74__BEGIN_DECLS
75
76struct APerformanceHintManager;
77struct APerformanceHintSession;
Peiyong Lin81780c42023-10-08 21:11:26 +000078struct AWorkDuration;
79
80/**
81 * {@link AWorkDuration} is an opaque type that represents the breakdown of the
82 * actual workload duration in each component internally.
83 *
84 * A new {@link AWorkDuration} can be obtained using
85 * {@link AWorkDuration_create()}, when the client finishes using
86 * {@link AWorkDuration}, {@link AWorkDuration_release()} must be
87 * called to destroy and free up the resources associated with
88 * {@link AWorkDuration}.
89 *
90 * This file provides a set of functions to allow clients to set the measured
91 * work duration of each component on {@link AWorkDuration}.
92 *
93 * - AWorkDuration_setWorkPeriodStartTimestampNanos()
94 * - AWorkDuration_setActualTotalDurationNanos()
95 * - AWorkDuration_setActualCpuDurationNanos()
96 * - AWorkDuration_setActualGpuDurationNanos()
97 */
98typedef struct AWorkDuration AWorkDuration;
Bo Liu406c8ab2021-11-10 19:20:40 -050099
100/**
101 * An opaque type representing a handle to a performance hint manager.
Bo Liu406c8ab2021-11-10 19:20:40 -0500102 *
Matt Buckleycc146422023-06-28 19:14:02 +0000103 * To use:<ul>
Bo Liu406c8ab2021-11-10 19:20:40 -0500104 * <li>Obtain the performance hint manager instance by calling
105 * {@link APerformanceHint_getManager} function.</li>
106 * <li>Create an {@link APerformanceHintSession} with
107 * {@link APerformanceHint_createSession}.</li>
108 * <li>Get the preferred update rate in nanoseconds with
109 * {@link APerformanceHint_getPreferredUpdateRateNanos}.</li>
110 */
111typedef struct APerformanceHintManager APerformanceHintManager;
112
113/**
Andy Yufa8eb012024-10-15 17:00:09 -0700114 * 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 */
125typedef struct ASessionCreationConfig ASessionCreationConfig;
126
127/**
Bo Liu406c8ab2021-11-10 19:20:40 -0500128 * An opaque type representing a handle to a performance hint session.
129 * A session can only be acquired from a {@link APerformanceHintManager}
Andy Yufa8eb012024-10-15 17:00:09 -0700130 * with {@link APerformanceHint_createSession}
131 * or {@link APerformanceHint_createSessionUsingConfig}. It must be
Bo Liu406c8ab2021-11-10 19:20:40 -0500132 * freed with {@link APerformanceHint_closeSession} after use.
133 *
134 * A Session represents a group of threads with an inter-related workload such that hints for
135 * their performance should be considered as a unit. The threads in a given session should be
Matt Buckleycc146422023-06-28 19:14:02 +0000136 * long-lived and not created or destroyed dynamically.
Bo Liu406c8ab2021-11-10 19:20:40 -0500137 *
Matt Buckleycc146422023-06-28 19:14:02 +0000138 * The work duration API can be used with periodic workloads to dynamically adjust thread
139 * performance and keep the work on schedule while optimizing the available power budget.
140 * When using the work duration API, the starting target duration should be specified
141 * while creating the session, and can later be adjusted with
142 * {@link APerformanceHint_updateTargetWorkDuration}. While using the work duration
143 * API, the client is expected to call {@link APerformanceHint_reportActualWorkDuration} each
144 * cycle to report the actual time taken to complete to the system.
Bo Liu406c8ab2021-11-10 19:20:40 -0500145 *
Xiang Wangc8681f82024-04-08 12:45:59 -0700146 * Note, methods of {@link APerformanceHintSession_*} are not thread safe so callers must
147 * ensure thread safety.
148 *
Matt Buckleycc146422023-06-28 19:14:02 +0000149 * All timings should be from `std::chrono::steady_clock` or `clock_gettime(CLOCK_MONOTONIC, ...)`
Bo Liu406c8ab2021-11-10 19:20:40 -0500150 */
151typedef struct APerformanceHintSession APerformanceHintSession;
152
153/**
154 * Acquire an instance of the performance hint manager.
155 *
Matt Buckleycc146422023-06-28 19:14:02 +0000156 * @return APerformanceHintManager instance on success, nullptr on failure.
Bo Liu406c8ab2021-11-10 19:20:40 -0500157 */
Xiang Wang352ff402024-01-09 13:27:05 -0800158APerformanceHintManager* _Nullable APerformanceHint_getManager()
159 __INTRODUCED_IN(__ANDROID_API_T__);
Bo Liu406c8ab2021-11-10 19:20:40 -0500160
161/**
162 * Creates a session for the given set of threads and sets their initial target work
163 * duration.
Matt Buckleycc146422023-06-28 19:14:02 +0000164 *
Bo Liu406c8ab2021-11-10 19:20:40 -0500165 * @param manager The performance hint manager instance.
166 * @param threadIds The list of threads to be associated with this session. They must be part of
Matt Buckleycc146422023-06-28 19:14:02 +0000167 * this process' thread group.
168 * @param size The size of the list of threadIds.
169 * @param initialTargetWorkDurationNanos The target duration in nanoseconds for the new session.
170 * This must be positive if using the work duration API, or 0 otherwise.
Andy Yufa8eb012024-10-15 17:00:09 -0700171 * @return APerformanceHintSession pointer on success, nullptr on failure.
Bo Liu406c8ab2021-11-10 19:20:40 -0500172 */
Peiyong Lin81780c42023-10-08 21:11:26 +0000173APerformanceHintSession* _Nullable APerformanceHint_createSession(
174 APerformanceHintManager* _Nonnull manager,
175 const int32_t* _Nonnull threadIds, size_t size,
Bo Liu406c8ab2021-11-10 19:20:40 -0500176 int64_t initialTargetWorkDurationNanos) __INTRODUCED_IN(__ANDROID_API_T__);
177
178/**
Andy Yufa8eb012024-10-15 17:00:09 -0700179 * 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 */
187APerformanceHintSession* _Nullable APerformanceHint_createSessionUsingConfig(
188 APerformanceHintManager* _Nonnull manager,
189 ASessionCreationConfig* _Nonnull config)
190 __INTRODUCED_IN(36);
191
192/**
Bo Liu406c8ab2021-11-10 19:20:40 -0500193 * Get preferred update rate information for this device.
194 *
195 * @param manager The performance hint manager instance.
196 * @return the preferred update rate supported by device software.
197 */
198int64_t APerformanceHint_getPreferredUpdateRateNanos(
Peiyong Lin81780c42023-10-08 21:11:26 +0000199 APerformanceHintManager* _Nonnull manager) __INTRODUCED_IN(__ANDROID_API_T__);
Bo Liu406c8ab2021-11-10 19:20:40 -0500200
201/**
Andy Yufa8eb012024-10-15 17:00:09 -0700202 * 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
210/**
Bo Liu406c8ab2021-11-10 19:20:40 -0500211 * Updates this session's target duration for each cycle of work.
212 *
213 * @param session The performance hint session instance to update.
Matt Buckleycc146422023-06-28 19:14:02 +0000214 * @param targetDurationNanos The new desired duration in nanoseconds. This must be positive.
215 * @return 0 on success.
Bo Liu406c8ab2021-11-10 19:20:40 -0500216 * EINVAL if targetDurationNanos is not positive.
217 * EPIPE if communication with the system service has failed.
218 */
219int APerformanceHint_updateTargetWorkDuration(
Peiyong Lin81780c42023-10-08 21:11:26 +0000220 APerformanceHintSession* _Nonnull session,
Bo Liu406c8ab2021-11-10 19:20:40 -0500221 int64_t targetDurationNanos) __INTRODUCED_IN(__ANDROID_API_T__);
222
223/**
224 * Reports the actual duration for the last cycle of work.
225 *
Matt Buckleycc146422023-06-28 19:14:02 +0000226 * The system will attempt to adjust the scheduling and performance of the
227 * threads within the thread group to bring the actual duration close to the target duration.
Bo Liu406c8ab2021-11-10 19:20:40 -0500228 *
229 * @param session The performance hint session instance to update.
Matt Buckleycc146422023-06-28 19:14:02 +0000230 * @param actualDurationNanos The duration of time the thread group took to complete its last
231 * task in nanoseconds. This must be positive.
232 * @return 0 on success.
Bo Liu406c8ab2021-11-10 19:20:40 -0500233 * EINVAL if actualDurationNanos is not positive.
234 * EPIPE if communication with the system service has failed.
235 */
236int APerformanceHint_reportActualWorkDuration(
Peiyong Lin81780c42023-10-08 21:11:26 +0000237 APerformanceHintSession* _Nonnull session,
Bo Liu406c8ab2021-11-10 19:20:40 -0500238 int64_t actualDurationNanos) __INTRODUCED_IN(__ANDROID_API_T__);
239
240/**
241 * Release the performance hint manager pointer acquired via
242 * {@link APerformanceHint_createSession}.
243 *
Matt Buckleyfeb30df2024-11-17 01:56:15 +0000244 * This cannot be used to close a Java PerformanceHintManager.Session, as its
245 * lifecycle is tied to the object in the SDK.
246 *
Bo Liu406c8ab2021-11-10 19:20:40 -0500247 * @param session The performance hint session instance to release.
248 */
249void APerformanceHint_closeSession(
Peiyong Lin81780c42023-10-08 21:11:26 +0000250 APerformanceHintSession* _Nonnull session) __INTRODUCED_IN(__ANDROID_API_T__);
Bo Liu406c8ab2021-11-10 19:20:40 -0500251
Peiyong Linf9c984f2022-11-11 18:28:20 +0000252/**
253 * Set a list of threads to the performance hint session. This operation will replace
254 * the current list of threads with the given list of threads.
255 *
Matt Buckleycc146422023-06-28 19:14:02 +0000256 * @param session The performance hint session instance to update.
Peiyong Linf9c984f2022-11-11 18:28:20 +0000257 * @param threadIds The list of threads to be associated with this session. They must be part of
258 * this app's thread group.
Matt Buckleycc146422023-06-28 19:14:02 +0000259 * @param size The size of the list of threadIds.
Peiyong Linf9c984f2022-11-11 18:28:20 +0000260 * @return 0 on success.
Matt Buckleycc146422023-06-28 19:14:02 +0000261 * EINVAL if the list of thread ids is empty or if any of the thread ids are not part of
262 the thread group.
Peiyong Linf9c984f2022-11-11 18:28:20 +0000263 * EPIPE if communication with the system service has failed.
Xiang Wangf6d21b52023-07-25 17:34:01 -0700264 * EPERM if any thread id doesn't belong to the application.
Peiyong Linf9c984f2022-11-11 18:28:20 +0000265 */
266int APerformanceHint_setThreads(
Peiyong Lin81780c42023-10-08 21:11:26 +0000267 APerformanceHintSession* _Nonnull session,
268 const pid_t* _Nonnull threadIds,
Peiyong Linf9c984f2022-11-11 18:28:20 +0000269 size_t size) __INTRODUCED_IN(__ANDROID_API_U__);
270
Matt Buckleycc146422023-06-28 19:14:02 +0000271/**
272 * This tells the session that these threads can be
273 * safely scheduled to prefer power efficiency over performance.
274 *
275 * @param session The performance hint session instance to update.
276 * @param enabled The flag which sets whether this session will use power-efficient scheduling.
277 * @return 0 on success.
278 * EPIPE if communication with the system service has failed.
279 */
280int APerformanceHint_setPreferPowerEfficiency(
Peiyong Lin81780c42023-10-08 21:11:26 +0000281 APerformanceHintSession* _Nonnull session,
Matt Buckleycc146422023-06-28 19:14:02 +0000282 bool enabled) __INTRODUCED_IN(__ANDROID_API_V__);
283
Peiyong Lin81780c42023-10-08 21:11:26 +0000284/**
285 * Reports the durations for the last cycle of work.
286 *
287 * The system will attempt to adjust the scheduling and performance of the
288 * threads within the thread group to bring the actual duration close to the target duration.
289 *
290 * @param session The {@link APerformanceHintSession} instance to update.
291 * @param workDuration The {@link AWorkDuration} structure of times the thread group took to
292 * complete its last task in nanoseconds breaking down into different components.
293 *
Matt Buckley0bbd1772024-01-31 22:10:42 +0000294 * The work period start timestamp and actual total duration must be greater than zero.
Peiyong Lin81780c42023-10-08 21:11:26 +0000295 *
Matt Buckley0bbd1772024-01-31 22:10:42 +0000296 * The actual CPU and GPU durations must be greater than or equal to zero, and at least one
297 * of them must be greater than zero. When one of them is equal to zero, it means that type
298 * of work was not measured for this workload.
Peiyong Lin81780c42023-10-08 21:11:26 +0000299 *
300 * @return 0 on success.
Matt Buckley81cc0932024-01-18 19:56:31 +0000301 * EINVAL if any duration is an invalid number.
Peiyong Lin81780c42023-10-08 21:11:26 +0000302 * EPIPE if communication with the system service has failed.
303 */
304int APerformanceHint_reportActualWorkDuration2(
305 APerformanceHintSession* _Nonnull session,
306 AWorkDuration* _Nonnull workDuration) __INTRODUCED_IN(__ANDROID_API_V__);
307
308/**
Matt Buckley122a1172024-10-21 12:16:36 -0700309 * Informs the framework of an upcoming increase in the workload of a graphics pipeline
310 * bound to this session. The user can specify whether the increase is expected to be
311 * on the CPU, GPU, or both.
312 *
313 * Sending hints for both CPU and GPU counts as two separate hints for the purposes of the
314 * rate limiter.
315 *
316 * @param cpu Indicates if the workload increase is expected to affect the CPU.
317 * @param gpu Indicates if the workload increase is expected to affect the GPU.
318 * @param debugName A required string used to identify this specific hint during
319 * tracing. This debug string will only be held for the duration of the
320 * method, and can be safely discarded after.
321 *
322 * @return 0 on success.
323 * EINVAL if no hints were requested.
324 * EBUSY if the hint was rate limited.
325 * EPIPE if communication with the system service has failed.
326 * ENOTSUP if the hint is not supported.
327 */
328int APerformanceHint_notifyWorkloadIncrease(
329 APerformanceHintSession* _Nonnull session,
330 bool cpu, bool gpu, const char* _Nonnull debugName) __INTRODUCED_IN(36);
331
332/**
333 * Informs the framework of an upcoming reset in the workload of a graphics pipeline
334 * bound to this session, or the imminent start of a new workload. The user can specify
335 * whether the reset is expected to affect the CPU, GPU, or both.
336 *
337 * Sending hints for both CPU and GPU counts as two separate hints for the purposes of the
338 * this load tracking.
339 *
340 * @param cpu Indicates if the workload reset is expected to affect the CPU.
341 * @param gpu Indicates if the workload reset is expected to affect the GPU.
342 * @param debugName A required string used to identify this specific hint during
343 * tracing. This debug string will only be held for the duration of the
344 * method, and can be safely discarded after.
345 *
346 * @return 0 on success.
347 * EINVAL if no hints were requested.
348 * EBUSY if the hint was rate limited.
349 * EPIPE if communication with the system service has failed.
350 * ENOTSUP if the hint is not supported.
351 */
352int APerformanceHint_notifyWorkloadReset(
353 APerformanceHintSession* _Nonnull session,
354 bool cpu, bool gpu, const char* _Nonnull debugName) __INTRODUCED_IN(36);
355
356/**
Peiyong Lin81780c42023-10-08 21:11:26 +0000357 * Creates a new AWorkDuration. When the client finishes using {@link AWorkDuration}, it should
358 * call {@link AWorkDuration_release()} to destroy {@link AWorkDuration} and release all resources
359 * associated with it.
360 *
Andy Yufa8eb012024-10-15 17:00:09 -0700361 * @return AWorkDuration pointer.
Peiyong Lin81780c42023-10-08 21:11:26 +0000362 */
363AWorkDuration* _Nonnull AWorkDuration_create() __INTRODUCED_IN(__ANDROID_API_V__);
364
365/**
Andy Yufa8eb012024-10-15 17:00:09 -0700366 * Destroys a {@link AWorkDuration} and frees all resources associated with it.
Peiyong Lin81780c42023-10-08 21:11:26 +0000367 *
368 * @param aWorkDuration The {@link AWorkDuration} created by calling {@link AWorkDuration_create()}
369 */
Xiang Wang352ff402024-01-09 13:27:05 -0800370void AWorkDuration_release(AWorkDuration* _Nonnull aWorkDuration)
371 __INTRODUCED_IN(__ANDROID_API_V__);
Peiyong Lin81780c42023-10-08 21:11:26 +0000372
373/**
374 * Sets the work period start timestamp in nanoseconds.
375 *
376 * @param aWorkDuration The {@link AWorkDuration} created by calling {@link AWorkDuration_create()}
377 * @param workPeriodStartTimestampNanos The work period start timestamp in nanoseconds based on
Matt Buckley81cc0932024-01-18 19:56:31 +0000378 * CLOCK_MONOTONIC about when the work starts. This timestamp must be greater than zero.
Peiyong Lin81780c42023-10-08 21:11:26 +0000379 */
380void AWorkDuration_setWorkPeriodStartTimestampNanos(AWorkDuration* _Nonnull aWorkDuration,
381 int64_t workPeriodStartTimestampNanos) __INTRODUCED_IN(__ANDROID_API_V__);
382
383/**
384 * Sets the actual total work duration in nanoseconds.
385 *
386 * @param aWorkDuration The {@link AWorkDuration} created by calling {@link AWorkDuration_create()}
Matt Buckley81cc0932024-01-18 19:56:31 +0000387 * @param actualTotalDurationNanos The actual total work duration in nanoseconds. This number must
388 * be greater than zero.
Peiyong Lin81780c42023-10-08 21:11:26 +0000389 */
390void AWorkDuration_setActualTotalDurationNanos(AWorkDuration* _Nonnull aWorkDuration,
391 int64_t actualTotalDurationNanos) __INTRODUCED_IN(__ANDROID_API_V__);
392
393/**
394 * Sets the actual CPU work duration in nanoseconds.
395 *
396 * @param aWorkDuration The {@link AWorkDuration} created by calling {@link AWorkDuration_create()}
Matt Buckley81cc0932024-01-18 19:56:31 +0000397 * @param actualCpuDurationNanos The actual CPU work duration in nanoseconds. This number must be
Matt Buckley0bbd1772024-01-31 22:10:42 +0000398 * greater than or equal to zero. If it is equal to zero, that means the CPU was not
399 * measured.
Peiyong Lin81780c42023-10-08 21:11:26 +0000400 */
401void AWorkDuration_setActualCpuDurationNanos(AWorkDuration* _Nonnull aWorkDuration,
402 int64_t actualCpuDurationNanos) __INTRODUCED_IN(__ANDROID_API_V__);
403
404/**
405 * Sets the actual GPU work duration in nanoseconds.
406 *
407 * @param aWorkDuration The {@link AWorkDuration} created by calling {@link AWorkDuration_create()}.
408 * @param actualGpuDurationNanos The actual GPU work duration in nanoseconds, the number must be
Matt Buckley0bbd1772024-01-31 22:10:42 +0000409 * greater than or equal to zero. If it is equal to zero, that means the GPU was not
Peiyong Lin81780c42023-10-08 21:11:26 +0000410 * measured.
411 */
412void AWorkDuration_setActualGpuDurationNanos(AWorkDuration* _Nonnull aWorkDuration,
413 int64_t actualGpuDurationNanos) __INTRODUCED_IN(__ANDROID_API_V__);
414
Matt Buckleyfeb30df2024-11-17 01:56:15 +0000415/**
416 * Return the APerformanceHintSession wrapped by a Java PerformanceHintManager.Session object.
417 *
418 * The Java session maintains ownership over the wrapped native session, so it cannot be
419 * closed using {@link APerformanceHint_closeSession}.
420 *
421 * @param env The Java environment where the PerformanceHintManager.Session lives.
422 * @param sessionObj The Java Session to unwrap.
423 *
424 * @return A pointer to the APerformanceHintManager that backs the Java Session.
425 */
426APerformanceHintSession* _Nonnull APerformanceHint_borrowSessionFromJava(
427 JNIEnv* _Nonnull env, jobject _Nonnull sessionObj) __INTRODUCED_IN(36);
428
Andy Yufa8eb012024-10-15 17:00:09 -0700429/*
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 */
439ASessionCreationConfig* _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 */
450void 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 */
465int 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 */
482int 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 */
499int 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 */
520int ASessionCreationConfig_setGraphicsPipeline(
521 ASessionCreationConfig* _Nonnull confi, bool enabled) __INTRODUCED_IN(36);
Matt Buckleyfeb30df2024-11-17 01:56:15 +0000522
Bo Liu406c8ab2021-11-10 19:20:40 -0500523__END_DECLS
524
525#endif // ANDROID_NATIVE_PERFORMANCE_HINT_H
Matt Buckleycc146422023-06-28 19:14:02 +0000526
Peiyong Lin81780c42023-10-08 21:11:26 +0000527/** @} */