diff options
Diffstat (limited to 'services/surfaceflinger/DispSync.cpp')
| -rw-r--r-- | services/surfaceflinger/DispSync.cpp | 72 | 
1 files changed, 39 insertions, 33 deletions
| diff --git a/services/surfaceflinger/DispSync.cpp b/services/surfaceflinger/DispSync.cpp index ea048397d0..bef12ea50f 100644 --- a/services/surfaceflinger/DispSync.cpp +++ b/services/surfaceflinger/DispSync.cpp @@ -30,7 +30,7 @@  #include <utils/Trace.h>  #include <utils/Vector.h> -#include <ui/Fence.h> +#include <ui/FenceTime.h>  #include "DispSync.h"  #include "SurfaceFlinger.h" @@ -421,25 +421,13 @@ void DispSync::reset() {      resetErrorLocked();  } -bool DispSync::addPresentFence(const sp<Fence>& fence) { +bool DispSync::addPresentFence(const std::shared_ptr<FenceTime>& fenceTime) {      Mutex::Autolock lock(mMutex); -    mPresentFences[mPresentSampleOffset] = fence; -    mPresentTimes[mPresentSampleOffset] = 0; +    mPresentFences[mPresentSampleOffset] = fenceTime;      mPresentSampleOffset = (mPresentSampleOffset + 1) % NUM_PRESENT_SAMPLES;      mNumResyncSamplesSincePresent = 0; -    for (size_t i = 0; i < NUM_PRESENT_SAMPLES; i++) { -        const sp<Fence>& f(mPresentFences[i]); -        if (f != NULL) { -            nsecs_t t = f->getSignalTime(); -            if (t < INT64_MAX) { -                mPresentFences[i].clear(); -                mPresentTimes[i] = t + mPresentTimeOffset; -            } -        } -    } -      updateErrorLocked();      return !mModelUpdated || mError > kErrorThreshold; @@ -604,21 +592,39 @@ void DispSync::updateErrorLocked() {      nsecs_t sqErrSum = 0;      for (size_t i = 0; i < NUM_PRESENT_SAMPLES; i++) { -        nsecs_t sample = mPresentTimes[i] - mReferenceTime; -        if (sample > mPhase) { -            nsecs_t sampleErr = (sample - mPhase) % period; -            if (sampleErr > period / 2) { -                sampleErr -= period; -            } -            sqErrSum += sampleErr * sampleErr; -            numErrSamples++; +        // Only check for the cached value of signal time to avoid unecessary +        // syscalls. It is the responsibility of the DispSync owner to +        // call getSignalTime() periodically so the cache is updated when the +        // fence signals. +        nsecs_t time = mPresentFences[i]->getCachedSignalTime(); +        if (time == Fence::SIGNAL_TIME_PENDING || +                time == Fence::SIGNAL_TIME_INVALID) { +            continue; +        } + +        nsecs_t sample = time - mReferenceTime; +        if (sample <= mPhase) { +            continue; +        } + +        nsecs_t sampleErr = (sample - mPhase) % period; +        if (sampleErr > period / 2) { +            sampleErr -= period;          } +        sqErrSum += sampleErr * sampleErr; +        numErrSamples++;      }      if (numErrSamples > 0) {          mError = sqErrSum / numErrSamples; +        mZeroErrSamplesCount = 0;      } else {          mError = 0; +        // Use mod ACCEPTABLE_ZERO_ERR_SAMPLES_COUNT to avoid log spam. +        mZeroErrSamplesCount++; +        ALOGE_IF( +                (mZeroErrSamplesCount % ACCEPTABLE_ZERO_ERR_SAMPLES_COUNT) == 0, +                "No present times for model error.");      }      if (kTraceDetailedInfo) { @@ -629,9 +635,9 @@ void DispSync::updateErrorLocked() {  void DispSync::resetErrorLocked() {      mPresentSampleOffset = 0;      mError = 0; +    mZeroErrSamplesCount = 0;      for (size_t i = 0; i < NUM_PRESENT_SAMPLES; i++) { -        mPresentFences[i].clear(); -        mPresentTimes[i] = 0; +        mPresentFences[i] = FenceTime::NO_FENCE;      }  } @@ -670,19 +676,19 @@ void DispSync::dump(String8& result) const {          previous = sampleTime;      } -    result.appendFormat("mPresentFences / mPresentTimes [%d]:\n", +    result.appendFormat("mPresentFences [%d]:\n",              NUM_PRESENT_SAMPLES);      nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC); -    previous = 0; +    previous = Fence::SIGNAL_TIME_INVALID;      for (size_t i = 0; i < NUM_PRESENT_SAMPLES; i++) {          size_t idx = (i + mPresentSampleOffset) % NUM_PRESENT_SAMPLES; -        bool signaled = mPresentFences[idx] == NULL; -        nsecs_t presentTime = mPresentTimes[idx]; -        if (!signaled) { +        nsecs_t presentTime = mPresentFences[idx]->getSignalTime(); +        if (presentTime == Fence::SIGNAL_TIME_PENDING) {              result.appendFormat("  [unsignaled fence]\n"); -        } else if (presentTime == 0) { -            result.appendFormat("  0\n"); -        } else if (previous == 0) { +        } else if(presentTime == Fence::SIGNAL_TIME_INVALID) { +            result.appendFormat("  [invalid fence]\n"); +        } else if (previous == Fence::SIGNAL_TIME_PENDING || +                previous == Fence::SIGNAL_TIME_INVALID) {              result.appendFormat("  %" PRId64 "  (%.3f ms ago)\n", presentTime,                      (now - presentTime) / 1000000.0);          } else { |