Mark Salyzyn | 1271716 | 2014-04-29 15:49:14 -0700 | [diff] [blame] | 1 | /* |
Suren Baghdasaryan | 82b72a5 | 2018-12-21 11:41:50 -0800 | [diff] [blame] | 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 | */ |
San Mehat | 493dad9 | 2009-09-12 10:06:57 -0700 | [diff] [blame] | 16 | |
Suren Baghdasaryan | 1bd127b | 2019-01-25 05:30:52 +0000 | [diff] [blame] | 17 | #include <processgroup/sched_policy.h> |
Elliott Hughes | 8e9aeb9 | 2017-11-10 10:22:07 -0800 | [diff] [blame] | 18 | |
Jeff Brown | bff8f3f | 2012-05-08 15:05:42 -0700 | [diff] [blame] | 19 | #define LOG_TAG "SchedPolicy" |
| 20 | |
San Mehat | 493dad9 | 2009-09-12 10:06:57 -0700 | [diff] [blame] | 21 | #include <errno.h> |
Mark Salyzyn | 1271716 | 2014-04-29 15:49:14 -0700 | [diff] [blame] | 22 | #include <unistd.h> |
| 23 | |
Suren Baghdasaryan | 82b72a5 | 2018-12-21 11:41:50 -0800 | [diff] [blame] | 24 | #include <android-base/logging.h> |
| 25 | #include <android-base/threads.h> |
| 26 | #include <cgroup_map.h> |
| 27 | #include <processgroup/processgroup.h> |
| 28 | |
| 29 | using android::base::GetThreadId; |
Mark Salyzyn | 1271716 | 2014-04-29 15:49:14 -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 | */ |
Suren Baghdasaryan | 82b72a5 | 2018-12-21 11:41:50 -0800 | [diff] [blame] | 35 | static inline SchedPolicy _policy(SchedPolicy p) { |
| 36 | return p == SP_DEFAULT ? SP_SYSTEM_DEFAULT : p; |
Jeff Brown | bff8f3f | 2012-05-08 15:05:42 -0700 | [diff] [blame] | 37 | } |
San Mehat | d2e4e46 | 2009-10-29 11:48:00 -0700 | [diff] [blame] | 38 | |
Suren Baghdasaryan | eca87cb | 2019-02-02 14:19:41 -0800 | [diff] [blame] | 39 | #if defined(__ANDROID__) |
| 40 | |
Suren Baghdasaryan | 82b72a5 | 2018-12-21 11:41:50 -0800 | [diff] [blame] | 41 | int set_cpuset_policy(int tid, SchedPolicy policy) { |
Glenn Kasten | 69bfb1f | 2012-03-16 09:43:19 -0700 | [diff] [blame] | 42 | if (tid == 0) { |
Suren Baghdasaryan | 82b72a5 | 2018-12-21 11:41:50 -0800 | [diff] [blame] | 43 | tid = GetThreadId(); |
Tim Murray | b769c8d | 2015-06-08 14:56:29 -0700 | [diff] [blame] | 44 | } |
| 45 | policy = _policy(policy); |
Tim Murray | b769c8d | 2015-06-08 14:56:29 -0700 | [diff] [blame] | 46 | |
Tim Murray | b769c8d | 2015-06-08 14:56:29 -0700 | [diff] [blame] | 47 | switch (policy) { |
Suren Baghdasaryan | 82b72a5 | 2018-12-21 11:41:50 -0800 | [diff] [blame] | 48 | case SP_BACKGROUND: |
Rick Yiu | 0b211fa | 2019-09-16 19:07:17 +0800 | [diff] [blame] | 49 | return SetTaskProfiles(tid, {"CPUSET_SP_BACKGROUND"}, true) ? 0 : -1; |
Suren Baghdasaryan | 82b72a5 | 2018-12-21 11:41:50 -0800 | [diff] [blame] | 50 | case SP_FOREGROUND: |
| 51 | case SP_AUDIO_APP: |
| 52 | case SP_AUDIO_SYS: |
Rick Yiu | 0b211fa | 2019-09-16 19:07:17 +0800 | [diff] [blame] | 53 | return SetTaskProfiles(tid, {"CPUSET_SP_FOREGROUND"}, true) ? 0 : -1; |
Suren Baghdasaryan | 82b72a5 | 2018-12-21 11:41:50 -0800 | [diff] [blame] | 54 | case SP_TOP_APP: |
Rick Yiu | 0b211fa | 2019-09-16 19:07:17 +0800 | [diff] [blame] | 55 | return SetTaskProfiles(tid, {"CPUSET_SP_TOP_APP"}, true) ? 0 : -1; |
Suren Baghdasaryan | 82b72a5 | 2018-12-21 11:41:50 -0800 | [diff] [blame] | 56 | case SP_SYSTEM: |
Rick Yiu | 0b211fa | 2019-09-16 19:07:17 +0800 | [diff] [blame] | 57 | return SetTaskProfiles(tid, {"CPUSET_SP_SYSTEM"}, true) ? 0 : -1; |
Suren Baghdasaryan | 82b72a5 | 2018-12-21 11:41:50 -0800 | [diff] [blame] | 58 | case SP_RESTRICTED: |
Rick Yiu | 0b211fa | 2019-09-16 19:07:17 +0800 | [diff] [blame] | 59 | return SetTaskProfiles(tid, {"CPUSET_SP_RESTRICTED"}, true) ? 0 : -1; |
Suren Baghdasaryan | 82b72a5 | 2018-12-21 11:41:50 -0800 | [diff] [blame] | 60 | default: |
| 61 | break; |
Todd Kjos | ba8a475 | 2015-10-26 16:22:11 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Tim Murray | 9991026 | 2015-06-22 14:00:56 -0700 | [diff] [blame] | 64 | return 0; |
Tim Murray | b769c8d | 2015-06-08 14:56:29 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Suren Baghdasaryan | 82b72a5 | 2018-12-21 11:41:50 -0800 | [diff] [blame] | 67 | int set_sched_policy(int tid, SchedPolicy policy) { |
Glenn Kasten | 69bfb1f | 2012-03-16 09:43:19 -0700 | [diff] [blame] | 68 | if (tid == 0) { |
Suren Baghdasaryan | 82b72a5 | 2018-12-21 11:41:50 -0800 | [diff] [blame] | 69 | tid = GetThreadId(); |
Glenn Kasten | 69bfb1f | 2012-03-16 09:43:19 -0700 | [diff] [blame] | 70 | } |
Glenn Kasten | 69bfb1f | 2012-03-16 09:43:19 -0700 | [diff] [blame] | 71 | policy = _policy(policy); |
San Mehat | 493dad9 | 2009-09-12 10:06:57 -0700 | [diff] [blame] | 72 | |
San Mehat | d2e4e46 | 2009-10-29 11:48:00 -0700 | [diff] [blame] | 73 | #if POLICY_DEBUG |
| 74 | char statfile[64]; |
| 75 | char statline[1024]; |
| 76 | char thread_name[255]; |
San Mehat | d2e4e46 | 2009-10-29 11:48:00 -0700 | [diff] [blame] | 77 | |
Raja M | a2f37e4 | 2016-04-19 23:55:14 +0530 | [diff] [blame] | 78 | snprintf(statfile, sizeof(statfile), "/proc/%d/stat", tid); |
San Mehat | d2e4e46 | 2009-10-29 11:48:00 -0700 | [diff] [blame] | 79 | memset(thread_name, 0, sizeof(thread_name)); |
| 80 | |
Suren Baghdasaryan | 82b72a5 | 2018-12-21 11:41:50 -0800 | [diff] [blame] | 81 | unique_fd fd(TEMP_FAILURE_RETRY(open(statfile, O_RDONLY | O_CLOEXEC))); |
San Mehat | d2e4e46 | 2009-10-29 11:48:00 -0700 | [diff] [blame] | 82 | if (fd >= 0) { |
| 83 | int rc = read(fd, statline, 1023); |
San Mehat | d2e4e46 | 2009-10-29 11:48:00 -0700 | [diff] [blame] | 84 | statline[rc] = 0; |
Suren Baghdasaryan | 82b72a5 | 2018-12-21 11:41:50 -0800 | [diff] [blame] | 85 | char* p = statline; |
| 86 | char* q; |
San Mehat | d2e4e46 | 2009-10-29 11:48:00 -0700 | [diff] [blame] | 87 | |
Suren Baghdasaryan | 82b72a5 | 2018-12-21 11:41:50 -0800 | [diff] [blame] | 88 | for (p = statline; *p != '('; p++) |
| 89 | ; |
San Mehat | d2e4e46 | 2009-10-29 11:48:00 -0700 | [diff] [blame] | 90 | p++; |
Suren Baghdasaryan | 82b72a5 | 2018-12-21 11:41:50 -0800 | [diff] [blame] | 91 | for (q = p; *q != ')'; q++) |
| 92 | ; |
San Mehat | d2e4e46 | 2009-10-29 11:48:00 -0700 | [diff] [blame] | 93 | |
Suren Baghdasaryan | 82b72a5 | 2018-12-21 11:41:50 -0800 | [diff] [blame] | 94 | strncpy(thread_name, p, (q - p)); |
San Mehat | d2e4e46 | 2009-10-29 11:48:00 -0700 | [diff] [blame] | 95 | } |
Glenn Kasten | 10ec3c7 | 2012-04-19 15:25:58 -0700 | [diff] [blame] | 96 | switch (policy) { |
Tim Murray | b769c8d | 2015-06-08 14:56:29 -0700 | [diff] [blame] | 97 | case SP_BACKGROUND: |
Suren Baghdasaryan | 82b72a5 | 2018-12-21 11:41:50 -0800 | [diff] [blame] | 98 | SLOGD("vvv tid %d (%s)", tid, thread_name); |
Tim Murray | b769c8d | 2015-06-08 14:56:29 -0700 | [diff] [blame] | 99 | break; |
| 100 | case SP_FOREGROUND: |
| 101 | case SP_AUDIO_APP: |
| 102 | case SP_AUDIO_SYS: |
Tim Murray | 6647bb5 | 2016-01-11 16:16:35 -0800 | [diff] [blame] | 103 | case SP_TOP_APP: |
Suren Baghdasaryan | 82b72a5 | 2018-12-21 11:41:50 -0800 | [diff] [blame] | 104 | SLOGD("^^^ tid %d (%s)", tid, thread_name); |
| 105 | break; |
| 106 | case SP_SYSTEM: |
| 107 | SLOGD("/// tid %d (%s)", tid, thread_name); |
Tim Murray | b769c8d | 2015-06-08 14:56:29 -0700 | [diff] [blame] | 108 | break; |
Joel Fernandes | 88ef9f0 | 2017-03-25 22:46:10 -0700 | [diff] [blame] | 109 | case SP_RT_APP: |
Suren Baghdasaryan | 82b72a5 | 2018-12-21 11:41:50 -0800 | [diff] [blame] | 110 | SLOGD("RT tid %d (%s)", tid, thread_name); |
Tim Murray | b769c8d | 2015-06-08 14:56:29 -0700 | [diff] [blame] | 111 | break; |
Suren Baghdasaryan | 82b72a5 | 2018-12-21 11:41:50 -0800 | [diff] [blame] | 112 | default: |
| 113 | SLOGD("??? tid %d (%s)", tid, thread_name); |
| 114 | break; |
| 115 | } |
| 116 | #endif |
Tim Murray | b769c8d | 2015-06-08 14:56:29 -0700 | [diff] [blame] | 117 | |
Suren Baghdasaryan | 82b72a5 | 2018-12-21 11:41:50 -0800 | [diff] [blame] | 118 | switch (policy) { |
| 119 | case SP_BACKGROUND: |
Rick Yiu | 0b211fa | 2019-09-16 19:07:17 +0800 | [diff] [blame] | 120 | return SetTaskProfiles(tid, {"SCHED_SP_BACKGROUND"}, true) ? 0 : -1; |
Suren Baghdasaryan | 82b72a5 | 2018-12-21 11:41:50 -0800 | [diff] [blame] | 121 | case SP_FOREGROUND: |
| 122 | case SP_AUDIO_APP: |
| 123 | case SP_AUDIO_SYS: |
Rick Yiu | 0b211fa | 2019-09-16 19:07:17 +0800 | [diff] [blame] | 124 | return SetTaskProfiles(tid, {"SCHED_SP_FOREGROUND"}, true) ? 0 : -1; |
Suren Baghdasaryan | 82b72a5 | 2018-12-21 11:41:50 -0800 | [diff] [blame] | 125 | case SP_TOP_APP: |
Rick Yiu | 0b211fa | 2019-09-16 19:07:17 +0800 | [diff] [blame] | 126 | return SetTaskProfiles(tid, {"SCHED_SP_TOP_APP"}, true) ? 0 : -1; |
Wei Wang | ab87979 | 2020-11-24 00:26:40 -0800 | [diff] [blame^] | 127 | case SP_SYSTEM: |
| 128 | return SetTaskProfiles(tid, {"SCHED_SP_SYSTEM"}, true) ? 0 : -1; |
Suren Baghdasaryan | 82b72a5 | 2018-12-21 11:41:50 -0800 | [diff] [blame] | 129 | case SP_RT_APP: |
Rick Yiu | 0b211fa | 2019-09-16 19:07:17 +0800 | [diff] [blame] | 130 | return SetTaskProfiles(tid, {"SCHED_SP_RT_APP"}, true) ? 0 : -1; |
Suren Baghdasaryan | 82b72a5 | 2018-12-21 11:41:50 -0800 | [diff] [blame] | 131 | default: |
Rick Yiu | 0b211fa | 2019-09-16 19:07:17 +0800 | [diff] [blame] | 132 | return SetTaskProfiles(tid, {"SCHED_SP_DEFAULT"}, true) ? 0 : -1; |
San Mehat | 493dad9 | 2009-09-12 10:06:57 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | return 0; |
| 136 | } |
Raphael | 0384a98 | 2009-09-15 17:10:17 -0700 | [diff] [blame] | 137 | |
Suren Baghdasaryan | 82b72a5 | 2018-12-21 11:41:50 -0800 | [diff] [blame] | 138 | bool cpusets_enabled() { |
Suren Baghdasaryan | fa7a05f | 2019-05-08 17:59:55 -0700 | [diff] [blame] | 139 | static bool enabled = (CgroupMap::GetInstance().FindController("cpuset").IsUsable()); |
Suren Baghdasaryan | 82b72a5 | 2018-12-21 11:41:50 -0800 | [diff] [blame] | 140 | return enabled; |
| 141 | } |
Jeff Brown | bff8f3f | 2012-05-08 15:05:42 -0700 | [diff] [blame] | 142 | |
Quentin Perret | 64811b7 | 2020-01-14 12:55:57 +0000 | [diff] [blame] | 143 | static bool schedtune_enabled() { |
| 144 | return (CgroupMap::GetInstance().FindController("schedtune").IsUsable()); |
| 145 | } |
| 146 | |
| 147 | static bool cpuctl_enabled() { |
| 148 | return (CgroupMap::GetInstance().FindController("cpu").IsUsable()); |
| 149 | } |
| 150 | |
Suren Baghdasaryan | 82b72a5 | 2018-12-21 11:41:50 -0800 | [diff] [blame] | 151 | bool schedboost_enabled() { |
Quentin Perret | 64811b7 | 2020-01-14 12:55:57 +0000 | [diff] [blame] | 152 | static bool enabled = schedtune_enabled() || cpuctl_enabled(); |
| 153 | |
Suren Baghdasaryan | 82b72a5 | 2018-12-21 11:41:50 -0800 | [diff] [blame] | 154 | return enabled; |
| 155 | } |
Jeff Brown | bff8f3f | 2012-05-08 15:05:42 -0700 | [diff] [blame] | 156 | |
Suren Baghdasaryan | 82b72a5 | 2018-12-21 11:41:50 -0800 | [diff] [blame] | 157 | static int getCGroupSubsys(int tid, const char* subsys, std::string& subgroup) { |
Yifan Hong | 53e0deb | 2019-03-22 17:01:08 -0700 | [diff] [blame] | 158 | auto controller = CgroupMap::GetInstance().FindController(subsys); |
Suren Baghdasaryan | 82b72a5 | 2018-12-21 11:41:50 -0800 | [diff] [blame] | 159 | |
Suren Baghdasaryan | fa7a05f | 2019-05-08 17:59:55 -0700 | [diff] [blame] | 160 | if (!controller.IsUsable()) return -1; |
Suren Baghdasaryan | 82b72a5 | 2018-12-21 11:41:50 -0800 | [diff] [blame] | 161 | |
Yifan Hong | 53e0deb | 2019-03-22 17:01:08 -0700 | [diff] [blame] | 162 | if (!controller.GetTaskGroup(tid, &subgroup)) { |
Wei Wang | d71d301 | 2019-03-07 11:59:12 -0800 | [diff] [blame] | 163 | LOG(ERROR) << "Failed to find cgroup for tid " << tid; |
Suren Baghdasaryan | 82b72a5 | 2018-12-21 11:41:50 -0800 | [diff] [blame] | 164 | return -1; |
| 165 | } |
Jeff Brown | bff8f3f | 2012-05-08 15:05:42 -0700 | [diff] [blame] | 166 | return 0; |
| 167 | } |
| 168 | |
Suren Baghdasaryan | 82b72a5 | 2018-12-21 11:41:50 -0800 | [diff] [blame] | 169 | int get_sched_policy(int tid, SchedPolicy* policy) { |
| 170 | if (tid == 0) { |
| 171 | tid = GetThreadId(); |
| 172 | } |
| 173 | |
| 174 | std::string group; |
| 175 | if (schedboost_enabled()) { |
Quentin Perret | 64811b7 | 2020-01-14 12:55:57 +0000 | [diff] [blame] | 176 | if ((getCGroupSubsys(tid, "schedtune", group) < 0) && |
| 177 | (getCGroupSubsys(tid, "cpu", group) < 0)) |
| 178 | return -1; |
Suren Baghdasaryan | 82b72a5 | 2018-12-21 11:41:50 -0800 | [diff] [blame] | 179 | } |
| 180 | if (group.empty() && cpusets_enabled()) { |
| 181 | if (getCGroupSubsys(tid, "cpuset", group) < 0) return -1; |
| 182 | } |
| 183 | |
| 184 | // TODO: replace hardcoded directories |
| 185 | if (group.empty()) { |
| 186 | *policy = SP_FOREGROUND; |
| 187 | } else if (group == "foreground") { |
| 188 | *policy = SP_FOREGROUND; |
| 189 | } else if (group == "system-background") { |
| 190 | *policy = SP_SYSTEM; |
| 191 | } else if (group == "background") { |
| 192 | *policy = SP_BACKGROUND; |
| 193 | } else if (group == "top-app") { |
| 194 | *policy = SP_TOP_APP; |
| 195 | } else if (group == "restricted") { |
| 196 | *policy = SP_RESTRICTED; |
| 197 | } else { |
| 198 | errno = ERANGE; |
| 199 | return -1; |
| 200 | } |
Jeff Brown | bff8f3f | 2012-05-08 15:05:42 -0700 | [diff] [blame] | 201 | return 0; |
| 202 | } |
| 203 | |
Suren Baghdasaryan | eca87cb | 2019-02-02 14:19:41 -0800 | [diff] [blame] | 204 | #else |
| 205 | |
| 206 | /* Stubs for non-Android targets. */ |
| 207 | |
| 208 | int set_sched_policy(int, SchedPolicy) { |
| 209 | return 0; |
| 210 | } |
| 211 | |
| 212 | int get_sched_policy(int, SchedPolicy* policy) { |
| 213 | *policy = SP_SYSTEM_DEFAULT; |
| 214 | return 0; |
| 215 | } |
| 216 | |
| 217 | #endif |
| 218 | |
Elliott Hughes | 9f49508 | 2018-04-25 14:52:50 -0700 | [diff] [blame] | 219 | const char* get_sched_policy_name(SchedPolicy policy) { |
Glenn Kasten | 69bfb1f | 2012-03-16 09:43:19 -0700 | [diff] [blame] | 220 | policy = _policy(policy); |
Elliott Hughes | 9f49508 | 2018-04-25 14:52:50 -0700 | [diff] [blame] | 221 | static const char* const kSchedPolicyNames[] = { |
Tim Murray | 419ba9e | 2018-04-13 10:15:49 -0700 | [diff] [blame] | 222 | [SP_BACKGROUND] = "bg", [SP_FOREGROUND] = "fg", [SP_SYSTEM] = " ", |
| 223 | [SP_AUDIO_APP] = "aa", [SP_AUDIO_SYS] = "as", [SP_TOP_APP] = "ta", |
| 224 | [SP_RT_APP] = "rt", [SP_RESTRICTED] = "rs", |
Glenn Kasten | 86c7cc8 | 2012-03-05 16:14:39 -0800 | [diff] [blame] | 225 | }; |
Elliott Hughes | 9f49508 | 2018-04-25 14:52:50 -0700 | [diff] [blame] | 226 | static_assert(arraysize(kSchedPolicyNames) == SP_CNT, "missing name"); |
| 227 | if (policy < SP_BACKGROUND || policy >= SP_CNT) { |
Wei Wang | ee2f260 | 2019-10-11 15:09:09 -0700 | [diff] [blame] | 228 | return nullptr; |
Elliott Hughes | 9f49508 | 2018-04-25 14:52:50 -0700 | [diff] [blame] | 229 | } |
| 230 | return kSchedPolicyNames[policy]; |
Glenn Kasten | 86c7cc8 | 2012-03-05 16:14:39 -0800 | [diff] [blame] | 231 | } |
Wei Wang | ee2f260 | 2019-10-11 15:09:09 -0700 | [diff] [blame] | 232 | |
| 233 | const char* get_cpuset_policy_profile_name(SchedPolicy policy) { |
| 234 | /* |
| 235 | * cpuset profile array for: |
| 236 | * SP_DEFAULT(-1), SP_BACKGROUND(0), SP_FOREGROUND(1), |
| 237 | * SP_SYSTEM(2), SP_AUDIO_APP(3), SP_AUDIO_SYS(4), |
| 238 | * SP_TOP_APP(5), SP_RT_APP(6), SP_RESTRICTED(7) |
| 239 | * index is policy + 1 |
| 240 | * this need keep in sync with SchedPolicy enum |
| 241 | */ |
| 242 | static constexpr const char* kCpusetProfiles[SP_CNT + 1] = { |
| 243 | "CPUSET_SP_DEFAULT", "CPUSET_SP_BACKGROUND", "CPUSET_SP_FOREGROUND", |
| 244 | "CPUSET_SP_SYSTEM", "CPUSET_SP_FOREGROUND", "CPUSET_SP_FOREGROUND", |
| 245 | "CPUSET_SP_TOP_APP", "CPUSET_SP_DEFAULT", "CPUSET_SP_RESTRICTED"}; |
| 246 | if (policy < SP_DEFAULT || policy >= SP_CNT) { |
| 247 | return nullptr; |
| 248 | } |
| 249 | return kCpusetProfiles[policy + 1]; |
| 250 | } |
| 251 | |
| 252 | const char* get_sched_policy_profile_name(SchedPolicy policy) { |
| 253 | /* |
| 254 | * sched profile array for: |
| 255 | * SP_DEFAULT(-1), SP_BACKGROUND(0), SP_FOREGROUND(1), |
| 256 | * SP_SYSTEM(2), SP_AUDIO_APP(3), SP_AUDIO_SYS(4), |
| 257 | * SP_TOP_APP(5), SP_RT_APP(6), SP_RESTRICTED(7) |
| 258 | * index is policy + 1 |
| 259 | * this need keep in sync with SchedPolicy enum |
| 260 | */ |
| 261 | static constexpr const char* kSchedProfiles[SP_CNT + 1] = { |
| 262 | "SCHED_SP_DEFAULT", "SCHED_SP_BACKGROUND", "SCHED_SP_FOREGROUND", |
Wei Wang | ab87979 | 2020-11-24 00:26:40 -0800 | [diff] [blame^] | 263 | "SCHED_SP_SYSTEM", "SCHED_SP_FOREGROUND", "SCHED_SP_FOREGROUND", |
Wei Wang | ee2f260 | 2019-10-11 15:09:09 -0700 | [diff] [blame] | 264 | "SCHED_SP_TOP_APP", "SCHED_SP_RT_APP", "SCHED_SP_DEFAULT"}; |
| 265 | if (policy < SP_DEFAULT || policy >= SP_CNT) { |
| 266 | return nullptr; |
| 267 | } |
| 268 | return kSchedProfiles[policy + 1]; |
| 269 | } |