summaryrefslogtreecommitdiffstats
path: root/libcutils/sched_policy.cpp
diff options
context:
space:
mode:
authorErik Staats <estaats@google.com>2017-04-26 15:15:55 -0700
committerErik Staats <estaats@google.com>2017-04-26 15:39:26 -0700
commitd32331fb272048eeb55184bee15071fb95b6a6c2 (patch)
tree562ca691fa218381e6640598d22d0f0b2c7516dc /libcutils/sched_policy.cpp
parent1ac29896b079f0d2c279f93f882fccca22947ab9 (diff)
downloadsystem_core-d32331fb272048eeb55184bee15071fb95b6a6c2.tar.gz
system_core-d32331fb272048eeb55184bee15071fb95b6a6c2.tar.bz2
system_core-d32331fb272048eeb55184bee15071fb95b6a6c2.zip
Change set_sched_policy to set slack for current thread.
Change set_sched_policy to use prctl PR_SET_TIMERSLACK if setting the policy for the current thread and /proc/<tid>/timerslack_ns is not supported by the kernel. Bug: 32972117 Test: Verified that libcutils SchedPolicy tests pass. See details in testing done comment in https://android-review.googlesource.com/381303 . Change-Id: Id70940ed7f9ed94c3d105213f069bf3e5a8d8824
Diffstat (limited to 'libcutils/sched_policy.cpp')
-rw-r--r--libcutils/sched_policy.cpp32
1 files changed, 19 insertions, 13 deletions
diff --git a/libcutils/sched_policy.cpp b/libcutils/sched_policy.cpp
index 217733a22..e29a8444c 100644
--- a/libcutils/sched_policy.cpp
+++ b/libcutils/sched_policy.cpp
@@ -343,16 +343,25 @@ 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.
- char buf[64];
- snprintf(buf, sizeof(buf), "/proc/%d/timerslack_ns", tid);
- int fd = open(buf, O_WRONLY | O_CLOEXEC);
- if (fd != -1) {
- int len = snprintf(buf, sizeof(buf), "%llu", slack);
- if (write(fd, buf, len) != len) {
- SLOGE("set_timerslack_ns write failed: %s\n", strerror(errno));
+ if (__sys_supports_timerslack) {
+ char buf[64];
+ snprintf(buf, sizeof(buf), "/proc/%d/timerslack_ns", tid);
+ int fd = open(buf, O_WRONLY | O_CLOEXEC);
+ if (fd != -1) {
+ int len = snprintf(buf, sizeof(buf), "%llu", slack);
+ if (write(fd, buf, len) != len) {
+ SLOGE("set_timerslack_ns write failed: %s\n", strerror(errno));
+ }
+ close(fd);
+ return;
+ }
+ }
+
+ // 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));
}
- close(fd);
- return;
}
}
@@ -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;
}