debug.c 24 KB

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