Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 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 | |
Matt Buckley | cc14642 | 2023-06-28 19:14:02 +0000 | [diff] [blame] | 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, |
Matt Buckley | 122a117 | 2024-10-21 12:16:36 -0700 | [diff] [blame] | 22 | * to help the system more accurately allocate resources for them. It is the NDK |
Matt Buckley | cc14642 | 2023-06-28 19:14:02 +0000 | [diff] [blame] | 23 | * counterpart to the Java PerformanceHintManager SDK API. |
| 24 | * |
Matt Buckley | 122a117 | 2024-10-21 12:16:36 -0700 | [diff] [blame] | 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. |
Matt Buckley | cc14642 | 2023-06-28 19:14:02 +0000 | [diff] [blame] | 39 | * @{ |
| 40 | */ |
| 41 | |
| 42 | /** |
| 43 | * @file performance_hint.h |
| 44 | * @brief API for creating and managing a hint session. |
| 45 | */ |
| 46 | |
| 47 | |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 48 | #ifndef ANDROID_NATIVE_PERFORMANCE_HINT_H |
| 49 | #define ANDROID_NATIVE_PERFORMANCE_HINT_H |
| 50 | |
| 51 | #include <sys/cdefs.h> |
Matt Buckley | feb30df | 2024-11-17 01:56:15 +0000 | [diff] [blame] | 52 | #include <jni.h> |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 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 | |
Dan Albert | 8d4bea1 | 2024-08-01 22:31:09 +0000 | [diff] [blame] | 70 | #include <stdbool.h> |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 71 | #include <stdint.h> |
Peiyong Lin | c1041d4 | 2023-01-26 00:51:33 +0000 | [diff] [blame] | 72 | #include <unistd.h> |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 73 | |
| 74 | __BEGIN_DECLS |
| 75 | |
| 76 | struct APerformanceHintManager; |
| 77 | struct APerformanceHintSession; |
Peiyong Lin | 81780c4 | 2023-10-08 21:11:26 +0000 | [diff] [blame] | 78 | struct 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 | */ |
| 98 | typedef struct AWorkDuration AWorkDuration; |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 99 | |
| 100 | /** |
| 101 | * An opaque type representing a handle to a performance hint manager. |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 102 | * |
Matt Buckley | cc14642 | 2023-06-28 19:14:02 +0000 | [diff] [blame] | 103 | * To use:<ul> |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 104 | * <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 | */ |
| 111 | typedef struct APerformanceHintManager APerformanceHintManager; |
| 112 | |
| 113 | /** |
Andy Yu | fa8eb01 | 2024-10-15 17:00:09 -0700 | [diff] [blame] | 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 | |
| 127 | /** |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 128 | * An opaque type representing a handle to a performance hint session. |
| 129 | * A session can only be acquired from a {@link APerformanceHintManager} |
Andy Yu | fa8eb01 | 2024-10-15 17:00:09 -0700 | [diff] [blame] | 130 | * with {@link APerformanceHint_createSession} |
| 131 | * or {@link APerformanceHint_createSessionUsingConfig}. It must be |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 132 | * 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 Buckley | cc14642 | 2023-06-28 19:14:02 +0000 | [diff] [blame] | 136 | * long-lived and not created or destroyed dynamically. |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 137 | * |
Matt Buckley | cc14642 | 2023-06-28 19:14:02 +0000 | [diff] [blame] | 138 | * 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 Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 145 | * |
Xiang Wang | c8681f8 | 2024-04-08 12:45:59 -0700 | [diff] [blame] | 146 | * Note, methods of {@link APerformanceHintSession_*} are not thread safe so callers must |
| 147 | * ensure thread safety. |
| 148 | * |
Matt Buckley | cc14642 | 2023-06-28 19:14:02 +0000 | [diff] [blame] | 149 | * All timings should be from `std::chrono::steady_clock` or `clock_gettime(CLOCK_MONOTONIC, ...)` |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 150 | */ |
| 151 | typedef struct APerformanceHintSession APerformanceHintSession; |
| 152 | |
| 153 | /** |
| 154 | * Acquire an instance of the performance hint manager. |
| 155 | * |
Matt Buckley | cc14642 | 2023-06-28 19:14:02 +0000 | [diff] [blame] | 156 | * @return APerformanceHintManager instance on success, nullptr on failure. |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 157 | */ |
Xiang Wang | 352ff40 | 2024-01-09 13:27:05 -0800 | [diff] [blame] | 158 | APerformanceHintManager* _Nullable APerformanceHint_getManager() |
| 159 | __INTRODUCED_IN(__ANDROID_API_T__); |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 160 | |
| 161 | /** |
| 162 | * Creates a session for the given set of threads and sets their initial target work |
| 163 | * duration. |
Matt Buckley | cc14642 | 2023-06-28 19:14:02 +0000 | [diff] [blame] | 164 | * |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 165 | * @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 Buckley | cc14642 | 2023-06-28 19:14:02 +0000 | [diff] [blame] | 167 | * 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 Yu | fa8eb01 | 2024-10-15 17:00:09 -0700 | [diff] [blame] | 171 | * @return APerformanceHintSession pointer on success, nullptr on failure. |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 172 | */ |
Peiyong Lin | 81780c4 | 2023-10-08 21:11:26 +0000 | [diff] [blame] | 173 | APerformanceHintSession* _Nullable APerformanceHint_createSession( |
| 174 | APerformanceHintManager* _Nonnull manager, |
| 175 | const int32_t* _Nonnull threadIds, size_t size, |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 176 | int64_t initialTargetWorkDurationNanos) __INTRODUCED_IN(__ANDROID_API_T__); |
| 177 | |
| 178 | /** |
Andy Yu | fa8eb01 | 2024-10-15 17:00:09 -0700 | [diff] [blame] | 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 | |
| 192 | /** |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 193 | * 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 | */ |
| 198 | int64_t APerformanceHint_getPreferredUpdateRateNanos( |
Peiyong Lin | 81780c4 | 2023-10-08 21:11:26 +0000 | [diff] [blame] | 199 | APerformanceHintManager* _Nonnull manager) __INTRODUCED_IN(__ANDROID_API_T__); |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 200 | |
| 201 | /** |
Andy Yu | fa8eb01 | 2024-10-15 17:00:09 -0700 | [diff] [blame] | 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 | |
| 210 | /** |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 211 | * Updates this session's target duration for each cycle of work. |
| 212 | * |
| 213 | * @param session The performance hint session instance to update. |
Matt Buckley | cc14642 | 2023-06-28 19:14:02 +0000 | [diff] [blame] | 214 | * @param targetDurationNanos The new desired duration in nanoseconds. This must be positive. |
| 215 | * @return 0 on success. |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 216 | * EINVAL if targetDurationNanos is not positive. |
| 217 | * EPIPE if communication with the system service has failed. |
| 218 | */ |
| 219 | int APerformanceHint_updateTargetWorkDuration( |
Peiyong Lin | 81780c4 | 2023-10-08 21:11:26 +0000 | [diff] [blame] | 220 | APerformanceHintSession* _Nonnull session, |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 221 | int64_t targetDurationNanos) __INTRODUCED_IN(__ANDROID_API_T__); |
| 222 | |
| 223 | /** |
| 224 | * Reports the actual duration for the last cycle of work. |
| 225 | * |
Matt Buckley | cc14642 | 2023-06-28 19:14:02 +0000 | [diff] [blame] | 226 | * 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 Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 228 | * |
| 229 | * @param session The performance hint session instance to update. |
Matt Buckley | cc14642 | 2023-06-28 19:14:02 +0000 | [diff] [blame] | 230 | * @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 Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 233 | * EINVAL if actualDurationNanos is not positive. |
| 234 | * EPIPE if communication with the system service has failed. |
| 235 | */ |
| 236 | int APerformanceHint_reportActualWorkDuration( |
Peiyong Lin | 81780c4 | 2023-10-08 21:11:26 +0000 | [diff] [blame] | 237 | APerformanceHintSession* _Nonnull session, |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 238 | 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 Buckley | feb30df | 2024-11-17 01:56:15 +0000 | [diff] [blame] | 244 | * This cannot be used to close a Java PerformanceHintManager.Session, as its |
| 245 | * lifecycle is tied to the object in the SDK. |
| 246 | * |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 247 | * @param session The performance hint session instance to release. |
| 248 | */ |
| 249 | void APerformanceHint_closeSession( |
Peiyong Lin | 81780c4 | 2023-10-08 21:11:26 +0000 | [diff] [blame] | 250 | APerformanceHintSession* _Nonnull session) __INTRODUCED_IN(__ANDROID_API_T__); |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 251 | |
Peiyong Lin | f9c984f | 2022-11-11 18:28:20 +0000 | [diff] [blame] | 252 | /** |
| 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 Buckley | cc14642 | 2023-06-28 19:14:02 +0000 | [diff] [blame] | 256 | * @param session The performance hint session instance to update. |
Peiyong Lin | f9c984f | 2022-11-11 18:28:20 +0000 | [diff] [blame] | 257 | * @param threadIds The list of threads to be associated with this session. They must be part of |
| 258 | * this app's thread group. |
Matt Buckley | cc14642 | 2023-06-28 19:14:02 +0000 | [diff] [blame] | 259 | * @param size The size of the list of threadIds. |
Peiyong Lin | f9c984f | 2022-11-11 18:28:20 +0000 | [diff] [blame] | 260 | * @return 0 on success. |
Matt Buckley | cc14642 | 2023-06-28 19:14:02 +0000 | [diff] [blame] | 261 | * 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 Lin | f9c984f | 2022-11-11 18:28:20 +0000 | [diff] [blame] | 263 | * EPIPE if communication with the system service has failed. |
Xiang Wang | f6d21b5 | 2023-07-25 17:34:01 -0700 | [diff] [blame] | 264 | * EPERM if any thread id doesn't belong to the application. |
Peiyong Lin | f9c984f | 2022-11-11 18:28:20 +0000 | [diff] [blame] | 265 | */ |
| 266 | int APerformanceHint_setThreads( |
Peiyong Lin | 81780c4 | 2023-10-08 21:11:26 +0000 | [diff] [blame] | 267 | APerformanceHintSession* _Nonnull session, |
| 268 | const pid_t* _Nonnull threadIds, |
Peiyong Lin | f9c984f | 2022-11-11 18:28:20 +0000 | [diff] [blame] | 269 | size_t size) __INTRODUCED_IN(__ANDROID_API_U__); |
| 270 | |
Matt Buckley | cc14642 | 2023-06-28 19:14:02 +0000 | [diff] [blame] | 271 | /** |
| 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 | */ |
| 280 | int APerformanceHint_setPreferPowerEfficiency( |
Peiyong Lin | 81780c4 | 2023-10-08 21:11:26 +0000 | [diff] [blame] | 281 | APerformanceHintSession* _Nonnull session, |
Matt Buckley | cc14642 | 2023-06-28 19:14:02 +0000 | [diff] [blame] | 282 | bool enabled) __INTRODUCED_IN(__ANDROID_API_V__); |
| 283 | |
Peiyong Lin | 81780c4 | 2023-10-08 21:11:26 +0000 | [diff] [blame] | 284 | /** |
| 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 Buckley | 0bbd177 | 2024-01-31 22:10:42 +0000 | [diff] [blame] | 294 | * The work period start timestamp and actual total duration must be greater than zero. |
Peiyong Lin | 81780c4 | 2023-10-08 21:11:26 +0000 | [diff] [blame] | 295 | * |
Matt Buckley | 0bbd177 | 2024-01-31 22:10:42 +0000 | [diff] [blame] | 296 | * 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 Lin | 81780c4 | 2023-10-08 21:11:26 +0000 | [diff] [blame] | 299 | * |
| 300 | * @return 0 on success. |
Matt Buckley | 81cc093 | 2024-01-18 19:56:31 +0000 | [diff] [blame] | 301 | * EINVAL if any duration is an invalid number. |
Peiyong Lin | 81780c4 | 2023-10-08 21:11:26 +0000 | [diff] [blame] | 302 | * EPIPE if communication with the system service has failed. |
| 303 | */ |
| 304 | int APerformanceHint_reportActualWorkDuration2( |
| 305 | APerformanceHintSession* _Nonnull session, |
| 306 | AWorkDuration* _Nonnull workDuration) __INTRODUCED_IN(__ANDROID_API_V__); |
| 307 | |
| 308 | /** |
Matt Buckley | 122a117 | 2024-10-21 12:16:36 -0700 | [diff] [blame] | 309 | * 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 | */ |
| 328 | int 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 | */ |
| 352 | int APerformanceHint_notifyWorkloadReset( |
| 353 | APerformanceHintSession* _Nonnull session, |
| 354 | bool cpu, bool gpu, const char* _Nonnull debugName) __INTRODUCED_IN(36); |
| 355 | |
| 356 | /** |
Peiyong Lin | 81780c4 | 2023-10-08 21:11:26 +0000 | [diff] [blame] | 357 | * 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 Yu | fa8eb01 | 2024-10-15 17:00:09 -0700 | [diff] [blame] | 361 | * @return AWorkDuration pointer. |
Peiyong Lin | 81780c4 | 2023-10-08 21:11:26 +0000 | [diff] [blame] | 362 | */ |
| 363 | AWorkDuration* _Nonnull AWorkDuration_create() __INTRODUCED_IN(__ANDROID_API_V__); |
| 364 | |
| 365 | /** |
Andy Yu | fa8eb01 | 2024-10-15 17:00:09 -0700 | [diff] [blame] | 366 | * Destroys a {@link AWorkDuration} and frees all resources associated with it. |
Peiyong Lin | 81780c4 | 2023-10-08 21:11:26 +0000 | [diff] [blame] | 367 | * |
| 368 | * @param aWorkDuration The {@link AWorkDuration} created by calling {@link AWorkDuration_create()} |
| 369 | */ |
Xiang Wang | 352ff40 | 2024-01-09 13:27:05 -0800 | [diff] [blame] | 370 | void AWorkDuration_release(AWorkDuration* _Nonnull aWorkDuration) |
| 371 | __INTRODUCED_IN(__ANDROID_API_V__); |
Peiyong Lin | 81780c4 | 2023-10-08 21:11:26 +0000 | [diff] [blame] | 372 | |
| 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 Buckley | 81cc093 | 2024-01-18 19:56:31 +0000 | [diff] [blame] | 378 | * CLOCK_MONOTONIC about when the work starts. This timestamp must be greater than zero. |
Peiyong Lin | 81780c4 | 2023-10-08 21:11:26 +0000 | [diff] [blame] | 379 | */ |
| 380 | void 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 Buckley | 81cc093 | 2024-01-18 19:56:31 +0000 | [diff] [blame] | 387 | * @param actualTotalDurationNanos The actual total work duration in nanoseconds. This number must |
| 388 | * be greater than zero. |
Peiyong Lin | 81780c4 | 2023-10-08 21:11:26 +0000 | [diff] [blame] | 389 | */ |
| 390 | void 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 Buckley | 81cc093 | 2024-01-18 19:56:31 +0000 | [diff] [blame] | 397 | * @param actualCpuDurationNanos The actual CPU work duration in nanoseconds. This number must be |
Matt Buckley | 0bbd177 | 2024-01-31 22:10:42 +0000 | [diff] [blame] | 398 | * greater than or equal to zero. If it is equal to zero, that means the CPU was not |
| 399 | * measured. |
Peiyong Lin | 81780c4 | 2023-10-08 21:11:26 +0000 | [diff] [blame] | 400 | */ |
| 401 | void 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 Buckley | 0bbd177 | 2024-01-31 22:10:42 +0000 | [diff] [blame] | 409 | * greater than or equal to zero. If it is equal to zero, that means the GPU was not |
Peiyong Lin | 81780c4 | 2023-10-08 21:11:26 +0000 | [diff] [blame] | 410 | * measured. |
| 411 | */ |
| 412 | void AWorkDuration_setActualGpuDurationNanos(AWorkDuration* _Nonnull aWorkDuration, |
| 413 | int64_t actualGpuDurationNanos) __INTRODUCED_IN(__ANDROID_API_V__); |
| 414 | |
Matt Buckley | feb30df | 2024-11-17 01:56:15 +0000 | [diff] [blame] | 415 | /** |
| 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 | */ |
| 426 | APerformanceHintSession* _Nonnull APerformanceHint_borrowSessionFromJava( |
| 427 | JNIEnv* _Nonnull env, jobject _Nonnull sessionObj) __INTRODUCED_IN(36); |
| 428 | |
Andy Yu | fa8eb01 | 2024-10-15 17:00:09 -0700 | [diff] [blame] | 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); |
Matt Buckley | feb30df | 2024-11-17 01:56:15 +0000 | [diff] [blame] | 522 | |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 523 | __END_DECLS |
| 524 | |
| 525 | #endif // ANDROID_NATIVE_PERFORMANCE_HINT_H |
Matt Buckley | cc14642 | 2023-06-28 19:14:02 +0000 | [diff] [blame] | 526 | |
Peiyong Lin | 81780c4 | 2023-10-08 21:11:26 +0000 | [diff] [blame] | 527 | /** @} */ |