diff options
Diffstat (limited to 'libcutils/sched_policy.c')
-rw-r--r-- | libcutils/sched_policy.c | 42 |
1 files changed, 20 insertions, 22 deletions
diff --git a/libcutils/sched_policy.c b/libcutils/sched_policy.c index d20d217..d3cedd4 100644 --- a/libcutils/sched_policy.c +++ b/libcutils/sched_policy.c @@ -1,6 +1,4 @@ - -/* libs/cutils/sched_policy.c -** +/* ** Copyright 2007, The Android Open Source Project ** ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,14 +16,17 @@ #define LOG_TAG "SchedPolicy" +#include <errno.h> +#include <fcntl.h> #include <stdio.h> #include <stdlib.h> -#include <unistd.h> #include <string.h> -#include <errno.h> -#include <fcntl.h> +#include <unistd.h> + #include <cutils/sched_policy.h> -#include <cutils/log.h> +#include <log/log.h> + +#define UNUSED __attribute__((__unused__)) /* 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. @@ -38,21 +39,20 @@ static inline SchedPolicy _policy(SchedPolicy p) #if defined(HAVE_ANDROID_OS) && defined(HAVE_SCHED_H) && defined(HAVE_PTHREADS) -#include <sched.h> #include <pthread.h> - -#ifndef SCHED_NORMAL - #define SCHED_NORMAL 0 -#endif - -#ifndef SCHED_BATCH - #define SCHED_BATCH 3 -#endif +#include <sched.h> +#include <sys/prctl.h> #define POLICY_DEBUG 0 #define CAN_SET_SP_SYSTEM 0 // non-zero means to implement set_sched_policy(tid, SP_SYSTEM) +// This prctl is only available in Android kernels. +#define PR_SET_TIMERSLACK_PID 41 + +// timer slack value in nS enforced when the thread moves to background +#define TIMER_SLACK_BG 40000000 + static pthread_once_t the_once = PTHREAD_ONCE_INIT; static int __sys_supports_schedgroups = -1; @@ -221,11 +221,9 @@ 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) { @@ -260,11 +258,9 @@ int get_sched_policy(int tid, SchedPolicy *policy) 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); @@ -324,6 +320,8 @@ int set_sched_policy(int tid, SchedPolicy policy) ¶m); } + prctl(PR_SET_TIMERSLACK_PID, policy == SP_BACKGROUND ? TIMER_SLACK_BG : 0, tid); + return 0; } @@ -331,12 +329,12 @@ int set_sched_policy(int tid, SchedPolicy policy) /* Stubs for non-Android targets. */ -int set_sched_policy(int tid, SchedPolicy policy) +int set_sched_policy(int tid UNUSED, SchedPolicy policy UNUSED) { return 0; } -int get_sched_policy(int tid, SchedPolicy *policy) +int get_sched_policy(int tid UNUSED, SchedPolicy *policy) { *policy = SP_SYSTEM_DEFAULT; return 0; |