debug.c 22 KB

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