lockdep_proc.c 19 KB

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