Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 | #pragma once |
| 18 | |
Dan Stoza | 030fbc1 | 2020-02-19 15:32:01 -0800 | [diff] [blame] | 19 | #include <atomic> |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 20 | #include <chrono> |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 21 | #include <unordered_map> |
Peiyong Lin | 74ca2f4 | 2019-01-14 19:36:57 -0800 | [diff] [blame] | 22 | #include <unordered_set> |
| 23 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 24 | #include <ui/DisplayId.h> |
| 25 | #include <ui/FenceTime.h> |
Dan Stoza | 2095000 | 2020-06-18 14:56:58 -0700 | [diff] [blame] | 26 | #include <utils/Mutex.h> |
| 27 | |
Xiang Wang | e12b4fa | 2022-03-25 23:48:40 +0000 | [diff] [blame] | 28 | #include <android/hardware/power/IPower.h> |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 29 | #include <compositionengine/impl/OutputCompositionState.h> |
Alec Mouri | ff79387 | 2022-01-13 17:45:06 -0800 | [diff] [blame] | 30 | #include <ui/DisplayIdentification.h> |
Dan Stoza | 030fbc1 | 2020-02-19 15:32:01 -0800 | [diff] [blame] | 31 | #include "../Scheduler/OneShotTimer.h" |
Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 32 | |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 33 | using namespace std::chrono_literals; |
| 34 | |
Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 35 | namespace android { |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 36 | |
| 37 | class SurfaceFlinger; |
| 38 | |
Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 39 | namespace Hwc2 { |
| 40 | |
| 41 | class PowerAdvisor { |
| 42 | public: |
| 43 | virtual ~PowerAdvisor(); |
| 44 | |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 45 | // Initializes resources that cannot be initialized on construction |
| 46 | virtual void init() = 0; |
Dan Stoza | 29e7bdf | 2020-03-23 14:43:09 -0700 | [diff] [blame] | 47 | virtual void onBootFinished() = 0; |
Peiyong Lin | 74ca2f4 | 2019-01-14 19:36:57 -0800 | [diff] [blame] | 48 | virtual void setExpensiveRenderingExpected(DisplayId displayId, bool expected) = 0; |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 49 | virtual bool isUsingExpensiveRendering() = 0; |
Dan Stoza | 030fbc1 | 2020-02-19 15:32:01 -0800 | [diff] [blame] | 50 | virtual void notifyDisplayUpdateImminent() = 0; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 51 | // Checks both if it supports and if it's enabled |
Matt Buckley | 06f299a | 2021-09-24 19:43:51 +0000 | [diff] [blame] | 52 | virtual bool usePowerHintSession() = 0; |
| 53 | virtual bool supportsPowerHintSession() = 0; |
| 54 | virtual bool isPowerHintSessionRunning() = 0; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 55 | // Sends a power hint that updates to the target work duration for the frame |
| 56 | virtual void setTargetWorkDuration(nsecs_t targetDuration) = 0; |
| 57 | // Sends a power hint for the actual known work duration at the end of the frame |
| 58 | virtual void sendActualWorkDuration() = 0; |
| 59 | // Sends a power hint for the upcoming frame predicted from previous frame timing |
| 60 | virtual void sendPredictedWorkDuration() = 0; |
| 61 | // Sets whether the power hint session is enabled |
Matt Buckley | 06f299a | 2021-09-24 19:43:51 +0000 | [diff] [blame] | 62 | virtual void enablePowerHint(bool enabled) = 0; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 63 | // Initializes the power hint session |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 64 | virtual bool startPowerHintSession(const std::vector<int32_t>& threadIds) = 0; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 65 | // Provides PowerAdvisor with a copy of the gpu fence so it can determine the gpu end time |
| 66 | virtual void setGpuFenceTime(DisplayId displayId, std::unique_ptr<FenceTime>&& fenceTime) = 0; |
Matt Buckley | 16dec1f | 2022-06-07 21:46:20 +0000 | [diff] [blame] | 67 | // Reports the start and end times of a hwc validate call this frame for a given display |
| 68 | virtual void setHwcValidateTiming(DisplayId displayId, nsecs_t validateStartTime, |
| 69 | nsecs_t validateEndTime) = 0; |
| 70 | // Reports the start and end times of a hwc present call this frame for a given display |
| 71 | virtual void setHwcPresentTiming(DisplayId displayId, nsecs_t presentStartTime, |
| 72 | nsecs_t presentEndTime) = 0; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 73 | virtual void setExpectedPresentTime(nsecs_t expectedPresentTime) = 0; |
| 74 | // Reports whether a display used client composition this frame |
| 75 | virtual void setRequiresClientComposition(DisplayId displayId, |
| 76 | bool requiresClientComposition) = 0; |
| 77 | // Reports whether a given display skipped validation this frame |
| 78 | virtual void setSkippedValidate(DisplayId displayId, bool skipped) = 0; |
Matt Buckley | 16dec1f | 2022-06-07 21:46:20 +0000 | [diff] [blame] | 79 | // Reports when a hwc present is delayed, and the time that it will resume |
| 80 | virtual void setHwcPresentDelayedTime( |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 81 | DisplayId displayId, std::chrono::steady_clock::time_point earliestFrameStartTime) = 0; |
| 82 | // Reports the start delay for SurfaceFlinger this frame |
| 83 | virtual void setFrameDelay(nsecs_t frameDelayDuration) = 0; |
| 84 | // Reports the SurfaceFlinger commit start time this frame |
| 85 | virtual void setCommitStart(nsecs_t commitStartTime) = 0; |
| 86 | // Reports the SurfaceFlinger composite end time this frame |
| 87 | virtual void setCompositeEnd(nsecs_t compositeEndTime) = 0; |
| 88 | // Reports the list of the currently active displays |
| 89 | virtual void setDisplays(std::vector<DisplayId>& displayIds) = 0; |
| 90 | // Sets the target duration for the entire pipeline including the gpu |
| 91 | virtual void setTotalFrameTargetWorkDuration(nsecs_t targetDuration) = 0; |
Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | namespace impl { |
| 95 | |
Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 96 | // PowerAdvisor is a wrapper around IPower HAL which takes into account the |
| 97 | // full state of the system when sending out power hints to things like the GPU. |
| 98 | class PowerAdvisor final : public Hwc2::PowerAdvisor { |
| 99 | public: |
Dan Stoza | 030fbc1 | 2020-02-19 15:32:01 -0800 | [diff] [blame] | 100 | class HalWrapper { |
| 101 | public: |
| 102 | virtual ~HalWrapper() = default; |
| 103 | |
| 104 | virtual bool setExpensiveRendering(bool enabled) = 0; |
| 105 | virtual bool notifyDisplayUpdateImminent() = 0; |
Matt Buckley | 06f299a | 2021-09-24 19:43:51 +0000 | [diff] [blame] | 106 | virtual bool supportsPowerHintSession() = 0; |
| 107 | virtual bool isPowerHintSessionRunning() = 0; |
| 108 | virtual void restartPowerHintSession() = 0; |
| 109 | virtual void setPowerHintSessionThreadIds(const std::vector<int32_t>& threadIds) = 0; |
| 110 | virtual bool startPowerHintSession() = 0; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 111 | virtual void setTargetWorkDuration(nsecs_t targetDuration) = 0; |
| 112 | virtual void sendActualWorkDuration(nsecs_t actualDuration, nsecs_t timestamp) = 0; |
Matt Buckley | 06f299a | 2021-09-24 19:43:51 +0000 | [diff] [blame] | 113 | virtual bool shouldReconnectHAL() = 0; |
| 114 | virtual std::vector<int32_t> getPowerHintSessionThreadIds() = 0; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 115 | virtual std::optional<nsecs_t> getTargetWorkDuration() = 0; |
Dan Stoza | 030fbc1 | 2020-02-19 15:32:01 -0800 | [diff] [blame] | 116 | }; |
| 117 | |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 118 | PowerAdvisor(SurfaceFlinger& flinger); |
Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 119 | ~PowerAdvisor() override; |
| 120 | |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 121 | void init() override; |
Dan Stoza | 29e7bdf | 2020-03-23 14:43:09 -0700 | [diff] [blame] | 122 | void onBootFinished() override; |
Peiyong Lin | 74ca2f4 | 2019-01-14 19:36:57 -0800 | [diff] [blame] | 123 | void setExpensiveRenderingExpected(DisplayId displayId, bool expected) override; |
Matt Buckley | 06f299a | 2021-09-24 19:43:51 +0000 | [diff] [blame] | 124 | bool isUsingExpensiveRendering() override { return mNotifiedExpensiveRendering; }; |
Dan Stoza | 030fbc1 | 2020-02-19 15:32:01 -0800 | [diff] [blame] | 125 | void notifyDisplayUpdateImminent() override; |
Matt Buckley | 06f299a | 2021-09-24 19:43:51 +0000 | [diff] [blame] | 126 | bool usePowerHintSession() override; |
| 127 | bool supportsPowerHintSession() override; |
| 128 | bool isPowerHintSessionRunning() override; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 129 | void setTargetWorkDuration(nsecs_t targetDuration) override; |
| 130 | void sendActualWorkDuration() override; |
| 131 | void sendPredictedWorkDuration() override; |
Matt Buckley | 06f299a | 2021-09-24 19:43:51 +0000 | [diff] [blame] | 132 | void enablePowerHint(bool enabled) override; |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 133 | bool startPowerHintSession(const std::vector<int32_t>& threadIds) override; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 134 | void setGpuFenceTime(DisplayId displayId, std::unique_ptr<FenceTime>&& fenceTime); |
Matt Buckley | 16dec1f | 2022-06-07 21:46:20 +0000 | [diff] [blame] | 135 | void setHwcValidateTiming(DisplayId displayId, nsecs_t valiateStartTime, |
| 136 | nsecs_t validateEndTime) override; |
| 137 | void setHwcPresentTiming(DisplayId displayId, nsecs_t presentStartTime, |
| 138 | nsecs_t presentEndTime) override; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 139 | void setSkippedValidate(DisplayId displayId, bool skipped) override; |
| 140 | void setRequiresClientComposition(DisplayId displayId, bool requiresClientComposition) override; |
| 141 | void setExpectedPresentTime(nsecs_t expectedPresentTime) override; |
Matt Buckley | 16dec1f | 2022-06-07 21:46:20 +0000 | [diff] [blame] | 142 | void setHwcPresentDelayedTime( |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 143 | DisplayId displayId, |
| 144 | std::chrono::steady_clock::time_point earliestFrameStartTime) override; |
| 145 | |
| 146 | void setFrameDelay(nsecs_t frameDelayDuration) override; |
| 147 | void setCommitStart(nsecs_t commitStartTime) override; |
| 148 | void setCompositeEnd(nsecs_t compositeEndTime) override; |
| 149 | void setDisplays(std::vector<DisplayId>& displayIds) override; |
| 150 | void setTotalFrameTargetWorkDuration(nsecs_t targetDuration) override; |
Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 151 | |
| 152 | private: |
Dan Stoza | 2095000 | 2020-06-18 14:56:58 -0700 | [diff] [blame] | 153 | HalWrapper* getPowerHal() REQUIRES(mPowerHalMutex); |
| 154 | bool mReconnectPowerHal GUARDED_BY(mPowerHalMutex) = false; |
| 155 | std::mutex mPowerHalMutex; |
Dan Stoza | 030fbc1 | 2020-02-19 15:32:01 -0800 | [diff] [blame] | 156 | |
Dan Stoza | 29e7bdf | 2020-03-23 14:43:09 -0700 | [diff] [blame] | 157 | std::atomic_bool mBootFinished = false; |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 158 | |
Peiyong Lin | 74ca2f4 | 2019-01-14 19:36:57 -0800 | [diff] [blame] | 159 | std::unordered_set<DisplayId> mExpensiveDisplays; |
Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 160 | bool mNotifiedExpensiveRendering = false; |
Dan Stoza | 030fbc1 | 2020-02-19 15:32:01 -0800 | [diff] [blame] | 161 | |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 162 | SurfaceFlinger& mFlinger; |
Dan Stoza | 030fbc1 | 2020-02-19 15:32:01 -0800 | [diff] [blame] | 163 | std::atomic_bool mSendUpdateImminent = true; |
Alec Mouri | c059dcf | 2022-05-05 23:40:07 +0000 | [diff] [blame] | 164 | std::atomic<nsecs_t> mLastScreenUpdatedTime = 0; |
| 165 | std::optional<scheduler::OneShotTimer> mScreenUpdateTimer; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 166 | |
| 167 | // Higher-level timing data used for estimation |
| 168 | struct DisplayTimeline { |
Matt Buckley | 16dec1f | 2022-06-07 21:46:20 +0000 | [diff] [blame] | 169 | // The start of hwc present, or the start of validate if it happened there instead |
| 170 | nsecs_t hwcPresentStartTime = -1; |
| 171 | // The end of hwc present or validate, whichever one actually presented |
| 172 | nsecs_t hwcPresentEndTime = -1; |
| 173 | // How long the actual hwc present was delayed after hwcPresentStartTime |
| 174 | nsecs_t hwcPresentDelayDuration = 0; |
| 175 | // When we think we started waiting for the release fence after calling into hwc present and |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 176 | // after potentially waiting for the earliest present time |
Matt Buckley | 16dec1f | 2022-06-07 21:46:20 +0000 | [diff] [blame] | 177 | nsecs_t releaseFenceWaitStartTime = -1; |
| 178 | // How long we ran after we finished waiting for the fence but before hwc present finished |
| 179 | nsecs_t postReleaseFenceHwcPresentDuration = 0; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 180 | // Are we likely to have waited for the present fence during composition |
Matt Buckley | 16dec1f | 2022-06-07 21:46:20 +0000 | [diff] [blame] | 181 | bool probablyWaitsForReleaseFence = false; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 182 | // Estimate one frame's timeline from that of a previous frame |
| 183 | DisplayTimeline estimateTimelineFromReference(nsecs_t fenceTime, nsecs_t displayStartTime); |
| 184 | }; |
| 185 | |
| 186 | struct GpuTimeline { |
| 187 | nsecs_t duration = 0; |
| 188 | nsecs_t startTime = -1; |
| 189 | }; |
| 190 | |
| 191 | // Power hint session data recorded from the pipeline |
| 192 | struct DisplayTimingData { |
| 193 | std::unique_ptr<FenceTime> gpuEndFenceTime; |
| 194 | std::optional<nsecs_t> gpuStartTime; |
| 195 | std::optional<nsecs_t> lastValidGpuEndTime; |
| 196 | std::optional<nsecs_t> lastValidGpuStartTime; |
Matt Buckley | 16dec1f | 2022-06-07 21:46:20 +0000 | [diff] [blame] | 197 | std::optional<nsecs_t> hwcPresentStartTime; |
| 198 | std::optional<nsecs_t> hwcPresentEndTime; |
| 199 | std::optional<nsecs_t> hwcValidateStartTime; |
| 200 | std::optional<nsecs_t> hwcValidateEndTime; |
| 201 | std::optional<nsecs_t> hwcPresentDelayedTime; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 202 | bool usedClientComposition = false; |
| 203 | bool skippedValidate = false; |
| 204 | // Calculate high-level timing milestones from more granular display timing data |
| 205 | DisplayTimeline calculateDisplayTimeline(nsecs_t fenceTime); |
| 206 | // Estimate the gpu duration for a given display from previous gpu timing data |
| 207 | std::optional<GpuTimeline> estimateGpuTiming(std::optional<nsecs_t> previousEnd); |
| 208 | }; |
| 209 | |
| 210 | template <class T, size_t N> |
| 211 | class RingBuffer { |
| 212 | std::array<T, N> elements = {}; |
| 213 | size_t mIndex = 0; |
| 214 | size_t numElements = 0; |
| 215 | |
| 216 | public: |
| 217 | void append(T item) { |
| 218 | mIndex = (mIndex + 1) % N; |
| 219 | numElements = std::min(N, numElements + 1); |
| 220 | elements[mIndex] = item; |
| 221 | } |
| 222 | bool isFull() const { return numElements == N; } |
| 223 | // Allows access like [0] == current, [-1] = previous, etc.. |
| 224 | T& operator[](int offset) { |
| 225 | size_t positiveOffset = |
| 226 | static_cast<size_t>((offset % static_cast<int>(N)) + static_cast<int>(N)); |
| 227 | return elements[(mIndex + positiveOffset) % N]; |
| 228 | } |
| 229 | }; |
| 230 | |
| 231 | // Filter and sort the display ids by a given property |
| 232 | std::vector<DisplayId> getOrderedDisplayIds(std::optional<nsecs_t> DisplayTimingData::*sortBy); |
| 233 | // Estimates a frame's total work duration including gpu time. |
| 234 | // Runs either at the beginning or end of a frame, using the most recent data available |
| 235 | std::optional<nsecs_t> estimateWorkDuration(bool earlyHint); |
| 236 | // There are two different targets and actual work durations we care about, |
| 237 | // this normalizes them together and takes the max of the two |
| 238 | nsecs_t combineTimingEstimates(nsecs_t totalDuration, nsecs_t flingerDuration); |
| 239 | |
| 240 | std::unordered_map<DisplayId, DisplayTimingData> mDisplayTimingData; |
| 241 | |
| 242 | // Current frame's delay |
| 243 | nsecs_t mFrameDelayDuration = 0; |
| 244 | // Last frame's composite end time |
| 245 | nsecs_t mLastCompositeEndTime = -1; |
| 246 | // Last frame's post-composition duration |
| 247 | nsecs_t mLastPostcompDuration = 0; |
| 248 | // Buffer of recent commit start times |
| 249 | RingBuffer<nsecs_t, 2> mCommitStartTimes; |
| 250 | // Buffer of recent expected present times |
| 251 | RingBuffer<nsecs_t, 3> mExpectedPresentTimes; |
| 252 | // Target for the entire pipeline including gpu |
| 253 | std::optional<nsecs_t> mTotalFrameTargetDuration; |
| 254 | // Updated list of display IDs |
| 255 | std::vector<DisplayId> mDisplayIds; |
| 256 | |
| 257 | std::optional<bool> mPowerHintEnabled; |
| 258 | std::optional<bool> mSupportsPowerHint; |
| 259 | bool mPowerHintSessionRunning = false; |
| 260 | |
| 261 | // An adjustable safety margin which moves the "target" earlier to allow flinger to |
| 262 | // go a bit over without dropping a frame, especially since we can't measure |
Matt Buckley | 16dec1f | 2022-06-07 21:46:20 +0000 | [diff] [blame] | 263 | // the exact time hwc finishes composition so "actual" durations are measured |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 264 | // from the end of present() instead, which is a bit later. |
| 265 | static constexpr const std::chrono::nanoseconds kTargetSafetyMargin = 1ms; |
| 266 | |
| 267 | // How long we expect hwc to run after the present call until it waits for the fence |
Matt Buckley | 16dec1f | 2022-06-07 21:46:20 +0000 | [diff] [blame] | 268 | static constexpr const std::chrono::nanoseconds kFenceWaitStartDelayValidated = 150us; |
| 269 | static constexpr const std::chrono::nanoseconds kFenceWaitStartDelaySkippedValidate = 250us; |
Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 270 | }; |
| 271 | |
Xiang Wang | e12b4fa | 2022-03-25 23:48:40 +0000 | [diff] [blame] | 272 | class AidlPowerHalWrapper : public PowerAdvisor::HalWrapper { |
| 273 | public: |
| 274 | explicit AidlPowerHalWrapper(sp<hardware::power::IPower> powerHal); |
| 275 | ~AidlPowerHalWrapper() override; |
| 276 | |
| 277 | static std::unique_ptr<HalWrapper> connect(); |
| 278 | |
| 279 | bool setExpensiveRendering(bool enabled) override; |
| 280 | bool notifyDisplayUpdateImminent() override; |
| 281 | bool supportsPowerHintSession() override; |
| 282 | bool isPowerHintSessionRunning() override; |
| 283 | void restartPowerHintSession() override; |
| 284 | void setPowerHintSessionThreadIds(const std::vector<int32_t>& threadIds) override; |
| 285 | bool startPowerHintSession() override; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 286 | void setTargetWorkDuration(nsecs_t targetDuration) override; |
| 287 | void sendActualWorkDuration(nsecs_t actualDuration, nsecs_t timestamp) override; |
Xiang Wang | e12b4fa | 2022-03-25 23:48:40 +0000 | [diff] [blame] | 288 | bool shouldReconnectHAL() override; |
| 289 | std::vector<int32_t> getPowerHintSessionThreadIds() override; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 290 | std::optional<nsecs_t> getTargetWorkDuration() override; |
Xiang Wang | e12b4fa | 2022-03-25 23:48:40 +0000 | [diff] [blame] | 291 | |
| 292 | private: |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 293 | friend class AidlPowerHalWrapperTest; |
| 294 | |
Xiang Wang | e12b4fa | 2022-03-25 23:48:40 +0000 | [diff] [blame] | 295 | bool checkPowerHintSessionSupported(); |
| 296 | void closePowerHintSession(); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 297 | bool shouldReportActualDurations(); |
| 298 | |
| 299 | // Used for testing |
| 300 | void setAllowedActualDeviation(nsecs_t); |
Xiang Wang | e12b4fa | 2022-03-25 23:48:40 +0000 | [diff] [blame] | 301 | |
| 302 | const sp<hardware::power::IPower> mPowerHal = nullptr; |
| 303 | bool mHasExpensiveRendering = false; |
| 304 | bool mHasDisplayUpdateImminent = false; |
| 305 | // Used to indicate an error state and need for reconstruction |
| 306 | bool mShouldReconnectHal = false; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 307 | |
| 308 | // Power hint session data |
| 309 | |
| 310 | // Concurrent access for this is protected by mPowerHalMutex |
Xiang Wang | e12b4fa | 2022-03-25 23:48:40 +0000 | [diff] [blame] | 311 | sp<hardware::power::IPowerHintSession> mPowerHintSession = nullptr; |
| 312 | // Queue of actual durations saved to report |
| 313 | std::vector<hardware::power::WorkDuration> mPowerHintQueue; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 314 | // The latest values we have received for target and actual |
| 315 | nsecs_t mTargetDuration = kDefaultTarget.count(); |
| 316 | std::optional<nsecs_t> mActualDuration; |
Xiang Wang | e12b4fa | 2022-03-25 23:48:40 +0000 | [diff] [blame] | 317 | // The list of thread ids, stored so we can restart the session from this class if needed |
| 318 | std::vector<int32_t> mPowerHintThreadIds; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 319 | bool mSupportsPowerHint = false; |
Xiang Wang | e12b4fa | 2022-03-25 23:48:40 +0000 | [diff] [blame] | 320 | // Keep track of the last messages sent for rate limiter change detection |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 321 | std::optional<nsecs_t> mLastActualDurationSent; |
| 322 | // Timestamp of the last report we sent, used to avoid stale sessions |
| 323 | nsecs_t mLastActualReportTimestamp = 0; |
| 324 | nsecs_t mLastTargetDurationSent = kDefaultTarget.count(); |
| 325 | // Max amount the error term can vary without causing an actual value report |
| 326 | nsecs_t mAllowedActualDeviation = -1; |
Xiang Wang | e12b4fa | 2022-03-25 23:48:40 +0000 | [diff] [blame] | 327 | // Whether we should emit ATRACE_INT data for hint sessions |
| 328 | static const bool sTraceHintSessionData; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 329 | static constexpr const std::chrono::nanoseconds kDefaultTarget = 16ms; |
Xiang Wang | e12b4fa | 2022-03-25 23:48:40 +0000 | [diff] [blame] | 330 | // Amount of time after the last message was sent before the session goes stale |
| 331 | // actually 100ms but we use 80 here to ideally avoid going stale |
| 332 | static constexpr const std::chrono::nanoseconds kStaleTimeout = 80ms; |
| 333 | }; |
| 334 | |
Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 335 | } // namespace impl |
| 336 | } // namespace Hwc2 |
| 337 | } // namespace android |