Pavankumar Kondeti | 4e13d11 | 2018-01-25 01:12:08 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2014-2018, The Linux Foundation. All rights reserved. |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
Pavankumar Kondeti | 088f334 | 2017-03-17 15:06:47 +0530 | [diff] [blame] | 13 | #define pr_fmt(fmt) "core_ctl: " fmt |
| 14 | |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 15 | #include <linux/init.h> |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 16 | #include <linux/cpu.h> |
| 17 | #include <linux/cpumask.h> |
| 18 | #include <linux/cpufreq.h> |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 19 | #include <linux/kthread.h> |
| 20 | #include <linux/sched.h> |
| 21 | #include <linux/sched/rt.h> |
Joonwoo Park | bf78570 | 2017-09-26 17:24:22 -0700 | [diff] [blame] | 22 | #include <linux/syscore_ops.h> |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 23 | |
Olav Haugan | 09bcc68 | 2016-09-02 17:12:20 -0700 | [diff] [blame] | 24 | #include <trace/events/sched.h> |
Pavankumar Kondeti | e027bd5 | 2017-10-16 14:09:29 +0530 | [diff] [blame] | 25 | #include "sched.h" |
| 26 | #include "walt.h" |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 27 | |
Pavankumar Kondeti | 4b62196 | 2017-04-10 14:08:31 +0530 | [diff] [blame] | 28 | #define MAX_CPUS_PER_CLUSTER 6 |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 29 | #define MAX_CLUSTERS 2 |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 30 | |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 31 | struct cluster_data { |
| 32 | bool inited; |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 33 | unsigned int min_cpus; |
| 34 | unsigned int max_cpus; |
| 35 | unsigned int offline_delay_ms; |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 36 | unsigned int busy_up_thres[MAX_CPUS_PER_CLUSTER]; |
| 37 | unsigned int busy_down_thres[MAX_CPUS_PER_CLUSTER]; |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 38 | unsigned int active_cpus; |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 39 | unsigned int num_cpus; |
Pavankumar Kondeti | 32b2dd0 | 2017-04-13 16:58:57 +0530 | [diff] [blame] | 40 | unsigned int nr_isolated_cpus; |
Pavankumar Kondeti | 8a0cb95 | 2017-10-05 14:36:08 +0530 | [diff] [blame] | 41 | unsigned int nr_not_preferred_cpus; |
Joonwoo Park | bf78570 | 2017-09-26 17:24:22 -0700 | [diff] [blame] | 42 | #ifdef CONFIG_SCHED_CORE_ROTATE |
| 43 | unsigned long set_max; |
| 44 | unsigned long set_cur; |
| 45 | #endif |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 46 | cpumask_t cpu_mask; |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 47 | unsigned int need_cpus; |
| 48 | unsigned int task_thres; |
Pavankumar Kondeti | 00530928 | 2017-05-10 15:43:29 +0530 | [diff] [blame] | 49 | unsigned int max_nr; |
Pavankumar Kondeti | 83236e3 | 2017-02-10 09:58:58 +0530 | [diff] [blame] | 50 | s64 need_ts; |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 51 | struct list_head lru; |
| 52 | bool pending; |
| 53 | spinlock_t pending_lock; |
| 54 | bool is_big_cluster; |
Sabyasachi Singh | 9453cb2 | 2017-05-09 18:50:19 -0700 | [diff] [blame] | 55 | bool enable; |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 56 | int nrrun; |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 57 | struct task_struct *core_ctl_thread; |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 58 | unsigned int first_cpu; |
Olav Haugan | a024f47 | 2016-10-13 10:34:11 -0700 | [diff] [blame] | 59 | unsigned int boost; |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 60 | struct kobject kobj; |
| 61 | }; |
| 62 | |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 63 | struct cpu_data { |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 64 | bool is_busy; |
| 65 | unsigned int busy; |
| 66 | unsigned int cpu; |
| 67 | bool not_preferred; |
| 68 | struct cluster_data *cluster; |
| 69 | struct list_head sib; |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 70 | bool isolated_by_us; |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 71 | }; |
| 72 | |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 73 | static DEFINE_PER_CPU(struct cpu_data, cpu_state); |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 74 | static struct cluster_data cluster_state[MAX_CLUSTERS]; |
| 75 | static unsigned int num_clusters; |
| 76 | |
| 77 | #define for_each_cluster(cluster, idx) \ |
| 78 | for ((cluster) = &cluster_state[idx]; (idx) < num_clusters;\ |
| 79 | (idx)++, (cluster) = &cluster_state[idx]) |
| 80 | |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 81 | static DEFINE_SPINLOCK(state_lock); |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 82 | static void apply_need(struct cluster_data *state); |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 83 | static void wake_up_core_ctl_thread(struct cluster_data *state); |
| 84 | static bool initialized; |
| 85 | |
| 86 | static unsigned int get_active_cpu_count(const struct cluster_data *cluster); |
Joonwoo Park | bf78570 | 2017-09-26 17:24:22 -0700 | [diff] [blame] | 87 | static void cpuset_next(struct cluster_data *cluster); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 88 | |
| 89 | /* ========================= sysfs interface =========================== */ |
| 90 | |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 91 | static ssize_t store_min_cpus(struct cluster_data *state, |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 92 | const char *buf, size_t count) |
| 93 | { |
| 94 | unsigned int val; |
| 95 | |
| 96 | if (sscanf(buf, "%u\n", &val) != 1) |
| 97 | return -EINVAL; |
| 98 | |
| 99 | state->min_cpus = min(val, state->max_cpus); |
Joonwoo Park | bf78570 | 2017-09-26 17:24:22 -0700 | [diff] [blame] | 100 | cpuset_next(state); |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 101 | wake_up_core_ctl_thread(state); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 102 | |
| 103 | return count; |
| 104 | } |
| 105 | |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 106 | static ssize_t show_min_cpus(const struct cluster_data *state, char *buf) |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 107 | { |
| 108 | return snprintf(buf, PAGE_SIZE, "%u\n", state->min_cpus); |
| 109 | } |
| 110 | |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 111 | static ssize_t store_max_cpus(struct cluster_data *state, |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 112 | const char *buf, size_t count) |
| 113 | { |
| 114 | unsigned int val; |
| 115 | |
| 116 | if (sscanf(buf, "%u\n", &val) != 1) |
| 117 | return -EINVAL; |
| 118 | |
| 119 | val = min(val, state->num_cpus); |
| 120 | state->max_cpus = val; |
| 121 | state->min_cpus = min(state->min_cpus, state->max_cpus); |
Joonwoo Park | bf78570 | 2017-09-26 17:24:22 -0700 | [diff] [blame] | 122 | cpuset_next(state); |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 123 | wake_up_core_ctl_thread(state); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 124 | |
| 125 | return count; |
| 126 | } |
| 127 | |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 128 | static ssize_t show_max_cpus(const struct cluster_data *state, char *buf) |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 129 | { |
| 130 | return snprintf(buf, PAGE_SIZE, "%u\n", state->max_cpus); |
| 131 | } |
| 132 | |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 133 | static ssize_t store_offline_delay_ms(struct cluster_data *state, |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 134 | const char *buf, size_t count) |
| 135 | { |
| 136 | unsigned int val; |
| 137 | |
| 138 | if (sscanf(buf, "%u\n", &val) != 1) |
| 139 | return -EINVAL; |
| 140 | |
| 141 | state->offline_delay_ms = val; |
| 142 | apply_need(state); |
| 143 | |
| 144 | return count; |
| 145 | } |
| 146 | |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 147 | static ssize_t show_task_thres(const struct cluster_data *state, char *buf) |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 148 | { |
| 149 | return snprintf(buf, PAGE_SIZE, "%u\n", state->task_thres); |
| 150 | } |
| 151 | |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 152 | static ssize_t store_task_thres(struct cluster_data *state, |
| 153 | const char *buf, size_t count) |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 154 | { |
| 155 | unsigned int val; |
| 156 | |
| 157 | if (sscanf(buf, "%u\n", &val) != 1) |
| 158 | return -EINVAL; |
| 159 | |
| 160 | if (val < state->num_cpus) |
| 161 | return -EINVAL; |
| 162 | |
| 163 | state->task_thres = val; |
| 164 | apply_need(state); |
| 165 | |
| 166 | return count; |
| 167 | } |
| 168 | |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 169 | static ssize_t show_offline_delay_ms(const struct cluster_data *state, |
| 170 | char *buf) |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 171 | { |
| 172 | return snprintf(buf, PAGE_SIZE, "%u\n", state->offline_delay_ms); |
| 173 | } |
| 174 | |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 175 | static ssize_t store_busy_up_thres(struct cluster_data *state, |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 176 | const char *buf, size_t count) |
| 177 | { |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 178 | unsigned int val[MAX_CPUS_PER_CLUSTER]; |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 179 | int ret, i; |
| 180 | |
Pavankumar Kondeti | 4b62196 | 2017-04-10 14:08:31 +0530 | [diff] [blame] | 181 | ret = sscanf(buf, "%u %u %u %u %u %u\n", |
| 182 | &val[0], &val[1], &val[2], &val[3], |
| 183 | &val[4], &val[5]); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 184 | if (ret != 1 && ret != state->num_cpus) |
| 185 | return -EINVAL; |
| 186 | |
| 187 | if (ret == 1) { |
| 188 | for (i = 0; i < state->num_cpus; i++) |
| 189 | state->busy_up_thres[i] = val[0]; |
| 190 | } else { |
| 191 | for (i = 0; i < state->num_cpus; i++) |
| 192 | state->busy_up_thres[i] = val[i]; |
| 193 | } |
| 194 | apply_need(state); |
| 195 | return count; |
| 196 | } |
| 197 | |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 198 | static ssize_t show_busy_up_thres(const struct cluster_data *state, char *buf) |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 199 | { |
| 200 | int i, count = 0; |
| 201 | |
| 202 | for (i = 0; i < state->num_cpus; i++) |
| 203 | count += snprintf(buf + count, PAGE_SIZE - count, "%u ", |
| 204 | state->busy_up_thres[i]); |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 205 | |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 206 | count += snprintf(buf + count, PAGE_SIZE - count, "\n"); |
| 207 | return count; |
| 208 | } |
| 209 | |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 210 | static ssize_t store_busy_down_thres(struct cluster_data *state, |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 211 | const char *buf, size_t count) |
| 212 | { |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 213 | unsigned int val[MAX_CPUS_PER_CLUSTER]; |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 214 | int ret, i; |
| 215 | |
Pavankumar Kondeti | 4b62196 | 2017-04-10 14:08:31 +0530 | [diff] [blame] | 216 | ret = sscanf(buf, "%u %u %u %u %u %u\n", |
| 217 | &val[0], &val[1], &val[2], &val[3], |
| 218 | &val[4], &val[5]); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 219 | if (ret != 1 && ret != state->num_cpus) |
| 220 | return -EINVAL; |
| 221 | |
| 222 | if (ret == 1) { |
| 223 | for (i = 0; i < state->num_cpus; i++) |
| 224 | state->busy_down_thres[i] = val[0]; |
| 225 | } else { |
| 226 | for (i = 0; i < state->num_cpus; i++) |
| 227 | state->busy_down_thres[i] = val[i]; |
| 228 | } |
| 229 | apply_need(state); |
| 230 | return count; |
| 231 | } |
| 232 | |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 233 | static ssize_t show_busy_down_thres(const struct cluster_data *state, char *buf) |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 234 | { |
| 235 | int i, count = 0; |
| 236 | |
| 237 | for (i = 0; i < state->num_cpus; i++) |
| 238 | count += snprintf(buf + count, PAGE_SIZE - count, "%u ", |
| 239 | state->busy_down_thres[i]); |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 240 | |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 241 | count += snprintf(buf + count, PAGE_SIZE - count, "\n"); |
| 242 | return count; |
| 243 | } |
| 244 | |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 245 | static ssize_t store_is_big_cluster(struct cluster_data *state, |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 246 | const char *buf, size_t count) |
| 247 | { |
| 248 | unsigned int val; |
| 249 | |
| 250 | if (sscanf(buf, "%u\n", &val) != 1) |
| 251 | return -EINVAL; |
| 252 | |
| 253 | state->is_big_cluster = val ? 1 : 0; |
| 254 | return count; |
| 255 | } |
| 256 | |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 257 | static ssize_t show_is_big_cluster(const struct cluster_data *state, char *buf) |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 258 | { |
| 259 | return snprintf(buf, PAGE_SIZE, "%u\n", state->is_big_cluster); |
| 260 | } |
| 261 | |
Sabyasachi Singh | 9453cb2 | 2017-05-09 18:50:19 -0700 | [diff] [blame] | 262 | static ssize_t store_enable(struct cluster_data *state, |
| 263 | const char *buf, size_t count) |
| 264 | { |
| 265 | unsigned int val; |
| 266 | bool bval; |
| 267 | |
| 268 | if (sscanf(buf, "%u\n", &val) != 1) |
| 269 | return -EINVAL; |
| 270 | |
| 271 | bval = !!val; |
| 272 | if (bval != state->enable) { |
| 273 | state->enable = bval; |
| 274 | apply_need(state); |
| 275 | } |
| 276 | |
| 277 | return count; |
| 278 | } |
| 279 | |
| 280 | static ssize_t show_enable(const struct cluster_data *state, char *buf) |
| 281 | { |
| 282 | return scnprintf(buf, PAGE_SIZE, "%u\n", state->enable); |
| 283 | } |
| 284 | |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 285 | static ssize_t show_need_cpus(const struct cluster_data *state, char *buf) |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 286 | { |
| 287 | return snprintf(buf, PAGE_SIZE, "%u\n", state->need_cpus); |
| 288 | } |
| 289 | |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 290 | static ssize_t show_active_cpus(const struct cluster_data *state, char *buf) |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 291 | { |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 292 | return snprintf(buf, PAGE_SIZE, "%u\n", state->active_cpus); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 293 | } |
| 294 | |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 295 | static ssize_t show_global_state(const struct cluster_data *state, char *buf) |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 296 | { |
| 297 | struct cpu_data *c; |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 298 | struct cluster_data *cluster; |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 299 | ssize_t count = 0; |
| 300 | unsigned int cpu; |
| 301 | |
Pavankumar Kondeti | a207d5c | 2017-04-13 18:44:24 +0530 | [diff] [blame] | 302 | spin_lock_irq(&state_lock); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 303 | for_each_possible_cpu(cpu) { |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 304 | c = &per_cpu(cpu_state, cpu); |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 305 | cluster = c->cluster; |
| 306 | if (!cluster || !cluster->inited) |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 307 | continue; |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 308 | |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 309 | count += snprintf(buf + count, PAGE_SIZE - count, |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 310 | "CPU%u\n", cpu); |
| 311 | count += snprintf(buf + count, PAGE_SIZE - count, |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 312 | "\tCPU: %u\n", c->cpu); |
| 313 | count += snprintf(buf + count, PAGE_SIZE - count, |
Pavankumar Kondeti | 85dfbfa | 2017-03-17 15:29:13 +0530 | [diff] [blame] | 314 | "\tOnline: %u\n", |
| 315 | cpu_online(c->cpu)); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 316 | count += snprintf(buf + count, PAGE_SIZE - count, |
Pavankumar Kondeti | fbfa7b3 | 2017-03-17 15:52:30 +0530 | [diff] [blame] | 317 | "\tIsolated: %u\n", |
| 318 | cpu_isolated(c->cpu)); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 319 | count += snprintf(buf + count, PAGE_SIZE - count, |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 320 | "\tFirst CPU: %u\n", |
| 321 | cluster->first_cpu); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 322 | count += snprintf(buf + count, PAGE_SIZE - count, |
| 323 | "\tBusy%%: %u\n", c->busy); |
| 324 | count += snprintf(buf + count, PAGE_SIZE - count, |
| 325 | "\tIs busy: %u\n", c->is_busy); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 326 | count += snprintf(buf + count, PAGE_SIZE - count, |
Pavankumar Kondeti | 63877bc | 2017-02-16 08:25:21 +0530 | [diff] [blame] | 327 | "\tNot preferred: %u\n", |
| 328 | c->not_preferred); |
| 329 | count += snprintf(buf + count, PAGE_SIZE - count, |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 330 | "\tNr running: %u\n", cluster->nrrun); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 331 | count += snprintf(buf + count, PAGE_SIZE - count, |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 332 | "\tActive CPUs: %u\n", get_active_cpu_count(cluster)); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 333 | count += snprintf(buf + count, PAGE_SIZE - count, |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 334 | "\tNeed CPUs: %u\n", cluster->need_cpus); |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 335 | count += snprintf(buf + count, PAGE_SIZE - count, |
Pavankumar Kondeti | 32b2dd0 | 2017-04-13 16:58:57 +0530 | [diff] [blame] | 336 | "\tNr isolated CPUs: %u\n", |
| 337 | cluster->nr_isolated_cpus); |
| 338 | count += snprintf(buf + count, PAGE_SIZE - count, |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 339 | "\tBoost: %u\n", (unsigned int) cluster->boost); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 340 | } |
Pavankumar Kondeti | a207d5c | 2017-04-13 18:44:24 +0530 | [diff] [blame] | 341 | spin_unlock_irq(&state_lock); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 342 | |
| 343 | return count; |
| 344 | } |
| 345 | |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 346 | static ssize_t store_not_preferred(struct cluster_data *state, |
| 347 | const char *buf, size_t count) |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 348 | { |
| 349 | struct cpu_data *c; |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 350 | unsigned int i; |
| 351 | unsigned int val[MAX_CPUS_PER_CLUSTER]; |
| 352 | unsigned long flags; |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 353 | int ret; |
Pavankumar Kondeti | 8a0cb95 | 2017-10-05 14:36:08 +0530 | [diff] [blame] | 354 | int not_preferred_count = 0; |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 355 | |
Pavankumar Kondeti | 4b62196 | 2017-04-10 14:08:31 +0530 | [diff] [blame] | 356 | ret = sscanf(buf, "%u %u %u %u %u %u\n", |
| 357 | &val[0], &val[1], &val[2], &val[3], |
| 358 | &val[4], &val[5]); |
Pavankumar Kondeti | 63877bc | 2017-02-16 08:25:21 +0530 | [diff] [blame] | 359 | if (ret != state->num_cpus) |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 360 | return -EINVAL; |
| 361 | |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 362 | spin_lock_irqsave(&state_lock, flags); |
Pavankumar Kondeti | 63877bc | 2017-02-16 08:25:21 +0530 | [diff] [blame] | 363 | for (i = 0; i < state->num_cpus; i++) { |
| 364 | c = &per_cpu(cpu_state, i + state->first_cpu); |
| 365 | c->not_preferred = val[i]; |
Pavankumar Kondeti | 8a0cb95 | 2017-10-05 14:36:08 +0530 | [diff] [blame] | 366 | not_preferred_count += !!val[i]; |
Pavankumar Kondeti | 63877bc | 2017-02-16 08:25:21 +0530 | [diff] [blame] | 367 | } |
Pavankumar Kondeti | 8a0cb95 | 2017-10-05 14:36:08 +0530 | [diff] [blame] | 368 | state->nr_not_preferred_cpus = not_preferred_count; |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 369 | spin_unlock_irqrestore(&state_lock, flags); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 370 | |
| 371 | return count; |
| 372 | } |
| 373 | |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 374 | static ssize_t show_not_preferred(const struct cluster_data *state, char *buf) |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 375 | { |
| 376 | struct cpu_data *c; |
| 377 | ssize_t count = 0; |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 378 | unsigned long flags; |
Pavankumar Kondeti | 63877bc | 2017-02-16 08:25:21 +0530 | [diff] [blame] | 379 | int i; |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 380 | |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 381 | spin_lock_irqsave(&state_lock, flags); |
Pavankumar Kondeti | 63877bc | 2017-02-16 08:25:21 +0530 | [diff] [blame] | 382 | for (i = 0; i < state->num_cpus; i++) { |
| 383 | c = &per_cpu(cpu_state, i + state->first_cpu); |
| 384 | count += scnprintf(buf + count, PAGE_SIZE - count, |
| 385 | "CPU#%d: %u\n", c->cpu, c->not_preferred); |
| 386 | } |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 387 | spin_unlock_irqrestore(&state_lock, flags); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 388 | |
| 389 | return count; |
| 390 | } |
| 391 | |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 392 | |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 393 | struct core_ctl_attr { |
| 394 | struct attribute attr; |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 395 | ssize_t (*show)(const struct cluster_data *, char *); |
| 396 | ssize_t (*store)(struct cluster_data *, const char *, size_t count); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 397 | }; |
| 398 | |
| 399 | #define core_ctl_attr_ro(_name) \ |
| 400 | static struct core_ctl_attr _name = \ |
| 401 | __ATTR(_name, 0444, show_##_name, NULL) |
| 402 | |
| 403 | #define core_ctl_attr_rw(_name) \ |
| 404 | static struct core_ctl_attr _name = \ |
| 405 | __ATTR(_name, 0644, show_##_name, store_##_name) |
| 406 | |
| 407 | core_ctl_attr_rw(min_cpus); |
| 408 | core_ctl_attr_rw(max_cpus); |
| 409 | core_ctl_attr_rw(offline_delay_ms); |
| 410 | core_ctl_attr_rw(busy_up_thres); |
| 411 | core_ctl_attr_rw(busy_down_thres); |
| 412 | core_ctl_attr_rw(task_thres); |
| 413 | core_ctl_attr_rw(is_big_cluster); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 414 | core_ctl_attr_ro(need_cpus); |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 415 | core_ctl_attr_ro(active_cpus); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 416 | core_ctl_attr_ro(global_state); |
| 417 | core_ctl_attr_rw(not_preferred); |
Sabyasachi Singh | 9453cb2 | 2017-05-09 18:50:19 -0700 | [diff] [blame] | 418 | core_ctl_attr_rw(enable); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 419 | |
| 420 | static struct attribute *default_attrs[] = { |
| 421 | &min_cpus.attr, |
| 422 | &max_cpus.attr, |
| 423 | &offline_delay_ms.attr, |
| 424 | &busy_up_thres.attr, |
| 425 | &busy_down_thres.attr, |
| 426 | &task_thres.attr, |
| 427 | &is_big_cluster.attr, |
Sabyasachi Singh | 9453cb2 | 2017-05-09 18:50:19 -0700 | [diff] [blame] | 428 | &enable.attr, |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 429 | &need_cpus.attr, |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 430 | &active_cpus.attr, |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 431 | &global_state.attr, |
| 432 | ¬_preferred.attr, |
| 433 | NULL |
| 434 | }; |
| 435 | |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 436 | #define to_cluster_data(k) container_of(k, struct cluster_data, kobj) |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 437 | #define to_attr(a) container_of(a, struct core_ctl_attr, attr) |
| 438 | static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf) |
| 439 | { |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 440 | struct cluster_data *data = to_cluster_data(kobj); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 441 | struct core_ctl_attr *cattr = to_attr(attr); |
| 442 | ssize_t ret = -EIO; |
| 443 | |
| 444 | if (cattr->show) |
| 445 | ret = cattr->show(data, buf); |
| 446 | |
| 447 | return ret; |
| 448 | } |
| 449 | |
| 450 | static ssize_t store(struct kobject *kobj, struct attribute *attr, |
| 451 | const char *buf, size_t count) |
| 452 | { |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 453 | struct cluster_data *data = to_cluster_data(kobj); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 454 | struct core_ctl_attr *cattr = to_attr(attr); |
| 455 | ssize_t ret = -EIO; |
| 456 | |
| 457 | if (cattr->store) |
| 458 | ret = cattr->store(data, buf, count); |
| 459 | |
| 460 | return ret; |
| 461 | } |
| 462 | |
| 463 | static const struct sysfs_ops sysfs_ops = { |
| 464 | .show = show, |
| 465 | .store = store, |
| 466 | }; |
| 467 | |
| 468 | static struct kobj_type ktype_core_ctl = { |
| 469 | .sysfs_ops = &sysfs_ops, |
| 470 | .default_attrs = default_attrs, |
| 471 | }; |
| 472 | |
| 473 | /* ==================== runqueue based core count =================== */ |
| 474 | |
Syed Rameez Mustafa | 20acfe7 | 2017-01-30 09:35:46 +0530 | [diff] [blame] | 475 | static void update_running_avg(void) |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 476 | { |
Syed Rameez Mustafa | 20acfe7 | 2017-01-30 09:35:46 +0530 | [diff] [blame] | 477 | int avg, iowait_avg, big_avg; |
Pavankumar Kondeti | 00530928 | 2017-05-10 15:43:29 +0530 | [diff] [blame] | 478 | int max_nr, big_max_nr; |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 479 | struct cluster_data *cluster; |
| 480 | unsigned int index = 0; |
Pavankumar Kondeti | b572a10 | 2017-10-16 14:43:06 +0530 | [diff] [blame] | 481 | unsigned long flags; |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 482 | |
Pavankumar Kondeti | 00530928 | 2017-05-10 15:43:29 +0530 | [diff] [blame] | 483 | sched_get_nr_running_avg(&avg, &iowait_avg, &big_avg, |
| 484 | &max_nr, &big_max_nr); |
Pavankumar Kondeti | 4e13d11 | 2018-01-25 01:12:08 +0530 | [diff] [blame] | 485 | walt_rotation_checkpoint(big_avg); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 486 | |
Pavankumar Kondeti | b572a10 | 2017-10-16 14:43:06 +0530 | [diff] [blame] | 487 | spin_lock_irqsave(&state_lock, flags); |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 488 | for_each_cluster(cluster, index) { |
| 489 | if (!cluster->inited) |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 490 | continue; |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 491 | cluster->nrrun = cluster->is_big_cluster ? big_avg : avg; |
Pavankumar Kondeti | 00530928 | 2017-05-10 15:43:29 +0530 | [diff] [blame] | 492 | cluster->max_nr = cluster->is_big_cluster ? big_max_nr : max_nr; |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 493 | } |
Pavankumar Kondeti | b572a10 | 2017-10-16 14:43:06 +0530 | [diff] [blame] | 494 | spin_unlock_irqrestore(&state_lock, flags); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 495 | } |
| 496 | |
Pavankumar Kondeti | 00530928 | 2017-05-10 15:43:29 +0530 | [diff] [blame] | 497 | #define MAX_NR_THRESHOLD 4 |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 498 | /* adjust needed CPUs based on current runqueue information */ |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 499 | static unsigned int apply_task_need(const struct cluster_data *cluster, |
| 500 | unsigned int new_need) |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 501 | { |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 502 | /* unisolate all cores if there are enough tasks */ |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 503 | if (cluster->nrrun >= cluster->task_thres) |
| 504 | return cluster->num_cpus; |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 505 | |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 506 | /* only unisolate more cores if there are tasks to run */ |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 507 | if (cluster->nrrun > new_need) |
Pavankumar Kondeti | 00530928 | 2017-05-10 15:43:29 +0530 | [diff] [blame] | 508 | new_need = new_need + 1; |
| 509 | |
| 510 | /* |
| 511 | * We don't want tasks to be overcrowded in a cluster. |
| 512 | * If any CPU has more than MAX_NR_THRESHOLD in the last |
| 513 | * window, bring another CPU to help out. |
| 514 | */ |
| 515 | if (cluster->max_nr > MAX_NR_THRESHOLD) |
| 516 | new_need = new_need + 1; |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 517 | |
| 518 | return new_need; |
| 519 | } |
| 520 | |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 521 | /* ======================= load based core count ====================== */ |
| 522 | |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 523 | static unsigned int apply_limits(const struct cluster_data *cluster, |
| 524 | unsigned int need_cpus) |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 525 | { |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 526 | return min(max(cluster->min_cpus, need_cpus), cluster->max_cpus); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 527 | } |
| 528 | |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 529 | static unsigned int get_active_cpu_count(const struct cluster_data *cluster) |
| 530 | { |
| 531 | return cluster->num_cpus - |
| 532 | sched_isolate_count(&cluster->cpu_mask, true); |
| 533 | } |
| 534 | |
| 535 | static bool is_active(const struct cpu_data *state) |
| 536 | { |
Pavankumar Kondeti | 85dfbfa | 2017-03-17 15:29:13 +0530 | [diff] [blame] | 537 | return cpu_online(state->cpu) && !cpu_isolated(state->cpu); |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | static bool adjustment_possible(const struct cluster_data *cluster, |
| 541 | unsigned int need) |
| 542 | { |
| 543 | return (need < cluster->active_cpus || (need > cluster->active_cpus && |
Pavankumar Kondeti | 32b2dd0 | 2017-04-13 16:58:57 +0530 | [diff] [blame] | 544 | cluster->nr_isolated_cpus)); |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 545 | } |
| 546 | |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 547 | static bool eval_need(struct cluster_data *cluster) |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 548 | { |
| 549 | unsigned long flags; |
| 550 | struct cpu_data *c; |
| 551 | unsigned int need_cpus = 0, last_need, thres_idx; |
| 552 | int ret = 0; |
| 553 | bool need_flag = false; |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 554 | unsigned int new_need; |
Pavankumar Kondeti | 0824857 | 2017-04-13 15:45:11 +0530 | [diff] [blame] | 555 | s64 now, elapsed; |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 556 | |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 557 | if (unlikely(!cluster->inited)) |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 558 | return 0; |
| 559 | |
| 560 | spin_lock_irqsave(&state_lock, flags); |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 561 | |
Sabyasachi Singh | 9453cb2 | 2017-05-09 18:50:19 -0700 | [diff] [blame] | 562 | if (cluster->boost || !cluster->enable) { |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 563 | need_cpus = cluster->max_cpus; |
| 564 | } else { |
Pavankumar Kondeti | 0824857 | 2017-04-13 15:45:11 +0530 | [diff] [blame] | 565 | cluster->active_cpus = get_active_cpu_count(cluster); |
| 566 | thres_idx = cluster->active_cpus ? cluster->active_cpus - 1 : 0; |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 567 | list_for_each_entry(c, &cluster->lru, sib) { |
Pavankumar Kondeti | eb7e146 | 2017-10-16 13:43:14 +0530 | [diff] [blame] | 568 | bool old_is_busy = c->is_busy; |
| 569 | |
Pavankumar Kondeti | e027bd5 | 2017-10-16 14:09:29 +0530 | [diff] [blame] | 570 | if (c->busy >= cluster->busy_up_thres[thres_idx] || |
| 571 | sched_cpu_high_irqload(c->cpu)) |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 572 | c->is_busy = true; |
| 573 | else if (c->busy < cluster->busy_down_thres[thres_idx]) |
| 574 | c->is_busy = false; |
Pavankumar Kondeti | eb7e146 | 2017-10-16 13:43:14 +0530 | [diff] [blame] | 575 | |
| 576 | trace_core_ctl_set_busy(c->cpu, c->busy, old_is_busy, |
| 577 | c->is_busy); |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 578 | need_cpus += c->is_busy; |
| 579 | } |
| 580 | need_cpus = apply_task_need(cluster, need_cpus); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 581 | } |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 582 | new_need = apply_limits(cluster, need_cpus); |
| 583 | need_flag = adjustment_possible(cluster, new_need); |
| 584 | |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 585 | last_need = cluster->need_cpus; |
Pavankumar Kondeti | 83236e3 | 2017-02-10 09:58:58 +0530 | [diff] [blame] | 586 | now = ktime_to_ms(ktime_get()); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 587 | |
Pavankumar Kondeti | 0824857 | 2017-04-13 15:45:11 +0530 | [diff] [blame] | 588 | if (new_need > cluster->active_cpus) { |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 589 | ret = 1; |
Pavankumar Kondeti | 0824857 | 2017-04-13 15:45:11 +0530 | [diff] [blame] | 590 | } else { |
Pavankumar Kondeti | f7ed52d | 2018-03-13 16:30:12 +0530 | [diff] [blame^] | 591 | /* |
| 592 | * When there is no change in need and there are no more |
| 593 | * active CPUs than currently needed, just update the |
| 594 | * need time stamp and return. |
| 595 | */ |
| 596 | if (new_need == last_need && new_need == cluster->active_cpus) { |
Pavankumar Kondeti | 0824857 | 2017-04-13 15:45:11 +0530 | [diff] [blame] | 597 | cluster->need_ts = now; |
| 598 | spin_unlock_irqrestore(&state_lock, flags); |
| 599 | return 0; |
| 600 | } |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 601 | |
Pavankumar Kondeti | 0824857 | 2017-04-13 15:45:11 +0530 | [diff] [blame] | 602 | elapsed = now - cluster->need_ts; |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 603 | ret = elapsed >= cluster->offline_delay_ms; |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 604 | } |
| 605 | |
Pavankumar Kondeti | 83236e3 | 2017-02-10 09:58:58 +0530 | [diff] [blame] | 606 | if (ret) { |
| 607 | cluster->need_ts = now; |
| 608 | cluster->need_cpus = new_need; |
| 609 | } |
Pavankumar Kondeti | 0824857 | 2017-04-13 15:45:11 +0530 | [diff] [blame] | 610 | trace_core_ctl_eval_need(cluster->first_cpu, last_need, new_need, |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 611 | ret && need_flag); |
| 612 | spin_unlock_irqrestore(&state_lock, flags); |
| 613 | |
| 614 | return ret && need_flag; |
| 615 | } |
| 616 | |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 617 | static void apply_need(struct cluster_data *cluster) |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 618 | { |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 619 | if (eval_need(cluster)) |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 620 | wake_up_core_ctl_thread(cluster); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 621 | } |
| 622 | |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 623 | /* ========================= core count enforcement ==================== */ |
| 624 | |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 625 | static void wake_up_core_ctl_thread(struct cluster_data *cluster) |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 626 | { |
| 627 | unsigned long flags; |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 628 | |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 629 | spin_lock_irqsave(&cluster->pending_lock, flags); |
| 630 | cluster->pending = true; |
| 631 | spin_unlock_irqrestore(&cluster->pending_lock, flags); |
Puja Gupta | 487dec6 | 2017-06-27 10:13:50 -0700 | [diff] [blame] | 632 | wake_up_process(cluster->core_ctl_thread); |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | static u64 core_ctl_check_timestamp; |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 636 | |
Olav Haugan | a024f47 | 2016-10-13 10:34:11 -0700 | [diff] [blame] | 637 | int core_ctl_set_boost(bool boost) |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 638 | { |
| 639 | unsigned int index = 0; |
| 640 | struct cluster_data *cluster; |
Olav Haugan | a024f47 | 2016-10-13 10:34:11 -0700 | [diff] [blame] | 641 | unsigned long flags; |
| 642 | int ret = 0; |
| 643 | bool boost_state_changed = false; |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 644 | |
Pavankumar Kondeti | d198dde | 2017-03-21 14:21:21 +0530 | [diff] [blame] | 645 | if (unlikely(!initialized)) |
| 646 | return 0; |
| 647 | |
Olav Haugan | a024f47 | 2016-10-13 10:34:11 -0700 | [diff] [blame] | 648 | spin_lock_irqsave(&state_lock, flags); |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 649 | for_each_cluster(cluster, index) { |
Pavankumar Kondeti | 35b7977 | 2017-10-05 13:40:00 +0530 | [diff] [blame] | 650 | if (boost) { |
| 651 | boost_state_changed = !cluster->boost; |
| 652 | ++cluster->boost; |
| 653 | } else { |
| 654 | if (!cluster->boost) { |
| 655 | pr_err("Error turning off boost. Boost already turned off\n"); |
| 656 | ret = -EINVAL; |
| 657 | break; |
Olav Haugan | a024f47 | 2016-10-13 10:34:11 -0700 | [diff] [blame] | 658 | } else { |
Pavankumar Kondeti | 35b7977 | 2017-10-05 13:40:00 +0530 | [diff] [blame] | 659 | --cluster->boost; |
| 660 | boost_state_changed = !cluster->boost; |
Olav Haugan | a024f47 | 2016-10-13 10:34:11 -0700 | [diff] [blame] | 661 | } |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 662 | } |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 663 | } |
Olav Haugan | a024f47 | 2016-10-13 10:34:11 -0700 | [diff] [blame] | 664 | spin_unlock_irqrestore(&state_lock, flags); |
| 665 | |
Pavankumar Kondeti | 35b7977 | 2017-10-05 13:40:00 +0530 | [diff] [blame] | 666 | if (boost_state_changed) { |
| 667 | index = 0; |
| 668 | for_each_cluster(cluster, index) |
| 669 | apply_need(cluster); |
| 670 | } |
Olav Haugan | a024f47 | 2016-10-13 10:34:11 -0700 | [diff] [blame] | 671 | |
| 672 | trace_core_ctl_set_boost(cluster->boost, ret); |
| 673 | |
| 674 | return ret; |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 675 | } |
Olav Haugan | 4d77e57 | 2016-11-14 16:14:23 -0800 | [diff] [blame] | 676 | EXPORT_SYMBOL(core_ctl_set_boost); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 677 | |
Syed Rameez Mustafa | 20acfe7 | 2017-01-30 09:35:46 +0530 | [diff] [blame] | 678 | void core_ctl_check(u64 window_start) |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 679 | { |
Syed Rameez Mustafa | 20acfe7 | 2017-01-30 09:35:46 +0530 | [diff] [blame] | 680 | int cpu; |
Syed Rameez Mustafa | 20acfe7 | 2017-01-30 09:35:46 +0530 | [diff] [blame] | 681 | struct cpu_data *c; |
| 682 | struct cluster_data *cluster; |
| 683 | unsigned int index = 0; |
Pavankumar Kondeti | b572a10 | 2017-10-16 14:43:06 +0530 | [diff] [blame] | 684 | unsigned long flags; |
Syed Rameez Mustafa | 20acfe7 | 2017-01-30 09:35:46 +0530 | [diff] [blame] | 685 | |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 686 | if (unlikely(!initialized)) |
| 687 | return; |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 688 | |
Syed Rameez Mustafa | 20acfe7 | 2017-01-30 09:35:46 +0530 | [diff] [blame] | 689 | if (window_start == core_ctl_check_timestamp) |
| 690 | return; |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 691 | |
Syed Rameez Mustafa | 20acfe7 | 2017-01-30 09:35:46 +0530 | [diff] [blame] | 692 | core_ctl_check_timestamp = window_start; |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 693 | |
Pavankumar Kondeti | b572a10 | 2017-10-16 14:43:06 +0530 | [diff] [blame] | 694 | spin_lock_irqsave(&state_lock, flags); |
Syed Rameez Mustafa | 20acfe7 | 2017-01-30 09:35:46 +0530 | [diff] [blame] | 695 | for_each_possible_cpu(cpu) { |
| 696 | |
| 697 | c = &per_cpu(cpu_state, cpu); |
| 698 | cluster = c->cluster; |
| 699 | |
| 700 | if (!cluster || !cluster->inited) |
| 701 | continue; |
| 702 | |
Pavankumar Kondeti | eb7e146 | 2017-10-16 13:43:14 +0530 | [diff] [blame] | 703 | c->busy = sched_get_cpu_util(cpu); |
Syed Rameez Mustafa | 20acfe7 | 2017-01-30 09:35:46 +0530 | [diff] [blame] | 704 | } |
Pavankumar Kondeti | b572a10 | 2017-10-16 14:43:06 +0530 | [diff] [blame] | 705 | spin_unlock_irqrestore(&state_lock, flags); |
Syed Rameez Mustafa | 20acfe7 | 2017-01-30 09:35:46 +0530 | [diff] [blame] | 706 | |
| 707 | update_running_avg(); |
| 708 | |
| 709 | for_each_cluster(cluster, index) { |
| 710 | if (eval_need(cluster)) |
| 711 | wake_up_core_ctl_thread(cluster); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 712 | } |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 713 | } |
| 714 | |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 715 | static void move_cpu_lru(struct cpu_data *cpu_data) |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 716 | { |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 717 | unsigned long flags; |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 718 | |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 719 | spin_lock_irqsave(&state_lock, flags); |
| 720 | list_del(&cpu_data->sib); |
| 721 | list_add_tail(&cpu_data->sib, &cpu_data->cluster->lru); |
| 722 | spin_unlock_irqrestore(&state_lock, flags); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 723 | } |
| 724 | |
Joonwoo Park | bf78570 | 2017-09-26 17:24:22 -0700 | [diff] [blame] | 725 | #ifdef CONFIG_SCHED_CORE_ROTATE |
| 726 | static void cpuset_next(struct cluster_data *cluster) |
| 727 | { |
| 728 | int cpus_needed = cluster->num_cpus - cluster->min_cpus; |
| 729 | |
| 730 | cluster->set_cur++; |
| 731 | cluster->set_cur = min(cluster->set_cur, cluster->set_max); |
| 732 | |
| 733 | /* |
| 734 | * This loop generates bit sets from 0 to pow(num_cpus, 2) - 1. |
| 735 | * We start loop from set_cur to set_cur - 1 and break when weight of |
| 736 | * set_cur equals to cpus_needed. |
| 737 | */ |
| 738 | |
| 739 | while (1) { |
| 740 | if (bitmap_weight(&cluster->set_cur, BITS_PER_LONG) == |
| 741 | cpus_needed) { |
| 742 | break; |
| 743 | } |
| 744 | cluster->set_cur++; |
| 745 | cluster->set_cur = min(cluster->set_cur, cluster->set_max); |
| 746 | if (cluster->set_cur == cluster->set_max) |
| 747 | /* roll over */ |
| 748 | cluster->set_cur = 0; |
| 749 | }; |
| 750 | |
| 751 | pr_debug("first_cpu=%d cpus_needed=%d set_cur=0x%lx\n", |
| 752 | cluster->first_cpu, cpus_needed, cluster->set_cur); |
| 753 | } |
| 754 | |
| 755 | static bool should_we_isolate(int cpu, struct cluster_data *cluster) |
| 756 | { |
| 757 | /* cpu should be part of cluster */ |
| 758 | return !!(cluster->set_cur & (1 << (cpu - cluster->first_cpu))); |
| 759 | } |
| 760 | |
| 761 | static void core_ctl_resume(void) |
| 762 | { |
| 763 | unsigned int i = 0; |
| 764 | struct cluster_data *cluster; |
| 765 | |
| 766 | /* move to next isolation cpu set */ |
| 767 | for_each_cluster(cluster, i) |
| 768 | cpuset_next(cluster); |
| 769 | } |
| 770 | |
| 771 | static struct syscore_ops core_ctl_syscore_ops = { |
| 772 | .resume = core_ctl_resume, |
| 773 | }; |
| 774 | |
| 775 | #else |
| 776 | |
| 777 | static void cpuset_next(struct cluster_data *cluster) { } |
| 778 | |
| 779 | static bool should_we_isolate(int cpu, struct cluster_data *cluster) |
| 780 | { |
| 781 | return true; |
| 782 | } |
| 783 | |
| 784 | #endif |
| 785 | |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 786 | static void try_to_isolate(struct cluster_data *cluster, unsigned int need) |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 787 | { |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 788 | struct cpu_data *c, *tmp; |
Olav Haugan | 8597073 | 2016-11-08 13:45:01 -0800 | [diff] [blame] | 789 | unsigned long flags; |
| 790 | unsigned int num_cpus = cluster->num_cpus; |
Pavankumar Kondeti | 32b2dd0 | 2017-04-13 16:58:57 +0530 | [diff] [blame] | 791 | unsigned int nr_isolated = 0; |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 792 | |
Olav Haugan | 8597073 | 2016-11-08 13:45:01 -0800 | [diff] [blame] | 793 | /* |
| 794 | * Protect against entry being removed (and added at tail) by other |
| 795 | * thread (hotplug). |
| 796 | */ |
| 797 | spin_lock_irqsave(&state_lock, flags); |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 798 | list_for_each_entry_safe(c, tmp, &cluster->lru, sib) { |
Olav Haugan | 8597073 | 2016-11-08 13:45:01 -0800 | [diff] [blame] | 799 | if (!num_cpus--) |
| 800 | break; |
| 801 | |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 802 | if (!is_active(c)) |
| 803 | continue; |
| 804 | if (cluster->active_cpus == need) |
| 805 | break; |
Pavankumar Kondeti | 8a0cb95 | 2017-10-05 14:36:08 +0530 | [diff] [blame] | 806 | /* Don't isolate busy CPUs. */ |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 807 | if (c->is_busy) |
| 808 | continue; |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 809 | |
Pavankumar Kondeti | 8a0cb95 | 2017-10-05 14:36:08 +0530 | [diff] [blame] | 810 | /* |
| 811 | * We isolate only the not_preferred CPUs. If none |
| 812 | * of the CPUs are selected as not_preferred, then |
| 813 | * all CPUs are eligible for isolation. |
| 814 | */ |
| 815 | if (cluster->nr_not_preferred_cpus && !c->not_preferred) |
| 816 | continue; |
| 817 | |
Joonwoo Park | bf78570 | 2017-09-26 17:24:22 -0700 | [diff] [blame] | 818 | if (!should_we_isolate(c->cpu, cluster)) |
| 819 | continue; |
| 820 | |
Olav Haugan | 8597073 | 2016-11-08 13:45:01 -0800 | [diff] [blame] | 821 | spin_unlock_irqrestore(&state_lock, flags); |
| 822 | |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 823 | pr_debug("Trying to isolate CPU%u\n", c->cpu); |
| 824 | if (!sched_isolate_cpu(c->cpu)) { |
| 825 | c->isolated_by_us = true; |
| 826 | move_cpu_lru(c); |
Pavankumar Kondeti | 32b2dd0 | 2017-04-13 16:58:57 +0530 | [diff] [blame] | 827 | nr_isolated++; |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 828 | } else { |
| 829 | pr_debug("Unable to isolate CPU%u\n", c->cpu); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 830 | } |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 831 | cluster->active_cpus = get_active_cpu_count(cluster); |
Olav Haugan | 8597073 | 2016-11-08 13:45:01 -0800 | [diff] [blame] | 832 | spin_lock_irqsave(&state_lock, flags); |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 833 | } |
Pavankumar Kondeti | 32b2dd0 | 2017-04-13 16:58:57 +0530 | [diff] [blame] | 834 | cluster->nr_isolated_cpus += nr_isolated; |
Olav Haugan | 8597073 | 2016-11-08 13:45:01 -0800 | [diff] [blame] | 835 | spin_unlock_irqrestore(&state_lock, flags); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 836 | |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 837 | /* |
| 838 | * If the number of active CPUs is within the limits, then |
| 839 | * don't force isolation of any busy CPUs. |
| 840 | */ |
| 841 | if (cluster->active_cpus <= cluster->max_cpus) |
| 842 | return; |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 843 | |
Pavankumar Kondeti | 32b2dd0 | 2017-04-13 16:58:57 +0530 | [diff] [blame] | 844 | nr_isolated = 0; |
Olav Haugan | 8597073 | 2016-11-08 13:45:01 -0800 | [diff] [blame] | 845 | num_cpus = cluster->num_cpus; |
| 846 | spin_lock_irqsave(&state_lock, flags); |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 847 | list_for_each_entry_safe(c, tmp, &cluster->lru, sib) { |
Olav Haugan | 8597073 | 2016-11-08 13:45:01 -0800 | [diff] [blame] | 848 | if (!num_cpus--) |
| 849 | break; |
| 850 | |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 851 | if (!is_active(c)) |
| 852 | continue; |
| 853 | if (cluster->active_cpus <= cluster->max_cpus) |
| 854 | break; |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 855 | |
Olav Haugan | 8597073 | 2016-11-08 13:45:01 -0800 | [diff] [blame] | 856 | spin_unlock_irqrestore(&state_lock, flags); |
| 857 | |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 858 | pr_debug("Trying to isolate CPU%u\n", c->cpu); |
| 859 | if (!sched_isolate_cpu(c->cpu)) { |
| 860 | c->isolated_by_us = true; |
| 861 | move_cpu_lru(c); |
Pavankumar Kondeti | 32b2dd0 | 2017-04-13 16:58:57 +0530 | [diff] [blame] | 862 | nr_isolated++; |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 863 | } else { |
| 864 | pr_debug("Unable to isolate CPU%u\n", c->cpu); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 865 | } |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 866 | cluster->active_cpus = get_active_cpu_count(cluster); |
Olav Haugan | 8597073 | 2016-11-08 13:45:01 -0800 | [diff] [blame] | 867 | spin_lock_irqsave(&state_lock, flags); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 868 | } |
Pavankumar Kondeti | 32b2dd0 | 2017-04-13 16:58:57 +0530 | [diff] [blame] | 869 | cluster->nr_isolated_cpus += nr_isolated; |
Olav Haugan | 8597073 | 2016-11-08 13:45:01 -0800 | [diff] [blame] | 870 | spin_unlock_irqrestore(&state_lock, flags); |
| 871 | |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 872 | } |
| 873 | |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 874 | static void __try_to_unisolate(struct cluster_data *cluster, |
| 875 | unsigned int need, bool force) |
| 876 | { |
| 877 | struct cpu_data *c, *tmp; |
Olav Haugan | 8597073 | 2016-11-08 13:45:01 -0800 | [diff] [blame] | 878 | unsigned long flags; |
| 879 | unsigned int num_cpus = cluster->num_cpus; |
Pavankumar Kondeti | 32b2dd0 | 2017-04-13 16:58:57 +0530 | [diff] [blame] | 880 | unsigned int nr_unisolated = 0; |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 881 | |
Olav Haugan | 8597073 | 2016-11-08 13:45:01 -0800 | [diff] [blame] | 882 | /* |
| 883 | * Protect against entry being removed (and added at tail) by other |
| 884 | * thread (hotplug). |
| 885 | */ |
| 886 | spin_lock_irqsave(&state_lock, flags); |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 887 | list_for_each_entry_safe(c, tmp, &cluster->lru, sib) { |
Olav Haugan | 8597073 | 2016-11-08 13:45:01 -0800 | [diff] [blame] | 888 | if (!num_cpus--) |
| 889 | break; |
| 890 | |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 891 | if (!c->isolated_by_us) |
| 892 | continue; |
Pavankumar Kondeti | 85dfbfa | 2017-03-17 15:29:13 +0530 | [diff] [blame] | 893 | if ((cpu_online(c->cpu) && !cpu_isolated(c->cpu)) || |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 894 | (!force && c->not_preferred)) |
| 895 | continue; |
| 896 | if (cluster->active_cpus == need) |
| 897 | break; |
| 898 | |
Olav Haugan | 8597073 | 2016-11-08 13:45:01 -0800 | [diff] [blame] | 899 | spin_unlock_irqrestore(&state_lock, flags); |
| 900 | |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 901 | pr_debug("Trying to unisolate CPU%u\n", c->cpu); |
| 902 | if (!sched_unisolate_cpu(c->cpu)) { |
| 903 | c->isolated_by_us = false; |
| 904 | move_cpu_lru(c); |
Pavankumar Kondeti | 32b2dd0 | 2017-04-13 16:58:57 +0530 | [diff] [blame] | 905 | nr_unisolated++; |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 906 | } else { |
| 907 | pr_debug("Unable to unisolate CPU%u\n", c->cpu); |
| 908 | } |
| 909 | cluster->active_cpus = get_active_cpu_count(cluster); |
Olav Haugan | 8597073 | 2016-11-08 13:45:01 -0800 | [diff] [blame] | 910 | spin_lock_irqsave(&state_lock, flags); |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 911 | } |
Pavankumar Kondeti | 32b2dd0 | 2017-04-13 16:58:57 +0530 | [diff] [blame] | 912 | cluster->nr_isolated_cpus -= nr_unisolated; |
Olav Haugan | 8597073 | 2016-11-08 13:45:01 -0800 | [diff] [blame] | 913 | spin_unlock_irqrestore(&state_lock, flags); |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 914 | } |
| 915 | |
| 916 | static void try_to_unisolate(struct cluster_data *cluster, unsigned int need) |
| 917 | { |
| 918 | bool force_use_non_preferred = false; |
| 919 | |
| 920 | __try_to_unisolate(cluster, need, force_use_non_preferred); |
| 921 | |
| 922 | if (cluster->active_cpus == need) |
| 923 | return; |
| 924 | |
| 925 | force_use_non_preferred = true; |
| 926 | __try_to_unisolate(cluster, need, force_use_non_preferred); |
| 927 | } |
| 928 | |
| 929 | static void __ref do_core_ctl(struct cluster_data *cluster) |
| 930 | { |
| 931 | unsigned int need; |
| 932 | |
| 933 | need = apply_limits(cluster, cluster->need_cpus); |
| 934 | |
| 935 | if (adjustment_possible(cluster, need)) { |
| 936 | pr_debug("Trying to adjust group %u from %u to %u\n", |
| 937 | cluster->first_cpu, cluster->active_cpus, need); |
| 938 | |
| 939 | if (cluster->active_cpus > need) |
| 940 | try_to_isolate(cluster, need); |
| 941 | else if (cluster->active_cpus < need) |
| 942 | try_to_unisolate(cluster, need); |
| 943 | } |
| 944 | } |
| 945 | |
| 946 | static int __ref try_core_ctl(void *data) |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 947 | { |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 948 | struct cluster_data *cluster = data; |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 949 | unsigned long flags; |
| 950 | |
| 951 | while (1) { |
| 952 | set_current_state(TASK_INTERRUPTIBLE); |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 953 | spin_lock_irqsave(&cluster->pending_lock, flags); |
| 954 | if (!cluster->pending) { |
| 955 | spin_unlock_irqrestore(&cluster->pending_lock, flags); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 956 | schedule(); |
| 957 | if (kthread_should_stop()) |
| 958 | break; |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 959 | spin_lock_irqsave(&cluster->pending_lock, flags); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 960 | } |
| 961 | set_current_state(TASK_RUNNING); |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 962 | cluster->pending = false; |
| 963 | spin_unlock_irqrestore(&cluster->pending_lock, flags); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 964 | |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 965 | do_core_ctl(cluster); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | return 0; |
| 969 | } |
| 970 | |
Sabyasachi Singh | 518d4abc | 2017-06-26 13:56:47 -0700 | [diff] [blame] | 971 | static int isolation_cpuhp_state(unsigned int cpu, bool online) |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 972 | { |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 973 | struct cpu_data *state = &per_cpu(cpu_state, cpu); |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 974 | struct cluster_data *cluster = state->cluster; |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 975 | unsigned int need; |
Sabyasachi Singh | 518d4abc | 2017-06-26 13:56:47 -0700 | [diff] [blame] | 976 | bool do_wakeup = false, unisolated = false; |
Pavankumar Kondeti | 32b2dd0 | 2017-04-13 16:58:57 +0530 | [diff] [blame] | 977 | unsigned long flags; |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 978 | |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 979 | if (unlikely(!cluster || !cluster->inited)) |
Sabyasachi Singh | 518d4abc | 2017-06-26 13:56:47 -0700 | [diff] [blame] | 980 | return 0; |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 981 | |
Sabyasachi Singh | 518d4abc | 2017-06-26 13:56:47 -0700 | [diff] [blame] | 982 | if (online) { |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 983 | cluster->active_cpus = get_active_cpu_count(cluster); |
| 984 | |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 985 | /* |
| 986 | * Moving to the end of the list should only happen in |
| 987 | * CPU_ONLINE and not on CPU_UP_PREPARE to prevent an |
| 988 | * infinite list traversal when thermal (or other entities) |
| 989 | * reject trying to online CPUs. |
| 990 | */ |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 991 | move_cpu_lru(state); |
Sabyasachi Singh | 518d4abc | 2017-06-26 13:56:47 -0700 | [diff] [blame] | 992 | } else { |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 993 | /* |
| 994 | * We don't want to have a CPU both offline and isolated. |
| 995 | * So unisolate a CPU that went down if it was isolated by us. |
| 996 | */ |
| 997 | if (state->isolated_by_us) { |
| 998 | sched_unisolate_cpu_unlocked(cpu); |
| 999 | state->isolated_by_us = false; |
Pavankumar Kondeti | 32b2dd0 | 2017-04-13 16:58:57 +0530 | [diff] [blame] | 1000 | unisolated = true; |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 1001 | } |
| 1002 | |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 1003 | /* Move a CPU to the end of the LRU when it goes offline. */ |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 1004 | move_cpu_lru(state); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 1005 | |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 1006 | state->busy = 0; |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 1007 | cluster->active_cpus = get_active_cpu_count(cluster); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 1008 | } |
| 1009 | |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 1010 | need = apply_limits(cluster, cluster->need_cpus); |
Pavankumar Kondeti | 32b2dd0 | 2017-04-13 16:58:57 +0530 | [diff] [blame] | 1011 | spin_lock_irqsave(&state_lock, flags); |
| 1012 | if (unisolated) |
| 1013 | cluster->nr_isolated_cpus--; |
| 1014 | do_wakeup = adjustment_possible(cluster, need); |
| 1015 | spin_unlock_irqrestore(&state_lock, flags); |
| 1016 | if (do_wakeup) |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 1017 | wake_up_core_ctl_thread(cluster); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 1018 | |
Sabyasachi Singh | 518d4abc | 2017-06-26 13:56:47 -0700 | [diff] [blame] | 1019 | return 0; |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 1020 | } |
| 1021 | |
Sabyasachi Singh | 518d4abc | 2017-06-26 13:56:47 -0700 | [diff] [blame] | 1022 | static int core_ctl_isolation_online_cpu(unsigned int cpu) |
| 1023 | { |
| 1024 | return isolation_cpuhp_state(cpu, true); |
| 1025 | } |
| 1026 | |
| 1027 | static int core_ctl_isolation_dead_cpu(unsigned int cpu) |
| 1028 | { |
| 1029 | return isolation_cpuhp_state(cpu, false); |
| 1030 | } |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 1031 | |
| 1032 | /* ============================ init code ============================== */ |
| 1033 | |
Pavankumar Kondeti | 1e951a7 | 2017-03-21 14:00:09 +0530 | [diff] [blame] | 1034 | static cpumask_var_t core_ctl_disable_cpumask; |
| 1035 | static bool core_ctl_disable_cpumask_present; |
| 1036 | |
| 1037 | static int __init core_ctl_disable_setup(char *str) |
| 1038 | { |
| 1039 | if (!*str) |
| 1040 | return -EINVAL; |
| 1041 | |
| 1042 | alloc_bootmem_cpumask_var(&core_ctl_disable_cpumask); |
| 1043 | |
| 1044 | if (cpulist_parse(str, core_ctl_disable_cpumask) < 0) { |
| 1045 | free_bootmem_cpumask_var(core_ctl_disable_cpumask); |
| 1046 | return -EINVAL; |
| 1047 | } |
| 1048 | |
| 1049 | core_ctl_disable_cpumask_present = true; |
| 1050 | pr_info("disable_cpumask=%*pbl\n", |
| 1051 | cpumask_pr_args(core_ctl_disable_cpumask)); |
| 1052 | |
| 1053 | return 0; |
| 1054 | } |
| 1055 | early_param("core_ctl_disable_cpumask", core_ctl_disable_setup); |
| 1056 | |
| 1057 | static bool should_skip(const struct cpumask *mask) |
| 1058 | { |
| 1059 | if (!core_ctl_disable_cpumask_present) |
| 1060 | return false; |
| 1061 | |
| 1062 | /* |
| 1063 | * We operate on a cluster basis. Disable the core_ctl for |
| 1064 | * a cluster, if all of it's cpus are specified in |
| 1065 | * core_ctl_disable_cpumask |
| 1066 | */ |
| 1067 | return cpumask_subset(mask, core_ctl_disable_cpumask); |
| 1068 | } |
| 1069 | |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 1070 | static struct cluster_data *find_cluster_by_first_cpu(unsigned int first_cpu) |
| 1071 | { |
| 1072 | unsigned int i; |
| 1073 | |
| 1074 | for (i = 0; i < num_clusters; ++i) { |
| 1075 | if (cluster_state[i].first_cpu == first_cpu) |
| 1076 | return &cluster_state[i]; |
| 1077 | } |
| 1078 | |
| 1079 | return NULL; |
| 1080 | } |
| 1081 | |
| 1082 | static int cluster_init(const struct cpumask *mask) |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 1083 | { |
| 1084 | struct device *dev; |
| 1085 | unsigned int first_cpu = cpumask_first(mask); |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 1086 | struct cluster_data *cluster; |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 1087 | struct cpu_data *state; |
| 1088 | unsigned int cpu; |
| 1089 | struct sched_param param = { .sched_priority = MAX_RT_PRIO-1 }; |
| 1090 | |
Pavankumar Kondeti | 1e951a7 | 2017-03-21 14:00:09 +0530 | [diff] [blame] | 1091 | if (should_skip(mask)) |
| 1092 | return 0; |
| 1093 | |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 1094 | if (find_cluster_by_first_cpu(first_cpu)) |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 1095 | return 0; |
| 1096 | |
| 1097 | dev = get_cpu_device(first_cpu); |
| 1098 | if (!dev) |
| 1099 | return -ENODEV; |
| 1100 | |
| 1101 | pr_info("Creating CPU group %d\n", first_cpu); |
| 1102 | |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 1103 | if (num_clusters == MAX_CLUSTERS) { |
| 1104 | pr_err("Unsupported number of clusters. Only %u supported\n", |
| 1105 | MAX_CLUSTERS); |
| 1106 | return -EINVAL; |
| 1107 | } |
| 1108 | cluster = &cluster_state[num_clusters]; |
| 1109 | ++num_clusters; |
| 1110 | |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 1111 | cpumask_copy(&cluster->cpu_mask, mask); |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 1112 | cluster->num_cpus = cpumask_weight(mask); |
| 1113 | if (cluster->num_cpus > MAX_CPUS_PER_CLUSTER) { |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 1114 | pr_err("HW configuration not supported\n"); |
| 1115 | return -EINVAL; |
| 1116 | } |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 1117 | cluster->first_cpu = first_cpu; |
| 1118 | cluster->min_cpus = 1; |
| 1119 | cluster->max_cpus = cluster->num_cpus; |
| 1120 | cluster->need_cpus = cluster->num_cpus; |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 1121 | cluster->offline_delay_ms = 100; |
| 1122 | cluster->task_thres = UINT_MAX; |
| 1123 | cluster->nrrun = cluster->num_cpus; |
Joonwoo Park | bf78570 | 2017-09-26 17:24:22 -0700 | [diff] [blame] | 1124 | #ifdef CONFIG_SCHED_CORE_ROTATE |
| 1125 | cluster->set_max = cluster->num_cpus * cluster->num_cpus; |
| 1126 | /* by default mark all cpus as eligible */ |
| 1127 | cluster->set_cur = cluster->set_max - 1; |
| 1128 | #endif |
Sabyasachi Singh | 9453cb2 | 2017-05-09 18:50:19 -0700 | [diff] [blame] | 1129 | cluster->enable = true; |
Pavankumar Kondeti | 8a0cb95 | 2017-10-05 14:36:08 +0530 | [diff] [blame] | 1130 | cluster->nr_not_preferred_cpus = 0; |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 1131 | INIT_LIST_HEAD(&cluster->lru); |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 1132 | spin_lock_init(&cluster->pending_lock); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 1133 | |
| 1134 | for_each_cpu(cpu, mask) { |
| 1135 | pr_info("Init CPU%u state\n", cpu); |
| 1136 | |
| 1137 | state = &per_cpu(cpu_state, cpu); |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 1138 | state->cluster = cluster; |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 1139 | state->cpu = cpu; |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 1140 | list_add_tail(&state->sib, &cluster->lru); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 1141 | } |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 1142 | cluster->active_cpus = get_active_cpu_count(cluster); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 1143 | |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 1144 | cluster->core_ctl_thread = kthread_run(try_core_ctl, (void *) cluster, |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 1145 | "core_ctl/%d", first_cpu); |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 1146 | if (IS_ERR(cluster->core_ctl_thread)) |
| 1147 | return PTR_ERR(cluster->core_ctl_thread); |
| 1148 | |
| 1149 | sched_setscheduler_nocheck(cluster->core_ctl_thread, SCHED_FIFO, |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 1150 | ¶m); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 1151 | |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 1152 | cluster->inited = true; |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 1153 | |
Olav Haugan | e3a3db9 | 2016-06-27 11:35:43 -0700 | [diff] [blame] | 1154 | kobject_init(&cluster->kobj, &ktype_core_ctl); |
| 1155 | return kobject_add(&cluster->kobj, &dev->kobj, "core_ctl"); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 1156 | } |
| 1157 | |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 1158 | static int __init core_ctl_init(void) |
| 1159 | { |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 1160 | unsigned int cpu; |
Syed Rameez Mustafa | 20acfe7 | 2017-01-30 09:35:46 +0530 | [diff] [blame] | 1161 | struct cpumask cpus = *cpu_possible_mask; |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 1162 | |
Pavankumar Kondeti | 1e951a7 | 2017-03-21 14:00:09 +0530 | [diff] [blame] | 1163 | if (should_skip(cpu_possible_mask)) |
| 1164 | return 0; |
| 1165 | |
Joonwoo Park | bf78570 | 2017-09-26 17:24:22 -0700 | [diff] [blame] | 1166 | #ifdef CONFIG_SCHED_CORE_ROTATE |
| 1167 | register_syscore_ops(&core_ctl_syscore_ops); |
| 1168 | #endif |
| 1169 | |
Sabyasachi Singh | 518d4abc | 2017-06-26 13:56:47 -0700 | [diff] [blame] | 1170 | cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, |
| 1171 | "core_ctl/isolation:online", |
| 1172 | core_ctl_isolation_online_cpu, NULL); |
| 1173 | |
| 1174 | cpuhp_setup_state_nocalls(CPUHP_CORE_CTL_ISOLATION_DEAD, |
| 1175 | "core_ctl/isolation:dead", |
| 1176 | NULL, core_ctl_isolation_dead_cpu); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 1177 | |
Syed Rameez Mustafa | 20acfe7 | 2017-01-30 09:35:46 +0530 | [diff] [blame] | 1178 | for_each_cpu(cpu, &cpus) { |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 1179 | int ret; |
Syed Rameez Mustafa | 20acfe7 | 2017-01-30 09:35:46 +0530 | [diff] [blame] | 1180 | const struct cpumask *cluster_cpus = cpu_coregroup_mask(cpu); |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 1181 | |
Syed Rameez Mustafa | 20acfe7 | 2017-01-30 09:35:46 +0530 | [diff] [blame] | 1182 | ret = cluster_init(cluster_cpus); |
| 1183 | if (ret) |
| 1184 | pr_warn("unable to create core ctl group: %d\n", ret); |
| 1185 | cpumask_andnot(&cpus, &cpus, cluster_cpus); |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 1186 | } |
Olav Haugan | 833926cb | 2016-06-27 11:38:06 -0700 | [diff] [blame] | 1187 | initialized = true; |
Olav Haugan | 9306c80 | 2016-08-18 17:22:44 -0700 | [diff] [blame] | 1188 | return 0; |
| 1189 | } |
| 1190 | |
| 1191 | late_initcall(core_ctl_init); |