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

Commit 1e06ed69 authored by Jagadeesh Pakaravoor's avatar Jagadeesh Pakaravoor
Browse files

Bump Surfaceflinger's binder threads to SCHED_FIFO

1) Set threads in Surfaceflinger's threadpool to have SCHED_FIFO policy
(and lowest RT priority). This is achieved by temporarily promoting the
priority of the thread creating the threadpool to the aforementioned
configuration.

2) Also set the minimum policy for the SF binder node to be SCHED_FIFO.

Test: presubmit
Bug: 183129340
Change-Id: I2df47fdc00fb0ae8937c30710243305cf018d830
parent c2d5b1bd
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -89,13 +89,47 @@ int main(int, char**) {
    // binder threads to 4.
    ProcessState::self()->setThreadPoolMaxThreadCount(4);

    // 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)
    // Once the pool is created we reset this thread's priority back to
    // original.
    int newPriority = 0;
    int origPolicy = sched_getscheduler(0);
    struct sched_param origSchedParam;

    int errorInPriorityModification = sched_getparam(0, &origSchedParam);
    if (errorInPriorityModification == 0) {
        int policy = SCHED_FIFO;
        newPriority = sched_get_priority_min(policy);

        struct sched_param param;
        param.sched_priority = newPriority;

        errorInPriorityModification = sched_setscheduler(0, policy, &param);
    }

    // start the thread pool
    sp<ProcessState> ps(ProcessState::self());
    ps->startThreadPool();

    // Reset current thread's policy and priority
    if (errorInPriorityModification == 0) {
        errorInPriorityModification = sched_setscheduler(0, origPolicy, &origSchedParam);
    } else {
        ALOGE("Failed to set SurfaceFlinger binder threadpool priority to SCHED_FIFO");
    }

    // instantiate surfaceflinger
    sp<SurfaceFlinger> flinger = surfaceflinger::createSurfaceFlinger();

    // Set the minimum policy of surfaceflinger node to be SCHED_FIFO.
    // So any thread with policy/priority lower than {SCHED_FIFO, 1}, will run
    // at least with SCHED_FIFO policy and priority 1.
    if (errorInPriorityModification == 0) {
        flinger->setMinSchedulerPolicy(SCHED_FIFO, newPriority);
    }

    setpriority(PRIO_PROCESS, 0, PRIORITY_URGENT_DISPLAY);

    set_sched_policy(0, SP_FOREGROUND);