• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __CUTILS_SCHED_POLICY_H
18 #define __CUTILS_SCHED_POLICY_H
19 
20 #include <stdbool.h>
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 /*
27  * Check if Linux kernel enables CPUSETS feature.
28  *
29  * Return value: 1 if Linux kernel CONFIG_CPUSETS=y; 0 otherwise.
30  */
31 extern bool cpusets_enabled();
32 
33 /*
34  * Check if Linux kernel enables SCHEDTUNE feature (only available in Android
35  * common kernel or Linaro LSK, not in mainline Linux as of v4.9)
36  *
37  * Return value: 1 if Linux kernel CONFIG_SCHEDTUNE=y; 0 otherwise.
38  */
39 extern bool schedboost_enabled();
40 
41 /* Keep in sync with THREAD_GROUP_* in frameworks/base/core/java/android/os/Process.java */
42 typedef enum {
43     SP_DEFAULT    = -1,
44     SP_BACKGROUND = 0,
45     SP_FOREGROUND = 1,
46     SP_SYSTEM     = 2,  // can't be used with set_sched_policy()
47     SP_AUDIO_APP  = 3,
48     SP_AUDIO_SYS  = 4,
49     SP_TOP_APP    = 5,
50     SP_CNT,
51     SP_MAX        = SP_CNT - 1,
52     SP_SYSTEM_DEFAULT = SP_FOREGROUND,
53 } SchedPolicy;
54 
55 extern int set_cpuset_policy(int tid, SchedPolicy policy);
56 
57 /* Assign thread tid to the cgroup associated with the specified policy.
58  * If the thread is a thread group leader, that is it's gettid() == getpid(),
59  * then the other threads in the same thread group are _not_ affected.
60  * On platforms which support gettid(), zero tid means current thread.
61  * Return value: 0 for success, or -errno for error.
62  */
63 extern int set_sched_policy(int tid, SchedPolicy policy);
64 
65 /* Return the policy associated with the cgroup of thread tid via policy pointer.
66  * On platforms which support gettid(), zero tid means current thread.
67  * Return value: 0 for success, or -1 for error and set errno.
68  */
69 extern int get_sched_policy(int tid, SchedPolicy *policy);
70 
71 /* Return a displayable string corresponding to policy.
72  * Return value: non-NULL NUL-terminated name of unspecified length;
73  * the caller is responsible for displaying the useful part of the string.
74  */
75 extern const char *get_sched_policy_name(SchedPolicy policy);
76 
77 #ifdef __cplusplus
78 }
79 #endif
80 
81 #endif /* __CUTILS_SCHED_POLICY_H */
82