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

Commit db3dfeec authored by Ady Abraham's avatar Ady Abraham
Browse files

SurfaceFlinger: add thread name to OneShotTimer

Test: interact with device and observe systraces
Bug: 170665374
Change-Id: I55af2ec268dfaa10c570876aeeb63e602ec08ef7
parent 1e19ac97
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ int32_t getUpdateTimeout() {
PowerAdvisor::PowerAdvisor()
      : mUseUpdateImminentTimer(getUpdateTimeout() > 0),
        mUpdateImminentTimer(
                OneShotTimer::Interval(getUpdateTimeout()),
                "UpdateImminentTimer", OneShotTimer::Interval(getUpdateTimeout()),
                /* resetCallback */ [this] { mSendUpdateImminent.store(false); },
                /* timeoutCallback */ [this] { mSendUpdateImminent.store(true); }) {
    if (mUseUpdateImminentTimer) {
+1 −0
Original line number Diff line number Diff line
@@ -175,6 +175,7 @@ RegionSamplingThread::RegionSamplingThread(SurfaceFlinger& flinger, Scheduler& s
        mScheduler(scheduler),
        mTunables(tunables),
        mIdleTimer(
                "RegionSamplingIdleTimer",
                std::chrono::duration_cast<std::chrono::milliseconds>(
                        mTunables.mSamplingTimerTimeout),
                [] {}, [this] { checkForStaleLuma(); }),
+10 −2
Original line number Diff line number Diff line
@@ -40,9 +40,13 @@ void calculateTimeoutTime(std::chrono::nanoseconds timestamp, timespec* spec) {
namespace android {
namespace scheduler {

OneShotTimer::OneShotTimer(const Interval& interval, const ResetCallback& resetCallback,
OneShotTimer::OneShotTimer(std::string name, const Interval& interval,
                           const ResetCallback& resetCallback,
                           const TimeoutCallback& timeoutCallback)
      : mInterval(interval), mResetCallback(resetCallback), mTimeoutCallback(timeoutCallback) {}
      : mName(std::move(name)),
        mInterval(interval),
        mResetCallback(resetCallback),
        mTimeoutCallback(timeoutCallback) {}

OneShotTimer::~OneShotTimer() {
    stop();
@@ -71,6 +75,10 @@ void OneShotTimer::stop() {
}

void OneShotTimer::loop() {
    if (pthread_setname_np(pthread_self(), mName.c_str())) {
        ALOGW("Failed to set thread name on dispatch thread");
    }

    TimerState state = TimerState::RESET;
    while (true) {
        bool triggerReset = false;
+4 −1
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ public:
    using ResetCallback = std::function<void()>;
    using TimeoutCallback = std::function<void()>;

    OneShotTimer(const Interval& interval, const ResetCallback& resetCallback,
    OneShotTimer(std::string name, const Interval& interval, const ResetCallback& resetCallback,
                 const TimeoutCallback& timeoutCallback);
    ~OneShotTimer();

@@ -81,6 +81,9 @@ private:
    // Semaphore to keep mThread synchronized.
    sem_t mSemaphore;

    // Timer's name.
    std::string mName;

    // Interval after which timer expires.
    const Interval mInterval;

+3 −3
Original line number Diff line number Diff line
@@ -135,7 +135,7 @@ Scheduler::Scheduler(const scheduler::RefreshRateConfigs& configs, ISchedulerCal
        const auto callback = mOptions.supportKernelTimer ? &Scheduler::kernelIdleTimerCallback
                                                          : &Scheduler::idleTimerCallback;
        mIdleTimer.emplace(
                std::chrono::milliseconds(millis),
                "IdleTimer", std::chrono::milliseconds(millis),
                [this, callback] { std::invoke(callback, this, TimerState::Reset); },
                [this, callback] { std::invoke(callback, this, TimerState::Expired); });
        mIdleTimer->start();
@@ -144,7 +144,7 @@ Scheduler::Scheduler(const scheduler::RefreshRateConfigs& configs, ISchedulerCal
    if (const int64_t millis = set_touch_timer_ms(0); millis > 0) {
        // Touch events are coming to SF every 100ms, so the timer needs to be higher than that
        mTouchTimer.emplace(
                std::chrono::milliseconds(millis),
                "TouchTimer", std::chrono::milliseconds(millis),
                [this] { touchTimerCallback(TimerState::Reset); },
                [this] { touchTimerCallback(TimerState::Expired); });
        mTouchTimer->start();
@@ -152,7 +152,7 @@ Scheduler::Scheduler(const scheduler::RefreshRateConfigs& configs, ISchedulerCal

    if (const int64_t millis = set_display_power_timer_ms(0); millis > 0) {
        mDisplayPowerTimer.emplace(
                std::chrono::milliseconds(millis),
                "DisplayPowerTimer", std::chrono::milliseconds(millis),
                [this] { displayPowerTimerCallback(TimerState::Reset); },
                [this] { displayPowerTimerCallback(TimerState::Expired); });
        mDisplayPowerTimer->start();
Loading