debug.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798
  1. /*
  2. * kernel/sched/debug.c
  3. *
  4. * Print the CFS rbtree
  5. *
  6. * Copyright(C) 2007, Red Hat, Inc., Ingo Molnar
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/proc_fs.h>
  13. #include <linux/sched.h>
  14. #include <linux/seq_file.h>
  15. #include <linux/kallsyms.h>
  16. #include <linux/utsname.h>
  17. #include <linux/mempolicy.h>
  18. #include <linux/debugfs.h>
  19. #include "sched.h"
  20. static DEFINE_SPINLOCK(sched_debug_lock);
  21. /*
  22. * This allows printing both to /proc/sched_debug and
  23. * to the console
  24. */
  25. #define SEQ_printf(m, x...) \
  26. do { \
  27. if (m) \
  28. seq_printf(m, x); \
  29. else \
  30. printk(x); \
  31. } while (0)
  32. /*
  33. * Ease the printing of nsec fields:
  34. */
  35. static long long nsec_high(unsigned long long nsec)
  36. {
  37. if ((long long)nsec < 0) {
  38. nsec = -nsec;
  39. do_div(nsec, 1000000);
  40. return -nsec;
  41. }
  42. do_div(nsec, 1000000);
  43. return nsec;
  44. }
  45. static unsigned long nsec_low(unsigned long long nsec)
  46. {
  47. if ((long long)nsec < 0)
  48. nsec = -nsec;
  49. return do_div(nsec, 1000000);
  50. }
  51. #define SPLIT_NS(x) nsec_high(x), nsec_low(x)
  52. #define SCHED_FEAT(name, enabled) \
  53. #name ,
  54. static const char * const sched_feat_names[] = {
  55. #include "features.h"
  56. };
  57. #undef SCHED_FEAT
  58. static int sched_feat_show(struct seq_file *m, void *v)
  59. {
  60. int i;
  61. for (i = 0; i < __SCHED_FEAT_NR; i++) {
  62. if (!(sysctl_sched_features & (1UL << i)))
  63. seq_puts(m, "NO_");
  64. seq_printf(m, "%s ", sched_feat_names[i]);
  65. }
  66. seq_puts(m, "\n");
  67. return 0;
  68. }
  69. #ifdef HAVE_JUMP_LABEL
  70. #define jump_label_key__true STATIC_KEY_INIT_TRUE
  71. #define jump_label_key__false STATIC_KEY_INIT_FALSE
  72. #define SCHED_FEAT(name, enabled) \
  73. jump_label_key__##enabled ,
  74. struct static_key sched_feat_keys[__SCHED_FEAT_NR] = {
  75. #include "features.h"
  76. };
  77. #undef SCHED_FEAT
  78. static void sched_feat_disable(int i)
  79. {
  80. static_key_disable(&sched_feat_keys[i]);
  81. }
  82. static void sched_feat_enable(int i)
  83. {
  84. static_key_enable(&sched_feat_keys[i]);
  85. }
  86. #else
  87. static void sched_feat_disable(int i) { };
  88. static void sched_feat_enable(int i) { };
  89. #endif /* HAVE_JUMP_LABEL */
  90. static int sched_feat_set(char *cmp)
  91. {
  92. int i;
  93. int neg = 0;
  94. if (strncmp(cmp, "NO_", 3) == 0) {
  95. neg = 1;
  96. cmp += 3;
  97. }
  98. for (i = 0; i < __SCHED_FEAT_NR; i++) {
  99. if (strcmp(cmp, sched_feat_names[i]) == 0) {
  100. if (neg) {
  101. sysctl_sched_features &= ~(1UL << i);
  102. sched_feat_disable(i);
  103. } else {
  104. sysctl_sched_features |= (1UL << i);
  105. sched_feat_enable(i);
  106. }
  107. break;
  108. }
  109. }
  110. return i;
  111. }
  112. static ssize_t
  113. sched_feat_write(struct file *filp, const char __user *ubuf,
  114. size_t cnt, loff_t *ppos)
  115. {
  116. char buf[64];
  117. char *cmp;
  118. int i;
  119. struct inode *inode;
  120. if (cnt > 63)
  121. cnt = 63;
  122. if (copy_from_user(&buf, ubuf, cnt))
  123. return -EFAULT;
  124. buf[cnt] = 0;
  125. cmp = strstrip(buf);
  126. /* Ensure the static_key remains in a consistent state */
  127. inode = file_inode(filp);
  128. inode_lock(inode);
  129. i = sched_feat_set(cmp);
  130. inode_unlock(inode);
  131. if (i == __SCHED_FEAT_NR)
  132. return -EINVAL;
  133. *ppos += cnt;
  134. return cnt;
  135. }
  136. static int sched_feat_open(struct inode *inode, struct file *filp)
  137. {
  138. return single_open(filp, sched_feat_show, NULL);
  139. }
  140. static const struct file_operations sched_feat_fops = {
  141. .open = sched_feat_open,
  142. .write = sched_feat_write,
  143. .read = seq_read,
  144. .llseek = seq_lseek,
  145. .release = single_release,
  146. };
  147. static __init int sched_init_debug(void)
  148. {
  149. debugfs_create_file("sched_features", 0644, NULL, NULL,
  150. &sched_feat_fops);
  151. return 0;
  152. }
  153. late_initcall(sched_init_debug);
  154. #ifdef CONFIG_FAIR_GROUP_SCHED
  155. static void print_cfs_group_stats(struct seq_file *m, int cpu, struct task_group *tg)
  156. {
  157. struct sched_entity *se = tg->se[cpu];
  158. #define P(F) \
  159. SEQ_printf(m, " .%-30s: %lld\n", #F, (long long)F)
  160. #define PN(F) \
  161. SEQ_printf(m, " .%-30s: %lld.%06ld\n", #F, SPLIT_NS((long long)F))
  162. if (!se)
  163. return;
  164. PN(se->exec_start);
  165. PN(se->vruntime);
  166. PN(se->sum_exec_runtime);
  167. #ifdef CONFIG_SCHEDSTATS
  168. if (schedstat_enabled()) {
  169. PN(se->statistics.wait_start);
  170. PN(se->statistics.sleep_start);
  171. PN(se->statistics.block_start);
  172. PN(se->statistics.sleep_max);
  173. PN(se->statistics.block_max);
  174. PN(se->statistics.exec_max);
  175. PN(se->statistics.slice_max);
  176. PN(se->statistics.wait_max);
  177. PN(se->statistics.wait_sum);
  178. P(se->statistics.wait_count);
  179. }
  180. #endif
  181. P(se->load.weight);
  182. #ifdef CONFIG_SMP
  183. P(se->avg.load_avg);
  184. P(se->avg.util_avg);
  185. #endif
  186. #undef PN
  187. #undef P
  188. }
  189. #endif
  190. #ifdef CONFIG_CGROUP_SCHED
  191. static char group_path[PATH_MAX];
  192. static char *task_group_path(struct task_group *tg)
  193. {
  194. if (autogroup_path(tg, group_path, PATH_MAX))
  195. return group_path;
  196. return cgroup_path(tg->css.cgroup, group_path, PATH_MAX);
  197. }
  198. #endif
  199. static void
  200. print_task(struct seq_file *m, struct rq *rq, struct task_struct *p)
  201. {
  202. if (rq->curr == p)
  203. SEQ_printf(m, "R");
  204. else
  205. SEQ_printf(m, " ");
  206. SEQ_printf(m, "%15s %5d %9Ld.%06ld %9Ld %5d ",
  207. p->comm, task_pid_nr(p),
  208. SPLIT_NS(p->se.vruntime),
  209. (long long)(p->nvcsw + p->nivcsw),
  210. p->prio);
  211. #ifdef CONFIG_SCHEDSTATS
  212. if (schedstat_enabled()) {
  213. SEQ_printf(m, "%9Ld.%06ld %9Ld.%06ld %9Ld.%06ld",
  214. SPLIT_NS(p->se.statistics.wait_sum),
  215. SPLIT_NS(p->se.sum_exec_runtime),
  216. SPLIT_NS(p->se.statistics.sum_sleep_runtime));
  217. }
  218. #else
  219. SEQ_printf(m, "%9Ld.%06ld %9Ld.%06ld %9Ld.%06ld",
  220. 0LL, 0L,
  221. SPLIT_NS(p->se.sum_exec_runtime),
  222. 0LL, 0L);
  223. #endif
  224. #ifdef CONFIG_NUMA_BALANCING
  225. SEQ_printf(m, " %d %d", task_node(p), task_numa_group_id(p));
  226. #endif
  227. #ifdef CONFIG_CGROUP_SCHED
  228. SEQ_printf(m, " %s", task_group_path(task_group(p)));
  229. #endif
  230. SEQ_printf(m, "\n");
  231. }
  232. static void print_rq(struct seq_file *m, struct rq *rq, int rq_cpu)
  233. {
  234. struct task_struct *g, *p;
  235. SEQ_printf(m,
  236. "\nrunnable tasks:\n"
  237. " task PID tree-key switches prio"
  238. " wait-time sum-exec sum-sleep\n"
  239. "------------------------------------------------------"
  240. "----------------------------------------------------\n");
  241. rcu_read_lock();
  242. for_each_process_thread(g, p) {
  243. if (task_cpu(p) != rq_cpu)
  244. continue;
  245. print_task(m, rq, p);
  246. }
  247. rcu_read_unlock();
  248. }
  249. void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)
  250. {
  251. s64 MIN_vruntime = -1, min_vruntime, max_vruntime = -1,
  252. spread, rq0_min_vruntime, spread0;
  253. struct rq *rq = cpu_rq(cpu);
  254. struct sched_entity *last;
  255. unsigned long flags;
  256. #ifdef CONFIG_FAIR_GROUP_SCHED
  257. SEQ_printf(m, "\ncfs_rq[%d]:%s\n", cpu, task_group_path(cfs_rq->tg));
  258. #else
  259. SEQ_printf(m, "\ncfs_rq[%d]:\n", cpu);
  260. #endif
  261. SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "exec_clock",
  262. SPLIT_NS(cfs_rq->exec_clock));
  263. raw_spin_lock_irqsave(&rq->lock, flags);
  264. if (cfs_rq->rb_leftmost)
  265. MIN_vruntime = (__pick_first_entity(cfs_rq))->vruntime;
  266. last = __pick_last_entity(cfs_rq);
  267. if (last)
  268. max_vruntime = last->vruntime;
  269. min_vruntime = cfs_rq->min_vruntime;
  270. rq0_min_vruntime = cpu_rq(0)->cfs.min_vruntime;
  271. raw_spin_unlock_irqrestore(&rq->lock, flags);
  272. SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "MIN_vruntime",
  273. SPLIT_NS(MIN_vruntime));
  274. SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "min_vruntime",
  275. SPLIT_NS(min_vruntime));
  276. SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "max_vruntime",
  277. SPLIT_NS(max_vruntime));
  278. spread = max_vruntime - MIN_vruntime;
  279. SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "spread",
  280. SPLIT_NS(spread));
  281. spread0 = min_vruntime - rq0_min_vruntime;
  282. SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "spread0",
  283. SPLIT_NS(spread0));
  284. SEQ_printf(m, " .%-30s: %d\n", "nr_spread_over",
  285. cfs_rq->nr_spread_over);
  286. SEQ_printf(m, " .%-30s: %d\n", "nr_running", cfs_rq->nr_running);
  287. SEQ_printf(m, " .%-30s: %ld\n", "load", cfs_rq->load.weight);
  288. #ifdef CONFIG_SMP
  289. SEQ_printf(m, " .%-30s: %lu\n", "load_avg",
  290. cfs_rq->avg.load_avg);
  291. SEQ_printf(m, " .%-30s: %lu\n", "runnable_load_avg",
  292. cfs_rq->runnable_load_avg);
  293. SEQ_printf(m, " .%-30s: %lu\n", "util_avg",
  294. cfs_rq->avg.util_avg);
  295. SEQ_printf(m, " .%-30s: %ld\n", "removed_load_avg",
  296. atomic_long_read(&cfs_rq->removed_load_avg));
  297. SEQ_printf(m, " .%-30s: %ld\n", "removed_util_avg",
  298. atomic_long_read(&cfs_rq->removed_util_avg));
  299. #ifdef CONFIG_FAIR_GROUP_SCHED
  300. SEQ_printf(m, " .%-30s: %lu\n", "tg_load_avg_contrib",
  301. cfs_rq->tg_load_avg_contrib);
  302. SEQ_printf(m, " .%-30s: %ld\n", "tg_load_avg",
  303. atomic_long_read(&cfs_rq->tg->load_avg));
  304. #endif
  305. #endif
  306. #ifdef CONFIG_CFS_BANDWIDTH
  307. SEQ_printf(m, " .%-30s: %d\n", "throttled",
  308. cfs_rq->throttled);
  309. SEQ_printf(m, " .%-30s: %d\n", "throttle_count",
  310. cfs_rq->throttle_count);
  311. #endif
  312. #ifdef CONFIG_FAIR_GROUP_SCHED
  313. print_cfs_group_stats(m, cpu, cfs_rq->tg);
  314. #endif
  315. }
  316. void print_rt_rq(struct seq_file *m, int cpu, struct rt_rq *rt_rq)
  317. {
  318. #ifdef CONFIG_RT_GROUP_SCHED
  319. SEQ_printf(m, "\nrt_rq[%d]:%s\n", cpu, task_group_path(rt_rq->tg));
  320. #else
  321. SEQ_printf(m, "\nrt_rq[%d]:\n", cpu);
  322. #endif
  323. #define P(x) \
  324. SEQ_printf(m, " .%-30s: %Ld\n", #x, (long long)(rt_rq->x))
  325. #define PN(x) \
  326. SEQ_printf(m, " .%-30s: %Ld.%06ld\n", #x, SPLIT_NS(rt_rq->x))
  327. P(rt_nr_running);
  328. P(rt_throttled);
  329. PN(rt_time);
  330. PN(rt_runtime);
  331. #undef PN
  332. #undef P
  333. }
  334. void print_dl_rq(struct seq_file *m, int cpu, struct dl_rq *dl_rq)
  335. {
  336. SEQ_printf(m, "\ndl_rq[%d]:\n", cpu);
  337. SEQ_printf(m, " .%-30s: %ld\n", "dl_nr_running", dl_rq->dl_nr_running);
  338. }
  339. extern __read_mostly int sched_clock_running;
  340. static void print_cpu(struct seq_file *m, int cpu)
  341. {
  342. struct rq *rq = cpu_rq(cpu);
  343. unsigned long flags;
  344. #ifdef CONFIG_X86
  345. {
  346. unsigned int freq = cpu_khz ? : 1;
  347. SEQ_printf(m, "cpu#%d, %u.%03u MHz\n",
  348. cpu, freq / 1000, (freq % 1000));
  349. }
  350. #else
  351. SEQ_printf(m, "cpu#%d\n", cpu);
  352. #endif
  353. #define P(x) \
  354. do { \
  355. if (sizeof(rq->x) == 4) \
  356. SEQ_printf(m, " .%-30s: %ld\n", #x, (long)(rq->x)); \
  357. else \
  358. SEQ_printf(m, " .%-30s: %Ld\n", #x, (long long)(rq->x));\
  359. } while (0)
  360. #define PN(x) \
  361. SEQ_printf(m, " .%-30s: %Ld.%06ld\n", #x, SPLIT_NS(rq->x))
  362. P(nr_running);
  363. SEQ_printf(m, " .%-30s: %lu\n", "load",
  364. rq->load.weight);
  365. P(nr_switches);
  366. P(nr_load_updates);
  367. P(nr_uninterruptible);
  368. PN(next_balance);
  369. SEQ_printf(m, " .%-30s: %ld\n", "curr->pid", (long)(task_pid_nr(rq->curr)));
  370. PN(clock);
  371. PN(clock_task);
  372. P(cpu_load[0]);
  373. P(cpu_load[1]);
  374. P(cpu_load[2]);
  375. P(cpu_load[3]);
  376. P(cpu_load[4]);
  377. #undef P
  378. #undef PN
  379. #ifdef CONFIG_SCHEDSTATS
  380. #define P(n) SEQ_printf(m, " .%-30s: %d\n", #n, rq->n);
  381. #define P64(n) SEQ_printf(m, " .%-30s: %Ld\n", #n, rq->n);
  382. #ifdef CONFIG_SMP
  383. P64(avg_idle);
  384. P64(max_idle_balance_cost);
  385. #endif
  386. if (schedstat_enabled()) {
  387. P(yld_count);
  388. P(sched_count);
  389. P(sched_goidle);
  390. P(ttwu_count);
  391. P(ttwu_local);
  392. }
  393. #undef P
  394. #undef P64
  395. #endif
  396. spin_lock_irqsave(&sched_debug_lock, flags);
  397. print_cfs_stats(m, cpu);
  398. print_rt_stats(m, cpu);
  399. print_dl_stats(m, cpu);
  400. print_rq(m, rq, cpu);
  401. spin_unlock_irqrestore(&sched_debug_lock, flags);
  402. SEQ_printf(m, "\n");
  403. }
  404. static const char *sched_tunable_scaling_names[] = {
  405. "none",
  406. "logaritmic",
  407. "linear"
  408. };
  409. static void sched_debug_header(struct seq_file *m)
  410. {
  411. u64 ktime, sched_clk, cpu_clk;
  412. unsigned long flags;
  413. local_irq_save(flags);
  414. ktime = ktime_to_ns(ktime_get());
  415. sched_clk = sched_clock();
  416. cpu_clk = local_clock();
  417. local_irq_restore(flags);
  418. SEQ_printf(m, "Sched Debug Version: v0.11, %s %.*s\n",
  419. init_utsname()->release,
  420. (int)strcspn(init_utsname()->version, " "),
  421. init_utsname()->version);
  422. #define P(x) \
  423. SEQ_printf(m, "%-40s: %Ld\n", #x, (long long)(x))
  424. #define PN(x) \
  425. SEQ_printf(m, "%-40s: %Ld.%06ld\n", #x, SPLIT_NS(x))
  426. PN(ktime);
  427. PN(sched_clk);
  428. PN(cpu_clk);
  429. P(jiffies);
  430. #ifdef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
  431. P(sched_clock_stable());
  432. #endif
  433. #undef PN
  434. #undef P
  435. SEQ_printf(m, "\n");
  436. SEQ_printf(m, "sysctl_sched\n");
  437. #define P(x) \
  438. SEQ_printf(m, " .%-40s: %Ld\n", #x, (long long)(x))
  439. #define PN(x) \
  440. SEQ_printf(m, " .%-40s: %Ld.%06ld\n", #x, SPLIT_NS(x))
  441. PN(sysctl_sched_latency);
  442. PN(sysctl_sched_min_granularity);
  443. PN(sysctl_sched_wakeup_granularity);
  444. P(sysctl_sched_child_runs_first);
  445. P(sysctl_sched_features);
  446. #undef PN
  447. #undef P
  448. SEQ_printf(m, " .%-40s: %d (%s)\n",
  449. "sysctl_sched_tunable_scaling",
  450. sysctl_sched_tunable_scaling,
  451. sched_tunable_scaling_names[sysctl_sched_tunable_scaling]);
  452. SEQ_printf(m, "\n");
  453. }
  454. static int sched_debug_show(struct seq_file *m, void *v)
  455. {
  456. int cpu = (unsigned long)(v - 2);
  457. if (cpu != -1)
  458. print_cpu(m, cpu);
  459. else
  460. sched_debug_header(m);
  461. return 0;
  462. }
  463. void sysrq_sched_debug_show(void)
  464. {
  465. int cpu;
  466. sched_debug_header(NULL);
  467. for_each_online_cpu(cpu)
  468. print_cpu(NULL, cpu);
  469. }
  470. /*
  471. * This itererator needs some explanation.
  472. * It returns 1 for the header position.
  473. * This means 2 is cpu 0.
  474. * In a hotplugged system some cpus, including cpu 0, may be missing so we have
  475. * to use cpumask_* to iterate over the cpus.
  476. */
  477. static void *sched_debug_start(struct seq_file *file, loff_t *offset)
  478. {
  479. unsigned long n = *offset;
  480. if (n == 0)
  481. return (void *) 1;
  482. n--;
  483. if (n > 0)
  484. n = cpumask_next(n - 1, cpu_online_mask);
  485. else
  486. n = cpumask_first(cpu_online_mask);
  487. *offset = n + 1;
  488. if (n < nr_cpu_ids)
  489. return (void *)(unsigned long)(n + 2);
  490. return NULL;
  491. }
  492. static void *sched_debug_next(struct seq_file *file, void *data, loff_t *offset)
  493. {
  494. (*offset)++;
  495. return sched_debug_start(file, offset);
  496. }
  497. static void sched_debug_stop(struct seq_file *file, void *data)
  498. {
  499. }
  500. static const struct seq_operations sched_debug_sops = {
  501. .start = sched_debug_start,
  502. .next = sched_debug_next,
  503. .stop = sched_debug_stop,
  504. .show = sched_debug_show,
  505. };
  506. static int sched_debug_release(struct inode *inode, struct file *file)
  507. {
  508. seq_release(inode, file);
  509. return 0;
  510. }
  511. static int sched_debug_open(struct inode *inode, struct file *filp)
  512. {
  513. int ret = 0;
  514. ret = seq_open(filp, &sched_debug_sops);
  515. return ret;
  516. }
  517. static const struct file_operations sched_debug_fops = {
  518. .open = sched_debug_open,
  519. .read = seq_read,
  520. .llseek = seq_lseek,
  521. .release = sched_debug_release,
  522. };
  523. static int __init init_sched_debug_procfs(void)
  524. {
  525. struct proc_dir_entry *pe;
  526. pe = proc_create("sched_debug", 0444, NULL, &sched_debug_fops);
  527. if (!pe)
  528. return -ENOMEM;
  529. return 0;
  530. }
  531. __initcall(init_sched_debug_procfs);
  532. #define __P(F) \
  533. SEQ_printf(m, "%-45s:%21Ld\n", #F, (long long)F)
  534. #define P(F) \
  535. SEQ_printf(m, "%-45s:%21Ld\n", #F, (long long)p->F)
  536. #define __PN(F) \
  537. SEQ_printf(m, "%-45s:%14Ld.%06ld\n", #F, SPLIT_NS((long long)F))
  538. #define PN(F) \
  539. SEQ_printf(m, "%-45s:%14Ld.%06ld\n", #F, SPLIT_NS((long long)p->F))
  540. #ifdef CONFIG_NUMA_BALANCING
  541. void print_numa_stats(struct seq_file *m, int node, unsigned long tsf,
  542. unsigned long tpf, unsigned long gsf, unsigned long gpf)
  543. {
  544. SEQ_printf(m, "numa_faults node=%d ", node);
  545. SEQ_printf(m, "task_private=%lu task_shared=%lu ", tsf, tpf);
  546. SEQ_printf(m, "group_private=%lu group_shared=%lu\n", gsf, gpf);
  547. }
  548. #endif
  549. static void sched_show_numa(struct task_struct *p, struct seq_file *m)
  550. {
  551. #ifdef CONFIG_NUMA_BALANCING
  552. struct mempolicy *pol;
  553. if (p->mm)
  554. P(mm->numa_scan_seq);
  555. task_lock(p);
  556. pol = p->mempolicy;
  557. if (pol && !(pol->flags & MPOL_F_MORON))
  558. pol = NULL;
  559. mpol_get(pol);
  560. task_unlock(p);
  561. P(numa_pages_migrated);
  562. P(numa_preferred_nid);
  563. P(total_numa_faults);
  564. SEQ_printf(m, "current_node=%d, numa_group_id=%d\n",
  565. task_node(p), task_numa_group_id(p));
  566. show_numa_stats(p, m);
  567. mpol_put(pol);
  568. #endif
  569. }
  570. void proc_sched_show_task(struct task_struct *p, struct seq_file *m)
  571. {
  572. unsigned long nr_switches;
  573. SEQ_printf(m, "%s (%d, #threads: %d)\n", p->comm, task_pid_nr(p),
  574. get_nr_threads(p));
  575. SEQ_printf(m,
  576. "---------------------------------------------------------"
  577. "----------\n");
  578. #define __P(F) \
  579. SEQ_printf(m, "%-45s:%21Ld\n", #F, (long long)F)
  580. #define P(F) \
  581. SEQ_printf(m, "%-45s:%21Ld\n", #F, (long long)p->F)
  582. #define __PN(F) \
  583. SEQ_printf(m, "%-45s:%14Ld.%06ld\n", #F, SPLIT_NS((long long)F))
  584. #define PN(F) \
  585. SEQ_printf(m, "%-45s:%14Ld.%06ld\n", #F, SPLIT_NS((long long)p->F))
  586. PN(se.exec_start);
  587. PN(se.vruntime);
  588. PN(se.sum_exec_runtime);
  589. nr_switches = p->nvcsw + p->nivcsw;
  590. #ifdef CONFIG_SCHEDSTATS
  591. P(se.nr_migrations);
  592. if (schedstat_enabled()) {
  593. u64 avg_atom, avg_per_cpu;
  594. PN(se.statistics.sum_sleep_runtime);
  595. PN(se.statistics.wait_start);
  596. PN(se.statistics.sleep_start);
  597. PN(se.statistics.block_start);
  598. PN(se.statistics.sleep_max);
  599. PN(se.statistics.block_max);
  600. PN(se.statistics.exec_max);
  601. PN(se.statistics.slice_max);
  602. PN(se.statistics.wait_max);
  603. PN(se.statistics.wait_sum);
  604. P(se.statistics.wait_count);
  605. PN(se.statistics.iowait_sum);
  606. P(se.statistics.iowait_count);
  607. P(se.statistics.nr_migrations_cold);
  608. P(se.statistics.nr_failed_migrations_affine);
  609. P(se.statistics.nr_failed_migrations_running);
  610. P(se.statistics.nr_failed_migrations_hot);
  611. P(se.statistics.nr_forced_migrations);
  612. P(se.statistics.nr_wakeups);
  613. P(se.statistics.nr_wakeups_sync);
  614. P(se.statistics.nr_wakeups_migrate);
  615. P(se.statistics.nr_wakeups_local);
  616. P(se.statistics.nr_wakeups_remote);
  617. P(se.statistics.nr_wakeups_affine);
  618. P(se.statistics.nr_wakeups_affine_attempts);
  619. P(se.statistics.nr_wakeups_passive);
  620. P(se.statistics.nr_wakeups_idle);
  621. avg_atom = p->se.sum_exec_runtime;
  622. if (nr_switches)
  623. avg_atom = div64_ul(avg_atom, nr_switches);
  624. else
  625. avg_atom = -1LL;
  626. avg_per_cpu = p->se.sum_exec_runtime;
  627. if (p->se.nr_migrations) {
  628. avg_per_cpu = div64_u64(avg_per_cpu,
  629. p->se.nr_migrations);
  630. } else {
  631. avg_per_cpu = -1LL;
  632. }
  633. __PN(avg_atom);
  634. __PN(avg_per_cpu);
  635. }
  636. #endif
  637. __P(nr_switches);
  638. SEQ_printf(m, "%-45s:%21Ld\n",
  639. "nr_voluntary_switches", (long long)p->nvcsw);
  640. SEQ_printf(m, "%-45s:%21Ld\n",
  641. "nr_involuntary_switches", (long long)p->nivcsw);
  642. P(se.load.weight);
  643. #ifdef CONFIG_SMP
  644. P(se.avg.load_sum);
  645. P(se.avg.util_sum);
  646. P(se.avg.load_avg);
  647. P(se.avg.util_avg);
  648. P(se.avg.last_update_time);
  649. #endif
  650. P(policy);
  651. P(prio);
  652. #undef PN
  653. #undef __PN
  654. #undef P
  655. #undef __P
  656. {
  657. unsigned int this_cpu = raw_smp_processor_id();
  658. u64 t0, t1;
  659. t0 = cpu_clock(this_cpu);
  660. t1 = cpu_clock(this_cpu);
  661. SEQ_printf(m, "%-45s:%21Ld\n",
  662. "clock-delta", (long long)(t1-t0));
  663. }
  664. sched_show_numa(p, m);
  665. }
  666. void proc_sched_set_task(struct task_struct *p)
  667. {
  668. #ifdef CONFIG_SCHEDSTATS
  669. memset(&p->se.statistics, 0, sizeof(p->se.statistics));
  670. #endif
  671. }