[Skiboot] [PATCH 02/13] lock: Add lock depth recording per CPU

Benjamin Herrenschmidt benh at kernel.crashing.org
Wed Feb 18 14:57:18 AEDT 2015


We want to move to pollers being run inly when no lock is held
so let's start recording lock depth. It will also be a useful
debugging tool.

Signed-off-by: Benjamin Herrenschmidt <benh at kernel.crashing.org>
---
 core/lock.c   | 5 +++++
 include/cpu.h | 1 +
 2 files changed, 6 insertions(+)

diff --git a/core/lock.c b/core/lock.c
index d916141..ac6cb3b 100644
--- a/core/lock.c
+++ b/core/lock.c
@@ -54,6 +54,9 @@ static void unlock_check(struct lock *l)
 
 	if (l->in_con_path && this_cpu()->con_suspend == 0)
 		lock_error(l, "Unlock con lock with console not suspended", 3);
+
+	if (this_cpu()->lock_depth == 0)
+		lock_error(l, "Releasing lock with 0 depth", 4);
 }
 
 #else
@@ -73,6 +76,7 @@ bool try_lock(struct lock *l)
 	if (__try_lock(l)) {
 		if (l->in_con_path)
 			this_cpu()->con_suspend++;
+		this_cpu()->lock_depth++;
 		return true;
 	}
 	return false;
@@ -101,6 +105,7 @@ void unlock(struct lock *l)
 	unlock_check(l);
 
 	lwsync();
+	this_cpu()->lock_depth--;
 	l->lock_val = 0;
 
 	if (l->in_con_path) {
diff --git a/include/cpu.h b/include/cpu.h
index 6112ab2..1d7c7c5 100644
--- a/include/cpu.h
+++ b/include/cpu.h
@@ -54,6 +54,7 @@ struct cpu_thread {
 	struct trace_info		*trace;
 	uint64_t			save_r1;
 	void				*icp_regs;
+	uint32_t			lock_depth;
 	uint32_t			con_suspend;
 	bool				con_need_flush;
 	bool				in_mcount;
-- 
2.1.0



More information about the Skiboot mailing list