debug.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982
  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 P_SCHEDSTAT(F) \
  309. SEQ_printf(m, " .%-30s: %lld\n", #F, (long long)schedstat_val(F))
  310. #define PN(F) \
  311. SEQ_printf(m, " .%-30s: %lld.%06ld\n", #F, SPLIT_NS((long long)F))
  312. #define PN_SCHEDSTAT(F) \
  313. SEQ_printf(m, " .%-30s: %lld.%06ld\n", #F, SPLIT_NS((long long)schedstat_val(F)))
  314. if (!se)
  315. return;
  316. PN(se->exec_start);
  317. PN(se->vruntime);
  318. PN(se->sum_exec_runtime);
  319. if (schedstat_enabled()) {
  320. PN_SCHEDSTAT(se->statistics.wait_start);
  321. PN_SCHEDSTAT(se->statistics.sleep_start);
  322. PN_SCHEDSTAT(se->statistics.block_start);
  323. PN_SCHEDSTAT(se->statistics.sleep_max);
  324. PN_SCHEDSTAT(se->statistics.block_max);
  325. PN_SCHEDSTAT(se->statistics.exec_max);
  326. PN_SCHEDSTAT(se->statistics.slice_max);
  327. PN_SCHEDSTAT(se->statistics.wait_max);
  328. PN_SCHEDSTAT(se->statistics.wait_sum);
  329. P_SCHEDSTAT(se->statistics.wait_count);
  330. }
  331. P(se->load.weight);
  332. #ifdef CONFIG_SMP
  333. P(se->avg.load_avg);
  334. P(se->avg.util_avg);
  335. #endif
  336. #undef PN_SCHEDSTAT
  337. #undef PN
  338. #undef P_SCHEDSTAT
  339. #undef P
  340. }
  341. #endif
  342. #ifdef CONFIG_CGROUP_SCHED
  343. static char group_path[PATH_MAX];
  344. static char *task_group_path(struct task_group *tg)
  345. {
  346. if (autogroup_path(tg, group_path, PATH_MAX))
  347. return group_path;
  348. cgroup_path(tg->css.cgroup, group_path, PATH_MAX);
  349. return group_path;
  350. }
  351. #endif
  352. static void
  353. print_task(struct seq_file *m, struct rq *rq, struct task_struct *p)
  354. {
  355. if (rq->curr == p)
  356. SEQ_printf(m, "R");
  357. else
  358. SEQ_printf(m, " ");
  359. SEQ_printf(m, "%15s %5d %9Ld.%06ld %9Ld %5d ",
  360. p->comm, task_pid_nr(p),
  361. SPLIT_NS(p->se.vruntime),
  362. (long long)(p->nvcsw + p->nivcsw),
  363. p->prio);
  364. SEQ_printf(m, "%9Ld.%06ld %9Ld.%06ld %9Ld.%06ld",
  365. SPLIT_NS(schedstat_val_or_zero(p->se.statistics.wait_sum)),
  366. SPLIT_NS(p->se.sum_exec_runtime),
  367. SPLIT_NS(schedstat_val_or_zero(p->se.statistics.sum_sleep_runtime)));
  368. #ifdef CONFIG_NUMA_BALANCING
  369. SEQ_printf(m, " %d %d", task_node(p), task_numa_group_id(p));
  370. #endif
  371. #ifdef CONFIG_CGROUP_SCHED
  372. SEQ_printf(m, " %s", task_group_path(task_group(p)));
  373. #endif
  374. SEQ_printf(m, "\n");
  375. }
  376. static void print_rq(struct seq_file *m, struct rq *rq, int rq_cpu)
  377. {
  378. struct task_struct *g, *p;
  379. SEQ_printf(m,
  380. "\nrunnable tasks:\n"
  381. " task PID tree-key switches prio"
  382. " wait-time sum-exec sum-sleep\n"
  383. "------------------------------------------------------"
  384. "----------------------------------------------------\n");
  385. rcu_read_lock();
  386. for_each_process_thread(g, p) {
  387. if (task_cpu(p) != rq_cpu)
  388. continue;
  389. print_task(m, rq, p);
  390. }
  391. rcu_read_unlock();
  392. }
  393. void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)
  394. {
  395. s64 MIN_vruntime = -1, min_vruntime, max_vruntime = -1,
  396. spread, rq0_min_vruntime, spread0;
  397. struct rq *rq = cpu_rq(cpu);
  398. struct sched_entity *last;
  399. unsigned long flags;
  400. #ifdef CONFIG_FAIR_GROUP_SCHED
  401. SEQ_printf(m, "\ncfs_rq[%d]:%s\n", cpu, task_group_path(cfs_rq->tg));
  402. #else
  403. SEQ_printf(m, "\ncfs_rq[%d]:\n", cpu);
  404. #endif
  405. SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "exec_clock",
  406. SPLIT_NS(cfs_rq->exec_clock));
  407. raw_spin_lock_irqsave(&rq->lock, flags);
  408. if (cfs_rq->rb_leftmost)
  409. MIN_vruntime = (__pick_first_entity(cfs_rq))->vruntime;
  410. last = __pick_last_entity(cfs_rq);
  411. if (last)
  412. max_vruntime = last->vruntime;
  413. min_vruntime = cfs_rq->min_vruntime;
  414. rq0_min_vruntime = cpu_rq(0)->cfs.min_vruntime;
  415. raw_spin_unlock_irqrestore(&rq->lock, flags);
  416. SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "MIN_vruntime",
  417. SPLIT_NS(MIN_vruntime));
  418. SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "min_vruntime",
  419. SPLIT_NS(min_vruntime));
  420. SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "max_vruntime",
  421. SPLIT_NS(max_vruntime));
  422. spread = max_vruntime - MIN_vruntime;
  423. SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "spread",
  424. SPLIT_NS(spread));
  425. spread0 = min_vruntime - rq0_min_vruntime;
  426. SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "spread0",
  427. SPLIT_NS(spread0));
  428. SEQ_printf(m, " .%-30s: %d\n", "nr_spread_over",
  429. cfs_rq->nr_spread_over);
  430. SEQ_printf(m, " .%-30s: %d\n", "nr_running", cfs_rq->nr_running);
  431. SEQ_printf(m, " .%-30s: %ld\n", "load", cfs_rq->load.weight);
  432. #ifdef CONFIG_SMP
  433. SEQ_printf(m, " .%-30s: %lu\n", "load_avg",
  434. cfs_rq->avg.load_avg);
  435. SEQ_printf(m, " .%-30s: %lu\n", "runnable_load_avg",
  436. cfs_rq->runnable_load_avg);
  437. SEQ_printf(m, " .%-30s: %lu\n", "util_avg",
  438. cfs_rq->avg.util_avg);
  439. SEQ_printf(m, " .%-30s: %ld\n", "removed_load_avg",
  440. atomic_long_read(&cfs_rq->removed_load_avg));
  441. SEQ_printf(m, " .%-30s: %ld\n", "removed_util_avg",
  442. atomic_long_read(&cfs_rq->removed_util_avg));
  443. #ifdef CONFIG_FAIR_GROUP_SCHED
  444. SEQ_printf(m, " .%-30s: %lu\n", "tg_load_avg_contrib",
  445. cfs_rq->tg_load_avg_contrib);
  446. SEQ_printf(m, " .%-30s: %ld\n", "tg_load_avg",
  447. atomic_long_read(&cfs_rq->tg->load_avg));
  448. #endif
  449. #endif
  450. #ifdef CONFIG_CFS_BANDWIDTH
  451. SEQ_printf(m, " .%-30s: %d\n", "throttled",
  452. cfs_rq->throttled);
  453. SEQ_printf(m, " .%-30s: %d\n", "throttle_count",
  454. cfs_rq->throttle_count);
  455. #endif
  456. #ifdef CONFIG_FAIR_GROUP_SCHED
  457. print_cfs_group_stats(m, cpu, cfs_rq->tg);
  458. #endif
  459. }
  460. void print_rt_rq(struct seq_file *m, int cpu, struct rt_rq *rt_rq)
  461. {
  462. #ifdef CONFIG_RT_GROUP_SCHED
  463. SEQ_printf(m, "\nrt_rq[%d]:%s\n", cpu, task_group_path(rt_rq->tg));
  464. #else
  465. SEQ_printf(m, "\nrt_rq[%d]:\n", cpu);
  466. #endif
  467. #define P(x) \
  468. SEQ_printf(m, " .%-30s: %Ld\n", #x, (long long)(rt_rq->x))
  469. #define PN(x) \
  470. SEQ_printf(m, " .%-30s: %Ld.%06ld\n", #x, SPLIT_NS(rt_rq->x))
  471. P(rt_nr_running);
  472. P(rt_throttled);
  473. PN(rt_time);
  474. PN(rt_runtime);
  475. #undef PN
  476. #undef P
  477. }
  478. void print_dl_rq(struct seq_file *m, int cpu, struct dl_rq *dl_rq)
  479. {
  480. struct dl_bw *dl_bw;
  481. SEQ_printf(m, "\ndl_rq[%d]:\n", cpu);
  482. SEQ_printf(m, " .%-30s: %ld\n", "dl_nr_running", dl_rq->dl_nr_running);
  483. #ifdef CONFIG_SMP
  484. dl_bw = &cpu_rq(cpu)->rd->dl_bw;
  485. #else
  486. dl_bw = &dl_rq->dl_bw;
  487. #endif
  488. SEQ_printf(m, " .%-30s: %lld\n", "dl_bw->bw", dl_bw->bw);
  489. SEQ_printf(m, " .%-30s: %lld\n", "dl_bw->total_bw", dl_bw->total_bw);
  490. }
  491. extern __read_mostly int sched_clock_running;
  492. static void print_cpu(struct seq_file *m, int cpu)
  493. {
  494. struct rq *rq = cpu_rq(cpu);
  495. unsigned long flags;
  496. #ifdef CONFIG_X86
  497. {
  498. unsigned int freq = cpu_khz ? : 1;
  499. SEQ_printf(m, "cpu#%d, %u.%03u MHz\n",
  500. cpu, freq / 1000, (freq % 1000));
  501. }
  502. #else
  503. SEQ_printf(m, "cpu#%d\n", cpu);
  504. #endif
  505. #define P(x) \
  506. do { \
  507. if (sizeof(rq->x) == 4) \
  508. SEQ_printf(m, " .%-30s: %ld\n", #x, (long)(rq->x)); \
  509. else \
  510. SEQ_printf(m, " .%-30s: %Ld\n", #x, (long long)(rq->x));\
  511. } while (0)
  512. #define PN(x) \
  513. SEQ_printf(m, " .%-30s: %Ld.%06ld\n", #x, SPLIT_NS(rq->x))
  514. P(nr_running);
  515. SEQ_printf(m, " .%-30s: %lu\n", "load",
  516. rq->load.weight);
  517. P(nr_switches);
  518. P(nr_load_updates);
  519. P(nr_uninterruptible);
  520. PN(next_balance);
  521. SEQ_printf(m, " .%-30s: %ld\n", "curr->pid", (long)(task_pid_nr(rq->curr)));
  522. PN(clock);
  523. PN(clock_task);
  524. P(cpu_load[0]);
  525. P(cpu_load[1]);
  526. P(cpu_load[2]);
  527. P(cpu_load[3]);
  528. P(cpu_load[4]);
  529. #undef P
  530. #undef PN
  531. #ifdef CONFIG_SMP
  532. #define P64(n) SEQ_printf(m, " .%-30s: %Ld\n", #n, rq->n);
  533. P64(avg_idle);
  534. P64(max_idle_balance_cost);
  535. #undef P64
  536. #endif
  537. #define P(n) SEQ_printf(m, " .%-30s: %d\n", #n, schedstat_val(rq->n));
  538. if (schedstat_enabled()) {
  539. P(yld_count);
  540. P(sched_count);
  541. P(sched_goidle);
  542. P(ttwu_count);
  543. P(ttwu_local);
  544. }
  545. #undef P
  546. spin_lock_irqsave(&sched_debug_lock, flags);
  547. print_cfs_stats(m, cpu);
  548. print_rt_stats(m, cpu);
  549. print_dl_stats(m, cpu);
  550. print_rq(m, rq, cpu);
  551. spin_unlock_irqrestore(&sched_debug_lock, flags);
  552. SEQ_printf(m, "\n");
  553. }
  554. static const char *sched_tunable_scaling_names[] = {
  555. "none",
  556. "logaritmic",
  557. "linear"
  558. };
  559. static void sched_debug_header(struct seq_file *m)
  560. {
  561. u64 ktime, sched_clk, cpu_clk;
  562. unsigned long flags;
  563. local_irq_save(flags);
  564. ktime = ktime_to_ns(ktime_get());
  565. sched_clk = sched_clock();
  566. cpu_clk = local_clock();
  567. local_irq_restore(flags);
  568. SEQ_printf(m, "Sched Debug Version: v0.11, %s %.*s\n",
  569. init_utsname()->release,
  570. (int)strcspn(init_utsname()->version, " "),
  571. init_utsname()->version);
  572. #define P(x) \
  573. SEQ_printf(m, "%-40s: %Ld\n", #x, (long long)(x))
  574. #define PN(x) \
  575. SEQ_printf(m, "%-40s: %Ld.%06ld\n", #x, SPLIT_NS(x))
  576. PN(ktime);
  577. PN(sched_clk);
  578. PN(cpu_clk);
  579. P(jiffies);
  580. #ifdef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
  581. P(sched_clock_stable());
  582. #endif
  583. #undef PN
  584. #undef P
  585. SEQ_printf(m, "\n");
  586. SEQ_printf(m, "sysctl_sched\n");
  587. #define P(x) \
  588. SEQ_printf(m, " .%-40s: %Ld\n", #x, (long long)(x))
  589. #define PN(x) \
  590. SEQ_printf(m, " .%-40s: %Ld.%06ld\n", #x, SPLIT_NS(x))
  591. PN(sysctl_sched_latency);
  592. PN(sysctl_sched_min_granularity);
  593. PN(sysctl_sched_wakeup_granularity);
  594. P(sysctl_sched_child_runs_first);
  595. P(sysctl_sched_features);
  596. #undef PN
  597. #undef P
  598. SEQ_printf(m, " .%-40s: %d (%s)\n",
  599. "sysctl_sched_tunable_scaling",
  600. sysctl_sched_tunable_scaling,
  601. sched_tunable_scaling_names[sysctl_sched_tunable_scaling]);
  602. SEQ_printf(m, "\n");
  603. }
  604. static int sched_debug_show(struct seq_file *m, void *v)
  605. {
  606. int cpu = (unsigned long)(v - 2);
  607. if (cpu != -1)
  608. print_cpu(m, cpu);
  609. else
  610. sched_debug_header(m);
  611. return 0;
  612. }
  613. void sysrq_sched_debug_show(void)
  614. {
  615. int cpu;
  616. sched_debug_header(NULL);
  617. for_each_online_cpu(cpu)
  618. print_cpu(NULL, cpu);
  619. }
  620. /*
  621. * This itererator needs some explanation.
  622. * It returns 1 for the header position.
  623. * This means 2 is cpu 0.
  624. * In a hotplugged system some cpus, including cpu 0, may be missing so we have
  625. * to use cpumask_* to iterate over the cpus.
  626. */
  627. static void *sched_debug_start(struct seq_file *file, loff_t *offset)
  628. {
  629. unsigned long n = *offset;
  630. if (n == 0)
  631. return (void *) 1;
  632. n--;
  633. if (n > 0)
  634. n = cpumask_next(n - 1, cpu_online_mask);
  635. else
  636. n = cpumask_first(cpu_online_mask);
  637. *offset = n + 1;
  638. if (n < nr_cpu_ids)
  639. return (void *)(unsigned long)(n + 2);
  640. return NULL;
  641. }
  642. static void *sched_debug_next(struct seq_file *file, void *data, loff_t *offset)
  643. {
  644. (*offset)++;
  645. return sched_debug_start(file, offset);
  646. }
  647. static void sched_debug_stop(struct seq_file *file, void *data)
  648. {
  649. }
  650. static const struct seq_operations sched_debug_sops = {
  651. .start = sched_debug_start,
  652. .next = sched_debug_next,
  653. .stop = sched_debug_stop,
  654. .show = sched_debug_show,
  655. };
  656. static int sched_debug_release(struct inode *inode, struct file *file)
  657. {
  658. seq_release(inode, file);
  659. return 0;
  660. }
  661. static int sched_debug_open(struct inode *inode, struct file *filp)
  662. {
  663. int ret = 0;
  664. ret = seq_open(filp, &sched_debug_sops);
  665. return ret;
  666. }
  667. static const struct file_operations sched_debug_fops = {
  668. .open = sched_debug_open,
  669. .read = seq_read,
  670. .llseek = seq_lseek,
  671. .release = sched_debug_release,
  672. };
  673. static int __init init_sched_debug_procfs(void)
  674. {
  675. struct proc_dir_entry *pe;
  676. pe = proc_create("sched_debug", 0444, NULL, &sched_debug_fops);
  677. if (!pe)
  678. return -ENOMEM;
  679. return 0;
  680. }
  681. __initcall(init_sched_debug_procfs);
  682. #define __P(F) \
  683. SEQ_printf(m, "%-45s:%21Ld\n", #F, (long long)F)
  684. #define P(F) \
  685. SEQ_printf(m, "%-45s:%21Ld\n", #F, (long long)p->F)
  686. #define __PN(F) \
  687. SEQ_printf(m, "%-45s:%14Ld.%06ld\n", #F, SPLIT_NS((long long)F))
  688. #define PN(F) \
  689. SEQ_printf(m, "%-45s:%14Ld.%06ld\n", #F, SPLIT_NS((long long)p->F))
  690. #ifdef CONFIG_NUMA_BALANCING
  691. void print_numa_stats(struct seq_file *m, int node, unsigned long tsf,
  692. unsigned long tpf, unsigned long gsf, unsigned long gpf)
  693. {
  694. SEQ_printf(m, "numa_faults node=%d ", node);
  695. SEQ_printf(m, "task_private=%lu task_shared=%lu ", tsf, tpf);
  696. SEQ_printf(m, "group_private=%lu group_shared=%lu\n", gsf, gpf);
  697. }
  698. #endif
  699. static void sched_show_numa(struct task_struct *p, struct seq_file *m)
  700. {
  701. #ifdef CONFIG_NUMA_BALANCING
  702. struct mempolicy *pol;
  703. if (p->mm)
  704. P(mm->numa_scan_seq);
  705. task_lock(p);
  706. pol = p->mempolicy;
  707. if (pol && !(pol->flags & MPOL_F_MORON))
  708. pol = NULL;
  709. mpol_get(pol);
  710. task_unlock(p);
  711. P(numa_pages_migrated);
  712. P(numa_preferred_nid);
  713. P(total_numa_faults);
  714. SEQ_printf(m, "current_node=%d, numa_group_id=%d\n",
  715. task_node(p), task_numa_group_id(p));
  716. show_numa_stats(p, m);
  717. mpol_put(pol);
  718. #endif
  719. }
  720. void proc_sched_show_task(struct task_struct *p, struct seq_file *m)
  721. {
  722. unsigned long nr_switches;
  723. SEQ_printf(m, "%s (%d, #threads: %d)\n", p->comm, task_pid_nr(p),
  724. get_nr_threads(p));
  725. SEQ_printf(m,
  726. "---------------------------------------------------------"
  727. "----------\n");
  728. #define __P(F) \
  729. SEQ_printf(m, "%-45s:%21Ld\n", #F, (long long)F)
  730. #define P(F) \
  731. SEQ_printf(m, "%-45s:%21Ld\n", #F, (long long)p->F)
  732. #define P_SCHEDSTAT(F) \
  733. SEQ_printf(m, "%-45s:%21Ld\n", #F, (long long)schedstat_val(p->F))
  734. #define __PN(F) \
  735. SEQ_printf(m, "%-45s:%14Ld.%06ld\n", #F, SPLIT_NS((long long)F))
  736. #define PN(F) \
  737. SEQ_printf(m, "%-45s:%14Ld.%06ld\n", #F, SPLIT_NS((long long)p->F))
  738. #define PN_SCHEDSTAT(F) \
  739. SEQ_printf(m, "%-45s:%14Ld.%06ld\n", #F, SPLIT_NS((long long)schedstat_val(p->F)))
  740. PN(se.exec_start);
  741. PN(se.vruntime);
  742. PN(se.sum_exec_runtime);
  743. nr_switches = p->nvcsw + p->nivcsw;
  744. P(se.nr_migrations);
  745. if (schedstat_enabled()) {
  746. u64 avg_atom, avg_per_cpu;
  747. PN_SCHEDSTAT(se.statistics.sum_sleep_runtime);
  748. PN_SCHEDSTAT(se.statistics.wait_start);
  749. PN_SCHEDSTAT(se.statistics.sleep_start);
  750. PN_SCHEDSTAT(se.statistics.block_start);
  751. PN_SCHEDSTAT(se.statistics.sleep_max);
  752. PN_SCHEDSTAT(se.statistics.block_max);
  753. PN_SCHEDSTAT(se.statistics.exec_max);
  754. PN_SCHEDSTAT(se.statistics.slice_max);
  755. PN_SCHEDSTAT(se.statistics.wait_max);
  756. PN_SCHEDSTAT(se.statistics.wait_sum);
  757. P_SCHEDSTAT(se.statistics.wait_count);
  758. PN_SCHEDSTAT(se.statistics.iowait_sum);
  759. P_SCHEDSTAT(se.statistics.iowait_count);
  760. P_SCHEDSTAT(se.statistics.nr_migrations_cold);
  761. P_SCHEDSTAT(se.statistics.nr_failed_migrations_affine);
  762. P_SCHEDSTAT(se.statistics.nr_failed_migrations_running);
  763. P_SCHEDSTAT(se.statistics.nr_failed_migrations_hot);
  764. P_SCHEDSTAT(se.statistics.nr_forced_migrations);
  765. P_SCHEDSTAT(se.statistics.nr_wakeups);
  766. P_SCHEDSTAT(se.statistics.nr_wakeups_sync);
  767. P_SCHEDSTAT(se.statistics.nr_wakeups_migrate);
  768. P_SCHEDSTAT(se.statistics.nr_wakeups_local);
  769. P_SCHEDSTAT(se.statistics.nr_wakeups_remote);
  770. P_SCHEDSTAT(se.statistics.nr_wakeups_affine);
  771. P_SCHEDSTAT(se.statistics.nr_wakeups_affine_attempts);
  772. P_SCHEDSTAT(se.statistics.nr_wakeups_passive);
  773. P_SCHEDSTAT(se.statistics.nr_wakeups_idle);
  774. avg_atom = p->se.sum_exec_runtime;
  775. if (nr_switches)
  776. avg_atom = div64_ul(avg_atom, nr_switches);
  777. else
  778. avg_atom = -1LL;
  779. avg_per_cpu = p->se.sum_exec_runtime;
  780. if (p->se.nr_migrations) {
  781. avg_per_cpu = div64_u64(avg_per_cpu,
  782. p->se.nr_migrations);
  783. } else {
  784. avg_per_cpu = -1LL;
  785. }
  786. __PN(avg_atom);
  787. __PN(avg_per_cpu);
  788. }
  789. __P(nr_switches);
  790. SEQ_printf(m, "%-45s:%21Ld\n",
  791. "nr_voluntary_switches", (long long)p->nvcsw);
  792. SEQ_printf(m, "%-45s:%21Ld\n",
  793. "nr_involuntary_switches", (long long)p->nivcsw);
  794. P(se.load.weight);
  795. #ifdef CONFIG_SMP
  796. P(se.avg.load_sum);
  797. P(se.avg.util_sum);
  798. P(se.avg.load_avg);
  799. P(se.avg.util_avg);
  800. P(se.avg.last_update_time);
  801. #endif
  802. P(policy);
  803. P(prio);
  804. #undef PN_SCHEDSTAT
  805. #undef PN
  806. #undef __PN
  807. #undef P_SCHEDSTAT
  808. #undef P
  809. #undef __P
  810. {
  811. unsigned int this_cpu = raw_smp_processor_id();
  812. u64 t0, t1;
  813. t0 = cpu_clock(this_cpu);
  814. t1 = cpu_clock(this_cpu);
  815. SEQ_printf(m, "%-45s:%21Ld\n",
  816. "clock-delta", (long long)(t1-t0));
  817. }
  818. sched_show_numa(p, m);
  819. }
  820. void proc_sched_set_task(struct task_struct *p)
  821. {
  822. #ifdef CONFIG_SCHEDSTATS
  823. memset(&p->se.statistics, 0, sizeof(p->se.statistics));
  824. #endif
  825. }