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