Mark Salyzyn | 1271716 | 2014-04-29 15:49:14 -0700 | [diff] [blame] | 1 | /* |
San Mehat | 493dad9 | 2009-09-12 10:06:57 -0700 | [diff] [blame] | 2 | ** Copyright 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 | |
Jeff Brown | bff8f3f | 2012-05-08 15:05:42 -0700 | [diff] [blame] | 17 | #define LOG_TAG "SchedPolicy" |
| 18 | |
San Mehat | 493dad9 | 2009-09-12 10:06:57 -0700 | [diff] [blame] | 19 | #include <errno.h> |
| 20 | #include <fcntl.h> |
Mark Salyzyn | 1271716 | 2014-04-29 15:49:14 -0700 | [diff] [blame] | 21 | #include <stdio.h> |
| 22 | #include <stdlib.h> |
| 23 | #include <string.h> |
| 24 | #include <unistd.h> |
| 25 | |
Jeff Brown | bff8f3f | 2012-05-08 15:05:42 -0700 | [diff] [blame] | 26 | #include <cutils/sched_policy.h> |
Mark Salyzyn | 1271716 | 2014-04-29 15:49:14 -0700 | [diff] [blame] | 27 | #include <log/log.h> |
| 28 | |
| 29 | #define UNUSED __attribute__((__unused__)) |
Raphael | 0384a98 | 2009-09-15 17:10:17 -0700 | [diff] [blame] | 30 | |
Jeff Brown | bff8f3f | 2012-05-08 15:05:42 -0700 | [diff] [blame] | 31 | /* Re-map SP_DEFAULT to the system default policy, and leave other values unchanged. |
| 32 | * Call this any place a SchedPolicy is used as an input parameter. |
| 33 | * Returns the possibly re-mapped policy. |
| 34 | */ |
| 35 | static inline SchedPolicy _policy(SchedPolicy p) |
| 36 | { |
| 37 | return p == SP_DEFAULT ? SP_SYSTEM_DEFAULT : p; |
| 38 | } |
San Mehat | d2e4e46 | 2009-10-29 11:48:00 -0700 | [diff] [blame] | 39 | |
Jeff Brown | bff8f3f | 2012-05-08 15:05:42 -0700 | [diff] [blame] | 40 | #if defined(HAVE_ANDROID_OS) && defined(HAVE_SCHED_H) && defined(HAVE_PTHREADS) |
Raphael | 0384a98 | 2009-09-15 17:10:17 -0700 | [diff] [blame] | 41 | |
Brad Fitzpatrick | 86b1215 | 2010-05-08 11:51:13 -0700 | [diff] [blame] | 42 | #include <pthread.h> |
Elliott Hughes | e07d77e | 2014-07-11 20:57:03 -0700 | [diff] [blame] | 43 | #include <sched.h> |
| 44 | #include <sys/prctl.h> |
San Mehat | 3cd5b66 | 2009-09-14 16:05:24 -0700 | [diff] [blame] | 45 | |
San Mehat | 805d67a | 2009-10-29 13:56:26 -0700 | [diff] [blame] | 46 | #define POLICY_DEBUG 0 |
San Mehat | d2e4e46 | 2009-10-29 11:48:00 -0700 | [diff] [blame] | 47 | |
Glenn Kasten | 10ec3c7 | 2012-04-19 15:25:58 -0700 | [diff] [blame] | 48 | #define CAN_SET_SP_SYSTEM 0 // non-zero means to implement set_sched_policy(tid, SP_SYSTEM) |
| 49 | |
Elliott Hughes | 400c381 | 2014-07-17 17:15:14 -0700 | [diff] [blame] | 50 | // This prctl is only available in Android kernels. |
| 51 | #define PR_SET_TIMERSLACK_PID 41 |
| 52 | |
Ruchi Kandoi | 422852e | 2014-04-22 18:55:08 -0700 | [diff] [blame] | 53 | // timer slack value in nS enforced when the thread moves to background |
| 54 | #define TIMER_SLACK_BG 40000000 |
| 55 | |
Brad Fitzpatrick | e43c248 | 2010-05-07 12:06:05 -0700 | [diff] [blame] | 56 | static pthread_once_t the_once = PTHREAD_ONCE_INIT; |
| 57 | |
San Mehat | c0dfca7 | 2009-10-27 11:52:55 -0700 | [diff] [blame] | 58 | static int __sys_supports_schedgroups = -1; |
| 59 | |
Brad Fitzpatrick | e43c248 | 2010-05-07 12:06:05 -0700 | [diff] [blame] | 60 | // File descriptors open to /dev/cpuctl/../tasks, setup by initialize, or -1 on error. |
Brad Fitzpatrick | e43c248 | 2010-05-07 12:06:05 -0700 | [diff] [blame] | 61 | static int bg_cgroup_fd = -1; |
Glenn Kasten | 10ec3c7 | 2012-04-19 15:25:58 -0700 | [diff] [blame] | 62 | static int fg_cgroup_fd = -1; |
| 63 | #if CAN_SET_SP_SYSTEM |
| 64 | static int system_cgroup_fd = -1; |
| 65 | #endif |
Brad Fitzpatrick | e43c248 | 2010-05-07 12:06:05 -0700 | [diff] [blame] | 66 | |
| 67 | /* Add tid to the scheduling group defined by the policy */ |
| 68 | static int add_tid_to_cgroup(int tid, SchedPolicy policy) |
San Mehat | 493dad9 | 2009-09-12 10:06:57 -0700 | [diff] [blame] | 69 | { |
| 70 | int fd; |
Brad Fitzpatrick | e43c248 | 2010-05-07 12:06:05 -0700 | [diff] [blame] | 71 | |
Glenn Kasten | 10ec3c7 | 2012-04-19 15:25:58 -0700 | [diff] [blame] | 72 | switch (policy) { |
| 73 | case SP_BACKGROUND: |
Brad Fitzpatrick | e43c248 | 2010-05-07 12:06:05 -0700 | [diff] [blame] | 74 | fd = bg_cgroup_fd; |
Glenn Kasten | 10ec3c7 | 2012-04-19 15:25:58 -0700 | [diff] [blame] | 75 | break; |
| 76 | case SP_FOREGROUND: |
Dima Zavin | 29319a6 | 2012-06-04 13:14:36 -0700 | [diff] [blame] | 77 | case SP_AUDIO_APP: |
| 78 | case SP_AUDIO_SYS: |
Glenn Kasten | 10ec3c7 | 2012-04-19 15:25:58 -0700 | [diff] [blame] | 79 | fd = fg_cgroup_fd; |
| 80 | break; |
| 81 | #if CAN_SET_SP_SYSTEM |
| 82 | case SP_SYSTEM: |
| 83 | fd = system_cgroup_fd; |
| 84 | break; |
| 85 | #endif |
Glenn Kasten | 10ec3c7 | 2012-04-19 15:25:58 -0700 | [diff] [blame] | 86 | default: |
| 87 | fd = -1; |
| 88 | break; |
Brad Fitzpatrick | e43c248 | 2010-05-07 12:06:05 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | if (fd < 0) { |
Glenn Kasten | 10ec3c7 | 2012-04-19 15:25:58 -0700 | [diff] [blame] | 92 | SLOGE("add_tid_to_cgroup failed; policy=%d\n", policy); |
San Mehat | 493dad9 | 2009-09-12 10:06:57 -0700 | [diff] [blame] | 93 | return -1; |
San Mehat | 805d67a | 2009-10-29 13:56:26 -0700 | [diff] [blame] | 94 | } |
San Mehat | 493dad9 | 2009-09-12 10:06:57 -0700 | [diff] [blame] | 95 | |
Brad Fitzpatrick | 253e27a | 2010-05-06 10:00:37 -0700 | [diff] [blame] | 96 | // specialized itoa -- works for tid > 0 |
| 97 | char text[22]; |
| 98 | char *end = text + sizeof(text) - 1; |
| 99 | char *ptr = end; |
| 100 | *ptr = '\0'; |
| 101 | while (tid > 0) { |
| 102 | *--ptr = '0' + (tid % 10); |
| 103 | tid = tid / 10; |
| 104 | } |
| 105 | |
| 106 | if (write(fd, ptr, end - ptr) < 0) { |
Brad Fitzpatrick | e43c248 | 2010-05-07 12:06:05 -0700 | [diff] [blame] | 107 | /* |
| 108 | * If the thread is in the process of exiting, |
| 109 | * don't flag an error |
| 110 | */ |
| 111 | if (errno == ESRCH) |
| 112 | return 0; |
Glenn Kasten | 10ec3c7 | 2012-04-19 15:25:58 -0700 | [diff] [blame] | 113 | SLOGW("add_tid_to_cgroup failed to write '%s' (%s); policy=%d\n", |
| 114 | ptr, strerror(errno), policy); |
San Mehat | 493dad9 | 2009-09-12 10:06:57 -0700 | [diff] [blame] | 115 | return -1; |
| 116 | } |
| 117 | |
San Mehat | 493dad9 | 2009-09-12 10:06:57 -0700 | [diff] [blame] | 118 | return 0; |
| 119 | } |
| 120 | |
Brad Fitzpatrick | e43c248 | 2010-05-07 12:06:05 -0700 | [diff] [blame] | 121 | static void __initialize(void) { |
| 122 | char* filename; |
| 123 | if (!access("/dev/cpuctl/tasks", F_OK)) { |
| 124 | __sys_supports_schedgroups = 1; |
| 125 | |
Glenn Kasten | 10ec3c7 | 2012-04-19 15:25:58 -0700 | [diff] [blame] | 126 | #if CAN_SET_SP_SYSTEM |
Brad Fitzpatrick | e43c248 | 2010-05-07 12:06:05 -0700 | [diff] [blame] | 127 | filename = "/dev/cpuctl/tasks"; |
Jeff Brown | 5b878d2 | 2012-05-08 15:07:58 -0700 | [diff] [blame] | 128 | system_cgroup_fd = open(filename, O_WRONLY | O_CLOEXEC); |
Glenn Kasten | 10ec3c7 | 2012-04-19 15:25:58 -0700 | [diff] [blame] | 129 | if (system_cgroup_fd < 0) { |
| 130 | SLOGV("open of %s failed: %s\n", filename, strerror(errno)); |
| 131 | } |
| 132 | #endif |
| 133 | |
Dima Zavin | 13ed76b | 2012-06-04 10:42:38 -0700 | [diff] [blame] | 134 | filename = "/dev/cpuctl/apps/tasks"; |
Jeff Brown | 5b878d2 | 2012-05-08 15:07:58 -0700 | [diff] [blame] | 135 | fg_cgroup_fd = open(filename, O_WRONLY | O_CLOEXEC); |
Glenn Kasten | 10ec3c7 | 2012-04-19 15:25:58 -0700 | [diff] [blame] | 136 | if (fg_cgroup_fd < 0) { |
Brad Fitzpatrick | e43c248 | 2010-05-07 12:06:05 -0700 | [diff] [blame] | 137 | SLOGE("open of %s failed: %s\n", filename, strerror(errno)); |
San Mehat | 493dad9 | 2009-09-12 10:06:57 -0700 | [diff] [blame] | 138 | } |
Brad Fitzpatrick | e43c248 | 2010-05-07 12:06:05 -0700 | [diff] [blame] | 139 | |
Dima Zavin | 13ed76b | 2012-06-04 10:42:38 -0700 | [diff] [blame] | 140 | filename = "/dev/cpuctl/apps/bg_non_interactive/tasks"; |
Jeff Brown | 5b878d2 | 2012-05-08 15:07:58 -0700 | [diff] [blame] | 141 | bg_cgroup_fd = open(filename, O_WRONLY | O_CLOEXEC); |
Brad Fitzpatrick | e43c248 | 2010-05-07 12:06:05 -0700 | [diff] [blame] | 142 | if (bg_cgroup_fd < 0) { |
| 143 | SLOGE("open of %s failed: %s\n", filename, strerror(errno)); |
| 144 | } |
| 145 | } else { |
| 146 | __sys_supports_schedgroups = 0; |
San Mehat | 493dad9 | 2009-09-12 10:06:57 -0700 | [diff] [blame] | 147 | } |
San Mehat | c0dfca7 | 2009-10-27 11:52:55 -0700 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | /* |
| 151 | * Try to get the scheduler group. |
| 152 | * |
San Mehat | 503df20 | 2010-03-02 17:09:56 -0800 | [diff] [blame] | 153 | * The data from /proc/<pid>/cgroup looks (something) like: |
San Mehat | c0dfca7 | 2009-10-27 11:52:55 -0700 | [diff] [blame] | 154 | * 2:cpu:/bg_non_interactive |
San Mehat | 503df20 | 2010-03-02 17:09:56 -0800 | [diff] [blame] | 155 | * 1:cpuacct:/ |
San Mehat | c0dfca7 | 2009-10-27 11:52:55 -0700 | [diff] [blame] | 156 | * |
| 157 | * We return the part after the "/", which will be an empty string for |
| 158 | * the default cgroup. If the string is longer than "bufLen", the string |
| 159 | * will be truncated. |
| 160 | */ |
| 161 | static int getSchedulerGroup(int tid, char* buf, size_t bufLen) |
| 162 | { |
| 163 | #ifdef HAVE_ANDROID_OS |
| 164 | char pathBuf[32]; |
San Mehat | 503df20 | 2010-03-02 17:09:56 -0800 | [diff] [blame] | 165 | char lineBuf[256]; |
| 166 | FILE *fp; |
San Mehat | c0dfca7 | 2009-10-27 11:52:55 -0700 | [diff] [blame] | 167 | |
| 168 | snprintf(pathBuf, sizeof(pathBuf), "/proc/%d/cgroup", tid); |
San Mehat | 503df20 | 2010-03-02 17:09:56 -0800 | [diff] [blame] | 169 | if (!(fp = fopen(pathBuf, "r"))) { |
San Mehat | c0dfca7 | 2009-10-27 11:52:55 -0700 | [diff] [blame] | 170 | return -1; |
| 171 | } |
| 172 | |
San Mehat | 503df20 | 2010-03-02 17:09:56 -0800 | [diff] [blame] | 173 | while(fgets(lineBuf, sizeof(lineBuf) -1, fp)) { |
| 174 | char *next = lineBuf; |
| 175 | char *subsys; |
| 176 | char *grp; |
| 177 | size_t len; |
San Mehat | c0dfca7 | 2009-10-27 11:52:55 -0700 | [diff] [blame] | 178 | |
San Mehat | 503df20 | 2010-03-02 17:09:56 -0800 | [diff] [blame] | 179 | /* Junk the first field */ |
| 180 | if (!strsep(&next, ":")) { |
| 181 | goto out_bad_data; |
| 182 | } |
San Mehat | c0dfca7 | 2009-10-27 11:52:55 -0700 | [diff] [blame] | 183 | |
San Mehat | 503df20 | 2010-03-02 17:09:56 -0800 | [diff] [blame] | 184 | if (!(subsys = strsep(&next, ":"))) { |
| 185 | goto out_bad_data; |
| 186 | } |
| 187 | |
| 188 | if (strcmp(subsys, "cpu")) { |
| 189 | /* Not the subsys we're looking for */ |
| 190 | continue; |
| 191 | } |
| 192 | |
| 193 | if (!(grp = strsep(&next, ":"))) { |
| 194 | goto out_bad_data; |
| 195 | } |
| 196 | grp++; /* Drop the leading '/' */ |
| 197 | len = strlen(grp); |
| 198 | grp[len-1] = '\0'; /* Drop the trailing '\n' */ |
| 199 | |
| 200 | if (bufLen <= len) { |
| 201 | len = bufLen - 1; |
| 202 | } |
| 203 | strncpy(buf, grp, len); |
| 204 | buf[len] = '\0'; |
| 205 | fclose(fp); |
| 206 | return 0; |
San Mehat | c0dfca7 | 2009-10-27 11:52:55 -0700 | [diff] [blame] | 207 | } |
| 208 | |
San Mehat | 7e8529a | 2010-03-25 09:31:42 -0700 | [diff] [blame] | 209 | SLOGE("Failed to find cpu subsys"); |
San Mehat | 503df20 | 2010-03-02 17:09:56 -0800 | [diff] [blame] | 210 | fclose(fp); |
| 211 | return -1; |
| 212 | out_bad_data: |
San Mehat | 7e8529a | 2010-03-25 09:31:42 -0700 | [diff] [blame] | 213 | SLOGE("Bad cgroup data {%s}", lineBuf); |
San Mehat | 503df20 | 2010-03-02 17:09:56 -0800 | [diff] [blame] | 214 | fclose(fp); |
| 215 | return -1; |
San Mehat | c0dfca7 | 2009-10-27 11:52:55 -0700 | [diff] [blame] | 216 | #else |
| 217 | errno = ENOSYS; |
| 218 | return -1; |
| 219 | #endif |
| 220 | } |
| 221 | |
| 222 | int get_sched_policy(int tid, SchedPolicy *policy) |
| 223 | { |
Glenn Kasten | 69bfb1f | 2012-03-16 09:43:19 -0700 | [diff] [blame] | 224 | if (tid == 0) { |
| 225 | tid = gettid(); |
| 226 | } |
Brad Fitzpatrick | e43c248 | 2010-05-07 12:06:05 -0700 | [diff] [blame] | 227 | pthread_once(&the_once, __initialize); |
San Mehat | c0dfca7 | 2009-10-27 11:52:55 -0700 | [diff] [blame] | 228 | |
| 229 | if (__sys_supports_schedgroups) { |
| 230 | char grpBuf[32]; |
| 231 | if (getSchedulerGroup(tid, grpBuf, sizeof(grpBuf)) < 0) |
| 232 | return -1; |
| 233 | if (grpBuf[0] == '\0') { |
Glenn Kasten | 10ec3c7 | 2012-04-19 15:25:58 -0700 | [diff] [blame] | 234 | *policy = SP_SYSTEM; |
Dima Zavin | 13ed76b | 2012-06-04 10:42:38 -0700 | [diff] [blame] | 235 | } else if (!strcmp(grpBuf, "apps/bg_non_interactive")) { |
San Mehat | c0dfca7 | 2009-10-27 11:52:55 -0700 | [diff] [blame] | 236 | *policy = SP_BACKGROUND; |
Dima Zavin | 13ed76b | 2012-06-04 10:42:38 -0700 | [diff] [blame] | 237 | } else if (!strcmp(grpBuf, "apps")) { |
Glenn Kasten | 10ec3c7 | 2012-04-19 15:25:58 -0700 | [diff] [blame] | 238 | *policy = SP_FOREGROUND; |
San Mehat | c0dfca7 | 2009-10-27 11:52:55 -0700 | [diff] [blame] | 239 | } else { |
| 240 | errno = ERANGE; |
| 241 | return -1; |
| 242 | } |
| 243 | } else { |
| 244 | int rc = sched_getscheduler(tid); |
| 245 | if (rc < 0) |
| 246 | return -1; |
| 247 | else if (rc == SCHED_NORMAL) |
| 248 | *policy = SP_FOREGROUND; |
| 249 | else if (rc == SCHED_BATCH) |
| 250 | *policy = SP_BACKGROUND; |
| 251 | else { |
| 252 | errno = ERANGE; |
| 253 | return -1; |
| 254 | } |
| 255 | } |
| 256 | return 0; |
| 257 | } |
| 258 | |
| 259 | int set_sched_policy(int tid, SchedPolicy policy) |
| 260 | { |
Glenn Kasten | 69bfb1f | 2012-03-16 09:43:19 -0700 | [diff] [blame] | 261 | if (tid == 0) { |
| 262 | tid = gettid(); |
| 263 | } |
Glenn Kasten | 69bfb1f | 2012-03-16 09:43:19 -0700 | [diff] [blame] | 264 | policy = _policy(policy); |
Brad Fitzpatrick | e43c248 | 2010-05-07 12:06:05 -0700 | [diff] [blame] | 265 | pthread_once(&the_once, __initialize); |
San Mehat | 493dad9 | 2009-09-12 10:06:57 -0700 | [diff] [blame] | 266 | |
San Mehat | d2e4e46 | 2009-10-29 11:48:00 -0700 | [diff] [blame] | 267 | #if POLICY_DEBUG |
| 268 | char statfile[64]; |
| 269 | char statline[1024]; |
| 270 | char thread_name[255]; |
| 271 | int fd; |
| 272 | |
| 273 | sprintf(statfile, "/proc/%d/stat", tid); |
| 274 | memset(thread_name, 0, sizeof(thread_name)); |
| 275 | |
| 276 | fd = open(statfile, O_RDONLY); |
| 277 | if (fd >= 0) { |
| 278 | int rc = read(fd, statline, 1023); |
| 279 | close(fd); |
| 280 | statline[rc] = 0; |
| 281 | char *p = statline; |
| 282 | char *q; |
| 283 | |
| 284 | for (p = statline; *p != '('; p++); |
| 285 | p++; |
| 286 | for (q = p; *q != ')'; q++); |
| 287 | |
| 288 | strncpy(thread_name, p, (q-p)); |
| 289 | } |
Glenn Kasten | 10ec3c7 | 2012-04-19 15:25:58 -0700 | [diff] [blame] | 290 | switch (policy) { |
| 291 | case SP_BACKGROUND: |
San Mehat | 7e8529a | 2010-03-25 09:31:42 -0700 | [diff] [blame] | 292 | SLOGD("vvv tid %d (%s)", tid, thread_name); |
Glenn Kasten | 10ec3c7 | 2012-04-19 15:25:58 -0700 | [diff] [blame] | 293 | break; |
| 294 | case SP_FOREGROUND: |
Dima Zavin | 29319a6 | 2012-06-04 13:14:36 -0700 | [diff] [blame] | 295 | case SP_AUDIO_APP: |
| 296 | case SP_AUDIO_SYS: |
San Mehat | 7e8529a | 2010-03-25 09:31:42 -0700 | [diff] [blame] | 297 | SLOGD("^^^ tid %d (%s)", tid, thread_name); |
Glenn Kasten | 10ec3c7 | 2012-04-19 15:25:58 -0700 | [diff] [blame] | 298 | break; |
| 299 | case SP_SYSTEM: |
| 300 | SLOGD("/// tid %d (%s)", tid, thread_name); |
| 301 | break; |
Glenn Kasten | 10ec3c7 | 2012-04-19 15:25:58 -0700 | [diff] [blame] | 302 | default: |
San Mehat | 7e8529a | 2010-03-25 09:31:42 -0700 | [diff] [blame] | 303 | SLOGD("??? tid %d (%s)", tid, thread_name); |
Glenn Kasten | 10ec3c7 | 2012-04-19 15:25:58 -0700 | [diff] [blame] | 304 | break; |
San Mehat | d2e4e46 | 2009-10-29 11:48:00 -0700 | [diff] [blame] | 305 | } |
| 306 | #endif |
| 307 | |
San Mehat | 493dad9 | 2009-09-12 10:06:57 -0700 | [diff] [blame] | 308 | if (__sys_supports_schedgroups) { |
Brad Fitzpatrick | e43c248 | 2010-05-07 12:06:05 -0700 | [diff] [blame] | 309 | if (add_tid_to_cgroup(tid, policy)) { |
San Mehat | 493dad9 | 2009-09-12 10:06:57 -0700 | [diff] [blame] | 310 | if (errno != ESRCH && errno != ENOENT) |
| 311 | return -errno; |
| 312 | } |
| 313 | } else { |
| 314 | struct sched_param param; |
| 315 | |
| 316 | param.sched_priority = 0; |
| 317 | sched_setscheduler(tid, |
| 318 | (policy == SP_BACKGROUND) ? |
| 319 | SCHED_BATCH : SCHED_NORMAL, |
| 320 | ¶m); |
| 321 | } |
| 322 | |
Ruchi Kandoi | 422852e | 2014-04-22 18:55:08 -0700 | [diff] [blame] | 323 | prctl(PR_SET_TIMERSLACK_PID, policy == SP_BACKGROUND ? TIMER_SLACK_BG : 0, tid); |
| 324 | |
San Mehat | 493dad9 | 2009-09-12 10:06:57 -0700 | [diff] [blame] | 325 | return 0; |
| 326 | } |
Raphael | 0384a98 | 2009-09-15 17:10:17 -0700 | [diff] [blame] | 327 | |
Jeff Brown | bff8f3f | 2012-05-08 15:05:42 -0700 | [diff] [blame] | 328 | #else |
| 329 | |
| 330 | /* Stubs for non-Android targets. */ |
| 331 | |
Mark Salyzyn | 1271716 | 2014-04-29 15:49:14 -0700 | [diff] [blame] | 332 | int set_sched_policy(int tid UNUSED, SchedPolicy policy UNUSED) |
Jeff Brown | bff8f3f | 2012-05-08 15:05:42 -0700 | [diff] [blame] | 333 | { |
| 334 | return 0; |
| 335 | } |
| 336 | |
Mark Salyzyn | 1271716 | 2014-04-29 15:49:14 -0700 | [diff] [blame] | 337 | int get_sched_policy(int tid UNUSED, SchedPolicy *policy) |
Jeff Brown | bff8f3f | 2012-05-08 15:05:42 -0700 | [diff] [blame] | 338 | { |
| 339 | *policy = SP_SYSTEM_DEFAULT; |
| 340 | return 0; |
| 341 | } |
| 342 | |
| 343 | #endif |
| 344 | |
Glenn Kasten | 86c7cc8 | 2012-03-05 16:14:39 -0800 | [diff] [blame] | 345 | const char *get_sched_policy_name(SchedPolicy policy) |
| 346 | { |
Glenn Kasten | 69bfb1f | 2012-03-16 09:43:19 -0700 | [diff] [blame] | 347 | policy = _policy(policy); |
Glenn Kasten | 86c7cc8 | 2012-03-05 16:14:39 -0800 | [diff] [blame] | 348 | static const char * const strings[SP_CNT] = { |
| 349 | [SP_BACKGROUND] = "bg", |
| 350 | [SP_FOREGROUND] = "fg", |
Glenn Kasten | 10ec3c7 | 2012-04-19 15:25:58 -0700 | [diff] [blame] | 351 | [SP_SYSTEM] = " ", |
| 352 | [SP_AUDIO_APP] = "aa", |
| 353 | [SP_AUDIO_SYS] = "as", |
Glenn Kasten | 86c7cc8 | 2012-03-05 16:14:39 -0800 | [diff] [blame] | 354 | }; |
| 355 | if ((policy < SP_CNT) && (strings[policy] != NULL)) |
| 356 | return strings[policy]; |
| 357 | else |
| 358 | return "error"; |
| 359 | } |
| 360 | |