• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 #pragma once
18 
19 #include <stdbool.h>
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 /*
26  * Check if Linux kernel enables CPUSETS feature.
27  *
28  * Return value: 1 if Linux kernel CONFIG_CPUSETS=y; 0 otherwise.
29  */
30 extern bool cpusets_enabled();
31 
32 /* Keep in sync with THREAD_GROUP_* in frameworks/base/core/java/android/os/Process.java */
33 typedef enum {
34     SP_DEFAULT = -1,
35     SP_BACKGROUND = 0,
36     SP_FOREGROUND = 1,
37     SP_SYSTEM = 2,
38     SP_AUDIO_APP = 3,
39     SP_AUDIO_SYS = 4,
40     SP_TOP_APP = 5,
41     SP_RT_APP = 6,
42     SP_RESTRICTED = 7,
43     SP_FOREGROUND_WINDOW = 8,
44     SP_CNT,
45     SP_MAX = SP_CNT - 1,
46     SP_SYSTEM_DEFAULT = SP_FOREGROUND,
47 } SchedPolicy;
48 
49 extern int set_cpuset_policy(int tid, SchedPolicy policy);
50 
51 /* Assign thread tid to the cgroup associated with the specified policy.
52  * If the thread is a thread group leader, that is it's gettid() == getpid(),
53  * then the other threads in the same thread group are _not_ affected.
54  * On platforms which support gettid(), zero tid means current thread.
55  * Return value: 0 for success, or -errno for error.
56  */
57 extern int set_sched_policy(int tid, SchedPolicy policy);
58 
59 /* Return the policy associated with the cgroup of thread tid via policy pointer.
60  * On platforms which support gettid(), zero tid means current thread.
61  * Return value: 0 for success, or -1 for error and set errno.
62  */
63 extern int get_sched_policy(int tid, SchedPolicy* policy);
64 
65 /* Return a displayable string corresponding to policy.
66  * Return value: NUL-terminated name of unspecified length, nullptr if invalid;
67  * the caller is responsible for displaying the useful part of the string.
68  */
69 extern const char* get_sched_policy_name(SchedPolicy policy);
70 
71 /* Return the aggregated task profile name corresponding to cpuset policy.
72  * Return value: NUL-terminated name of unspecified length, nullptr if invalid;
73  * the caller could use it to call SetTaskProfiles.
74  */
75 extern const char* get_cpuset_policy_profile_name(SchedPolicy policy);
76 
77 /* Return the aggregated task profile name corresponding to sched policy.
78  * Return value: NUL-terminated name of unspecified length, nullptr if invalid;
79  * the caller could use it to call SetTaskProfiles.
80  */
81 extern const char* get_sched_policy_profile_name(SchedPolicy policy);
82 #ifdef __cplusplus
83 }
84 #endif
85