lockdep_proc.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  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. nr += 5; /* for display rounding */
  408. rem = do_div(nr, 1000); /* XXX: do_div_signed */
  409. snprintf(buf, bufsiz, "%lld.%02d", (long long)nr, (int)rem/10);
  410. }
  411. static void seq_time(struct seq_file *m, s64 time)
  412. {
  413. char num[15];
  414. snprint_time(num, sizeof(num), time);
  415. seq_printf(m, " %14s", num);
  416. }
  417. static void seq_lock_time(struct seq_file *m, struct lock_time *lt)
  418. {
  419. seq_printf(m, "%14lu", lt->nr);
  420. seq_time(m, lt->min);
  421. seq_time(m, lt->max);
  422. seq_time(m, lt->total);
  423. }
  424. static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
  425. {
  426. char name[39];
  427. struct lock_class *class;
  428. struct lock_class_stats *stats;
  429. int i, namelen;
  430. class = data->class;
  431. stats = &data->stats;
  432. namelen = 38;
  433. if (class->name_version > 1)
  434. namelen -= 2; /* XXX truncates versions > 9 */
  435. if (class->subclass)
  436. namelen -= 2;
  437. if (!class->name) {
  438. char str[KSYM_NAME_LEN];
  439. const char *key_name;
  440. key_name = __get_key_name(class->key, str);
  441. snprintf(name, namelen, "%s", key_name);
  442. } else {
  443. snprintf(name, namelen, "%s", class->name);
  444. }
  445. namelen = strlen(name);
  446. if (class->name_version > 1) {
  447. snprintf(name+namelen, 3, "#%d", class->name_version);
  448. namelen += 2;
  449. }
  450. if (class->subclass) {
  451. snprintf(name+namelen, 3, "/%d", class->subclass);
  452. namelen += 2;
  453. }
  454. if (stats->write_holdtime.nr) {
  455. if (stats->read_holdtime.nr)
  456. seq_printf(m, "%38s-W:", name);
  457. else
  458. seq_printf(m, "%40s:", name);
  459. seq_printf(m, "%14lu ", stats->bounces[bounce_contended_write]);
  460. seq_lock_time(m, &stats->write_waittime);
  461. seq_printf(m, " %14lu ", stats->bounces[bounce_acquired_write]);
  462. seq_lock_time(m, &stats->write_holdtime);
  463. seq_puts(m, "\n");
  464. }
  465. if (stats->read_holdtime.nr) {
  466. seq_printf(m, "%38s-R:", name);
  467. seq_printf(m, "%14lu ", stats->bounces[bounce_contended_read]);
  468. seq_lock_time(m, &stats->read_waittime);
  469. seq_printf(m, " %14lu ", stats->bounces[bounce_acquired_read]);
  470. seq_lock_time(m, &stats->read_holdtime);
  471. seq_puts(m, "\n");
  472. }
  473. if (stats->read_waittime.nr + stats->write_waittime.nr == 0)
  474. return;
  475. if (stats->read_holdtime.nr)
  476. namelen += 2;
  477. for (i = 0; i < ARRAY_SIZE(class->contention_point); i++) {
  478. char sym[KSYM_SYMBOL_LEN];
  479. char ip[32];
  480. if (class->contention_point[i] == 0)
  481. break;
  482. if (!i)
  483. seq_line(m, '-', 40-namelen, namelen);
  484. sprint_symbol(sym, class->contention_point[i]);
  485. snprintf(ip, sizeof(ip), "[<%p>]",
  486. (void *)class->contention_point[i]);
  487. seq_printf(m, "%40s %14lu %29s %s\n", name,
  488. stats->contention_point[i],
  489. ip, sym);
  490. }
  491. if (i) {
  492. seq_puts(m, "\n");
  493. seq_line(m, '.', 0, 40 + 1 + 10 * (14 + 1));
  494. seq_puts(m, "\n");
  495. }
  496. }
  497. static void seq_header(struct seq_file *m)
  498. {
  499. seq_printf(m, "lock_stat version 0.2\n");
  500. seq_line(m, '-', 0, 40 + 1 + 10 * (14 + 1));
  501. seq_printf(m, "%40s %14s %14s %14s %14s %14s %14s %14s %14s "
  502. "%14s %14s\n",
  503. "class name",
  504. "con-bounces",
  505. "contentions",
  506. "waittime-min",
  507. "waittime-max",
  508. "waittime-total",
  509. "acq-bounces",
  510. "acquisitions",
  511. "holdtime-min",
  512. "holdtime-max",
  513. "holdtime-total");
  514. seq_line(m, '-', 0, 40 + 1 + 10 * (14 + 1));
  515. seq_printf(m, "\n");
  516. }
  517. static void *ls_start(struct seq_file *m, loff_t *pos)
  518. {
  519. struct lock_stat_seq *data = m->private;
  520. if (*pos == 0)
  521. return SEQ_START_TOKEN;
  522. data->iter = data->stats + *pos;
  523. if (data->iter >= data->iter_end)
  524. data->iter = NULL;
  525. return data->iter;
  526. }
  527. static void *ls_next(struct seq_file *m, void *v, loff_t *pos)
  528. {
  529. struct lock_stat_seq *data = m->private;
  530. (*pos)++;
  531. if (v == SEQ_START_TOKEN)
  532. data->iter = data->stats;
  533. else {
  534. data->iter = v;
  535. data->iter++;
  536. }
  537. if (data->iter == data->iter_end)
  538. data->iter = NULL;
  539. return data->iter;
  540. }
  541. static void ls_stop(struct seq_file *m, void *v)
  542. {
  543. }
  544. static int ls_show(struct seq_file *m, void *v)
  545. {
  546. if (v == SEQ_START_TOKEN)
  547. seq_header(m);
  548. else
  549. seq_stats(m, v);
  550. return 0;
  551. }
  552. static struct seq_operations lockstat_ops = {
  553. .start = ls_start,
  554. .next = ls_next,
  555. .stop = ls_stop,
  556. .show = ls_show,
  557. };
  558. static int lock_stat_open(struct inode *inode, struct file *file)
  559. {
  560. int res;
  561. struct lock_class *class;
  562. struct lock_stat_seq *data = vmalloc(sizeof(struct lock_stat_seq));
  563. if (!data)
  564. return -ENOMEM;
  565. res = seq_open(file, &lockstat_ops);
  566. if (!res) {
  567. struct lock_stat_data *iter = data->stats;
  568. struct seq_file *m = file->private_data;
  569. data->iter = iter;
  570. list_for_each_entry(class, &all_lock_classes, lock_entry) {
  571. iter->class = class;
  572. iter->stats = lock_stats(class);
  573. iter++;
  574. }
  575. data->iter_end = iter;
  576. sort(data->stats, data->iter_end - data->iter,
  577. sizeof(struct lock_stat_data),
  578. lock_stat_cmp, NULL);
  579. m->private = data;
  580. } else
  581. vfree(data);
  582. return res;
  583. }
  584. static ssize_t lock_stat_write(struct file *file, const char __user *buf,
  585. size_t count, loff_t *ppos)
  586. {
  587. struct lock_class *class;
  588. char c;
  589. if (count) {
  590. if (get_user(c, buf))
  591. return -EFAULT;
  592. if (c != '0')
  593. return count;
  594. list_for_each_entry(class, &all_lock_classes, lock_entry)
  595. clear_lock_stats(class);
  596. }
  597. return count;
  598. }
  599. static int lock_stat_release(struct inode *inode, struct file *file)
  600. {
  601. struct seq_file *seq = file->private_data;
  602. vfree(seq->private);
  603. seq->private = NULL;
  604. return seq_release(inode, file);
  605. }
  606. static const struct file_operations proc_lock_stat_operations = {
  607. .open = lock_stat_open,
  608. .write = lock_stat_write,
  609. .read = seq_read,
  610. .llseek = seq_lseek,
  611. .release = lock_stat_release,
  612. };
  613. #endif /* CONFIG_LOCK_STAT */
  614. static int __init lockdep_proc_init(void)
  615. {
  616. proc_create("lockdep", S_IRUSR, NULL, &proc_lockdep_operations);
  617. #ifdef CONFIG_PROVE_LOCKING
  618. proc_create("lockdep_chains", S_IRUSR, NULL,
  619. &proc_lockdep_chains_operations);
  620. #endif
  621. proc_create("lockdep_stats", S_IRUSR, NULL,
  622. &proc_lockdep_stats_operations);
  623. #ifdef CONFIG_LOCK_STAT
  624. proc_create("lock_stat", S_IRUSR, NULL, &proc_lock_stat_operations);
  625. #endif
  626. return 0;
  627. }
  628. __initcall(lockdep_proc_init);