Merge changes from topic 'stune' into nyc-mr1-dev

* changes:
  Add support for top-app stune group.
  Set stune groups from set_sched_policy.
This commit is contained in:
Tim Murray 2016-07-11 20:29:38 +00:00 committed by Android (Google) Code Review
commit 4b75a86858
2 changed files with 29 additions and 4 deletions

View file

@ -66,9 +66,12 @@ static int system_bg_cpuset_fd = -1;
static int bg_cpuset_fd = -1; static int bg_cpuset_fd = -1;
static int fg_cpuset_fd = -1; static int fg_cpuset_fd = -1;
static int ta_cpuset_fd = -1; // special cpuset for top app 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 bg_schedboost_fd = -1;
static int fg_schedboost_fd = -1; static int fg_schedboost_fd = -1;
#endif static int ta_schedboost_fd = -1;
/* Add tid to the scheduling group defined by the policy */ /* Add tid to the scheduling group defined by the policy */
static int add_tid_to_cgroup(int tid, int fd) static int add_tid_to_cgroup(int tid, int fd)
@ -138,6 +141,8 @@ static void __initialize(void) {
ta_cpuset_fd = open(filename, O_WRONLY | O_CLOEXEC); ta_cpuset_fd = open(filename, O_WRONLY | O_CLOEXEC);
#ifdef USE_SCHEDBOOST #ifdef USE_SCHEDBOOST
filename = "/dev/stune/top-app/tasks";
ta_schedboost_fd = open(filename, O_WRONLY | O_CLOEXEC);
filename = "/dev/stune/foreground/tasks"; filename = "/dev/stune/foreground/tasks";
fg_schedboost_fd = open(filename, O_WRONLY | O_CLOEXEC); fg_schedboost_fd = open(filename, O_WRONLY | O_CLOEXEC);
filename = "/dev/stune/tasks"; filename = "/dev/stune/tasks";
@ -294,11 +299,11 @@ int set_cpuset_policy(int tid, SchedPolicy policy)
case SP_AUDIO_APP: case SP_AUDIO_APP:
case SP_AUDIO_SYS: case SP_AUDIO_SYS:
fd = fg_cpuset_fd; fd = fg_cpuset_fd;
boost_fd = bg_schedboost_fd; boost_fd = fg_schedboost_fd;
break; break;
case SP_TOP_APP : case SP_TOP_APP :
fd = ta_cpuset_fd; fd = ta_cpuset_fd;
boost_fd = fg_schedboost_fd; boost_fd = ta_schedboost_fd;
break; break;
case SP_SYSTEM: case SP_SYSTEM:
fd = system_bg_cpuset_fd; fd = system_bg_cpuset_fd;
@ -313,10 +318,12 @@ int set_cpuset_policy(int tid, SchedPolicy policy)
return -errno; return -errno;
} }
#ifdef USE_SCHEDBOOST
if (boost_fd > 0 && add_tid_to_cgroup(tid, boost_fd) != 0) { if (boost_fd > 0 && add_tid_to_cgroup(tid, boost_fd) != 0) {
if (errno != ESRCH && errno != ENOENT) if (errno != ESRCH && errno != ENOENT)
return -errno; return -errno;
} }
#endif
return 0; return 0;
#endif #endif
@ -373,19 +380,26 @@ int set_sched_policy(int tid, SchedPolicy policy)
#endif #endif
if (__sys_supports_schedgroups) { if (__sys_supports_schedgroups) {
int fd; int fd = -1;
int boost_fd = -1;
switch (policy) { switch (policy) {
case SP_BACKGROUND: case SP_BACKGROUND:
fd = bg_cgroup_fd; fd = bg_cgroup_fd;
boost_fd = bg_schedboost_fd;
break; break;
case SP_FOREGROUND: case SP_FOREGROUND:
case SP_AUDIO_APP: case SP_AUDIO_APP:
case SP_AUDIO_SYS: case SP_AUDIO_SYS:
fd = fg_cgroup_fd;
boost_fd = fg_schedboost_fd;
break;
case SP_TOP_APP: case SP_TOP_APP:
fd = fg_cgroup_fd; fd = fg_cgroup_fd;
boost_fd = ta_schedboost_fd;
break; break;
default: default:
fd = -1; fd = -1;
boost_fd = -1;
break; break;
} }
@ -394,6 +408,13 @@ int set_sched_policy(int tid, SchedPolicy policy)
if (errno != ESRCH && errno != ENOENT) if (errno != ESRCH && errno != ENOENT)
return -errno; 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 { } else {
struct sched_param param; struct sched_param param;

View file

@ -50,12 +50,16 @@ on init
mkdir /dev/stune mkdir /dev/stune
mount cgroup none /dev/stune schedtune mount cgroup none /dev/stune schedtune
mkdir /dev/stune/foreground mkdir /dev/stune/foreground
mkdir /dev/stune/top-app
chown system system /dev/stune chown system system /dev/stune
chown system system /dev/stune/foreground chown system system /dev/stune/foreground
chown system system /dev/stune/top-app
chown system system /dev/stune/tasks chown system system /dev/stune/tasks
chown system system /dev/stune/foreground/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/tasks
chmod 0664 /dev/stune/foreground/tasks chmod 0664 /dev/stune/foreground/tasks
chmod 0664 /dev/stune/top-app/tasks
# Mount staging areas for devices managed by vold # Mount staging areas for devices managed by vold
# See storage config details at http://source.android.com/tech/storage/ # See storage config details at http://source.android.com/tech/storage/