From 534879b0c068189d2e8155f390f0b5b0724e8861 Mon Sep 17 00:00:00 2001 From: Ali Mashtizadeh Date: Thu, 22 Jan 2015 13:52:02 -0800 Subject: [PATCH] Show lock stack when a spinlock waits too long --- sys/include/spinlock.h | 1 + sys/kern/spinlock.c | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/sys/include/spinlock.h b/sys/include/spinlock.h index 495879a..dccda9a 100644 --- a/sys/include/spinlock.h +++ b/sys/include/spinlock.h @@ -16,6 +16,7 @@ typedef struct Spinlock uint64_t lockedTSC; char name[SPINLOCK_NAMELEN]; LIST_ENTRY(Spinlock) lockList; + TAILQ_ENTRY(Spinlock) lockStack; } Spinlock; void Critical_Init(); diff --git a/sys/kern/spinlock.c b/sys/kern/spinlock.c index f329a90..6a811a8 100644 --- a/sys/kern/spinlock.c +++ b/sys/kern/spinlock.c @@ -11,10 +11,14 @@ #include #include +#include +#include Spinlock lockListLock = { 0, 0, 0, 0, 0, 0, "SPINLOCK LIST" }; LIST_HEAD(LockListHead, Spinlock) lockList = LIST_HEAD_INITIALIZER(lockList); +TAILQ_HEAD(LockStack, Spinlock) lockStack = TAILQ_HEAD_INITIALIZER(lockStack); + extern uint64_t ticksPerSecond; void @@ -52,6 +56,7 @@ Spinlock_Lock(Spinlock *lock) { if ((Time_GetTSC() - startTSC) / ticksPerSecond > 1) { kprintf("Spinlock_Lock(%s): waiting for over a second!\n", lock->name); + breakpoint(); } } lock->waitTime += Time_GetTSC() - startTSC; @@ -59,11 +64,15 @@ Spinlock_Lock(Spinlock *lock) lock->cpu = CPU(); lock->count++; lock->lockedTSC = Time_GetTSC(); + + TAILQ_INSERT_TAIL(&lockStack, lock, lockStack); } void Spinlock_Unlock(Spinlock *lock) { + TAILQ_REMOVE(&lockStack, lock, lockStack); + lock->cpu = 0; lock->lockTime += Time_GetTSC() - lock->lockedTSC; @@ -98,3 +107,16 @@ Debug_Spinlocks(int argc, const char *argv[]) REGISTER_DBGCMD(spinlocks, "Display list of spinlocks", Debug_Spinlocks); +void +Debug_LockStack(int argc, const char *argv[]) +{ + Spinlock *lock; + + kprintf("Lock Stack:\n"); + TAILQ_FOREACH(lock, &lockStack, lockStack) { + kprintf(" %s\n", lock->name); + } +} + +REGISTER_DBGCMD(lockstack, "Display stack of held spinlocks", Debug_LockStack); +