Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 2 | /* |
Peter Zijlstra | 391e43d | 2011-11-15 17:14:39 +0100 | [diff] [blame] | 3 | * kernel/sched/debug.c |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 4 | * |
Ingo Molnar | 325ea10 | 2018-03-03 12:20:47 +0100 | [diff] [blame] | 5 | * Print the CFS rbtree and other debugging details |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 6 | * |
| 7 | * Copyright(C) 2007, Red Hat, Inc., Ingo Molnar |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 8 | */ |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 9 | #include "sched.h" |
| 10 | |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 11 | /* |
| 12 | * This allows printing both to /proc/sched_debug and |
| 13 | * to the console |
| 14 | */ |
| 15 | #define SEQ_printf(m, x...) \ |
| 16 | do { \ |
| 17 | if (m) \ |
| 18 | seq_printf(m, x); \ |
| 19 | else \ |
Joe Lawrence | a8c024c | 2018-03-19 14:35:54 -0400 | [diff] [blame] | 20 | pr_cont(x); \ |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 21 | } while (0) |
| 22 | |
Ingo Molnar | ef83a57 | 2007-10-15 17:00:08 +0200 | [diff] [blame] | 23 | /* |
| 24 | * Ease the printing of nsec fields: |
| 25 | */ |
Ingo Molnar | 90b2628 | 2007-12-30 17:24:35 +0100 | [diff] [blame] | 26 | static long long nsec_high(unsigned long long nsec) |
Ingo Molnar | ef83a57 | 2007-10-15 17:00:08 +0200 | [diff] [blame] | 27 | { |
Ingo Molnar | 90b2628 | 2007-12-30 17:24:35 +0100 | [diff] [blame] | 28 | if ((long long)nsec < 0) { |
Ingo Molnar | ef83a57 | 2007-10-15 17:00:08 +0200 | [diff] [blame] | 29 | nsec = -nsec; |
| 30 | do_div(nsec, 1000000); |
| 31 | return -nsec; |
| 32 | } |
| 33 | do_div(nsec, 1000000); |
| 34 | |
| 35 | return nsec; |
| 36 | } |
| 37 | |
Ingo Molnar | 90b2628 | 2007-12-30 17:24:35 +0100 | [diff] [blame] | 38 | static unsigned long nsec_low(unsigned long long nsec) |
Ingo Molnar | ef83a57 | 2007-10-15 17:00:08 +0200 | [diff] [blame] | 39 | { |
Ingo Molnar | 90b2628 | 2007-12-30 17:24:35 +0100 | [diff] [blame] | 40 | if ((long long)nsec < 0) |
Ingo Molnar | ef83a57 | 2007-10-15 17:00:08 +0200 | [diff] [blame] | 41 | nsec = -nsec; |
| 42 | |
| 43 | return do_div(nsec, 1000000); |
| 44 | } |
| 45 | |
| 46 | #define SPLIT_NS(x) nsec_high(x), nsec_low(x) |
| 47 | |
Steven Rostedt (Red Hat) | d6ca41d | 2016-02-22 16:26:50 -0500 | [diff] [blame] | 48 | #define SCHED_FEAT(name, enabled) \ |
| 49 | #name , |
| 50 | |
| 51 | static const char * const sched_feat_names[] = { |
| 52 | #include "features.h" |
| 53 | }; |
| 54 | |
| 55 | #undef SCHED_FEAT |
| 56 | |
| 57 | static int sched_feat_show(struct seq_file *m, void *v) |
| 58 | { |
| 59 | int i; |
| 60 | |
| 61 | for (i = 0; i < __SCHED_FEAT_NR; i++) { |
| 62 | if (!(sysctl_sched_features & (1UL << i))) |
| 63 | seq_puts(m, "NO_"); |
| 64 | seq_printf(m, "%s ", sched_feat_names[i]); |
| 65 | } |
| 66 | seq_puts(m, "\n"); |
| 67 | |
| 68 | return 0; |
| 69 | } |
| 70 | |
Masahiro Yamada | e9666d1 | 2018-12-31 00:14:15 +0900 | [diff] [blame] | 71 | #ifdef CONFIG_JUMP_LABEL |
Steven Rostedt (Red Hat) | d6ca41d | 2016-02-22 16:26:50 -0500 | [diff] [blame] | 72 | |
| 73 | #define jump_label_key__true STATIC_KEY_INIT_TRUE |
| 74 | #define jump_label_key__false STATIC_KEY_INIT_FALSE |
| 75 | |
| 76 | #define SCHED_FEAT(name, enabled) \ |
| 77 | jump_label_key__##enabled , |
| 78 | |
| 79 | struct static_key sched_feat_keys[__SCHED_FEAT_NR] = { |
| 80 | #include "features.h" |
| 81 | }; |
| 82 | |
| 83 | #undef SCHED_FEAT |
| 84 | |
| 85 | static void sched_feat_disable(int i) |
| 86 | { |
Jiada Wang | e73e819 | 2018-07-31 21:12:22 +0900 | [diff] [blame] | 87 | static_key_disable_cpuslocked(&sched_feat_keys[i]); |
Steven Rostedt (Red Hat) | d6ca41d | 2016-02-22 16:26:50 -0500 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | static void sched_feat_enable(int i) |
| 91 | { |
Jiada Wang | e73e819 | 2018-07-31 21:12:22 +0900 | [diff] [blame] | 92 | static_key_enable_cpuslocked(&sched_feat_keys[i]); |
Steven Rostedt (Red Hat) | d6ca41d | 2016-02-22 16:26:50 -0500 | [diff] [blame] | 93 | } |
| 94 | #else |
| 95 | static void sched_feat_disable(int i) { }; |
| 96 | static void sched_feat_enable(int i) { }; |
Masahiro Yamada | e9666d1 | 2018-12-31 00:14:15 +0900 | [diff] [blame] | 97 | #endif /* CONFIG_JUMP_LABEL */ |
Steven Rostedt (Red Hat) | d6ca41d | 2016-02-22 16:26:50 -0500 | [diff] [blame] | 98 | |
| 99 | static int sched_feat_set(char *cmp) |
| 100 | { |
| 101 | int i; |
| 102 | int neg = 0; |
| 103 | |
| 104 | if (strncmp(cmp, "NO_", 3) == 0) { |
| 105 | neg = 1; |
| 106 | cmp += 3; |
| 107 | } |
| 108 | |
Yisheng Xie | 8f894bf | 2018-05-31 19:11:19 +0800 | [diff] [blame] | 109 | i = match_string(sched_feat_names, __SCHED_FEAT_NR, cmp); |
| 110 | if (i < 0) |
| 111 | return i; |
| 112 | |
| 113 | if (neg) { |
| 114 | sysctl_sched_features &= ~(1UL << i); |
| 115 | sched_feat_disable(i); |
| 116 | } else { |
| 117 | sysctl_sched_features |= (1UL << i); |
| 118 | sched_feat_enable(i); |
Steven Rostedt (Red Hat) | d6ca41d | 2016-02-22 16:26:50 -0500 | [diff] [blame] | 119 | } |
| 120 | |
Yisheng Xie | 8f894bf | 2018-05-31 19:11:19 +0800 | [diff] [blame] | 121 | return 0; |
Steven Rostedt (Red Hat) | d6ca41d | 2016-02-22 16:26:50 -0500 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | static ssize_t |
| 125 | sched_feat_write(struct file *filp, const char __user *ubuf, |
| 126 | size_t cnt, loff_t *ppos) |
| 127 | { |
| 128 | char buf[64]; |
| 129 | char *cmp; |
Yisheng Xie | 8f894bf | 2018-05-31 19:11:19 +0800 | [diff] [blame] | 130 | int ret; |
Steven Rostedt (Red Hat) | d6ca41d | 2016-02-22 16:26:50 -0500 | [diff] [blame] | 131 | struct inode *inode; |
| 132 | |
| 133 | if (cnt > 63) |
| 134 | cnt = 63; |
| 135 | |
| 136 | if (copy_from_user(&buf, ubuf, cnt)) |
| 137 | return -EFAULT; |
| 138 | |
| 139 | buf[cnt] = 0; |
| 140 | cmp = strstrip(buf); |
| 141 | |
| 142 | /* Ensure the static_key remains in a consistent state */ |
| 143 | inode = file_inode(filp); |
Jiada Wang | e73e819 | 2018-07-31 21:12:22 +0900 | [diff] [blame] | 144 | cpus_read_lock(); |
Steven Rostedt (Red Hat) | d6ca41d | 2016-02-22 16:26:50 -0500 | [diff] [blame] | 145 | inode_lock(inode); |
Yisheng Xie | 8f894bf | 2018-05-31 19:11:19 +0800 | [diff] [blame] | 146 | ret = sched_feat_set(cmp); |
Steven Rostedt (Red Hat) | d6ca41d | 2016-02-22 16:26:50 -0500 | [diff] [blame] | 147 | inode_unlock(inode); |
Jiada Wang | e73e819 | 2018-07-31 21:12:22 +0900 | [diff] [blame] | 148 | cpus_read_unlock(); |
Yisheng Xie | 8f894bf | 2018-05-31 19:11:19 +0800 | [diff] [blame] | 149 | if (ret < 0) |
| 150 | return ret; |
Steven Rostedt (Red Hat) | d6ca41d | 2016-02-22 16:26:50 -0500 | [diff] [blame] | 151 | |
| 152 | *ppos += cnt; |
| 153 | |
| 154 | return cnt; |
| 155 | } |
| 156 | |
| 157 | static int sched_feat_open(struct inode *inode, struct file *filp) |
| 158 | { |
| 159 | return single_open(filp, sched_feat_show, NULL); |
| 160 | } |
| 161 | |
| 162 | static const struct file_operations sched_feat_fops = { |
| 163 | .open = sched_feat_open, |
| 164 | .write = sched_feat_write, |
| 165 | .read = seq_read, |
| 166 | .llseek = seq_lseek, |
| 167 | .release = single_release, |
| 168 | }; |
| 169 | |
Peter Zijlstra | 8a99b68 | 2021-03-24 11:43:21 +0100 | [diff] [blame] | 170 | #ifdef CONFIG_SMP |
| 171 | |
| 172 | static ssize_t sched_scaling_write(struct file *filp, const char __user *ubuf, |
| 173 | size_t cnt, loff_t *ppos) |
| 174 | { |
| 175 | char buf[16]; |
Mel Gorman | 7030661 | 2021-09-27 12:46:35 +0100 | [diff] [blame] | 176 | unsigned int scaling; |
Peter Zijlstra | 8a99b68 | 2021-03-24 11:43:21 +0100 | [diff] [blame] | 177 | |
| 178 | if (cnt > 15) |
| 179 | cnt = 15; |
| 180 | |
| 181 | if (copy_from_user(&buf, ubuf, cnt)) |
| 182 | return -EFAULT; |
Mel Gorman | 7030661 | 2021-09-27 12:46:35 +0100 | [diff] [blame] | 183 | buf[cnt] = '\0'; |
Peter Zijlstra | 8a99b68 | 2021-03-24 11:43:21 +0100 | [diff] [blame] | 184 | |
Mel Gorman | 7030661 | 2021-09-27 12:46:35 +0100 | [diff] [blame] | 185 | if (kstrtouint(buf, 10, &scaling)) |
Peter Zijlstra | 8a99b68 | 2021-03-24 11:43:21 +0100 | [diff] [blame] | 186 | return -EINVAL; |
| 187 | |
Mel Gorman | 7030661 | 2021-09-27 12:46:35 +0100 | [diff] [blame] | 188 | if (scaling >= SCHED_TUNABLESCALING_END) |
| 189 | return -EINVAL; |
| 190 | |
| 191 | sysctl_sched_tunable_scaling = scaling; |
Peter Zijlstra | 8a99b68 | 2021-03-24 11:43:21 +0100 | [diff] [blame] | 192 | if (sched_update_scaling()) |
| 193 | return -EINVAL; |
| 194 | |
| 195 | *ppos += cnt; |
| 196 | return cnt; |
| 197 | } |
| 198 | |
| 199 | static int sched_scaling_show(struct seq_file *m, void *v) |
| 200 | { |
| 201 | seq_printf(m, "%d\n", sysctl_sched_tunable_scaling); |
| 202 | return 0; |
| 203 | } |
| 204 | |
| 205 | static int sched_scaling_open(struct inode *inode, struct file *filp) |
| 206 | { |
| 207 | return single_open(filp, sched_scaling_show, NULL); |
| 208 | } |
| 209 | |
| 210 | static const struct file_operations sched_scaling_fops = { |
| 211 | .open = sched_scaling_open, |
| 212 | .write = sched_scaling_write, |
| 213 | .read = seq_read, |
| 214 | .llseek = seq_lseek, |
| 215 | .release = single_release, |
| 216 | }; |
| 217 | |
| 218 | #endif /* SMP */ |
| 219 | |
Peter Zijlstra | 1011dcc | 2021-03-25 12:21:38 +0100 | [diff] [blame] | 220 | #ifdef CONFIG_PREEMPT_DYNAMIC |
| 221 | |
| 222 | static ssize_t sched_dynamic_write(struct file *filp, const char __user *ubuf, |
| 223 | size_t cnt, loff_t *ppos) |
| 224 | { |
| 225 | char buf[16]; |
| 226 | int mode; |
| 227 | |
| 228 | if (cnt > 15) |
| 229 | cnt = 15; |
| 230 | |
| 231 | if (copy_from_user(&buf, ubuf, cnt)) |
| 232 | return -EFAULT; |
| 233 | |
| 234 | buf[cnt] = 0; |
| 235 | mode = sched_dynamic_mode(strstrip(buf)); |
| 236 | if (mode < 0) |
| 237 | return mode; |
| 238 | |
| 239 | sched_dynamic_update(mode); |
| 240 | |
| 241 | *ppos += cnt; |
| 242 | |
| 243 | return cnt; |
| 244 | } |
| 245 | |
| 246 | static int sched_dynamic_show(struct seq_file *m, void *v) |
| 247 | { |
| 248 | static const char * preempt_modes[] = { |
| 249 | "none", "voluntary", "full" |
| 250 | }; |
| 251 | int i; |
| 252 | |
| 253 | for (i = 0; i < ARRAY_SIZE(preempt_modes); i++) { |
| 254 | if (preempt_dynamic_mode == i) |
| 255 | seq_puts(m, "("); |
| 256 | seq_puts(m, preempt_modes[i]); |
| 257 | if (preempt_dynamic_mode == i) |
| 258 | seq_puts(m, ")"); |
| 259 | |
| 260 | seq_puts(m, " "); |
| 261 | } |
| 262 | |
| 263 | seq_puts(m, "\n"); |
| 264 | return 0; |
| 265 | } |
| 266 | |
| 267 | static int sched_dynamic_open(struct inode *inode, struct file *filp) |
| 268 | { |
| 269 | return single_open(filp, sched_dynamic_show, NULL); |
| 270 | } |
| 271 | |
| 272 | static const struct file_operations sched_dynamic_fops = { |
| 273 | .open = sched_dynamic_open, |
| 274 | .write = sched_dynamic_write, |
| 275 | .read = seq_read, |
| 276 | .llseek = seq_lseek, |
| 277 | .release = single_release, |
| 278 | }; |
| 279 | |
| 280 | #endif /* CONFIG_PREEMPT_DYNAMIC */ |
| 281 | |
Peter Zijlstra | 9406415 | 2021-04-15 18:23:17 +0200 | [diff] [blame] | 282 | __read_mostly bool sched_debug_verbose; |
Peter Zijlstra | 9469eb0 | 2017-09-07 17:03:53 +0200 | [diff] [blame] | 283 | |
Peter Zijlstra | d27e9ae | 2021-03-25 15:18:19 +0100 | [diff] [blame] | 284 | static const struct seq_operations sched_debug_sops; |
| 285 | |
| 286 | static int sched_debug_open(struct inode *inode, struct file *filp) |
| 287 | { |
| 288 | return seq_open(filp, &sched_debug_sops); |
| 289 | } |
| 290 | |
| 291 | static const struct file_operations sched_debug_fops = { |
| 292 | .open = sched_debug_open, |
| 293 | .read = seq_read, |
| 294 | .llseek = seq_lseek, |
| 295 | .release = seq_release, |
| 296 | }; |
| 297 | |
Peter Zijlstra | 1011dcc | 2021-03-25 12:21:38 +0100 | [diff] [blame] | 298 | static struct dentry *debugfs_sched; |
Peter Zijlstra | 8a99b68 | 2021-03-24 11:43:21 +0100 | [diff] [blame] | 299 | |
Steven Rostedt (Red Hat) | d6ca41d | 2016-02-22 16:26:50 -0500 | [diff] [blame] | 300 | static __init int sched_init_debug(void) |
| 301 | { |
Peter Zijlstra | 8a99b68 | 2021-03-24 11:43:21 +0100 | [diff] [blame] | 302 | struct dentry __maybe_unused *numa; |
Steven Rostedt (Red Hat) | d6ca41d | 2016-02-22 16:26:50 -0500 | [diff] [blame] | 303 | |
Peter Zijlstra | 8a99b68 | 2021-03-24 11:43:21 +0100 | [diff] [blame] | 304 | debugfs_sched = debugfs_create_dir("sched", NULL); |
| 305 | |
| 306 | debugfs_create_file("features", 0644, debugfs_sched, NULL, &sched_feat_fops); |
Peter Zijlstra | 9406415 | 2021-04-15 18:23:17 +0200 | [diff] [blame] | 307 | debugfs_create_bool("verbose", 0644, debugfs_sched, &sched_debug_verbose); |
Peter Zijlstra | 1011dcc | 2021-03-25 12:21:38 +0100 | [diff] [blame] | 308 | #ifdef CONFIG_PREEMPT_DYNAMIC |
| 309 | debugfs_create_file("preempt", 0644, debugfs_sched, NULL, &sched_dynamic_fops); |
| 310 | #endif |
Peter Zijlstra | 8a99b68 | 2021-03-24 11:43:21 +0100 | [diff] [blame] | 311 | |
| 312 | debugfs_create_u32("latency_ns", 0644, debugfs_sched, &sysctl_sched_latency); |
| 313 | debugfs_create_u32("min_granularity_ns", 0644, debugfs_sched, &sysctl_sched_min_granularity); |
Josh Don | 51ce83e | 2021-08-19 18:04:02 -0700 | [diff] [blame] | 314 | debugfs_create_u32("idle_min_granularity_ns", 0644, debugfs_sched, &sysctl_sched_idle_min_granularity); |
Peter Zijlstra | 8a99b68 | 2021-03-24 11:43:21 +0100 | [diff] [blame] | 315 | debugfs_create_u32("wakeup_granularity_ns", 0644, debugfs_sched, &sysctl_sched_wakeup_granularity); |
| 316 | |
Paul Turner | c006fac | 2021-04-16 14:29:36 -0700 | [diff] [blame] | 317 | debugfs_create_u32("latency_warn_ms", 0644, debugfs_sched, &sysctl_resched_latency_warn_ms); |
| 318 | debugfs_create_u32("latency_warn_once", 0644, debugfs_sched, &sysctl_resched_latency_warn_once); |
| 319 | |
Peter Zijlstra | 8a99b68 | 2021-03-24 11:43:21 +0100 | [diff] [blame] | 320 | #ifdef CONFIG_SMP |
| 321 | debugfs_create_file("tunable_scaling", 0644, debugfs_sched, NULL, &sched_scaling_fops); |
| 322 | debugfs_create_u32("migration_cost_ns", 0644, debugfs_sched, &sysctl_sched_migration_cost); |
| 323 | debugfs_create_u32("nr_migrate", 0644, debugfs_sched, &sysctl_sched_nr_migrate); |
Peter Zijlstra | 3b87f13 | 2021-03-25 11:31:20 +0100 | [diff] [blame] | 324 | |
| 325 | mutex_lock(&sched_domains_mutex); |
| 326 | update_sched_domain_debugfs(); |
| 327 | mutex_unlock(&sched_domains_mutex); |
Peter Zijlstra | 8a99b68 | 2021-03-24 11:43:21 +0100 | [diff] [blame] | 328 | #endif |
| 329 | |
| 330 | #ifdef CONFIG_NUMA_BALANCING |
| 331 | numa = debugfs_create_dir("numa_balancing", debugfs_sched); |
| 332 | |
| 333 | debugfs_create_u32("scan_delay_ms", 0644, numa, &sysctl_numa_balancing_scan_delay); |
| 334 | debugfs_create_u32("scan_period_min_ms", 0644, numa, &sysctl_numa_balancing_scan_period_min); |
| 335 | debugfs_create_u32("scan_period_max_ms", 0644, numa, &sysctl_numa_balancing_scan_period_max); |
| 336 | debugfs_create_u32("scan_size_mb", 0644, numa, &sysctl_numa_balancing_scan_size); |
| 337 | #endif |
Peter Zijlstra | 9469eb0 | 2017-09-07 17:03:53 +0200 | [diff] [blame] | 338 | |
Peter Zijlstra | d27e9ae | 2021-03-25 15:18:19 +0100 | [diff] [blame] | 339 | debugfs_create_file("debug", 0444, debugfs_sched, NULL, &sched_debug_fops); |
| 340 | |
Steven Rostedt (Red Hat) | d6ca41d | 2016-02-22 16:26:50 -0500 | [diff] [blame] | 341 | return 0; |
| 342 | } |
| 343 | late_initcall(sched_init_debug); |
| 344 | |
Steven Rostedt (Red Hat) | 3866e84 | 2016-02-22 16:26:51 -0500 | [diff] [blame] | 345 | #ifdef CONFIG_SMP |
| 346 | |
Peter Zijlstra | 3b87f13 | 2021-03-25 11:31:20 +0100 | [diff] [blame] | 347 | static cpumask_var_t sd_sysctl_cpus; |
| 348 | static struct dentry *sd_dentry; |
Steven Rostedt (Red Hat) | 3866e84 | 2016-02-22 16:26:51 -0500 | [diff] [blame] | 349 | |
Peter Zijlstra | 3b87f13 | 2021-03-25 11:31:20 +0100 | [diff] [blame] | 350 | static int sd_flags_show(struct seq_file *m, void *v) |
Steven Rostedt (Red Hat) | 3866e84 | 2016-02-22 16:26:51 -0500 | [diff] [blame] | 351 | { |
Peter Zijlstra | 3b87f13 | 2021-03-25 11:31:20 +0100 | [diff] [blame] | 352 | unsigned long flags = *(unsigned int *)m->private; |
Valentin Schneider | 5b9f8ff | 2020-08-17 12:29:52 +0100 | [diff] [blame] | 353 | int idx; |
| 354 | |
Valentin Schneider | 5b9f8ff | 2020-08-17 12:29:52 +0100 | [diff] [blame] | 355 | for_each_set_bit(idx, &flags, __SD_FLAG_CNT) { |
Peter Zijlstra | 3b87f13 | 2021-03-25 11:31:20 +0100 | [diff] [blame] | 356 | seq_puts(m, sd_flag_debug[idx].name); |
| 357 | seq_puts(m, " "); |
Valentin Schneider | 5b9f8ff | 2020-08-17 12:29:52 +0100 | [diff] [blame] | 358 | } |
Peter Zijlstra | 3b87f13 | 2021-03-25 11:31:20 +0100 | [diff] [blame] | 359 | seq_puts(m, "\n"); |
Valentin Schneider | 5b9f8ff | 2020-08-17 12:29:52 +0100 | [diff] [blame] | 360 | |
| 361 | return 0; |
| 362 | } |
| 363 | |
Peter Zijlstra | 3b87f13 | 2021-03-25 11:31:20 +0100 | [diff] [blame] | 364 | static int sd_flags_open(struct inode *inode, struct file *file) |
Steven Rostedt (Red Hat) | 3866e84 | 2016-02-22 16:26:51 -0500 | [diff] [blame] | 365 | { |
Peter Zijlstra | 3b87f13 | 2021-03-25 11:31:20 +0100 | [diff] [blame] | 366 | return single_open(file, sd_flags_show, inode->i_private); |
Steven Rostedt (Red Hat) | 3866e84 | 2016-02-22 16:26:51 -0500 | [diff] [blame] | 367 | } |
| 368 | |
Peter Zijlstra | 3b87f13 | 2021-03-25 11:31:20 +0100 | [diff] [blame] | 369 | static const struct file_operations sd_flags_fops = { |
| 370 | .open = sd_flags_open, |
| 371 | .read = seq_read, |
| 372 | .llseek = seq_lseek, |
| 373 | .release = single_release, |
| 374 | }; |
| 375 | |
| 376 | static void register_sd(struct sched_domain *sd, struct dentry *parent) |
Steven Rostedt (Red Hat) | 3866e84 | 2016-02-22 16:26:51 -0500 | [diff] [blame] | 377 | { |
Peter Zijlstra | 3b87f13 | 2021-03-25 11:31:20 +0100 | [diff] [blame] | 378 | #define SDM(type, mode, member) \ |
| 379 | debugfs_create_##type(#member, mode, parent, &sd->member) |
Steven Rostedt (Red Hat) | 3866e84 | 2016-02-22 16:26:51 -0500 | [diff] [blame] | 380 | |
Peter Zijlstra | 3b87f13 | 2021-03-25 11:31:20 +0100 | [diff] [blame] | 381 | SDM(ulong, 0644, min_interval); |
| 382 | SDM(ulong, 0644, max_interval); |
| 383 | SDM(u64, 0644, max_newidle_lb_cost); |
| 384 | SDM(u32, 0644, busy_factor); |
| 385 | SDM(u32, 0644, imbalance_pct); |
| 386 | SDM(u32, 0644, cache_nice_tries); |
| 387 | SDM(str, 0444, name); |
Steven Rostedt (Red Hat) | 3866e84 | 2016-02-22 16:26:51 -0500 | [diff] [blame] | 388 | |
Peter Zijlstra | 3b87f13 | 2021-03-25 11:31:20 +0100 | [diff] [blame] | 389 | #undef SDM |
| 390 | |
| 391 | debugfs_create_file("flags", 0444, parent, &sd->flags, &sd_flags_fops); |
Steven Rostedt (Red Hat) | 3866e84 | 2016-02-22 16:26:51 -0500 | [diff] [blame] | 392 | } |
| 393 | |
Peter Zijlstra | 3b87f13 | 2021-03-25 11:31:20 +0100 | [diff] [blame] | 394 | void update_sched_domain_debugfs(void) |
Steven Rostedt (Red Hat) | 3866e84 | 2016-02-22 16:26:51 -0500 | [diff] [blame] | 395 | { |
Peter Zijlstra | 3b87f13 | 2021-03-25 11:31:20 +0100 | [diff] [blame] | 396 | int cpu, i; |
Peter Zijlstra | bbdacdf | 2017-08-10 17:10:26 +0200 | [diff] [blame] | 397 | |
Valentin Schneider | 459b09b | 2021-05-18 14:07:25 +0100 | [diff] [blame] | 398 | /* |
| 399 | * This can unfortunately be invoked before sched_debug_init() creates |
| 400 | * the debug directory. Don't touch sd_sysctl_cpus until then. |
| 401 | */ |
| 402 | if (!debugfs_sched) |
| 403 | return; |
| 404 | |
Peter Zijlstra | bbdacdf | 2017-08-10 17:10:26 +0200 | [diff] [blame] | 405 | if (!cpumask_available(sd_sysctl_cpus)) { |
| 406 | if (!alloc_cpumask_var(&sd_sysctl_cpus, GFP_KERNEL)) |
| 407 | return; |
Peter Zijlstra | bbdacdf | 2017-08-10 17:10:26 +0200 | [diff] [blame] | 408 | cpumask_copy(sd_sysctl_cpus, cpu_possible_mask); |
| 409 | } |
| 410 | |
Peter Zijlstra | 3b87f13 | 2021-03-25 11:31:20 +0100 | [diff] [blame] | 411 | if (!sd_dentry) |
| 412 | sd_dentry = debugfs_create_dir("domains", debugfs_sched); |
Peter Zijlstra | bbdacdf | 2017-08-10 17:10:26 +0200 | [diff] [blame] | 413 | |
Peter Zijlstra | 3b87f13 | 2021-03-25 11:31:20 +0100 | [diff] [blame] | 414 | for_each_cpu(cpu, sd_sysctl_cpus) { |
| 415 | struct sched_domain *sd; |
| 416 | struct dentry *d_cpu; |
| 417 | char buf[32]; |
Peter Zijlstra | bbdacdf | 2017-08-10 17:10:26 +0200 | [diff] [blame] | 418 | |
Peter Zijlstra | 3b87f13 | 2021-03-25 11:31:20 +0100 | [diff] [blame] | 419 | snprintf(buf, sizeof(buf), "cpu%d", cpu); |
| 420 | debugfs_remove(debugfs_lookup(buf, sd_dentry)); |
| 421 | d_cpu = debugfs_create_dir(buf, sd_dentry); |
| 422 | |
| 423 | i = 0; |
| 424 | for_each_domain(cpu, sd) { |
| 425 | struct dentry *d_sd; |
| 426 | |
| 427 | snprintf(buf, sizeof(buf), "domain%d", i); |
| 428 | d_sd = debugfs_create_dir(buf, d_cpu); |
| 429 | |
| 430 | register_sd(sd, d_sd); |
| 431 | i++; |
Peter Zijlstra | bbdacdf | 2017-08-10 17:10:26 +0200 | [diff] [blame] | 432 | } |
Peter Zijlstra | bbdacdf | 2017-08-10 17:10:26 +0200 | [diff] [blame] | 433 | |
Peter Zijlstra | 3b87f13 | 2021-03-25 11:31:20 +0100 | [diff] [blame] | 434 | __cpumask_clear_cpu(cpu, sd_sysctl_cpus); |
Steven Rostedt (Red Hat) | 3866e84 | 2016-02-22 16:26:51 -0500 | [diff] [blame] | 435 | } |
Steven Rostedt (Red Hat) | 3866e84 | 2016-02-22 16:26:51 -0500 | [diff] [blame] | 436 | } |
| 437 | |
Peter Zijlstra | bbdacdf | 2017-08-10 17:10:26 +0200 | [diff] [blame] | 438 | void dirty_sched_domain_sysctl(int cpu) |
| 439 | { |
| 440 | if (cpumask_available(sd_sysctl_cpus)) |
| 441 | __cpumask_set_cpu(cpu, sd_sysctl_cpus); |
| 442 | } |
| 443 | |
Steven Rostedt (Red Hat) | 3866e84 | 2016-02-22 16:26:51 -0500 | [diff] [blame] | 444 | #endif /* CONFIG_SMP */ |
| 445 | |
Bharata B Rao | ff9b48c | 2008-11-10 21:34:09 +0530 | [diff] [blame] | 446 | #ifdef CONFIG_FAIR_GROUP_SCHED |
Mike Galbraith | 5091faa | 2010-11-30 14:18:03 +0100 | [diff] [blame] | 447 | static void print_cfs_group_stats(struct seq_file *m, int cpu, struct task_group *tg) |
Bharata B Rao | ff9b48c | 2008-11-10 21:34:09 +0530 | [diff] [blame] | 448 | { |
| 449 | struct sched_entity *se = tg->se[cpu]; |
Bharata B Rao | ff9b48c | 2008-11-10 21:34:09 +0530 | [diff] [blame] | 450 | |
Ingo Molnar | 97fb7a0 | 2018-03-03 14:01:12 +0100 | [diff] [blame] | 451 | #define P(F) SEQ_printf(m, " .%-30s: %lld\n", #F, (long long)F) |
Yafang Shao | ceeadb8 | 2021-09-05 14:35:41 +0000 | [diff] [blame] | 452 | #define P_SCHEDSTAT(F) SEQ_printf(m, " .%-30s: %lld\n", \ |
| 453 | #F, (long long)schedstat_val(stats->F)) |
Ingo Molnar | 97fb7a0 | 2018-03-03 14:01:12 +0100 | [diff] [blame] | 454 | #define PN(F) SEQ_printf(m, " .%-30s: %lld.%06ld\n", #F, SPLIT_NS((long long)F)) |
Yafang Shao | ceeadb8 | 2021-09-05 14:35:41 +0000 | [diff] [blame] | 455 | #define PN_SCHEDSTAT(F) SEQ_printf(m, " .%-30s: %lld.%06ld\n", \ |
| 456 | #F, SPLIT_NS((long long)schedstat_val(stats->F))) |
Bharata B Rao | ff9b48c | 2008-11-10 21:34:09 +0530 | [diff] [blame] | 457 | |
Yuyang Du | cd126af | 2015-07-15 08:04:36 +0800 | [diff] [blame] | 458 | if (!se) |
Ben Segall | 18bf280 | 2012-10-04 12:51:20 +0200 | [diff] [blame] | 459 | return; |
Ben Segall | 18bf280 | 2012-10-04 12:51:20 +0200 | [diff] [blame] | 460 | |
Bharata B Rao | ff9b48c | 2008-11-10 21:34:09 +0530 | [diff] [blame] | 461 | PN(se->exec_start); |
| 462 | PN(se->vruntime); |
| 463 | PN(se->sum_exec_runtime); |
Ingo Molnar | 97fb7a0 | 2018-03-03 14:01:12 +0100 | [diff] [blame] | 464 | |
Mel Gorman | cb25176 | 2016-02-05 09:08:36 +0000 | [diff] [blame] | 465 | if (schedstat_enabled()) { |
Peter Zijlstra | 769fdf8 | 2021-10-06 10:12:05 +0200 | [diff] [blame] | 466 | struct sched_statistics *stats; |
| 467 | stats = __schedstats_from_se(se); |
Yafang Shao | ceeadb8 | 2021-09-05 14:35:41 +0000 | [diff] [blame] | 468 | |
| 469 | PN_SCHEDSTAT(wait_start); |
| 470 | PN_SCHEDSTAT(sleep_start); |
| 471 | PN_SCHEDSTAT(block_start); |
| 472 | PN_SCHEDSTAT(sleep_max); |
| 473 | PN_SCHEDSTAT(block_max); |
| 474 | PN_SCHEDSTAT(exec_max); |
| 475 | PN_SCHEDSTAT(slice_max); |
| 476 | PN_SCHEDSTAT(wait_max); |
| 477 | PN_SCHEDSTAT(wait_sum); |
| 478 | P_SCHEDSTAT(wait_count); |
Mel Gorman | cb25176 | 2016-02-05 09:08:36 +0000 | [diff] [blame] | 479 | } |
Ingo Molnar | 97fb7a0 | 2018-03-03 14:01:12 +0100 | [diff] [blame] | 480 | |
Bharata B Rao | ff9b48c | 2008-11-10 21:34:09 +0530 | [diff] [blame] | 481 | P(se->load.weight); |
Paul Turner | 9d85f21 | 2012-10-04 13:18:29 +0200 | [diff] [blame] | 482 | #ifdef CONFIG_SMP |
Yuyang Du | 9d89c25 | 2015-07-15 08:04:37 +0800 | [diff] [blame] | 483 | P(se->avg.load_avg); |
| 484 | P(se->avg.util_avg); |
Vincent Guittot | 9f68395 | 2020-02-24 09:52:18 +0000 | [diff] [blame] | 485 | P(se->avg.runnable_avg); |
Paul Turner | 9d85f21 | 2012-10-04 13:18:29 +0200 | [diff] [blame] | 486 | #endif |
Josh Poimboeuf | 4fa8d29 | 2016-06-17 12:43:26 -0500 | [diff] [blame] | 487 | |
| 488 | #undef PN_SCHEDSTAT |
Bharata B Rao | ff9b48c | 2008-11-10 21:34:09 +0530 | [diff] [blame] | 489 | #undef PN |
Josh Poimboeuf | 4fa8d29 | 2016-06-17 12:43:26 -0500 | [diff] [blame] | 490 | #undef P_SCHEDSTAT |
Bharata B Rao | ff9b48c | 2008-11-10 21:34:09 +0530 | [diff] [blame] | 491 | #undef P |
| 492 | } |
| 493 | #endif |
| 494 | |
Bharata B Rao | efe25c2 | 2011-01-11 15:41:54 +0530 | [diff] [blame] | 495 | #ifdef CONFIG_CGROUP_SCHED |
Waiman Long | ad789f8 | 2021-04-15 15:54:26 -0400 | [diff] [blame] | 496 | static DEFINE_SPINLOCK(sched_debug_lock); |
Bharata B Rao | efe25c2 | 2011-01-11 15:41:54 +0530 | [diff] [blame] | 497 | static char group_path[PATH_MAX]; |
| 498 | |
Waiman Long | ad789f8 | 2021-04-15 15:54:26 -0400 | [diff] [blame] | 499 | static void task_group_path(struct task_group *tg, char *path, int plen) |
Bharata B Rao | efe25c2 | 2011-01-11 15:41:54 +0530 | [diff] [blame] | 500 | { |
Waiman Long | ad789f8 | 2021-04-15 15:54:26 -0400 | [diff] [blame] | 501 | if (autogroup_path(tg, path, plen)) |
| 502 | return; |
Bharata B Rao | 8ecedd7 | 2011-01-11 15:42:57 +0530 | [diff] [blame] | 503 | |
Waiman Long | ad789f8 | 2021-04-15 15:54:26 -0400 | [diff] [blame] | 504 | cgroup_path(tg->css.cgroup, path, plen); |
| 505 | } |
Ingo Molnar | 97fb7a0 | 2018-03-03 14:01:12 +0100 | [diff] [blame] | 506 | |
Waiman Long | ad789f8 | 2021-04-15 15:54:26 -0400 | [diff] [blame] | 507 | /* |
| 508 | * Only 1 SEQ_printf_task_group_path() caller can use the full length |
| 509 | * group_path[] for cgroup path. Other simultaneous callers will have |
| 510 | * to use a shorter stack buffer. A "..." suffix is appended at the end |
| 511 | * of the stack buffer so that it will show up in case the output length |
| 512 | * matches the given buffer size to indicate possible path name truncation. |
| 513 | */ |
| 514 | #define SEQ_printf_task_group_path(m, tg, fmt...) \ |
| 515 | { \ |
| 516 | if (spin_trylock(&sched_debug_lock)) { \ |
| 517 | task_group_path(tg, group_path, sizeof(group_path)); \ |
| 518 | SEQ_printf(m, fmt, group_path); \ |
| 519 | spin_unlock(&sched_debug_lock); \ |
| 520 | } else { \ |
| 521 | char buf[128]; \ |
| 522 | char *bufend = buf + sizeof(buf) - 3; \ |
| 523 | task_group_path(tg, buf, bufend - buf); \ |
| 524 | strcpy(bufend - 1, "..."); \ |
| 525 | SEQ_printf(m, fmt, buf); \ |
| 526 | } \ |
Bharata B Rao | efe25c2 | 2011-01-11 15:41:54 +0530 | [diff] [blame] | 527 | } |
| 528 | #endif |
| 529 | |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 530 | static void |
Ingo Molnar | a48da48 | 2007-08-09 11:16:51 +0200 | [diff] [blame] | 531 | print_task(struct seq_file *m, struct rq *rq, struct task_struct *p) |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 532 | { |
Hui Su | 65bcf07 | 2020-10-31 01:32:23 +0800 | [diff] [blame] | 533 | if (task_current(rq, p)) |
Xie XiuQi | e8c1649 | 2017-08-07 16:44:22 +0800 | [diff] [blame] | 534 | SEQ_printf(m, ">R"); |
Xie XiuQi | 20435d8 | 2017-08-07 16:44:23 +0800 | [diff] [blame] | 535 | else |
| 536 | SEQ_printf(m, " %c", task_state_to_char(p)); |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 537 | |
Xie XiuQi | f080d93 | 2020-04-14 20:57:21 +0800 | [diff] [blame] | 538 | SEQ_printf(m, " %15s %5d %9Ld.%06ld %9Ld %5d ", |
Peter Zijlstra | fc84091 | 2013-09-09 13:01:41 +0200 | [diff] [blame] | 539 | p->comm, task_pid_nr(p), |
Ingo Molnar | ef83a57 | 2007-10-15 17:00:08 +0200 | [diff] [blame] | 540 | SPLIT_NS(p->se.vruntime), |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 541 | (long long)(p->nvcsw + p->nivcsw), |
Al Viro | 6f605d8 | 2007-08-06 04:26:59 +0100 | [diff] [blame] | 542 | p->prio); |
Josh Poimboeuf | 9c57259 | 2016-06-03 17:58:40 -0500 | [diff] [blame] | 543 | |
Yafang Shao | 847fc0c | 2021-09-05 14:35:43 +0000 | [diff] [blame] | 544 | SEQ_printf(m, "%9lld.%06ld %9lld.%06ld %9lld.%06ld %9lld.%06ld", |
Yafang Shao | ceeadb8 | 2021-09-05 14:35:41 +0000 | [diff] [blame] | 545 | SPLIT_NS(schedstat_val_or_zero(p->stats.wait_sum)), |
Srikar Dronamraju | 33d6176 | 2015-06-08 13:40:39 +0530 | [diff] [blame] | 546 | SPLIT_NS(p->se.sum_exec_runtime), |
Yafang Shao | 847fc0c | 2021-09-05 14:35:43 +0000 | [diff] [blame] | 547 | SPLIT_NS(schedstat_val_or_zero(p->stats.sum_sleep_runtime)), |
| 548 | SPLIT_NS(schedstat_val_or_zero(p->stats.sum_block_runtime))); |
Josh Poimboeuf | 9c57259 | 2016-06-03 17:58:40 -0500 | [diff] [blame] | 549 | |
Ingo Molnar | b32e86b | 2013-10-07 11:29:30 +0100 | [diff] [blame] | 550 | #ifdef CONFIG_NUMA_BALANCING |
Srikar Dronamraju | e3d24d0 | 2015-06-25 22:51:42 +0530 | [diff] [blame] | 551 | SEQ_printf(m, " %d %d", task_node(p), task_numa_group_id(p)); |
Ingo Molnar | b32e86b | 2013-10-07 11:29:30 +0100 | [diff] [blame] | 552 | #endif |
Bharata B Rao | efe25c2 | 2011-01-11 15:41:54 +0530 | [diff] [blame] | 553 | #ifdef CONFIG_CGROUP_SCHED |
Waiman Long | ad789f8 | 2021-04-15 15:54:26 -0400 | [diff] [blame] | 554 | SEQ_printf_task_group_path(m, task_group(p), " %s") |
Bharata B Rao | efe25c2 | 2011-01-11 15:41:54 +0530 | [diff] [blame] | 555 | #endif |
Peter Zijlstra | d19ca30 | 2008-04-19 19:45:00 +0200 | [diff] [blame] | 556 | |
Peter Zijlstra | d19ca30 | 2008-04-19 19:45:00 +0200 | [diff] [blame] | 557 | SEQ_printf(m, "\n"); |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 558 | } |
| 559 | |
Ingo Molnar | a48da48 | 2007-08-09 11:16:51 +0200 | [diff] [blame] | 560 | static void print_rq(struct seq_file *m, struct rq *rq, int rq_cpu) |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 561 | { |
| 562 | struct task_struct *g, *p; |
| 563 | |
Joe Lawrence | e9ca267 | 2018-03-19 14:35:55 -0400 | [diff] [blame] | 564 | SEQ_printf(m, "\n"); |
| 565 | SEQ_printf(m, "runnable tasks:\n"); |
Xie XiuQi | f080d93 | 2020-04-14 20:57:21 +0800 | [diff] [blame] | 566 | SEQ_printf(m, " S task PID tree-key switches prio" |
Joe Lawrence | e9ca267 | 2018-03-19 14:35:55 -0400 | [diff] [blame] | 567 | " wait-time sum-exec sum-sleep\n"); |
| 568 | SEQ_printf(m, "-------------------------------------------------------" |
Xie XiuQi | f080d93 | 2020-04-14 20:57:21 +0800 | [diff] [blame] | 569 | "------------------------------------------------------\n"); |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 570 | |
Oleg Nesterov | 5bd96ab | 2014-09-21 21:33:41 +0200 | [diff] [blame] | 571 | rcu_read_lock(); |
Oleg Nesterov | d38e83c | 2014-08-13 21:19:56 +0200 | [diff] [blame] | 572 | for_each_process_thread(g, p) { |
Ingo Molnar | b32e86b | 2013-10-07 11:29:30 +0100 | [diff] [blame] | 573 | if (task_cpu(p) != rq_cpu) |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 574 | continue; |
| 575 | |
Ingo Molnar | a48da48 | 2007-08-09 11:16:51 +0200 | [diff] [blame] | 576 | print_task(m, rq, p); |
Oleg Nesterov | d38e83c | 2014-08-13 21:19:56 +0200 | [diff] [blame] | 577 | } |
Oleg Nesterov | 5bd96ab | 2014-09-21 21:33:41 +0200 | [diff] [blame] | 578 | rcu_read_unlock(); |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 579 | } |
| 580 | |
Ingo Molnar | 5cef9ec | 2007-08-09 11:16:47 +0200 | [diff] [blame] | 581 | void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq) |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 582 | { |
Ingo Molnar | 86d9560 | 2007-10-15 17:00:06 +0200 | [diff] [blame] | 583 | s64 MIN_vruntime = -1, min_vruntime, max_vruntime = -1, |
| 584 | spread, rq0_min_vruntime, spread0; |
Hitoshi Mitake | 348ec61 | 2009-06-17 22:20:55 +0900 | [diff] [blame] | 585 | struct rq *rq = cpu_rq(cpu); |
Ingo Molnar | 67e12ea | 2007-10-15 17:00:05 +0200 | [diff] [blame] | 586 | struct sched_entity *last; |
| 587 | unsigned long flags; |
| 588 | |
Bharata B Rao | efe25c2 | 2011-01-11 15:41:54 +0530 | [diff] [blame] | 589 | #ifdef CONFIG_FAIR_GROUP_SCHED |
Joe Lawrence | e9ca267 | 2018-03-19 14:35:55 -0400 | [diff] [blame] | 590 | SEQ_printf(m, "\n"); |
Waiman Long | ad789f8 | 2021-04-15 15:54:26 -0400 | [diff] [blame] | 591 | SEQ_printf_task_group_path(m, cfs_rq->tg, "cfs_rq[%d]:%s\n", cpu); |
Bharata B Rao | efe25c2 | 2011-01-11 15:41:54 +0530 | [diff] [blame] | 592 | #else |
Joe Lawrence | e9ca267 | 2018-03-19 14:35:55 -0400 | [diff] [blame] | 593 | SEQ_printf(m, "\n"); |
| 594 | SEQ_printf(m, "cfs_rq[%d]:\n", cpu); |
Bharata B Rao | efe25c2 | 2011-01-11 15:41:54 +0530 | [diff] [blame] | 595 | #endif |
Ingo Molnar | ef83a57 | 2007-10-15 17:00:08 +0200 | [diff] [blame] | 596 | SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "exec_clock", |
| 597 | SPLIT_NS(cfs_rq->exec_clock)); |
Ingo Molnar | 67e12ea | 2007-10-15 17:00:05 +0200 | [diff] [blame] | 598 | |
Peter Zijlstra | 5cb9eaa | 2020-11-17 18:19:31 -0500 | [diff] [blame] | 599 | raw_spin_rq_lock_irqsave(rq, flags); |
Davidlohr Bueso | bfb0688 | 2017-09-08 16:14:55 -0700 | [diff] [blame] | 600 | if (rb_first_cached(&cfs_rq->tasks_timeline)) |
Rik van Riel | ac53db5 | 2011-02-01 09:51:03 -0500 | [diff] [blame] | 601 | MIN_vruntime = (__pick_first_entity(cfs_rq))->vruntime; |
Ingo Molnar | 67e12ea | 2007-10-15 17:00:05 +0200 | [diff] [blame] | 602 | last = __pick_last_entity(cfs_rq); |
| 603 | if (last) |
| 604 | max_vruntime = last->vruntime; |
Peter Zijlstra | 5ac5c4d | 2008-11-10 10:46:32 +0100 | [diff] [blame] | 605 | min_vruntime = cfs_rq->min_vruntime; |
Hitoshi Mitake | 348ec61 | 2009-06-17 22:20:55 +0900 | [diff] [blame] | 606 | rq0_min_vruntime = cpu_rq(0)->cfs.min_vruntime; |
Peter Zijlstra | 5cb9eaa | 2020-11-17 18:19:31 -0500 | [diff] [blame] | 607 | raw_spin_rq_unlock_irqrestore(rq, flags); |
Ingo Molnar | ef83a57 | 2007-10-15 17:00:08 +0200 | [diff] [blame] | 608 | SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "MIN_vruntime", |
| 609 | SPLIT_NS(MIN_vruntime)); |
| 610 | SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "min_vruntime", |
| 611 | SPLIT_NS(min_vruntime)); |
| 612 | SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "max_vruntime", |
| 613 | SPLIT_NS(max_vruntime)); |
Ingo Molnar | 67e12ea | 2007-10-15 17:00:05 +0200 | [diff] [blame] | 614 | spread = max_vruntime - MIN_vruntime; |
Ingo Molnar | ef83a57 | 2007-10-15 17:00:08 +0200 | [diff] [blame] | 615 | SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "spread", |
| 616 | SPLIT_NS(spread)); |
Ingo Molnar | 86d9560 | 2007-10-15 17:00:06 +0200 | [diff] [blame] | 617 | spread0 = min_vruntime - rq0_min_vruntime; |
Ingo Molnar | ef83a57 | 2007-10-15 17:00:08 +0200 | [diff] [blame] | 618 | SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "spread0", |
| 619 | SPLIT_NS(spread0)); |
Peter Zijlstra | 5ac5c4d | 2008-11-10 10:46:32 +0100 | [diff] [blame] | 620 | SEQ_printf(m, " .%-30s: %d\n", "nr_spread_over", |
Peter Zijlstra | ddc9729 | 2007-10-15 17:00:10 +0200 | [diff] [blame] | 621 | cfs_rq->nr_spread_over); |
Peter Zijlstra | c82513e | 2012-04-26 13:12:27 +0200 | [diff] [blame] | 622 | SEQ_printf(m, " .%-30s: %d\n", "nr_running", cfs_rq->nr_running); |
Josh Don | 3040003 | 2021-07-29 19:00:18 -0700 | [diff] [blame] | 623 | SEQ_printf(m, " .%-30s: %d\n", "h_nr_running", cfs_rq->h_nr_running); |
Josh Don | a480add | 2021-08-19 18:04:01 -0700 | [diff] [blame] | 624 | SEQ_printf(m, " .%-30s: %d\n", "idle_nr_running", |
| 625 | cfs_rq->idle_nr_running); |
Josh Don | 3040003 | 2021-07-29 19:00:18 -0700 | [diff] [blame] | 626 | SEQ_printf(m, " .%-30s: %d\n", "idle_h_nr_running", |
| 627 | cfs_rq->idle_h_nr_running); |
Peter Zijlstra | 2069dd7 | 2010-11-15 15:47:00 -0800 | [diff] [blame] | 628 | SEQ_printf(m, " .%-30s: %ld\n", "load", cfs_rq->load.weight); |
Peter Zijlstra | c09595f | 2008-06-27 13:41:14 +0200 | [diff] [blame] | 629 | #ifdef CONFIG_SMP |
Yuyang Du | 9d89c25 | 2015-07-15 08:04:37 +0800 | [diff] [blame] | 630 | SEQ_printf(m, " .%-30s: %lu\n", "load_avg", |
| 631 | cfs_rq->avg.load_avg); |
Vincent Guittot | 9f68395 | 2020-02-24 09:52:18 +0000 | [diff] [blame] | 632 | SEQ_printf(m, " .%-30s: %lu\n", "runnable_avg", |
| 633 | cfs_rq->avg.runnable_avg); |
Yuyang Du | 9d89c25 | 2015-07-15 08:04:37 +0800 | [diff] [blame] | 634 | SEQ_printf(m, " .%-30s: %lu\n", "util_avg", |
| 635 | cfs_rq->avg.util_avg); |
Patrick Bellasi | 7f65ea4 | 2018-03-09 09:52:42 +0000 | [diff] [blame] | 636 | SEQ_printf(m, " .%-30s: %u\n", "util_est_enqueued", |
| 637 | cfs_rq->avg.util_est.enqueued); |
Peter Zijlstra | 2a2f5d4e | 2017-05-08 16:51:41 +0200 | [diff] [blame] | 638 | SEQ_printf(m, " .%-30s: %ld\n", "removed.load_avg", |
| 639 | cfs_rq->removed.load_avg); |
| 640 | SEQ_printf(m, " .%-30s: %ld\n", "removed.util_avg", |
| 641 | cfs_rq->removed.util_avg); |
Vincent Guittot | 9f68395 | 2020-02-24 09:52:18 +0000 | [diff] [blame] | 642 | SEQ_printf(m, " .%-30s: %ld\n", "removed.runnable_avg", |
| 643 | cfs_rq->removed.runnable_avg); |
Alex Shi | 333bb86 | 2013-06-28 19:10:35 +0800 | [diff] [blame] | 644 | #ifdef CONFIG_FAIR_GROUP_SCHED |
Yuyang Du | 9d89c25 | 2015-07-15 08:04:37 +0800 | [diff] [blame] | 645 | SEQ_printf(m, " .%-30s: %lu\n", "tg_load_avg_contrib", |
| 646 | cfs_rq->tg_load_avg_contrib); |
Alex Shi | 333bb86 | 2013-06-28 19:10:35 +0800 | [diff] [blame] | 647 | SEQ_printf(m, " .%-30s: %ld\n", "tg_load_avg", |
| 648 | atomic_long_read(&cfs_rq->tg->load_avg)); |
Peter Zijlstra | c09595f | 2008-06-27 13:41:14 +0200 | [diff] [blame] | 649 | #endif |
Alex Shi | 333bb86 | 2013-06-28 19:10:35 +0800 | [diff] [blame] | 650 | #endif |
Ben Segall | f9f9ffc | 2013-10-16 11:16:32 -0700 | [diff] [blame] | 651 | #ifdef CONFIG_CFS_BANDWIDTH |
Ben Segall | f9f9ffc | 2013-10-16 11:16:32 -0700 | [diff] [blame] | 652 | SEQ_printf(m, " .%-30s: %d\n", "throttled", |
| 653 | cfs_rq->throttled); |
| 654 | SEQ_printf(m, " .%-30s: %d\n", "throttle_count", |
| 655 | cfs_rq->throttle_count); |
| 656 | #endif |
Peter Zijlstra | 2069dd7 | 2010-11-15 15:47:00 -0800 | [diff] [blame] | 657 | |
Alex Shi | 333bb86 | 2013-06-28 19:10:35 +0800 | [diff] [blame] | 658 | #ifdef CONFIG_FAIR_GROUP_SCHED |
Bharata B Rao | ff9b48c | 2008-11-10 21:34:09 +0530 | [diff] [blame] | 659 | print_cfs_group_stats(m, cpu, cfs_rq->tg); |
Peter Zijlstra | c09595f | 2008-06-27 13:41:14 +0200 | [diff] [blame] | 660 | #endif |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 661 | } |
| 662 | |
Peter Zijlstra | ada18de | 2008-06-19 14:22:24 +0200 | [diff] [blame] | 663 | void print_rt_rq(struct seq_file *m, int cpu, struct rt_rq *rt_rq) |
| 664 | { |
Bharata B Rao | efe25c2 | 2011-01-11 15:41:54 +0530 | [diff] [blame] | 665 | #ifdef CONFIG_RT_GROUP_SCHED |
Joe Lawrence | e9ca267 | 2018-03-19 14:35:55 -0400 | [diff] [blame] | 666 | SEQ_printf(m, "\n"); |
Waiman Long | ad789f8 | 2021-04-15 15:54:26 -0400 | [diff] [blame] | 667 | SEQ_printf_task_group_path(m, rt_rq->tg, "rt_rq[%d]:%s\n", cpu); |
Bharata B Rao | efe25c2 | 2011-01-11 15:41:54 +0530 | [diff] [blame] | 668 | #else |
Joe Lawrence | e9ca267 | 2018-03-19 14:35:55 -0400 | [diff] [blame] | 669 | SEQ_printf(m, "\n"); |
| 670 | SEQ_printf(m, "rt_rq[%d]:\n", cpu); |
Bharata B Rao | efe25c2 | 2011-01-11 15:41:54 +0530 | [diff] [blame] | 671 | #endif |
Peter Zijlstra | ada18de | 2008-06-19 14:22:24 +0200 | [diff] [blame] | 672 | |
| 673 | #define P(x) \ |
| 674 | SEQ_printf(m, " .%-30s: %Ld\n", #x, (long long)(rt_rq->x)) |
Daniel Bristot de Oliveira | 48365b3 | 2017-06-26 17:07:14 +0200 | [diff] [blame] | 675 | #define PU(x) \ |
| 676 | SEQ_printf(m, " .%-30s: %lu\n", #x, (unsigned long)(rt_rq->x)) |
Peter Zijlstra | ada18de | 2008-06-19 14:22:24 +0200 | [diff] [blame] | 677 | #define PN(x) \ |
| 678 | SEQ_printf(m, " .%-30s: %Ld.%06ld\n", #x, SPLIT_NS(rt_rq->x)) |
| 679 | |
Daniel Bristot de Oliveira | 48365b3 | 2017-06-26 17:07:14 +0200 | [diff] [blame] | 680 | PU(rt_nr_running); |
| 681 | #ifdef CONFIG_SMP |
| 682 | PU(rt_nr_migratory); |
| 683 | #endif |
Peter Zijlstra | ada18de | 2008-06-19 14:22:24 +0200 | [diff] [blame] | 684 | P(rt_throttled); |
| 685 | PN(rt_time); |
| 686 | PN(rt_runtime); |
| 687 | |
| 688 | #undef PN |
Daniel Bristot de Oliveira | 48365b3 | 2017-06-26 17:07:14 +0200 | [diff] [blame] | 689 | #undef PU |
Peter Zijlstra | ada18de | 2008-06-19 14:22:24 +0200 | [diff] [blame] | 690 | #undef P |
| 691 | } |
| 692 | |
Wanpeng Li | acb3213 | 2014-10-31 06:39:33 +0800 | [diff] [blame] | 693 | void print_dl_rq(struct seq_file *m, int cpu, struct dl_rq *dl_rq) |
| 694 | { |
Steven Rostedt (Red Hat) | ef47718 | 2016-02-22 16:26:52 -0500 | [diff] [blame] | 695 | struct dl_bw *dl_bw; |
| 696 | |
Joe Lawrence | e9ca267 | 2018-03-19 14:35:55 -0400 | [diff] [blame] | 697 | SEQ_printf(m, "\n"); |
| 698 | SEQ_printf(m, "dl_rq[%d]:\n", cpu); |
Daniel Bristot de Oliveira | 48365b3 | 2017-06-26 17:07:14 +0200 | [diff] [blame] | 699 | |
| 700 | #define PU(x) \ |
| 701 | SEQ_printf(m, " .%-30s: %lu\n", #x, (unsigned long)(dl_rq->x)) |
| 702 | |
| 703 | PU(dl_nr_running); |
Steven Rostedt (Red Hat) | ef47718 | 2016-02-22 16:26:52 -0500 | [diff] [blame] | 704 | #ifdef CONFIG_SMP |
Daniel Bristot de Oliveira | 48365b3 | 2017-06-26 17:07:14 +0200 | [diff] [blame] | 705 | PU(dl_nr_migratory); |
Steven Rostedt (Red Hat) | ef47718 | 2016-02-22 16:26:52 -0500 | [diff] [blame] | 706 | dl_bw = &cpu_rq(cpu)->rd->dl_bw; |
| 707 | #else |
| 708 | dl_bw = &dl_rq->dl_bw; |
| 709 | #endif |
| 710 | SEQ_printf(m, " .%-30s: %lld\n", "dl_bw->bw", dl_bw->bw); |
| 711 | SEQ_printf(m, " .%-30s: %lld\n", "dl_bw->total_bw", dl_bw->total_bw); |
Daniel Bristot de Oliveira | 48365b3 | 2017-06-26 17:07:14 +0200 | [diff] [blame] | 712 | |
| 713 | #undef PU |
Wanpeng Li | acb3213 | 2014-10-31 06:39:33 +0800 | [diff] [blame] | 714 | } |
| 715 | |
Ingo Molnar | a48da48 | 2007-08-09 11:16:51 +0200 | [diff] [blame] | 716 | static void print_cpu(struct seq_file *m, int cpu) |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 717 | { |
Hitoshi Mitake | 348ec61 | 2009-06-17 22:20:55 +0900 | [diff] [blame] | 718 | struct rq *rq = cpu_rq(cpu); |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 719 | |
| 720 | #ifdef CONFIG_X86 |
| 721 | { |
| 722 | unsigned int freq = cpu_khz ? : 1; |
| 723 | |
Nathan Zimmer | bbbfeac | 2013-02-21 15:15:09 -0800 | [diff] [blame] | 724 | SEQ_printf(m, "cpu#%d, %u.%03u MHz\n", |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 725 | cpu, freq / 1000, (freq % 1000)); |
| 726 | } |
| 727 | #else |
Nathan Zimmer | bbbfeac | 2013-02-21 15:15:09 -0800 | [diff] [blame] | 728 | SEQ_printf(m, "cpu#%d\n", cpu); |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 729 | #endif |
| 730 | |
Peter Zijlstra | 13e099d | 2012-05-14 14:34:00 +0200 | [diff] [blame] | 731 | #define P(x) \ |
| 732 | do { \ |
| 733 | if (sizeof(rq->x) == 4) \ |
| 734 | SEQ_printf(m, " .%-30s: %ld\n", #x, (long)(rq->x)); \ |
| 735 | else \ |
| 736 | SEQ_printf(m, " .%-30s: %Ld\n", #x, (long long)(rq->x));\ |
| 737 | } while (0) |
| 738 | |
Ingo Molnar | ef83a57 | 2007-10-15 17:00:08 +0200 | [diff] [blame] | 739 | #define PN(x) \ |
| 740 | SEQ_printf(m, " .%-30s: %Ld.%06ld\n", #x, SPLIT_NS(rq->x)) |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 741 | |
| 742 | P(nr_running); |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 743 | P(nr_switches); |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 744 | P(nr_uninterruptible); |
Ingo Molnar | ef83a57 | 2007-10-15 17:00:08 +0200 | [diff] [blame] | 745 | PN(next_balance); |
Peter Zijlstra | fc84091 | 2013-09-09 13:01:41 +0200 | [diff] [blame] | 746 | SEQ_printf(m, " .%-30s: %ld\n", "curr->pid", (long)(task_pid_nr(rq->curr))); |
Ingo Molnar | ef83a57 | 2007-10-15 17:00:08 +0200 | [diff] [blame] | 747 | PN(clock); |
Peter Zijlstra | 5a53759 | 2015-01-05 11:18:12 +0100 | [diff] [blame] | 748 | PN(clock_task); |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 749 | #undef P |
Ingo Molnar | ef83a57 | 2007-10-15 17:00:08 +0200 | [diff] [blame] | 750 | #undef PN |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 751 | |
Mike Galbraith | 1b9508f | 2009-11-04 17:53:50 +0100 | [diff] [blame] | 752 | #ifdef CONFIG_SMP |
Wanpeng Li | db6ea2f | 2016-05-03 12:38:25 +0800 | [diff] [blame] | 753 | #define P64(n) SEQ_printf(m, " .%-30s: %Ld\n", #n, rq->n); |
Mike Galbraith | 1b9508f | 2009-11-04 17:53:50 +0100 | [diff] [blame] | 754 | P64(avg_idle); |
Alex Shi | 37e6bae | 2014-01-23 18:39:54 +0800 | [diff] [blame] | 755 | P64(max_idle_balance_cost); |
Wanpeng Li | db6ea2f | 2016-05-03 12:38:25 +0800 | [diff] [blame] | 756 | #undef P64 |
Mike Galbraith | 1b9508f | 2009-11-04 17:53:50 +0100 | [diff] [blame] | 757 | #endif |
Peter Zijlstra | 5ac5c4d | 2008-11-10 10:46:32 +0100 | [diff] [blame] | 758 | |
Josh Poimboeuf | 4fa8d29 | 2016-06-17 12:43:26 -0500 | [diff] [blame] | 759 | #define P(n) SEQ_printf(m, " .%-30s: %d\n", #n, schedstat_val(rq->n)); |
Mel Gorman | cb25176 | 2016-02-05 09:08:36 +0000 | [diff] [blame] | 760 | if (schedstat_enabled()) { |
| 761 | P(yld_count); |
| 762 | P(sched_count); |
| 763 | P(sched_goidle); |
| 764 | P(ttwu_count); |
| 765 | P(ttwu_local); |
| 766 | } |
Peter Zijlstra | 5ac5c4d | 2008-11-10 10:46:32 +0100 | [diff] [blame] | 767 | #undef P |
Josh Poimboeuf | 4fa8d29 | 2016-06-17 12:43:26 -0500 | [diff] [blame] | 768 | |
Ingo Molnar | 5cef9ec | 2007-08-09 11:16:47 +0200 | [diff] [blame] | 769 | print_cfs_stats(m, cpu); |
Peter Zijlstra | ada18de | 2008-06-19 14:22:24 +0200 | [diff] [blame] | 770 | print_rt_stats(m, cpu); |
Wanpeng Li | acb3213 | 2014-10-31 06:39:33 +0800 | [diff] [blame] | 771 | print_dl_stats(m, cpu); |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 772 | |
Ingo Molnar | a48da48 | 2007-08-09 11:16:51 +0200 | [diff] [blame] | 773 | print_rq(m, rq, cpu); |
Nathan Zimmer | bbbfeac | 2013-02-21 15:15:09 -0800 | [diff] [blame] | 774 | SEQ_printf(m, "\n"); |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 775 | } |
| 776 | |
Christian Ehrhardt | 1983a92 | 2009-11-30 12:16:47 +0100 | [diff] [blame] | 777 | static const char *sched_tunable_scaling_names[] = { |
| 778 | "none", |
Colin Ian King | ad2e379 | 2018-11-28 15:23:50 +0000 | [diff] [blame] | 779 | "logarithmic", |
Christian Ehrhardt | 1983a92 | 2009-11-30 12:16:47 +0100 | [diff] [blame] | 780 | "linear" |
| 781 | }; |
| 782 | |
Nathan Zimmer | bbbfeac | 2013-02-21 15:15:09 -0800 | [diff] [blame] | 783 | static void sched_debug_header(struct seq_file *m) |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 784 | { |
Peter Zijlstra | 5bb6b1e | 2010-11-19 21:11:09 +0100 | [diff] [blame] | 785 | u64 ktime, sched_clk, cpu_clk; |
| 786 | unsigned long flags; |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 787 | |
Peter Zijlstra | 5bb6b1e | 2010-11-19 21:11:09 +0100 | [diff] [blame] | 788 | local_irq_save(flags); |
| 789 | ktime = ktime_to_ns(ktime_get()); |
| 790 | sched_clk = sched_clock(); |
| 791 | cpu_clk = local_clock(); |
| 792 | local_irq_restore(flags); |
| 793 | |
Ingo Molnar | b32e86b | 2013-10-07 11:29:30 +0100 | [diff] [blame] | 794 | SEQ_printf(m, "Sched Debug Version: v0.11, %s %.*s\n", |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 795 | init_utsname()->release, |
| 796 | (int)strcspn(init_utsname()->version, " "), |
| 797 | init_utsname()->version); |
| 798 | |
Peter Zijlstra | 5bb6b1e | 2010-11-19 21:11:09 +0100 | [diff] [blame] | 799 | #define P(x) \ |
| 800 | SEQ_printf(m, "%-40s: %Ld\n", #x, (long long)(x)) |
| 801 | #define PN(x) \ |
| 802 | SEQ_printf(m, "%-40s: %Ld.%06ld\n", #x, SPLIT_NS(x)) |
| 803 | PN(ktime); |
| 804 | PN(sched_clk); |
| 805 | PN(cpu_clk); |
| 806 | P(jiffies); |
| 807 | #ifdef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK |
Peter Zijlstra | 35af99e | 2013-11-28 19:38:42 +0100 | [diff] [blame] | 808 | P(sched_clock_stable()); |
Peter Zijlstra | 5bb6b1e | 2010-11-19 21:11:09 +0100 | [diff] [blame] | 809 | #endif |
| 810 | #undef PN |
| 811 | #undef P |
| 812 | |
| 813 | SEQ_printf(m, "\n"); |
| 814 | SEQ_printf(m, "sysctl_sched\n"); |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 815 | |
Ingo Molnar | 1aa4731 | 2007-10-15 17:00:10 +0200 | [diff] [blame] | 816 | #define P(x) \ |
Ingo Molnar | d822cec | 2007-10-15 17:00:10 +0200 | [diff] [blame] | 817 | SEQ_printf(m, " .%-40s: %Ld\n", #x, (long long)(x)) |
Ingo Molnar | 1aa4731 | 2007-10-15 17:00:10 +0200 | [diff] [blame] | 818 | #define PN(x) \ |
Ingo Molnar | d822cec | 2007-10-15 17:00:10 +0200 | [diff] [blame] | 819 | SEQ_printf(m, " .%-40s: %Ld.%06ld\n", #x, SPLIT_NS(x)) |
Ingo Molnar | 1aa4731 | 2007-10-15 17:00:10 +0200 | [diff] [blame] | 820 | PN(sysctl_sched_latency); |
Peter Zijlstra | b2be5e9 | 2007-11-09 22:39:37 +0100 | [diff] [blame] | 821 | PN(sysctl_sched_min_granularity); |
Josh Don | 51ce83e | 2021-08-19 18:04:02 -0700 | [diff] [blame] | 822 | PN(sysctl_sched_idle_min_granularity); |
Ingo Molnar | 1aa4731 | 2007-10-15 17:00:10 +0200 | [diff] [blame] | 823 | PN(sysctl_sched_wakeup_granularity); |
Josh Hunt | eebef74 | 2010-07-19 12:31:16 -0700 | [diff] [blame] | 824 | P(sysctl_sched_child_runs_first); |
Ingo Molnar | 1aa4731 | 2007-10-15 17:00:10 +0200 | [diff] [blame] | 825 | P(sysctl_sched_features); |
| 826 | #undef PN |
| 827 | #undef P |
| 828 | |
Nathan Zimmer | bbbfeac | 2013-02-21 15:15:09 -0800 | [diff] [blame] | 829 | SEQ_printf(m, " .%-40s: %d (%s)\n", |
| 830 | "sysctl_sched_tunable_scaling", |
Christian Ehrhardt | 1983a92 | 2009-11-30 12:16:47 +0100 | [diff] [blame] | 831 | sysctl_sched_tunable_scaling, |
| 832 | sched_tunable_scaling_names[sysctl_sched_tunable_scaling]); |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 833 | SEQ_printf(m, "\n"); |
Nathan Zimmer | bbbfeac | 2013-02-21 15:15:09 -0800 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | static int sched_debug_show(struct seq_file *m, void *v) |
| 837 | { |
| 838 | int cpu = (unsigned long)(v - 2); |
| 839 | |
| 840 | if (cpu != -1) |
| 841 | print_cpu(m, cpu); |
| 842 | else |
| 843 | sched_debug_header(m); |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 844 | |
| 845 | return 0; |
| 846 | } |
| 847 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 848 | void sysrq_sched_debug_show(void) |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 849 | { |
Nathan Zimmer | bbbfeac | 2013-02-21 15:15:09 -0800 | [diff] [blame] | 850 | int cpu; |
| 851 | |
| 852 | sched_debug_header(NULL); |
Wei Li | 02d4ac5 | 2019-12-26 16:52:24 +0800 | [diff] [blame] | 853 | for_each_online_cpu(cpu) { |
| 854 | /* |
| 855 | * Need to reset softlockup watchdogs on all CPUs, because |
| 856 | * another CPU might be blocked waiting for us to process |
| 857 | * an IPI or stop_machine. |
| 858 | */ |
| 859 | touch_nmi_watchdog(); |
| 860 | touch_all_softlockup_watchdogs(); |
Nathan Zimmer | bbbfeac | 2013-02-21 15:15:09 -0800 | [diff] [blame] | 861 | print_cpu(NULL, cpu); |
Wei Li | 02d4ac5 | 2019-12-26 16:52:24 +0800 | [diff] [blame] | 862 | } |
Nathan Zimmer | bbbfeac | 2013-02-21 15:15:09 -0800 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | /* |
Ingo Molnar | 3b03706 | 2021-03-18 13:38:50 +0100 | [diff] [blame] | 866 | * This iterator needs some explanation. |
Nathan Zimmer | bbbfeac | 2013-02-21 15:15:09 -0800 | [diff] [blame] | 867 | * It returns 1 for the header position. |
Ingo Molnar | 97fb7a0 | 2018-03-03 14:01:12 +0100 | [diff] [blame] | 868 | * This means 2 is CPU 0. |
| 869 | * In a hotplugged system some CPUs, including CPU 0, may be missing so we have |
| 870 | * to use cpumask_* to iterate over the CPUs. |
Nathan Zimmer | bbbfeac | 2013-02-21 15:15:09 -0800 | [diff] [blame] | 871 | */ |
| 872 | static void *sched_debug_start(struct seq_file *file, loff_t *offset) |
| 873 | { |
| 874 | unsigned long n = *offset; |
| 875 | |
| 876 | if (n == 0) |
| 877 | return (void *) 1; |
| 878 | |
| 879 | n--; |
| 880 | |
| 881 | if (n > 0) |
| 882 | n = cpumask_next(n - 1, cpu_online_mask); |
| 883 | else |
| 884 | n = cpumask_first(cpu_online_mask); |
| 885 | |
| 886 | *offset = n + 1; |
| 887 | |
| 888 | if (n < nr_cpu_ids) |
| 889 | return (void *)(unsigned long)(n + 2); |
Ingo Molnar | 97fb7a0 | 2018-03-03 14:01:12 +0100 | [diff] [blame] | 890 | |
Nathan Zimmer | bbbfeac | 2013-02-21 15:15:09 -0800 | [diff] [blame] | 891 | return NULL; |
| 892 | } |
| 893 | |
| 894 | static void *sched_debug_next(struct seq_file *file, void *data, loff_t *offset) |
| 895 | { |
| 896 | (*offset)++; |
| 897 | return sched_debug_start(file, offset); |
| 898 | } |
| 899 | |
| 900 | static void sched_debug_stop(struct seq_file *file, void *data) |
| 901 | { |
| 902 | } |
| 903 | |
| 904 | static const struct seq_operations sched_debug_sops = { |
Ingo Molnar | 97fb7a0 | 2018-03-03 14:01:12 +0100 | [diff] [blame] | 905 | .start = sched_debug_start, |
| 906 | .next = sched_debug_next, |
| 907 | .stop = sched_debug_stop, |
| 908 | .show = sched_debug_show, |
Nathan Zimmer | bbbfeac | 2013-02-21 15:15:09 -0800 | [diff] [blame] | 909 | }; |
| 910 | |
Valentin Schneider | 9e3bf94 | 2020-02-26 12:45:42 +0000 | [diff] [blame] | 911 | #define __PS(S, F) SEQ_printf(m, "%-45s:%21Ld\n", S, (long long)(F)) |
| 912 | #define __P(F) __PS(#F, F) |
| 913 | #define P(F) __PS(#F, p->F) |
Dietmar Eggemann | 68d7a19 | 2021-06-02 16:58:08 +0200 | [diff] [blame] | 914 | #define PM(F, M) __PS(#F, p->F & (M)) |
Valentin Schneider | 9e3bf94 | 2020-02-26 12:45:42 +0000 | [diff] [blame] | 915 | #define __PSN(S, F) SEQ_printf(m, "%-45s:%14Ld.%06ld\n", S, SPLIT_NS((long long)(F))) |
| 916 | #define __PN(F) __PSN(#F, F) |
| 917 | #define PN(F) __PSN(#F, p->F) |
Ingo Molnar | b32e86b | 2013-10-07 11:29:30 +0100 | [diff] [blame] | 918 | |
| 919 | |
Srikar Dronamraju | 397f237 | 2015-06-25 22:51:43 +0530 | [diff] [blame] | 920 | #ifdef CONFIG_NUMA_BALANCING |
| 921 | void print_numa_stats(struct seq_file *m, int node, unsigned long tsf, |
| 922 | unsigned long tpf, unsigned long gsf, unsigned long gpf) |
| 923 | { |
| 924 | SEQ_printf(m, "numa_faults node=%d ", node); |
Srikar Dronamraju | 67d9f6c25 | 2018-06-20 22:32:47 +0530 | [diff] [blame] | 925 | SEQ_printf(m, "task_private=%lu task_shared=%lu ", tpf, tsf); |
| 926 | SEQ_printf(m, "group_private=%lu group_shared=%lu\n", gpf, gsf); |
Srikar Dronamraju | 397f237 | 2015-06-25 22:51:43 +0530 | [diff] [blame] | 927 | } |
| 928 | #endif |
| 929 | |
| 930 | |
Ingo Molnar | b32e86b | 2013-10-07 11:29:30 +0100 | [diff] [blame] | 931 | static void sched_show_numa(struct task_struct *p, struct seq_file *m) |
| 932 | { |
| 933 | #ifdef CONFIG_NUMA_BALANCING |
| 934 | struct mempolicy *pol; |
Ingo Molnar | b32e86b | 2013-10-07 11:29:30 +0100 | [diff] [blame] | 935 | |
| 936 | if (p->mm) |
| 937 | P(mm->numa_scan_seq); |
| 938 | |
| 939 | task_lock(p); |
| 940 | pol = p->mempolicy; |
| 941 | if (pol && !(pol->flags & MPOL_F_MORON)) |
| 942 | pol = NULL; |
| 943 | mpol_get(pol); |
| 944 | task_unlock(p); |
| 945 | |
Srikar Dronamraju | 397f237 | 2015-06-25 22:51:43 +0530 | [diff] [blame] | 946 | P(numa_pages_migrated); |
| 947 | P(numa_preferred_nid); |
| 948 | P(total_numa_faults); |
| 949 | SEQ_printf(m, "current_node=%d, numa_group_id=%d\n", |
| 950 | task_node(p), task_numa_group_id(p)); |
| 951 | show_numa_stats(p, m); |
Ingo Molnar | b32e86b | 2013-10-07 11:29:30 +0100 | [diff] [blame] | 952 | mpol_put(pol); |
| 953 | #endif |
| 954 | } |
| 955 | |
Aleksa Sarai | 74dc338 | 2017-08-06 14:41:41 +1000 | [diff] [blame] | 956 | void proc_sched_show_task(struct task_struct *p, struct pid_namespace *ns, |
| 957 | struct seq_file *m) |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 958 | { |
Ingo Molnar | cc36773 | 2007-10-15 17:00:18 +0200 | [diff] [blame] | 959 | unsigned long nr_switches; |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 960 | |
Aleksa Sarai | 74dc338 | 2017-08-06 14:41:41 +1000 | [diff] [blame] | 961 | SEQ_printf(m, "%s (%d, #threads: %d)\n", p->comm, task_pid_nr_ns(p, ns), |
Oleg Nesterov | 5089a97 | 2010-05-26 14:43:22 -0700 | [diff] [blame] | 962 | get_nr_threads(p)); |
Ingo Molnar | 2d92f22 | 2007-10-15 17:00:18 +0200 | [diff] [blame] | 963 | SEQ_printf(m, |
Kamalesh Babulal | add332a | 2013-06-27 22:20:05 +0530 | [diff] [blame] | 964 | "---------------------------------------------------------" |
| 965 | "----------\n"); |
Valentin Schneider | 9e3bf94 | 2020-02-26 12:45:42 +0000 | [diff] [blame] | 966 | |
Yafang Shao | ceeadb8 | 2021-09-05 14:35:41 +0000 | [diff] [blame] | 967 | #define P_SCHEDSTAT(F) __PS(#F, schedstat_val(p->stats.F)) |
| 968 | #define PN_SCHEDSTAT(F) __PSN(#F, schedstat_val(p->stats.F)) |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 969 | |
Ingo Molnar | ef83a57 | 2007-10-15 17:00:08 +0200 | [diff] [blame] | 970 | PN(se.exec_start); |
| 971 | PN(se.vruntime); |
| 972 | PN(se.sum_exec_runtime); |
Ingo Molnar | 6cfb0d5 | 2007-08-02 17:41:40 +0200 | [diff] [blame] | 973 | |
Ingo Molnar | cc36773 | 2007-10-15 17:00:18 +0200 | [diff] [blame] | 974 | nr_switches = p->nvcsw + p->nivcsw; |
| 975 | |
Ingo Molnar | cc36773 | 2007-10-15 17:00:18 +0200 | [diff] [blame] | 976 | P(se.nr_migrations); |
Ingo Molnar | cc36773 | 2007-10-15 17:00:18 +0200 | [diff] [blame] | 977 | |
Mel Gorman | cb25176 | 2016-02-05 09:08:36 +0000 | [diff] [blame] | 978 | if (schedstat_enabled()) { |
Ingo Molnar | cc36773 | 2007-10-15 17:00:18 +0200 | [diff] [blame] | 979 | u64 avg_atom, avg_per_cpu; |
| 980 | |
Yafang Shao | ceeadb8 | 2021-09-05 14:35:41 +0000 | [diff] [blame] | 981 | PN_SCHEDSTAT(sum_sleep_runtime); |
Yafang Shao | 847fc0c | 2021-09-05 14:35:43 +0000 | [diff] [blame] | 982 | PN_SCHEDSTAT(sum_block_runtime); |
Yafang Shao | ceeadb8 | 2021-09-05 14:35:41 +0000 | [diff] [blame] | 983 | PN_SCHEDSTAT(wait_start); |
| 984 | PN_SCHEDSTAT(sleep_start); |
| 985 | PN_SCHEDSTAT(block_start); |
| 986 | PN_SCHEDSTAT(sleep_max); |
| 987 | PN_SCHEDSTAT(block_max); |
| 988 | PN_SCHEDSTAT(exec_max); |
| 989 | PN_SCHEDSTAT(slice_max); |
| 990 | PN_SCHEDSTAT(wait_max); |
| 991 | PN_SCHEDSTAT(wait_sum); |
| 992 | P_SCHEDSTAT(wait_count); |
| 993 | PN_SCHEDSTAT(iowait_sum); |
| 994 | P_SCHEDSTAT(iowait_count); |
| 995 | P_SCHEDSTAT(nr_migrations_cold); |
| 996 | P_SCHEDSTAT(nr_failed_migrations_affine); |
| 997 | P_SCHEDSTAT(nr_failed_migrations_running); |
| 998 | P_SCHEDSTAT(nr_failed_migrations_hot); |
| 999 | P_SCHEDSTAT(nr_forced_migrations); |
| 1000 | P_SCHEDSTAT(nr_wakeups); |
| 1001 | P_SCHEDSTAT(nr_wakeups_sync); |
| 1002 | P_SCHEDSTAT(nr_wakeups_migrate); |
| 1003 | P_SCHEDSTAT(nr_wakeups_local); |
| 1004 | P_SCHEDSTAT(nr_wakeups_remote); |
| 1005 | P_SCHEDSTAT(nr_wakeups_affine); |
| 1006 | P_SCHEDSTAT(nr_wakeups_affine_attempts); |
| 1007 | P_SCHEDSTAT(nr_wakeups_passive); |
| 1008 | P_SCHEDSTAT(nr_wakeups_idle); |
Mel Gorman | cb25176 | 2016-02-05 09:08:36 +0000 | [diff] [blame] | 1009 | |
Ingo Molnar | cc36773 | 2007-10-15 17:00:18 +0200 | [diff] [blame] | 1010 | avg_atom = p->se.sum_exec_runtime; |
| 1011 | if (nr_switches) |
Mateusz Guzik | b0ab99e | 2014-06-14 15:00:09 +0200 | [diff] [blame] | 1012 | avg_atom = div64_ul(avg_atom, nr_switches); |
Ingo Molnar | cc36773 | 2007-10-15 17:00:18 +0200 | [diff] [blame] | 1013 | else |
| 1014 | avg_atom = -1LL; |
| 1015 | |
| 1016 | avg_per_cpu = p->se.sum_exec_runtime; |
Ingo Molnar | c1a8974 | 2007-11-28 15:52:56 +0100 | [diff] [blame] | 1017 | if (p->se.nr_migrations) { |
Roman Zippel | 6f6d6a1 | 2008-05-01 04:34:28 -0700 | [diff] [blame] | 1018 | avg_per_cpu = div64_u64(avg_per_cpu, |
| 1019 | p->se.nr_migrations); |
Ingo Molnar | c1a8974 | 2007-11-28 15:52:56 +0100 | [diff] [blame] | 1020 | } else { |
Ingo Molnar | cc36773 | 2007-10-15 17:00:18 +0200 | [diff] [blame] | 1021 | avg_per_cpu = -1LL; |
Ingo Molnar | c1a8974 | 2007-11-28 15:52:56 +0100 | [diff] [blame] | 1022 | } |
Ingo Molnar | cc36773 | 2007-10-15 17:00:18 +0200 | [diff] [blame] | 1023 | |
| 1024 | __PN(avg_atom); |
| 1025 | __PN(avg_per_cpu); |
| 1026 | } |
Josh Poimboeuf | 4fa8d29 | 2016-06-17 12:43:26 -0500 | [diff] [blame] | 1027 | |
Ingo Molnar | cc36773 | 2007-10-15 17:00:18 +0200 | [diff] [blame] | 1028 | __P(nr_switches); |
Valentin Schneider | 9e3bf94 | 2020-02-26 12:45:42 +0000 | [diff] [blame] | 1029 | __PS("nr_voluntary_switches", p->nvcsw); |
| 1030 | __PS("nr_involuntary_switches", p->nivcsw); |
Ingo Molnar | cc36773 | 2007-10-15 17:00:18 +0200 | [diff] [blame] | 1031 | |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 1032 | P(se.load.weight); |
Alex Shi | 333bb86 | 2013-06-28 19:10:35 +0800 | [diff] [blame] | 1033 | #ifdef CONFIG_SMP |
Yuyang Du | 9d89c25 | 2015-07-15 08:04:37 +0800 | [diff] [blame] | 1034 | P(se.avg.load_sum); |
Vincent Guittot | 9f68395 | 2020-02-24 09:52:18 +0000 | [diff] [blame] | 1035 | P(se.avg.runnable_sum); |
Yuyang Du | 9d89c25 | 2015-07-15 08:04:37 +0800 | [diff] [blame] | 1036 | P(se.avg.util_sum); |
| 1037 | P(se.avg.load_avg); |
Vincent Guittot | 9f68395 | 2020-02-24 09:52:18 +0000 | [diff] [blame] | 1038 | P(se.avg.runnable_avg); |
Yuyang Du | 9d89c25 | 2015-07-15 08:04:37 +0800 | [diff] [blame] | 1039 | P(se.avg.util_avg); |
| 1040 | P(se.avg.last_update_time); |
Patrick Bellasi | 7f65ea4 | 2018-03-09 09:52:42 +0000 | [diff] [blame] | 1041 | P(se.avg.util_est.ewma); |
Dietmar Eggemann | 68d7a19 | 2021-06-02 16:58:08 +0200 | [diff] [blame] | 1042 | PM(se.avg.util_est.enqueued, ~UTIL_AVG_UNCHANGED); |
Kamalesh Babulal | 939fd73 | 2013-06-25 13:33:36 +0530 | [diff] [blame] | 1043 | #endif |
Valentin Schneider | 96e74eb | 2020-02-26 12:45:43 +0000 | [diff] [blame] | 1044 | #ifdef CONFIG_UCLAMP_TASK |
Pavankumar Kondeti | ad32bb4 | 2020-05-10 18:26:41 +0530 | [diff] [blame] | 1045 | __PS("uclamp.min", p->uclamp_req[UCLAMP_MIN].value); |
| 1046 | __PS("uclamp.max", p->uclamp_req[UCLAMP_MAX].value); |
Valentin Schneider | 96e74eb | 2020-02-26 12:45:43 +0000 | [diff] [blame] | 1047 | __PS("effective uclamp.min", uclamp_eff_value(p, UCLAMP_MIN)); |
| 1048 | __PS("effective uclamp.max", uclamp_eff_value(p, UCLAMP_MAX)); |
| 1049 | #endif |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 1050 | P(policy); |
| 1051 | P(prio); |
Viresh Kumar | 1da1843 | 2018-11-05 16:51:55 +0530 | [diff] [blame] | 1052 | if (task_has_dl_policy(p)) { |
Tommaso Cucinotta | 59f8c29 | 2016-10-26 11:17:17 +0200 | [diff] [blame] | 1053 | P(dl.runtime); |
| 1054 | P(dl.deadline); |
| 1055 | } |
Josh Poimboeuf | 4fa8d29 | 2016-06-17 12:43:26 -0500 | [diff] [blame] | 1056 | #undef PN_SCHEDSTAT |
Josh Poimboeuf | 4fa8d29 | 2016-06-17 12:43:26 -0500 | [diff] [blame] | 1057 | #undef P_SCHEDSTAT |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 1058 | |
| 1059 | { |
Ingo Molnar | 29d7b90 | 2008-11-16 08:07:15 +0100 | [diff] [blame] | 1060 | unsigned int this_cpu = raw_smp_processor_id(); |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 1061 | u64 t0, t1; |
| 1062 | |
Ingo Molnar | 29d7b90 | 2008-11-16 08:07:15 +0100 | [diff] [blame] | 1063 | t0 = cpu_clock(this_cpu); |
| 1064 | t1 = cpu_clock(this_cpu); |
Valentin Schneider | 9e3bf94 | 2020-02-26 12:45:42 +0000 | [diff] [blame] | 1065 | __PS("clock-delta", t1-t0); |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 1066 | } |
Ingo Molnar | b32e86b | 2013-10-07 11:29:30 +0100 | [diff] [blame] | 1067 | |
| 1068 | sched_show_numa(p, m); |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 1069 | } |
| 1070 | |
| 1071 | void proc_sched_set_task(struct task_struct *p) |
| 1072 | { |
Ingo Molnar | 6cfb0d5 | 2007-08-02 17:41:40 +0200 | [diff] [blame] | 1073 | #ifdef CONFIG_SCHEDSTATS |
Yafang Shao | ceeadb8 | 2021-09-05 14:35:41 +0000 | [diff] [blame] | 1074 | memset(&p->stats, 0, sizeof(p->stats)); |
Ingo Molnar | 6cfb0d5 | 2007-08-02 17:41:40 +0200 | [diff] [blame] | 1075 | #endif |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 1076 | } |
Paul Turner | c006fac | 2021-04-16 14:29:36 -0700 | [diff] [blame] | 1077 | |
| 1078 | void resched_latency_warn(int cpu, u64 latency) |
| 1079 | { |
| 1080 | static DEFINE_RATELIMIT_STATE(latency_check_ratelimit, 60 * 60 * HZ, 1); |
| 1081 | |
| 1082 | WARN(__ratelimit(&latency_check_ratelimit), |
| 1083 | "sched: CPU %d need_resched set for > %llu ns (%d ticks) " |
| 1084 | "without schedule\n", |
| 1085 | cpu, latency, cpu_rq(cpu)->ticks_without_resched); |
| 1086 | } |