Loading services/surfaceflinger/SurfaceFlinger.cpp +46 −0 Original line number Diff line number Diff line Loading @@ -4474,6 +4474,11 @@ void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, hal: } const auto vsyncPeriod = mRefreshRateConfigs->getCurrentRefreshRate().getVsyncPeriod(); 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) { ALOGW("Couldn't set SCHED_FIFO on display on: %s\n", strerror(errno)); } Loading @@ -4492,6 +4497,9 @@ void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, hal: if (SurfaceFlinger::setSchedFifo(false) != NO_ERROR) { 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) { mScheduler->disableHardwareVsync(true); mScheduler->onScreenReleased(mAppConnectionHandle); Loading Loading @@ -5841,6 +5849,44 @@ status_t SurfaceFlinger::setSchedFifo(bool enabled) { if (sched_setscheduler(0, sched_policy, ¶m) != 0) { 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; } Loading services/surfaceflinger/SurfaceFlinger.h +3 −0 Original line number Diff line number Diff line Loading @@ -186,6 +186,9 @@ public: // set main thread scheduling policy 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"; } // This is the phase offset in nanoseconds of the software vsync event Loading services/surfaceflinger/main_surfaceflinger.cpp +6 −0 Original line number Diff line number Diff line Loading @@ -89,6 +89,12 @@ int main(int, char**) { // binder threads to 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 // of (this) creating thread. We want the binder thread pool to have // SCHED_FIFO policy and priority 1 (lowest RT priority) Loading Loading
services/surfaceflinger/SurfaceFlinger.cpp +46 −0 Original line number Diff line number Diff line Loading @@ -4474,6 +4474,11 @@ void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, hal: } const auto vsyncPeriod = mRefreshRateConfigs->getCurrentRefreshRate().getVsyncPeriod(); 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) { ALOGW("Couldn't set SCHED_FIFO on display on: %s\n", strerror(errno)); } Loading @@ -4492,6 +4497,9 @@ void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, hal: if (SurfaceFlinger::setSchedFifo(false) != NO_ERROR) { 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) { mScheduler->disableHardwareVsync(true); mScheduler->onScreenReleased(mAppConnectionHandle); Loading Loading @@ -5841,6 +5849,44 @@ status_t SurfaceFlinger::setSchedFifo(bool enabled) { if (sched_setscheduler(0, sched_policy, ¶m) != 0) { 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; } Loading
services/surfaceflinger/SurfaceFlinger.h +3 −0 Original line number Diff line number Diff line Loading @@ -186,6 +186,9 @@ public: // set main thread scheduling policy 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"; } // This is the phase offset in nanoseconds of the software vsync event Loading
services/surfaceflinger/main_surfaceflinger.cpp +6 −0 Original line number Diff line number Diff line Loading @@ -89,6 +89,12 @@ int main(int, char**) { // binder threads to 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 // of (this) creating thread. We want the binder thread pool to have // SCHED_FIFO policy and priority 1 (lowest RT priority) Loading