Scheduling group cleanup - add comment, SP_DEFAULT
Also tid == 0 maps to gettid() on platforms that support it. This is needed by mediaserver code that was formerly using the old C++ API. Change-Id: I8baaa3e42315c9b924cec26b6da01e7cb69e0078
This commit is contained in:
parent
c28cbb2c5a
commit
69bfb1f099
|
@ -21,21 +21,26 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Keep in sync with THREAD_GROUP_* in frameworks/base/core/java/android/os/Process.java */
|
||||
typedef enum {
|
||||
SP_DEFAULT = -1,
|
||||
SP_BACKGROUND = 0,
|
||||
SP_FOREGROUND = 1,
|
||||
SP_CNT,
|
||||
SP_MAX = SP_CNT - 1,
|
||||
SP_SYSTEM_DEFAULT = SP_FOREGROUND,
|
||||
} SchedPolicy;
|
||||
|
||||
/* Assign thread tid to the cgroup associated with the specified policy.
|
||||
* If the thread is a thread group leader, that is it's gettid() == getpid(),
|
||||
* then the other threads in the same thread group are _not_ affected.
|
||||
* On platforms which support gettid(), zero tid means current thread.
|
||||
* Return value: 0 for success, or -errno for error.
|
||||
*/
|
||||
extern int set_sched_policy(int tid, SchedPolicy policy);
|
||||
|
||||
/* Return the policy associated with the cgroup of thread tid via policy pointer.
|
||||
* On platforms which support gettid(), zero tid means current thread.
|
||||
* Return value: 0 for success, or -1 for error and set errno.
|
||||
*/
|
||||
extern int get_sched_policy(int tid, SchedPolicy *policy);
|
||||
|
|
|
@ -189,6 +189,11 @@ static int getSchedulerGroup(int tid, char* buf, size_t bufLen)
|
|||
|
||||
int get_sched_policy(int tid, SchedPolicy *policy)
|
||||
{
|
||||
#ifdef HAVE_GETTID
|
||||
if (tid == 0) {
|
||||
tid = gettid();
|
||||
}
|
||||
#endif
|
||||
pthread_once(&the_once, __initialize);
|
||||
|
||||
if (__sys_supports_schedgroups) {
|
||||
|
@ -219,8 +224,23 @@ int get_sched_policy(int tid, SchedPolicy *policy)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* Re-map SP_DEFAULT to the system default policy, and leave other values unchanged.
|
||||
* Call this any place a SchedPolicy is used as an input parameter.
|
||||
* Returns the possibly re-mapped policy.
|
||||
*/
|
||||
static inline SchedPolicy _policy(SchedPolicy p)
|
||||
{
|
||||
return p == SP_DEFAULT ? SP_SYSTEM_DEFAULT : p;
|
||||
}
|
||||
|
||||
int set_sched_policy(int tid, SchedPolicy policy)
|
||||
{
|
||||
#ifdef HAVE_GETTID
|
||||
if (tid == 0) {
|
||||
tid = gettid();
|
||||
}
|
||||
#endif
|
||||
policy = _policy(policy);
|
||||
pthread_once(&the_once, __initialize);
|
||||
|
||||
#if POLICY_DEBUG
|
||||
|
@ -275,6 +295,7 @@ int set_sched_policy(int tid, SchedPolicy policy)
|
|||
|
||||
const char *get_sched_policy_name(SchedPolicy policy)
|
||||
{
|
||||
policy = _policy(policy);
|
||||
static const char * const strings[SP_CNT] = {
|
||||
[SP_BACKGROUND] = "bg",
|
||||
[SP_FOREGROUND] = "fg",
|
||||
|
|
Loading…
Reference in New Issue