lockdep_proc.c 17 KB

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