lockdep_proc.c 18 KB

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