From d34fac541a5a541b4207ee9cdbcc5005b5fa848c Mon Sep 17 00:00:00 2001 From: Isaac Chen Date: Thu, 16 Feb 2017 11:51:08 +0800 Subject: [PATCH] Turned ENABLE_CPUSETS into runtime decision. ENABLE_CPUSETS is usually set in BoardConfig.mk to use CONFIG_CPUSETS feature of Linux kernel. This change turns the build time variable into runtime decision by checking if a special file, "tasks", can be found under the mount point, /dev/cpuset, for cpusets. Bug: 34726944 Test: Tested on Sailfish without cpuset mounted with cpuset mounted, but without schedtune mounted with cpuset mounted and with schedtune mounted Change-Id: I1c044c3c9d4d15360a1605e7022da84d94df4014 --- core/jni/android_util_Process.cpp | 58 +++++++++++++++---------------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/core/jni/android_util_Process.cpp b/core/jni/android_util_Process.cpp index b57f2362a2846..a03d3c503e1c3 100644 --- a/core/jni/android_util_Process.cpp +++ b/core/jni/android_util_Process.cpp @@ -252,25 +252,26 @@ void android_os_Process_setProcessGroup(JNIEnv* env, jobject clazz, int pid, jin if (t_pri >= ANDROID_PRIORITY_BACKGROUND) { // This task wants to stay at background // update its cpuset so it doesn't only run on bg core(s) -#ifdef ENABLE_CPUSETS - int err = set_cpuset_policy(t_pid, sp); - if (err != NO_ERROR) { - signalExceptionForGroupError(env, -err, t_pid); - break; + if (cpusets_enabled()) { + int err = set_cpuset_policy(t_pid, sp); + if (err != NO_ERROR) { + signalExceptionForGroupError(env, -err, t_pid); + break; + } } -#endif continue; } } int err; -#ifdef ENABLE_CPUSETS - // set both cpuset and cgroup for general threads - err = set_cpuset_policy(t_pid, sp); - if (err != NO_ERROR) { - signalExceptionForGroupError(env, -err, t_pid); - break; + + if (cpusets_enabled()) { + // set both cpuset and cgroup for general threads + err = set_cpuset_policy(t_pid, sp); + if (err != NO_ERROR) { + signalExceptionForGroupError(env, -err, t_pid); + break; + } } -#endif err = set_sched_policy(t_pid, sp); if (err != NO_ERROR) { @@ -291,7 +292,6 @@ jint android_os_Process_getProcessGroup(JNIEnv* env, jobject clazz, jint pid) return (int) sp; } -#ifdef ENABLE_CPUSETS /** Sample CPUset list format: * 0-3,4,6-8 */ @@ -367,7 +367,6 @@ static void get_cpuset_cores_for_policy(SchedPolicy policy, cpu_set_t *cpu_set) } return; } -#endif /** @@ -376,22 +375,21 @@ static void get_cpuset_cores_for_policy(SchedPolicy policy, cpu_set_t *cpu_set) * them in the passed in cpu_set_t */ void get_exclusive_cpuset_cores(SchedPolicy policy, cpu_set_t *cpu_set) { -#ifdef ENABLE_CPUSETS - int i; - cpu_set_t tmp_set; - get_cpuset_cores_for_policy(policy, cpu_set); - for (i = 0; i < SP_CNT; i++) { - if ((SchedPolicy) i == policy) continue; - get_cpuset_cores_for_policy((SchedPolicy)i, &tmp_set); - // First get cores exclusive to one set or the other - CPU_XOR(&tmp_set, cpu_set, &tmp_set); - // Then get the ones only in cpu_set - CPU_AND(cpu_set, cpu_set, &tmp_set); + if (cpusets_enabled()) { + int i; + cpu_set_t tmp_set; + get_cpuset_cores_for_policy(policy, cpu_set); + for (i = 0; i < SP_CNT; i++) { + if ((SchedPolicy) i == policy) continue; + get_cpuset_cores_for_policy((SchedPolicy)i, &tmp_set); + // First get cores exclusive to one set or the other + CPU_XOR(&tmp_set, cpu_set, &tmp_set); + // Then get the ones only in cpu_set + CPU_AND(cpu_set, cpu_set, &tmp_set); + } + } else { + CPU_ZERO(cpu_set); } -#else - (void) policy; - CPU_ZERO(cpu_set); -#endif return; }