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