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

Commit 4696b411 authored by Erik Staats's avatar Erik Staats Committed by android-build-merger
Browse files

Merge "Change set_sched_policy to set slack for current thread." am: d6f8b5f2

am: fc6d7170

Change-Id: I72c9b3afd6458852158ce96b7ef46b1b1e2e97c4
parents d492d04c fc6d7170
Loading
Loading
Loading
Loading
+19 −13
Original line number Diff line number Diff line
@@ -343,6 +343,7 @@ int set_cpuset_policy(int tid, SchedPolicy policy)
static void set_timerslack_ns(int tid, unsigned long long slack) {
    // v4.6+ kernels support the /proc/<tid>/timerslack_ns interface.
    // TODO: once we've backported this, log if the open(2) fails.
    if (__sys_supports_timerslack) {
        char buf[64];
        snprintf(buf, sizeof(buf), "/proc/%d/timerslack_ns", tid);
        int fd = open(buf, O_WRONLY | O_CLOEXEC);
@@ -356,6 +357,14 @@ static void set_timerslack_ns(int tid, unsigned long long slack) {
        }
    }

    // TODO: Remove when /proc/<tid>/timerslack_ns interface is backported.
    if ((tid == 0) || (tid == gettid())) {
        if (prctl(PR_SET_TIMERSLACK, slack) == -1) {
            SLOGE("set_timerslack_ns prctl failed: %s\n", strerror(errno));
        }
    }
}

int set_sched_policy(int tid, SchedPolicy policy)
{
    if (tid == 0) {
@@ -431,10 +440,7 @@ int set_sched_policy(int tid, SchedPolicy policy)

    }

    if (__sys_supports_timerslack) {
        set_timerslack_ns(tid, policy == SP_BACKGROUND ?
                               TIMER_SLACK_BG : TIMER_SLACK_FG);
    }
    set_timerslack_ns(tid, policy == SP_BACKGROUND ? TIMER_SLACK_BG : TIMER_SLACK_FG);

    return 0;
}