debug.c 27 KB

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