From 6647bb51301ea101b73e7431888f70bb35a4fabb Mon Sep 17 00:00:00 2001 From: Tim Murray Date: Mon, 11 Jan 2016 16:16:35 -0800 Subject: [PATCH] Enable top-app cpuset support. Allows ActivityManager to use the top-app cpuset to grant the currently focused app exclusive access to a CPU core. Change-Id: I45bca5170477e413dec6e5889338399d0859706c --- include/cutils/sched_policy.h | 1 + libcutils/sched_policy.c | 10 ++++++++++ rootdir/init.rc | 7 +++++++ 3 files changed, 18 insertions(+) diff --git a/include/cutils/sched_policy.h b/include/cutils/sched_policy.h index 6a8d570b2..591bd4478 100644 --- a/include/cutils/sched_policy.h +++ b/include/cutils/sched_policy.h @@ -29,6 +29,7 @@ typedef enum { SP_SYSTEM = 2, // can't be used with set_sched_policy() SP_AUDIO_APP = 3, SP_AUDIO_SYS = 4, + SP_TOP_APP = 5, 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 280a0834b..54d112290 100644 --- a/libcutils/sched_policy.c +++ b/libcutils/sched_policy.c @@ -65,6 +65,7 @@ static int fg_cgroup_fd = -1; static int system_bg_cpuset_fd = -1; static int bg_cpuset_fd = -1; static int fg_cpuset_fd = -1; +static int ta_cpuset_fd = -1; // special cpuset for top app static int bg_schedboost_fd = -1; static int fg_schedboost_fd = -1; #endif @@ -133,6 +134,8 @@ static void __initialize(void) { bg_cpuset_fd = open(filename, O_WRONLY | O_CLOEXEC); filename = "/dev/cpuset/system-background/tasks"; system_bg_cpuset_fd = open(filename, O_WRONLY | O_CLOEXEC); + filename = "/dev/cpuset/top-app/tasks"; + ta_cpuset_fd = open(filename, O_WRONLY | O_CLOEXEC); #ifdef USE_SCHEDBOOST filename = "/sys/fs/cgroup/stune/foreground/tasks"; @@ -276,6 +279,10 @@ int set_cpuset_policy(int tid, SchedPolicy policy) fd = fg_cpuset_fd; boost_fd = fg_schedboost_fd; break; + case SP_TOP_APP : + fd = ta_cpuset_fd; + boost_fd = fg_schedboost_fd; + break; case SP_SYSTEM: fd = system_bg_cpuset_fd; boost_fd = bg_schedboost_fd; @@ -337,6 +344,7 @@ int set_sched_policy(int tid, SchedPolicy policy) case SP_FOREGROUND: case SP_AUDIO_APP: case SP_AUDIO_SYS: + case SP_TOP_APP: SLOGD("^^^ tid %d (%s)", tid, thread_name); break; case SP_SYSTEM: @@ -357,6 +365,7 @@ int set_sched_policy(int tid, SchedPolicy policy) case SP_FOREGROUND: case SP_AUDIO_APP: case SP_AUDIO_SYS: + case SP_TOP_APP: fd = fg_cgroup_fd; break; default: @@ -411,6 +420,7 @@ const char *get_sched_policy_name(SchedPolicy policy) [SP_SYSTEM] = " ", [SP_AUDIO_APP] = "aa", [SP_AUDIO_SYS] = "as", + [SP_TOP_APP] = "ta", }; if ((policy < SP_CNT) && (strings[policy] != NULL)) return strings[policy]; diff --git a/rootdir/init.rc b/rootdir/init.rc index 289bdec7f..1b367c79f 100644 --- a/rootdir/init.rc +++ b/rootdir/init.rc @@ -173,17 +173,23 @@ on init write /dev/cpuset/system-background/cpus 0 write /dev/cpuset/system-background/mems 0 + mkdir /dev/cpuset/top-app + write /dev/cpuset/top-app/cpus 0 + write /dev/cpuset/top-app/mems 0 + # change permissions for all cpusets we'll touch at runtime chown system system /dev/cpuset chown system system /dev/cpuset/foreground chown system system /dev/cpuset/foreground/boost chown system system /dev/cpuset/background chown system system /dev/cpuset/system-background + chown system system /dev/cpuset/top-app chown system system /dev/cpuset/tasks chown system system /dev/cpuset/foreground/tasks chown system system /dev/cpuset/foreground/boost/tasks chown system system /dev/cpuset/background/tasks chown system system /dev/cpuset/system-background/tasks + chown system system /dev/cpuset/top-app/tasks # set system-background to 0775 so SurfaceFlinger can touch it chmod 0775 /dev/cpuset/system-background @@ -192,6 +198,7 @@ on init chmod 0664 /dev/cpuset/foreground/boost/tasks chmod 0664 /dev/cpuset/background/tasks chmod 0664 /dev/cpuset/system-background/tasks + chmod 0664 /dev/cpuset/top-app/tasks chmod 0664 /dev/cpuset/tasks