lockdep_proc.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  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. 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[128];
  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. }
  367. static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
  368. {
  369. char name[39];
  370. struct lock_class *class;
  371. struct lock_class_stats *stats;
  372. int i, namelen;
  373. class = data->class;
  374. stats = &data->stats;
  375. namelen = 38;
  376. if (class->name_version > 1)
  377. namelen -= 2; /* XXX truncates versions > 9 */
  378. if (class->subclass)
  379. namelen -= 2;
  380. if (!class->name) {
  381. char str[KSYM_NAME_LEN];
  382. const char *key_name;
  383. key_name = __get_key_name(class->key, str);
  384. snprintf(name, namelen, "%s", key_name);
  385. } else {
  386. snprintf(name, namelen, "%s", class->name);
  387. }
  388. namelen = strlen(name);
  389. if (class->name_version > 1) {
  390. snprintf(name+namelen, 3, "#%d", class->name_version);
  391. namelen += 2;
  392. }
  393. if (class->subclass) {
  394. snprintf(name+namelen, 3, "/%d", class->subclass);
  395. namelen += 2;
  396. }
  397. if (stats->write_holdtime.nr) {
  398. if (stats->read_holdtime.nr)
  399. seq_printf(m, "%38s-W:", name);
  400. else
  401. seq_printf(m, "%40s:", name);
  402. seq_printf(m, "%14lu ", stats->bounces[bounce_contended_write]);
  403. seq_lock_time(m, &stats->write_waittime);
  404. seq_printf(m, " %14lu ", stats->bounces[bounce_acquired_write]);
  405. seq_lock_time(m, &stats->write_holdtime);
  406. seq_puts(m, "\n");
  407. }
  408. if (stats->read_holdtime.nr) {
  409. seq_printf(m, "%38s-R:", name);
  410. seq_printf(m, "%14lu ", stats->bounces[bounce_contended_read]);
  411. seq_lock_time(m, &stats->read_waittime);
  412. seq_printf(m, " %14lu ", stats->bounces[bounce_acquired_read]);
  413. seq_lock_time(m, &stats->read_holdtime);
  414. seq_puts(m, "\n");
  415. }
  416. if (stats->read_waittime.nr + stats->write_waittime.nr == 0)
  417. return;
  418. if (stats->read_holdtime.nr)
  419. namelen += 2;
  420. for (i = 0; i < LOCKSTAT_POINTS; i++) {
  421. char ip[32];
  422. if (class->contention_point[i] == 0)
  423. break;
  424. if (!i)
  425. seq_line(m, '-', 40-namelen, namelen);
  426. snprintf(ip, sizeof(ip), "[<%p>]",
  427. (void *)class->contention_point[i]);
  428. seq_printf(m, "%40s %14lu %29s %pS\n",
  429. name, stats->contention_point[i],
  430. ip, (void *)class->contention_point[i]);
  431. }
  432. for (i = 0; i < LOCKSTAT_POINTS; i++) {
  433. char ip[32];
  434. if (class->contending_point[i] == 0)
  435. break;
  436. if (!i)
  437. seq_line(m, '-', 40-namelen, namelen);
  438. snprintf(ip, sizeof(ip), "[<%p>]",
  439. (void *)class->contending_point[i]);
  440. seq_printf(m, "%40s %14lu %29s %pS\n",
  441. name, stats->contending_point[i],
  442. ip, (void *)class->contending_point[i]);
  443. }
  444. if (i) {
  445. seq_puts(m, "\n");
  446. seq_line(m, '.', 0, 40 + 1 + 10 * (14 + 1));
  447. seq_puts(m, "\n");
  448. }
  449. }
  450. static void seq_header(struct seq_file *m)
  451. {
  452. seq_printf(m, "lock_stat version 0.3\n");
  453. if (unlikely(!debug_locks))
  454. seq_printf(m, "*WARNING* lock debugging disabled!! - possibly due to a lockdep warning\n");
  455. seq_line(m, '-', 0, 40 + 1 + 10 * (14 + 1));
  456. seq_printf(m, "%40s %14s %14s %14s %14s %14s %14s %14s %14s "
  457. "%14s %14s\n",
  458. "class name",
  459. "con-bounces",
  460. "contentions",
  461. "waittime-min",
  462. "waittime-max",
  463. "waittime-total",
  464. "acq-bounces",
  465. "acquisitions",
  466. "holdtime-min",
  467. "holdtime-max",
  468. "holdtime-total");
  469. seq_line(m, '-', 0, 40 + 1 + 10 * (14 + 1));
  470. seq_printf(m, "\n");
  471. }
  472. static void *ls_start(struct seq_file *m, loff_t *pos)
  473. {
  474. struct lock_stat_seq *data = m->private;
  475. struct lock_stat_data *iter;
  476. if (*pos == 0)
  477. return SEQ_START_TOKEN;
  478. iter = data->stats + (*pos - 1);
  479. if (iter >= data->iter_end)
  480. iter = NULL;
  481. return iter;
  482. }
  483. static void *ls_next(struct seq_file *m, void *v, loff_t *pos)
  484. {
  485. (*pos)++;
  486. return ls_start(m, pos);
  487. }
  488. static void ls_stop(struct seq_file *m, void *v)
  489. {
  490. }
  491. static int ls_show(struct seq_file *m, void *v)
  492. {
  493. if (v == SEQ_START_TOKEN)
  494. seq_header(m);
  495. else
  496. seq_stats(m, v);
  497. return 0;
  498. }
  499. static const struct seq_operations lockstat_ops = {
  500. .start = ls_start,
  501. .next = ls_next,
  502. .stop = ls_stop,
  503. .show = ls_show,
  504. };
  505. static int lock_stat_open(struct inode *inode, struct file *file)
  506. {
  507. int res;
  508. struct lock_class *class;
  509. struct lock_stat_seq *data = vmalloc(sizeof(struct lock_stat_seq));
  510. if (!data)
  511. return -ENOMEM;
  512. res = seq_open(file, &lockstat_ops);
  513. if (!res) {
  514. struct lock_stat_data *iter = data->stats;
  515. struct seq_file *m = file->private_data;
  516. list_for_each_entry(class, &all_lock_classes, lock_entry) {
  517. iter->class = class;
  518. iter->stats = lock_stats(class);
  519. iter++;
  520. }
  521. data->iter_end = iter;
  522. sort(data->stats, data->iter_end - data->stats,
  523. sizeof(struct lock_stat_data),
  524. lock_stat_cmp, NULL);
  525. m->private = data;
  526. } else
  527. vfree(data);
  528. return res;
  529. }
  530. static ssize_t lock_stat_write(struct file *file, const char __user *buf,
  531. size_t count, loff_t *ppos)
  532. {
  533. struct lock_class *class;
  534. char c;
  535. if (count) {
  536. if (get_user(c, buf))
  537. return -EFAULT;
  538. if (c != '0')
  539. return count;
  540. list_for_each_entry(class, &all_lock_classes, lock_entry)
  541. clear_lock_stats(class);
  542. }
  543. return count;
  544. }
  545. static int lock_stat_release(struct inode *inode, struct file *file)
  546. {
  547. struct seq_file *seq = file->private_data;
  548. vfree(seq->private);
  549. return seq_release(inode, file);
  550. }
  551. static const struct file_operations proc_lock_stat_operations = {
  552. .open = lock_stat_open,
  553. .write = lock_stat_write,
  554. .read = seq_read,
  555. .llseek = seq_lseek,
  556. .release = lock_stat_release,
  557. };
  558. #endif /* CONFIG_LOCK_STAT */
  559. static int __init lockdep_proc_init(void)
  560. {
  561. proc_create("lockdep", S_IRUSR, NULL, &proc_lockdep_operations);
  562. #ifdef CONFIG_PROVE_LOCKING
  563. proc_create("lockdep_chains", S_IRUSR, NULL,
  564. &proc_lockdep_chains_operations);
  565. #endif
  566. proc_create("lockdep_stats", S_IRUSR, NULL,
  567. &proc_lockdep_stats_operations);
  568. #ifdef CONFIG_LOCK_STAT
  569. proc_create("lock_stat", S_IRUSR | S_IWUSR, NULL,
  570. &proc_lock_stat_operations);
  571. #endif
  572. return 0;
  573. }
  574. __initcall(lockdep_proc_init);