Improving process debugging code and scheduler queues

This commit is contained in:
Ali Mashtizadeh 2015-01-14 14:44:32 -08:00
parent 9d9f301bdd
commit 156e25fcc5
2 changed files with 46 additions and 15 deletions

View File

@ -40,6 +40,7 @@ typedef struct Thread {
typedef struct Process {
uint64_t pid;
AS *space;
TAILQ_ENTRY(Process) processList;
// Threads
uint64_t threads;
// Handles

View File

@ -18,8 +18,13 @@ Spinlock threadLock;
uint64_t nextProcessID;
uint64_t nextThreadID;
Thread *curProc;
// Runnable Queue
TAILQ_HEAD(ThreadQueueHead, Thread) threadQueue;
// Scheduler Queues
TAILQ_HEAD(WaitQueueHead, Thread) waitQueue;
TAILQ_HEAD(RunnableQueueHead, Thread) runnableQueue;
// Process List
TAILQ_HEAD(ProcessListHead, Process) processList;
Slab processSlab;
Slab threadSlab;
@ -35,16 +40,18 @@ Thread_Init()
Slab_Init(&processSlab, "Process Objects", sizeof(Process), 16);
Slab_Init(&threadSlab, "Thread Objects", sizeof(Thread), 16);
Spinlock_Init(&threadLock, "Thread Lock");
TAILQ_INIT(&waitQueue);
TAILQ_INIT(&runnableQueue);
TAILQ_INIT(&processList);
Handle_GlobalInit();
// Create an thread object for current context
Process *proc = Thread_CreateProcess();
curProc = Thread_Create(proc);
curProc->schedState = SCHED_STATE_RUNNING;
Spinlock_Init(&threadLock, "Thread Lock");
TAILQ_INIT(&threadQueue);
Handle_GlobalInit();
}
Thread *
@ -118,6 +125,8 @@ Thread_CreateProcess()
Handle_Init(proc);
TAILQ_INSERT_TAIL(&processList, proc, processList);
return proc;
}
@ -172,7 +181,7 @@ Thread_SetRunnable(Thread *thr)
Spinlock_Lock(&threadLock);
thr->schedState = SCHED_STATE_RUNNABLE;
TAILQ_INSERT_TAIL(&threadQueue, thr, schedQueue);
TAILQ_INSERT_TAIL(&runnableQueue, thr, schedQueue);
Spinlock_Unlock(&threadLock);
}
@ -216,8 +225,8 @@ Thread_Scheduler()
Spinlock_Lock(&threadLock);
// Select next thread
next = TAILQ_FIRST(&threadQueue);
TAILQ_REMOVE(&threadQueue, next, schedQueue);
next = TAILQ_FIRST(&runnableQueue);
TAILQ_REMOVE(&runnableQueue, next, schedQueue);
prev = curProc;
curProc = next;
@ -226,7 +235,7 @@ Thread_Scheduler()
if (prev->schedState == SCHED_STATE_RUNNING) {
prev->schedState = SCHED_STATE_RUNNABLE;
TAILQ_INSERT_TAIL(&threadQueue, prev, schedQueue);
TAILQ_INSERT_TAIL(&runnableQueue, prev, schedQueue);
}
Thread_Switch(prev, next);
@ -279,10 +288,14 @@ Debug_Threads(int argc, const char *argv[])
//Spinlock_Lock(&threadLock);
kprintf("Current: %d(%016llx) %d\n", curProc->tid, curProc, curProc->ctxSwitches);
TAILQ_FOREACH(thr, &threadQueue, schedQueue)
kprintf("Current Thread: %d(%016llx) %d\n", curProc->tid, curProc, curProc->ctxSwitches);
TAILQ_FOREACH(thr, &runnableQueue, schedQueue)
{
kprintf("Thread: %d(%016llx) %d\n", curProc->tid, thr, thr->ctxSwitches);
kprintf("Runnable Thread: %d(%016llx) %d\n", thr->tid, thr, thr->ctxSwitches);
}
TAILQ_FOREACH(thr, &waitQueue, schedQueue)
{
kprintf("Waiting Thread: %d(%016llx) %d\n", thr->tid, thr, thr->ctxSwitches);
}
//Spinlock_Unlock(&threadLock);
@ -290,6 +303,23 @@ Debug_Threads(int argc, const char *argv[])
REGISTER_DBGCMD(threads, "Display list of threads", Debug_Threads);
void
Debug_Processes(int argc, const char *argv[])
{
Process *proc;
//Spinlock_Lock(&threadLock);
TAILQ_FOREACH(proc, &processList, processList)
{
kprintf("Process: %d(%016llx)\n", proc->pid, proc);
}
//Spinlock_Unlock(&threadLock);
}
REGISTER_DBGCMD(processes, "Display list of processes", Debug_Processes);
void
Debug_ThreadInfo(int argc, const char *argv[])
{