debug.c 23 KB

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