| 1 | |
| 2 | |
| 3 | * kernel/sched/debug.c
|
| 4 | *
|
| 5 | * Print the CFS rbtree and other debugging details
|
| 6 | *
|
| 7 | * Copyright(C) 2007, Red Hat, Inc., Ingo Molnar
|
| 8 |
|
| 9 | #include <linux/debugfs.h>
|
| 10 | #include <linux/nmi.h>
|
| 11 | #include <linux/log2.h>
|
| 12 | #include "sched.h"
|
| 13 |
|
| 14 | |
| 15 | * This allows printing both to /sys/kernel/debug/sched/debug and
|
| 16 | * to the console
|
| 17 |
|
| 18 | #define SEQ_printf(m, x...) \
|
| 19 | do { \
|
| 20 | if (m) \
|
| 21 | seq_printf(m, x); \
|
| 22 | else \
|
| 23 | pr_cont(x); \
|
| 24 | } while (0)
|
| 25 |
|
| 26 | |
| 27 | * Ease the printing of nsec fields:
|
| 28 |
|
| 29 | static long long nsec_high(unsigned long long nsec)
|
| 30 | {
|
| 31 | if ((long long)nsec < 0) {
|
| 32 | nsec = -nsec;
|
| 33 | do_div(nsec, 1000000);
|
| 34 | return -nsec;
|
| 35 | }
|
| 36 | do_div(nsec, 1000000);
|
| 37 |
|
| 38 | return nsec;
|
| 39 | }
|
| 40 |
|
| 41 | static unsigned long nsec_low(unsigned long long nsec)
|
| 42 | {
|
| 43 | if ((long long)nsec < 0)
|
| 44 | nsec = -nsec;
|
| 45 |
|
| 46 | return do_div(nsec, 1000000);
|
| 47 | }
|
| 48 |
|
| 49 | #define SPLIT_NS(x) nsec_high(x), nsec_low(x)
|
| 50 |
|
| 51 | #define SCHED_FEAT(name, enabled) \
|
| 52 | #name ,
|
| 53 |
|
| 54 | static const char * const sched_feat_names[] = {
|
| 55 | #include "features.h"
|
| 56 | };
|
| 57 |
|
| 58 | #undef SCHED_FEAT
|
| 59 |
|
| 60 | static int sched_feat_show(struct seq_file *m, void *v)
|
| 61 | {
|
| 62 | int i;
|
| 63 |
|
| 64 | for (i = 0; i < __SCHED_FEAT_NR; i++) {
|
| 65 | if (!(sysctl_sched_features & (1UL << i)))
|
| 66 | seq_puts(m, "NO_");
|
| 67 | seq_printf(m, "%s ", sched_feat_names[i]);
|
| 68 | }
|
| 69 | seq_puts(m, "\n");
|
| 70 |
|
| 71 | return 0;
|
| 72 | }
|
| 73 |
|
| 74 | #ifdef CONFIG_JUMP_LABEL
|
| 75 |
|
| 76 | #define jump_label_key__true STATIC_KEY_INIT_TRUE
|
| 77 | #define jump_label_key__false STATIC_KEY_INIT_FALSE
|
| 78 |
|
| 79 | #define SCHED_FEAT(name, enabled) \
|
| 80 | jump_label_key__##enabled ,
|
| 81 |
|
| 82 | struct static_key sched_feat_keys[__SCHED_FEAT_NR] = {
|
| 83 | #include "features.h"
|
| 84 | };
|
| 85 |
|
| 86 | #undef SCHED_FEAT
|
| 87 |
|
| 88 | static void sched_feat_disable(int i)
|
| 89 | {
|
| 90 | static_key_disable_cpuslocked(&sched_feat_keys[i]);
|
| 91 | }
|
| 92 |
|
| 93 | static void sched_feat_enable(int i)
|
| 94 | {
|
| 95 | static_key_enable_cpuslocked(&sched_feat_keys[i]);
|
| 96 | }
|
| 97 | #else
|
| 98 | static void sched_feat_disable(int i) { };
|
| 99 | static void sched_feat_enable(int i) { };
|
| 100 | #endif
|
| 101 |
|
| 102 | static int sched_feat_set(char *cmp)
|
| 103 | {
|
| 104 | int i;
|
| 105 | int neg = 0;
|
| 106 |
|
| 107 | if (strncmp(cmp, "NO_", 3) == 0) {
|
| 108 | neg = 1;
|
| 109 | cmp += 3;
|
| 110 | }
|
| 111 |
|
| 112 | i = match_string(sched_feat_names, __SCHED_FEAT_NR, cmp);
|
| 113 | if (i < 0)
|
| 114 | return i;
|
| 115 |
|
| 116 | if (neg) {
|
| 117 | sysctl_sched_features &= ~(1UL << i);
|
| 118 | sched_feat_disable(i);
|
| 119 | } else {
|
| 120 | sysctl_sched_features |= (1UL << i);
|
| 121 | sched_feat_enable(i);
|
| 122 | }
|
| 123 |
|
| 124 | return 0;
|
| 125 | }
|
| 126 |
|
| 127 | static ssize_t
|
| 128 | sched_feat_write(struct file *filp, const char __user *ubuf,
|
| 129 | size_t cnt, loff_t *ppos)
|
| 130 | {
|
| 131 | char buf[64];
|
| 132 | char *cmp;
|
| 133 | int ret;
|
| 134 | struct inode *inode;
|
| 135 |
|
| 136 | if (cnt > 63)
|
| 137 | cnt = 63;
|
| 138 |
|
| 139 | if (copy_from_user(buf, ubuf, cnt))
|
| 140 | return -EFAULT;
|
| 141 |
|
| 142 | buf[cnt] = 0;
|
| 143 | cmp = strstrip(buf);
|
| 144 |
|
| 145 |
|
| 146 | inode = file_inode(filp);
|
| 147 | cpus_read_lock();
|
| 148 | inode_lock(inode);
|
| 149 | ret = sched_feat_set(cmp);
|
| 150 | inode_unlock(inode);
|
| 151 | cpus_read_unlock();
|
| 152 | if (ret < 0)
|
| 153 | return ret;
|
| 154 |
|
| 155 | *ppos += cnt;
|
| 156 |
|
| 157 | return cnt;
|
| 158 | }
|
| 159 |
|
| 160 | static int sched_feat_open(struct inode *inode, struct file *filp)
|
| 161 | {
|
| 162 | return single_open(filp, sched_feat_show, NULL);
|
| 163 | }
|
| 164 |
|
| 165 | static const struct file_operations sched_feat_fops = {
|
| 166 | .open = sched_feat_open,
|
| 167 | .write = sched_feat_write,
|
| 168 | .read = seq_read,
|
| 169 | .llseek = seq_lseek,
|
| 170 | .release = single_release,
|
| 171 | };
|
| 172 |
|
| 173 | static ssize_t sched_scaling_write(struct file *filp, const char __user *ubuf,
|
| 174 | size_t cnt, loff_t *ppos)
|
| 175 | {
|
| 176 | unsigned int scaling;
|
| 177 | int ret;
|
| 178 |
|
| 179 | ret = kstrtouint_from_user(ubuf, cnt, 10, &scaling);
|
| 180 | if (ret)
|
| 181 | return ret;
|
| 182 |
|
| 183 | if (scaling >= SCHED_TUNABLESCALING_END)
|
| 184 | return -EINVAL;
|
| 185 |
|
| 186 | sysctl_sched_tunable_scaling = scaling;
|
| 187 | if (sched_update_scaling())
|
| 188 | return -EINVAL;
|
| 189 |
|
| 190 | *ppos += cnt;
|
| 191 | return cnt;
|
| 192 | }
|
| 193 |
|
| 194 | static int sched_scaling_show(struct seq_file *m, void *v)
|
| 195 | {
|
| 196 | seq_printf(m, "%d\n", sysctl_sched_tunable_scaling);
|
| 197 | return 0;
|
| 198 | }
|
| 199 |
|
| 200 | static int sched_scaling_open(struct inode *inode, struct file *filp)
|
| 201 | {
|
| 202 | return single_open(filp, sched_scaling_show, NULL);
|
| 203 | }
|
| 204 |
|
| 205 | static const struct file_operations sched_scaling_fops = {
|
| 206 | .open = sched_scaling_open,
|
| 207 | .write = sched_scaling_write,
|
| 208 | .read = seq_read,
|
| 209 | .llseek = seq_lseek,
|
| 210 | .release = single_release,
|
| 211 | };
|
| 212 |
|
| 213 | #ifdef CONFIG_SCHED_CACHE
|
| 214 | static ssize_t
|
| 215 | sched_cache_enable_write(struct file *filp, const char __user *ubuf,
|
| 216 | size_t cnt, loff_t *ppos)
|
| 217 | {
|
| 218 | bool val;
|
| 219 | int ret;
|
| 220 |
|
| 221 | ret = kstrtobool_from_user(ubuf, cnt, &val);
|
| 222 | if (ret)
|
| 223 | return ret;
|
| 224 |
|
| 225 | sysctl_sched_cache_user = val;
|
| 226 |
|
| 227 | sched_cache_active_set();
|
| 228 |
|
| 229 | *ppos += cnt;
|
| 230 |
|
| 231 | return cnt;
|
| 232 | }
|
| 233 |
|
| 234 | static int sched_cache_enable_show(struct seq_file *m, void *v)
|
| 235 | {
|
| 236 | seq_printf(m, "%d\n", sysctl_sched_cache_user);
|
| 237 | return 0;
|
| 238 | }
|
| 239 |
|
| 240 | static int sched_cache_enable_open(struct inode *inode,
|
| 241 | struct file *filp)
|
| 242 | {
|
| 243 | return single_open(filp, sched_cache_enable_show, NULL);
|
| 244 | }
|
| 245 |
|
| 246 | static const struct file_operations sched_cache_enable_fops = {
|
| 247 | .open = sched_cache_enable_open,
|
| 248 | .write = sched_cache_enable_write,
|
| 249 | .read = seq_read,
|
| 250 | .llseek = seq_lseek,
|
| 251 | .release = single_release,
|
| 252 | };
|
| 253 | #endif
|
| 254 |
|
| 255 | #ifdef CONFIG_PREEMPT_DYNAMIC
|
| 256 |
|
| 257 | static ssize_t sched_dynamic_write(struct file *filp, const char __user *ubuf,
|
| 258 | size_t cnt, loff_t *ppos)
|
| 259 | {
|
| 260 | char buf[16];
|
| 261 | int mode;
|
| 262 |
|
| 263 | if (cnt > 15)
|
| 264 | cnt = 15;
|
| 265 |
|
| 266 | if (copy_from_user(buf, ubuf, cnt))
|
| 267 | return -EFAULT;
|
| 268 |
|
| 269 | buf[cnt] = 0;
|
| 270 | mode = sched_dynamic_mode(strstrip(buf));
|
| 271 | if (mode < 0)
|
| 272 | return mode;
|
| 273 |
|
| 274 | sched_dynamic_update(mode);
|
| 275 |
|
| 276 | *ppos += cnt;
|
| 277 |
|
| 278 | return cnt;
|
| 279 | }
|
| 280 |
|
| 281 | static int sched_dynamic_show(struct seq_file *m, void *v)
|
| 282 | {
|
| 283 | int i = (IS_ENABLED(CONFIG_PREEMPT_RT) || IS_ENABLED(CONFIG_ARCH_HAS_PREEMPT_LAZY)) * 2;
|
| 284 | int mode = READ_ONCE(preempt_dynamic_mode);
|
| 285 | int j;
|
| 286 |
|
| 287 |
|
| 288 | for (j = 0; preempt_modes[j]; j++)
|
| 289 | ;
|
| 290 | j -= !IS_ENABLED(CONFIG_ARCH_HAS_PREEMPT_LAZY);
|
| 291 |
|
| 292 | for (; i < j; i++) {
|
| 293 | if (mode == i)
|
| 294 | seq_puts(m, "(");
|
| 295 | seq_puts(m, preempt_modes[i]);
|
| 296 | if (mode == i)
|
| 297 | seq_puts(m, ")");
|
| 298 |
|
| 299 | seq_puts(m, " ");
|
| 300 | }
|
| 301 |
|
| 302 | seq_puts(m, "\n");
|
| 303 | return 0;
|
| 304 | }
|
| 305 |
|
| 306 | static int sched_dynamic_open(struct inode *inode, struct file *filp)
|
| 307 | {
|
| 308 | return single_open(filp, sched_dynamic_show, NULL);
|
| 309 | }
|
| 310 |
|
| 311 | static const struct file_operations sched_dynamic_fops = {
|
| 312 | .open = sched_dynamic_open,
|
| 313 | .write = sched_dynamic_write,
|
| 314 | .read = seq_read,
|
| 315 | .llseek = seq_lseek,
|
| 316 | .release = single_release,
|
| 317 | };
|
| 318 |
|
| 319 | #endif
|
| 320 |
|
| 321 | __read_mostly bool sched_debug_verbose;
|
| 322 |
|
| 323 | static struct dentry *sd_dentry;
|
| 324 |
|
| 325 |
|
| 326 | static ssize_t sched_verbose_write(struct file *filp, const char __user *ubuf,
|
| 327 | size_t cnt, loff_t *ppos)
|
| 328 | {
|
| 329 | ssize_t result;
|
| 330 | bool orig;
|
| 331 |
|
| 332 | cpus_read_lock();
|
| 333 | sched_domains_mutex_lock();
|
| 334 |
|
| 335 | orig = sched_debug_verbose;
|
| 336 | result = debugfs_write_file_bool(filp, ubuf, cnt, ppos);
|
| 337 |
|
| 338 | if (sched_debug_verbose && !orig)
|
| 339 | update_sched_domain_debugfs();
|
| 340 | else if (!sched_debug_verbose && orig) {
|
| 341 | debugfs_remove(sd_dentry);
|
| 342 | sd_dentry = NULL;
|
| 343 | }
|
| 344 |
|
| 345 | sched_domains_mutex_unlock();
|
| 346 | cpus_read_unlock();
|
| 347 |
|
| 348 | return result;
|
| 349 | }
|
| 350 |
|
| 351 | static const struct file_operations sched_verbose_fops = {
|
| 352 | .read = debugfs_read_file_bool,
|
| 353 | .write = sched_verbose_write,
|
| 354 | .open = simple_open,
|
| 355 | .llseek = default_llseek,
|
| 356 | };
|
| 357 |
|
| 358 | static const struct seq_operations sched_debug_sops;
|
| 359 |
|
| 360 | static int sched_debug_open(struct inode *inode, struct file *filp)
|
| 361 | {
|
| 362 | return seq_open(filp, &sched_debug_sops);
|
| 363 | }
|
| 364 |
|
| 365 | static const struct file_operations sched_debug_fops = {
|
| 366 | .open = sched_debug_open,
|
| 367 | .read = seq_read,
|
| 368 | .llseek = seq_lseek,
|
| 369 | .release = seq_release,
|
| 370 | };
|
| 371 |
|
| 372 | enum dl_param {
|
| 373 | DL_RUNTIME = 0,
|
| 374 | DL_PERIOD,
|
| 375 | };
|
| 376 |
|
| 377 | static unsigned long dl_server_period_max = (1UL << 22) * NSEC_PER_USEC;
|
| 378 | static unsigned long dl_server_period_min = (100) * NSEC_PER_USEC;
|
| 379 |
|
| 380 | static ssize_t sched_server_write_common(struct file *filp, const char __user *ubuf,
|
| 381 | size_t cnt, loff_t *ppos, enum dl_param param,
|
| 382 | void *server)
|
| 383 | {
|
| 384 | long cpu = (long) ((struct seq_file *) filp->private_data)->private;
|
| 385 | struct sched_dl_entity *dl_se = (struct sched_dl_entity *)server;
|
| 386 | u64 old_runtime, runtime, period;
|
| 387 | struct rq *rq = cpu_rq(cpu);
|
| 388 | int retval = 0;
|
| 389 | size_t err;
|
| 390 | u64 value;
|
| 391 |
|
| 392 | err = kstrtoull_from_user(ubuf, cnt, 10, &value);
|
| 393 | if (err)
|
| 394 | return err;
|
| 395 |
|
| 396 | scoped_guard (rq_lock_irqsave, rq) {
|
| 397 | old_runtime = runtime = dl_se->dl_runtime;
|
| 398 | period = dl_se->dl_period;
|
| 399 |
|
| 400 | switch (param) {
|
| 401 | case DL_RUNTIME:
|
| 402 | if (runtime == value)
|
| 403 | break;
|
| 404 | runtime = value;
|
| 405 | break;
|
| 406 | case DL_PERIOD:
|
| 407 | if (value == period)
|
| 408 | break;
|
| 409 | period = value;
|
| 410 | break;
|
| 411 | }
|
| 412 |
|
| 413 | if (runtime > period ||
|
| 414 | period > dl_server_period_max ||
|
| 415 | period < dl_server_period_min) {
|
| 416 | return -EINVAL;
|
| 417 | }
|
| 418 |
|
| 419 | if (!cpu_online(cpu_of(rq)))
|
| 420 | return -EBUSY;
|
| 421 |
|
| 422 | update_rq_clock(rq);
|
| 423 | dl_server_stop(dl_se);
|
| 424 | retval = dl_server_apply_params(dl_se, runtime, period, 0);
|
| 425 | dl_server_start(dl_se);
|
| 426 |
|
| 427 | if (retval < 0)
|
| 428 | return retval;
|
| 429 | }
|
| 430 |
|
| 431 | if (!!old_runtime ^ !!runtime) {
|
| 432 | pr_info("%s server %sabled on CPU %d%s.\n",
|
| 433 | server == &rq->fair_server ? "Fair" : "Ext",
|
| 434 | runtime ? "en" : "dis",
|
| 435 | cpu_of(rq),
|
| 436 | runtime ? "" : ", system may malfunction due to starvation");
|
| 437 | }
|
| 438 |
|
| 439 | *ppos += cnt;
|
| 440 | return cnt;
|
| 441 | }
|
| 442 |
|
| 443 | static size_t sched_server_show_common(struct seq_file *m, void *v, enum dl_param param,
|
| 444 | void *server)
|
| 445 | {
|
| 446 | struct sched_dl_entity *dl_se = (struct sched_dl_entity *)server;
|
| 447 | u64 value;
|
| 448 |
|
| 449 | switch (param) {
|
| 450 | case DL_RUNTIME:
|
| 451 | value = dl_se->dl_runtime;
|
| 452 | break;
|
| 453 | case DL_PERIOD:
|
| 454 | value = dl_se->dl_period;
|
| 455 | break;
|
| 456 | }
|
| 457 |
|
| 458 | seq_printf(m, "%llu\n", value);
|
| 459 | return 0;
|
| 460 | }
|
| 461 |
|
| 462 | static ssize_t
|
| 463 | sched_fair_server_runtime_write(struct file *filp, const char __user *ubuf,
|
| 464 | size_t cnt, loff_t *ppos)
|
| 465 | {
|
| 466 | long cpu = (long) ((struct seq_file *) filp->private_data)->private;
|
| 467 | struct rq *rq = cpu_rq(cpu);
|
| 468 |
|
| 469 | return sched_server_write_common(filp, ubuf, cnt, ppos, DL_RUNTIME,
|
| 470 | &rq->fair_server);
|
| 471 | }
|
| 472 |
|
| 473 | static int sched_fair_server_runtime_show(struct seq_file *m, void *v)
|
| 474 | {
|
| 475 | unsigned long cpu = (unsigned long) m->private;
|
| 476 | struct rq *rq = cpu_rq(cpu);
|
| 477 |
|
| 478 | return sched_server_show_common(m, v, DL_RUNTIME, &rq->fair_server);
|
| 479 | }
|
| 480 |
|
| 481 | static int sched_fair_server_runtime_open(struct inode *inode, struct file *filp)
|
| 482 | {
|
| 483 | return single_open(filp, sched_fair_server_runtime_show, inode->i_private);
|
| 484 | }
|
| 485 |
|
| 486 | static const struct file_operations fair_server_runtime_fops = {
|
| 487 | .open = sched_fair_server_runtime_open,
|
| 488 | .write = sched_fair_server_runtime_write,
|
| 489 | .read = seq_read,
|
| 490 | .llseek = seq_lseek,
|
| 491 | .release = single_release,
|
| 492 | };
|
| 493 |
|
| 494 | static struct dentry *debugfs_sched;
|
| 495 |
|
| 496 | #ifdef CONFIG_SCHED_CLASS_EXT
|
| 497 | static ssize_t
|
| 498 | sched_ext_server_runtime_write(struct file *filp, const char __user *ubuf,
|
| 499 | size_t cnt, loff_t *ppos)
|
| 500 | {
|
| 501 | long cpu = (long) ((struct seq_file *) filp->private_data)->private;
|
| 502 | struct rq *rq = cpu_rq(cpu);
|
| 503 |
|
| 504 | return sched_server_write_common(filp, ubuf, cnt, ppos, DL_RUNTIME,
|
| 505 | &rq->ext_server);
|
| 506 | }
|
| 507 |
|
| 508 | static int sched_ext_server_runtime_show(struct seq_file *m, void *v)
|
| 509 | {
|
| 510 | unsigned long cpu = (unsigned long) m->private;
|
| 511 | struct rq *rq = cpu_rq(cpu);
|
| 512 |
|
| 513 | return sched_server_show_common(m, v, DL_RUNTIME, &rq->ext_server);
|
| 514 | }
|
| 515 |
|
| 516 | static int sched_ext_server_runtime_open(struct inode *inode, struct file *filp)
|
| 517 | {
|
| 518 | return single_open(filp, sched_ext_server_runtime_show, inode->i_private);
|
| 519 | }
|
| 520 |
|
| 521 | static const struct file_operations ext_server_runtime_fops = {
|
| 522 | .open = sched_ext_server_runtime_open,
|
| 523 | .write = sched_ext_server_runtime_write,
|
| 524 | .read = seq_read,
|
| 525 | .llseek = seq_lseek,
|
| 526 | .release = single_release,
|
| 527 | };
|
| 528 |
|
| 529 | static ssize_t
|
| 530 | sched_ext_server_period_write(struct file *filp, const char __user *ubuf,
|
| 531 | size_t cnt, loff_t *ppos)
|
| 532 | {
|
| 533 | long cpu = (long) ((struct seq_file *) filp->private_data)->private;
|
| 534 | struct rq *rq = cpu_rq(cpu);
|
| 535 |
|
| 536 | return sched_server_write_common(filp, ubuf, cnt, ppos, DL_PERIOD,
|
| 537 | &rq->ext_server);
|
| 538 | }
|
| 539 |
|
| 540 | static int sched_ext_server_period_show(struct seq_file *m, void *v)
|
| 541 | {
|
| 542 | unsigned long cpu = (unsigned long) m->private;
|
| 543 | struct rq *rq = cpu_rq(cpu);
|
| 544 |
|
| 545 | return sched_server_show_common(m, v, DL_PERIOD, &rq->ext_server);
|
| 546 | }
|
| 547 |
|
| 548 | static int sched_ext_server_period_open(struct inode *inode, struct file *filp)
|
| 549 | {
|
| 550 | return single_open(filp, sched_ext_server_period_show, inode->i_private);
|
| 551 | }
|
| 552 |
|
| 553 | static const struct file_operations ext_server_period_fops = {
|
| 554 | .open = sched_ext_server_period_open,
|
| 555 | .write = sched_ext_server_period_write,
|
| 556 | .read = seq_read,
|
| 557 | .llseek = seq_lseek,
|
| 558 | .release = single_release,
|
| 559 | };
|
| 560 |
|
| 561 | static void debugfs_ext_server_init(void)
|
| 562 | {
|
| 563 | struct dentry *d_ext;
|
| 564 | unsigned long cpu;
|
| 565 |
|
| 566 | d_ext = debugfs_create_dir("ext_server", debugfs_sched);
|
| 567 | if (!d_ext)
|
| 568 | return;
|
| 569 |
|
| 570 | for_each_possible_cpu(cpu) {
|
| 571 | struct dentry *d_cpu;
|
| 572 | char buf[32];
|
| 573 |
|
| 574 | snprintf(buf, sizeof(buf), "cpu%lu", cpu);
|
| 575 | d_cpu = debugfs_create_dir(buf, d_ext);
|
| 576 |
|
| 577 | debugfs_create_file("runtime", 0644, d_cpu, (void *) cpu, &ext_server_runtime_fops);
|
| 578 | debugfs_create_file("period", 0644, d_cpu, (void *) cpu, &ext_server_period_fops);
|
| 579 | }
|
| 580 | }
|
| 581 | #endif
|
| 582 |
|
| 583 | static ssize_t
|
| 584 | sched_fair_server_period_write(struct file *filp, const char __user *ubuf,
|
| 585 | size_t cnt, loff_t *ppos)
|
| 586 | {
|
| 587 | long cpu = (long) ((struct seq_file *) filp->private_data)->private;
|
| 588 | struct rq *rq = cpu_rq(cpu);
|
| 589 |
|
| 590 | return sched_server_write_common(filp, ubuf, cnt, ppos, DL_PERIOD,
|
| 591 | &rq->fair_server);
|
| 592 | }
|
| 593 |
|
| 594 | static int sched_fair_server_period_show(struct seq_file *m, void *v)
|
| 595 | {
|
| 596 | unsigned long cpu = (unsigned long) m->private;
|
| 597 | struct rq *rq = cpu_rq(cpu);
|
| 598 |
|
| 599 | return sched_server_show_common(m, v, DL_PERIOD, &rq->fair_server);
|
| 600 | }
|
| 601 |
|
| 602 | static int sched_fair_server_period_open(struct inode *inode, struct file *filp)
|
| 603 | {
|
| 604 | return single_open(filp, sched_fair_server_period_show, inode->i_private);
|
| 605 | }
|
| 606 |
|
| 607 | static const struct file_operations fair_server_period_fops = {
|
| 608 | .open = sched_fair_server_period_open,
|
| 609 | .write = sched_fair_server_period_write,
|
| 610 | .read = seq_read,
|
| 611 | .llseek = seq_lseek,
|
| 612 | .release = single_release,
|
| 613 | };
|
| 614 |
|
| 615 | static void debugfs_fair_server_init(void)
|
| 616 | {
|
| 617 | struct dentry *d_fair;
|
| 618 | unsigned long cpu;
|
| 619 |
|
| 620 | d_fair = debugfs_create_dir("fair_server", debugfs_sched);
|
| 621 | if (!d_fair)
|
| 622 | return;
|
| 623 |
|
| 624 | for_each_possible_cpu(cpu) {
|
| 625 | struct dentry *d_cpu;
|
| 626 | char buf[32];
|
| 627 |
|
| 628 | snprintf(buf, sizeof(buf), "cpu%lu", cpu);
|
| 629 | d_cpu = debugfs_create_dir(buf, d_fair);
|
| 630 |
|
| 631 | debugfs_create_file("runtime", 0644, d_cpu, (void *) cpu, &fair_server_runtime_fops);
|
| 632 | debugfs_create_file("period", 0644, d_cpu, (void *) cpu, &fair_server_period_fops);
|
| 633 | }
|
| 634 | }
|
| 635 |
|
| 636 | static __init int sched_init_debug(void)
|
| 637 | {
|
| 638 | struct dentry __maybe_unused *numa, *llc;
|
| 639 |
|
| 640 | debugfs_sched = debugfs_create_dir("sched", NULL);
|
| 641 |
|
| 642 | debugfs_create_file("features", 0644, debugfs_sched, NULL, &sched_feat_fops);
|
| 643 | debugfs_create_file_unsafe("verbose", 0644, debugfs_sched, &sched_debug_verbose, &sched_verbose_fops);
|
| 644 | #ifdef CONFIG_PREEMPT_DYNAMIC
|
| 645 | debugfs_create_file("preempt", 0644, debugfs_sched, NULL, &sched_dynamic_fops);
|
| 646 | #endif
|
| 647 |
|
| 648 | debugfs_create_u32("base_slice_ns", 0644, debugfs_sched, &sysctl_sched_base_slice);
|
| 649 |
|
| 650 | debugfs_create_u32("latency_warn_ms", 0644, debugfs_sched, &sysctl_resched_latency_warn_ms);
|
| 651 | debugfs_create_u32("latency_warn_once", 0644, debugfs_sched, &sysctl_resched_latency_warn_once);
|
| 652 |
|
| 653 | debugfs_create_file("tunable_scaling", 0644, debugfs_sched, NULL, &sched_scaling_fops);
|
| 654 | debugfs_create_u32("migration_cost_ns", 0644, debugfs_sched, &sysctl_sched_migration_cost);
|
| 655 | debugfs_create_u32("nr_migrate", 0644, debugfs_sched, &sysctl_sched_nr_migrate);
|
| 656 |
|
| 657 | sched_domains_mutex_lock();
|
| 658 | update_sched_domain_debugfs();
|
| 659 | sched_domains_mutex_unlock();
|
| 660 |
|
| 661 | #ifdef CONFIG_NUMA_BALANCING
|
| 662 | numa = debugfs_create_dir("numa_balancing", debugfs_sched);
|
| 663 |
|
| 664 | debugfs_create_u32("scan_delay_ms", 0644, numa, &sysctl_numa_balancing_scan_delay);
|
| 665 | debugfs_create_u32("scan_period_min_ms", 0644, numa, &sysctl_numa_balancing_scan_period_min);
|
| 666 | debugfs_create_u32("scan_period_max_ms", 0644, numa, &sysctl_numa_balancing_scan_period_max);
|
| 667 | debugfs_create_u32("scan_size_mb", 0644, numa, &sysctl_numa_balancing_scan_size);
|
| 668 | debugfs_create_u32("hot_threshold_ms", 0644, numa, &sysctl_numa_balancing_hot_threshold);
|
| 669 | #endif
|
| 670 |
|
| 671 | #ifdef CONFIG_SCHED_CACHE
|
| 672 | llc = debugfs_create_dir("llc_balancing", debugfs_sched);
|
| 673 | debugfs_create_file("enabled", 0644, llc, NULL,
|
| 674 | &sched_cache_enable_fops);
|
| 675 | debugfs_create_u32("aggr_tolerance", 0644, llc,
|
| 676 | &llc_aggr_tolerance);
|
| 677 | debugfs_create_u32("epoch_period", 0644, llc,
|
| 678 | &llc_epoch_period);
|
| 679 | debugfs_create_u32("epoch_affinity_timeout", 0644, llc,
|
| 680 | &llc_epoch_affinity_timeout);
|
| 681 | debugfs_create_u32("overaggr_pct", 0644, llc,
|
| 682 | &llc_overaggr_pct);
|
| 683 | debugfs_create_u32("imb_pct", 0644, llc,
|
| 684 | &llc_imb_pct);
|
| 685 | #endif
|
| 686 |
|
| 687 | debugfs_create_file("debug", 0444, debugfs_sched, NULL, &sched_debug_fops);
|
| 688 |
|
| 689 | debugfs_fair_server_init();
|
| 690 | #ifdef CONFIG_SCHED_CLASS_EXT
|
| 691 | debugfs_ext_server_init();
|
| 692 | #endif
|
| 693 |
|
| 694 | return 0;
|
| 695 | }
|
| 696 | late_initcall(sched_init_debug);
|
| 697 |
|
| 698 | static cpumask_var_t sd_sysctl_cpus;
|
| 699 |
|
| 700 | static int sd_flags_show(struct seq_file *m, void *v)
|
| 701 | {
|
| 702 | unsigned long flags = *(unsigned int *)m->private;
|
| 703 | int idx;
|
| 704 |
|
| 705 | for_each_set_bit(idx, &flags, __SD_FLAG_CNT) {
|
| 706 | seq_puts(m, sd_flag_debug[idx].name);
|
| 707 | seq_puts(m, " ");
|
| 708 | }
|
| 709 | seq_puts(m, "\n");
|
| 710 |
|
| 711 | return 0;
|
| 712 | }
|
| 713 |
|
| 714 | static int sd_flags_open(struct inode *inode, struct file *file)
|
| 715 | {
|
| 716 | return single_open(file, sd_flags_show, inode->i_private);
|
| 717 | }
|
| 718 |
|
| 719 | static const struct file_operations sd_flags_fops = {
|
| 720 | .open = sd_flags_open,
|
| 721 | .read = seq_read,
|
| 722 | .llseek = seq_lseek,
|
| 723 | .release = single_release,
|
| 724 | };
|
| 725 |
|
| 726 | static void register_sd(struct sched_domain *sd, struct dentry *parent)
|
| 727 | {
|
| 728 | #define SDM(type, mode, member) \
|
| 729 | debugfs_create_##type(#member, mode, parent, &sd->member)
|
| 730 |
|
| 731 | SDM(ulong, 0644, min_interval);
|
| 732 | SDM(ulong, 0644, max_interval);
|
| 733 | SDM(u64, 0644, max_newidle_lb_cost);
|
| 734 | SDM(u32, 0644, busy_factor);
|
| 735 | SDM(u32, 0644, imbalance_pct);
|
| 736 | SDM(u32, 0644, cache_nice_tries);
|
| 737 | SDM(str, 0444, name);
|
| 738 |
|
| 739 | #undef SDM
|
| 740 |
|
| 741 | debugfs_create_file("flags", 0444, parent, &sd->flags, &sd_flags_fops);
|
| 742 | debugfs_create_file("groups_flags", 0444, parent, &sd->groups->flags, &sd_flags_fops);
|
| 743 | debugfs_create_u32("level", 0444, parent, (u32 *)&sd->level);
|
| 744 |
|
| 745 | if (sd->flags & SD_ASYM_PACKING)
|
| 746 | debugfs_create_u32("group_asym_prefer_cpu", 0444, parent,
|
| 747 | (u32 *)&sd->groups->asym_prefer_cpu);
|
| 748 | }
|
| 749 |
|
| 750 | void update_sched_domain_debugfs(void)
|
| 751 | {
|
| 752 | int cpu, i;
|
| 753 |
|
| 754 | |
| 755 | * This can unfortunately be invoked before sched_debug_init() creates
|
| 756 | * the debug directory. Don't touch sd_sysctl_cpus until then.
|
| 757 |
|
| 758 | if (!debugfs_sched)
|
| 759 | return;
|
| 760 |
|
| 761 | if (!sched_debug_verbose)
|
| 762 | return;
|
| 763 |
|
| 764 | if (!cpumask_available(sd_sysctl_cpus)) {
|
| 765 | if (!alloc_cpumask_var(&sd_sysctl_cpus, GFP_KERNEL))
|
| 766 | return;
|
| 767 | cpumask_copy(sd_sysctl_cpus, cpu_possible_mask);
|
| 768 | }
|
| 769 |
|
| 770 | if (!sd_dentry) {
|
| 771 | sd_dentry = debugfs_create_dir("domains", debugfs_sched);
|
| 772 |
|
| 773 |
|
| 774 | if (cpumask_empty(sd_sysctl_cpus))
|
| 775 | cpumask_copy(sd_sysctl_cpus, cpu_online_mask);
|
| 776 | }
|
| 777 |
|
| 778 | for_each_cpu(cpu, sd_sysctl_cpus) {
|
| 779 | struct sched_domain *sd;
|
| 780 | struct dentry *d_cpu;
|
| 781 | char buf[32];
|
| 782 |
|
| 783 | snprintf(buf, sizeof(buf), "cpu%d", cpu);
|
| 784 | debugfs_lookup_and_remove(buf, sd_dentry);
|
| 785 | d_cpu = debugfs_create_dir(buf, sd_dentry);
|
| 786 |
|
| 787 | i = 0;
|
| 788 | for_each_domain(cpu, sd) {
|
| 789 | struct dentry *d_sd;
|
| 790 |
|
| 791 | snprintf(buf, sizeof(buf), "domain%d", i);
|
| 792 | d_sd = debugfs_create_dir(buf, d_cpu);
|
| 793 |
|
| 794 | register_sd(sd, d_sd);
|
| 795 | i++;
|
| 796 | }
|
| 797 |
|
| 798 | __cpumask_clear_cpu(cpu, sd_sysctl_cpus);
|
| 799 | }
|
| 800 | }
|
| 801 |
|
| 802 | void dirty_sched_domain_sysctl(int cpu)
|
| 803 | {
|
| 804 | if (cpumask_available(sd_sysctl_cpus))
|
| 805 | __cpumask_set_cpu(cpu, sd_sysctl_cpus);
|
| 806 | }
|
| 807 |
|
| 808 | #ifdef CONFIG_FAIR_GROUP_SCHED
|
| 809 | static void print_cfs_group_stats(struct seq_file *m, int cpu, struct task_group *tg)
|
| 810 | {
|
| 811 | struct sched_entity *se = tg_se(tg, cpu);
|
| 812 |
|
| 813 | #define P(F) SEQ_printf(m, " .%-30s: %lld\n", #F, (long long)F)
|
| 814 | #define P_SCHEDSTAT(F) SEQ_printf(m, " .%-30s: %lld\n", \
|
| 815 | #F, (long long)schedstat_val(stats->F))
|
| 816 | #define PN(F) SEQ_printf(m, " .%-30s: %lld.%06ld\n", #F, SPLIT_NS((long long)F))
|
| 817 | #define PN_SCHEDSTAT(F) SEQ_printf(m, " .%-30s: %lld.%06ld\n", \
|
| 818 | #F, SPLIT_NS((long long)schedstat_val(stats->F)))
|
| 819 |
|
| 820 | if (!se)
|
| 821 | return;
|
| 822 |
|
| 823 | PN(se->exec_start);
|
| 824 | PN(se->vruntime);
|
| 825 | PN(se->sum_exec_runtime);
|
| 826 |
|
| 827 | if (schedstat_enabled()) {
|
| 828 | struct sched_statistics *stats;
|
| 829 | stats = __schedstats_from_se(se);
|
| 830 |
|
| 831 | PN_SCHEDSTAT(wait_start);
|
| 832 | PN_SCHEDSTAT(sleep_start);
|
| 833 | PN_SCHEDSTAT(block_start);
|
| 834 | PN_SCHEDSTAT(sleep_max);
|
| 835 | PN_SCHEDSTAT(block_max);
|
| 836 | PN_SCHEDSTAT(exec_max);
|
| 837 | PN_SCHEDSTAT(slice_max);
|
| 838 | PN_SCHEDSTAT(wait_max);
|
| 839 | PN_SCHEDSTAT(wait_sum);
|
| 840 | P_SCHEDSTAT(wait_count);
|
| 841 | }
|
| 842 |
|
| 843 | P(se->load.weight);
|
| 844 | P(se->avg.load_avg);
|
| 845 | P(se->avg.util_avg);
|
| 846 | P(se->avg.runnable_avg);
|
| 847 |
|
| 848 | #undef PN_SCHEDSTAT
|
| 849 | #undef PN
|
| 850 | #undef P_SCHEDSTAT
|
| 851 | #undef P
|
| 852 | }
|
| 853 | #endif
|
| 854 |
|
| 855 | #ifdef CONFIG_CGROUP_SCHED
|
| 856 | static DEFINE_SPINLOCK(sched_debug_lock);
|
| 857 | static char group_path[PATH_MAX];
|
| 858 |
|
| 859 | static void task_group_path(struct task_group *tg, char *path, int plen)
|
| 860 | {
|
| 861 | if (autogroup_path(tg, path, plen))
|
| 862 | return;
|
| 863 |
|
| 864 | cgroup_path(tg->css.cgroup, path, plen);
|
| 865 | }
|
| 866 |
|
| 867 | |
| 868 | * Only 1 SEQ_printf_task_group_path() caller can use the full length
|
| 869 | * group_path[] for cgroup path. Other simultaneous callers will have
|
| 870 | * to use a shorter stack buffer. A "..." suffix is appended at the end
|
| 871 | * of the stack buffer so that it will show up in case the output length
|
| 872 | * matches the given buffer size to indicate possible path name truncation.
|
| 873 |
|
| 874 | #define SEQ_printf_task_group_path(m, tg, fmt...) \
|
| 875 | { \
|
| 876 | if (spin_trylock(&sched_debug_lock)) { \
|
| 877 | task_group_path(tg, group_path, sizeof(group_path)); \
|
| 878 | SEQ_printf(m, fmt, group_path); \
|
| 879 | spin_unlock(&sched_debug_lock); \
|
| 880 | } else { \
|
| 881 | char buf[128]; \
|
| 882 | char *bufend = buf + sizeof(buf) - 3; \
|
| 883 | task_group_path(tg, buf, bufend - buf); \
|
| 884 | strcpy(bufend - 1, "..."); \
|
| 885 | SEQ_printf(m, fmt, buf); \
|
| 886 | } \
|
| 887 | }
|
| 888 | #endif
|
| 889 |
|
| 890 | static void
|
| 891 | print_task(struct seq_file *m, struct rq *rq, struct task_struct *p)
|
| 892 | {
|
| 893 | if (task_current(rq, p))
|
| 894 | SEQ_printf(m, ">R");
|
| 895 | else
|
| 896 | SEQ_printf(m, " %c", task_state_to_char(p));
|
| 897 |
|
| 898 | SEQ_printf(m, " %15s %5d %9Ld.%06ld %c %9Ld.%06ld %c %9Ld.%06ld %9Ld.%06ld %9Ld %5d ",
|
| 899 | p->comm, task_pid_nr(p),
|
| 900 | SPLIT_NS(p->se.vruntime),
|
| 901 | entity_eligible(cfs_rq_of(&p->se), &p->se) ? 'E' : 'N',
|
| 902 | SPLIT_NS(p->se.deadline),
|
| 903 | p->se.custom_slice ? 'S' : ' ',
|
| 904 | SPLIT_NS(p->se.slice),
|
| 905 | SPLIT_NS(p->se.sum_exec_runtime),
|
| 906 | (long long)(p->nvcsw + p->nivcsw),
|
| 907 | p->prio);
|
| 908 |
|
| 909 | SEQ_printf(m, "%9lld.%06ld %9lld.%06ld %9lld.%06ld",
|
| 910 | SPLIT_NS(schedstat_val_or_zero(p->stats.wait_sum)),
|
| 911 | SPLIT_NS(schedstat_val_or_zero(p->stats.sum_sleep_runtime)),
|
| 912 | SPLIT_NS(schedstat_val_or_zero(p->stats.sum_block_runtime)));
|
| 913 |
|
| 914 | #ifdef CONFIG_NUMA_BALANCING
|
| 915 | SEQ_printf(m, " %d %d", task_node(p), task_numa_group_id(p));
|
| 916 | #endif
|
| 917 | #ifdef CONFIG_CGROUP_SCHED
|
| 918 | SEQ_printf_task_group_path(m, task_group(p), " %s")
|
| 919 | #endif
|
| 920 |
|
| 921 | SEQ_printf(m, "\n");
|
| 922 | }
|
| 923 |
|
| 924 | static void print_rq(struct seq_file *m, struct rq *rq, int rq_cpu)
|
| 925 | {
|
| 926 | struct task_struct *g, *p;
|
| 927 |
|
| 928 | SEQ_printf(m, "\n");
|
| 929 | SEQ_printf(m, "runnable tasks:\n");
|
| 930 | SEQ_printf(m, " S task PID vruntime eligible "
|
| 931 | "deadline slice sum-exec switches "
|
| 932 | "prio wait-time sum-sleep sum-block"
|
| 933 | #ifdef CONFIG_NUMA_BALANCING
|
| 934 | " node group-id"
|
| 935 | #endif
|
| 936 | #ifdef CONFIG_CGROUP_SCHED
|
| 937 | " group-path"
|
| 938 | #endif
|
| 939 | "\n");
|
| 940 | SEQ_printf(m, "-------------------------------------------------------"
|
| 941 | "------------------------------------------------------"
|
| 942 | "------------------------------------------------------"
|
| 943 | #ifdef CONFIG_NUMA_BALANCING
|
| 944 | "--------------"
|
| 945 | #endif
|
| 946 | #ifdef CONFIG_CGROUP_SCHED
|
| 947 | "--------------"
|
| 948 | #endif
|
| 949 | "\n");
|
| 950 |
|
| 951 | rcu_read_lock();
|
| 952 | for_each_process_thread(g, p) {
|
| 953 | if (task_cpu(p) != rq_cpu)
|
| 954 | continue;
|
| 955 |
|
| 956 | print_task(m, rq, p);
|
| 957 | }
|
| 958 | rcu_read_unlock();
|
| 959 | }
|
| 960 |
|
| 961 | void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)
|
| 962 | {
|
| 963 | s64 left_vruntime = -1, right_vruntime = -1, left_deadline = -1, spread;
|
| 964 | s64 zero_vruntime = -1, sum_w_vruntime = -1;
|
| 965 | u64 avruntime;
|
| 966 | struct sched_entity *last, *first, *root;
|
| 967 | struct rq *rq = cpu_rq(cpu);
|
| 968 | unsigned int sum_shift;
|
| 969 | unsigned long flags;
|
| 970 | u64 sum_weight;
|
| 971 |
|
| 972 | #ifdef CONFIG_FAIR_GROUP_SCHED
|
| 973 | SEQ_printf(m, "\n");
|
| 974 | SEQ_printf_task_group_path(m, cfs_rq->tg, "cfs_rq[%d]:%s\n", cpu);
|
| 975 | #else
|
| 976 | SEQ_printf(m, "\n");
|
| 977 | SEQ_printf(m, "cfs_rq[%d]:\n", cpu);
|
| 978 | #endif
|
| 979 |
|
| 980 | raw_spin_rq_lock_irqsave(rq, flags);
|
| 981 | root = __pick_root_entity(cfs_rq);
|
| 982 | if (root)
|
| 983 | left_vruntime = root->min_vruntime;
|
| 984 | first = __pick_first_entity(cfs_rq);
|
| 985 | if (first)
|
| 986 | left_deadline = first->deadline;
|
| 987 | last = __pick_last_entity(cfs_rq);
|
| 988 | if (last)
|
| 989 | right_vruntime = last->vruntime;
|
| 990 | zero_vruntime = cfs_rq->zero_vruntime;
|
| 991 | sum_w_vruntime = cfs_rq->sum_w_vruntime;
|
| 992 | sum_weight = cfs_rq->sum_weight;
|
| 993 | sum_shift = cfs_rq->sum_shift;
|
| 994 | avruntime = avg_vruntime(cfs_rq);
|
| 995 | raw_spin_rq_unlock_irqrestore(rq, flags);
|
| 996 |
|
| 997 | SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "left_deadline",
|
| 998 | SPLIT_NS(left_deadline));
|
| 999 | SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "left_vruntime",
|
| 1000 | SPLIT_NS(left_vruntime));
|
| 1001 | SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "zero_vruntime",
|
| 1002 | SPLIT_NS(zero_vruntime));
|
| 1003 | SEQ_printf(m, " .%-30s: %Ld (%d bits)\n", "sum_w_vruntime",
|
| 1004 | sum_w_vruntime, ilog2(abs(sum_w_vruntime)));
|
| 1005 | SEQ_printf(m, " .%-30s: %Lu\n", "sum_weight",
|
| 1006 | sum_weight);
|
| 1007 | SEQ_printf(m, " .%-30s: %u\n", "sum_shift", sum_shift);
|
| 1008 | SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "avg_vruntime",
|
| 1009 | SPLIT_NS(avruntime));
|
| 1010 | SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "right_vruntime",
|
| 1011 | SPLIT_NS(right_vruntime));
|
| 1012 | spread = right_vruntime - left_vruntime;
|
| 1013 | SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "spread", SPLIT_NS(spread));
|
| 1014 | SEQ_printf(m, " .%-30s: %d\n", "nr_queued", cfs_rq->nr_queued);
|
| 1015 | SEQ_printf(m, " .%-30s: %d\n", "h_nr_runnable", cfs_rq->h_nr_runnable);
|
| 1016 | SEQ_printf(m, " .%-30s: %d\n", "h_nr_queued", cfs_rq->h_nr_queued);
|
| 1017 | SEQ_printf(m, " .%-30s: %d\n", "h_nr_idle", cfs_rq->h_nr_idle);
|
| 1018 | SEQ_printf(m, " .%-30s: %ld\n", "load", cfs_rq->load.weight);
|
| 1019 | SEQ_printf(m, " .%-30s: %lu\n", "load_avg",
|
| 1020 | cfs_rq->avg.load_avg);
|
| 1021 | SEQ_printf(m, " .%-30s: %lu\n", "runnable_avg",
|
| 1022 | cfs_rq->avg.runnable_avg);
|
| 1023 | SEQ_printf(m, " .%-30s: %lu\n", "util_avg",
|
| 1024 | cfs_rq->avg.util_avg);
|
| 1025 | SEQ_printf(m, " .%-30s: %u\n", "util_est",
|
| 1026 | cfs_rq->avg.util_est);
|
| 1027 | SEQ_printf(m, " .%-30s: %ld\n", "removed.load_avg",
|
| 1028 | cfs_rq->removed.load_avg);
|
| 1029 | SEQ_printf(m, " .%-30s: %ld\n", "removed.util_avg",
|
| 1030 | cfs_rq->removed.util_avg);
|
| 1031 | SEQ_printf(m, " .%-30s: %ld\n", "removed.runnable_avg",
|
| 1032 | cfs_rq->removed.runnable_avg);
|
| 1033 | #ifdef CONFIG_FAIR_GROUP_SCHED
|
| 1034 | SEQ_printf(m, " .%-30s: %lu\n", "tg_load_avg_contrib",
|
| 1035 | cfs_rq->tg_load_avg_contrib);
|
| 1036 | SEQ_printf(m, " .%-30s: %ld\n", "tg_load_avg",
|
| 1037 | atomic_long_read(&cfs_rq->tg->load_avg));
|
| 1038 | #endif
|
| 1039 | #ifdef CONFIG_CFS_BANDWIDTH
|
| 1040 | SEQ_printf(m, " .%-30s: %d\n", "throttled",
|
| 1041 | cfs_rq->throttled);
|
| 1042 | SEQ_printf(m, " .%-30s: %d\n", "throttle_count",
|
| 1043 | cfs_rq->throttle_count);
|
| 1044 | #endif
|
| 1045 |
|
| 1046 | #ifdef CONFIG_FAIR_GROUP_SCHED
|
| 1047 | print_cfs_group_stats(m, cpu, cfs_rq->tg);
|
| 1048 | #endif
|
| 1049 | }
|
| 1050 |
|
| 1051 | void print_rt_rq(struct seq_file *m, int cpu, struct rt_rq *rt_rq)
|
| 1052 | {
|
| 1053 | #ifdef CONFIG_RT_GROUP_SCHED
|
| 1054 | SEQ_printf(m, "\n");
|
| 1055 | SEQ_printf_task_group_path(m, rt_rq->tg, "rt_rq[%d]:%s\n", cpu);
|
| 1056 | #else
|
| 1057 | SEQ_printf(m, "\n");
|
| 1058 | SEQ_printf(m, "rt_rq[%d]:\n", cpu);
|
| 1059 | #endif
|
| 1060 |
|
| 1061 | #define P(x) \
|
| 1062 | SEQ_printf(m, " .%-30s: %Ld\n", #x, (long long)(rt_rq->x))
|
| 1063 | #define PU(x) \
|
| 1064 | SEQ_printf(m, " .%-30s: %lu\n", #x, (unsigned long)(rt_rq->x))
|
| 1065 | #define PN(x) \
|
| 1066 | SEQ_printf(m, " .%-30s: %Ld.%06ld\n", #x, SPLIT_NS(rt_rq->x))
|
| 1067 |
|
| 1068 | PU(rt_nr_running);
|
| 1069 |
|
| 1070 | #ifdef CONFIG_RT_GROUP_SCHED
|
| 1071 | P(rt_throttled);
|
| 1072 | PN(rt_time);
|
| 1073 | PN(rt_runtime);
|
| 1074 | #endif
|
| 1075 |
|
| 1076 | #undef PN
|
| 1077 | #undef PU
|
| 1078 | #undef P
|
| 1079 | }
|
| 1080 |
|
| 1081 | void print_dl_rq(struct seq_file *m, int cpu, struct dl_rq *dl_rq)
|
| 1082 | {
|
| 1083 | struct dl_bw *dl_bw;
|
| 1084 |
|
| 1085 | SEQ_printf(m, "\n");
|
| 1086 | SEQ_printf(m, "dl_rq[%d]:\n", cpu);
|
| 1087 |
|
| 1088 | #define PU(x) \
|
| 1089 | SEQ_printf(m, " .%-30s: %lu\n", #x, (unsigned long)(dl_rq->x))
|
| 1090 |
|
| 1091 | PU(dl_nr_running);
|
| 1092 | dl_bw = &cpu_rq(cpu)->rd->dl_bw;
|
| 1093 | SEQ_printf(m, " .%-30s: %lld\n", "dl_bw->bw", dl_bw->bw);
|
| 1094 | SEQ_printf(m, " .%-30s: %lld\n", "dl_bw->total_bw", dl_bw->total_bw);
|
| 1095 |
|
| 1096 | #undef PU
|
| 1097 | }
|
| 1098 |
|
| 1099 | static void print_cpu(struct seq_file *m, int cpu)
|
| 1100 | {
|
| 1101 | struct rq *rq = cpu_rq(cpu);
|
| 1102 |
|
| 1103 | #ifdef CONFIG_X86
|
| 1104 | {
|
| 1105 | unsigned int freq = cpu_khz ? : 1;
|
| 1106 |
|
| 1107 | SEQ_printf(m, "cpu#%d, %u.%03u MHz\n",
|
| 1108 | cpu, freq / 1000, (freq % 1000));
|
| 1109 | }
|
| 1110 | #else
|
| 1111 | SEQ_printf(m, "cpu#%d\n", cpu);
|
| 1112 | #endif
|
| 1113 |
|
| 1114 | #define P(x) \
|
| 1115 | do { \
|
| 1116 | if (sizeof(rq->x) == 4) \
|
| 1117 | SEQ_printf(m, " .%-30s: %d\n", #x, (int)(rq->x)); \
|
| 1118 | else \
|
| 1119 | SEQ_printf(m, " .%-30s: %Ld\n", #x, (long long)(rq->x));\
|
| 1120 | } while (0)
|
| 1121 |
|
| 1122 | #define PN(x) \
|
| 1123 | SEQ_printf(m, " .%-30s: %Ld.%06ld\n", #x, SPLIT_NS(rq->x))
|
| 1124 |
|
| 1125 | P(nr_running);
|
| 1126 | P(nr_switches);
|
| 1127 | P(nr_uninterruptible);
|
| 1128 | PN(next_balance);
|
| 1129 | SEQ_printf(m, " .%-30s: %ld\n", "curr->pid", (long)(task_pid_nr(rq->curr)));
|
| 1130 | PN(clock);
|
| 1131 | PN(clock_task);
|
| 1132 | #undef P
|
| 1133 | #undef PN
|
| 1134 |
|
| 1135 | #define P64(n) SEQ_printf(m, " .%-30s: %Ld\n", #n, rq->n);
|
| 1136 | P64(avg_idle);
|
| 1137 | P64(max_idle_balance_cost);
|
| 1138 | #undef P64
|
| 1139 |
|
| 1140 | #define P(n) SEQ_printf(m, " .%-30s: %d\n", #n, schedstat_val(rq->n));
|
| 1141 | if (schedstat_enabled()) {
|
| 1142 | P(yld_count);
|
| 1143 | P(sched_count);
|
| 1144 | P(sched_goidle);
|
| 1145 | P(ttwu_count);
|
| 1146 | P(ttwu_local);
|
| 1147 | }
|
| 1148 | #undef P
|
| 1149 |
|
| 1150 | print_cfs_stats(m, cpu);
|
| 1151 | print_rt_stats(m, cpu);
|
| 1152 | print_dl_stats(m, cpu);
|
| 1153 |
|
| 1154 | print_rq(m, rq, cpu);
|
| 1155 | SEQ_printf(m, "\n");
|
| 1156 | }
|
| 1157 |
|
| 1158 | static const char *sched_tunable_scaling_names[] = {
|
| 1159 | "none",
|
| 1160 | "logarithmic",
|
| 1161 | "linear"
|
| 1162 | };
|
| 1163 |
|
| 1164 | static void sched_debug_header(struct seq_file *m)
|
| 1165 | {
|
| 1166 | u64 ktime, sched_clk, cpu_clk;
|
| 1167 | unsigned long flags;
|
| 1168 |
|
| 1169 | local_irq_save(flags);
|
| 1170 | ktime = ktime_to_ns(ktime_get());
|
| 1171 | sched_clk = sched_clock();
|
| 1172 | cpu_clk = local_clock();
|
| 1173 | local_irq_restore(flags);
|
| 1174 |
|
| 1175 | SEQ_printf(m, "Sched Debug Version: v0.11, %s %.*s\n",
|
| 1176 | init_utsname()->release,
|
| 1177 | (int)strcspn(init_utsname()->version, " "),
|
| 1178 | init_utsname()->version);
|
| 1179 |
|
| 1180 | #define P(x) \
|
| 1181 | SEQ_printf(m, "%-40s: %Ld\n", #x, (long long)(x))
|
| 1182 | #define PN(x) \
|
| 1183 | SEQ_printf(m, "%-40s: %Ld.%06ld\n", #x, SPLIT_NS(x))
|
| 1184 | PN(ktime);
|
| 1185 | PN(sched_clk);
|
| 1186 | PN(cpu_clk);
|
| 1187 | P(jiffies);
|
| 1188 | #ifdef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
|
| 1189 | P(sched_clock_stable());
|
| 1190 | #endif
|
| 1191 | #undef PN
|
| 1192 | #undef P
|
| 1193 |
|
| 1194 | SEQ_printf(m, "\n");
|
| 1195 | SEQ_printf(m, "sysctl_sched\n");
|
| 1196 |
|
| 1197 | #define P(x) \
|
| 1198 | SEQ_printf(m, " .%-40s: %Ld\n", #x, (long long)(x))
|
| 1199 | #define PN(x) \
|
| 1200 | SEQ_printf(m, " .%-40s: %Ld.%06ld\n", #x, SPLIT_NS(x))
|
| 1201 | PN(sysctl_sched_base_slice);
|
| 1202 | P(sysctl_sched_features);
|
| 1203 | #undef PN
|
| 1204 | #undef P
|
| 1205 |
|
| 1206 | SEQ_printf(m, " .%-40s: %d (%s)\n",
|
| 1207 | "sysctl_sched_tunable_scaling",
|
| 1208 | sysctl_sched_tunable_scaling,
|
| 1209 | sched_tunable_scaling_names[sysctl_sched_tunable_scaling]);
|
| 1210 | SEQ_printf(m, "\n");
|
| 1211 | }
|
| 1212 |
|
| 1213 | static int sched_debug_show(struct seq_file *m, void *v)
|
| 1214 | {
|
| 1215 | int cpu = (unsigned long)(v - 2);
|
| 1216 |
|
| 1217 | if (cpu != -1)
|
| 1218 | print_cpu(m, cpu);
|
| 1219 | else
|
| 1220 | sched_debug_header(m);
|
| 1221 |
|
| 1222 | return 0;
|
| 1223 | }
|
| 1224 |
|
| 1225 | void sysrq_sched_debug_show(void)
|
| 1226 | {
|
| 1227 | int cpu;
|
| 1228 |
|
| 1229 | sched_debug_header(NULL);
|
| 1230 | for_each_online_cpu(cpu) {
|
| 1231 | |
| 1232 | * Need to reset softlockup watchdogs on all CPUs, because
|
| 1233 | * another CPU might be blocked waiting for us to process
|
| 1234 | * an IPI or stop_machine.
|
| 1235 |
|
| 1236 | touch_nmi_watchdog();
|
| 1237 | touch_all_softlockup_watchdogs();
|
| 1238 | print_cpu(NULL, cpu);
|
| 1239 | }
|
| 1240 | }
|
| 1241 |
|
| 1242 | |
| 1243 | * This iterator needs some explanation.
|
| 1244 | * It returns 1 for the header position.
|
| 1245 | * This means 2 is CPU 0.
|
| 1246 | * In a hotplugged system some CPUs, including CPU 0, may be missing so we have
|
| 1247 | * to use cpumask_* to iterate over the CPUs.
|
| 1248 |
|
| 1249 | static void *sched_debug_start(struct seq_file *file, loff_t *offset)
|
| 1250 | {
|
| 1251 | unsigned long n = *offset;
|
| 1252 |
|
| 1253 | if (n == 0)
|
| 1254 | return (void *) 1;
|
| 1255 |
|
| 1256 | n--;
|
| 1257 |
|
| 1258 | if (n > 0)
|
| 1259 | n = cpumask_next(n - 1, cpu_online_mask);
|
| 1260 | else
|
| 1261 | n = cpumask_first(cpu_online_mask);
|
| 1262 |
|
| 1263 | *offset = n + 1;
|
| 1264 |
|
| 1265 | if (n < nr_cpu_ids)
|
| 1266 | return (void *)(unsigned long)(n + 2);
|
| 1267 |
|
| 1268 | return NULL;
|
| 1269 | }
|
| 1270 |
|
| 1271 | static void *sched_debug_next(struct seq_file *file, void *data, loff_t *offset)
|
| 1272 | {
|
| 1273 | (*offset)++;
|
| 1274 | return sched_debug_start(file, offset);
|
| 1275 | }
|
| 1276 |
|
| 1277 | static void sched_debug_stop(struct seq_file *file, void *data)
|
| 1278 | {
|
| 1279 | }
|
| 1280 |
|
| 1281 | static const struct seq_operations sched_debug_sops = {
|
| 1282 | .start = sched_debug_start,
|
| 1283 | .next = sched_debug_next,
|
| 1284 | .stop = sched_debug_stop,
|
| 1285 | .show = sched_debug_show,
|
| 1286 | };
|
| 1287 |
|
| 1288 | #define __PS(S, F) SEQ_printf(m, "%-45s:%21Ld\n", S, (long long)(F))
|
| 1289 | #define __P(F) __PS(#F, F)
|
| 1290 | #define P(F) __PS(#F, p->F)
|
| 1291 | #define PM(F, M) __PS(#F, p->F & (M))
|
| 1292 | #define __PSN(S, F) SEQ_printf(m, "%-45s:%14Ld.%06ld\n", S, SPLIT_NS((long long)(F)))
|
| 1293 | #define __PN(F) __PSN(#F, F)
|
| 1294 | #define PN(F) __PSN(#F, p->F)
|
| 1295 |
|
| 1296 |
|
| 1297 | #ifdef CONFIG_NUMA_BALANCING
|
| 1298 | void print_numa_stats(struct seq_file *m, int node, unsigned long tsf,
|
| 1299 | unsigned long tpf, unsigned long gsf, unsigned long gpf)
|
| 1300 | {
|
| 1301 | SEQ_printf(m, "numa_faults node=%d ", node);
|
| 1302 | SEQ_printf(m, "task_private=%lu task_shared=%lu ", tpf, tsf);
|
| 1303 | SEQ_printf(m, "group_private=%lu group_shared=%lu\n", gpf, gsf);
|
| 1304 | }
|
| 1305 | #endif
|
| 1306 |
|
| 1307 |
|
| 1308 | static void sched_show_numa(struct task_struct *p, struct seq_file *m)
|
| 1309 | {
|
| 1310 | #ifdef CONFIG_NUMA_BALANCING
|
| 1311 | if (p->mm)
|
| 1312 | P(mm->numa_scan_seq);
|
| 1313 |
|
| 1314 | P(numa_pages_migrated);
|
| 1315 | P(numa_preferred_nid);
|
| 1316 | P(total_numa_faults);
|
| 1317 | SEQ_printf(m, "current_node=%d, numa_group_id=%d\n",
|
| 1318 | task_node(p), task_numa_group_id(p));
|
| 1319 | show_numa_stats(p, m);
|
| 1320 | #endif
|
| 1321 | }
|
| 1322 |
|
| 1323 | void proc_sched_show_task(struct task_struct *p, struct pid_namespace *ns,
|
| 1324 | struct seq_file *m)
|
| 1325 | {
|
| 1326 | unsigned long nr_switches;
|
| 1327 |
|
| 1328 | SEQ_printf(m, "%s (%d, #threads: %d)\n", p->comm, task_pid_nr_ns(p, ns),
|
| 1329 | get_nr_threads(p));
|
| 1330 | SEQ_printf(m,
|
| 1331 | "---------------------------------------------------------"
|
| 1332 | "----------\n");
|
| 1333 |
|
| 1334 | #define P_SCHEDSTAT(F) __PS(#F, schedstat_val(p->stats.F))
|
| 1335 | #define PN_SCHEDSTAT(F) __PSN(#F, schedstat_val(p->stats.F))
|
| 1336 |
|
| 1337 | PN(se.exec_start);
|
| 1338 | PN(se.vruntime);
|
| 1339 | PN(se.sum_exec_runtime);
|
| 1340 |
|
| 1341 | nr_switches = p->nvcsw + p->nivcsw;
|
| 1342 |
|
| 1343 | P(se.nr_migrations);
|
| 1344 |
|
| 1345 | if (schedstat_enabled()) {
|
| 1346 | u64 avg_atom, avg_per_cpu;
|
| 1347 |
|
| 1348 | PN_SCHEDSTAT(sum_sleep_runtime);
|
| 1349 | PN_SCHEDSTAT(sum_block_runtime);
|
| 1350 | PN_SCHEDSTAT(wait_start);
|
| 1351 | PN_SCHEDSTAT(sleep_start);
|
| 1352 | PN_SCHEDSTAT(block_start);
|
| 1353 | PN_SCHEDSTAT(sleep_max);
|
| 1354 | PN_SCHEDSTAT(block_max);
|
| 1355 | PN_SCHEDSTAT(exec_max);
|
| 1356 | PN_SCHEDSTAT(slice_max);
|
| 1357 | PN_SCHEDSTAT(wait_max);
|
| 1358 | PN_SCHEDSTAT(wait_sum);
|
| 1359 | P_SCHEDSTAT(wait_count);
|
| 1360 | PN_SCHEDSTAT(iowait_sum);
|
| 1361 | P_SCHEDSTAT(iowait_count);
|
| 1362 | P_SCHEDSTAT(nr_migrations_cold);
|
| 1363 | P_SCHEDSTAT(nr_failed_migrations_affine);
|
| 1364 | P_SCHEDSTAT(nr_failed_migrations_running);
|
| 1365 | P_SCHEDSTAT(nr_failed_migrations_hot);
|
| 1366 | P_SCHEDSTAT(nr_forced_migrations);
|
| 1367 | P_SCHEDSTAT(nr_wakeups);
|
| 1368 | P_SCHEDSTAT(nr_wakeups_sync);
|
| 1369 | P_SCHEDSTAT(nr_wakeups_migrate);
|
| 1370 | P_SCHEDSTAT(nr_wakeups_local);
|
| 1371 | P_SCHEDSTAT(nr_wakeups_remote);
|
| 1372 | P_SCHEDSTAT(nr_wakeups_affine);
|
| 1373 | P_SCHEDSTAT(nr_wakeups_affine_attempts);
|
| 1374 | P_SCHEDSTAT(nr_wakeups_passive);
|
| 1375 | P_SCHEDSTAT(nr_wakeups_idle);
|
| 1376 |
|
| 1377 | avg_atom = p->se.sum_exec_runtime;
|
| 1378 | if (nr_switches)
|
| 1379 | avg_atom = div64_ul(avg_atom, nr_switches);
|
| 1380 | else
|
| 1381 | avg_atom = -1LL;
|
| 1382 |
|
| 1383 | avg_per_cpu = p->se.sum_exec_runtime;
|
| 1384 | if (p->se.nr_migrations) {
|
| 1385 | avg_per_cpu = div64_u64(avg_per_cpu,
|
| 1386 | p->se.nr_migrations);
|
| 1387 | } else {
|
| 1388 | avg_per_cpu = -1LL;
|
| 1389 | }
|
| 1390 |
|
| 1391 | __PN(avg_atom);
|
| 1392 | __PN(avg_per_cpu);
|
| 1393 |
|
| 1394 | #ifdef CONFIG_SCHED_CORE
|
| 1395 | PN_SCHEDSTAT(core_forceidle_sum);
|
| 1396 | #endif
|
| 1397 | }
|
| 1398 |
|
| 1399 | __P(nr_switches);
|
| 1400 | __PS("nr_voluntary_switches", p->nvcsw);
|
| 1401 | __PS("nr_involuntary_switches", p->nivcsw);
|
| 1402 |
|
| 1403 | P(se.load.weight);
|
| 1404 | P(se.avg.load_sum);
|
| 1405 | P(se.avg.runnable_sum);
|
| 1406 | P(se.avg.util_sum);
|
| 1407 | P(se.avg.load_avg);
|
| 1408 | P(se.avg.runnable_avg);
|
| 1409 | P(se.avg.util_avg);
|
| 1410 | P(se.avg.last_update_time);
|
| 1411 | PM(se.avg.util_est, ~UTIL_AVG_UNCHANGED);
|
| 1412 | #ifdef CONFIG_UCLAMP_TASK
|
| 1413 | __PS("uclamp.min", p->uclamp_req[UCLAMP_MIN].value);
|
| 1414 | __PS("uclamp.max", p->uclamp_req[UCLAMP_MAX].value);
|
| 1415 | __PS("effective uclamp.min", uclamp_eff_value(p, UCLAMP_MIN));
|
| 1416 | __PS("effective uclamp.max", uclamp_eff_value(p, UCLAMP_MAX));
|
| 1417 | #endif
|
| 1418 | P(policy);
|
| 1419 | P(prio);
|
| 1420 | if (task_has_dl_policy(p)) {
|
| 1421 | P(dl.runtime);
|
| 1422 | P(dl.deadline);
|
| 1423 | } else if (fair_policy(p->policy)) {
|
| 1424 | P(se.slice);
|
| 1425 | }
|
| 1426 | #ifdef CONFIG_SCHED_CLASS_EXT
|
| 1427 | __PS("ext.enabled", task_on_scx(p));
|
| 1428 | #endif
|
| 1429 | #undef PN_SCHEDSTAT
|
| 1430 | #undef P_SCHEDSTAT
|
| 1431 |
|
| 1432 | {
|
| 1433 | unsigned int this_cpu = raw_smp_processor_id();
|
| 1434 | u64 t0, t1;
|
| 1435 |
|
| 1436 | t0 = cpu_clock(this_cpu);
|
| 1437 | t1 = cpu_clock(this_cpu);
|
| 1438 | __PS("clock-delta", t1-t0);
|
| 1439 | }
|
| 1440 |
|
| 1441 | sched_show_numa(p, m);
|
| 1442 | }
|
| 1443 |
|
| 1444 | void proc_sched_set_task(struct task_struct *p)
|
| 1445 | {
|
| 1446 | #ifdef CONFIG_SCHEDSTATS
|
| 1447 | memset(&p->stats, 0, sizeof(p->stats));
|
| 1448 | #endif
|
| 1449 | }
|
| 1450 |
|
| 1451 | void resched_latency_warn(int cpu, u64 latency)
|
| 1452 | {
|
| 1453 | static DEFINE_RATELIMIT_STATE(latency_check_ratelimit, 60 * 60 * HZ, 1);
|
| 1454 |
|
| 1455 | if (likely(!__ratelimit(&latency_check_ratelimit)))
|
| 1456 | return;
|
| 1457 |
|
| 1458 | pr_err("sched: CPU %d need_resched set for > %llu ns (%d ticks) without schedule\n",
|
| 1459 | cpu, latency, cpu_rq(cpu)->ticks_without_resched);
|
| 1460 | dump_stack();
|
| 1461 | }
|