timers: use DPCs to handle callbacks

This commit is contained in:
Matheus
2023-06-26 19:46:30 -03:00
parent 99a7eccbe4
commit e3bc7e8b8b
3 changed files with 16 additions and 10 deletions
+3 -4
View File
@@ -297,9 +297,10 @@ vnode_t *sched_getroot() {
return getnodeslock(&proc->root);
}
static void timerhook(void *private, context_t *context) {
static void timerhook(context_t *context, dpcarg_t arg) {
thread_t* current = _cpu()->thread;
interrupt_set(false);
spinlock_acquire(&runqueuelock);
thread_t *next = runqueuenext(current->priority);
@@ -338,8 +339,6 @@ void sched_init() {
__assert(_cpu()->schedulerstack);
_cpu()->schedulerstack = (void *)((uintptr_t)_cpu()->schedulerstack + SCHEDULER_STACK_SIZE);
_cpu()->schedtimerentry.func = timerhook;
_cpu()->schedtimerentry.repeatus = QUANTUM_US;
SPINLOCK_INIT(runqueuelock);
_cpu()->idlethread = sched_newthread(cpuidlethread, PAGE_SIZE * 4, 3, NULL, NULL);
@@ -347,7 +346,7 @@ void sched_init() {
_cpu()->thread = sched_newthread(NULL, PAGE_SIZE * 32, 0, NULL, NULL);
__assert(_cpu()->thread);
timer_insert(_cpu()->timer, &_cpu()->schedtimerentry, QUANTUM_US);
timer_insert(_cpu()->timer, &_cpu()->schedtimerentry, timerhook, NULL, QUANTUM_US, true);
// XXX move this resume to a more appropriate place
timer_resume(_cpu()->timer);
}
+7 -3
View File
@@ -38,11 +38,11 @@ void timer_isr(timer_t *timer, context_t *context) {
timerentry_t *oldentry = timer->queue;
timer->queue = timer->queue->next;
oldentry->func(oldentry->private, context);
if (oldentry->repeatus)
insert(timer, oldentry, oldentry->repeatus);
dpc_enqueue(&oldentry->dpc, oldentry->fn, oldentry->arg);
if (timer->queue) {
// TODO handle this
__assert(timer->queue->absolutetick > timer->tickcurrent);
@@ -79,13 +79,17 @@ void timer_stop(timer_t *timer) {
interrupt_loweripl(oldipl);
}
void timer_insert(timer_t *timer, timerentry_t* entry, time_t us) {
void timer_insert(timer_t *timer, timerentry_t *entry, dpcfn_t fn, dpcarg_t arg, time_t us, bool repeating) {
long oldipl = interrupt_raiseipl(IPL_TIMER);
spinlock_acquire(&timer->lock);
if (timer->running)
timer->tickcurrent += timer->stop(timer);
entry->repeatus = repeating ? us : 0;
entry->fn = fn;
entry->arg = arg;
insert(timer, entry, us);
if (timer->running) {