debug.c 24 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * kernel/sched/debug.c
  4. *
  5. * Print the CFS rbtree and other debugging details
  6. *
  7. * Copyright(C) 2007, Red Hat, Inc., Ingo Molnar
  8. */
  9. #include "sched.h"
  10. static DEFINE_SPINLOCK(sched_debug_lock);
  11. /*
  12. * This allows printing both to /proc/sched_debug and
  13. * to the console
  14. */
  15. #define SEQ_printf(m, x...) \
  16. do { \
  17. if (m) \
  18. seq_printf(m, x); \
  19. else \
  20. pr_cont(x); \
  21. } while (0)
  22. /*
  23. * Ease the printing of nsec fields:
  24. */
  25. static long long nsec_high(unsigned long long nsec)
  26. {
  27. if ((long long)nsec < 0) {
  28. nsec = -nsec;
  29. do_div(nsec, 1000000);
  30. return -nsec;
  31. }
  32. do_div(nsec, 1000000);
  33. return nsec;
  34. }
  35. static unsigned long nsec_low(unsigned long long nsec)
  36. {
  37. if ((long long)nsec < 0)
  38. nsec = -nsec;
  39. return do_div(nsec, 1000000);
  40. }
  41. #define SPLIT_NS(x) nsec_high(x), nsec_low(x)
  42. #define SCHED_FEAT(name, enabled) \
  43. #name ,
  44. const char * const sched_feat_names[] = {
  45. #include "features.h"
  46. };
  47. EXPORT_SYMBOL_GPL(sched_feat_names);
  48. #undef SCHED_FEAT
  49. static int sched_feat_show(struct seq_file *m, void *v)
  50. {
  51. int i;
  52. for (i = 0; i < __SCHED_FEAT_NR; i++) {
  53. if (!(sysctl_sched_features & (1UL << i)))
  54. seq_puts(m, "NO_");
  55. seq_printf(m, "%s ", sched_feat_names[i]);
  56. }
  57. seq_puts(m, "\n");
  58. return 0;
  59. }
  60. #ifdef CONFIG_JUMP_LABEL
  61. #define jump_label_key__true STATIC_KEY_INIT_TRUE
  62. #define jump_label_key__false STATIC_KEY_INIT_FALSE
  63. #define SCHED_FEAT(name, enabled) \
  64. jump_label_key__##enabled ,
  65. struct static_key sched_feat_keys[__SCHED_FEAT_NR] = {
  66. #include "features.h"
  67. };
  68. EXPORT_SYMBOL_GPL(sched_feat_keys);
  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 void
  191. set_table_entry(struct ctl_table *entry,
  192. const char *procname, void *data, int maxlen,
  193. umode_t mode, proc_handler *proc_handler)
  194. {
  195. entry->procname = procname;
  196. entry->data = data;
  197. entry->maxlen = maxlen;
  198. entry->mode = mode;
  199. entry->proc_handler = proc_handler;
  200. }
  201. static int sd_ctl_doflags(struct ctl_table *table, int write,
  202. void *buffer, size_t *lenp, loff_t *ppos)
  203. {
  204. unsigned long flags = *(unsigned long *)table->data;
  205. size_t data_size = 0;
  206. size_t len = 0;
  207. char *tmp, *buf;
  208. int idx;
  209. if (write)
  210. return 0;
  211. for_each_set_bit(idx, &flags, __SD_FLAG_CNT) {
  212. char *name = sd_flag_debug[idx].name;
  213. /* Name plus whitespace */
  214. data_size += strlen(name) + 1;
  215. }
  216. if (*ppos > data_size) {
  217. *lenp = 0;
  218. return 0;
  219. }
  220. buf = kcalloc(data_size + 1, sizeof(*buf), GFP_KERNEL);
  221. if (!buf)
  222. return -ENOMEM;
  223. for_each_set_bit(idx, &flags, __SD_FLAG_CNT) {
  224. char *name = sd_flag_debug[idx].name;
  225. len += snprintf(buf + len, strlen(name) + 2, "%s ", name);
  226. }
  227. tmp = buf + *ppos;
  228. len -= *ppos;
  229. if (len > *lenp)
  230. len = *lenp;
  231. if (len)
  232. memcpy(buffer, tmp, len);
  233. if (len < *lenp) {
  234. ((char *)buffer)[len] = '\n';
  235. len++;
  236. }
  237. *lenp = len;
  238. *ppos += len;
  239. kfree(buf);
  240. return 0;
  241. }
  242. static struct ctl_table *
  243. sd_alloc_ctl_domain_table(struct sched_domain *sd)
  244. {
  245. struct ctl_table *table = sd_alloc_ctl_entry(9);
  246. if (table == NULL)
  247. return NULL;
  248. set_table_entry(&table[0], "min_interval", &sd->min_interval, sizeof(long), 0644, proc_doulongvec_minmax);
  249. set_table_entry(&table[1], "max_interval", &sd->max_interval, sizeof(long), 0644, proc_doulongvec_minmax);
  250. set_table_entry(&table[2], "busy_factor", &sd->busy_factor, sizeof(int), 0644, proc_dointvec_minmax);
  251. set_table_entry(&table[3], "imbalance_pct", &sd->imbalance_pct, sizeof(int), 0644, proc_dointvec_minmax);
  252. set_table_entry(&table[4], "cache_nice_tries", &sd->cache_nice_tries, sizeof(int), 0644, proc_dointvec_minmax);
  253. set_table_entry(&table[5], "flags", &sd->flags, sizeof(int), 0444, sd_ctl_doflags);
  254. set_table_entry(&table[6], "max_newidle_lb_cost", &sd->max_newidle_lb_cost, sizeof(long), 0644, proc_doulongvec_minmax);
  255. set_table_entry(&table[7], "name", sd->name, CORENAME_MAX_SIZE, 0444, proc_dostring);
  256. /* &table[8] is terminator */
  257. return table;
  258. }
  259. static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
  260. {
  261. struct ctl_table *entry, *table;
  262. struct sched_domain *sd;
  263. int domain_num = 0, i;
  264. char buf[32];
  265. for_each_domain(cpu, sd)
  266. domain_num++;
  267. entry = table = sd_alloc_ctl_entry(domain_num + 1);
  268. if (table == NULL)
  269. return NULL;
  270. i = 0;
  271. for_each_domain(cpu, sd) {
  272. snprintf(buf, 32, "domain%d", i);
  273. entry->procname = kstrdup(buf, GFP_KERNEL);
  274. entry->mode = 0555;
  275. entry->child = sd_alloc_ctl_domain_table(sd);
  276. entry++;
  277. i++;
  278. }
  279. return table;
  280. }
  281. static cpumask_var_t sd_sysctl_cpus;
  282. static struct ctl_table_header *sd_sysctl_header;
  283. void register_sched_domain_sysctl(void)
  284. {
  285. static struct ctl_table *cpu_entries;
  286. static struct ctl_table **cpu_idx;
  287. static bool init_done = false;
  288. char buf[32];
  289. int i;
  290. if (!cpu_entries) {
  291. cpu_entries = sd_alloc_ctl_entry(num_possible_cpus() + 1);
  292. if (!cpu_entries)
  293. return;
  294. WARN_ON(sd_ctl_dir[0].child);
  295. sd_ctl_dir[0].child = cpu_entries;
  296. }
  297. if (!cpu_idx) {
  298. struct ctl_table *e = cpu_entries;
  299. cpu_idx = kcalloc(nr_cpu_ids, sizeof(struct ctl_table*), GFP_KERNEL);
  300. if (!cpu_idx)
  301. return;
  302. /* deal with sparse possible map */
  303. for_each_possible_cpu(i) {
  304. cpu_idx[i] = e;
  305. e++;
  306. }
  307. }
  308. if (!cpumask_available(sd_sysctl_cpus)) {
  309. if (!alloc_cpumask_var(&sd_sysctl_cpus, GFP_KERNEL))
  310. return;
  311. }
  312. if (!init_done) {
  313. init_done = true;
  314. /* init to possible to not have holes in @cpu_entries */
  315. cpumask_copy(sd_sysctl_cpus, cpu_possible_mask);
  316. }
  317. for_each_cpu(i, sd_sysctl_cpus) {
  318. struct ctl_table *e = cpu_idx[i];
  319. if (e->child)
  320. sd_free_ctl_entry(&e->child);
  321. if (!e->procname) {
  322. snprintf(buf, 32, "cpu%d", i);
  323. e->procname = kstrdup(buf, GFP_KERNEL);
  324. }
  325. e->mode = 0555;
  326. e->child = sd_alloc_ctl_cpu_table(i);
  327. __cpumask_clear_cpu(i, sd_sysctl_cpus);
  328. }
  329. WARN_ON(sd_sysctl_header);
  330. sd_sysctl_header = register_sysctl_table(sd_ctl_root);
  331. }
  332. void dirty_sched_domain_sysctl(int cpu)
  333. {
  334. if (cpumask_available(sd_sysctl_cpus))
  335. __cpumask_set_cpu(cpu, sd_sysctl_cpus);
  336. }
  337. /* may be called multiple times per register */
  338. void unregister_sched_domain_sysctl(void)
  339. {
  340. unregister_sysctl_table(sd_sysctl_header);
  341. sd_sysctl_header = NULL;
  342. }
  343. #endif /* CONFIG_SYSCTL */
  344. #endif /* CONFIG_SMP */
  345. #ifdef CONFIG_FAIR_GROUP_SCHED
  346. static void print_cfs_group_stats(struct seq_file *m, int cpu, struct task_group *tg)
  347. {
  348. struct sched_entity *se = tg->se[cpu];
  349. #define P(F) SEQ_printf(m, " .%-30s: %lld\n", #F, (long long)F)
  350. #define P_SCHEDSTAT(F) SEQ_printf(m, " .%-30s: %lld\n", #F, (long long)schedstat_val(F))
  351. #define PN(F) SEQ_printf(m, " .%-30s: %lld.%06ld\n", #F, SPLIT_NS((long long)F))
  352. #define PN_SCHEDSTAT(F) SEQ_printf(m, " .%-30s: %lld.%06ld\n", #F, SPLIT_NS((long long)schedstat_val(F)))
  353. if (!se)
  354. return;
  355. PN(se->exec_start);
  356. PN(se->vruntime);
  357. PN(se->sum_exec_runtime);
  358. if (schedstat_enabled()) {
  359. PN_SCHEDSTAT(se->statistics.wait_start);
  360. PN_SCHEDSTAT(se->statistics.sleep_start);
  361. PN_SCHEDSTAT(se->statistics.block_start);
  362. PN_SCHEDSTAT(se->statistics.sleep_max);
  363. PN_SCHEDSTAT(se->statistics.block_max);
  364. PN_SCHEDSTAT(se->statistics.exec_max);
  365. PN_SCHEDSTAT(se->statistics.slice_max);
  366. PN_SCHEDSTAT(se->statistics.wait_max);
  367. PN_SCHEDSTAT(se->statistics.wait_sum);
  368. P_SCHEDSTAT(se->statistics.wait_count);
  369. }
  370. P(se->load.weight);
  371. #ifdef CONFIG_SMP
  372. P(se->avg.load_avg);
  373. P(se->avg.util_avg);
  374. P(se->avg.runnable_avg);
  375. #endif
  376. #undef PN_SCHEDSTAT
  377. #undef PN
  378. #undef P_SCHEDSTAT
  379. #undef P
  380. }
  381. #endif
  382. #ifdef CONFIG_CGROUP_SCHED
  383. static char group_path[PATH_MAX];
  384. static char *task_group_path(struct task_group *tg)
  385. {
  386. if (autogroup_path(tg, group_path, PATH_MAX))
  387. return group_path;
  388. cgroup_path(tg->css.cgroup, group_path, PATH_MAX);
  389. return group_path;
  390. }
  391. #endif
  392. static void
  393. print_task(struct seq_file *m, struct rq *rq, struct task_struct *p)
  394. {
  395. if (rq->curr == p)
  396. SEQ_printf(m, ">R");
  397. else
  398. SEQ_printf(m, " %c", task_state_to_char(p));
  399. SEQ_printf(m, " %15s %5d %9Ld.%06ld %9Ld %5d ",
  400. p->comm, task_pid_nr(p),
  401. SPLIT_NS(p->se.vruntime),
  402. (long long)(p->nvcsw + p->nivcsw),
  403. p->prio);
  404. SEQ_printf(m, "%9Ld.%06ld %9Ld.%06ld %9Ld.%06ld",
  405. SPLIT_NS(schedstat_val_or_zero(p->se.statistics.wait_sum)),
  406. SPLIT_NS(p->se.sum_exec_runtime),
  407. SPLIT_NS(schedstat_val_or_zero(p->se.statistics.sum_sleep_runtime)));
  408. #ifdef CONFIG_NUMA_BALANCING
  409. SEQ_printf(m, " %d %d", task_node(p), task_numa_group_id(p));
  410. #endif
  411. #ifdef CONFIG_CGROUP_SCHED
  412. SEQ_printf(m, " %s", task_group_path(task_group(p)));
  413. #endif
  414. SEQ_printf(m, "\n");
  415. }
  416. static void print_rq(struct seq_file *m, struct rq *rq, int rq_cpu)
  417. {
  418. struct task_struct *g, *p;
  419. SEQ_printf(m, "\n");
  420. SEQ_printf(m, "runnable tasks:\n");
  421. SEQ_printf(m, " S task PID tree-key switches prio"
  422. " wait-time sum-exec sum-sleep\n");
  423. SEQ_printf(m, "-------------------------------------------------------"
  424. "------------------------------------------------------\n");
  425. rcu_read_lock();
  426. for_each_process_thread(g, p) {
  427. if (task_cpu(p) != rq_cpu)
  428. continue;
  429. print_task(m, rq, p);
  430. }
  431. rcu_read_unlock();
  432. }
  433. void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)
  434. {
  435. s64 MIN_vruntime = -1, min_vruntime, max_vruntime = -1,
  436. spread, rq0_min_vruntime, spread0;
  437. struct rq *rq = cpu_rq(cpu);
  438. struct sched_entity *last;
  439. unsigned long flags;
  440. #ifdef CONFIG_FAIR_GROUP_SCHED
  441. SEQ_printf(m, "\n");
  442. SEQ_printf(m, "cfs_rq[%d]:%s\n", cpu, task_group_path(cfs_rq->tg));
  443. #else
  444. SEQ_printf(m, "\n");
  445. SEQ_printf(m, "cfs_rq[%d]:\n", cpu);
  446. #endif
  447. SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "exec_clock",
  448. SPLIT_NS(cfs_rq->exec_clock));
  449. raw_spin_lock_irqsave(&rq->lock, flags);
  450. if (rb_first_cached(&cfs_rq->tasks_timeline))
  451. MIN_vruntime = (__pick_first_entity(cfs_rq))->vruntime;
  452. last = __pick_last_entity(cfs_rq);
  453. if (last)
  454. max_vruntime = last->vruntime;
  455. min_vruntime = cfs_rq->min_vruntime;
  456. rq0_min_vruntime = cpu_rq(0)->cfs.min_vruntime;
  457. raw_spin_unlock_irqrestore(&rq->lock, flags);
  458. SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "MIN_vruntime",
  459. SPLIT_NS(MIN_vruntime));
  460. SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "min_vruntime",
  461. SPLIT_NS(min_vruntime));
  462. SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "max_vruntime",
  463. SPLIT_NS(max_vruntime));
  464. spread = max_vruntime - MIN_vruntime;
  465. SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "spread",
  466. SPLIT_NS(spread));
  467. spread0 = min_vruntime - rq0_min_vruntime;
  468. SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "spread0",
  469. SPLIT_NS(spread0));
  470. SEQ_printf(m, " .%-30s: %d\n", "nr_spread_over",
  471. cfs_rq->nr_spread_over);
  472. SEQ_printf(m, " .%-30s: %d\n", "nr_running", cfs_rq->nr_running);
  473. SEQ_printf(m, " .%-30s: %ld\n", "load", cfs_rq->load.weight);
  474. #ifdef CONFIG_SMP
  475. SEQ_printf(m, " .%-30s: %lu\n", "load_avg",
  476. cfs_rq->avg.load_avg);
  477. SEQ_printf(m, " .%-30s: %lu\n", "runnable_avg",
  478. cfs_rq->avg.runnable_avg);
  479. SEQ_printf(m, " .%-30s: %lu\n", "util_avg",
  480. cfs_rq->avg.util_avg);
  481. SEQ_printf(m, " .%-30s: %u\n", "util_est_enqueued",
  482. cfs_rq->avg.util_est.enqueued);
  483. SEQ_printf(m, " .%-30s: %ld\n", "removed.load_avg",
  484. cfs_rq->removed.load_avg);
  485. SEQ_printf(m, " .%-30s: %ld\n", "removed.util_avg",
  486. cfs_rq->removed.util_avg);
  487. SEQ_printf(m, " .%-30s: %ld\n", "removed.runnable_avg",
  488. cfs_rq->removed.runnable_avg);
  489. #ifdef CONFIG_FAIR_GROUP_SCHED
  490. SEQ_printf(m, " .%-30s: %lu\n", "tg_load_avg_contrib",
  491. cfs_rq->tg_load_avg_contrib);
  492. SEQ_printf(m, " .%-30s: %ld\n", "tg_load_avg",
  493. atomic_long_read(&cfs_rq->tg->load_avg));
  494. #endif
  495. #endif
  496. #ifdef CONFIG_CFS_BANDWIDTH
  497. SEQ_printf(m, " .%-30s: %d\n", "throttled",
  498. cfs_rq->throttled);
  499. SEQ_printf(m, " .%-30s: %d\n", "throttle_count",
  500. cfs_rq->throttle_count);
  501. #endif
  502. #ifdef CONFIG_FAIR_GROUP_SCHED
  503. print_cfs_group_stats(m, cpu, cfs_rq->tg);
  504. #endif
  505. }
  506. void print_rt_rq(struct seq_file *m, int cpu, struct rt_rq *rt_rq)
  507. {
  508. #ifdef CONFIG_RT_GROUP_SCHED
  509. SEQ_printf(m, "\n");
  510. SEQ_printf(m, "rt_rq[%d]:%s\n", cpu, task_group_path(rt_rq->tg));
  511. #else
  512. SEQ_printf(m, "\n");
  513. SEQ_printf(m, "rt_rq[%d]:\n", cpu);
  514. #endif
  515. #define P(x) \
  516. SEQ_printf(m, " .%-30s: %Ld\n", #x, (long long)(rt_rq->x))
  517. #define PU(x) \
  518. SEQ_printf(m, " .%-30s: %lu\n", #x, (unsigned long)(rt_rq->x))
  519. #define PN(x) \
  520. SEQ_printf(m, " .%-30s: %Ld.%06ld\n", #x, SPLIT_NS(rt_rq->x))
  521. PU(rt_nr_running);
  522. #ifdef CONFIG_SMP
  523. PU(rt_nr_migratory);
  524. #endif
  525. P(rt_throttled);
  526. PN(rt_time);
  527. PN(rt_runtime);
  528. #undef PN
  529. #undef PU
  530. #undef P
  531. }
  532. void print_dl_rq(struct seq_file *m, int cpu, struct dl_rq *dl_rq)
  533. {
  534. struct dl_bw *dl_bw;
  535. SEQ_printf(m, "\n");
  536. SEQ_printf(m, "dl_rq[%d]:\n", cpu);
  537. #define PU(x) \
  538. SEQ_printf(m, " .%-30s: %lu\n", #x, (unsigned long)(dl_rq->x))
  539. PU(dl_nr_running);
  540. #ifdef CONFIG_SMP
  541. PU(dl_nr_migratory);
  542. dl_bw = &cpu_rq(cpu)->rd->dl_bw;
  543. #else
  544. dl_bw = &dl_rq->dl_bw;
  545. #endif
  546. SEQ_printf(m, " .%-30s: %lld\n", "dl_bw->bw", dl_bw->bw);
  547. SEQ_printf(m, " .%-30s: %lld\n", "dl_bw->total_bw", dl_bw->total_bw);
  548. #undef PU
  549. }
  550. static void print_cpu(struct seq_file *m, int cpu)
  551. {
  552. struct rq *rq = cpu_rq(cpu);
  553. unsigned long flags;
  554. #ifdef CONFIG_X86
  555. {
  556. unsigned int freq = cpu_khz ? : 1;
  557. SEQ_printf(m, "cpu#%d, %u.%03u MHz\n",
  558. cpu, freq / 1000, (freq % 1000));
  559. }
  560. #else
  561. SEQ_printf(m, "cpu#%d\n", cpu);
  562. #endif
  563. #define P(x) \
  564. do { \
  565. if (sizeof(rq->x) == 4) \
  566. SEQ_printf(m, " .%-30s: %ld\n", #x, (long)(rq->x)); \
  567. else \
  568. SEQ_printf(m, " .%-30s: %Ld\n", #x, (long long)(rq->x));\
  569. } while (0)
  570. #define PN(x) \
  571. SEQ_printf(m, " .%-30s: %Ld.%06ld\n", #x, SPLIT_NS(rq->x))
  572. P(nr_running);
  573. P(nr_switches);
  574. P(nr_uninterruptible);
  575. PN(next_balance);
  576. SEQ_printf(m, " .%-30s: %ld\n", "curr->pid", (long)(task_pid_nr(rq->curr)));
  577. PN(clock);
  578. PN(clock_task);
  579. #undef P
  580. #undef PN
  581. #ifdef CONFIG_SMP
  582. #define P64(n) SEQ_printf(m, " .%-30s: %Ld\n", #n, rq->n);
  583. P64(avg_idle);
  584. P64(max_idle_balance_cost);
  585. #undef P64
  586. #endif
  587. #define P(n) SEQ_printf(m, " .%-30s: %d\n", #n, schedstat_val(rq->n));
  588. if (schedstat_enabled()) {
  589. P(yld_count);
  590. P(sched_count);
  591. P(sched_goidle);
  592. P(ttwu_count);
  593. P(ttwu_local);
  594. }
  595. #undef P
  596. spin_lock_irqsave(&sched_debug_lock, flags);
  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. spin_unlock_irqrestore(&sched_debug_lock, flags);
  602. SEQ_printf(m, "\n");
  603. }
  604. static const char *sched_tunable_scaling_names[] = {
  605. "none",
  606. "logarithmic",
  607. "linear"
  608. };
  609. static void sched_debug_header(struct seq_file *m)
  610. {
  611. u64 ktime, sched_clk, cpu_clk;
  612. unsigned long flags;
  613. local_irq_save(flags);
  614. ktime = ktime_to_ns(ktime_get());
  615. sched_clk = sched_clock();
  616. cpu_clk = local_clock();
  617. local_irq_restore(flags);
  618. SEQ_printf(m, "Sched Debug Version: v0.11, %s %.*s\n",
  619. init_utsname()->release,
  620. (int)strcspn(init_utsname()->version, " "),
  621. init_utsname()->version);
  622. #define P(x) \
  623. SEQ_printf(m, "%-40s: %Ld\n", #x, (long long)(x))
  624. #define PN(x) \
  625. SEQ_printf(m, "%-40s: %Ld.%06ld\n", #x, SPLIT_NS(x))
  626. PN(ktime);
  627. PN(sched_clk);
  628. PN(cpu_clk);
  629. P(jiffies);
  630. #ifdef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
  631. P(sched_clock_stable());
  632. #endif
  633. #undef PN
  634. #undef P
  635. SEQ_printf(m, "\n");
  636. SEQ_printf(m, "sysctl_sched\n");
  637. #define P(x) \
  638. SEQ_printf(m, " .%-40s: %Ld\n", #x, (long long)(x))
  639. #define PN(x) \
  640. SEQ_printf(m, " .%-40s: %Ld.%06ld\n", #x, SPLIT_NS(x))
  641. PN(sysctl_sched_latency);
  642. PN(sysctl_sched_min_granularity);
  643. PN(sysctl_sched_wakeup_granularity);
  644. P(sysctl_sched_child_runs_first);
  645. P(sysctl_sched_features);
  646. #undef PN
  647. #undef P
  648. SEQ_printf(m, " .%-40s: %d (%s)\n",
  649. "sysctl_sched_tunable_scaling",
  650. sysctl_sched_tunable_scaling,
  651. sched_tunable_scaling_names[sysctl_sched_tunable_scaling]);
  652. SEQ_printf(m, "\n");
  653. }
  654. static int sched_debug_show(struct seq_file *m, void *v)
  655. {
  656. int cpu = (unsigned long)(v - 2);
  657. if (cpu != -1)
  658. print_cpu(m, cpu);
  659. else
  660. sched_debug_header(m);
  661. return 0;
  662. }
  663. void sysrq_sched_debug_show(void)
  664. {
  665. int cpu;
  666. sched_debug_header(NULL);
  667. for_each_online_cpu(cpu) {
  668. /*
  669. * Need to reset softlockup watchdogs on all CPUs, because
  670. * another CPU might be blocked waiting for us to process
  671. * an IPI or stop_machine.
  672. */
  673. touch_nmi_watchdog();
  674. touch_all_softlockup_watchdogs();
  675. print_cpu(NULL, cpu);
  676. }
  677. }
  678. /*
  679. * This itererator needs some explanation.
  680. * It returns 1 for the header position.
  681. * This means 2 is CPU 0.
  682. * In a hotplugged system some CPUs, including CPU 0, may be missing so we have
  683. * to use cpumask_* to iterate over the CPUs.
  684. */
  685. static void *sched_debug_start(struct seq_file *file, loff_t *offset)
  686. {
  687. unsigned long n = *offset;
  688. if (n == 0)
  689. return (void *) 1;
  690. n--;
  691. if (n > 0)
  692. n = cpumask_next(n - 1, cpu_online_mask);
  693. else
  694. n = cpumask_first(cpu_online_mask);
  695. *offset = n + 1;
  696. if (n < nr_cpu_ids)
  697. return (void *)(unsigned long)(n + 2);
  698. return NULL;
  699. }
  700. static void *sched_debug_next(struct seq_file *file, void *data, loff_t *offset)
  701. {
  702. (*offset)++;
  703. return sched_debug_start(file, offset);
  704. }
  705. static void sched_debug_stop(struct seq_file *file, void *data)
  706. {
  707. }
  708. static const struct seq_operations sched_debug_sops = {
  709. .start = sched_debug_start,
  710. .next = sched_debug_next,
  711. .stop = sched_debug_stop,
  712. .show = sched_debug_show,
  713. };
  714. static int __init init_sched_debug_procfs(void)
  715. {
  716. if (!proc_create_seq("sched_debug", 0444, NULL, &sched_debug_sops))
  717. return -ENOMEM;
  718. return 0;
  719. }
  720. __initcall(init_sched_debug_procfs);
  721. #define __PS(S, F) SEQ_printf(m, "%-45s:%21Ld\n", S, (long long)(F))
  722. #define __P(F) __PS(#F, F)
  723. #define P(F) __PS(#F, p->F)
  724. #define __PSN(S, F) SEQ_printf(m, "%-45s:%14Ld.%06ld\n", S, SPLIT_NS((long long)(F)))
  725. #define __PN(F) __PSN(#F, F)
  726. #define PN(F) __PSN(#F, p->F)
  727. #ifdef CONFIG_NUMA_BALANCING
  728. void print_numa_stats(struct seq_file *m, int node, unsigned long tsf,
  729. unsigned long tpf, unsigned long gsf, unsigned long gpf)
  730. {
  731. SEQ_printf(m, "numa_faults node=%d ", node);
  732. SEQ_printf(m, "task_private=%lu task_shared=%lu ", tpf, tsf);
  733. SEQ_printf(m, "group_private=%lu group_shared=%lu\n", gpf, gsf);
  734. }
  735. #endif
  736. static void sched_show_numa(struct task_struct *p, struct seq_file *m)
  737. {
  738. #ifdef CONFIG_NUMA_BALANCING
  739. struct mempolicy *pol;
  740. if (p->mm)
  741. P(mm->numa_scan_seq);
  742. task_lock(p);
  743. pol = p->mempolicy;
  744. if (pol && !(pol->flags & MPOL_F_MORON))
  745. pol = NULL;
  746. mpol_get(pol);
  747. task_unlock(p);
  748. P(numa_pages_migrated);
  749. P(numa_preferred_nid);
  750. P(total_numa_faults);
  751. SEQ_printf(m, "current_node=%d, numa_group_id=%d\n",
  752. task_node(p), task_numa_group_id(p));
  753. show_numa_stats(p, m);
  754. mpol_put(pol);
  755. #endif
  756. }
  757. void proc_sched_show_task(struct task_struct *p, struct pid_namespace *ns,
  758. struct seq_file *m)
  759. {
  760. unsigned long nr_switches;
  761. SEQ_printf(m, "%s (%d, #threads: %d)\n", p->comm, task_pid_nr_ns(p, ns),
  762. get_nr_threads(p));
  763. SEQ_printf(m,
  764. "---------------------------------------------------------"
  765. "----------\n");
  766. #define P_SCHEDSTAT(F) __PS(#F, schedstat_val(p->F))
  767. #define PN_SCHEDSTAT(F) __PSN(#F, schedstat_val(p->F))
  768. PN(se.exec_start);
  769. PN(se.vruntime);
  770. PN(se.sum_exec_runtime);
  771. nr_switches = p->nvcsw + p->nivcsw;
  772. P(se.nr_migrations);
  773. if (schedstat_enabled()) {
  774. u64 avg_atom, avg_per_cpu;
  775. PN_SCHEDSTAT(se.statistics.sum_sleep_runtime);
  776. PN_SCHEDSTAT(se.statistics.wait_start);
  777. PN_SCHEDSTAT(se.statistics.sleep_start);
  778. PN_SCHEDSTAT(se.statistics.block_start);
  779. PN_SCHEDSTAT(se.statistics.sleep_max);
  780. PN_SCHEDSTAT(se.statistics.block_max);
  781. PN_SCHEDSTAT(se.statistics.exec_max);
  782. PN_SCHEDSTAT(se.statistics.slice_max);
  783. PN_SCHEDSTAT(se.statistics.wait_max);
  784. PN_SCHEDSTAT(se.statistics.wait_sum);
  785. P_SCHEDSTAT(se.statistics.wait_count);
  786. PN_SCHEDSTAT(se.statistics.iowait_sum);
  787. P_SCHEDSTAT(se.statistics.iowait_count);
  788. P_SCHEDSTAT(se.statistics.nr_migrations_cold);
  789. P_SCHEDSTAT(se.statistics.nr_failed_migrations_affine);
  790. P_SCHEDSTAT(se.statistics.nr_failed_migrations_running);
  791. P_SCHEDSTAT(se.statistics.nr_failed_migrations_hot);
  792. P_SCHEDSTAT(se.statistics.nr_forced_migrations);
  793. P_SCHEDSTAT(se.statistics.nr_wakeups);
  794. P_SCHEDSTAT(se.statistics.nr_wakeups_sync);
  795. P_SCHEDSTAT(se.statistics.nr_wakeups_migrate);
  796. P_SCHEDSTAT(se.statistics.nr_wakeups_local);
  797. P_SCHEDSTAT(se.statistics.nr_wakeups_remote);
  798. P_SCHEDSTAT(se.statistics.nr_wakeups_affine);
  799. P_SCHEDSTAT(se.statistics.nr_wakeups_affine_attempts);
  800. P_SCHEDSTAT(se.statistics.nr_wakeups_passive);
  801. P_SCHEDSTAT(se.statistics.nr_wakeups_idle);
  802. avg_atom = p->se.sum_exec_runtime;
  803. if (nr_switches)
  804. avg_atom = div64_ul(avg_atom, nr_switches);
  805. else
  806. avg_atom = -1LL;
  807. avg_per_cpu = p->se.sum_exec_runtime;
  808. if (p->se.nr_migrations) {
  809. avg_per_cpu = div64_u64(avg_per_cpu,
  810. p->se.nr_migrations);
  811. } else {
  812. avg_per_cpu = -1LL;
  813. }
  814. __PN(avg_atom);
  815. __PN(avg_per_cpu);
  816. }
  817. __P(nr_switches);
  818. __PS("nr_voluntary_switches", p->nvcsw);
  819. __PS("nr_involuntary_switches", p->nivcsw);
  820. P(se.load.weight);
  821. #ifdef CONFIG_SMP
  822. P(se.avg.load_sum);
  823. P(se.avg.runnable_sum);
  824. P(se.avg.util_sum);
  825. P(se.avg.load_avg);
  826. P(se.avg.runnable_avg);
  827. P(se.avg.util_avg);
  828. P(se.avg.last_update_time);
  829. P(se.avg.util_est.ewma);
  830. P(se.avg.util_est.enqueued);
  831. #endif
  832. #ifdef CONFIG_UCLAMP_TASK
  833. __PS("uclamp.min", p->uclamp_req[UCLAMP_MIN].value);
  834. __PS("uclamp.max", p->uclamp_req[UCLAMP_MAX].value);
  835. __PS("effective uclamp.min", uclamp_eff_value(p, UCLAMP_MIN));
  836. __PS("effective uclamp.max", uclamp_eff_value(p, UCLAMP_MAX));
  837. #endif
  838. P(policy);
  839. P(prio);
  840. if (task_has_dl_policy(p)) {
  841. P(dl.runtime);
  842. P(dl.deadline);
  843. }
  844. #undef PN_SCHEDSTAT
  845. #undef P_SCHEDSTAT
  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. __PS("clock-delta", t1-t0);
  852. }
  853. sched_show_numa(p, m);
  854. }
  855. void proc_sched_set_task(struct task_struct *p)
  856. {
  857. #ifdef CONFIG_SCHEDSTATS
  858. memset(&p->se.statistics, 0, sizeof(p->se.statistics));
  859. #endif
  860. }