summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@android.com>2010-05-06 12:43:07 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2010-05-06 12:43:07 -0700
commit4e226a5006a5c64385b6c88a36c6a4044bd6ffdd (patch)
treea0e4a06541657efe07ac17c91ac1928b78f27c41
parent7a9f4c26902b012aec0aa7373a03feaffd2134d1 (diff)
parentba9025ce958bf07f843c2301fa60b6a5499f20ca (diff)
downloadsystem_core-4e226a5006a5c64385b6c88a36c6a4044bd6ffdd.zip
system_core-4e226a5006a5c64385b6c88a36c6a4044bd6ffdd.tar.gz
system_core-4e226a5006a5c64385b6c88a36c6a4044bd6ffdd.tar.bz2
am ba9025ce: am 253e27ac: Optimize set_sched_policy(), which gets called in every binder call.
Merge commit 'ba9025ce958bf07f843c2301fa60b6a5499f20ca' into kraken * commit 'ba9025ce958bf07f843c2301fa60b6a5499f20ca': Optimize set_sched_policy(), which gets called in every binder call.
-rw-r--r--libcutils/sched_policy.c38
1 files changed, 22 insertions, 16 deletions
diff --git a/libcutils/sched_policy.c b/libcutils/sched_policy.c
index 3a18b0b..6d2727b 100644
--- a/libcutils/sched_policy.c
+++ b/libcutils/sched_policy.c
@@ -44,22 +44,27 @@
static int __sys_supports_schedgroups = -1;
-static int add_tid_to_cgroup(int tid, const char *grp_name)
+/* Add tid to the group defined by dev_path ("/dev/cpuctl/.../tasks") */
+static int add_tid_to_cgroup(int tid, const char *dev_path)
{
int fd;
- char path[255];
- char text[64];
-
- sprintf(path, "/dev/cpuctl/%s/tasks", grp_name);
-
- if ((fd = open(path, O_WRONLY)) < 0) {
- SLOGE("add_tid_to_cgroup failed to open '%s' (%s)\n", path,
+ if ((fd = open(dev_path, O_WRONLY)) < 0) {
+ SLOGE("add_tid_to_cgroup failed to open '%s' (%s)\n", dev_path,
strerror(errno));
return -1;
}
- sprintf(text, "%d", tid);
- if (write(fd, text, strlen(text)) < 0) {
+ // specialized itoa -- works for tid > 0
+ char text[22];
+ char *end = text + sizeof(text) - 1;
+ char *ptr = end;
+ *ptr = '\0';
+ while (tid > 0) {
+ *--ptr = '0' + (tid % 10);
+ tid = tid / 10;
+ }
+
+ if (write(fd, ptr, end - ptr) < 0) {
close(fd);
/*
* If the thread is in the process of exiting,
@@ -67,8 +72,8 @@ static int add_tid_to_cgroup(int tid, const char *grp_name)
*/
if (errno == ESRCH)
return 0;
- SLOGW("add_tid_to_cgroup failed to write '%s' (%s)\n", path,
- strerror(errno));
+ SLOGW("add_tid_to_cgroup failed to write '%s' to '%s' (%s)\n",
+ ptr, dev_path, strerror(errno));
return -1;
}
@@ -228,13 +233,14 @@ int set_sched_policy(int tid, SchedPolicy policy)
#endif
if (__sys_supports_schedgroups) {
- const char *grp = "";
-
+ const char *dev_path;
if (policy == SP_BACKGROUND) {
- grp = "bg_non_interactive";
+ dev_path = "/dev/cpuctl/bg_non_interactive/tasks";
+ } else {
+ dev_path = "/dev/cpuctl/tasks";
}
- if (add_tid_to_cgroup(tid, grp)) {
+ if (add_tid_to_cgroup(tid, dev_path)) {
if (errno != ESRCH && errno != ENOENT)
return -errno;
}