Renaming Timer to KTimer to mach the file names

This commit is contained in:
Ali Mashtizadeh 2015-01-17 13:52:04 -08:00
parent 929784bc52
commit 4d3eefa3e7
7 changed files with 38 additions and 38 deletions

View File

@ -43,6 +43,7 @@ src_common = [
"kern/diskcache.c",
"kern/handle.c",
"kern/ktime.c",
"kern/ktimer.c",
"kern/libc.c",
"kern/loader.c",
"kern/nic.c",
@ -54,7 +55,6 @@ src_common = [
"kern/syscall.c",
"kern/sysctl.c",
"kern/thread.c",
"kern/timer.c",
"kern/vfs.c",
"kern/vfsuio.c",
"dev/ahci.c",

View File

@ -23,7 +23,7 @@
#include "../dev/console.h"
extern void KTime_Init();
extern void Timer_Init();
extern void KTimer_Init();
extern void RTC_Init();
extern void PS2_Init();
extern void PCI_Init();
@ -148,7 +148,7 @@ void Machine_Init()
IOAPIC_Enable(0); // Enable timer interrupts
Thread_Init();
Timer_Init(); // Depends on RTC and KTime
KTimer_Init(); // Depends on RTC and KTime
PS2_Init();
PCI_Init();

View File

@ -20,7 +20,7 @@
extern uint64_t trap_table[T_MAX];
extern void trap_pop(TrapFrame *tf);
extern void Debug_Breakpoint(TrapFrame *tf);
extern void Timer_Process();
extern void KTimer_Process();
static InteruptGate64 idt[256];
static PseudoDescriptor idtdesc;
@ -178,7 +178,7 @@ trap_entry(TrapFrame *tf)
LAPIC_SendEOI();
IRQ_Handler(tf->vector - T_IRQ_BASE);
if (tf->vector == T_IRQ_TIMER) {
Timer_Process();
KTimer_Process();
Thread_Scheduler();
}

View File

@ -4,21 +4,21 @@
#include <sys/queue.h>
typedef void (*TimerCB)(void *);
typedef void (*KTimerCB)(void *);
typedef struct TimerEvent {
typedef struct KTimerEvent {
uint64_t refCount;
uint64_t timeout;
TimerCB cb;
KTimerCB cb;
void *arg;
LIST_ENTRY(TimerEvent) timerQueue;
} TimerEvent;
LIST_ENTRY(KTimerEvent) timerQueue;
} KTimerEvent;
TimerEvent *Timer_Create(uint64_t timeout, TimerCB cb, void *arg);
void Timer_Retain(TimerEvent *evt);
void Timer_Release(TimerEvent *evt);
void Timer_Cancel(TimerEvent *evt);
void Timer_Process();
KTimerEvent *KTimer_Create(uint64_t timeout, KTimerCB cb, void *arg);
void KTimer_Retain(KTimerEvent *evt);
void KTimer_Release(KTimerEvent *evt);
void KTimer_Cancel(KTimerEvent *evt);
void KTimer_Process();
#endif /* __SYS_KTIMER_H__ */

View File

@ -30,7 +30,7 @@ typedef struct Thread {
// Scheduler
int schedState;
TAILQ_ENTRY(Thread) schedQueue;
TimerEvent *timerEvt; // Timer event for wakeups
KTimerEvent *timerEvt; // Timer event for wakeups
uintptr_t exitValue;
// Statistics
uint64_t ctxSwitches;

View File

@ -12,21 +12,21 @@
#define TIMER_WHEEL_LENGTH 256
int timerHead = 0;
uint64_t timerNow = 0;
LIST_HEAD(TimerWheelHead, TimerEvent) timerSlot[TIMER_WHEEL_LENGTH];
Spinlock timerLock;
Slab timerSlab;
static int timerHead = 0;
static uint64_t timerNow = 0;
static LIST_HEAD(TimerWheelHead, KTimerEvent) timerSlot[TIMER_WHEEL_LENGTH];
static Spinlock timerLock;
static Slab timerSlab;
DEFINE_SLAB(TimerEvent, &timerSlab);
DEFINE_SLAB(KTimerEvent, &timerSlab);
void
Timer_Init()
KTimer_Init()
{
int i;
Spinlock_Init(&timerLock, "Timer Lock");
Slab_Init(&timerSlab, "TimerEvent Slab", sizeof(TimerEvent), 16);
Spinlock_Init(&timerLock, "KTimer Lock");
Slab_Init(&timerSlab, "KTimerEvent Slab", sizeof(KTimerEvent), 16);
// Initialize wheel
timerHead = 0;
@ -36,11 +36,11 @@ Timer_Init()
}
}
TimerEvent *
Timer_Create(uint64_t timeout, TimerCB cb, void *arg)
KTimerEvent *
KTimer_Create(uint64_t timeout, KTimerCB cb, void *arg)
{
int slot;
TimerEvent *evt = TimerEvent_Alloc();
KTimerEvent *evt = KTimerEvent_Alloc();
evt->refCount = 2; // One for the wheel and one for the callee
evt->timeout = timerNow + timeout;
@ -57,48 +57,48 @@ Timer_Create(uint64_t timeout, TimerCB cb, void *arg)
}
void
Timer_Retain(TimerEvent *evt)
KTimer_Retain(KTimerEvent *evt)
{
ASSERT(evt->refCount != 0);
__sync_fetch_and_add(&evt->refCount, 1);
}
void
Timer_Release(TimerEvent *evt)
KTimer_Release(KTimerEvent *evt)
{
ASSERT(evt->refCount != 0);
if (__sync_fetch_and_sub(&evt->refCount, 1) == 1) {
TimerEvent_Free(evt);
KTimerEvent_Free(evt);
}
}
void
Timer_Cancel(TimerEvent *evt)
KTimer_Cancel(KTimerEvent *evt)
{
Spinlock_Lock(&timerLock);
LIST_REMOVE(evt, timerQueue);
Timer_Release(evt);
KTimer_Release(evt);
Spinlock_Unlock(&timerLock);
}
void
Timer_Process()
KTimer_Process()
{
uint64_t now = KTime_GetEpoch();
Spinlock_Lock(&timerLock);
while (now > timerNow) {
TimerEvent *it, *tmp;
KTimerEvent *it, *tmp;
// Dispatch pending timer events
LIST_FOREACH_SAFE(it, &timerSlot[timerHead], timerQueue, tmp) {
if (it->timeout <= now) {
(it->cb)(it->arg);
LIST_REMOVE(it, timerQueue);
Timer_Release(it);
KTimer_Release(it);
}
}

View File

@ -321,7 +321,7 @@ ThreadWakeupHelper(void *arg)
Thread *thr = (Thread *)arg;
Thread_SetRunnable(thr);
Timer_Release(thr->timerEvt);
KTimer_Release(thr->timerEvt);
thr->timerEvt = NULL;
}
@ -332,7 +332,7 @@ Syscall_ThreadSleep(uint64_t time)
// If the sleep time is zero just yield
if (time != 0) {
cur->timerEvt = Timer_Create(time, ThreadWakeupHelper, cur);
cur->timerEvt = KTimer_Create(time, ThreadWakeupHelper, cur);
if (cur->timerEvt == NULL)
return -ENOMEM;