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

Commit 0f56c2d2 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Add a setting for vendor to set uclamp.min boost for SF main thread"...

Merge "Add a setting for vendor to set uclamp.min boost for SF main thread" into sc-dev am: 83530cf1

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/native/+/14848523

Change-Id: Iaac13aec391053c8937514b1e0fee0207295f8cc
parents a41ad501 83530cf1
Loading
Loading
Loading
Loading
+46 −0
Original line number Original line Diff line number Diff line
@@ -4494,6 +4494,11 @@ void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, hal:
    }
    }
    const auto vsyncPeriod = mRefreshRateConfigs->getCurrentRefreshRate().getVsyncPeriod();
    const auto vsyncPeriod = mRefreshRateConfigs->getCurrentRefreshRate().getVsyncPeriod();
    if (currentMode == hal::PowerMode::OFF) {
    if (currentMode == hal::PowerMode::OFF) {
        // Keep uclamp in a separate syscall and set it before changing to RT due to b/190237315.
        // We can merge the syscall later.
        if (SurfaceFlinger::setSchedAttr(true) != NO_ERROR) {
            ALOGW("Couldn't set uclamp.min on display on: %s\n", strerror(errno));
        }
        if (SurfaceFlinger::setSchedFifo(true) != NO_ERROR) {
        if (SurfaceFlinger::setSchedFifo(true) != NO_ERROR) {
            ALOGW("Couldn't set SCHED_FIFO on display on: %s\n", strerror(errno));
            ALOGW("Couldn't set SCHED_FIFO on display on: %s\n", strerror(errno));
        }
        }
@@ -4512,6 +4517,9 @@ void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, hal:
        if (SurfaceFlinger::setSchedFifo(false) != NO_ERROR) {
        if (SurfaceFlinger::setSchedFifo(false) != NO_ERROR) {
            ALOGW("Couldn't set SCHED_OTHER on display off: %s\n", strerror(errno));
            ALOGW("Couldn't set SCHED_OTHER on display off: %s\n", strerror(errno));
        }
        }
        if (SurfaceFlinger::setSchedAttr(false) != NO_ERROR) {
            ALOGW("Couldn't set uclamp.min on display off: %s\n", strerror(errno));
        }
        if (display->isPrimary() && currentMode != hal::PowerMode::DOZE_SUSPEND) {
        if (display->isPrimary() && currentMode != hal::PowerMode::DOZE_SUSPEND) {
            mScheduler->disableHardwareVsync(true);
            mScheduler->disableHardwareVsync(true);
            mScheduler->onScreenReleased(mAppConnectionHandle);
            mScheduler->onScreenReleased(mAppConnectionHandle);
@@ -5861,6 +5869,44 @@ status_t SurfaceFlinger::setSchedFifo(bool enabled) {
    if (sched_setscheduler(0, sched_policy, &param) != 0) {
    if (sched_setscheduler(0, sched_policy, &param) != 0) {
        return -errno;
        return -errno;
    }
    }

    return NO_ERROR;
}

status_t SurfaceFlinger::setSchedAttr(bool enabled) {
    static const unsigned int kUclampMin =
            base::GetUintProperty<unsigned int>("ro.surface_flinger.uclamp.min", 0U);

    if (!kUclampMin) {
        // uclamp.min set to 0 (default), skip setting
        return NO_ERROR;
    }

    // Currently, there is no wrapper in bionic: b/183240349.
    struct sched_attr {
        uint32_t size;
        uint32_t sched_policy;
        uint64_t sched_flags;
        int32_t sched_nice;
        uint32_t sched_priority;
        uint64_t sched_runtime;
        uint64_t sched_deadline;
        uint64_t sched_period;
        uint32_t sched_util_min;
        uint32_t sched_util_max;
    };

    sched_attr attr = {};
    attr.size = sizeof(attr);

    attr.sched_flags = (SCHED_FLAG_KEEP_ALL | SCHED_FLAG_UTIL_CLAMP);
    attr.sched_util_min = enabled ? kUclampMin : 0;
    attr.sched_util_max = 1024;

    if (syscall(__NR_sched_setattr, 0, &attr, 0)) {
        return -errno;
    }

    return NO_ERROR;
    return NO_ERROR;
}
}


+3 −0
Original line number Original line Diff line number Diff line
@@ -186,6 +186,9 @@ public:
    // set main thread scheduling policy
    // set main thread scheduling policy
    static status_t setSchedFifo(bool enabled) ANDROID_API;
    static status_t setSchedFifo(bool enabled) ANDROID_API;


    // set main thread scheduling attributes
    static status_t setSchedAttr(bool enabled);

    static char const* getServiceName() ANDROID_API { return "SurfaceFlinger"; }
    static char const* getServiceName() ANDROID_API { return "SurfaceFlinger"; }


    // This is the phase offset in nanoseconds of the software vsync event
    // This is the phase offset in nanoseconds of the software vsync event
+6 −0
Original line number Original line Diff line number Diff line
@@ -89,6 +89,12 @@ int main(int, char**) {
    // binder threads to 4.
    // binder threads to 4.
    ProcessState::self()->setThreadPoolMaxThreadCount(4);
    ProcessState::self()->setThreadPoolMaxThreadCount(4);


    // Set uclamp.min setting on all threads, maybe an overkill but we want
    // to cover important threads like RenderEngine.
    if (SurfaceFlinger::setSchedAttr(true) != NO_ERROR) {
        ALOGW("Couldn't set uclamp.min: %s\n", strerror(errno));
    }

    // The binder threadpool we start will inherit sched policy and priority
    // The binder threadpool we start will inherit sched policy and priority
    // of (this) creating thread. We want the binder thread pool to have
    // of (this) creating thread. We want the binder thread pool to have
    // SCHED_FIFO policy and priority 1 (lowest RT priority)
    // SCHED_FIFO policy and priority 1 (lowest RT priority)