1 /* 2 * kernel/sched/debug.c 3 * 4 * Print the CFS rbtree and other debugging details 5 * 6 * Copyright(C) 2007, Red Hat, Inc., Ingo Molnar 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License version 2 as 10 * published by the Free Software Foundation. 11 */ 12 #include "sched.h" 13 14 static DEFINE_SPINLOCK(sched_debug_lock); 15 16 /* 17 * This allows printing both to /proc/sched_debug and 18 * to the console 19 */ 20 #define SEQ_printf(m, x...) \ 21 do { \ 22 if (m) \ 23 seq_printf(m, x); \ 24 else \ 25 pr_cont(x); \ 26 } while (0) 27 28 /* 29 * Ease the printing of nsec fields: 30 */ 31 static long long nsec_high(unsigned long long nsec) 32 { 33 if ((long long)nsec < 0) { 34 nsec = -nsec; 35 do_div(nsec, 1000000); 36 return -nsec; 37 } 38 do_div(nsec, 1000000); 39 40 return nsec; 41 } 42 43 static unsigned long nsec_low(unsigned long long nsec) 44 { 45 if ((long long)nsec < 0) 46 nsec = -nsec; 47 48 return do_div(nsec, 1000000); 49 } 50 51 #define SPLIT_NS(x) nsec_high(x), nsec_low(x) 52 53 #define SCHED_FEAT(name, enabled) \ 54 #name , 55 56 static const char * const sched_feat_names[] = { 57 #include "features.h" 58 }; 59 60 #undef SCHED_FEAT 61 62 static int sched_feat_show(struct seq_file *m, void *v) 63 { 64 int i; 65 66 for (i = 0; i < __SCHED_FEAT_NR; i++) { 67 if (!(sysctl_sched_features & (1UL << i))) 68 seq_puts(m, "NO_"); 69 seq_printf(m, "%s ", sched_feat_names[i]); 70 } 71 seq_puts(m, "\n"); 72 73 return 0; 74 } 75 76 #ifdef HAVE_JUMP_LABEL 77 78 #define jump_label_key__true STATIC_KEY_INIT_TRUE 79 #define jump_label_key__false STATIC_KEY_INIT_FALSE 80 81 #define SCHED_FEAT(name, enabled) \ 82 jump_label_key__##enabled , 83 84 struct static_key sched_feat_keys[__SCHED_FEAT_NR] = { 85 #include "features.h" 86 }; 87 88 #undef SCHED_FEAT 89 90 static void sched_feat_disable(int i) 91 { 92 static_key_disable(&sched_feat_keys[i]); 93 } 94 95 static void sched_feat_enable(int i) 96 { 97 static_key_enable(&sched_feat_keys[i]); 98 } 99 #else 100 static void sched_feat_disable(int i) { }; 101 static void sched_feat_enable(int i) { }; 102 #endif /* HAVE_JUMP_LABEL */ 103 104 static int sched_feat_set(char *cmp) 105 { 106 int i; 107 int neg = 0; 108 109 if (strncmp(cmp, "NO_", 3) == 0) { 110 neg = 1; 111 cmp += 3; 112 } 113 114 i = match_string(sched_feat_names, __SCHED_FEAT_NR, cmp); 115 if (i < 0) 116 return i; 117 118 if (neg) { 119 sysctl_sched_features &= ~(1UL << i); 120 sched_feat_disable(i); 121 } else { 122 sysctl_sched_features |= (1UL << i); 123 sched_feat_enable(i); 124 } 125 126 return 0; 127 } 128 129 static ssize_t 130 sched_feat_write(struct file *filp, const char __user *ubuf, 131 size_t cnt, loff_t *ppos) 132 { 133 char buf[64]; 134 char *cmp; 135 int ret; 136 struct inode *inode; 137 138 if (cnt > 63) 139 cnt = 63; 140 141 if (copy_from_user(&buf, ubuf, cnt)) 142 return -EFAULT; 143 144 buf[cnt] = 0; 145 cmp = strstrip(buf); 146 147 /* Ensure the static_key remains in a consistent state */ 148 inode = file_inode(filp); 149 inode_lock(inode); 150 ret = sched_feat_set(cmp); 151 inode_unlock(inode); 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 __read_mostly bool sched_debug_enabled; 174 175 static __init int sched_init_debug(void) 176 { 177 debugfs_create_file("sched_features", 0644, NULL, NULL, 178 &sched_feat_fops); 179 180 debugfs_create_bool("sched_debug", 0644, NULL, 181 &sched_debug_enabled); 182 183 return 0; 184 } 185 late_initcall(sched_init_debug); 186 187 #ifdef CONFIG_SMP 188 189 #ifdef CONFIG_SYSCTL 190 191 static struct ctl_table sd_ctl_dir[] = { 192 { 193 .procname = "sched_domain", 194 .mode = 0555, 195 }, 196 {} 197 }; 198 199 static struct ctl_table sd_ctl_root[] = { 200 { 201 .procname = "kernel", 202 .mode = 0555, 203 .child = sd_ctl_dir, 204 }, 205 {} 206 }; 207 208 static struct ctl_table *sd_alloc_ctl_entry(int n) 209 { 210 struct ctl_table *entry = 211 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL); 212 213 return entry; 214 } 215 216 static void sd_free_ctl_entry(struct ctl_table **tablep) 217 { 218 struct ctl_table *entry; 219 220 /* 221 * In the intermediate directories, both the child directory and 222 * procname are dynamically allocated and could fail but the mode 223 * will always be set. In the lowest directory the names are 224 * static strings and all have proc handlers. 225 */ 226 for (entry = *tablep; entry->mode; entry++) { 227 if (entry->child) 228 sd_free_ctl_entry(&entry->child); 229 if (entry->proc_handler == NULL) 230 kfree(entry->procname); 231 } 232 233 kfree(*tablep); 234 *tablep = NULL; 235 } 236 237 static int min_load_idx = 0; 238 static int max_load_idx = CPU_LOAD_IDX_MAX-1; 239 240 static void 241 set_table_entry(struct ctl_table *entry, 242 const char *procname, void *data, int maxlen, 243 umode_t mode, proc_handler *proc_handler, 244 bool load_idx) 245 { 246 entry->procname = procname; 247 entry->data = data; 248 entry->maxlen = maxlen; 249 entry->mode = mode; 250 entry->proc_handler = proc_handler; 251 252 if (load_idx) { 253 entry->extra1 = &min_load_idx; 254 entry->extra2 = &max_load_idx; 255 } 256 } 257 258 static struct ctl_table * 259 sd_alloc_ctl_domain_table(struct sched_domain *sd) 260 { 261 struct ctl_table *table = sd_alloc_ctl_entry(14); 262 263 if (table == NULL) 264 return NULL; 265 266 set_table_entry(&table[0] , "min_interval", &sd->min_interval, sizeof(long), 0644, proc_doulongvec_minmax, false); 267 set_table_entry(&table[1] , "max_interval", &sd->max_interval, sizeof(long), 0644, proc_doulongvec_minmax, false); 268 set_table_entry(&table[2] , "busy_idx", &sd->busy_idx, sizeof(int) , 0644, proc_dointvec_minmax, true ); 269 set_table_entry(&table[3] , "idle_idx", &sd->idle_idx, sizeof(int) , 0644, proc_dointvec_minmax, true ); 270 set_table_entry(&table[4] , "newidle_idx", &sd->newidle_idx, sizeof(int) , 0644, proc_dointvec_minmax, true ); 271 set_table_entry(&table[5] , "wake_idx", &sd->wake_idx, sizeof(int) , 0644, proc_dointvec_minmax, true ); 272 set_table_entry(&table[6] , "forkexec_idx", &sd->forkexec_idx, sizeof(int) , 0644, proc_dointvec_minmax, true ); 273 set_table_entry(&table[7] , "busy_factor", &sd->busy_factor, sizeof(int) , 0644, proc_dointvec_minmax, false); 274 set_table_entry(&table[8] , "imbalance_pct", &sd->imbalance_pct, sizeof(int) , 0644, proc_dointvec_minmax, false); 275 set_table_entry(&table[9] , "cache_nice_tries", &sd->cache_nice_tries, sizeof(int) , 0644, proc_dointvec_minmax, false); 276 set_table_entry(&table[10], "flags", &sd->flags, sizeof(int) , 0644, proc_dointvec_minmax, false); 277 set_table_entry(&table[11], "max_newidle_lb_cost", &sd->max_newidle_lb_cost, sizeof(long), 0644, proc_doulongvec_minmax, false); 278 set_table_entry(&table[12], "name", sd->name, CORENAME_MAX_SIZE, 0444, proc_dostring, false); 279 /* &table[13] is terminator */ 280 281 return table; 282 } 283 284 static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu) 285 { 286 struct ctl_table *entry, *table; 287 struct sched_domain *sd; 288 int domain_num = 0, i; 289 char buf[32]; 290 291 for_each_domain(cpu, sd) 292 domain_num++; 293 entry = table = sd_alloc_ctl_entry(domain_num + 1); 294 if (table == NULL) 295 return NULL; 296 297 i = 0; 298 for_each_domain(cpu, sd) { 299 snprintf(buf, 32, "domain%d", i); 300 entry->procname = kstrdup(buf, GFP_KERNEL); 301 entry->mode = 0555; 302 entry->child = sd_alloc_ctl_domain_table(sd); 303 entry++; 304 i++; 305 } 306 return table; 307 } 308 309 static cpumask_var_t sd_sysctl_cpus; 310 static struct ctl_table_header *sd_sysctl_header; 311 312 void register_sched_domain_sysctl(void) 313 { 314 static struct ctl_table *cpu_entries; 315 static struct ctl_table **cpu_idx; 316 char buf[32]; 317 int i; 318 319 if (!cpu_entries) { 320 cpu_entries = sd_alloc_ctl_entry(num_possible_cpus() + 1); 321 if (!cpu_entries) 322 return; 323 324 WARN_ON(sd_ctl_dir[0].child); 325 sd_ctl_dir[0].child = cpu_entries; 326 } 327 328 if (!cpu_idx) { 329 struct ctl_table *e = cpu_entries; 330 331 cpu_idx = kcalloc(nr_cpu_ids, sizeof(struct ctl_table*), GFP_KERNEL); 332 if (!cpu_idx) 333 return; 334 335 /* deal with sparse possible map */ 336 for_each_possible_cpu(i) { 337 cpu_idx[i] = e; 338 e++; 339 } 340 } 341 342 if (!cpumask_available(sd_sysctl_cpus)) { 343 if (!alloc_cpumask_var(&sd_sysctl_cpus, GFP_KERNEL)) 344 return; 345 346 /* init to possible to not have holes in @cpu_entries */ 347 cpumask_copy(sd_sysctl_cpus, cpu_possible_mask); 348 } 349 350 for_each_cpu(i, sd_sysctl_cpus) { 351 struct ctl_table *e = cpu_idx[i]; 352 353 if (e->child) 354 sd_free_ctl_entry(&e->child); 355 356 if (!e->procname) { 357 snprintf(buf, 32, "cpu%d", i); 358 e->procname = kstrdup(buf, GFP_KERNEL); 359 } 360 e->mode = 0555; 361 e->child = sd_alloc_ctl_cpu_table(i); 362 363 __cpumask_clear_cpu(i, sd_sysctl_cpus); 364 } 365 366 WARN_ON(sd_sysctl_header); 367 sd_sysctl_header = register_sysctl_table(sd_ctl_root); 368 } 369 370 void dirty_sched_domain_sysctl(int cpu) 371 { 372 if (cpumask_available(sd_sysctl_cpus)) 373 __cpumask_set_cpu(cpu, sd_sysctl_cpus); 374 } 375 376 /* may be called multiple times per register */ 377 void unregister_sched_domain_sysctl(void) 378 { 379 unregister_sysctl_table(sd_sysctl_header); 380 sd_sysctl_header = NULL; 381 } 382 #endif /* CONFIG_SYSCTL */ 383 #endif /* CONFIG_SMP */ 384 385 #ifdef CONFIG_FAIR_GROUP_SCHED 386 static void print_cfs_group_stats(struct seq_file *m, int cpu, struct task_group *tg) 387 { 388 struct sched_entity *se = tg->se[cpu]; 389 390 #define P(F) SEQ_printf(m, " .%-30s: %lld\n", #F, (long long)F) 391 #define P_SCHEDSTAT(F) SEQ_printf(m, " .%-30s: %lld\n", #F, (long long)schedstat_val(F)) 392 #define PN(F) SEQ_printf(m, " .%-30s: %lld.%06ld\n", #F, SPLIT_NS((long long)F)) 393 #define PN_SCHEDSTAT(F) SEQ_printf(m, " .%-30s: %lld.%06ld\n", #F, SPLIT_NS((long long)schedstat_val(F))) 394 395 if (!se) 396 return; 397 398 PN(se->exec_start); 399 PN(se->vruntime); 400 PN(se->sum_exec_runtime); 401 402 if (schedstat_enabled()) { 403 PN_SCHEDSTAT(se->statistics.wait_start); 404 PN_SCHEDSTAT(se->statistics.sleep_start); 405 PN_SCHEDSTAT(se->statistics.block_start); 406 PN_SCHEDSTAT(se->statistics.sleep_max); 407 PN_SCHEDSTAT(se->statistics.block_max); 408 PN_SCHEDSTAT(se->statistics.exec_max); 409 PN_SCHEDSTAT(se->statistics.slice_max); 410 PN_SCHEDSTAT(se->statistics.wait_max); 411 PN_SCHEDSTAT(se->statistics.wait_sum); 412 P_SCHEDSTAT(se->statistics.wait_count); 413 } 414 415 P(se->load.weight); 416 P(se->runnable_weight); 417 #ifdef CONFIG_SMP 418 P(se->avg.load_avg); 419 P(se->avg.util_avg); 420 P(se->avg.runnable_load_avg); 421 #endif 422 423 #undef PN_SCHEDSTAT 424 #undef PN 425 #undef P_SCHEDSTAT 426 #undef P 427 } 428 #endif 429 430 #ifdef CONFIG_CGROUP_SCHED 431 static char group_path[PATH_MAX]; 432 433 static char *task_group_path(struct task_group *tg) 434 { 435 if (autogroup_path(tg, group_path, PATH_MAX)) 436 return group_path; 437 438 cgroup_path(tg->css.cgroup, group_path, PATH_MAX); 439 440 return group_path; 441 } 442 #endif 443 444 static void 445 print_task(struct seq_file *m, struct rq *rq, struct task_struct *p) 446 { 447 if (rq->curr == p) 448 SEQ_printf(m, ">R"); 449 else 450 SEQ_printf(m, " %c", task_state_to_char(p)); 451 452 SEQ_printf(m, "%15s %5d %9Ld.%06ld %9Ld %5d ", 453 p->comm, task_pid_nr(p), 454 SPLIT_NS(p->se.vruntime), 455 (long long)(p->nvcsw + p->nivcsw), 456 p->prio); 457 458 SEQ_printf(m, "%9Ld.%06ld %9Ld.%06ld %9Ld.%06ld", 459 SPLIT_NS(schedstat_val_or_zero(p->se.statistics.wait_sum)), 460 SPLIT_NS(p->se.sum_exec_runtime), 461 SPLIT_NS(schedstat_val_or_zero(p->se.statistics.sum_sleep_runtime))); 462 463 #ifdef CONFIG_NUMA_BALANCING 464 SEQ_printf(m, " %d %d", task_node(p), task_numa_group_id(p)); 465 #endif 466 #ifdef CONFIG_CGROUP_SCHED 467 SEQ_printf(m, " %s", task_group_path(task_group(p))); 468 #endif 469 470 SEQ_printf(m, "\n"); 471 } 472 473 static void print_rq(struct seq_file *m, struct rq *rq, int rq_cpu) 474 { 475 struct task_struct *g, *p; 476 477 SEQ_printf(m, "\n"); 478 SEQ_printf(m, "runnable tasks:\n"); 479 SEQ_printf(m, " S task PID tree-key switches prio" 480 " wait-time sum-exec sum-sleep\n"); 481 SEQ_printf(m, "-------------------------------------------------------" 482 "----------------------------------------------------\n"); 483 484 rcu_read_lock(); 485 for_each_process_thread(g, p) { 486 if (task_cpu(p) != rq_cpu) 487 continue; 488 489 print_task(m, rq, p); 490 } 491 rcu_read_unlock(); 492 } 493 494 void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq) 495 { 496 s64 MIN_vruntime = -1, min_vruntime, max_vruntime = -1, 497 spread, rq0_min_vruntime, spread0; 498 struct rq *rq = cpu_rq(cpu); 499 struct sched_entity *last; 500 unsigned long flags; 501 502 #ifdef CONFIG_FAIR_GROUP_SCHED 503 SEQ_printf(m, "\n"); 504 SEQ_printf(m, "cfs_rq[%d]:%s\n", cpu, task_group_path(cfs_rq->tg)); 505 #else 506 SEQ_printf(m, "\n"); 507 SEQ_printf(m, "cfs_rq[%d]:\n", cpu); 508 #endif 509 SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "exec_clock", 510 SPLIT_NS(cfs_rq->exec_clock)); 511 512 raw_spin_lock_irqsave(&rq->lock, flags); 513 if (rb_first_cached(&cfs_rq->tasks_timeline)) 514 MIN_vruntime = (__pick_first_entity(cfs_rq))->vruntime; 515 last = __pick_last_entity(cfs_rq); 516 if (last) 517 max_vruntime = last->vruntime; 518 min_vruntime = cfs_rq->min_vruntime; 519 rq0_min_vruntime = cpu_rq(0)->cfs.min_vruntime; 520 raw_spin_unlock_irqrestore(&rq->lock, flags); 521 SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "MIN_vruntime", 522 SPLIT_NS(MIN_vruntime)); 523 SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "min_vruntime", 524 SPLIT_NS(min_vruntime)); 525 SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "max_vruntime", 526 SPLIT_NS(max_vruntime)); 527 spread = max_vruntime - MIN_vruntime; 528 SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "spread", 529 SPLIT_NS(spread)); 530 spread0 = min_vruntime - rq0_min_vruntime; 531 SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "spread0", 532 SPLIT_NS(spread0)); 533 SEQ_printf(m, " .%-30s: %d\n", "nr_spread_over", 534 cfs_rq->nr_spread_over); 535 SEQ_printf(m, " .%-30s: %d\n", "nr_running", cfs_rq->nr_running); 536 SEQ_printf(m, " .%-30s: %ld\n", "load", cfs_rq->load.weight); 537 #ifdef CONFIG_SMP 538 SEQ_printf(m, " .%-30s: %ld\n", "runnable_weight", cfs_rq->runnable_weight); 539 SEQ_printf(m, " .%-30s: %lu\n", "load_avg", 540 cfs_rq->avg.load_avg); 541 SEQ_printf(m, " .%-30s: %lu\n", "runnable_load_avg", 542 cfs_rq->avg.runnable_load_avg); 543 SEQ_printf(m, " .%-30s: %lu\n", "util_avg", 544 cfs_rq->avg.util_avg); 545 SEQ_printf(m, " .%-30s: %u\n", "util_est_enqueued", 546 cfs_rq->avg.util_est.enqueued); 547 SEQ_printf(m, " .%-30s: %ld\n", "removed.load_avg", 548 cfs_rq->removed.load_avg); 549 SEQ_printf(m, " .%-30s: %ld\n", "removed.util_avg", 550 cfs_rq->removed.util_avg); 551 SEQ_printf(m, " .%-30s: %ld\n", "removed.runnable_sum", 552 cfs_rq->removed.runnable_sum); 553 #ifdef CONFIG_FAIR_GROUP_SCHED 554 SEQ_printf(m, " .%-30s: %lu\n", "tg_load_avg_contrib", 555 cfs_rq->tg_load_avg_contrib); 556 SEQ_printf(m, " .%-30s: %ld\n", "tg_load_avg", 557 atomic_long_read(&cfs_rq->tg->load_avg)); 558 #endif 559 #endif 560 #ifdef CONFIG_CFS_BANDWIDTH 561 SEQ_printf(m, " .%-30s: %d\n", "throttled", 562 cfs_rq->throttled); 563 SEQ_printf(m, " .%-30s: %d\n", "throttle_count", 564 cfs_rq->throttle_count); 565 #endif 566 567 #ifdef CONFIG_FAIR_GROUP_SCHED 568 print_cfs_group_stats(m, cpu, cfs_rq->tg); 569 #endif 570 } 571 572 void print_rt_rq(struct seq_file *m, int cpu, struct rt_rq *rt_rq) 573 { 574 #ifdef CONFIG_RT_GROUP_SCHED 575 SEQ_printf(m, "\n"); 576 SEQ_printf(m, "rt_rq[%d]:%s\n", cpu, task_group_path(rt_rq->tg)); 577 #else 578 SEQ_printf(m, "\n"); 579 SEQ_printf(m, "rt_rq[%d]:\n", cpu); 580 #endif 581 582 #define P(x) \ 583 SEQ_printf(m, " .%-30s: %Ld\n", #x, (long long)(rt_rq->x)) 584 #define PU(x) \ 585 SEQ_printf(m, " .%-30s: %lu\n", #x, (unsigned long)(rt_rq->x)) 586 #define PN(x) \ 587 SEQ_printf(m, " .%-30s: %Ld.%06ld\n", #x, SPLIT_NS(rt_rq->x)) 588 589 PU(rt_nr_running); 590 #ifdef CONFIG_SMP 591 PU(rt_nr_migratory); 592 #endif 593 P(rt_throttled); 594 PN(rt_time); 595 PN(rt_runtime); 596 597 #undef PN 598 #undef PU 599 #undef P 600 } 601 602 void print_dl_rq(struct seq_file *m, int cpu, struct dl_rq *dl_rq) 603 { 604 struct dl_bw *dl_bw; 605 606 SEQ_printf(m, "\n"); 607 SEQ_printf(m, "dl_rq[%d]:\n", cpu); 608 609 #define PU(x) \ 610 SEQ_printf(m, " .%-30s: %lu\n", #x, (unsigned long)(dl_rq->x)) 611 612 PU(dl_nr_running); 613 #ifdef CONFIG_SMP 614 PU(dl_nr_migratory); 615 dl_bw = &cpu_rq(cpu)->rd->dl_bw; 616 #else 617 dl_bw = &dl_rq->dl_bw; 618 #endif 619 SEQ_printf(m, " .%-30s: %lld\n", "dl_bw->bw", dl_bw->bw); 620 SEQ_printf(m, " .%-30s: %lld\n", "dl_bw->total_bw", dl_bw->total_bw); 621 622 #undef PU 623 } 624 625 static void print_cpu(struct seq_file *m, int cpu) 626 { 627 struct rq *rq = cpu_rq(cpu); 628 unsigned long flags; 629 630 #ifdef CONFIG_X86 631 { 632 unsigned int freq = cpu_khz ? : 1; 633 634 SEQ_printf(m, "cpu#%d, %u.%03u MHz\n", 635 cpu, freq / 1000, (freq % 1000)); 636 } 637 #else 638 SEQ_printf(m, "cpu#%d\n", cpu); 639 #endif 640 641 #define P(x) \ 642 do { \ 643 if (sizeof(rq->x) == 4) \ 644 SEQ_printf(m, " .%-30s: %ld\n", #x, (long)(rq->x)); \ 645 else \ 646 SEQ_printf(m, " .%-30s: %Ld\n", #x, (long long)(rq->x));\ 647 } while (0) 648 649 #define PN(x) \ 650 SEQ_printf(m, " .%-30s: %Ld.%06ld\n", #x, SPLIT_NS(rq->x)) 651 652 P(nr_running); 653 SEQ_printf(m, " .%-30s: %lu\n", "load", 654 rq->load.weight); 655 P(nr_switches); 656 P(nr_load_updates); 657 P(nr_uninterruptible); 658 PN(next_balance); 659 SEQ_printf(m, " .%-30s: %ld\n", "curr->pid", (long)(task_pid_nr(rq->curr))); 660 PN(clock); 661 PN(clock_task); 662 P(cpu_load[0]); 663 P(cpu_load[1]); 664 P(cpu_load[2]); 665 P(cpu_load[3]); 666 P(cpu_load[4]); 667 #undef P 668 #undef PN 669 670 #ifdef CONFIG_SMP 671 #define P64(n) SEQ_printf(m, " .%-30s: %Ld\n", #n, rq->n); 672 P64(avg_idle); 673 P64(max_idle_balance_cost); 674 #undef P64 675 #endif 676 677 #define P(n) SEQ_printf(m, " .%-30s: %d\n", #n, schedstat_val(rq->n)); 678 if (schedstat_enabled()) { 679 P(yld_count); 680 P(sched_count); 681 P(sched_goidle); 682 P(ttwu_count); 683 P(ttwu_local); 684 } 685 #undef P 686 687 spin_lock_irqsave(&sched_debug_lock, flags); 688 print_cfs_stats(m, cpu); 689 print_rt_stats(m, cpu); 690 print_dl_stats(m, cpu); 691 692 print_rq(m, rq, cpu); 693 spin_unlock_irqrestore(&sched_debug_lock, flags); 694 SEQ_printf(m, "\n"); 695 } 696 697 static const char *sched_tunable_scaling_names[] = { 698 "none", 699 "logaritmic", 700 "linear" 701 }; 702 703 static void sched_debug_header(struct seq_file *m) 704 { 705 u64 ktime, sched_clk, cpu_clk; 706 unsigned long flags; 707 708 local_irq_save(flags); 709 ktime = ktime_to_ns(ktime_get()); 710 sched_clk = sched_clock(); 711 cpu_clk = local_clock(); 712 local_irq_restore(flags); 713 714 SEQ_printf(m, "Sched Debug Version: v0.11, %s %.*s\n", 715 init_utsname()->release, 716 (int)strcspn(init_utsname()->version, " "), 717 init_utsname()->version); 718 719 #define P(x) \ 720 SEQ_printf(m, "%-40s: %Ld\n", #x, (long long)(x)) 721 #define PN(x) \ 722 SEQ_printf(m, "%-40s: %Ld.%06ld\n", #x, SPLIT_NS(x)) 723 PN(ktime); 724 PN(sched_clk); 725 PN(cpu_clk); 726 P(jiffies); 727 #ifdef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK 728 P(sched_clock_stable()); 729 #endif 730 #undef PN 731 #undef P 732 733 SEQ_printf(m, "\n"); 734 SEQ_printf(m, "sysctl_sched\n"); 735 736 #define P(x) \ 737 SEQ_printf(m, " .%-40s: %Ld\n", #x, (long long)(x)) 738 #define PN(x) \ 739 SEQ_printf(m, " .%-40s: %Ld.%06ld\n", #x, SPLIT_NS(x)) 740 PN(sysctl_sched_latency); 741 PN(sysctl_sched_min_granularity); 742 PN(sysctl_sched_wakeup_granularity); 743 P(sysctl_sched_child_runs_first); 744 P(sysctl_sched_features); 745 #undef PN 746 #undef P 747 748 SEQ_printf(m, " .%-40s: %d (%s)\n", 749 "sysctl_sched_tunable_scaling", 750 sysctl_sched_tunable_scaling, 751 sched_tunable_scaling_names[sysctl_sched_tunable_scaling]); 752 SEQ_printf(m, "\n"); 753 } 754 755 static int sched_debug_show(struct seq_file *m, void *v) 756 { 757 int cpu = (unsigned long)(v - 2); 758 759 if (cpu != -1) 760 print_cpu(m, cpu); 761 else 762 sched_debug_header(m); 763 764 return 0; 765 } 766 767 void sysrq_sched_debug_show(void) 768 { 769 int cpu; 770 771 sched_debug_header(NULL); 772 for_each_online_cpu(cpu) 773 print_cpu(NULL, cpu); 774 775 } 776 777 /* 778 * This itererator needs some explanation. 779 * It returns 1 for the header position. 780 * This means 2 is CPU 0. 781 * In a hotplugged system some CPUs, including CPU 0, may be missing so we have 782 * to use cpumask_* to iterate over the CPUs. 783 */ 784 static void *sched_debug_start(struct seq_file *file, loff_t *offset) 785 { 786 unsigned long n = *offset; 787 788 if (n == 0) 789 return (void *) 1; 790 791 n--; 792 793 if (n > 0) 794 n = cpumask_next(n - 1, cpu_online_mask); 795 else 796 n = cpumask_first(cpu_online_mask); 797 798 *offset = n + 1; 799 800 if (n < nr_cpu_ids) 801 return (void *)(unsigned long)(n + 2); 802 803 return NULL; 804 } 805 806 static void *sched_debug_next(struct seq_file *file, void *data, loff_t *offset) 807 { 808 (*offset)++; 809 return sched_debug_start(file, offset); 810 } 811 812 static void sched_debug_stop(struct seq_file *file, void *data) 813 { 814 } 815 816 static const struct seq_operations sched_debug_sops = { 817 .start = sched_debug_start, 818 .next = sched_debug_next, 819 .stop = sched_debug_stop, 820 .show = sched_debug_show, 821 }; 822 823 static int __init init_sched_debug_procfs(void) 824 { 825 if (!proc_create_seq("sched_debug", 0444, NULL, &sched_debug_sops)) 826 return -ENOMEM; 827 return 0; 828 } 829 830 __initcall(init_sched_debug_procfs); 831 832 #define __P(F) SEQ_printf(m, "%-45s:%21Ld\n", #F, (long long)F) 833 #define P(F) SEQ_printf(m, "%-45s:%21Ld\n", #F, (long long)p->F) 834 #define __PN(F) SEQ_printf(m, "%-45s:%14Ld.%06ld\n", #F, SPLIT_NS((long long)F)) 835 #define PN(F) SEQ_printf(m, "%-45s:%14Ld.%06ld\n", #F, SPLIT_NS((long long)p->F)) 836 837 838 #ifdef CONFIG_NUMA_BALANCING 839 void print_numa_stats(struct seq_file *m, int node, unsigned long tsf, 840 unsigned long tpf, unsigned long gsf, unsigned long gpf) 841 { 842 SEQ_printf(m, "numa_faults node=%d ", node); 843 SEQ_printf(m, "task_private=%lu task_shared=%lu ", tpf, tsf); 844 SEQ_printf(m, "group_private=%lu group_shared=%lu\n", gpf, gsf); 845 } 846 #endif 847 848 849 static void sched_show_numa(struct task_struct *p, struct seq_file *m) 850 { 851 #ifdef CONFIG_NUMA_BALANCING 852 struct mempolicy *pol; 853 854 if (p->mm) 855 P(mm->numa_scan_seq); 856 857 task_lock(p); 858 pol = p->mempolicy; 859 if (pol && !(pol->flags & MPOL_F_MORON)) 860 pol = NULL; 861 mpol_get(pol); 862 task_unlock(p); 863 864 P(numa_pages_migrated); 865 P(numa_preferred_nid); 866 P(total_numa_faults); 867 SEQ_printf(m, "current_node=%d, numa_group_id=%d\n", 868 task_node(p), task_numa_group_id(p)); 869 show_numa_stats(p, m); 870 mpol_put(pol); 871 #endif 872 } 873 874 void proc_sched_show_task(struct task_struct *p, struct pid_namespace *ns, 875 struct seq_file *m) 876 { 877 unsigned long nr_switches; 878 879 SEQ_printf(m, "%s (%d, #threads: %d)\n", p->comm, task_pid_nr_ns(p, ns), 880 get_nr_threads(p)); 881 SEQ_printf(m, 882 "---------------------------------------------------------" 883 "----------\n"); 884 #define __P(F) \ 885 SEQ_printf(m, "%-45s:%21Ld\n", #F, (long long)F) 886 #define P(F) \ 887 SEQ_printf(m, "%-45s:%21Ld\n", #F, (long long)p->F) 888 #define P_SCHEDSTAT(F) \ 889 SEQ_printf(m, "%-45s:%21Ld\n", #F, (long long)schedstat_val(p->F)) 890 #define __PN(F) \ 891 SEQ_printf(m, "%-45s:%14Ld.%06ld\n", #F, SPLIT_NS((long long)F)) 892 #define PN(F) \ 893 SEQ_printf(m, "%-45s:%14Ld.%06ld\n", #F, SPLIT_NS((long long)p->F)) 894 #define PN_SCHEDSTAT(F) \ 895 SEQ_printf(m, "%-45s:%14Ld.%06ld\n", #F, SPLIT_NS((long long)schedstat_val(p->F))) 896 897 PN(se.exec_start); 898 PN(se.vruntime); 899 PN(se.sum_exec_runtime); 900 901 nr_switches = p->nvcsw + p->nivcsw; 902 903 P(se.nr_migrations); 904 905 if (schedstat_enabled()) { 906 u64 avg_atom, avg_per_cpu; 907 908 PN_SCHEDSTAT(se.statistics.sum_sleep_runtime); 909 PN_SCHEDSTAT(se.statistics.wait_start); 910 PN_SCHEDSTAT(se.statistics.sleep_start); 911 PN_SCHEDSTAT(se.statistics.block_start); 912 PN_SCHEDSTAT(se.statistics.sleep_max); 913 PN_SCHEDSTAT(se.statistics.block_max); 914 PN_SCHEDSTAT(se.statistics.exec_max); 915 PN_SCHEDSTAT(se.statistics.slice_max); 916 PN_SCHEDSTAT(se.statistics.wait_max); 917 PN_SCHEDSTAT(se.statistics.wait_sum); 918 P_SCHEDSTAT(se.statistics.wait_count); 919 PN_SCHEDSTAT(se.statistics.iowait_sum); 920 P_SCHEDSTAT(se.statistics.iowait_count); 921 P_SCHEDSTAT(se.statistics.nr_migrations_cold); 922 P_SCHEDSTAT(se.statistics.nr_failed_migrations_affine); 923 P_SCHEDSTAT(se.statistics.nr_failed_migrations_running); 924 P_SCHEDSTAT(se.statistics.nr_failed_migrations_hot); 925 P_SCHEDSTAT(se.statistics.nr_forced_migrations); 926 P_SCHEDSTAT(se.statistics.nr_wakeups); 927 P_SCHEDSTAT(se.statistics.nr_wakeups_sync); 928 P_SCHEDSTAT(se.statistics.nr_wakeups_migrate); 929 P_SCHEDSTAT(se.statistics.nr_wakeups_local); 930 P_SCHEDSTAT(se.statistics.nr_wakeups_remote); 931 P_SCHEDSTAT(se.statistics.nr_wakeups_affine); 932 P_SCHEDSTAT(se.statistics.nr_wakeups_affine_attempts); 933 P_SCHEDSTAT(se.statistics.nr_wakeups_passive); 934 P_SCHEDSTAT(se.statistics.nr_wakeups_idle); 935 936 avg_atom = p->se.sum_exec_runtime; 937 if (nr_switches) 938 avg_atom = div64_ul(avg_atom, nr_switches); 939 else 940 avg_atom = -1LL; 941 942 avg_per_cpu = p->se.sum_exec_runtime; 943 if (p->se.nr_migrations) { 944 avg_per_cpu = div64_u64(avg_per_cpu, 945 p->se.nr_migrations); 946 } else { 947 avg_per_cpu = -1LL; 948 } 949 950 __PN(avg_atom); 951 __PN(avg_per_cpu); 952 } 953 954 __P(nr_switches); 955 SEQ_printf(m, "%-45s:%21Ld\n", 956 "nr_voluntary_switches", (long long)p->nvcsw); 957 SEQ_printf(m, "%-45s:%21Ld\n", 958 "nr_involuntary_switches", (long long)p->nivcsw); 959 960 P(se.load.weight); 961 P(se.runnable_weight); 962 #ifdef CONFIG_SMP 963 P(se.avg.load_sum); 964 P(se.avg.runnable_load_sum); 965 P(se.avg.util_sum); 966 P(se.avg.load_avg); 967 P(se.avg.runnable_load_avg); 968 P(se.avg.util_avg); 969 P(se.avg.last_update_time); 970 P(se.avg.util_est.ewma); 971 P(se.avg.util_est.enqueued); 972 #endif 973 P(policy); 974 P(prio); 975 if (p->policy == SCHED_DEADLINE) { 976 P(dl.runtime); 977 P(dl.deadline); 978 } 979 #undef PN_SCHEDSTAT 980 #undef PN 981 #undef __PN 982 #undef P_SCHEDSTAT 983 #undef P 984 #undef __P 985 986 { 987 unsigned int this_cpu = raw_smp_processor_id(); 988 u64 t0, t1; 989 990 t0 = cpu_clock(this_cpu); 991 t1 = cpu_clock(this_cpu); 992 SEQ_printf(m, "%-45s:%21Ld\n", 993 "clock-delta", (long long)(t1-t0)); 994 } 995 996 sched_show_numa(p, m); 997 } 998 999 void proc_sched_set_task(struct task_struct *p) 1000 { 1001 #ifdef CONFIG_SCHEDSTATS 1002 memset(&p->se.statistics, 0, sizeof(p->se.statistics)); 1003 #endif 1004 } 1005