debug.c 24 KB

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