diff --git a/kernel/amd64/apic.c b/kernel/amd64/apic.c index 4100106..4019f75 100644 --- a/kernel/amd64/apic.c +++ b/kernel/amd64/apic.c @@ -239,12 +239,12 @@ static uint32_t lapic_calibrate (uint32_t us) { lapic_write (LAPIC_DCR, DIVIDER_VALUE); - lapic_write (LAPIC_LVTTR, INTR_SCHED_PREEMPT_TIMER | (1 << 16)); + lapic_write (LAPIC_LVTTR, INTR_SYSTICK | (1 << 16)); lapic_write (LAPIC_TIMICT, 0xFFFFFFFF); sleep_micro (us); - lapic_write (LAPIC_LVTTR, INTR_SCHED_PREEMPT_TIMER | (0 << 16)); + lapic_write (LAPIC_LVTTR, INTR_SYSTICK | (0 << 16)); uint32_t ticks = 0xFFFFFFFF - lapic_read (LAPIC_TIMCCT); DEBUG ("timer ticks = %u\n", ticks); @@ -254,14 +254,14 @@ static uint32_t lapic_calibrate (uint32_t us) { } /* - * Starts a Local APIC, configures LVT timer to send interrupts at SCHED_PREEMPT_TIMER. + * Starts a Local APIC, configures LVT timer to send interrupts at SYSTICK. * * ticks - Initial tick count */ static void lapic_start (uint32_t ticks) { lapic_write (LAPIC_DCR, DIVIDER_VALUE); lapic_write (LAPIC_TIMICT, ticks); - lapic_write (LAPIC_LVTTR, INTR_SCHED_PREEMPT_TIMER | (1 << 17)); + lapic_write (LAPIC_LVTTR, INTR_SYSTICK | (1 << 17)); } /* diff --git a/kernel/amd64/bootmain.c b/kernel/amd64/bootmain.c index 41cd886..e0e268e 100644 --- a/kernel/amd64/bootmain.c +++ b/kernel/amd64/bootmain.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -62,7 +63,7 @@ void bootmain (void) { bsp_cpu->kproc = kproc_create (); - lapic_init (5000); + lapic_init (1000); __asm__ volatile ("sti"); @@ -78,7 +79,7 @@ void bootmain (void) { struct device* temp0 = device_find ("temp0"); vfs_create_volume (thiscpu->kproc, &rctx, "temp", FS_FAT16, temp0, true); - irq_attach (&proc_irq_sched, NULL, INTR_SCHED_PREEMPT_TIMER); + irq_attach (&systick_irq, NULL, INTR_SYSTICK); irq_attach (&proc_irq_sched, NULL, INTR_CPU_REQUEST_SCHED); smp_init (); diff --git a/kernel/amd64/intr.c b/kernel/amd64/intr.c index a803bb8..9f2bc17 100644 --- a/kernel/amd64/intr.c +++ b/kernel/amd64/intr.c @@ -126,7 +126,7 @@ static void idt_init (void) { IDT_ENTRY (40, 2); IDT_ENTRY (41, 2); IDT_ENTRY (42, 2); IDT_ENTRY (43, 2); IDT_ENTRY (44, 2); IDT_ENTRY (45, 2); IDT_ENTRY (46, 2); IDT_ENTRY (47, 2); - IDT_ENTRY (INTR_SCHED_PREEMPT_TIMER, 2); + IDT_ENTRY (INTR_SYSTICK, 2); IDT_ENTRY (INTR_CPU_REQUEST_SCHED, 2); IDT_ENTRY (INTR_CPU_SPURIOUS, 2); /* clang-format on */ diff --git a/kernel/amd64/intr_defs.h b/kernel/amd64/intr_defs.h index 185a930..815809c 100644 --- a/kernel/amd64/intr_defs.h +++ b/kernel/amd64/intr_defs.h @@ -6,8 +6,8 @@ #define INTR_IDE_DRIVE_SCND 34 #define INTR_XHCI 35 -#define INTR_SCHED_PREEMPT_TIMER 80 -#define INTR_CPU_REQUEST_SCHED 82 -#define INTR_CPU_SPURIOUS 255 +#define INTR_SYSTICK 80 +#define INTR_CPU_REQUEST_SCHED 82 +#define INTR_CPU_SPURIOUS 255 #endif // _KERNEL_AMD64_INTR_DEFS_H diff --git a/kernel/amd64/intr_stub.S b/kernel/amd64/intr_stub.S index 014c13e..a04d2c5 100644 --- a/kernel/amd64/intr_stub.S +++ b/kernel/amd64/intr_stub.S @@ -91,6 +91,6 @@ make_intr_stub(no_err, 45) make_intr_stub(no_err, 46) make_intr_stub(no_err, 47) -make_intr_stub(no_err, INTR_SCHED_PREEMPT_TIMER) +make_intr_stub(no_err, INTR_SYSTICK) make_intr_stub(no_err, INTR_CPU_REQUEST_SCHED) make_intr_stub(no_err, INTR_CPU_SPURIOUS) diff --git a/kernel/amd64/smp.c b/kernel/amd64/smp.c index f870e22..6b6e13c 100644 --- a/kernel/amd64/smp.c +++ b/kernel/amd64/smp.c @@ -100,7 +100,7 @@ static void smp_bootstrap (struct limine_mp_info* mp_info) { syscall_init (); sse_enable (); - lapic_init (5000); + lapic_init (1000); DEBUG ("CPU %u is online!\n", thiscpu->id); diff --git a/kernel/amd64/src.mk b/kernel/amd64/src.mk index c2a491a..8bc059c 100644 --- a/kernel/amd64/src.mk +++ b/kernel/amd64/src.mk @@ -13,7 +13,8 @@ c += amd64/bootmain.c \ amd64/proc.c \ amd64/syscall.c \ amd64/gdt.c \ - amd64/stall.c + amd64/stall.c \ + amd64/systick.c S += amd64/intr_stub.S \ amd64/spin.S \ @@ -41,4 +42,5 @@ o += amd64/bootmain.o \ amd64/syscallentry.o \ amd64/gdt.o \ amd64/sse.o \ - amd64/stall.o + amd64/stall.o \ + amd64/systick.o diff --git a/kernel/amd64/systick.c b/kernel/amd64/systick.c new file mode 100644 index 0000000..79875a1 --- /dev/null +++ b/kernel/amd64/systick.c @@ -0,0 +1,12 @@ +#include +#include +#include + +static uint32_t systicks = 0; + +void systick_irq (void* arg, void* regs, bool user, struct reschedule_ctx* rctx) { + systicks++; + + if (systicks % 5 == 0) + rctx_insert_cpu (rctx, thiscpu); +} diff --git a/kernel/amd64/systick.h b/kernel/amd64/systick.h new file mode 100644 index 0000000..29895c2 --- /dev/null +++ b/kernel/amd64/systick.h @@ -0,0 +1,9 @@ +#ifndef _KERNEL_AMD64_SYSTICK_H +#define _KERNEL_AMD64_SYSTICK_H + +#include +#include + +void systick_irq (void* arg, void* regs, bool user, struct reschedule_ctx* rctx); + +#endif // // _KERNEL_AMD64_SYSTICK_H