Commit ef681026 authored by Ming Lei's avatar Ming Lei Committed by Peter Zijlstra
Browse files

lockdep: Implement lockdep_count_*ward_deps by BFS



Implement lockdep_count_{for,back}ward using BFS.

Signed-off-by: default avatarMing Lei <tom.leiming@gmail.com>
Signed-off-by: default avatarPeter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <1246201486-7308-8-git-send-email-tom.leiming@gmail.com>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 24208ca7
Loading
Loading
Loading
Loading
+25 −27
Original line number Original line Diff line number Diff line
@@ -1115,61 +1115,59 @@ static noinline int print_bfs_bug(int ret)
	return 0;
	return 0;
}
}


unsigned long __lockdep_count_forward_deps(struct lock_class *class,
static int noop_count(struct lock_list *entry, void *data)
					   unsigned int depth)
{
{
	struct lock_list *entry;
	(*(unsigned long *)data)++;
	unsigned long ret = 1;

	if (lockdep_dependency_visit(class, depth))
	return 0;
	return 0;
}


	/*
unsigned long __lockdep_count_forward_deps(struct lock_list *this)
	 * Recurse this class's dependency list:
{
	 */
	unsigned long  count = 0;
	list_for_each_entry(entry, &class->locks_after, entry)
	struct lock_list *uninitialized_var(target_entry);
		ret += __lockdep_count_forward_deps(entry->class, depth + 1);


	return ret;
	__bfs_forwards(this, (void *)&count, noop_count, &target_entry);
}


	return count;
}
unsigned long lockdep_count_forward_deps(struct lock_class *class)
unsigned long lockdep_count_forward_deps(struct lock_class *class)
{
{
	unsigned long ret, flags;
	unsigned long ret, flags;
	struct lock_list this;

	this.parent = NULL;
	this.class = class;


	local_irq_save(flags);
	local_irq_save(flags);
	__raw_spin_lock(&lockdep_lock);
	__raw_spin_lock(&lockdep_lock);
	ret = __lockdep_count_forward_deps(class, 0);
	ret = __lockdep_count_forward_deps(&this);
	__raw_spin_unlock(&lockdep_lock);
	__raw_spin_unlock(&lockdep_lock);
	local_irq_restore(flags);
	local_irq_restore(flags);


	return ret;
	return ret;
}
}


unsigned long __lockdep_count_backward_deps(struct lock_class *class,
unsigned long __lockdep_count_backward_deps(struct lock_list *this)
					    unsigned int depth)
{
{
	struct lock_list *entry;
	unsigned long  count = 0;
	unsigned long ret = 1;
	struct lock_list *uninitialized_var(target_entry);


	if (lockdep_dependency_visit(class, depth))
	__bfs_backwards(this, (void *)&count, noop_count, &target_entry);
		return 0;
	/*
	 * Recurse this class's dependency list:
	 */
	list_for_each_entry(entry, &class->locks_before, entry)
		ret += __lockdep_count_backward_deps(entry->class, depth + 1);


	return ret;
	return count;
}
}


unsigned long lockdep_count_backward_deps(struct lock_class *class)
unsigned long lockdep_count_backward_deps(struct lock_class *class)
{
{
	unsigned long ret, flags;
	unsigned long ret, flags;
	struct lock_list this;

	this.parent = NULL;
	this.class = class;


	local_irq_save(flags);
	local_irq_save(flags);
	__raw_spin_lock(&lockdep_lock);
	__raw_spin_lock(&lockdep_lock);
	ret = __lockdep_count_backward_deps(class, 0);
	ret = __lockdep_count_backward_deps(&this);
	__raw_spin_unlock(&lockdep_lock);
	__raw_spin_unlock(&lockdep_lock);
	local_irq_restore(flags);
	local_irq_restore(flags);