Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7b1cf06a authored by Matt Buckley's avatar Matt Buckley Committed by Android (Google) Code Review
Browse files

Merge "Make SF Hint Session safety margin adjustable with a debug prop" into udc-dev

parents f2424652 ac15a1bf
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -219,7 +219,7 @@ void PowerAdvisor::sendActualWorkDuration() {
        std::lock_guard lock(mPowerHalMutex);
        HalWrapper* const halWrapper = getPowerHal();
        if (halWrapper != nullptr) {
            halWrapper->sendActualWorkDuration(*actualDuration + kTargetSafetyMargin,
            halWrapper->sendActualWorkDuration(*actualDuration + sTargetSafetyMargin,
                                               TimePoint::now());
        }
    }
@@ -232,12 +232,11 @@ void PowerAdvisor::sendPredictedWorkDuration() {
    }

    const std::optional<Duration> predictedDuration = estimateWorkDuration(true);

    if (predictedDuration.has_value()) {
        std::lock_guard lock(mPowerHalMutex);
        HalWrapper* const halWrapper = getPowerHal();
        if (halWrapper != nullptr) {
            halWrapper->sendActualWorkDuration(*predictedDuration + kTargetSafetyMargin,
            halWrapper->sendActualWorkDuration(*predictedDuration + sTargetSafetyMargin,
                                               TimePoint::now());
        }
    }
@@ -812,6 +811,10 @@ std::optional<Duration> AidlPowerHalWrapper::getTargetWorkDuration() {
const bool AidlPowerHalWrapper::sTraceHintSessionData =
        base::GetBoolProperty(std::string("debug.sf.trace_hint_sessions"), false);

const Duration PowerAdvisor::sTargetSafetyMargin = std::chrono::microseconds(
        base::GetIntProperty<int64_t>("debug.sf.hint_margin_us",
                                      ticks<std::micro>(PowerAdvisor::kDefaultTargetSafetyMargin)));

PowerAdvisor::HalWrapper* PowerAdvisor::getPowerHal() {
    if (!mHasHal) {
        return nullptr;
+2 −1
Original line number Diff line number Diff line
@@ -274,7 +274,8 @@ private:

    // An adjustable safety margin which pads the "actual" value sent to PowerHAL,
    // encouraging more aggressive boosting to give SurfaceFlinger a larger margin for error
    static constexpr const Duration kTargetSafetyMargin{1ms};
    static const Duration sTargetSafetyMargin;
    static constexpr const Duration kDefaultTargetSafetyMargin{1ms};

    // How long we expect hwc to run after the present call until it waits for the fence
    static constexpr const Duration kFenceWaitStartDelayValidated{150us};
+10 −4
Original line number Diff line number Diff line
@@ -42,12 +42,12 @@ public:
    void fakeBasicFrameTiming(TimePoint startTime, Duration vsyncPeriod);
    void setExpectedTiming(Duration totalFrameTargetDuration, TimePoint expectedPresentTime);
    Duration getFenceWaitDelayDuration(bool skipValidate);
    Duration getErrorMargin();

protected:
    TestableSurfaceFlinger mFlinger;
    std::unique_ptr<PowerAdvisor> mPowerAdvisor;
    NiceMock<MockAidlPowerHalWrapper>* mMockAidlWrapper;
    Duration kErrorMargin = 1ms;
};

void PowerAdvisorTest::SetUp() FTL_FAKE_GUARD(mPowerAdvisor->mPowerHalMutex) {
@@ -77,6 +77,8 @@ void PowerAdvisorTest::fakeBasicFrameTiming(TimePoint startTime, Duration vsyncP
    mPowerAdvisor->setCommitStart(startTime);
    mPowerAdvisor->setFrameDelay(0ns);
    mPowerAdvisor->setTargetWorkDuration(vsyncPeriod);
    ON_CALL(*mMockAidlWrapper, getTargetWorkDuration())
            .WillByDefault(Return(std::make_optional(vsyncPeriod)));
}

Duration PowerAdvisorTest::getFenceWaitDelayDuration(bool skipValidate) {
@@ -84,6 +86,10 @@ Duration PowerAdvisorTest::getFenceWaitDelayDuration(bool skipValidate) {
                         : PowerAdvisor::kFenceWaitStartDelayValidated);
}

Duration PowerAdvisorTest::getErrorMargin() {
    return mPowerAdvisor->sTargetSafetyMargin;
}

namespace {

TEST_F(PowerAdvisorTest, hintSessionUseHwcDisplay) {
@@ -109,7 +115,7 @@ TEST_F(PowerAdvisorTest, hintSessionUseHwcDisplay) {
    // increment the frame
    startTime += vsyncPeriod;

    const Duration expectedDuration = kErrorMargin + presentDuration + postCompDuration;
    const Duration expectedDuration = getErrorMargin() + presentDuration + postCompDuration;
    EXPECT_CALL(*mMockAidlWrapper, sendActualWorkDuration(Eq(expectedDuration), _)).Times(1);

    fakeBasicFrameTiming(startTime, vsyncPeriod);
@@ -145,7 +151,7 @@ TEST_F(PowerAdvisorTest, hintSessionSubtractsHwcFenceTime) {
    // increment the frame
    startTime += vsyncPeriod;

    const Duration expectedDuration = kErrorMargin + presentDuration +
    const Duration expectedDuration = getErrorMargin() + presentDuration +
            getFenceWaitDelayDuration(false) - hwcBlockedDuration + postCompDuration;
    EXPECT_CALL(*mMockAidlWrapper, sendActualWorkDuration(Eq(expectedDuration), _)).Times(1);

@@ -185,7 +191,7 @@ TEST_F(PowerAdvisorTest, hintSessionUsingSecondaryVirtualDisplays) {
    // increment the frame
    startTime += vsyncPeriod;

    const Duration expectedDuration = kErrorMargin + presentDuration + postCompDuration;
    const Duration expectedDuration = getErrorMargin() + presentDuration + postCompDuration;
    EXPECT_CALL(*mMockAidlWrapper, sendActualWorkDuration(Eq(expectedDuration), _)).Times(1);

    fakeBasicFrameTiming(startTime, vsyncPeriod);
+2 −0
Original line number Diff line number Diff line
@@ -47,6 +47,8 @@ public:
    MOCK_METHOD(void, sendActualWorkDuration, (Duration actualDuration, TimePoint timestamp),
                (override));
    MOCK_METHOD(bool, shouldReconnectHAL, (), (override));
    MOCK_METHOD(std::vector<int32_t>, getPowerHintSessionThreadIds, (), (override));
    MOCK_METHOD(std::optional<Duration>, getTargetWorkDuration, (), (override));
};

} // namespace android::Hwc2::mock
 No newline at end of file