diff options
-rw-r--r-- | include/cutils/sched_policy.h | 3 | ||||
-rw-r--r-- | libcutils/sched_policy.c | 94 | ||||
-rw-r--r-- | rootdir/init.rc | 36 |
3 files changed, 112 insertions, 21 deletions
diff --git a/include/cutils/sched_policy.h b/include/cutils/sched_policy.h index c6e4fc4..ba84ce3 100644 --- a/include/cutils/sched_policy.h +++ b/include/cutils/sched_policy.h @@ -26,6 +26,9 @@ typedef enum { SP_DEFAULT = -1, SP_BACKGROUND = 0, SP_FOREGROUND = 1, + SP_SYSTEM = 2, // can't be used with set_sched_policy() + SP_AUDIO_APP = 3, + SP_AUDIO_SYS = 4, SP_CNT, SP_MAX = SP_CNT - 1, SP_SYSTEM_DEFAULT = SP_FOREGROUND, diff --git a/libcutils/sched_policy.c b/libcutils/sched_policy.c index 345532b..20771c0 100644 --- a/libcutils/sched_policy.c +++ b/libcutils/sched_policy.c @@ -44,28 +44,51 @@ #define POLICY_DEBUG 0 +#define CAN_SET_SP_SYSTEM 0 // non-zero means to implement set_sched_policy(tid, SP_SYSTEM) + 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 normal_cgroup_fd = -1; static int bg_cgroup_fd = -1; +static int fg_cgroup_fd = -1; +#if CAN_SET_SP_SYSTEM +static int system_cgroup_fd = -1; +#endif +static int audio_app_cgroup_fd = -1; +static int audio_sys_cgroup_fd = -1; /* Add tid to the scheduling group defined by the policy */ static int add_tid_to_cgroup(int tid, SchedPolicy policy) { int fd; - if (policy == SP_BACKGROUND) { + switch (policy) { + case SP_BACKGROUND: fd = bg_cgroup_fd; - } else { - fd = normal_cgroup_fd; + break; + case SP_FOREGROUND: + fd = fg_cgroup_fd; + break; +#if CAN_SET_SP_SYSTEM + case SP_SYSTEM: + fd = system_cgroup_fd; + break; +#endif + case SP_AUDIO_APP: + fd = audio_app_cgroup_fd; + break; + case SP_AUDIO_SYS: + fd = audio_sys_cgroup_fd; + break; + default: + fd = -1; + break; } if (fd < 0) { - SLOGE("add_tid_to_cgroup failed; background=%d\n", - policy == SP_BACKGROUND ? 1 : 0); + SLOGE("add_tid_to_cgroup failed; policy=%d\n", policy); return -1; } @@ -86,8 +109,8 @@ static int add_tid_to_cgroup(int tid, SchedPolicy policy) */ if (errno == ESRCH) return 0; - SLOGW("add_tid_to_cgroup failed to write '%s' (%s); background=%d\n", - ptr, strerror(errno), policy == SP_BACKGROUND ? 1 : 0); + SLOGW("add_tid_to_cgroup failed to write '%s' (%s); policy=%d\n", + ptr, strerror(errno), policy); return -1; } @@ -99,9 +122,17 @@ static void __initialize(void) { if (!access("/dev/cpuctl/tasks", F_OK)) { __sys_supports_schedgroups = 1; +#if CAN_SET_SP_SYSTEM filename = "/dev/cpuctl/tasks"; - normal_cgroup_fd = open(filename, O_WRONLY); - if (normal_cgroup_fd < 0) { + system_cgroup_fd = open(filename, O_WRONLY); + if (system_cgroup_fd < 0) { + SLOGV("open of %s failed: %s\n", filename, strerror(errno)); + } +#endif + + filename = "/dev/cpuctl/foreground/tasks"; + fg_cgroup_fd = open(filename, O_WRONLY); + if (fg_cgroup_fd < 0) { SLOGE("open of %s failed: %s\n", filename, strerror(errno)); } @@ -110,6 +141,19 @@ static void __initialize(void) { if (bg_cgroup_fd < 0) { SLOGE("open of %s failed: %s\n", filename, strerror(errno)); } + + filename = "/dev/cpuctl/audio_app/tasks"; + audio_app_cgroup_fd = open(filename, O_WRONLY); + if (audio_app_cgroup_fd < 0) { + SLOGV("open of %s failed: %s\n", filename, strerror(errno)); + } + + filename = "/dev/cpuctl/audio_sys/tasks"; + audio_sys_cgroup_fd = open(filename, O_WRONLY); + if (audio_sys_cgroup_fd < 0) { + SLOGV("open of %s failed: %s\n", filename, strerror(errno)); + } + } else { __sys_supports_schedgroups = 0; } @@ -201,9 +245,15 @@ int get_sched_policy(int tid, SchedPolicy *policy) if (getSchedulerGroup(tid, grpBuf, sizeof(grpBuf)) < 0) return -1; if (grpBuf[0] == '\0') { - *policy = SP_FOREGROUND; + *policy = SP_SYSTEM; } else if (!strcmp(grpBuf, "bg_non_interactive")) { *policy = SP_BACKGROUND; + } else if (!strcmp(grpBuf, "foreground")) { + *policy = SP_FOREGROUND; + } else if (!strcmp(grpBuf, "audio_app")) { + *policy = SP_AUDIO_APP; + } else if (!strcmp(grpBuf, "audio_sys")) { + *policy = SP_AUDIO_SYS; } else { errno = ERANGE; return -1; @@ -266,12 +316,25 @@ int set_sched_policy(int tid, SchedPolicy policy) strncpy(thread_name, p, (q-p)); } - if (policy == SP_BACKGROUND) { + switch (policy) { + case SP_BACKGROUND: SLOGD("vvv tid %d (%s)", tid, thread_name); - } else if (policy == SP_FOREGROUND) { + break; + case SP_FOREGROUND: SLOGD("^^^ tid %d (%s)", tid, thread_name); - } else { + break; + case SP_SYSTEM: + SLOGD("/// tid %d (%s)", tid, thread_name); + break; + case SP_AUDIO_APP: + SLOGD("aaa tid %d (%s)", tid, thread_name); + break; + case SP_AUDIO_SYS: + SLOGD("sss tid %d (%s)", tid, thread_name); + break; + default: SLOGD("??? tid %d (%s)", tid, thread_name); + break; } #endif @@ -299,6 +362,9 @@ const char *get_sched_policy_name(SchedPolicy policy) static const char * const strings[SP_CNT] = { [SP_BACKGROUND] = "bg", [SP_FOREGROUND] = "fg", + [SP_SYSTEM] = " ", + [SP_AUDIO_APP] = "aa", + [SP_AUDIO_SYS] = "as", }; if ((policy < SP_CNT) && (strings[policy] != NULL)) return strings[policy]; diff --git a/rootdir/init.rc b/rootdir/init.rc index 69b8e44..212edf4 100644 --- a/rootdir/init.rc +++ b/rootdir/init.rc @@ -80,25 +80,47 @@ loglevel 3 write /proc/sys/kernel/kptr_restrict 2 write /proc/sys/kernel/dmesg_restrict 1 write /proc/sys/vm/mmap_min_addr 32768 + write /proc/sys/kernel/sched_rt_runtime_us 950000 + write /proc/sys/kernel/sched_rt_period_us 1000000 # Create cgroup mount points for process groups mkdir /dev/cpuctl mount cgroup none /dev/cpuctl cpu chown system system /dev/cpuctl chown system system /dev/cpuctl/tasks - chmod 0777 /dev/cpuctl/tasks + chmod 0660 /dev/cpuctl/tasks write /dev/cpuctl/cpu.shares 1024 + write /dev/cpuctl/cpu.rt_runtime_us 950000 + write /dev/cpuctl/cpu.rt_period_us 1000000 - mkdir /dev/cpuctl/fg_boost - chown system system /dev/cpuctl/fg_boost/tasks - chmod 0777 /dev/cpuctl/fg_boost/tasks - write /dev/cpuctl/fg_boost/cpu.shares 1024 + mkdir /dev/cpuctl/foreground + chown system system /dev/cpuctl/foreground/tasks + chmod 0666 /dev/cpuctl/foreground/tasks + write /dev/cpuctl/foreground/cpu.shares 1024 + write /dev/cpuctl/foreground/cpu.rt_runtime_us 0 + write /dev/cpuctl/foreground/cpu.rt_period_us 1000000 mkdir /dev/cpuctl/bg_non_interactive chown system system /dev/cpuctl/bg_non_interactive/tasks - chmod 0777 /dev/cpuctl/bg_non_interactive/tasks + chmod 0666 /dev/cpuctl/bg_non_interactive/tasks # 5.0 % write /dev/cpuctl/bg_non_interactive/cpu.shares 52 + write /dev/cpuctl/bg_non_interactive/cpu.rt_runtime_us 0 + write /dev/cpuctl/bg_non_interactive/cpu.rt_period_us 1000000 + + mkdir /dev/cpuctl/audio_app + chown system system /dev/cpuctl/audio_app/tasks + chmod 0660 /dev/cpuctl/audio_app/tasks + write /dev/cpuctl/audio_app/cpu.shares 10 + write /dev/cpuctl/audio_app/cpu.rt_runtime_us 50000 + write /dev/cpuctl/audio_app/cpu.rt_period_us 1000000 + + mkdir /dev/cpuctl/audio_sys + chown system system /dev/cpuctl/audio_sys/tasks + chmod 0660 /dev/cpuctl/audio_sys/tasks + write /dev/cpuctl/audio_sys/cpu.shares 10 + write /dev/cpuctl/audio_sys/cpu.rt_runtime_us 50000 + write /dev/cpuctl/audio_sys/cpu.rt_period_us 1000000 # Allow everybody to read the xt_qtaguid resource tracking misc dev. # This is needed by any process that uses socket tagging. @@ -213,7 +235,7 @@ on boot # Memory management. Basic kernel parameters, and allow the high # level system server to be able to adjust the kernel OOM driver -# paramters to match how it is managing things. +# parameters to match how it is managing things. write /proc/sys/vm/overcommit_memory 1 write /proc/sys/vm/min_free_order_shift 4 chown root system /sys/module/lowmemorykiller/parameters/adj |