summaryrefslogtreecommitdiffstats
path: root/libcutils
diff options
context:
space:
mode:
authorJohn Stultz <john.stultz@linaro.org>2016-07-30 05:20:34 +0000
committerandroid-build-merger <android-build-merger@google.com>2016-07-30 05:20:34 +0000
commitacf5e849b4edd44fb87f2bab7833f5f242b91590 (patch)
treee869ad576fe678f3527e0ac1a9dfd09d28897614 /libcutils
parent8df46540b4d0af156583eecaea79c1e131c76f8a (diff)
parent817d53493aeeca3d10f5a06776d1ffa1ab69f19b (diff)
downloadsystem_core-acf5e849b4edd44fb87f2bab7833f5f242b91590.tar.gz
system_core-acf5e849b4edd44fb87f2bab7833f5f242b91590.tar.bz2
system_core-acf5e849b4edd44fb87f2bab7833f5f242b91590.zip
Merge \"sched_policy: Add support for /proc/<tid>/timerslack_ns over PR_SET_TIMERSLACK_PID\"
am: 817d53493a Change-Id: Iea895b632b3bfa7daae0be34c2cc69563a18a6d5
Diffstat (limited to 'libcutils')
-rw-r--r--libcutils/sched_policy.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/libcutils/sched_policy.c b/libcutils/sched_policy.c
index 884ee178e..2ac8145ba 100644
--- a/libcutils/sched_policy.c
+++ b/libcutils/sched_policy.c
@@ -166,7 +166,7 @@ static int getCGroupSubsys(int tid, const char* subsys, char* buf, size_t bufLen
FILE *fp;
snprintf(pathBuf, sizeof(pathBuf), "/proc/%d/cgroup", tid);
- if (!(fp = fopen(pathBuf, "r"))) {
+ if (!(fp = fopen(pathBuf, "re"))) {
return -1;
}
@@ -323,6 +323,27 @@ int set_cpuset_policy(int tid, SchedPolicy policy)
#endif
}
+static void set_timerslack_ns(int tid, unsigned long long slack) {
+ char buf[64];
+
+ /* v4.6+ kernels support the /proc/<tid>/timerslack_ns interface. */
+ 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;
+ }
+
+ /* If the above fails, try the old common.git PR_SET_TIMERSLACK_PID. */
+ if (prctl(PR_SET_TIMERSLACK_PID, slack, tid) == -1) {
+ SLOGE("set_timerslack_ns prctl failed: %s\n", strerror(errno));
+ }
+}
+
int set_sched_policy(int tid, SchedPolicy policy)
{
if (tid == 0) {
@@ -335,12 +356,11 @@ int set_sched_policy(int tid, SchedPolicy policy)
char statfile[64];
char statline[1024];
char thread_name[255];
- int fd;
snprintf(statfile, sizeof(statfile), "/proc/%d/stat", tid);
memset(thread_name, 0, sizeof(thread_name));
- fd = open(statfile, O_RDONLY);
+ int fd = open(statfile, O_RDONLY | O_CLOEXEC);
if (fd >= 0) {
int rc = read(fd, statline, 1023);
close(fd);
@@ -405,8 +425,8 @@ int set_sched_policy(int tid, SchedPolicy policy)
&param);
}
- prctl(PR_SET_TIMERSLACK_PID,
- policy == SP_BACKGROUND ? TIMER_SLACK_BG : TIMER_SLACK_FG, tid);
+ set_timerslack_ns(tid, policy == SP_BACKGROUND ?
+ TIMER_SLACK_BG : TIMER_SLACK_FG);
return 0;
}