debug.c 23 KB

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