debug.c 24 KB

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