ia64/linux-2.6.18-xen.hg

diff kernel/lockdep_proc.c @ 0:831230e53067

Import 2.6.18 from kernel.org tarball.
author Ian Campbell <ian.campbell@xensource.com>
date Wed Apr 11 14:15:44 2007 +0100 (2007-04-11)
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/kernel/lockdep_proc.c	Wed Apr 11 14:15:44 2007 +0100
     1.3 @@ -0,0 +1,345 @@
     1.4 +/*
     1.5 + * kernel/lockdep_proc.c
     1.6 + *
     1.7 + * Runtime locking correctness validator
     1.8 + *
     1.9 + * Started by Ingo Molnar:
    1.10 + *
    1.11 + *  Copyright (C) 2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
    1.12 + *
    1.13 + * Code for /proc/lockdep and /proc/lockdep_stats:
    1.14 + *
    1.15 + */
    1.16 +#include <linux/sched.h>
    1.17 +#include <linux/module.h>
    1.18 +#include <linux/proc_fs.h>
    1.19 +#include <linux/seq_file.h>
    1.20 +#include <linux/kallsyms.h>
    1.21 +#include <linux/debug_locks.h>
    1.22 +
    1.23 +#include "lockdep_internals.h"
    1.24 +
    1.25 +static void *l_next(struct seq_file *m, void *v, loff_t *pos)
    1.26 +{
    1.27 +	struct lock_class *class = v;
    1.28 +
    1.29 +	(*pos)++;
    1.30 +
    1.31 +	if (class->lock_entry.next != &all_lock_classes)
    1.32 +		class = list_entry(class->lock_entry.next, struct lock_class,
    1.33 +				  lock_entry);
    1.34 +	else
    1.35 +		class = NULL;
    1.36 +	m->private = class;
    1.37 +
    1.38 +	return class;
    1.39 +}
    1.40 +
    1.41 +static void *l_start(struct seq_file *m, loff_t *pos)
    1.42 +{
    1.43 +	struct lock_class *class = m->private;
    1.44 +
    1.45 +	if (&class->lock_entry == all_lock_classes.next)
    1.46 +		seq_printf(m, "all lock classes:\n");
    1.47 +
    1.48 +	return class;
    1.49 +}
    1.50 +
    1.51 +static void l_stop(struct seq_file *m, void *v)
    1.52 +{
    1.53 +}
    1.54 +
    1.55 +static unsigned long count_forward_deps(struct lock_class *class)
    1.56 +{
    1.57 +	struct lock_list *entry;
    1.58 +	unsigned long ret = 1;
    1.59 +
    1.60 +	/*
    1.61 +	 * Recurse this class's dependency list:
    1.62 +	 */
    1.63 +	list_for_each_entry(entry, &class->locks_after, entry)
    1.64 +		ret += count_forward_deps(entry->class);
    1.65 +
    1.66 +	return ret;
    1.67 +}
    1.68 +
    1.69 +static unsigned long count_backward_deps(struct lock_class *class)
    1.70 +{
    1.71 +	struct lock_list *entry;
    1.72 +	unsigned long ret = 1;
    1.73 +
    1.74 +	/*
    1.75 +	 * Recurse this class's dependency list:
    1.76 +	 */
    1.77 +	list_for_each_entry(entry, &class->locks_before, entry)
    1.78 +		ret += count_backward_deps(entry->class);
    1.79 +
    1.80 +	return ret;
    1.81 +}
    1.82 +
    1.83 +static int l_show(struct seq_file *m, void *v)
    1.84 +{
    1.85 +	unsigned long nr_forward_deps, nr_backward_deps;
    1.86 +	struct lock_class *class = m->private;
    1.87 +	char str[128], c1, c2, c3, c4;
    1.88 +	const char *name;
    1.89 +
    1.90 +	seq_printf(m, "%p", class->key);
    1.91 +#ifdef CONFIG_DEBUG_LOCKDEP
    1.92 +	seq_printf(m, " OPS:%8ld", class->ops);
    1.93 +#endif
    1.94 +	nr_forward_deps = count_forward_deps(class);
    1.95 +	seq_printf(m, " FD:%5ld", nr_forward_deps);
    1.96 +
    1.97 +	nr_backward_deps = count_backward_deps(class);
    1.98 +	seq_printf(m, " BD:%5ld", nr_backward_deps);
    1.99 +
   1.100 +	get_usage_chars(class, &c1, &c2, &c3, &c4);
   1.101 +	seq_printf(m, " %c%c%c%c", c1, c2, c3, c4);
   1.102 +
   1.103 +	name = class->name;
   1.104 +	if (!name) {
   1.105 +		name = __get_key_name(class->key, str);
   1.106 +		seq_printf(m, ": %s", name);
   1.107 +	} else{
   1.108 +		seq_printf(m, ": %s", name);
   1.109 +		if (class->name_version > 1)
   1.110 +			seq_printf(m, "#%d", class->name_version);
   1.111 +		if (class->subclass)
   1.112 +			seq_printf(m, "/%d", class->subclass);
   1.113 +	}
   1.114 +	seq_puts(m, "\n");
   1.115 +
   1.116 +	return 0;
   1.117 +}
   1.118 +
   1.119 +static struct seq_operations lockdep_ops = {
   1.120 +	.start	= l_start,
   1.121 +	.next	= l_next,
   1.122 +	.stop	= l_stop,
   1.123 +	.show	= l_show,
   1.124 +};
   1.125 +
   1.126 +static int lockdep_open(struct inode *inode, struct file *file)
   1.127 +{
   1.128 +	int res = seq_open(file, &lockdep_ops);
   1.129 +	if (!res) {
   1.130 +		struct seq_file *m = file->private_data;
   1.131 +
   1.132 +		if (!list_empty(&all_lock_classes))
   1.133 +			m->private = list_entry(all_lock_classes.next,
   1.134 +					struct lock_class, lock_entry);
   1.135 +		else
   1.136 +			m->private = NULL;
   1.137 +	}
   1.138 +	return res;
   1.139 +}
   1.140 +
   1.141 +static struct file_operations proc_lockdep_operations = {
   1.142 +	.open		= lockdep_open,
   1.143 +	.read		= seq_read,
   1.144 +	.llseek		= seq_lseek,
   1.145 +	.release	= seq_release,
   1.146 +};
   1.147 +
   1.148 +static void lockdep_stats_debug_show(struct seq_file *m)
   1.149 +{
   1.150 +#ifdef CONFIG_DEBUG_LOCKDEP
   1.151 +	unsigned int hi1 = debug_atomic_read(&hardirqs_on_events),
   1.152 +		     hi2 = debug_atomic_read(&hardirqs_off_events),
   1.153 +		     hr1 = debug_atomic_read(&redundant_hardirqs_on),
   1.154 +		     hr2 = debug_atomic_read(&redundant_hardirqs_off),
   1.155 +		     si1 = debug_atomic_read(&softirqs_on_events),
   1.156 +		     si2 = debug_atomic_read(&softirqs_off_events),
   1.157 +		     sr1 = debug_atomic_read(&redundant_softirqs_on),
   1.158 +		     sr2 = debug_atomic_read(&redundant_softirqs_off);
   1.159 +
   1.160 +	seq_printf(m, " chain lookup misses:           %11u\n",
   1.161 +		debug_atomic_read(&chain_lookup_misses));
   1.162 +	seq_printf(m, " chain lookup hits:             %11u\n",
   1.163 +		debug_atomic_read(&chain_lookup_hits));
   1.164 +	seq_printf(m, " cyclic checks:                 %11u\n",
   1.165 +		debug_atomic_read(&nr_cyclic_checks));
   1.166 +	seq_printf(m, " cyclic-check recursions:       %11u\n",
   1.167 +		debug_atomic_read(&nr_cyclic_check_recursions));
   1.168 +	seq_printf(m, " find-mask forwards checks:     %11u\n",
   1.169 +		debug_atomic_read(&nr_find_usage_forwards_checks));
   1.170 +	seq_printf(m, " find-mask forwards recursions: %11u\n",
   1.171 +		debug_atomic_read(&nr_find_usage_forwards_recursions));
   1.172 +	seq_printf(m, " find-mask backwards checks:    %11u\n",
   1.173 +		debug_atomic_read(&nr_find_usage_backwards_checks));
   1.174 +	seq_printf(m, " find-mask backwards recursions:%11u\n",
   1.175 +		debug_atomic_read(&nr_find_usage_backwards_recursions));
   1.176 +
   1.177 +	seq_printf(m, " hardirq on events:             %11u\n", hi1);
   1.178 +	seq_printf(m, " hardirq off events:            %11u\n", hi2);
   1.179 +	seq_printf(m, " redundant hardirq ons:         %11u\n", hr1);
   1.180 +	seq_printf(m, " redundant hardirq offs:        %11u\n", hr2);
   1.181 +	seq_printf(m, " softirq on events:             %11u\n", si1);
   1.182 +	seq_printf(m, " softirq off events:            %11u\n", si2);
   1.183 +	seq_printf(m, " redundant softirq ons:         %11u\n", sr1);
   1.184 +	seq_printf(m, " redundant softirq offs:        %11u\n", sr2);
   1.185 +#endif
   1.186 +}
   1.187 +
   1.188 +static int lockdep_stats_show(struct seq_file *m, void *v)
   1.189 +{
   1.190 +	struct lock_class *class;
   1.191 +	unsigned long nr_unused = 0, nr_uncategorized = 0,
   1.192 +		      nr_irq_safe = 0, nr_irq_unsafe = 0,
   1.193 +		      nr_softirq_safe = 0, nr_softirq_unsafe = 0,
   1.194 +		      nr_hardirq_safe = 0, nr_hardirq_unsafe = 0,
   1.195 +		      nr_irq_read_safe = 0, nr_irq_read_unsafe = 0,
   1.196 +		      nr_softirq_read_safe = 0, nr_softirq_read_unsafe = 0,
   1.197 +		      nr_hardirq_read_safe = 0, nr_hardirq_read_unsafe = 0,
   1.198 +		      sum_forward_deps = 0, factor = 0;
   1.199 +
   1.200 +	list_for_each_entry(class, &all_lock_classes, lock_entry) {
   1.201 +
   1.202 +		if (class->usage_mask == 0)
   1.203 +			nr_unused++;
   1.204 +		if (class->usage_mask == LOCKF_USED)
   1.205 +			nr_uncategorized++;
   1.206 +		if (class->usage_mask & LOCKF_USED_IN_IRQ)
   1.207 +			nr_irq_safe++;
   1.208 +		if (class->usage_mask & LOCKF_ENABLED_IRQS)
   1.209 +			nr_irq_unsafe++;
   1.210 +		if (class->usage_mask & LOCKF_USED_IN_SOFTIRQ)
   1.211 +			nr_softirq_safe++;
   1.212 +		if (class->usage_mask & LOCKF_ENABLED_SOFTIRQS)
   1.213 +			nr_softirq_unsafe++;
   1.214 +		if (class->usage_mask & LOCKF_USED_IN_HARDIRQ)
   1.215 +			nr_hardirq_safe++;
   1.216 +		if (class->usage_mask & LOCKF_ENABLED_HARDIRQS)
   1.217 +			nr_hardirq_unsafe++;
   1.218 +		if (class->usage_mask & LOCKF_USED_IN_IRQ_READ)
   1.219 +			nr_irq_read_safe++;
   1.220 +		if (class->usage_mask & LOCKF_ENABLED_IRQS_READ)
   1.221 +			nr_irq_read_unsafe++;
   1.222 +		if (class->usage_mask & LOCKF_USED_IN_SOFTIRQ_READ)
   1.223 +			nr_softirq_read_safe++;
   1.224 +		if (class->usage_mask & LOCKF_ENABLED_SOFTIRQS_READ)
   1.225 +			nr_softirq_read_unsafe++;
   1.226 +		if (class->usage_mask & LOCKF_USED_IN_HARDIRQ_READ)
   1.227 +			nr_hardirq_read_safe++;
   1.228 +		if (class->usage_mask & LOCKF_ENABLED_HARDIRQS_READ)
   1.229 +			nr_hardirq_read_unsafe++;
   1.230 +
   1.231 +		sum_forward_deps += count_forward_deps(class);
   1.232 +	}
   1.233 +#ifdef CONFIG_LOCKDEP_DEBUG
   1.234 +	DEBUG_LOCKS_WARN_ON(debug_atomic_read(&nr_unused_locks) != nr_unused);
   1.235 +#endif
   1.236 +	seq_printf(m, " lock-classes:                  %11lu [max: %lu]\n",
   1.237 +			nr_lock_classes, MAX_LOCKDEP_KEYS);
   1.238 +	seq_printf(m, " direct dependencies:           %11lu [max: %lu]\n",
   1.239 +			nr_list_entries, MAX_LOCKDEP_ENTRIES);
   1.240 +	seq_printf(m, " indirect dependencies:         %11lu\n",
   1.241 +			sum_forward_deps);
   1.242 +
   1.243 +	/*
   1.244 +	 * Total number of dependencies:
   1.245 +	 *
   1.246 +	 * All irq-safe locks may nest inside irq-unsafe locks,
   1.247 +	 * plus all the other known dependencies:
   1.248 +	 */
   1.249 +	seq_printf(m, " all direct dependencies:       %11lu\n",
   1.250 +			nr_irq_unsafe * nr_irq_safe +
   1.251 +			nr_hardirq_unsafe * nr_hardirq_safe +
   1.252 +			nr_list_entries);
   1.253 +
   1.254 +	/*
   1.255 +	 * Estimated factor between direct and indirect
   1.256 +	 * dependencies:
   1.257 +	 */
   1.258 +	if (nr_list_entries)
   1.259 +		factor = sum_forward_deps / nr_list_entries;
   1.260 +
   1.261 +	seq_printf(m, " dependency chains:             %11lu [max: %lu]\n",
   1.262 +			nr_lock_chains, MAX_LOCKDEP_CHAINS);
   1.263 +
   1.264 +#ifdef CONFIG_TRACE_IRQFLAGS
   1.265 +	seq_printf(m, " in-hardirq chains:             %11u\n",
   1.266 +			nr_hardirq_chains);
   1.267 +	seq_printf(m, " in-softirq chains:             %11u\n",
   1.268 +			nr_softirq_chains);
   1.269 +#endif
   1.270 +	seq_printf(m, " in-process chains:             %11u\n",
   1.271 +			nr_process_chains);
   1.272 +	seq_printf(m, " stack-trace entries:           %11lu [max: %lu]\n",
   1.273 +			nr_stack_trace_entries, MAX_STACK_TRACE_ENTRIES);
   1.274 +	seq_printf(m, " combined max dependencies:     %11u\n",
   1.275 +			(nr_hardirq_chains + 1) *
   1.276 +			(nr_softirq_chains + 1) *
   1.277 +			(nr_process_chains + 1)
   1.278 +	);
   1.279 +	seq_printf(m, " hardirq-safe locks:            %11lu\n",
   1.280 +			nr_hardirq_safe);
   1.281 +	seq_printf(m, " hardirq-unsafe locks:          %11lu\n",
   1.282 +			nr_hardirq_unsafe);
   1.283 +	seq_printf(m, " softirq-safe locks:            %11lu\n",
   1.284 +			nr_softirq_safe);
   1.285 +	seq_printf(m, " softirq-unsafe locks:          %11lu\n",
   1.286 +			nr_softirq_unsafe);
   1.287 +	seq_printf(m, " irq-safe locks:                %11lu\n",
   1.288 +			nr_irq_safe);
   1.289 +	seq_printf(m, " irq-unsafe locks:              %11lu\n",
   1.290 +			nr_irq_unsafe);
   1.291 +
   1.292 +	seq_printf(m, " hardirq-read-safe locks:       %11lu\n",
   1.293 +			nr_hardirq_read_safe);
   1.294 +	seq_printf(m, " hardirq-read-unsafe locks:     %11lu\n",
   1.295 +			nr_hardirq_read_unsafe);
   1.296 +	seq_printf(m, " softirq-read-safe locks:       %11lu\n",
   1.297 +			nr_softirq_read_safe);
   1.298 +	seq_printf(m, " softirq-read-unsafe locks:     %11lu\n",
   1.299 +			nr_softirq_read_unsafe);
   1.300 +	seq_printf(m, " irq-read-safe locks:           %11lu\n",
   1.301 +			nr_irq_read_safe);
   1.302 +	seq_printf(m, " irq-read-unsafe locks:         %11lu\n",
   1.303 +			nr_irq_read_unsafe);
   1.304 +
   1.305 +	seq_printf(m, " uncategorized locks:           %11lu\n",
   1.306 +			nr_uncategorized);
   1.307 +	seq_printf(m, " unused locks:                  %11lu\n",
   1.308 +			nr_unused);
   1.309 +	seq_printf(m, " max locking depth:             %11u\n",
   1.310 +			max_lockdep_depth);
   1.311 +	seq_printf(m, " max recursion depth:           %11u\n",
   1.312 +			max_recursion_depth);
   1.313 +	lockdep_stats_debug_show(m);
   1.314 +	seq_printf(m, " debug_locks:                   %11u\n",
   1.315 +			debug_locks);
   1.316 +
   1.317 +	return 0;
   1.318 +}
   1.319 +
   1.320 +static int lockdep_stats_open(struct inode *inode, struct file *file)
   1.321 +{
   1.322 +	return single_open(file, lockdep_stats_show, NULL);
   1.323 +}
   1.324 +
   1.325 +static struct file_operations proc_lockdep_stats_operations = {
   1.326 +	.open		= lockdep_stats_open,
   1.327 +	.read		= seq_read,
   1.328 +	.llseek		= seq_lseek,
   1.329 +	.release	= seq_release,
   1.330 +};
   1.331 +
   1.332 +static int __init lockdep_proc_init(void)
   1.333 +{
   1.334 +	struct proc_dir_entry *entry;
   1.335 +
   1.336 +	entry = create_proc_entry("lockdep", S_IRUSR, NULL);
   1.337 +	if (entry)
   1.338 +		entry->proc_fops = &proc_lockdep_operations;
   1.339 +
   1.340 +	entry = create_proc_entry("lockdep_stats", S_IRUSR, NULL);
   1.341 +	if (entry)
   1.342 +		entry->proc_fops = &proc_lockdep_stats_operations;
   1.343 +
   1.344 +	return 0;
   1.345 +}
   1.346 +
   1.347 +__initcall(lockdep_proc_init);
   1.348 +