lockdep_proc.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  1. /*
  2. * kernel/lockdep_proc.c
  3. *
  4. * Runtime locking correctness validator
  5. *
  6. * Started by Ingo Molnar:
  7. *
  8. * Copyright (C) 2006,2007 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
  9. * Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra <pzijlstr@redhat.com>
  10. *
  11. * Code for /proc/lockdep and /proc/lockdep_stats:
  12. *
  13. */
  14. #include <linux/module.h>
  15. #include <linux/proc_fs.h>
  16. #include <linux/seq_file.h>
  17. #include <linux/kallsyms.h>
  18. #include <linux/debug_locks.h>
  19. #include <linux/vmalloc.h>
  20. #include <linux/sort.h>
  21. #include <asm/uaccess.h>
  22. #include <asm/div64.h>
  23. #include "lockdep_internals.h"
  24. static void *l_next(struct seq_file *m, void *v, loff_t *pos)
  25. {
  26. struct lock_class *class;
  27. (*pos)++;
  28. if (v == SEQ_START_TOKEN)
  29. class = m->private;
  30. else {
  31. class = v;
  32. if (class->lock_entry.next != &all_lock_classes)
  33. class = list_entry(class->lock_entry.next,
  34. struct lock_class, lock_entry);
  35. else
  36. class = NULL;
  37. }
  38. return class;
  39. }
  40. static void *l_start(struct seq_file *m, loff_t *pos)
  41. {
  42. struct lock_class *class;
  43. loff_t i = 0;
  44. if (*pos == 0)
  45. return SEQ_START_TOKEN;
  46. list_for_each_entry(class, &all_lock_classes, lock_entry) {
  47. if (++i == *pos)
  48. return class;
  49. }
  50. return NULL;
  51. }
  52. static void l_stop(struct seq_file *m, void *v)
  53. {
  54. }
  55. static unsigned long count_forward_deps(struct lock_class *class)
  56. {
  57. struct lock_list *entry;
  58. unsigned long ret = 1;
  59. /*
  60. * Recurse this class's dependency list:
  61. */
  62. list_for_each_entry(entry, &class->locks_after, entry)
  63. ret += count_forward_deps(entry->class);
  64. return ret;
  65. }
  66. static unsigned long count_backward_deps(struct lock_class *class)
  67. {
  68. struct lock_list *entry;
  69. unsigned long ret = 1;
  70. /*
  71. * Recurse this class's dependency list:
  72. */
  73. list_for_each_entry(entry, &class->locks_before, entry)
  74. ret += count_backward_deps(entry->class);
  75. return ret;
  76. }
  77. static void print_name(struct seq_file *m, struct lock_class *class)
  78. {
  79. char str[128];
  80. const char *name = class->name;
  81. if (!name) {
  82. name = __get_key_name(class->key, str);
  83. seq_printf(m, "%s", name);
  84. } else{
  85. seq_printf(m, "%s", name);
  86. if (class->name_version > 1)
  87. seq_printf(m, "#%d", class->name_version);
  88. if (class->subclass)
  89. seq_printf(m, "/%d", class->subclass);
  90. }
  91. }
  92. static int l_show(struct seq_file *m, void *v)
  93. {
  94. unsigned long nr_forward_deps, nr_backward_deps;
  95. struct lock_class *class = v;
  96. struct lock_list *entry;
  97. char c1, c2, c3, c4;
  98. if (v == SEQ_START_TOKEN) {
  99. seq_printf(m, "all lock classes:\n");
  100. return 0;
  101. }
  102. seq_printf(m, "%p", class->key);
  103. #ifdef CONFIG_DEBUG_LOCKDEP
  104. seq_printf(m, " OPS:%8ld", class->ops);
  105. #endif
  106. nr_forward_deps = count_forward_deps(class);
  107. seq_printf(m, " FD:%5ld", nr_forward_deps);
  108. nr_backward_deps = count_backward_deps(class);
  109. seq_printf(m, " BD:%5ld", nr_backward_deps);
  110. get_usage_chars(class, &c1, &c2, &c3, &c4);
  111. seq_printf(m, " %c%c%c%c", c1, c2, c3, c4);
  112. seq_printf(m, ": ");
  113. print_name(m, class);
  114. seq_puts(m, "\n");
  115. list_for_each_entry(entry, &class->locks_after, entry) {
  116. if (entry->distance == 1) {
  117. seq_printf(m, " -> [%p] ", entry->class->key);
  118. print_name(m, entry->class);
  119. seq_puts(m, "\n");
  120. }
  121. }
  122. seq_puts(m, "\n");
  123. return 0;
  124. }
  125. static const struct seq_operations lockdep_ops = {
  126. .start = l_start,
  127. .next = l_next,
  128. .stop = l_stop,
  129. .show = l_show,
  130. };
  131. static int lockdep_open(struct inode *inode, struct file *file)
  132. {
  133. int res = seq_open(file, &lockdep_ops);
  134. if (!res) {
  135. struct seq_file *m = file->private_data;
  136. if (!list_empty(&all_lock_classes))
  137. m->private = list_entry(all_lock_classes.next,
  138. struct lock_class, lock_entry);
  139. else
  140. m->private = NULL;
  141. }
  142. return res;
  143. }
  144. static const struct file_operations proc_lockdep_operations = {
  145. .open = lockdep_open,
  146. .read = seq_read,
  147. .llseek = seq_lseek,
  148. .release = seq_release,
  149. };
  150. #ifdef CONFIG_PROVE_LOCKING
  151. static void *lc_next(struct seq_file *m, void *v, loff_t *pos)
  152. {
  153. struct lock_chain *chain;
  154. (*pos)++;
  155. if (v == SEQ_START_TOKEN)
  156. chain = m->private;
  157. else {
  158. chain = v;
  159. if (*pos < nr_lock_chains)
  160. chain = lock_chains + *pos;
  161. else
  162. chain = NULL;
  163. }
  164. return chain;
  165. }
  166. static void *lc_start(struct seq_file *m, loff_t *pos)
  167. {
  168. if (*pos == 0)
  169. return SEQ_START_TOKEN;
  170. if (*pos < nr_lock_chains)
  171. return lock_chains + *pos;
  172. return NULL;
  173. }
  174. static void lc_stop(struct seq_file *m, void *v)
  175. {
  176. }
  177. static int lc_show(struct seq_file *m, void *v)
  178. {
  179. struct lock_chain *chain = v;
  180. struct lock_class *class;
  181. int i;
  182. if (v == SEQ_START_TOKEN) {
  183. seq_printf(m, "all lock chains:\n");
  184. return 0;
  185. }
  186. seq_printf(m, "irq_context: %d\n", chain->irq_context);
  187. for (i = 0; i < chain->depth; i++) {
  188. class = lock_chain_get_class(chain, i);
  189. seq_printf(m, "[%p] ", class->key);
  190. print_name(m, class);
  191. seq_puts(m, "\n");
  192. }
  193. seq_puts(m, "\n");
  194. return 0;
  195. }
  196. static const struct seq_operations lockdep_chains_ops = {
  197. .start = lc_start,
  198. .next = lc_next,
  199. .stop = lc_stop,
  200. .show = lc_show,
  201. };
  202. static int lockdep_chains_open(struct inode *inode, struct file *file)
  203. {
  204. int res = seq_open(file, &lockdep_chains_ops);
  205. if (!res) {
  206. struct seq_file *m = file->private_data;
  207. if (nr_lock_chains)
  208. m->private = lock_chains;
  209. else
  210. m->private = NULL;
  211. }
  212. return res;
  213. }
  214. static const struct file_operations proc_lockdep_chains_operations = {
  215. .open = lockdep_chains_open,
  216. .read = seq_read,
  217. .llseek = seq_lseek,
  218. .release = seq_release,
  219. };
  220. #endif /* CONFIG_PROVE_LOCKING */
  221. static void lockdep_stats_debug_show(struct seq_file *m)
  222. {
  223. #ifdef CONFIG_DEBUG_LOCKDEP
  224. unsigned int hi1 = debug_atomic_read(&hardirqs_on_events),
  225. hi2 = debug_atomic_read(&hardirqs_off_events),
  226. hr1 = debug_atomic_read(&redundant_hardirqs_on),
  227. hr2 = debug_atomic_read(&redundant_hardirqs_off),
  228. si1 = debug_atomic_read(&softirqs_on_events),
  229. si2 = debug_atomic_read(&softirqs_off_events),
  230. sr1 = debug_atomic_read(&redundant_softirqs_on),
  231. sr2 = debug_atomic_read(&redundant_softirqs_off);
  232. seq_printf(m, " chain lookup misses: %11u\n",
  233. debug_atomic_read(&chain_lookup_misses));
  234. seq_printf(m, " chain lookup hits: %11u\n",
  235. debug_atomic_read(&chain_lookup_hits));
  236. seq_printf(m, " cyclic checks: %11u\n",
  237. debug_atomic_read(&nr_cyclic_checks));
  238. seq_printf(m, " cyclic-check recursions: %11u\n",
  239. debug_atomic_read(&nr_cyclic_check_recursions));
  240. seq_printf(m, " find-mask forwards checks: %11u\n",
  241. debug_atomic_read(&nr_find_usage_forwards_checks));
  242. seq_printf(m, " find-mask forwards recursions: %11u\n",
  243. debug_atomic_read(&nr_find_usage_forwards_recursions));
  244. seq_printf(m, " find-mask backwards checks: %11u\n",
  245. debug_atomic_read(&nr_find_usage_backwards_checks));
  246. seq_printf(m, " find-mask backwards recursions:%11u\n",
  247. debug_atomic_read(&nr_find_usage_backwards_recursions));
  248. seq_printf(m, " hardirq on events: %11u\n", hi1);
  249. seq_printf(m, " hardirq off events: %11u\n", hi2);
  250. seq_printf(m, " redundant hardirq ons: %11u\n", hr1);
  251. seq_printf(m, " redundant hardirq offs: %11u\n", hr2);
  252. seq_printf(m, " softirq on events: %11u\n", si1);
  253. seq_printf(m, " softirq off events: %11u\n", si2);
  254. seq_printf(m, " redundant softirq ons: %11u\n", sr1);
  255. seq_printf(m, " redundant softirq offs: %11u\n", sr2);
  256. #endif
  257. }
  258. static int lockdep_stats_show(struct seq_file *m, void *v)
  259. {
  260. struct lock_class *class;
  261. unsigned long nr_unused = 0, nr_uncategorized = 0,
  262. nr_irq_safe = 0, nr_irq_unsafe = 0,
  263. nr_softirq_safe = 0, nr_softirq_unsafe = 0,
  264. nr_hardirq_safe = 0, nr_hardirq_unsafe = 0,
  265. nr_irq_read_safe = 0, nr_irq_read_unsafe = 0,
  266. nr_softirq_read_safe = 0, nr_softirq_read_unsafe = 0,
  267. nr_hardirq_read_safe = 0, nr_hardirq_read_unsafe = 0,
  268. sum_forward_deps = 0, factor = 0;
  269. list_for_each_entry(class, &all_lock_classes, lock_entry) {
  270. if (class->usage_mask == 0)
  271. nr_unused++;
  272. if (class->usage_mask == LOCKF_USED)
  273. nr_uncategorized++;
  274. if (class->usage_mask & LOCKF_USED_IN_IRQ)
  275. nr_irq_safe++;
  276. if (class->usage_mask & LOCKF_ENABLED_IRQS)
  277. nr_irq_unsafe++;
  278. if (class->usage_mask & LOCKF_USED_IN_SOFTIRQ)
  279. nr_softirq_safe++;
  280. if (class->usage_mask & LOCKF_ENABLED_SOFTIRQS)
  281. nr_softirq_unsafe++;
  282. if (class->usage_mask & LOCKF_USED_IN_HARDIRQ)
  283. nr_hardirq_safe++;
  284. if (class->usage_mask & LOCKF_ENABLED_HARDIRQS)
  285. nr_hardirq_unsafe++;
  286. if (class->usage_mask & LOCKF_USED_IN_IRQ_READ)
  287. nr_irq_read_safe++;
  288. if (class->usage_mask & LOCKF_ENABLED_IRQS_READ)
  289. nr_irq_read_unsafe++;
  290. if (class->usage_mask & LOCKF_USED_IN_SOFTIRQ_READ)
  291. nr_softirq_read_safe++;
  292. if (class->usage_mask & LOCKF_ENABLED_SOFTIRQS_READ)
  293. nr_softirq_read_unsafe++;
  294. if (class->usage_mask & LOCKF_USED_IN_HARDIRQ_READ)
  295. nr_hardirq_read_safe++;
  296. if (class->usage_mask & LOCKF_ENABLED_HARDIRQS_READ)
  297. nr_hardirq_read_unsafe++;
  298. sum_forward_deps += count_forward_deps(class);
  299. }
  300. #ifdef CONFIG_DEBUG_LOCKDEP
  301. DEBUG_LOCKS_WARN_ON(debug_atomic_read(&nr_unused_locks) != nr_unused);
  302. #endif
  303. seq_printf(m, " lock-classes: %11lu [max: %lu]\n",
  304. nr_lock_classes, MAX_LOCKDEP_KEYS);
  305. seq_printf(m, " direct dependencies: %11lu [max: %lu]\n",
  306. nr_list_entries, MAX_LOCKDEP_ENTRIES);
  307. seq_printf(m, " indirect dependencies: %11lu\n",
  308. sum_forward_deps);
  309. /*
  310. * Total number of dependencies:
  311. *
  312. * All irq-safe locks may nest inside irq-unsafe locks,
  313. * plus all the other known dependencies:
  314. */
  315. seq_printf(m, " all direct dependencies: %11lu\n",
  316. nr_irq_unsafe * nr_irq_safe +
  317. nr_hardirq_unsafe * nr_hardirq_safe +
  318. nr_list_entries);
  319. /*
  320. * Estimated factor between direct and indirect
  321. * dependencies:
  322. */
  323. if (nr_list_entries)
  324. factor = sum_forward_deps / nr_list_entries;
  325. #ifdef CONFIG_PROVE_LOCKING
  326. seq_printf(m, " dependency chains: %11lu [max: %lu]\n",
  327. nr_lock_chains, MAX_LOCKDEP_CHAINS);
  328. seq_printf(m, " dependency chain hlocks: %11d [max: %lu]\n",
  329. nr_chain_hlocks, MAX_LOCKDEP_CHAIN_HLOCKS);
  330. #endif
  331. #ifdef CONFIG_TRACE_IRQFLAGS
  332. seq_printf(m, " in-hardirq chains: %11u\n",
  333. nr_hardirq_chains);
  334. seq_printf(m, " in-softirq chains: %11u\n",
  335. nr_softirq_chains);
  336. #endif
  337. seq_printf(m, " in-process chains: %11u\n",
  338. nr_process_chains);
  339. seq_printf(m, " stack-trace entries: %11lu [max: %lu]\n",
  340. nr_stack_trace_entries, MAX_STACK_TRACE_ENTRIES);
  341. seq_printf(m, " combined max dependencies: %11u\n",
  342. (nr_hardirq_chains + 1) *
  343. (nr_softirq_chains + 1) *
  344. (nr_process_chains + 1)
  345. );
  346. seq_printf(m, " hardirq-safe locks: %11lu\n",
  347. nr_hardirq_safe);
  348. seq_printf(m, " hardirq-unsafe locks: %11lu\n",
  349. nr_hardirq_unsafe);
  350. seq_printf(m, " softirq-safe locks: %11lu\n",
  351. nr_softirq_safe);
  352. seq_printf(m, " softirq-unsafe locks: %11lu\n",
  353. nr_softirq_unsafe);
  354. seq_printf(m, " irq-safe locks: %11lu\n",
  355. nr_irq_safe);
  356. seq_printf(m, " irq-unsafe locks: %11lu\n",
  357. nr_irq_unsafe);
  358. seq_printf(m, " hardirq-read-safe locks: %11lu\n",
  359. nr_hardirq_read_safe);
  360. seq_printf(m, " hardirq-read-unsafe locks: %11lu\n",
  361. nr_hardirq_read_unsafe);
  362. seq_printf(m, " softirq-read-safe locks: %11lu\n",
  363. nr_softirq_read_safe);
  364. seq_printf(m, " softirq-read-unsafe locks: %11lu\n",
  365. nr_softirq_read_unsafe);
  366. seq_printf(m, " irq-read-safe locks: %11lu\n",
  367. nr_irq_read_safe);
  368. seq_printf(m, " irq-read-unsafe locks: %11lu\n",
  369. nr_irq_read_unsafe);
  370. seq_printf(m, " uncategorized locks: %11lu\n",
  371. nr_uncategorized);
  372. seq_printf(m, " unused locks: %11lu\n",
  373. nr_unused);
  374. seq_printf(m, " max locking depth: %11u\n",
  375. max_lockdep_depth);
  376. seq_printf(m, " max recursion depth: %11u\n",
  377. max_recursion_depth);
  378. lockdep_stats_debug_show(m);
  379. seq_printf(m, " debug_locks: %11u\n",
  380. debug_locks);
  381. return 0;
  382. }
  383. static int lockdep_stats_open(struct inode *inode, struct file *file)
  384. {
  385. return single_open(file, lockdep_stats_show, NULL);
  386. }
  387. static const struct file_operations proc_lockdep_stats_operations = {
  388. .open = lockdep_stats_open,
  389. .read = seq_read,
  390. .llseek = seq_lseek,
  391. .release = single_release,
  392. };
  393. #ifdef CONFIG_LOCK_STAT
  394. struct lock_stat_data {
  395. struct lock_class *class;
  396. struct lock_class_stats stats;
  397. };
  398. struct lock_stat_seq {
  399. struct lock_stat_data *iter;
  400. struct lock_stat_data *iter_end;
  401. struct lock_stat_data stats[MAX_LOCKDEP_KEYS];
  402. };
  403. /*
  404. * sort on absolute number of contentions
  405. */
  406. static int lock_stat_cmp(const void *l, const void *r)
  407. {
  408. const struct lock_stat_data *dl = l, *dr = r;
  409. unsigned long nl, nr;
  410. nl = dl->stats.read_waittime.nr + dl->stats.write_waittime.nr;
  411. nr = dr->stats.read_waittime.nr + dr->stats.write_waittime.nr;
  412. return nr - nl;
  413. }
  414. static void seq_line(struct seq_file *m, char c, int offset, int length)
  415. {
  416. int i;
  417. for (i = 0; i < offset; i++)
  418. seq_puts(m, " ");
  419. for (i = 0; i < length; i++)
  420. seq_printf(m, "%c", c);
  421. seq_puts(m, "\n");
  422. }
  423. static void snprint_time(char *buf, size_t bufsiz, s64 nr)
  424. {
  425. unsigned long rem;
  426. rem = do_div(nr, 1000); /* XXX: do_div_signed */
  427. snprintf(buf, bufsiz, "%lld.%02d", (long long)nr, ((int)rem+5)/10);
  428. }
  429. static void seq_time(struct seq_file *m, s64 time)
  430. {
  431. char num[15];
  432. snprint_time(num, sizeof(num), time);
  433. seq_printf(m, " %14s", num);
  434. }
  435. static void seq_lock_time(struct seq_file *m, struct lock_time *lt)
  436. {
  437. seq_printf(m, "%14lu", lt->nr);
  438. seq_time(m, lt->min);
  439. seq_time(m, lt->max);
  440. seq_time(m, lt->total);
  441. }
  442. static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
  443. {
  444. char name[39];
  445. struct lock_class *class;
  446. struct lock_class_stats *stats;
  447. int i, namelen;
  448. class = data->class;
  449. stats = &data->stats;
  450. namelen = 38;
  451. if (class->name_version > 1)
  452. namelen -= 2; /* XXX truncates versions > 9 */
  453. if (class->subclass)
  454. namelen -= 2;
  455. if (!class->name) {
  456. char str[KSYM_NAME_LEN];
  457. const char *key_name;
  458. key_name = __get_key_name(class->key, str);
  459. snprintf(name, namelen, "%s", key_name);
  460. } else {
  461. snprintf(name, namelen, "%s", class->name);
  462. }
  463. namelen = strlen(name);
  464. if (class->name_version > 1) {
  465. snprintf(name+namelen, 3, "#%d", class->name_version);
  466. namelen += 2;
  467. }
  468. if (class->subclass) {
  469. snprintf(name+namelen, 3, "/%d", class->subclass);
  470. namelen += 2;
  471. }
  472. if (stats->write_holdtime.nr) {
  473. if (stats->read_holdtime.nr)
  474. seq_printf(m, "%38s-W:", name);
  475. else
  476. seq_printf(m, "%40s:", name);
  477. seq_printf(m, "%14lu ", stats->bounces[bounce_contended_write]);
  478. seq_lock_time(m, &stats->write_waittime);
  479. seq_printf(m, " %14lu ", stats->bounces[bounce_acquired_write]);
  480. seq_lock_time(m, &stats->write_holdtime);
  481. seq_puts(m, "\n");
  482. }
  483. if (stats->read_holdtime.nr) {
  484. seq_printf(m, "%38s-R:", name);
  485. seq_printf(m, "%14lu ", stats->bounces[bounce_contended_read]);
  486. seq_lock_time(m, &stats->read_waittime);
  487. seq_printf(m, " %14lu ", stats->bounces[bounce_acquired_read]);
  488. seq_lock_time(m, &stats->read_holdtime);
  489. seq_puts(m, "\n");
  490. }
  491. if (stats->read_waittime.nr + stats->write_waittime.nr == 0)
  492. return;
  493. if (stats->read_holdtime.nr)
  494. namelen += 2;
  495. for (i = 0; i < ARRAY_SIZE(class->contention_point); i++) {
  496. char sym[KSYM_SYMBOL_LEN];
  497. char ip[32];
  498. if (class->contention_point[i] == 0)
  499. break;
  500. if (!i)
  501. seq_line(m, '-', 40-namelen, namelen);
  502. sprint_symbol(sym, class->contention_point[i]);
  503. snprintf(ip, sizeof(ip), "[<%p>]",
  504. (void *)class->contention_point[i]);
  505. seq_printf(m, "%40s %14lu %29s %s\n", name,
  506. stats->contention_point[i],
  507. ip, sym);
  508. }
  509. if (i) {
  510. seq_puts(m, "\n");
  511. seq_line(m, '.', 0, 40 + 1 + 10 * (14 + 1));
  512. seq_puts(m, "\n");
  513. }
  514. }
  515. static void seq_header(struct seq_file *m)
  516. {
  517. seq_printf(m, "lock_stat version 0.2\n");
  518. seq_line(m, '-', 0, 40 + 1 + 10 * (14 + 1));
  519. seq_printf(m, "%40s %14s %14s %14s %14s %14s %14s %14s %14s "
  520. "%14s %14s\n",
  521. "class name",
  522. "con-bounces",
  523. "contentions",
  524. "waittime-min",
  525. "waittime-max",
  526. "waittime-total",
  527. "acq-bounces",
  528. "acquisitions",
  529. "holdtime-min",
  530. "holdtime-max",
  531. "holdtime-total");
  532. seq_line(m, '-', 0, 40 + 1 + 10 * (14 + 1));
  533. seq_printf(m, "\n");
  534. }
  535. static void *ls_start(struct seq_file *m, loff_t *pos)
  536. {
  537. struct lock_stat_seq *data = m->private;
  538. if (*pos == 0)
  539. return SEQ_START_TOKEN;
  540. data->iter = data->stats + *pos;
  541. if (data->iter >= data->iter_end)
  542. data->iter = NULL;
  543. return data->iter;
  544. }
  545. static void *ls_next(struct seq_file *m, void *v, loff_t *pos)
  546. {
  547. struct lock_stat_seq *data = m->private;
  548. (*pos)++;
  549. if (v == SEQ_START_TOKEN)
  550. data->iter = data->stats;
  551. else {
  552. data->iter = v;
  553. data->iter++;
  554. }
  555. if (data->iter == data->iter_end)
  556. data->iter = NULL;
  557. return data->iter;
  558. }
  559. static void ls_stop(struct seq_file *m, void *v)
  560. {
  561. }
  562. static int ls_show(struct seq_file *m, void *v)
  563. {
  564. if (v == SEQ_START_TOKEN)
  565. seq_header(m);
  566. else
  567. seq_stats(m, v);
  568. return 0;
  569. }
  570. static struct seq_operations lockstat_ops = {
  571. .start = ls_start,
  572. .next = ls_next,
  573. .stop = ls_stop,
  574. .show = ls_show,
  575. };
  576. static int lock_stat_open(struct inode *inode, struct file *file)
  577. {
  578. int res;
  579. struct lock_class *class;
  580. struct lock_stat_seq *data = vmalloc(sizeof(struct lock_stat_seq));
  581. if (!data)
  582. return -ENOMEM;
  583. res = seq_open(file, &lockstat_ops);
  584. if (!res) {
  585. struct lock_stat_data *iter = data->stats;
  586. struct seq_file *m = file->private_data;
  587. data->iter = iter;
  588. list_for_each_entry(class, &all_lock_classes, lock_entry) {
  589. iter->class = class;
  590. iter->stats = lock_stats(class);
  591. iter++;
  592. }
  593. data->iter_end = iter;
  594. sort(data->stats, data->iter_end - data->iter,
  595. sizeof(struct lock_stat_data),
  596. lock_stat_cmp, NULL);
  597. m->private = data;
  598. } else
  599. vfree(data);
  600. return res;
  601. }
  602. static ssize_t lock_stat_write(struct file *file, const char __user *buf,
  603. size_t count, loff_t *ppos)
  604. {
  605. struct lock_class *class;
  606. char c;
  607. if (count) {
  608. if (get_user(c, buf))
  609. return -EFAULT;
  610. if (c != '0')
  611. return count;
  612. list_for_each_entry(class, &all_lock_classes, lock_entry)
  613. clear_lock_stats(class);
  614. }
  615. return count;
  616. }
  617. static int lock_stat_release(struct inode *inode, struct file *file)
  618. {
  619. struct seq_file *seq = file->private_data;
  620. vfree(seq->private);
  621. seq->private = NULL;
  622. return seq_release(inode, file);
  623. }
  624. static const struct file_operations proc_lock_stat_operations = {
  625. .open = lock_stat_open,
  626. .write = lock_stat_write,
  627. .read = seq_read,
  628. .llseek = seq_lseek,
  629. .release = lock_stat_release,
  630. };
  631. #endif /* CONFIG_LOCK_STAT */
  632. static int __init lockdep_proc_init(void)
  633. {
  634. proc_create("lockdep", S_IRUSR, NULL, &proc_lockdep_operations);
  635. #ifdef CONFIG_PROVE_LOCKING
  636. proc_create("lockdep_chains", S_IRUSR, NULL,
  637. &proc_lockdep_chains_operations);
  638. #endif
  639. proc_create("lockdep_stats", S_IRUSR, NULL,
  640. &proc_lockdep_stats_operations);
  641. #ifdef CONFIG_LOCK_STAT
  642. proc_create("lock_stat", S_IRUSR, NULL, &proc_lock_stat_operations);
  643. #endif
  644. return 0;
  645. }
  646. __initcall(lockdep_proc_init);