Make spinlock stack per-CPU

This commit is contained in:
Ali Mashtizadeh 2015-02-15 20:05:24 -08:00
parent 4ce2388ef2
commit d5535ded23
2 changed files with 16 additions and 4 deletions

View File

@ -119,6 +119,7 @@ void Machine_SyscallInit()
void Machine_EarlyInit()
{
Spinlock_EarlyInit();
Critical_Init();
Critical_Enter();
Console_Init();

View File

@ -21,10 +21,20 @@ Spinlock lockListLock = {
};
LIST_HEAD(LockListHead, Spinlock) lockList = LIST_HEAD_INITIALIZER(lockList);
TAILQ_HEAD(LockStack, Spinlock) lockStack = TAILQ_HEAD_INITIALIZER(lockStack);
TAILQ_HEAD(LockStack, Spinlock) lockStack[MAX_CPUS];
extern uint64_t ticksPerSecond;
void
Spinlock_EarlyInit()
{
int c;
for (c = 0; c < MAX_CPUS; c++) {
TAILQ_INIT(&lockStack[c]);
}
}
void
Spinlock_Init(Spinlock *lock, const char *name, uint64_t type)
{
@ -77,13 +87,13 @@ Spinlock_Lock(Spinlock *lock)
if (lock->rCount == 1)
lock->lockedTSC = Time_GetTSC();
TAILQ_INSERT_TAIL(&lockStack, lock, lockStack);
TAILQ_INSERT_TAIL(&lockStack[CPU()], lock, lockStack);
}
void
Spinlock_Unlock(Spinlock *lock)
{
TAILQ_REMOVE(&lockStack, lock, lockStack);
TAILQ_REMOVE(&lockStack[CPU()], lock, lockStack);
lock->rCount--;
if (lock->rCount == 0) {
@ -124,10 +134,11 @@ REGISTER_DBGCMD(spinlocks, "Display list of spinlocks", Debug_Spinlocks);
void
Debug_LockStack(int argc, const char *argv[])
{
int c = CPU();
Spinlock *lock;
kprintf("Lock Stack:\n");
TAILQ_FOREACH(lock, &lockStack, lockStack) {
TAILQ_FOREACH(lock, &lockStack[c], lockStack) {
kprintf(" %s\n", lock->name);
}
}