diff options
author | Marvin Borner | 2020-11-24 16:42:10 +0100 |
---|---|---|
committer | Marvin Borner | 2020-11-24 16:42:10 +0100 |
commit | 9257facb17bf74eb0eb1babfc59ff3549eb66242 (patch) | |
tree | 78af10bf8de91b4b8ecca878d5a358c79ae907b4 | |
parent | 0564c8006da7077064222d15a899b858ae2d7e61 (diff) |
Fixed timer counting with yield()
-rw-r--r-- | kernel/drivers/timer.c | 19 | ||||
-rw-r--r-- | kernel/features/proc.c | 14 | ||||
-rw-r--r-- | kernel/inc/proc.h | 3 | ||||
-rw-r--r-- | kernel/inc/timer.h | 3 | ||||
-rw-r--r-- | libnet/inc/net.h | 2 |
5 files changed, 23 insertions, 18 deletions
diff --git a/kernel/drivers/timer.c b/kernel/drivers/timer.c index 17a8991..766512f 100644 --- a/kernel/drivers/timer.c +++ b/kernel/drivers/timer.c @@ -3,8 +3,10 @@ #include <cpu.h> #include <def.h> #include <interrupts.h> +#include <proc.h> static u32 timer_ticks = 0; +static u8 call_scheduler = 0; void timer_phase(int hz) { @@ -19,12 +21,15 @@ u32 timer_get(void) return timer_ticks; } -void timer_handler() +void timer_handler(struct regs *r) { if (timer_ticks >= U32_MAX) timer_ticks = 0; else timer_ticks++; + + if (call_scheduler) + scheduler(r); } // "Delay" function with CPU sleep @@ -44,3 +49,15 @@ void timer_install(void) timer_phase(1000); irq_install_handler(0, timer_handler); } + +void scheduler_enable(void) +{ + call_scheduler = 1; + irq_install_handler(0, timer_handler); +} + +void scheduler_disable(void) +{ + call_scheduler = 0; + irq_install_handler(0, timer_handler); +} diff --git a/kernel/features/proc.c b/kernel/features/proc.c index f4e6124..d76312c 100644 --- a/kernel/features/proc.c +++ b/kernel/features/proc.c @@ -22,8 +22,6 @@ struct node *current; // TODO: 20 priority queues (https://www.kernel.org/doc/html/latest/scheduler/sched-nice-design.html) void scheduler(struct regs *regs) { - timer_handler(); - if (quantum == 0) { quantum = PROC_QUANTUM; } else { @@ -65,18 +63,6 @@ void scheduler(struct regs *regs) /* printf("{%d}", ((struct proc *)current->data)->pid); */ } -void scheduler_enable(void) -{ - timer_install(); - irq_install_handler(0, scheduler); -} - -void scheduler_disable(void) -{ - irq_uninstall_handler(0); - timer_install(); -} - void proc_print(void) { struct node *node = proc_list->head; diff --git a/kernel/inc/proc.h b/kernel/inc/proc.h index dc12369..5fc217c 100644 --- a/kernel/inc/proc.h +++ b/kernel/inc/proc.h @@ -36,8 +36,7 @@ struct proc_message { struct proc *kernel_proc; -void scheduler_enable(void); -void scheduler_disable(void); +void scheduler(struct regs *regs); void proc_init(void); void proc_print(void); struct proc *proc_current(void); diff --git a/kernel/inc/timer.h b/kernel/inc/timer.h index 21dd437..d6123b4 100644 --- a/kernel/inc/timer.h +++ b/kernel/inc/timer.h @@ -10,4 +10,7 @@ void timer_wait(u32 ticks); void timer_install(void); void timer_handler(void); // For scheduler +void scheduler_enable(void); +void scheduler_disable(void); + #endif diff --git a/libnet/inc/net.h b/libnet/inc/net.h index 6884690..a897f1d 100644 --- a/libnet/inc/net.h +++ b/libnet/inc/net.h @@ -19,7 +19,7 @@ #define ip(a, b, c, d) \ ((((a)&0xff) << 24) | (((b)&0xff) << 16) | (((c)&0xff) << 8) | (((d)&0xff) << 0)) -#define NET_TIMEOUT 500 +#define NET_TIMEOUT 2000 #define NET_NO_TIMEOUT 0 static inline int net_data_available(struct socket *socket) |