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 | /** |
| 114 | * An opaque type representing a handle to a performance hint session. |
| 115 | * A session can only be acquired from a {@link APerformanceHintManager} |
Matt Buckley | cc14642 | 2023-06-28 19:14:02 +0000 | [diff] [blame] | 116 | * with {@link APerformanceHint_createSession}. It must be |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 117 | * freed with {@link APerformanceHint_closeSession} after use. |
| 118 | * |
| 119 | * A Session represents a group of threads with an inter-related workload such that hints for |
| 120 | * 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] | 121 | * long-lived and not created or destroyed dynamically. |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 122 | * |
Matt Buckley | cc14642 | 2023-06-28 19:14:02 +0000 | [diff] [blame] | 123 | * The work duration API can be used with periodic workloads to dynamically adjust thread |
| 124 | * performance and keep the work on schedule while optimizing the available power budget. |
| 125 | * When using the work duration API, the starting target duration should be specified |
| 126 | * while creating the session, and can later be adjusted with |
| 127 | * {@link APerformanceHint_updateTargetWorkDuration}. While using the work duration |
| 128 | * API, the client is expected to call {@link APerformanceHint_reportActualWorkDuration} each |
| 129 | * cycle to report the actual time taken to complete to the system. |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 130 | * |
Xiang Wang | c8681f8 | 2024-04-08 12:45:59 -0700 | [diff] [blame] | 131 | * Note, methods of {@link APerformanceHintSession_*} are not thread safe so callers must |
| 132 | * ensure thread safety. |
| 133 | * |
Matt Buckley | cc14642 | 2023-06-28 19:14:02 +0000 | [diff] [blame] | 134 | * 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] | 135 | */ |
| 136 | typedef struct APerformanceHintSession APerformanceHintSession; |
| 137 | |
| 138 | /** |
| 139 | * Acquire an instance of the performance hint manager. |
| 140 | * |
Matt Buckley | cc14642 | 2023-06-28 19:14:02 +0000 | [diff] [blame] | 141 | * @return APerformanceHintManager instance on success, nullptr on failure. |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 142 | */ |
Xiang Wang | 352ff40 | 2024-01-09 13:27:05 -0800 | [diff] [blame] | 143 | APerformanceHintManager* _Nullable APerformanceHint_getManager() |
| 144 | __INTRODUCED_IN(__ANDROID_API_T__); |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 145 | |
| 146 | /** |
| 147 | * Creates a session for the given set of threads and sets their initial target work |
| 148 | * duration. |
Matt Buckley | cc14642 | 2023-06-28 19:14:02 +0000 | [diff] [blame] | 149 | * |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 150 | * @param manager The performance hint manager instance. |
| 151 | * @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] | 152 | * this process' thread group. |
| 153 | * @param size The size of the list of threadIds. |
| 154 | * @param initialTargetWorkDurationNanos The target duration in nanoseconds for the new session. |
| 155 | * This must be positive if using the work duration API, or 0 otherwise. |
| 156 | * @return APerformanceHintManager instance on success, nullptr on failure. |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 157 | */ |
Peiyong Lin | 81780c4 | 2023-10-08 21:11:26 +0000 | [diff] [blame] | 158 | APerformanceHintSession* _Nullable APerformanceHint_createSession( |
| 159 | APerformanceHintManager* _Nonnull manager, |
| 160 | const int32_t* _Nonnull threadIds, size_t size, |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 161 | int64_t initialTargetWorkDurationNanos) __INTRODUCED_IN(__ANDROID_API_T__); |
| 162 | |
| 163 | /** |
| 164 | * Get preferred update rate information for this device. |
| 165 | * |
| 166 | * @param manager The performance hint manager instance. |
| 167 | * @return the preferred update rate supported by device software. |
| 168 | */ |
| 169 | int64_t APerformanceHint_getPreferredUpdateRateNanos( |
Peiyong Lin | 81780c4 | 2023-10-08 21:11:26 +0000 | [diff] [blame] | 170 | APerformanceHintManager* _Nonnull manager) __INTRODUCED_IN(__ANDROID_API_T__); |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 171 | |
| 172 | /** |
| 173 | * Updates this session's target duration for each cycle of work. |
| 174 | * |
| 175 | * @param session The performance hint session instance to update. |
Matt Buckley | cc14642 | 2023-06-28 19:14:02 +0000 | [diff] [blame] | 176 | * @param targetDurationNanos The new desired duration in nanoseconds. This must be positive. |
| 177 | * @return 0 on success. |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 178 | * EINVAL if targetDurationNanos is not positive. |
| 179 | * EPIPE if communication with the system service has failed. |
| 180 | */ |
| 181 | int APerformanceHint_updateTargetWorkDuration( |
Peiyong Lin | 81780c4 | 2023-10-08 21:11:26 +0000 | [diff] [blame] | 182 | APerformanceHintSession* _Nonnull session, |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 183 | int64_t targetDurationNanos) __INTRODUCED_IN(__ANDROID_API_T__); |
| 184 | |
| 185 | /** |
| 186 | * Reports the actual duration for the last cycle of work. |
| 187 | * |
Matt Buckley | cc14642 | 2023-06-28 19:14:02 +0000 | [diff] [blame] | 188 | * The system will attempt to adjust the scheduling and performance of the |
| 189 | * 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] | 190 | * |
| 191 | * @param session The performance hint session instance to update. |
Matt Buckley | cc14642 | 2023-06-28 19:14:02 +0000 | [diff] [blame] | 192 | * @param actualDurationNanos The duration of time the thread group took to complete its last |
| 193 | * task in nanoseconds. This must be positive. |
| 194 | * @return 0 on success. |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 195 | * EINVAL if actualDurationNanos is not positive. |
| 196 | * EPIPE if communication with the system service has failed. |
| 197 | */ |
| 198 | int APerformanceHint_reportActualWorkDuration( |
Peiyong Lin | 81780c4 | 2023-10-08 21:11:26 +0000 | [diff] [blame] | 199 | APerformanceHintSession* _Nonnull session, |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 200 | int64_t actualDurationNanos) __INTRODUCED_IN(__ANDROID_API_T__); |
| 201 | |
| 202 | /** |
| 203 | * Release the performance hint manager pointer acquired via |
| 204 | * {@link APerformanceHint_createSession}. |
| 205 | * |
Matt Buckley | feb30df | 2024-11-17 01:56:15 +0000 | [diff] [blame^] | 206 | * This cannot be used to close a Java PerformanceHintManager.Session, as its |
| 207 | * lifecycle is tied to the object in the SDK. |
| 208 | * |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 209 | * @param session The performance hint session instance to release. |
| 210 | */ |
| 211 | void APerformanceHint_closeSession( |
Peiyong Lin | 81780c4 | 2023-10-08 21:11:26 +0000 | [diff] [blame] | 212 | APerformanceHintSession* _Nonnull session) __INTRODUCED_IN(__ANDROID_API_T__); |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 213 | |
Peiyong Lin | f9c984f | 2022-11-11 18:28:20 +0000 | [diff] [blame] | 214 | /** |
| 215 | * Set a list of threads to the performance hint session. This operation will replace |
| 216 | * the current list of threads with the given list of threads. |
| 217 | * |
Matt Buckley | cc14642 | 2023-06-28 19:14:02 +0000 | [diff] [blame] | 218 | * @param session The performance hint session instance to update. |
Peiyong Lin | f9c984f | 2022-11-11 18:28:20 +0000 | [diff] [blame] | 219 | * @param threadIds The list of threads to be associated with this session. They must be part of |
| 220 | * this app's thread group. |
Matt Buckley | cc14642 | 2023-06-28 19:14:02 +0000 | [diff] [blame] | 221 | * @param size The size of the list of threadIds. |
Peiyong Lin | f9c984f | 2022-11-11 18:28:20 +0000 | [diff] [blame] | 222 | * @return 0 on success. |
Matt Buckley | cc14642 | 2023-06-28 19:14:02 +0000 | [diff] [blame] | 223 | * EINVAL if the list of thread ids is empty or if any of the thread ids are not part of |
| 224 | the thread group. |
Peiyong Lin | f9c984f | 2022-11-11 18:28:20 +0000 | [diff] [blame] | 225 | * EPIPE if communication with the system service has failed. |
Xiang Wang | f6d21b5 | 2023-07-25 17:34:01 -0700 | [diff] [blame] | 226 | * EPERM if any thread id doesn't belong to the application. |
Peiyong Lin | f9c984f | 2022-11-11 18:28:20 +0000 | [diff] [blame] | 227 | */ |
| 228 | int APerformanceHint_setThreads( |
Peiyong Lin | 81780c4 | 2023-10-08 21:11:26 +0000 | [diff] [blame] | 229 | APerformanceHintSession* _Nonnull session, |
| 230 | const pid_t* _Nonnull threadIds, |
Peiyong Lin | f9c984f | 2022-11-11 18:28:20 +0000 | [diff] [blame] | 231 | size_t size) __INTRODUCED_IN(__ANDROID_API_U__); |
| 232 | |
Matt Buckley | cc14642 | 2023-06-28 19:14:02 +0000 | [diff] [blame] | 233 | /** |
| 234 | * This tells the session that these threads can be |
| 235 | * safely scheduled to prefer power efficiency over performance. |
| 236 | * |
| 237 | * @param session The performance hint session instance to update. |
| 238 | * @param enabled The flag which sets whether this session will use power-efficient scheduling. |
| 239 | * @return 0 on success. |
| 240 | * EPIPE if communication with the system service has failed. |
| 241 | */ |
| 242 | int APerformanceHint_setPreferPowerEfficiency( |
Peiyong Lin | 81780c4 | 2023-10-08 21:11:26 +0000 | [diff] [blame] | 243 | APerformanceHintSession* _Nonnull session, |
Matt Buckley | cc14642 | 2023-06-28 19:14:02 +0000 | [diff] [blame] | 244 | bool enabled) __INTRODUCED_IN(__ANDROID_API_V__); |
| 245 | |
Peiyong Lin | 81780c4 | 2023-10-08 21:11:26 +0000 | [diff] [blame] | 246 | /** |
| 247 | * Reports the durations for the last cycle of work. |
| 248 | * |
| 249 | * The system will attempt to adjust the scheduling and performance of the |
| 250 | * threads within the thread group to bring the actual duration close to the target duration. |
| 251 | * |
| 252 | * @param session The {@link APerformanceHintSession} instance to update. |
| 253 | * @param workDuration The {@link AWorkDuration} structure of times the thread group took to |
| 254 | * complete its last task in nanoseconds breaking down into different components. |
| 255 | * |
Matt Buckley | 0bbd177 | 2024-01-31 22:10:42 +0000 | [diff] [blame] | 256 | * 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] | 257 | * |
Matt Buckley | 0bbd177 | 2024-01-31 22:10:42 +0000 | [diff] [blame] | 258 | * The actual CPU and GPU durations must be greater than or equal to zero, and at least one |
| 259 | * of them must be greater than zero. When one of them is equal to zero, it means that type |
| 260 | * of work was not measured for this workload. |
Peiyong Lin | 81780c4 | 2023-10-08 21:11:26 +0000 | [diff] [blame] | 261 | * |
| 262 | * @return 0 on success. |
Matt Buckley | 81cc093 | 2024-01-18 19:56:31 +0000 | [diff] [blame] | 263 | * EINVAL if any duration is an invalid number. |
Peiyong Lin | 81780c4 | 2023-10-08 21:11:26 +0000 | [diff] [blame] | 264 | * EPIPE if communication with the system service has failed. |
| 265 | */ |
| 266 | int APerformanceHint_reportActualWorkDuration2( |
| 267 | APerformanceHintSession* _Nonnull session, |
| 268 | AWorkDuration* _Nonnull workDuration) __INTRODUCED_IN(__ANDROID_API_V__); |
| 269 | |
| 270 | /** |
Matt Buckley | 122a117 | 2024-10-21 12:16:36 -0700 | [diff] [blame] | 271 | * Informs the framework of an upcoming increase in the workload of a graphics pipeline |
| 272 | * bound to this session. The user can specify whether the increase is expected to be |
| 273 | * on the CPU, GPU, or both. |
| 274 | * |
| 275 | * Sending hints for both CPU and GPU counts as two separate hints for the purposes of the |
| 276 | * rate limiter. |
| 277 | * |
| 278 | * @param cpu Indicates if the workload increase is expected to affect the CPU. |
| 279 | * @param gpu Indicates if the workload increase is expected to affect the GPU. |
| 280 | * @param debugName A required string used to identify this specific hint during |
| 281 | * tracing. This debug string will only be held for the duration of the |
| 282 | * method, and can be safely discarded after. |
| 283 | * |
| 284 | * @return 0 on success. |
| 285 | * EINVAL if no hints were requested. |
| 286 | * EBUSY if the hint was rate limited. |
| 287 | * EPIPE if communication with the system service has failed. |
| 288 | * ENOTSUP if the hint is not supported. |
| 289 | */ |
| 290 | int APerformanceHint_notifyWorkloadIncrease( |
| 291 | APerformanceHintSession* _Nonnull session, |
| 292 | bool cpu, bool gpu, const char* _Nonnull debugName) __INTRODUCED_IN(36); |
| 293 | |
| 294 | /** |
| 295 | * Informs the framework of an upcoming reset in the workload of a graphics pipeline |
| 296 | * bound to this session, or the imminent start of a new workload. The user can specify |
| 297 | * whether the reset is expected to affect the CPU, GPU, or both. |
| 298 | * |
| 299 | * Sending hints for both CPU and GPU counts as two separate hints for the purposes of the |
| 300 | * this load tracking. |
| 301 | * |
| 302 | * @param cpu Indicates if the workload reset is expected to affect the CPU. |
| 303 | * @param gpu Indicates if the workload reset is expected to affect the GPU. |
| 304 | * @param debugName A required string used to identify this specific hint during |
| 305 | * tracing. This debug string will only be held for the duration of the |
| 306 | * method, and can be safely discarded after. |
| 307 | * |
| 308 | * @return 0 on success. |
| 309 | * EINVAL if no hints were requested. |
| 310 | * EBUSY if the hint was rate limited. |
| 311 | * EPIPE if communication with the system service has failed. |
| 312 | * ENOTSUP if the hint is not supported. |
| 313 | */ |
| 314 | int APerformanceHint_notifyWorkloadReset( |
| 315 | APerformanceHintSession* _Nonnull session, |
| 316 | bool cpu, bool gpu, const char* _Nonnull debugName) __INTRODUCED_IN(36); |
| 317 | |
| 318 | /** |
Peiyong Lin | 81780c4 | 2023-10-08 21:11:26 +0000 | [diff] [blame] | 319 | * Creates a new AWorkDuration. When the client finishes using {@link AWorkDuration}, it should |
| 320 | * call {@link AWorkDuration_release()} to destroy {@link AWorkDuration} and release all resources |
| 321 | * associated with it. |
| 322 | * |
| 323 | * @return AWorkDuration on success and nullptr otherwise. |
| 324 | */ |
| 325 | AWorkDuration* _Nonnull AWorkDuration_create() __INTRODUCED_IN(__ANDROID_API_V__); |
| 326 | |
| 327 | /** |
| 328 | * Destroys {@link AWorkDuration} and free all resources associated to it. |
| 329 | * |
| 330 | * @param aWorkDuration The {@link AWorkDuration} created by calling {@link AWorkDuration_create()} |
| 331 | */ |
Xiang Wang | 352ff40 | 2024-01-09 13:27:05 -0800 | [diff] [blame] | 332 | void AWorkDuration_release(AWorkDuration* _Nonnull aWorkDuration) |
| 333 | __INTRODUCED_IN(__ANDROID_API_V__); |
Peiyong Lin | 81780c4 | 2023-10-08 21:11:26 +0000 | [diff] [blame] | 334 | |
| 335 | /** |
| 336 | * Sets the work period start timestamp in nanoseconds. |
| 337 | * |
| 338 | * @param aWorkDuration The {@link AWorkDuration} created by calling {@link AWorkDuration_create()} |
| 339 | * @param workPeriodStartTimestampNanos The work period start timestamp in nanoseconds based on |
Matt Buckley | 81cc093 | 2024-01-18 19:56:31 +0000 | [diff] [blame] | 340 | * 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] | 341 | */ |
| 342 | void AWorkDuration_setWorkPeriodStartTimestampNanos(AWorkDuration* _Nonnull aWorkDuration, |
| 343 | int64_t workPeriodStartTimestampNanos) __INTRODUCED_IN(__ANDROID_API_V__); |
| 344 | |
| 345 | /** |
| 346 | * Sets the actual total work duration in nanoseconds. |
| 347 | * |
| 348 | * @param aWorkDuration The {@link AWorkDuration} created by calling {@link AWorkDuration_create()} |
Matt Buckley | 81cc093 | 2024-01-18 19:56:31 +0000 | [diff] [blame] | 349 | * @param actualTotalDurationNanos The actual total work duration in nanoseconds. This number must |
| 350 | * be greater than zero. |
Peiyong Lin | 81780c4 | 2023-10-08 21:11:26 +0000 | [diff] [blame] | 351 | */ |
| 352 | void AWorkDuration_setActualTotalDurationNanos(AWorkDuration* _Nonnull aWorkDuration, |
| 353 | int64_t actualTotalDurationNanos) __INTRODUCED_IN(__ANDROID_API_V__); |
| 354 | |
| 355 | /** |
| 356 | * Sets the actual CPU work duration in nanoseconds. |
| 357 | * |
| 358 | * @param aWorkDuration The {@link AWorkDuration} created by calling {@link AWorkDuration_create()} |
Matt Buckley | 81cc093 | 2024-01-18 19:56:31 +0000 | [diff] [blame] | 359 | * @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] | 360 | * greater than or equal to zero. If it is equal to zero, that means the CPU was not |
| 361 | * measured. |
Peiyong Lin | 81780c4 | 2023-10-08 21:11:26 +0000 | [diff] [blame] | 362 | */ |
| 363 | void AWorkDuration_setActualCpuDurationNanos(AWorkDuration* _Nonnull aWorkDuration, |
| 364 | int64_t actualCpuDurationNanos) __INTRODUCED_IN(__ANDROID_API_V__); |
| 365 | |
| 366 | /** |
| 367 | * Sets the actual GPU work duration in nanoseconds. |
| 368 | * |
| 369 | * @param aWorkDuration The {@link AWorkDuration} created by calling {@link AWorkDuration_create()}. |
| 370 | * @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] | 371 | * 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] | 372 | * measured. |
| 373 | */ |
| 374 | void AWorkDuration_setActualGpuDurationNanos(AWorkDuration* _Nonnull aWorkDuration, |
| 375 | int64_t actualGpuDurationNanos) __INTRODUCED_IN(__ANDROID_API_V__); |
| 376 | |
Matt Buckley | feb30df | 2024-11-17 01:56:15 +0000 | [diff] [blame^] | 377 | /** |
| 378 | * Return the APerformanceHintSession wrapped by a Java PerformanceHintManager.Session object. |
| 379 | * |
| 380 | * The Java session maintains ownership over the wrapped native session, so it cannot be |
| 381 | * closed using {@link APerformanceHint_closeSession}. |
| 382 | * |
| 383 | * @param env The Java environment where the PerformanceHintManager.Session lives. |
| 384 | * @param sessionObj The Java Session to unwrap. |
| 385 | * |
| 386 | * @return A pointer to the APerformanceHintManager that backs the Java Session. |
| 387 | */ |
| 388 | APerformanceHintSession* _Nonnull APerformanceHint_borrowSessionFromJava( |
| 389 | JNIEnv* _Nonnull env, jobject _Nonnull sessionObj) __INTRODUCED_IN(36); |
| 390 | |
| 391 | |
Bo Liu | 406c8ab | 2021-11-10 19:20:40 -0500 | [diff] [blame] | 392 | __END_DECLS |
| 393 | |
| 394 | #endif // ANDROID_NATIVE_PERFORMANCE_HINT_H |
Matt Buckley | cc14642 | 2023-06-28 19:14:02 +0000 | [diff] [blame] | 395 | |
Peiyong Lin | 81780c4 | 2023-10-08 21:11:26 +0000 | [diff] [blame] | 396 | /** @} */ |