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