Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [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 | |
| 17 | #define LOG_TAG "perf_hint" |
| 18 | |
Matt Buckley | 56093a7 | 2022-11-07 21:50:50 +0000 | [diff] [blame] | 19 | #include <aidl/android/hardware/power/SessionHint.h> |
Matt Buckley | 423c1b3 | 2023-06-28 19:13:42 +0000 | [diff] [blame] | 20 | #include <aidl/android/hardware/power/SessionMode.h> |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 21 | #include <aidl/android/hardware/power/SessionTag.h> |
| 22 | #include <aidl/android/hardware/power/WorkDuration.h> |
| 23 | #include <aidl/android/os/IHintManager.h> |
| 24 | #include <aidl/android/os/IHintSession.h> |
Matt Buckley | e3d5c3a | 2023-12-01 23:10:32 +0000 | [diff] [blame] | 25 | #include <android-base/stringprintf.h> |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 26 | #include <android/binder_manager.h> |
| 27 | #include <android/binder_status.h> |
Bo Liu | 2b739bb | 2021-11-10 19:20:03 -0500 | [diff] [blame] | 28 | #include <android/performance_hint.h> |
Matt Buckley | e3d5c3a | 2023-12-01 23:10:32 +0000 | [diff] [blame] | 29 | #include <android/trace.h> |
Peiyong Lin | 70de085 | 2023-10-25 21:12:35 +0000 | [diff] [blame] | 30 | #include <inttypes.h> |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 31 | #include <performance_hint_private.h> |
| 32 | #include <utils/SystemClock.h> |
| 33 | |
Matt Buckley | 56093a7 | 2022-11-07 21:50:50 +0000 | [diff] [blame] | 34 | #include <chrono> |
Matt Buckley | e3d5c3a | 2023-12-01 23:10:32 +0000 | [diff] [blame] | 35 | #include <set> |
Bo Liu | 2b739bb | 2021-11-10 19:20:03 -0500 | [diff] [blame] | 36 | #include <utility> |
| 37 | #include <vector> |
| 38 | |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 39 | using namespace android; |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 40 | using namespace aidl::android::os; |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 41 | |
Matt Buckley | 56093a7 | 2022-11-07 21:50:50 +0000 | [diff] [blame] | 42 | using namespace std::chrono_literals; |
| 43 | |
Matt Buckley | 7c2de58 | 2024-04-05 08:41:35 +0000 | [diff] [blame] | 44 | // Namespace for AIDL types coming from the PowerHAL |
| 45 | namespace hal = aidl::android::hardware::power; |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 46 | |
Matt Buckley | e3d5c3a | 2023-12-01 23:10:32 +0000 | [diff] [blame] | 47 | using android::base::StringPrintf; |
Matt Buckley | 56093a7 | 2022-11-07 21:50:50 +0000 | [diff] [blame] | 48 | |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 49 | struct APerformanceHintSession; |
| 50 | |
Matt Buckley | 56093a7 | 2022-11-07 21:50:50 +0000 | [diff] [blame] | 51 | constexpr int64_t SEND_HINT_TIMEOUT = std::chrono::nanoseconds(100ms).count(); |
Matt Buckley | 7c2de58 | 2024-04-05 08:41:35 +0000 | [diff] [blame] | 52 | struct AWorkDuration : public hal::WorkDuration {}; |
Matt Buckley | 56093a7 | 2022-11-07 21:50:50 +0000 | [diff] [blame] | 53 | |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 54 | struct APerformanceHintManager { |
| 55 | public: |
| 56 | static APerformanceHintManager* getInstance(); |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 57 | APerformanceHintManager(std::shared_ptr<IHintManager> service, int64_t preferredRateNanos); |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 58 | APerformanceHintManager() = delete; |
| 59 | ~APerformanceHintManager() = default; |
| 60 | |
| 61 | APerformanceHintSession* createSession(const int32_t* threadIds, size_t size, |
Matt Buckley | e073c73 | 2024-04-05 22:32:31 +0000 | [diff] [blame] | 62 | int64_t initialTargetWorkDurationNanos, |
| 63 | hal::SessionTag tag = hal::SessionTag::OTHER); |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 64 | int64_t getPreferredRateNanos() const; |
| 65 | |
| 66 | private: |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 67 | // Necessary to create an empty binder object |
| 68 | static void* tokenStubOnCreate(void*) { |
| 69 | return nullptr; |
| 70 | } |
| 71 | static void tokenStubOnDestroy(void*) {} |
| 72 | static binder_status_t tokenStubOnTransact(AIBinder*, transaction_code_t, const AParcel*, |
| 73 | AParcel*) { |
| 74 | return STATUS_OK; |
| 75 | } |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 76 | |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 77 | static APerformanceHintManager* create(std::shared_ptr<IHintManager> iHintManager); |
| 78 | |
| 79 | std::shared_ptr<IHintManager> mHintManager; |
| 80 | ndk::SpAIBinder mToken; |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 81 | const int64_t mPreferredRateNanos; |
| 82 | }; |
| 83 | |
| 84 | struct APerformanceHintSession { |
| 85 | public: |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 86 | APerformanceHintSession(std::shared_ptr<IHintManager> hintManager, |
| 87 | std::shared_ptr<IHintSession> session, int64_t preferredRateNanos, |
Matt Buckley | e073c73 | 2024-04-05 22:32:31 +0000 | [diff] [blame] | 88 | int64_t targetDurationNanos, |
| 89 | std::optional<hal::SessionConfig> sessionConfig); |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 90 | APerformanceHintSession() = delete; |
| 91 | ~APerformanceHintSession(); |
| 92 | |
| 93 | int updateTargetWorkDuration(int64_t targetDurationNanos); |
| 94 | int reportActualWorkDuration(int64_t actualDurationNanos); |
Steven Moreland | 42a8cce | 2023-03-03 23:31:17 +0000 | [diff] [blame] | 95 | int sendHint(SessionHint hint); |
Peiyong Lin | 095de76 | 2022-11-11 18:28:12 +0000 | [diff] [blame] | 96 | int setThreads(const int32_t* threadIds, size_t size); |
| 97 | int getThreadIds(int32_t* const threadIds, size_t* size); |
Matt Buckley | 423c1b3 | 2023-06-28 19:13:42 +0000 | [diff] [blame] | 98 | int setPreferPowerEfficiency(bool enabled); |
Peiyong Lin | 70de085 | 2023-10-25 21:12:35 +0000 | [diff] [blame] | 99 | int reportActualWorkDuration(AWorkDuration* workDuration); |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 100 | |
| 101 | private: |
| 102 | friend struct APerformanceHintManager; |
| 103 | |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 104 | int reportActualWorkDurationInternal(AWorkDuration* workDuration); |
Peiyong Lin | 70de085 | 2023-10-25 21:12:35 +0000 | [diff] [blame] | 105 | |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 106 | std::shared_ptr<IHintManager> mHintManager; |
| 107 | std::shared_ptr<IHintSession> mHintSession; |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 108 | // HAL preferred update rate |
| 109 | const int64_t mPreferredRateNanos; |
| 110 | // Target duration for choosing update rate |
| 111 | int64_t mTargetDurationNanos; |
Wei Wang | 00feb50 | 2022-10-18 10:56:59 -0700 | [diff] [blame] | 112 | // First target hit timestamp |
| 113 | int64_t mFirstTargetMetTimestamp; |
| 114 | // Last target hit timestamp |
| 115 | int64_t mLastTargetMetTimestamp; |
Matt Buckley | 56093a7 | 2022-11-07 21:50:50 +0000 | [diff] [blame] | 116 | // Last hint reported from sendHint indexed by hint value |
| 117 | std::vector<int64_t> mLastHintSentTimestamp; |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 118 | // Cached samples |
Matt Buckley | 7c2de58 | 2024-04-05 08:41:35 +0000 | [diff] [blame] | 119 | std::vector<hal::WorkDuration> mActualWorkDurations; |
Matt Buckley | e3d5c3a | 2023-12-01 23:10:32 +0000 | [diff] [blame] | 120 | std::string mSessionName; |
Matt Buckley | e073c73 | 2024-04-05 22:32:31 +0000 | [diff] [blame] | 121 | static int64_t sIDCounter; |
Matt Buckley | e3d5c3a | 2023-12-01 23:10:32 +0000 | [diff] [blame] | 122 | // The most recent set of thread IDs |
| 123 | std::vector<int32_t> mLastThreadIDs; |
Matt Buckley | e073c73 | 2024-04-05 22:32:31 +0000 | [diff] [blame] | 124 | std::optional<hal::SessionConfig> mSessionConfig; |
Matt Buckley | e3d5c3a | 2023-12-01 23:10:32 +0000 | [diff] [blame] | 125 | // Tracing helpers |
| 126 | void traceThreads(std::vector<int32_t>& tids); |
| 127 | void tracePowerEfficient(bool powerEfficient); |
| 128 | void traceActualDuration(int64_t actualDuration); |
| 129 | void traceBatchSize(size_t batchSize); |
| 130 | void traceTargetDuration(int64_t targetDuration); |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 131 | }; |
| 132 | |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 133 | static std::shared_ptr<IHintManager>* gIHintManagerForTesting = nullptr; |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 134 | static APerformanceHintManager* gHintManagerForTesting = nullptr; |
Matt Buckley | e073c73 | 2024-04-05 22:32:31 +0000 | [diff] [blame] | 135 | // Start above the int32 range so we don't collide with config sessions |
| 136 | int64_t APerformanceHintSession::sIDCounter = INT32_MAX; |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 137 | |
| 138 | // ===================================== APerformanceHintManager implementation |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 139 | APerformanceHintManager::APerformanceHintManager(std::shared_ptr<IHintManager> manager, |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 140 | int64_t preferredRateNanos) |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 141 | : mHintManager(std::move(manager)), mPreferredRateNanos(preferredRateNanos) { |
| 142 | static AIBinder_Class* tokenBinderClass = |
| 143 | AIBinder_Class_define("phm_token", tokenStubOnCreate, tokenStubOnDestroy, |
| 144 | tokenStubOnTransact); |
| 145 | mToken = ndk::SpAIBinder(AIBinder_new(tokenBinderClass, nullptr)); |
| 146 | } |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 147 | |
| 148 | APerformanceHintManager* APerformanceHintManager::getInstance() { |
| 149 | if (gHintManagerForTesting) return gHintManagerForTesting; |
| 150 | if (gIHintManagerForTesting) { |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 151 | APerformanceHintManager* manager = create(*gIHintManagerForTesting); |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 152 | gIHintManagerForTesting = nullptr; |
| 153 | return manager; |
| 154 | } |
| 155 | static APerformanceHintManager* instance = create(nullptr); |
| 156 | return instance; |
| 157 | } |
| 158 | |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 159 | APerformanceHintManager* APerformanceHintManager::create(std::shared_ptr<IHintManager> manager) { |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 160 | if (!manager) { |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 161 | manager = IHintManager::fromBinder( |
| 162 | ndk::SpAIBinder(AServiceManager_waitForService("performance_hint"))); |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 163 | } |
| 164 | if (manager == nullptr) { |
| 165 | ALOGE("%s: PerformanceHint service is not ready ", __FUNCTION__); |
| 166 | return nullptr; |
| 167 | } |
| 168 | int64_t preferredRateNanos = -1L; |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 169 | ndk::ScopedAStatus ret = manager->getHintSessionPreferredRate(&preferredRateNanos); |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 170 | if (!ret.isOk()) { |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 171 | ALOGE("%s: PerformanceHint cannot get preferred rate. %s", __FUNCTION__, ret.getMessage()); |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 172 | return nullptr; |
| 173 | } |
| 174 | if (preferredRateNanos <= 0) { |
Bo Liu | d6a0960 | 2021-07-26 14:48:41 -0400 | [diff] [blame] | 175 | preferredRateNanos = -1L; |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 176 | } |
| 177 | return new APerformanceHintManager(std::move(manager), preferredRateNanos); |
| 178 | } |
| 179 | |
| 180 | APerformanceHintSession* APerformanceHintManager::createSession( |
Matt Buckley | e073c73 | 2024-04-05 22:32:31 +0000 | [diff] [blame] | 181 | const int32_t* threadIds, size_t size, int64_t initialTargetWorkDurationNanos, |
| 182 | hal::SessionTag tag) { |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 183 | std::vector<int32_t> tids(threadIds, threadIds + size); |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 184 | std::shared_ptr<IHintSession> session; |
Matt Buckley | e073c73 | 2024-04-05 22:32:31 +0000 | [diff] [blame] | 185 | ndk::ScopedAStatus ret; |
| 186 | std::optional<hal::SessionConfig> sessionConfig; |
| 187 | ret = mHintManager->createHintSessionWithConfig(mToken, tids, initialTargetWorkDurationNanos, |
| 188 | tag, &sessionConfig, &session); |
| 189 | |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 190 | if (!ret.isOk() || !session) { |
| 191 | return nullptr; |
| 192 | } |
Matt Buckley | e3d5c3a | 2023-12-01 23:10:32 +0000 | [diff] [blame] | 193 | auto out = new APerformanceHintSession(mHintManager, std::move(session), mPreferredRateNanos, |
Matt Buckley | e073c73 | 2024-04-05 22:32:31 +0000 | [diff] [blame] | 194 | initialTargetWorkDurationNanos, sessionConfig); |
Matt Buckley | e3d5c3a | 2023-12-01 23:10:32 +0000 | [diff] [blame] | 195 | out->traceThreads(tids); |
| 196 | out->traceTargetDuration(initialTargetWorkDurationNanos); |
| 197 | out->tracePowerEfficient(false); |
| 198 | return out; |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | int64_t APerformanceHintManager::getPreferredRateNanos() const { |
| 202 | return mPreferredRateNanos; |
| 203 | } |
| 204 | |
| 205 | // ===================================== APerformanceHintSession implementation |
| 206 | |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 207 | APerformanceHintSession::APerformanceHintSession(std::shared_ptr<IHintManager> hintManager, |
| 208 | std::shared_ptr<IHintSession> session, |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 209 | int64_t preferredRateNanos, |
Matt Buckley | e073c73 | 2024-04-05 22:32:31 +0000 | [diff] [blame] | 210 | int64_t targetDurationNanos, |
| 211 | std::optional<hal::SessionConfig> sessionConfig) |
Peiyong Lin | 095de76 | 2022-11-11 18:28:12 +0000 | [diff] [blame] | 212 | : mHintManager(hintManager), |
| 213 | mHintSession(std::move(session)), |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 214 | mPreferredRateNanos(preferredRateNanos), |
| 215 | mTargetDurationNanos(targetDurationNanos), |
Wei Wang | 00feb50 | 2022-10-18 10:56:59 -0700 | [diff] [blame] | 216 | mFirstTargetMetTimestamp(0), |
Matt Buckley | e073c73 | 2024-04-05 22:32:31 +0000 | [diff] [blame] | 217 | mLastTargetMetTimestamp(0), |
| 218 | mSessionConfig(sessionConfig) { |
| 219 | if (sessionConfig->id > INT32_MAX) { |
| 220 | ALOGE("Session ID too large, must fit 32-bit integer"); |
| 221 | } |
| 222 | constexpr int numEnums = |
| 223 | ndk::enum_range<hal::SessionHint>().end() - ndk::enum_range<hal::SessionHint>().begin(); |
| 224 | mLastHintSentTimestamp = std::vector<int64_t>(numEnums, 0); |
| 225 | int64_t traceId = sessionConfig.has_value() ? sessionConfig->id : ++sIDCounter; |
| 226 | mSessionName = android::base::StringPrintf("ADPF Session %" PRId64, traceId); |
Matt Buckley | 56093a7 | 2022-11-07 21:50:50 +0000 | [diff] [blame] | 227 | } |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 228 | |
| 229 | APerformanceHintSession::~APerformanceHintSession() { |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 230 | ndk::ScopedAStatus ret = mHintSession->close(); |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 231 | if (!ret.isOk()) { |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 232 | ALOGE("%s: HintSession close failed: %s", __FUNCTION__, ret.getMessage()); |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 233 | } |
| 234 | } |
| 235 | |
| 236 | int APerformanceHintSession::updateTargetWorkDuration(int64_t targetDurationNanos) { |
| 237 | if (targetDurationNanos <= 0) { |
| 238 | ALOGE("%s: targetDurationNanos must be positive", __FUNCTION__); |
| 239 | return EINVAL; |
| 240 | } |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 241 | ndk::ScopedAStatus ret = mHintSession->updateTargetWorkDuration(targetDurationNanos); |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 242 | if (!ret.isOk()) { |
Matt Buckley | 354cc0a | 2022-09-28 20:54:46 +0000 | [diff] [blame] | 243 | ALOGE("%s: HintSession updateTargetWorkDuration failed: %s", __FUNCTION__, |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 244 | ret.getMessage()); |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 245 | return EPIPE; |
| 246 | } |
| 247 | mTargetDurationNanos = targetDurationNanos; |
| 248 | /** |
| 249 | * Most of the workload is target_duration dependent, so now clear the cached samples |
| 250 | * as they are most likely obsolete. |
| 251 | */ |
Peiyong Lin | 70de085 | 2023-10-25 21:12:35 +0000 | [diff] [blame] | 252 | mActualWorkDurations.clear(); |
Matt Buckley | e3d5c3a | 2023-12-01 23:10:32 +0000 | [diff] [blame] | 253 | traceBatchSize(0); |
| 254 | traceTargetDuration(targetDurationNanos); |
Wei Wang | 00feb50 | 2022-10-18 10:56:59 -0700 | [diff] [blame] | 255 | mFirstTargetMetTimestamp = 0; |
| 256 | mLastTargetMetTimestamp = 0; |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 257 | return 0; |
| 258 | } |
| 259 | |
| 260 | int APerformanceHintSession::reportActualWorkDuration(int64_t actualDurationNanos) { |
Matt Buckley | 7c2de58 | 2024-04-05 08:41:35 +0000 | [diff] [blame] | 261 | hal::WorkDuration workDuration{.durationNanos = actualDurationNanos, |
| 262 | .workPeriodStartTimestampNanos = 0, |
| 263 | .cpuDurationNanos = actualDurationNanos, |
| 264 | .gpuDurationNanos = 0}; |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 265 | |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 266 | return reportActualWorkDurationInternal(static_cast<AWorkDuration*>(&workDuration)); |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 267 | } |
| 268 | |
Steven Moreland | 42a8cce | 2023-03-03 23:31:17 +0000 | [diff] [blame] | 269 | int APerformanceHintSession::sendHint(SessionHint hint) { |
Matt Buckley | 56093a7 | 2022-11-07 21:50:50 +0000 | [diff] [blame] | 270 | if (hint < 0 || hint >= static_cast<int32_t>(mLastHintSentTimestamp.size())) { |
| 271 | ALOGE("%s: invalid session hint %d", __FUNCTION__, hint); |
Matt Buckley | 354cc0a | 2022-09-28 20:54:46 +0000 | [diff] [blame] | 272 | return EINVAL; |
| 273 | } |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 274 | int64_t now = uptimeNanos(); |
Matt Buckley | 56093a7 | 2022-11-07 21:50:50 +0000 | [diff] [blame] | 275 | |
| 276 | // Limit sendHint to a pre-detemined rate for safety |
| 277 | if (now < (mLastHintSentTimestamp[hint] + SEND_HINT_TIMEOUT)) { |
| 278 | return 0; |
| 279 | } |
Matt Buckley | 354cc0a | 2022-09-28 20:54:46 +0000 | [diff] [blame] | 280 | |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 281 | ndk::ScopedAStatus ret = mHintSession->sendHint(hint); |
Matt Buckley | 354cc0a | 2022-09-28 20:54:46 +0000 | [diff] [blame] | 282 | |
| 283 | if (!ret.isOk()) { |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 284 | ALOGE("%s: HintSession sendHint failed: %s", __FUNCTION__, ret.getMessage()); |
Matt Buckley | 354cc0a | 2022-09-28 20:54:46 +0000 | [diff] [blame] | 285 | return EPIPE; |
| 286 | } |
Matt Buckley | 56093a7 | 2022-11-07 21:50:50 +0000 | [diff] [blame] | 287 | mLastHintSentTimestamp[hint] = now; |
Matt Buckley | 354cc0a | 2022-09-28 20:54:46 +0000 | [diff] [blame] | 288 | return 0; |
| 289 | } |
| 290 | |
Peiyong Lin | 095de76 | 2022-11-11 18:28:12 +0000 | [diff] [blame] | 291 | int APerformanceHintSession::setThreads(const int32_t* threadIds, size_t size) { |
| 292 | if (size == 0) { |
| 293 | ALOGE("%s: the list of thread ids must not be empty.", __FUNCTION__); |
| 294 | return EINVAL; |
| 295 | } |
| 296 | std::vector<int32_t> tids(threadIds, threadIds + size); |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 297 | ndk::ScopedAStatus ret = mHintManager->setHintSessionThreads(mHintSession, tids); |
Peiyong Lin | 095de76 | 2022-11-11 18:28:12 +0000 | [diff] [blame] | 298 | if (!ret.isOk()) { |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 299 | ALOGE("%s: failed: %s", __FUNCTION__, ret.getMessage()); |
| 300 | if (ret.getExceptionCode() == EX_ILLEGAL_ARGUMENT) { |
Peiyong Lin | 095de76 | 2022-11-11 18:28:12 +0000 | [diff] [blame] | 301 | return EINVAL; |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 302 | } else if (ret.getExceptionCode() == EX_SECURITY) { |
Xiang Wang | bee6f16 | 2023-07-18 17:58:10 -0700 | [diff] [blame] | 303 | return EPERM; |
Peiyong Lin | 095de76 | 2022-11-11 18:28:12 +0000 | [diff] [blame] | 304 | } |
| 305 | return EPIPE; |
| 306 | } |
Matt Buckley | e3d5c3a | 2023-12-01 23:10:32 +0000 | [diff] [blame] | 307 | |
| 308 | traceThreads(tids); |
| 309 | |
Peiyong Lin | 095de76 | 2022-11-11 18:28:12 +0000 | [diff] [blame] | 310 | return 0; |
| 311 | } |
| 312 | |
| 313 | int APerformanceHintSession::getThreadIds(int32_t* const threadIds, size_t* size) { |
| 314 | std::vector<int32_t> tids; |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 315 | ndk::ScopedAStatus ret = mHintManager->getHintSessionThreadIds(mHintSession, &tids); |
Peiyong Lin | 095de76 | 2022-11-11 18:28:12 +0000 | [diff] [blame] | 316 | if (!ret.isOk()) { |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 317 | ALOGE("%s: failed: %s", __FUNCTION__, ret.getMessage()); |
Peiyong Lin | 095de76 | 2022-11-11 18:28:12 +0000 | [diff] [blame] | 318 | return EPIPE; |
| 319 | } |
| 320 | |
| 321 | // When threadIds is nullptr, this is the first call to determine the size |
| 322 | // of the thread ids list. |
| 323 | if (threadIds == nullptr) { |
| 324 | *size = tids.size(); |
| 325 | return 0; |
| 326 | } |
| 327 | |
| 328 | // Second call to return the actual list of thread ids. |
| 329 | *size = tids.size(); |
| 330 | for (size_t i = 0; i < *size; ++i) { |
| 331 | threadIds[i] = tids[i]; |
| 332 | } |
| 333 | return 0; |
| 334 | } |
| 335 | |
Matt Buckley | 423c1b3 | 2023-06-28 19:13:42 +0000 | [diff] [blame] | 336 | int APerformanceHintSession::setPreferPowerEfficiency(bool enabled) { |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 337 | ndk::ScopedAStatus ret = |
Matt Buckley | 7c2de58 | 2024-04-05 08:41:35 +0000 | [diff] [blame] | 338 | mHintSession->setMode(static_cast<int32_t>(hal::SessionMode::POWER_EFFICIENCY), |
| 339 | enabled); |
Matt Buckley | 423c1b3 | 2023-06-28 19:13:42 +0000 | [diff] [blame] | 340 | |
| 341 | if (!ret.isOk()) { |
| 342 | ALOGE("%s: HintSession setPreferPowerEfficiency failed: %s", __FUNCTION__, |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 343 | ret.getMessage()); |
Matt Buckley | 423c1b3 | 2023-06-28 19:13:42 +0000 | [diff] [blame] | 344 | return EPIPE; |
| 345 | } |
Matt Buckley | e3d5c3a | 2023-12-01 23:10:32 +0000 | [diff] [blame] | 346 | tracePowerEfficient(enabled); |
Matt Buckley | 423c1b3 | 2023-06-28 19:13:42 +0000 | [diff] [blame] | 347 | return OK; |
| 348 | } |
| 349 | |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 350 | int APerformanceHintSession::reportActualWorkDuration(AWorkDuration* workDuration) { |
Peiyong Lin | 70de085 | 2023-10-25 21:12:35 +0000 | [diff] [blame] | 351 | return reportActualWorkDurationInternal(workDuration); |
| 352 | } |
| 353 | |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 354 | int APerformanceHintSession::reportActualWorkDurationInternal(AWorkDuration* workDuration) { |
| 355 | int64_t actualTotalDurationNanos = workDuration->durationNanos; |
Peiyong Lin | 70de085 | 2023-10-25 21:12:35 +0000 | [diff] [blame] | 356 | int64_t now = uptimeNanos(); |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 357 | workDuration->timeStampNanos = now; |
| 358 | traceActualDuration(workDuration->durationNanos); |
Peiyong Lin | 70de085 | 2023-10-25 21:12:35 +0000 | [diff] [blame] | 359 | mActualWorkDurations.push_back(std::move(*workDuration)); |
| 360 | |
| 361 | if (actualTotalDurationNanos >= mTargetDurationNanos) { |
| 362 | // Reset timestamps if we are equal or over the target. |
| 363 | mFirstTargetMetTimestamp = 0; |
| 364 | } else { |
| 365 | // Set mFirstTargetMetTimestamp for first time meeting target. |
| 366 | if (!mFirstTargetMetTimestamp || !mLastTargetMetTimestamp || |
| 367 | (now - mLastTargetMetTimestamp > 2 * mPreferredRateNanos)) { |
| 368 | mFirstTargetMetTimestamp = now; |
| 369 | } |
| 370 | /** |
| 371 | * Rate limit the change if the update is over mPreferredRateNanos since first |
| 372 | * meeting target and less than mPreferredRateNanos since last meeting target. |
| 373 | */ |
| 374 | if (now - mFirstTargetMetTimestamp > mPreferredRateNanos && |
| 375 | now - mLastTargetMetTimestamp <= mPreferredRateNanos) { |
Matt Buckley | e3d5c3a | 2023-12-01 23:10:32 +0000 | [diff] [blame] | 376 | traceBatchSize(mActualWorkDurations.size()); |
Peiyong Lin | 70de085 | 2023-10-25 21:12:35 +0000 | [diff] [blame] | 377 | return 0; |
| 378 | } |
| 379 | mLastTargetMetTimestamp = now; |
| 380 | } |
| 381 | |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 382 | ndk::ScopedAStatus ret = mHintSession->reportActualWorkDuration2(mActualWorkDurations); |
Peiyong Lin | 70de085 | 2023-10-25 21:12:35 +0000 | [diff] [blame] | 383 | if (!ret.isOk()) { |
| 384 | ALOGE("%s: HintSession reportActualWorkDuration failed: %s", __FUNCTION__, |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 385 | ret.getMessage()); |
Peiyong Lin | 70de085 | 2023-10-25 21:12:35 +0000 | [diff] [blame] | 386 | mFirstTargetMetTimestamp = 0; |
| 387 | mLastTargetMetTimestamp = 0; |
Matt Buckley | e3d5c3a | 2023-12-01 23:10:32 +0000 | [diff] [blame] | 388 | traceBatchSize(mActualWorkDurations.size()); |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 389 | return ret.getExceptionCode() == EX_ILLEGAL_ARGUMENT ? EINVAL : EPIPE; |
Peiyong Lin | 70de085 | 2023-10-25 21:12:35 +0000 | [diff] [blame] | 390 | } |
| 391 | mActualWorkDurations.clear(); |
Matt Buckley | e3d5c3a | 2023-12-01 23:10:32 +0000 | [diff] [blame] | 392 | traceBatchSize(0); |
Peiyong Lin | 70de085 | 2023-10-25 21:12:35 +0000 | [diff] [blame] | 393 | |
| 394 | return 0; |
| 395 | } |
Matt Buckley | e3d5c3a | 2023-12-01 23:10:32 +0000 | [diff] [blame] | 396 | // ===================================== Tracing helpers |
| 397 | |
| 398 | void APerformanceHintSession::traceThreads(std::vector<int32_t>& tids) { |
| 399 | std::set<int32_t> tidSet{tids.begin(), tids.end()}; |
| 400 | |
| 401 | // Disable old TID tracing |
| 402 | for (int32_t tid : mLastThreadIDs) { |
| 403 | if (!tidSet.count(tid)) { |
| 404 | std::string traceName = |
| 405 | android::base::StringPrintf("%s TID: %" PRId32, mSessionName.c_str(), tid); |
| 406 | ATrace_setCounter(traceName.c_str(), 0); |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | // Add new TID tracing |
| 411 | for (int32_t tid : tids) { |
| 412 | std::string traceName = |
| 413 | android::base::StringPrintf("%s TID: %" PRId32, mSessionName.c_str(), tid); |
| 414 | ATrace_setCounter(traceName.c_str(), 1); |
| 415 | } |
| 416 | |
| 417 | mLastThreadIDs = std::move(tids); |
| 418 | } |
| 419 | |
| 420 | void APerformanceHintSession::tracePowerEfficient(bool powerEfficient) { |
| 421 | ATrace_setCounter((mSessionName + " power efficiency mode").c_str(), powerEfficient); |
| 422 | } |
| 423 | |
| 424 | void APerformanceHintSession::traceActualDuration(int64_t actualDuration) { |
| 425 | ATrace_setCounter((mSessionName + " actual duration").c_str(), actualDuration); |
| 426 | } |
| 427 | |
| 428 | void APerformanceHintSession::traceBatchSize(size_t batchSize) { |
| 429 | std::string traceName = StringPrintf("%s batch size", mSessionName.c_str()); |
| 430 | ATrace_setCounter((mSessionName + " batch size").c_str(), batchSize); |
| 431 | } |
| 432 | |
| 433 | void APerformanceHintSession::traceTargetDuration(int64_t targetDuration) { |
| 434 | ATrace_setCounter((mSessionName + " target duration").c_str(), targetDuration); |
| 435 | } |
Peiyong Lin | 70de085 | 2023-10-25 21:12:35 +0000 | [diff] [blame] | 436 | |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 437 | // ===================================== C API |
| 438 | APerformanceHintManager* APerformanceHint_getManager() { |
| 439 | return APerformanceHintManager::getInstance(); |
| 440 | } |
| 441 | |
Matt Buckley | 83f7709 | 2024-01-18 19:57:29 +0000 | [diff] [blame] | 442 | #define VALIDATE_PTR(ptr) \ |
| 443 | LOG_ALWAYS_FATAL_IF(ptr == nullptr, "%s: " #ptr " is nullptr", __FUNCTION__); |
| 444 | |
| 445 | #define VALIDATE_INT(value, cmp) \ |
| 446 | if (!(value cmp)) { \ |
| 447 | ALOGE("%s: Invalid value. Check failed: (" #value " " #cmp ") with value: %" PRIi64, \ |
| 448 | __FUNCTION__, value); \ |
| 449 | return EINVAL; \ |
| 450 | } |
| 451 | |
| 452 | #define WARN_INT(value, cmp) \ |
| 453 | if (!(value cmp)) { \ |
| 454 | ALOGE("%s: Invalid value. Check failed: (" #value " " #cmp ") with value: %" PRIi64, \ |
| 455 | __FUNCTION__, value); \ |
| 456 | } |
| 457 | |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 458 | APerformanceHintSession* APerformanceHint_createSession(APerformanceHintManager* manager, |
| 459 | const int32_t* threadIds, size_t size, |
| 460 | int64_t initialTargetWorkDurationNanos) { |
Matt Buckley | 83f7709 | 2024-01-18 19:57:29 +0000 | [diff] [blame] | 461 | VALIDATE_PTR(manager) |
| 462 | VALIDATE_PTR(threadIds) |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 463 | return manager->createSession(threadIds, size, initialTargetWorkDurationNanos); |
| 464 | } |
| 465 | |
Matt Buckley | 27da134 | 2024-04-05 23:10:48 +0000 | [diff] [blame] | 466 | APerformanceHintSession* APerformanceHint_createSessionInternal( |
| 467 | APerformanceHintManager* manager, const int32_t* threadIds, size_t size, |
| 468 | int64_t initialTargetWorkDurationNanos, SessionTag tag) { |
| 469 | VALIDATE_PTR(manager) |
| 470 | VALIDATE_PTR(threadIds) |
| 471 | return manager->createSession(threadIds, size, initialTargetWorkDurationNanos, |
| 472 | static_cast<hal::SessionTag>(tag)); |
| 473 | } |
| 474 | |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 475 | int64_t APerformanceHint_getPreferredUpdateRateNanos(APerformanceHintManager* manager) { |
Matt Buckley | 83f7709 | 2024-01-18 19:57:29 +0000 | [diff] [blame] | 476 | VALIDATE_PTR(manager) |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 477 | return manager->getPreferredRateNanos(); |
| 478 | } |
| 479 | |
| 480 | int APerformanceHint_updateTargetWorkDuration(APerformanceHintSession* session, |
| 481 | int64_t targetDurationNanos) { |
Matt Buckley | 83f7709 | 2024-01-18 19:57:29 +0000 | [diff] [blame] | 482 | VALIDATE_PTR(session) |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 483 | return session->updateTargetWorkDuration(targetDurationNanos); |
| 484 | } |
| 485 | |
| 486 | int APerformanceHint_reportActualWorkDuration(APerformanceHintSession* session, |
| 487 | int64_t actualDurationNanos) { |
Matt Buckley | 83f7709 | 2024-01-18 19:57:29 +0000 | [diff] [blame] | 488 | VALIDATE_PTR(session) |
| 489 | VALIDATE_INT(actualDurationNanos, > 0) |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 490 | return session->reportActualWorkDuration(actualDurationNanos); |
| 491 | } |
| 492 | |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 493 | void APerformanceHint_closeSession(APerformanceHintSession* session) { |
Matt Buckley | 83f7709 | 2024-01-18 19:57:29 +0000 | [diff] [blame] | 494 | VALIDATE_PTR(session) |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 495 | delete session; |
| 496 | } |
| 497 | |
Matt Buckley | 27da134 | 2024-04-05 23:10:48 +0000 | [diff] [blame] | 498 | int APerformanceHint_sendHint(APerformanceHintSession* session, SessionHint hint) { |
Matt Buckley | 83f7709 | 2024-01-18 19:57:29 +0000 | [diff] [blame] | 499 | VALIDATE_PTR(session) |
Matt Buckley | 27da134 | 2024-04-05 23:10:48 +0000 | [diff] [blame] | 500 | return session->sendHint(hint); |
Matt Buckley | 61726a3 | 2022-12-06 23:44:45 +0000 | [diff] [blame] | 501 | } |
| 502 | |
Peiyong Lin | 7ed6de3 | 2023-01-26 00:52:54 +0000 | [diff] [blame] | 503 | int APerformanceHint_setThreads(APerformanceHintSession* session, const pid_t* threadIds, |
Peiyong Lin | 095de76 | 2022-11-11 18:28:12 +0000 | [diff] [blame] | 504 | size_t size) { |
Matt Buckley | 83f7709 | 2024-01-18 19:57:29 +0000 | [diff] [blame] | 505 | VALIDATE_PTR(session) |
| 506 | VALIDATE_PTR(threadIds) |
Peiyong Lin | 095de76 | 2022-11-11 18:28:12 +0000 | [diff] [blame] | 507 | return session->setThreads(threadIds, size); |
| 508 | } |
| 509 | |
Matt Buckley | 27da134 | 2024-04-05 23:10:48 +0000 | [diff] [blame] | 510 | int APerformanceHint_getThreadIds(APerformanceHintSession* session, int32_t* const threadIds, |
Peiyong Lin | 095de76 | 2022-11-11 18:28:12 +0000 | [diff] [blame] | 511 | size_t* const size) { |
Matt Buckley | 27da134 | 2024-04-05 23:10:48 +0000 | [diff] [blame] | 512 | VALIDATE_PTR(session) |
| 513 | return session->getThreadIds(threadIds, size); |
Peiyong Lin | 095de76 | 2022-11-11 18:28:12 +0000 | [diff] [blame] | 514 | } |
| 515 | |
Matt Buckley | 423c1b3 | 2023-06-28 19:13:42 +0000 | [diff] [blame] | 516 | int APerformanceHint_setPreferPowerEfficiency(APerformanceHintSession* session, bool enabled) { |
Matt Buckley | 83f7709 | 2024-01-18 19:57:29 +0000 | [diff] [blame] | 517 | VALIDATE_PTR(session) |
Matt Buckley | 423c1b3 | 2023-06-28 19:13:42 +0000 | [diff] [blame] | 518 | return session->setPreferPowerEfficiency(enabled); |
| 519 | } |
| 520 | |
Peiyong Lin | 70de085 | 2023-10-25 21:12:35 +0000 | [diff] [blame] | 521 | int APerformanceHint_reportActualWorkDuration2(APerformanceHintSession* session, |
Matt Buckley | 83f7709 | 2024-01-18 19:57:29 +0000 | [diff] [blame] | 522 | AWorkDuration* workDurationPtr) { |
| 523 | VALIDATE_PTR(session) |
| 524 | VALIDATE_PTR(workDurationPtr) |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 525 | VALIDATE_INT(workDurationPtr->durationNanos, > 0) |
| 526 | VALIDATE_INT(workDurationPtr->workPeriodStartTimestampNanos, > 0) |
| 527 | VALIDATE_INT(workDurationPtr->cpuDurationNanos, >= 0) |
| 528 | VALIDATE_INT(workDurationPtr->gpuDurationNanos, >= 0) |
| 529 | VALIDATE_INT(workDurationPtr->gpuDurationNanos + workDurationPtr->cpuDurationNanos, > 0) |
Matt Buckley | 83f7709 | 2024-01-18 19:57:29 +0000 | [diff] [blame] | 530 | return session->reportActualWorkDuration(workDurationPtr); |
Peiyong Lin | 70de085 | 2023-10-25 21:12:35 +0000 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | AWorkDuration* AWorkDuration_create() { |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 534 | return new AWorkDuration(); |
Peiyong Lin | 70de085 | 2023-10-25 21:12:35 +0000 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | void AWorkDuration_release(AWorkDuration* aWorkDuration) { |
Matt Buckley | 83f7709 | 2024-01-18 19:57:29 +0000 | [diff] [blame] | 538 | VALIDATE_PTR(aWorkDuration) |
Peiyong Lin | 70de085 | 2023-10-25 21:12:35 +0000 | [diff] [blame] | 539 | delete aWorkDuration; |
| 540 | } |
| 541 | |
Peiyong Lin | 70de085 | 2023-10-25 21:12:35 +0000 | [diff] [blame] | 542 | void AWorkDuration_setActualTotalDurationNanos(AWorkDuration* aWorkDuration, |
| 543 | int64_t actualTotalDurationNanos) { |
Matt Buckley | 83f7709 | 2024-01-18 19:57:29 +0000 | [diff] [blame] | 544 | VALIDATE_PTR(aWorkDuration) |
| 545 | WARN_INT(actualTotalDurationNanos, > 0) |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 546 | aWorkDuration->durationNanos = actualTotalDurationNanos; |
| 547 | } |
| 548 | |
| 549 | void AWorkDuration_setWorkPeriodStartTimestampNanos(AWorkDuration* aWorkDuration, |
| 550 | int64_t workPeriodStartTimestampNanos) { |
| 551 | VALIDATE_PTR(aWorkDuration) |
| 552 | WARN_INT(workPeriodStartTimestampNanos, > 0) |
| 553 | aWorkDuration->workPeriodStartTimestampNanos = workPeriodStartTimestampNanos; |
Peiyong Lin | 70de085 | 2023-10-25 21:12:35 +0000 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | void AWorkDuration_setActualCpuDurationNanos(AWorkDuration* aWorkDuration, |
| 557 | int64_t actualCpuDurationNanos) { |
Matt Buckley | 83f7709 | 2024-01-18 19:57:29 +0000 | [diff] [blame] | 558 | VALIDATE_PTR(aWorkDuration) |
Matt Buckley | a115b12 | 2024-01-31 20:57:49 +0000 | [diff] [blame] | 559 | WARN_INT(actualCpuDurationNanos, >= 0) |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 560 | aWorkDuration->cpuDurationNanos = actualCpuDurationNanos; |
Peiyong Lin | 70de085 | 2023-10-25 21:12:35 +0000 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | void AWorkDuration_setActualGpuDurationNanos(AWorkDuration* aWorkDuration, |
| 564 | int64_t actualGpuDurationNanos) { |
Matt Buckley | 83f7709 | 2024-01-18 19:57:29 +0000 | [diff] [blame] | 565 | VALIDATE_PTR(aWorkDuration) |
| 566 | WARN_INT(actualGpuDurationNanos, >= 0) |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 567 | aWorkDuration->gpuDurationNanos = actualGpuDurationNanos; |
Peiyong Lin | 70de085 | 2023-10-25 21:12:35 +0000 | [diff] [blame] | 568 | } |
| 569 | |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 570 | void APerformanceHint_setIHintManagerForTesting(void* iManager) { |
| 571 | delete gHintManagerForTesting; |
| 572 | gHintManagerForTesting = nullptr; |
Matt Buckley | 5897772 | 2024-03-11 23:32:09 +0000 | [diff] [blame] | 573 | gIHintManagerForTesting = static_cast<std::shared_ptr<IHintManager>*>(iManager); |
Bo Liu | 4426772 | 2021-07-16 17:03:20 -0400 | [diff] [blame] | 574 | } |