From aa45cb85e3d5d7f717feab6fe421ef377301c559 Mon Sep 17 00:00:00 2001 From: Tim Murray Date: Fri, 8 Jul 2016 15:47:11 -0700 Subject: [PATCH 1/2] Set stune groups from set_sched_policy. bug 29512132 Change-Id: Ib4176b80787db9e7ace9468cbf670f05cc428786 --- libcutils/sched_policy.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/libcutils/sched_policy.c b/libcutils/sched_policy.c index ac12f2eab..ff38e50c6 100644 --- a/libcutils/sched_policy.c +++ b/libcutils/sched_policy.c @@ -66,9 +66,11 @@ 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 +#endif + +// File descriptors open to /dev/stune/../tasks, setup by initialize, or -1 on error static int bg_schedboost_fd = -1; static int fg_schedboost_fd = -1; -#endif /* Add tid to the scheduling group defined by the policy */ static int add_tid_to_cgroup(int tid, int fd) @@ -313,10 +315,12 @@ int set_cpuset_policy(int tid, SchedPolicy policy) return -errno; } +#ifdef USE_SCHEDBOOST if (boost_fd > 0 && add_tid_to_cgroup(tid, boost_fd) != 0) { if (errno != ESRCH && errno != ENOENT) return -errno; } +#endif return 0; #endif @@ -373,19 +377,26 @@ int set_sched_policy(int tid, SchedPolicy policy) #endif if (__sys_supports_schedgroups) { - int fd; + int fd = -1; + int boost_fd = -1; switch (policy) { case SP_BACKGROUND: fd = bg_cgroup_fd; + boost_fd = bg_schedboost_fd; break; case SP_FOREGROUND: case SP_AUDIO_APP: case SP_AUDIO_SYS: + fd = fg_cgroup_fd; + boost_fd = bg_schedboost_fd; + break; case SP_TOP_APP: fd = fg_cgroup_fd; + boost_fd = fg_schedboost_fd; break; default: fd = -1; + boost_fd = -1; break; } @@ -394,6 +405,13 @@ int set_sched_policy(int tid, SchedPolicy policy) if (errno != ESRCH && errno != ENOENT) return -errno; } + +#ifdef USE_SCHEDBOOST + if (boost_fd > 0 && add_tid_to_cgroup(tid, boost_fd) != 0) { + if (errno != ESRCH && errno != ENOENT) + return -errno; + } +#endif } else { struct sched_param param; From 955694b657012c50312de99e6f78084beae52d60 Mon Sep 17 00:00:00 2001 From: Tim Murray Date: Mon, 11 Jul 2016 11:40:15 -0700 Subject: [PATCH 2/2] Add support for top-app stune group. bug 29512132 Change-Id: I41ec2dd80a469309f48dbb59fc27fbe43fcd67b3 --- libcutils/sched_policy.c | 11 +++++++---- rootdir/init.rc | 4 ++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/libcutils/sched_policy.c b/libcutils/sched_policy.c index ff38e50c6..c097a1215 100644 --- a/libcutils/sched_policy.c +++ b/libcutils/sched_policy.c @@ -71,6 +71,7 @@ static int ta_cpuset_fd = -1; // special cpuset for top app // File descriptors open to /dev/stune/../tasks, setup by initialize, or -1 on error static int bg_schedboost_fd = -1; static int fg_schedboost_fd = -1; +static int ta_schedboost_fd = -1; /* Add tid to the scheduling group defined by the policy */ static int add_tid_to_cgroup(int tid, int fd) @@ -140,6 +141,8 @@ static void __initialize(void) { ta_cpuset_fd = open(filename, O_WRONLY | O_CLOEXEC); #ifdef USE_SCHEDBOOST + filename = "/dev/stune/top-app/tasks"; + ta_schedboost_fd = open(filename, O_WRONLY | O_CLOEXEC); filename = "/dev/stune/foreground/tasks"; fg_schedboost_fd = open(filename, O_WRONLY | O_CLOEXEC); filename = "/dev/stune/tasks"; @@ -296,11 +299,11 @@ int set_cpuset_policy(int tid, SchedPolicy policy) case SP_AUDIO_APP: case SP_AUDIO_SYS: fd = fg_cpuset_fd; - boost_fd = bg_schedboost_fd; + boost_fd = fg_schedboost_fd; break; case SP_TOP_APP : fd = ta_cpuset_fd; - boost_fd = fg_schedboost_fd; + boost_fd = ta_schedboost_fd; break; case SP_SYSTEM: fd = system_bg_cpuset_fd; @@ -388,11 +391,11 @@ int set_sched_policy(int tid, SchedPolicy policy) case SP_AUDIO_APP: case SP_AUDIO_SYS: fd = fg_cgroup_fd; - boost_fd = bg_schedboost_fd; + boost_fd = fg_schedboost_fd; break; case SP_TOP_APP: fd = fg_cgroup_fd; - boost_fd = fg_schedboost_fd; + boost_fd = ta_schedboost_fd; break; default: fd = -1; diff --git a/rootdir/init.rc b/rootdir/init.rc index da3b98b87..32970e434 100644 --- a/rootdir/init.rc +++ b/rootdir/init.rc @@ -50,12 +50,16 @@ on init mkdir /dev/stune mount cgroup none /dev/stune schedtune mkdir /dev/stune/foreground + mkdir /dev/stune/top-app chown system system /dev/stune chown system system /dev/stune/foreground + chown system system /dev/stune/top-app chown system system /dev/stune/tasks chown system system /dev/stune/foreground/tasks + chown system system /dev/stune/top-app/tasks chmod 0664 /dev/stune/tasks chmod 0664 /dev/stune/foreground/tasks + chmod 0664 /dev/stune/top-app/tasks # Mount staging areas for devices managed by vold # See storage config details at http://source.android.com/tech/storage/