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> |
Matt Buckley | 0538cae | 2022-11-08 23:12:04 +0000 | [diff] [blame^] | 30 | #include <powermanager/PowerHalController.h> |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 31 | #include <scheduler/Time.h> |
Alec Mouri | ff79387 | 2022-01-13 17:45:06 -0800 | [diff] [blame] | 32 | #include <ui/DisplayIdentification.h> |
Dan Stoza | 030fbc1 | 2020-02-19 15:32:01 -0800 | [diff] [blame] | 33 | #include "../Scheduler/OneShotTimer.h" |
Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 34 | |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 35 | using namespace std::chrono_literals; |
| 36 | |
Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 37 | namespace android { |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 38 | |
| 39 | class SurfaceFlinger; |
| 40 | |
Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 41 | namespace Hwc2 { |
| 42 | |
| 43 | class PowerAdvisor { |
| 44 | public: |
| 45 | virtual ~PowerAdvisor(); |
| 46 | |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 47 | // Initializes resources that cannot be initialized on construction |
| 48 | virtual void init() = 0; |
Dan Stoza | 29e7bdf | 2020-03-23 14:43:09 -0700 | [diff] [blame] | 49 | virtual void onBootFinished() = 0; |
Peiyong Lin | 74ca2f4 | 2019-01-14 19:36:57 -0800 | [diff] [blame] | 50 | virtual void setExpensiveRenderingExpected(DisplayId displayId, bool expected) = 0; |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 51 | virtual bool isUsingExpensiveRendering() = 0; |
Matt Buckley | 15ecd1c | 2022-11-01 21:57:16 +0000 | [diff] [blame] | 52 | virtual void notifyDisplayUpdateImminentAndCpuReset() = 0; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 53 | // Checks both if it supports and if it's enabled |
Matt Buckley | 06f299a | 2021-09-24 19:43:51 +0000 | [diff] [blame] | 54 | virtual bool usePowerHintSession() = 0; |
| 55 | virtual bool supportsPowerHintSession() = 0; |
Matt Buckley | 0538cae | 2022-11-08 23:12:04 +0000 | [diff] [blame^] | 56 | |
| 57 | virtual bool ensurePowerHintSessionRunning() = 0; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 58 | // Sends a power hint that updates to the target work duration for the frame |
Matt Buckley | 0538cae | 2022-11-08 23:12:04 +0000 | [diff] [blame^] | 59 | virtual void updateTargetWorkDuration(Duration targetDuration) = 0; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 60 | // Sends a power hint for the actual known work duration at the end of the frame |
Matt Buckley | 0538cae | 2022-11-08 23:12:04 +0000 | [diff] [blame^] | 61 | virtual void reportActualWorkDuration() = 0; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 62 | // Sets whether the power hint session is enabled |
Matt Buckley | 0538cae | 2022-11-08 23:12:04 +0000 | [diff] [blame^] | 63 | virtual void enablePowerHintSession(bool enabled) = 0; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 64 | // Initializes the power hint session |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 65 | virtual bool startPowerHintSession(const std::vector<int32_t>& threadIds) = 0; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 66 | // Provides PowerAdvisor with a copy of the gpu fence so it can determine the gpu end time |
| 67 | virtual void setGpuFenceTime(DisplayId displayId, std::unique_ptr<FenceTime>&& fenceTime) = 0; |
Matt Buckley | 16dec1f | 2022-06-07 21:46:20 +0000 | [diff] [blame] | 68 | // Reports the start and end times of a hwc validate call this frame for a given display |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 69 | virtual void setHwcValidateTiming(DisplayId displayId, TimePoint validateStartTime, |
| 70 | TimePoint validateEndTime) = 0; |
Matt Buckley | 16dec1f | 2022-06-07 21:46:20 +0000 | [diff] [blame] | 71 | // Reports the start and end times of a hwc present call this frame for a given display |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 72 | virtual void setHwcPresentTiming(DisplayId displayId, TimePoint presentStartTime, |
| 73 | TimePoint presentEndTime) = 0; |
Matt Buckley | c6b9d38 | 2022-06-17 15:28:07 -0700 | [diff] [blame] | 74 | // Reports the expected time that the current frame will present to the display |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 75 | virtual void setExpectedPresentTime(TimePoint expectedPresentTime) = 0; |
Matt Buckley | 1809d90 | 2022-08-05 06:51:43 +0000 | [diff] [blame] | 76 | // Reports the most recent present fence time and end time once known |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 77 | virtual void setSfPresentTiming(TimePoint presentFenceTime, TimePoint presentEndTime) = 0; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 78 | // Reports whether a display used client composition this frame |
| 79 | virtual void setRequiresClientComposition(DisplayId displayId, |
| 80 | bool requiresClientComposition) = 0; |
| 81 | // Reports whether a given display skipped validation this frame |
| 82 | virtual void setSkippedValidate(DisplayId displayId, bool skipped) = 0; |
Matt Buckley | 16dec1f | 2022-06-07 21:46:20 +0000 | [diff] [blame] | 83 | // Reports when a hwc present is delayed, and the time that it will resume |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 84 | virtual void setHwcPresentDelayedTime(DisplayId displayId, |
| 85 | TimePoint earliestFrameStartTime) = 0; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 86 | // Reports the start delay for SurfaceFlinger this frame |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 87 | virtual void setFrameDelay(Duration frameDelayDuration) = 0; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 88 | // Reports the SurfaceFlinger commit start time this frame |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 89 | virtual void setCommitStart(TimePoint commitStartTime) = 0; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 90 | // Reports the SurfaceFlinger composite end time this frame |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 91 | virtual void setCompositeEnd(TimePoint compositeEndTime) = 0; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 92 | // Reports the list of the currently active displays |
| 93 | virtual void setDisplays(std::vector<DisplayId>& displayIds) = 0; |
| 94 | // Sets the target duration for the entire pipeline including the gpu |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 95 | virtual void setTotalFrameTargetWorkDuration(Duration targetDuration) = 0; |
Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | namespace impl { |
| 99 | |
Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 100 | // PowerAdvisor is a wrapper around IPower HAL which takes into account the |
| 101 | // full state of the system when sending out power hints to things like the GPU. |
| 102 | class PowerAdvisor final : public Hwc2::PowerAdvisor { |
| 103 | public: |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 104 | PowerAdvisor(SurfaceFlinger& flinger); |
Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 105 | ~PowerAdvisor() override; |
| 106 | |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 107 | void init() override; |
Dan Stoza | 29e7bdf | 2020-03-23 14:43:09 -0700 | [diff] [blame] | 108 | void onBootFinished() override; |
Peiyong Lin | 74ca2f4 | 2019-01-14 19:36:57 -0800 | [diff] [blame] | 109 | void setExpensiveRenderingExpected(DisplayId displayId, bool expected) override; |
Matt Buckley | 06f299a | 2021-09-24 19:43:51 +0000 | [diff] [blame] | 110 | bool isUsingExpensiveRendering() override { return mNotifiedExpensiveRendering; }; |
Matt Buckley | 15ecd1c | 2022-11-01 21:57:16 +0000 | [diff] [blame] | 111 | void notifyDisplayUpdateImminentAndCpuReset() override; |
Matt Buckley | 06f299a | 2021-09-24 19:43:51 +0000 | [diff] [blame] | 112 | bool usePowerHintSession() override; |
| 113 | bool supportsPowerHintSession() override; |
Matt Buckley | 0538cae | 2022-11-08 23:12:04 +0000 | [diff] [blame^] | 114 | bool ensurePowerHintSessionRunning() override; |
| 115 | void updateTargetWorkDuration(Duration targetDuration) override; |
| 116 | void reportActualWorkDuration() override; |
| 117 | void enablePowerHintSession(bool enabled) override; |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 118 | bool startPowerHintSession(const std::vector<int32_t>& threadIds) override; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 119 | void setGpuFenceTime(DisplayId displayId, std::unique_ptr<FenceTime>&& fenceTime); |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 120 | void setHwcValidateTiming(DisplayId displayId, TimePoint validateStartTime, |
| 121 | TimePoint validateEndTime) override; |
| 122 | void setHwcPresentTiming(DisplayId displayId, TimePoint presentStartTime, |
| 123 | TimePoint presentEndTime) override; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 124 | void setSkippedValidate(DisplayId displayId, bool skipped) override; |
| 125 | void setRequiresClientComposition(DisplayId displayId, bool requiresClientComposition) override; |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 126 | void setExpectedPresentTime(TimePoint expectedPresentTime) override; |
| 127 | void setSfPresentTiming(TimePoint presentFenceTime, TimePoint presentEndTime) override; |
| 128 | void setHwcPresentDelayedTime(DisplayId displayId, TimePoint earliestFrameStartTime) override; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 129 | |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 130 | void setFrameDelay(Duration frameDelayDuration) override; |
| 131 | void setCommitStart(TimePoint commitStartTime) override; |
| 132 | void setCompositeEnd(TimePoint compositeEndTime) override; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 133 | void setDisplays(std::vector<DisplayId>& displayIds) override; |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 134 | void setTotalFrameTargetWorkDuration(Duration targetDuration) override; |
Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 135 | |
| 136 | private: |
Matt Buckley | 5727405 | 2022-08-12 21:54:23 +0000 | [diff] [blame] | 137 | friend class PowerAdvisorTest; |
| 138 | |
Matt Buckley | 0538cae | 2022-11-08 23:12:04 +0000 | [diff] [blame^] | 139 | std::unique_ptr<power::PowerHalController> mPowerHal; |
Dan Stoza | 29e7bdf | 2020-03-23 14:43:09 -0700 | [diff] [blame] | 140 | std::atomic_bool mBootFinished = false; |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 141 | |
Peiyong Lin | 74ca2f4 | 2019-01-14 19:36:57 -0800 | [diff] [blame] | 142 | std::unordered_set<DisplayId> mExpensiveDisplays; |
Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 143 | bool mNotifiedExpensiveRendering = false; |
Dan Stoza | 030fbc1 | 2020-02-19 15:32:01 -0800 | [diff] [blame] | 144 | |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 145 | SurfaceFlinger& mFlinger; |
Dan Stoza | 030fbc1 | 2020-02-19 15:32:01 -0800 | [diff] [blame] | 146 | std::atomic_bool mSendUpdateImminent = true; |
Alec Mouri | c059dcf | 2022-05-05 23:40:07 +0000 | [diff] [blame] | 147 | std::atomic<nsecs_t> mLastScreenUpdatedTime = 0; |
| 148 | std::optional<scheduler::OneShotTimer> mScreenUpdateTimer; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 149 | |
| 150 | // Higher-level timing data used for estimation |
| 151 | struct DisplayTimeline { |
Matt Buckley | 16dec1f | 2022-06-07 21:46:20 +0000 | [diff] [blame] | 152 | // The start of hwc present, or the start of validate if it happened there instead |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 153 | TimePoint hwcPresentStartTime; |
Matt Buckley | 16dec1f | 2022-06-07 21:46:20 +0000 | [diff] [blame] | 154 | // The end of hwc present or validate, whichever one actually presented |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 155 | TimePoint hwcPresentEndTime; |
Matt Buckley | 16dec1f | 2022-06-07 21:46:20 +0000 | [diff] [blame] | 156 | // How long the actual hwc present was delayed after hwcPresentStartTime |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 157 | Duration hwcPresentDelayDuration{0ns}; |
Matt Buckley | c6b9d38 | 2022-06-17 15:28:07 -0700 | [diff] [blame] | 158 | // When we think we started waiting for the present fence after calling into hwc present and |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 159 | // after potentially waiting for the earliest present time |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 160 | TimePoint presentFenceWaitStartTime; |
Matt Buckley | 16dec1f | 2022-06-07 21:46:20 +0000 | [diff] [blame] | 161 | // How long we ran after we finished waiting for the fence but before hwc present finished |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 162 | Duration postPresentFenceHwcPresentDuration{0ns}; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 163 | // Are we likely to have waited for the present fence during composition |
Matt Buckley | c6b9d38 | 2022-06-17 15:28:07 -0700 | [diff] [blame] | 164 | bool probablyWaitsForPresentFence = false; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 165 | }; |
| 166 | |
| 167 | struct GpuTimeline { |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 168 | Duration duration{0ns}; |
| 169 | TimePoint startTime; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 170 | }; |
| 171 | |
| 172 | // Power hint session data recorded from the pipeline |
| 173 | struct DisplayTimingData { |
| 174 | std::unique_ptr<FenceTime> gpuEndFenceTime; |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 175 | std::optional<TimePoint> gpuStartTime; |
| 176 | std::optional<TimePoint> lastValidGpuEndTime; |
| 177 | std::optional<TimePoint> lastValidGpuStartTime; |
| 178 | std::optional<TimePoint> hwcPresentStartTime; |
| 179 | std::optional<TimePoint> hwcPresentEndTime; |
| 180 | std::optional<TimePoint> hwcValidateStartTime; |
| 181 | std::optional<TimePoint> hwcValidateEndTime; |
| 182 | std::optional<TimePoint> hwcPresentDelayedTime; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 183 | bool usedClientComposition = false; |
| 184 | bool skippedValidate = false; |
| 185 | // Calculate high-level timing milestones from more granular display timing data |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 186 | DisplayTimeline calculateDisplayTimeline(TimePoint fenceTime); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 187 | // Estimate the gpu duration for a given display from previous gpu timing data |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 188 | std::optional<GpuTimeline> estimateGpuTiming(std::optional<TimePoint> previousEndTime); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 189 | }; |
| 190 | |
| 191 | template <class T, size_t N> |
| 192 | class RingBuffer { |
| 193 | std::array<T, N> elements = {}; |
| 194 | size_t mIndex = 0; |
| 195 | size_t numElements = 0; |
| 196 | |
| 197 | public: |
| 198 | void append(T item) { |
| 199 | mIndex = (mIndex + 1) % N; |
| 200 | numElements = std::min(N, numElements + 1); |
| 201 | elements[mIndex] = item; |
| 202 | } |
| 203 | bool isFull() const { return numElements == N; } |
| 204 | // Allows access like [0] == current, [-1] = previous, etc.. |
| 205 | T& operator[](int offset) { |
| 206 | size_t positiveOffset = |
| 207 | static_cast<size_t>((offset % static_cast<int>(N)) + static_cast<int>(N)); |
| 208 | return elements[(mIndex + positiveOffset) % N]; |
| 209 | } |
| 210 | }; |
| 211 | |
| 212 | // Filter and sort the display ids by a given property |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 213 | std::vector<DisplayId> getOrderedDisplayIds( |
| 214 | std::optional<TimePoint> DisplayTimingData::*sortBy); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 215 | // Estimates a frame's total work duration including gpu time. |
Matt Buckley | 0538cae | 2022-11-08 23:12:04 +0000 | [diff] [blame^] | 216 | std::optional<Duration> estimateWorkDuration(); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 217 | // There are two different targets and actual work durations we care about, |
| 218 | // this normalizes them together and takes the max of the two |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 219 | Duration combineTimingEstimates(Duration totalDuration, Duration flingerDuration); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 220 | |
| 221 | std::unordered_map<DisplayId, DisplayTimingData> mDisplayTimingData; |
| 222 | |
| 223 | // Current frame's delay |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 224 | Duration mFrameDelayDuration{0ns}; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 225 | // Last frame's post-composition duration |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 226 | Duration mLastPostcompDuration{0ns}; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 227 | // Buffer of recent commit start times |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 228 | RingBuffer<TimePoint, 2> mCommitStartTimes; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 229 | // Buffer of recent expected present times |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 230 | RingBuffer<TimePoint, 2> mExpectedPresentTimes; |
Matt Buckley | a2ad1dc | 2022-08-16 20:07:26 +0000 | [diff] [blame] | 231 | // Most recent present fence time, provided by SF after composition engine finishes presenting |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 232 | TimePoint mLastPresentFenceTime; |
Matt Buckley | a2ad1dc | 2022-08-16 20:07:26 +0000 | [diff] [blame] | 233 | // Most recent composition engine present end time, returned with the present fence from SF |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 234 | TimePoint mLastSfPresentEndTime; |
Matt Buckley | a2ad1dc | 2022-08-16 20:07:26 +0000 | [diff] [blame] | 235 | // Target duration for the entire pipeline including gpu |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 236 | std::optional<Duration> mTotalFrameTargetDuration; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 237 | // Updated list of display IDs |
| 238 | std::vector<DisplayId> mDisplayIds; |
| 239 | |
Matt Buckley | 0538cae | 2022-11-08 23:12:04 +0000 | [diff] [blame^] | 240 | // Ensure powerhal connection is initialized |
| 241 | power::PowerHalController& getPowerHal(); |
| 242 | |
| 243 | std::optional<bool> mHintSessionEnabled; |
| 244 | std::optional<bool> mSupportsHintSession; |
| 245 | bool mHintSessionRunning = false; |
| 246 | |
| 247 | std::mutex mHintSessionMutex; |
| 248 | sp<hardware::power::IPowerHintSession> mHintSession GUARDED_BY(mHintSessionMutex) = nullptr; |
| 249 | |
| 250 | // Initialize to true so we try to call, to check if it's supported |
| 251 | bool mHasExpensiveRendering = true; |
| 252 | bool mHasDisplayUpdateImminent = true; |
| 253 | // Queue of actual durations saved to report |
| 254 | std::vector<hardware::power::WorkDuration> mHintSessionQueue; |
| 255 | // The latest values we have received for target and actual |
| 256 | Duration mTargetDuration = kDefaultTargetDuration; |
| 257 | std::optional<Duration> mActualDuration; |
| 258 | // The list of thread ids, stored so we can restart the session from this class if needed |
| 259 | std::vector<int32_t> mHintSessionThreadIds; |
| 260 | Duration mLastTargetDurationSent = kDefaultTargetDuration; |
| 261 | // Whether we should emit ATRACE_INT data for hint sessions |
| 262 | static const bool sTraceHintSessionData; |
| 263 | |
| 264 | // Default target duration for the hint session |
| 265 | static constexpr const Duration kDefaultTargetDuration{16ms}; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 266 | |
Matt Buckley | c6b9d38 | 2022-06-17 15:28:07 -0700 | [diff] [blame] | 267 | // An adjustable safety margin which pads the "actual" value sent to PowerHAL, |
| 268 | // encouraging more aggressive boosting to give SurfaceFlinger a larger margin for error |
Matt Buckley | ac15a1b | 2023-02-28 06:51:28 +0000 | [diff] [blame] | 269 | static const Duration sTargetSafetyMargin; |
| 270 | static constexpr const Duration kDefaultTargetSafetyMargin{1ms}; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 271 | |
| 272 | // How long we expect hwc to run after the present call until it waits for the fence |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 273 | static constexpr const Duration kFenceWaitStartDelayValidated{150us}; |
| 274 | static constexpr const Duration kFenceWaitStartDelaySkippedValidate{250us}; |
Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 275 | }; |
| 276 | |
Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 277 | } // namespace impl |
| 278 | } // namespace Hwc2 |
| 279 | } // namespace android |