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

Commit 4a322350 authored by Martin Liu's avatar Martin Liu
Browse files

SurfaceFlinger: align init and resume mode priority

Align init and resume mode RT priority. This could
also sync with HWC RT priority which reduces RT priority
inherit effort during HWbinder transaction.

Bug: 152294747
Test: check SF RT priority
Change-Id: I7c2f8d37de9e3a5ee403120c5a8d523b64c39a51
parent 89260bd4
Loading
Loading
Loading
Loading
+25 −10
Original line number Diff line number Diff line
@@ -4131,6 +4131,9 @@ void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, int
    }

    if (currentMode == HWC_POWER_MODE_OFF) {
        if (SurfaceFlinger::setSchedFifo(true) != NO_ERROR) {
            ALOGW("Couldn't set SCHED_FIFO on display on: %s\n", strerror(errno));
        }
        getHwComposer().setPowerMode(*displayId, mode);
        if (display->isPrimary() && mode != HWC_POWER_MODE_DOZE_SUSPEND) {
            setVsyncEnabledInHWC(*displayId, mHWCVsyncPendingState);
@@ -4141,19 +4144,11 @@ void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, int
        mVisibleRegionsDirty = true;
        mHasPoweredOff = true;
        repaintEverything();

        struct sched_param param = {0};
        param.sched_priority = 1;
        if (sched_setscheduler(0, SCHED_FIFO, &param) != 0) {
            ALOGW("Couldn't set SCHED_FIFO on display on");
        }
    } else if (mode == HWC_POWER_MODE_OFF) {
        // Turn off the display
        struct sched_param param = {0};
        if (sched_setscheduler(0, SCHED_OTHER, &param) != 0) {
            ALOGW("Couldn't set SCHED_OTHER on display off");
        if (SurfaceFlinger::setSchedFifo(false) != NO_ERROR) {
            ALOGW("Couldn't set SCHED_OTHER on display off: %s\n", strerror(errno));
        }

        if (display->isPrimary() && currentMode != HWC_POWER_MODE_DOZE_SUSPEND) {
            mScheduler->disableHardwareVsync(true);
            mScheduler->onScreenReleased(mAppConnectionHandle);
@@ -5340,6 +5335,26 @@ static Dataspace pickDataspaceFromColorMode(const ColorMode colorMode) {
    }
}

status_t SurfaceFlinger::setSchedFifo(bool enabled) {
    static constexpr int kFifoPriority = 2;
    static constexpr int kOtherPriority = 0;

    struct sched_param param = {0};
    int sched_policy;
    if (enabled) {
        sched_policy = SCHED_FIFO;
        param.sched_priority = kFifoPriority;
    } else {
        sched_policy = SCHED_OTHER;
        param.sched_priority = kOtherPriority;
    }

    if (sched_setscheduler(0, sched_policy, &param) != 0) {
        return -errno;
    }
    return NO_ERROR;
}

const sp<DisplayDevice> SurfaceFlinger::getDisplayByIdOrLayerStack(uint64_t displayOrLayerStack) {
    const sp<IBinder> displayToken = getPhysicalDisplayTokenLocked(DisplayId{displayOrLayerStack});
    if (displayToken) {
+3 −0
Original line number Diff line number Diff line
@@ -259,6 +259,9 @@ public:
    // overhead that is caused by reading from sysprop.
    static bool useFrameRateApi;

    // set main thread scheduling policy
    static status_t setSchedFifo(bool enabled) ANDROID_API;

    static char const* getServiceName() ANDROID_API {
        return "SurfaceFlinger";
    }
+3 −4
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@
#include <binder/ProcessState.h>
#include <configstore/Utils.h>
#include <displayservice/DisplayService.h>
#include <errno.h>
#include <hidl/LegacySupport.h>
#include <processgroup/sched_policy.h>
#include "SurfaceFlinger.h"
@@ -114,10 +115,8 @@ int main(int, char**) {

    startDisplayService(); // dependency on SF getting registered above

    struct sched_param param = {0};
    param.sched_priority = 2;
    if (sched_setscheduler(0, SCHED_FIFO, &param) != 0) {
        ALOGE("Couldn't set SCHED_FIFO");
    if (SurfaceFlinger::setSchedFifo(true) != NO_ERROR) {
        ALOGW("Couldn't set to SCHED_FIFO: %s", strerror(errno));
    }

    // run surface flinger in this thread