debug.c 23 KB

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