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

Commit 18c6fcf6 authored by Alec Mouri's avatar Alec Mouri Committed by Automerger Merge Worker
Browse files

Reduce kernel instructions for PowerAdvisor am: 19609698

parents 8dd1f77a 19609698
Loading
Loading
Loading
Loading
+35 −16
Original line number Diff line number Diff line
@@ -80,22 +80,33 @@ void traceExpensiveRendering(bool enabled) {

} // namespace

PowerAdvisor::PowerAdvisor(SurfaceFlinger& flinger)
      : mFlinger(flinger),
        mUseScreenUpdateTimer(getUpdateTimeout() > 0),
        mScreenUpdateTimer(
                "UpdateImminentTimer", OneShotTimer::Interval(getUpdateTimeout()),
                /* resetCallback */ [this] { mSendUpdateImminent.store(false); },
PowerAdvisor::PowerAdvisor(SurfaceFlinger& flinger) : mFlinger(flinger) {
    if (getUpdateTimeout()) {
        mScreenUpdateTimer.emplace("UpdateImminentTimer",
                                   OneShotTimer::Interval(getUpdateTimeout()),
                                   /* resetCallback */ nullptr,
                                   /* timeoutCallback */
                                   [this] {
                                       const nsecs_t timeSinceLastUpdate =
                                               systemTime() - mLastScreenUpdatedTime.load();
                                       if (timeSinceLastUpdate < getUpdateTimeout()) {
                                           // We may try to disable expensive rendering and allow
                                           // for sending DISPLAY_UPDATE_IMMINENT hints too early if
                                           // we idled very shortly after updating the screen, so
                                           // make sure we wait enough time.
                                           std::this_thread::sleep_for(std::chrono::nanoseconds(
                                                   getUpdateTimeout() - timeSinceLastUpdate));
                                       }
                                       mSendUpdateImminent.store(true);
                                       mFlinger.disableExpensiveRendering();
                }) {}
                                   });
    }
}

void PowerAdvisor::init() {
    // Defer starting the screen update timer until SurfaceFlinger finishes construction.
    if (mUseScreenUpdateTimer) {
        mScreenUpdateTimer.start();
    if (mScreenUpdateTimer) {
        mScreenUpdateTimer->start();
    }
}

@@ -135,7 +146,7 @@ void PowerAdvisor::notifyDisplayUpdateImminent() {
        return;
    }

    if (mSendUpdateImminent.load()) {
    if (mSendUpdateImminent.exchange(false)) {
        std::lock_guard lock(mPowerHalMutex);
        HalWrapper* const halWrapper = getPowerHal();
        if (halWrapper == nullptr) {
@@ -147,10 +158,18 @@ void PowerAdvisor::notifyDisplayUpdateImminent() {
            mReconnectPowerHal = true;
            return;
        }

        if (mScreenUpdateTimer) {
            mScreenUpdateTimer->reset();
        } else {
            // If we don't have a screen update timer, then we don't throttle power hal calls so
            // flip this bit back to allow for calling into power hal again.
            mSendUpdateImminent.store(true);
        }
    }

    if (mUseScreenUpdateTimer) {
        mScreenUpdateTimer.reset();
    if (mScreenUpdateTimer) {
        mLastScreenUpdatedTime.store(systemTime());
    }
}

+2 −2
Original line number Diff line number Diff line
@@ -114,9 +114,9 @@ private:
    bool mNotifiedExpensiveRendering = false;

    SurfaceFlinger& mFlinger;
    const bool mUseScreenUpdateTimer;
    std::atomic_bool mSendUpdateImminent = true;
    scheduler::OneShotTimer mScreenUpdateTimer;
    std::atomic<nsecs_t> mLastScreenUpdatedTime = 0;
    std::optional<scheduler::OneShotTimer> mScreenUpdateTimer;
};

class AidlPowerHalWrapper : public PowerAdvisor::HalWrapper {