diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2017-05-04 22:05:54 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2017-05-04 22:05:54 +0000 |
commit | 1d2adc7f41485bc42e19f395c5d6c7b73d419c70 (patch) | |
tree | a1bcb3bcb6850c0ea9cc4a29ada23b55acdd55e9 | |
parent | 1726d557ff17ceac11fe65a9b5d29e3b7f92a965 (diff) | |
parent | a1ca49bf2ee2982d6a78a82ad9535e4c2ee46f3e (diff) |
release-request-3b995630-3bae-4f9e-868a-935ab7740cc9-for-git_nyc-mr2-pixel-monthly-release-3934930 snap-temp-L20000000060688928
Change-Id: I0b0e54d53ba4dd01b340a98cbd22998853fcb7ae
-rw-r--r-- | libcutils/sched_policy.c | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/libcutils/sched_policy.c b/libcutils/sched_policy.c index e11eb2e9e..6d905898a 100644 --- a/libcutils/sched_policy.c +++ b/libcutils/sched_policy.c @@ -56,6 +56,10 @@ static pthread_once_t the_once = PTHREAD_ONCE_INIT; static int __sys_supports_schedgroups = -1; +// File descriptors open to /dev/cpuctl/../tasks, setup by initialize, or -1 on error. +static int bg_cgroup_fd = -1; +static int fg_cgroup_fd = -1; + #ifdef USE_CPUSETS // File descriptors open to /dev/cpuset/../tasks, setup by initialize, or -1 on error static int system_bg_cpuset_fd = -1; @@ -69,7 +73,6 @@ static int bg_schedboost_fd = -1; static int fg_schedboost_fd = -1; static int ta_schedboost_fd = -1; -#if defined(USE_CPUSETS) || defined(USE_SCHEDBOOST) /* Add tid to the scheduling group defined by the policy */ static int add_tid_to_cgroup(int tid, int fd) { @@ -104,18 +107,30 @@ static int add_tid_to_cgroup(int tid, int fd) return 0; } -#endif //defined(USE_CPUSETS) || defined(USE_SCHEDBOOST) static void __initialize(void) { + char* filename; if (!access("/dev/cpuctl/tasks", F_OK)) { __sys_supports_schedgroups = 1; + + filename = "/dev/cpuctl/tasks"; + fg_cgroup_fd = open(filename, O_WRONLY | O_CLOEXEC); + if (fg_cgroup_fd < 0) { + SLOGE("open of %s failed: %s\n", filename, strerror(errno)); + } + + filename = "/dev/cpuctl/bg_non_interactive/tasks"; + bg_cgroup_fd = open(filename, O_WRONLY | O_CLOEXEC); + if (bg_cgroup_fd < 0) { + SLOGE("open of %s failed: %s\n", filename, strerror(errno)); + } } else { __sys_supports_schedgroups = 0; } #ifdef USE_CPUSETS if (!access("/dev/cpuset/tasks", F_OK)) { - char* filename; + filename = "/dev/cpuset/foreground/tasks"; fg_cpuset_fd = open(filename, O_WRONLY | O_CLOEXEC); filename = "/dev/cpuset/background/tasks"; @@ -365,24 +380,35 @@ int set_sched_policy(int tid, SchedPolicy policy) #endif if (__sys_supports_schedgroups) { + int fd = -1; int boost_fd = -1; switch (policy) { case SP_BACKGROUND: + fd = bg_cgroup_fd; boost_fd = bg_schedboost_fd; break; case SP_FOREGROUND: case SP_AUDIO_APP: case SP_AUDIO_SYS: + fd = fg_cgroup_fd; boost_fd = fg_schedboost_fd; break; case SP_TOP_APP: + fd = fg_cgroup_fd; boost_fd = ta_schedboost_fd; break; default: + fd = -1; boost_fd = -1; break; } + + if (fd > 0 && add_tid_to_cgroup(tid, fd) != 0) { + if (errno != ESRCH && errno != ENOENT) + return -errno; + } + #ifdef USE_SCHEDBOOST if (boost_fd > 0 && add_tid_to_cgroup(tid, boost_fd) != 0) { if (errno != ESRCH && errno != ENOENT) |