diff options
author | Dianne Hackborn <hackbod@google.com> | 2010-09-03 17:07:07 -0700 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2010-09-07 11:19:11 -0700 |
commit | 84bb52ed614f3a13370c923a8bc2a8b7c6db8d30 (patch) | |
tree | 343bb945db493f71b75b55f99ed1da0a8424d4c3 /libs/utils | |
parent | 69717ccd13bb5568b912701ab39d603cfa7091cc (diff) | |
download | frameworks_base-84bb52ed614f3a13370c923a8bc2a8b7c6db8d30.zip frameworks_base-84bb52ed614f3a13370c923a8bc2a8b7c6db8d30.tar.gz frameworks_base-84bb52ed614f3a13370c923a8bc2a8b7c6db8d30.tar.bz2 |
Add system property to turn off scheduling groups.
Do this:
adb shell setprop debug.sys.noschedgroups 1
Change-Id: I6e06a74205fd45ee1526ce71fe33944465d39984
Diffstat (limited to 'libs/utils')
-rw-r--r-- | libs/utils/Threads.cpp | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/libs/utils/Threads.cpp b/libs/utils/Threads.cpp index 2b1f490..c8de1f5 100644 --- a/libs/utils/Threads.cpp +++ b/libs/utils/Threads.cpp @@ -21,6 +21,7 @@ #include <utils/Log.h> #include <cutils/sched_policy.h> +#include <cutils/properties.h> #include <stdio.h> #include <stdlib.h> @@ -57,7 +58,7 @@ using namespace android; // ---------------------------------------------------------------------------- /* - * Create and run a new thead. + * Create and run a new thread. * * We create it "detached", so it cleans up after itself. */ @@ -280,6 +281,20 @@ pid_t androidGetTid() #endif } +static pthread_once_t gDoSchedulingGroupOnce = PTHREAD_ONCE_INIT; +static bool gDoSchedulingGroup = true; + +static void checkDoSchedulingGroup(void) { + char buf[PROPERTY_VALUE_MAX]; + int len = property_get("debug.sys.noschedgroups", buf, ""); + if (len > 0) { + int temp; + if (sscanf(buf, "%d", &temp) == 1) { + gDoSchedulingGroup = temp == 0; + } + } +} + int androidSetThreadSchedulingGroup(pid_t tid, int grp) { if (grp > ANDROID_TGROUP_MAX || grp < 0) { @@ -287,9 +302,12 @@ int androidSetThreadSchedulingGroup(pid_t tid, int grp) } #if defined(HAVE_PTHREADS) - if (set_sched_policy(tid, (grp == ANDROID_TGROUP_BG_NONINTERACT) ? - SP_BACKGROUND : SP_FOREGROUND)) { - return PERMISSION_DENIED; + pthread_once(&gDoSchedulingGroupOnce, checkDoSchedulingGroup); + if (gDoSchedulingGroup) { + if (set_sched_policy(tid, (grp == ANDROID_TGROUP_BG_NONINTERACT) ? + SP_BACKGROUND : SP_FOREGROUND)) { + return PERMISSION_DENIED; + } } #endif @@ -303,10 +321,13 @@ int androidSetThreadPriority(pid_t tid, int pri) #if defined(HAVE_PTHREADS) int lasterr = 0; - if (pri >= ANDROID_PRIORITY_BACKGROUND) { - rc = set_sched_policy(tid, SP_BACKGROUND); - } else if (getpriority(PRIO_PROCESS, tid) >= ANDROID_PRIORITY_BACKGROUND) { - rc = set_sched_policy(tid, SP_FOREGROUND); + pthread_once(&gDoSchedulingGroupOnce, checkDoSchedulingGroup); + if (gDoSchedulingGroup) { + if (pri >= ANDROID_PRIORITY_BACKGROUND) { + rc = set_sched_policy(tid, SP_BACKGROUND); + } else if (getpriority(PRIO_PROCESS, tid) >= ANDROID_PRIORITY_BACKGROUND) { + rc = set_sched_policy(tid, SP_FOREGROUND); + } } if (rc) { |