debug.c 25 KB

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