Keep track of process wait times

This commit is contained in:
Ali Mashtizadeh 2015-01-16 15:25:36 -08:00
parent 6953d03cb3
commit c408b47966
2 changed files with 11 additions and 0 deletions

View File

@ -35,6 +35,7 @@ typedef struct Thread {
uint64_t userTime;
uint64_t kernTime;
uint64_t waitTime;
uint64_t waitStart;
} Thread;
#define PROCESS_HANDLE_SLOTS 128

View File

@ -7,6 +7,7 @@
#include <sys/kconfig.h>
#include <sys/kdebug.h>
#include <sys/kmem.h>
#include <sys/ktime.h>
#include <sys/mp.h>
#include <sys/spinlock.h>
#include <sys/thread.h>
@ -181,6 +182,11 @@ Thread_SetRunnable(Thread *thr)
{
Spinlock_Lock(&threadLock);
if (thr->schedState == SCHED_STATE_WAITING) {
thr->waitTime += KTime_GetEpochNS() - thr->waitStart;
thr->waitStart = 0;
TAILQ_REMOVE(&waitQueue, thr, schedQueue);
}
thr->schedState = SCHED_STATE_RUNNABLE;
TAILQ_INSERT_TAIL(&runnableQueue, thr, schedQueue);
@ -194,6 +200,7 @@ Thread_SetWaiting(Thread *thr)
thr->schedState = SCHED_STATE_WAITING;
TAILQ_INSERT_TAIL(&waitQueue, thr, schedQueue);
thr->waitStart = KTime_GetEpochNS();
Spinlock_Unlock(&threadLock);
}
@ -309,13 +316,16 @@ Debug_Threads(int argc, const char *argv[])
//Spinlock_Lock(&threadLock);
kprintf("Current Thread: %d(%016llx) %d\n", curProc->tid, curProc, curProc->ctxSwitches);
Thread_Dump(curProc);
TAILQ_FOREACH(thr, &runnableQueue, schedQueue)
{
kprintf("Runnable Thread: %d(%016llx) %d\n", thr->tid, thr, thr->ctxSwitches);
Thread_Dump(thr);
}
TAILQ_FOREACH(thr, &waitQueue, schedQueue)
{
kprintf("Waiting Thread: %d(%016llx) %d\n", thr->tid, thr, thr->ctxSwitches);
Thread_Dump(thr);
}
//Spinlock_Unlock(&threadLock);