am b8bcfed5: am f703b77c: Merge "Add system property to turn off scheduling groups." into gingerbread
Merge commit 'b8bcfed5524a37ee51e3f1129f1df91bc4a59cb4' * commit 'b8bcfed5524a37ee51e3f1129f1df91bc4a59cb4': Add system property to turn off scheduling groups.
This commit is contained in:
commit
3d2bca9abd
@ -21,6 +21,7 @@
|
|||||||
#include <utils/Log.h>
|
#include <utils/Log.h>
|
||||||
|
|
||||||
#include <cutils/sched_policy.h>
|
#include <cutils/sched_policy.h>
|
||||||
|
#include <cutils/properties.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.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.
|
* We create it "detached", so it cleans up after itself.
|
||||||
*/
|
*/
|
||||||
@ -280,6 +281,20 @@ pid_t androidGetTid()
|
|||||||
#endif
|
#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)
|
int androidSetThreadSchedulingGroup(pid_t tid, int grp)
|
||||||
{
|
{
|
||||||
if (grp > ANDROID_TGROUP_MAX || grp < 0) {
|
if (grp > ANDROID_TGROUP_MAX || grp < 0) {
|
||||||
@ -287,10 +302,13 @@ int androidSetThreadSchedulingGroup(pid_t tid, int grp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(HAVE_PTHREADS)
|
#if defined(HAVE_PTHREADS)
|
||||||
|
pthread_once(&gDoSchedulingGroupOnce, checkDoSchedulingGroup);
|
||||||
|
if (gDoSchedulingGroup) {
|
||||||
if (set_sched_policy(tid, (grp == ANDROID_TGROUP_BG_NONINTERACT) ?
|
if (set_sched_policy(tid, (grp == ANDROID_TGROUP_BG_NONINTERACT) ?
|
||||||
SP_BACKGROUND : SP_FOREGROUND)) {
|
SP_BACKGROUND : SP_FOREGROUND)) {
|
||||||
return PERMISSION_DENIED;
|
return PERMISSION_DENIED;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return NO_ERROR;
|
return NO_ERROR;
|
||||||
@ -303,11 +321,14 @@ int androidSetThreadPriority(pid_t tid, int pri)
|
|||||||
#if defined(HAVE_PTHREADS)
|
#if defined(HAVE_PTHREADS)
|
||||||
int lasterr = 0;
|
int lasterr = 0;
|
||||||
|
|
||||||
|
pthread_once(&gDoSchedulingGroupOnce, checkDoSchedulingGroup);
|
||||||
|
if (gDoSchedulingGroup) {
|
||||||
if (pri >= ANDROID_PRIORITY_BACKGROUND) {
|
if (pri >= ANDROID_PRIORITY_BACKGROUND) {
|
||||||
rc = set_sched_policy(tid, SP_BACKGROUND);
|
rc = set_sched_policy(tid, SP_BACKGROUND);
|
||||||
} else if (getpriority(PRIO_PROCESS, tid) >= ANDROID_PRIORITY_BACKGROUND) {
|
} else if (getpriority(PRIO_PROCESS, tid) >= ANDROID_PRIORITY_BACKGROUND) {
|
||||||
rc = set_sched_policy(tid, SP_FOREGROUND);
|
rc = set_sched_policy(tid, SP_FOREGROUND);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (rc) {
|
if (rc) {
|
||||||
lasterr = errno;
|
lasterr = errno;
|
||||||
|
Loading…
Reference in New Issue
Block a user