summaryrefslogtreecommitdiffstats
path: root/libcutils
diff options
context:
space:
mode:
authorPat Erley <perley@cyngn.com>2016-03-22 15:58:47 -0700
committerPat Erley <perley@cyngn.com>2016-03-24 16:57:14 -0700
commit26bc3e918e79909fed67ddca66045b9faf888c84 (patch)
tree7c31bf35f72abb5381d8ae6e9689b5313f52c3a6 /libcutils
parentbc667ac5f12fd82fe16f4aa9f4883a4b010f10ca (diff)
downloadsystem_core-26bc3e918e79909fed67ddca66045b9faf888c84.zip
system_core-26bc3e918e79909fed67ddca66045b9faf888c84.tar.gz
system_core-26bc3e918e79909fed67ddca66045b9faf888c84.tar.bz2
sched_policy: split add_tid_to_cgroup
add_tid_to_cgroup was also being used to add threads to cpusets. Split this into a generic write_tid_to_fd, and wrap it for cpusets and cgroups. This lets errors align with what the actual failure is. Change-Id: I2c5c97117428a33b6a328f73741d3516d4141f78
Diffstat (limited to 'libcutils')
-rw-r--r--libcutils/sched_policy.c49
1 files changed, 38 insertions, 11 deletions
diff --git a/libcutils/sched_policy.c b/libcutils/sched_policy.c
index 2c29003..aa4f39d 100644
--- a/libcutils/sched_policy.c
+++ b/libcutils/sched_policy.c
@@ -69,15 +69,8 @@ static int system_bg_cpuset_fd = -1;
static int bg_cpuset_fd = -1;
static int fg_cpuset_fd = -1;
-/* Add tid to the scheduling group defined by the policy */
-static int add_tid_to_cgroup(int tid, int fd)
+static int write_tid_to_fd(int tid, int fd)
{
- if (fd < 0) {
- SLOGE("%s add_tid_to_cgroup failed; fd=%d\n", proc_name, fd);
- errno = EINVAL;
- return -1;
- }
-
// specialized itoa -- works for tid > 0
char text[22];
char *end = text + sizeof(text) - 1;
@@ -95,8 +88,42 @@ static int add_tid_to_cgroup(int tid, int fd)
*/
if (errno == ESRCH)
return 0;
- SLOGW("%s add_tid_to_cgroup failed to write '%s' (%s); fd=%d\n",
- proc_name, ptr, strerror(errno), fd);
+ return -1;
+ }
+
+ return 0;
+}
+
+/* Add tid to the scheduling group defined by the policy */
+static int add_tid_to_cgroup(int tid, int fd)
+{
+ if (fd < 0) {
+ SLOGE("%s add_tid_to_cgroup failed; fd=%d\n", proc_name, fd);
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (write_tid_to_fd(tid, fd) != 0) {
+ SLOGW("%s add_tid_to_cgroup failed to write '%d' (%s); fd=%d\n",
+ proc_name, tid, strerror(errno), fd);
+ errno = EINVAL;
+ return -1;
+ }
+
+ return 0;
+}
+
+static int add_tid_to_cpuset(int tid, int fd)
+{
+ if (fd < 0) {
+ SLOGE("%s add_tid_to_cpuset failed; fd=%d\n", proc_name, fd);
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (write_tid_to_fd(tid, fd) != 0) {
+ SLOGW("%s add_tid_to_cpuset failed to write '%d' (%s); fd=%d\n",
+ proc_name, tid, strerror(errno), fd);
errno = EINVAL;
return -1;
}
@@ -341,7 +368,7 @@ int set_cpuset_policy(int tid, SchedPolicy policy)
break;
}
- if (add_tid_to_cgroup(tid, fd) != 0) {
+ if (add_tid_to_cpuset(tid, fd) != 0) {
if (errno != ESRCH && errno != ENOENT)
return -errno;
}