debug.c 24 KB

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