Show lock stack when a spinlock waits too long
This commit is contained in:
parent
ee3874da77
commit
534879b0c0
@ -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();
|
||||
|
@ -11,10 +11,14 @@
|
||||
#include <sys/spinlock.h>
|
||||
|
||||
#include <machine/atomic.h>
|
||||
#include <machine/amd64.h>
|
||||
#include <machine/amd64op.h>
|
||||
|
||||
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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user