lockdep_proc.c 19 KB

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