dthain / basekernel

A simple OS kernel for research, teaching, and fun.
GNU General Public License v2.0
804 stars 109 forks source link

kernel/clock.c ticks at double the rate #288

Closed DevHyperCoder closed 12 months ago

DevHyperCoder commented 12 months ago

Hello!

I've been playing around with clock.c (from kernel).

I made the following change

-       kshell_launch();
+    serial_write(0, 'a');
+    clock_wait(5000);
+    serial_write(0, 'b');
+       //kshell_launch();

in kernel/main.c

and switched to the serial monitor in QEMU. I timed it using a stop watch and I can see b in the serial console in 2.5 seconds, but in theory clock_wait should wait for 5 seconds.

In kernel/clock.c, I modified line 29

--- a/kernel/clock.c
+++ b/kernel/clock.c
@@ -26,7 +26,7 @@ static void clock_interrupt(int i, int code)
 {
        clicks++;
        process_wakeup_all(&queue);
-       if(clicks >= CLICKS_PER_SECOND) {
+       if(clicks >= CLICKS_PER_SECOND * 2) {
                clicks = 0;
                seconds++;
                process_preempt();

and now the clock seems to be ticking properly. I will go through the osdev wiki on PICs once again to figure out why the code ticks twice as fast. So while I have "fixed" it, I'm yet to understand the cause.

Is this some thing other people can also replicate?