调度器18—/proc/schedstat文件
作者:互联网
一、打印说明
1. 打印文件 kernel/sched/stats.c
// SPDX-License-Identifier: GPL-2.0 /* * /proc/schedstat implementation, kernel/sched/stats.c */ #include "sched.h" /* * Current schedstat API version. * * Bump this up when changing the output format or the meaning of an existing * format, so that tools can adapt (or abort) */ #define SCHEDSTAT_VERSION 15 static int show_schedstat(struct seq_file *seq, void *v) { int cpu; if (v == (void *)1) { seq_printf(seq, "version %d\n", SCHEDSTAT_VERSION); seq_printf(seq, "timestamp %lu\n", jiffies); } else { struct rq *rq; #ifdef CONFIG_SMP struct sched_domain *sd; int dcount = 0; #endif cpu = (unsigned long)(v - 2); rq = cpu_rq(cpu); /* runqueue-specific stats */ seq_printf(seq, "cpu%d %u 0 %u %u %u %u %llu %llu %lu", cpu, rq->yld_count, rq->sched_count, rq->sched_goidle, rq->ttwu_count, rq->ttwu_local, rq->rq_cpu_time, rq->rq_sched_info.run_delay, rq->rq_sched_info.pcount); seq_printf(seq, "\n"); #ifdef CONFIG_SMP /* domain-specific stats */ rcu_read_lock(); for_each_domain(cpu, sd) { enum cpu_idle_type itype; seq_printf(seq, "domain%d %*pb", dcount++, cpumask_pr_args(sched_domain_span(sd))); for (itype = CPU_IDLE; itype < CPU_MAX_IDLE_TYPES; itype++) { seq_printf(seq, " %u %u %u %u %u %u %u %u", sd->lb_count[itype], sd->lb_balanced[itype], sd->lb_failed[itype], sd->lb_imbalance[itype], sd->lb_gained[itype], sd->lb_hot_gained[itype], sd->lb_nobusyq[itype], sd->lb_nobusyg[itype]); } seq_printf(seq, " %u %u %u %u %u %u %u %u %u %u %u %u\n", sd->alb_count, sd->alb_failed, sd->alb_pushed, sd->sbe_count, sd->sbe_balanced, sd->sbe_pushed, sd->sbf_count, sd->sbf_balanced, sd->sbf_pushed, sd->ttwu_wake_remote, sd->ttwu_move_affine, sd->ttwu_move_balance); } rcu_read_unlock(); #endif } return 0; } /* * This itererator needs some explanation. * It returns 1 for the header position. * This means 2 is cpu 0. * In a hotplugged system some CPUs, including cpu 0, may be missing so we have * to use cpumask_* to iterate over the CPUs. */ static void *schedstat_start(struct seq_file *file, loff_t *offset) { unsigned long n = *offset; if (n == 0) return (void *) 1; n--; if (n > 0) n = cpumask_next(n - 1, cpu_online_mask); else n = cpumask_first(cpu_online_mask); *offset = n + 1; if (n < nr_cpu_ids) return (void *)(unsigned long)(n + 2); return NULL; } static void *schedstat_next(struct seq_file *file, void *data, loff_t *offset) { (*offset)++; return schedstat_start(file, offset); } static void schedstat_stop(struct seq_file *file, void *data) { } static const struct seq_operations schedstat_sops = { .start = schedstat_start, .next = schedstat_next, .stop = schedstat_stop, .show = show_schedstat, }; static int __init proc_schedstat_init(void) { proc_create_seq("schedstat", 0, NULL, &schedstat_sops); return 0; } subsys_initcall(proc_schedstat_init);
2. 打印格式
# cat /proc/schedstat version 15 timestamp 4299704439 cpu0 45138 0 542397 168341 2109253 149554 211881422606 111767530843 330385 domain0 0f 227641 224888 1633 422336 1219 17 3 224887 2153 1760 268 388564 233 4 0 1760 73662 62207 2826 16446 8629 0 3 62204 19 0 19 0 0 0 0 0 0 152749 6486 0 domain1 ff 173232 172862 297 152593 116 3 17 143952 1005 1000 0 25484 7 0 1 261 64513 62039 1620 692752 854 6 192 61847 1 0 1 0 0 0 0 0 0 1806952 8003 0 cpu1 45841 0 624737 207959 238253 89621 324903926519 116922840103 373278 domain0 0f 173648 170909 1025 413908 1784 22 1 170941 9388 8952 273 464751 273 6 1 8951 81913 70676 2878 41542 8359 4 3 70673 21 0 21 0 0 0 0 0 0 72591 5884 0 domain1 ff 133941 133783 104 38284 59 1 9 4621 3319 3319 0 0 0 0 0 0 73117 70478 1762 858868 877 0 178 70300 0 0 0 0 0 0 0 0 0 76041 7324 0 cpu2 51178 0 321468 71432 126760 48041 161480944503 94681870241 202908 domain0 0f 189232 184881 2163 490574 2324 33 2 184881 1263 820 289 403211 246 5 0 820 42119 32517 2393 15705 7209 2 2 32515 33 1 32 0 0 0 0 0 0 40358 6456 0 domain1 ff 143982 143908 43 24175 49 0 5 1340 532 532 0 0 0 0 0 0 34564 32329 1406 638964 829 0 180 32149 0 0 0 0 0 0 0 0 0 38361 7785 0 cpu3 35501 0 565446 192840 273957 83773 337833473407 121948859432 340993 domain0 0f 177897 175874 1149 167989 974 20 0 175873 8620 8170 289 327360 288 5 0 8170 71849 61682 2271 13143 7896 2 5 61677 22 0 22 0 0 0 0 0 0 79642 5715 0 domain1 ff 136929 136891 22 6872 35 1 3 482 5531 5531 0 0 0 0 0 0 63573 61254 1590 774906 729 0 119 61135 0 0 0 0 0 0 0 0 0 110542 5091 0 cpu4 27314 0 4131892 1759198 1846940 1410620 492045817989 272120457957 2331643 domain0 70 318277 307849 2580 42250 8712 1 3 307850 6953 6823 25 256628 224 0 1 6822 175848 106984 15687 116797 53177 3 3 106970 0 0 0 0 0 0 0 0 0 336853 7759 0 domain1 ff 82908 80926 1806 2383686 446 255 8 67670 409 335 54 748960 32 0 0 92 121846 100176 20364 14634247 1306 24 339 99837 274 23 251 0 0 0 0 0 0 99467 5856 0 cpu5 28142 0 15038899 7208189 6659568 6139758 1042148156910 266948961272 7783970 domain0 70 559016 550747 2238 42294 6887 2 1 550747 6026 5876 18 265564 308 0 2 5874 192275 122809 17145 119657 52321 3 1 122796 0 0 0 0 0 0 0 0 0 383241 7752 0 domain1 ff 272867 272091 695 792819 299 206 9 15905 430 430 0 0 0 0 0 0 138634 113585 23877 25276253 1172 10 282 113303 231 29 202 0 0 0 0 0 0 136569 6039 0 cpu6 21540 0 5412884 2397119 2410659 1938283 595211270931 269219056980 2977818 domain0 70 385866 377440 2536 68482 6719 0 2 377449 8519 8384 23 285279 262 0 0 8384 180564 110492 18169 116184 51903 2 4 110484 0 0 0 0 0 0 0 0 0 368876 7967 0 domain1 ff 248297 247825 430 619453 295 220 5 6035 696 696 0 0 0 0 0 0 127391 103044 23221 24362600 1126 14 335 102709 247 25 222 0 0 0 0 0 0 103500 6013 0 cpu7 21675 0 379280 116596 213543 101590 116532614349 54500059021 242622 domain0 ff 55862 54336 1446 749920 334 210 17 54319 220 116 71 487137 82 1 1 115 25738 14742 9617 4602503 1379 20 392 14350 232 19 213 0 0 0 0 0 0 111953 324 0
3. 总结:打印每个cpu rq 上的部分信息和 load balance 统计信息。
标签:itype,rq,seq,18,schedstat,proc,cpu,sd 来源: https://www.cnblogs.com/hellokitty2/p/15662868.html