debug.c 25 KB

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