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

Commit bb4e3baf authored by Alec Mouri's avatar Alec Mouri
Browse files

Fix up reference times for period changes.

* When the model is reset, use the last seen reference time instead
of 0, since the reference time of 0 is guaranteed to yield inaccurate
pulses.
* When the DispSync model is updated, reduce the reference time by a
period to derisk spurious events firing when the model is updated.

Bug: 124383894
Test: systrace
Change-Id: Idb7fd5a9bacdd78133ab6451b5a79789a32e339e
parent 066bd7e0
Loading
Loading
Loading
Loading
+19 −3
Original line number Diff line number Diff line
@@ -76,9 +76,18 @@ public:
    void updateModel(nsecs_t period, nsecs_t phase, nsecs_t referenceTime) {
        if (mTraceDetailedInfo) ATRACE_CALL();
        Mutex::Autolock lock(mMutex);
        mPeriod = period;

        mPhase = phase;
        mReferenceTime = referenceTime;
        if (mPeriod != period && mReferenceTime != 0) {
            // Inflate the reference time to be the most recent predicted
            // vsync before the current time.
            const nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
            const nsecs_t baseTime = now - mReferenceTime;
            const nsecs_t numOldPeriods = baseTime / mPeriod;
            mReferenceTime = mReferenceTime + (numOldPeriods)*mPeriod;
        }
        mPeriod = period;
        if (mTraceDetailedInfo) {
            ATRACE_INT64("DispSync:Period", mPeriod);
            ATRACE_INT64("DispSync:Phase", mPhase + mPeriod / 2);
@@ -429,8 +438,16 @@ void DispSync::reset() {

void DispSync::resetLocked() {
    mPhase = 0;
    mReferenceTime = 0;
    const size_t lastSampleIdx = (mFirstResyncSample + mNumResyncSamples - 1) % MAX_RESYNC_SAMPLES;
    // Keep the most recent sample, when we resync to hardware we'll overwrite this
    // with a more accurate signal
    if (mResyncSamples[lastSampleIdx] != 0) {
        mReferenceTime = mResyncSamples[lastSampleIdx];
    }
    mModelUpdated = false;
    for (size_t i = 0; i < MAX_RESYNC_SAMPLES; i++) {
        mResyncSamples[i] = 0;
    }
    mNumResyncSamples = 0;
    mFirstResyncSample = 0;
    mNumResyncSamplesSincePresent = 0;
@@ -530,7 +547,6 @@ void DispSync::setPeriod(nsecs_t period) {
    Mutex::Autolock lock(mMutex);
    mPeriod = period;
    mPhase = 0;
    mReferenceTime = 0;
    mThread->updateModel(mPeriod, mPhase, mReferenceTime);
}

+1 −1
Original line number Diff line number Diff line
@@ -213,7 +213,7 @@ private:
    // These member variables are the state used during the resynchronization
    // process to store information about the hardware vsync event times used
    // to compute the model.
    nsecs_t mResyncSamples[MAX_RESYNC_SAMPLES];
    nsecs_t mResyncSamples[MAX_RESYNC_SAMPLES] = {0};
    size_t mFirstResyncSample;
    size_t mNumResyncSamples;
    int mNumResyncSamplesSincePresent;