debug.c 26 KB

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