CeDOS - Commit 9efe84da

alarms: Switch to RTC Use RTC interrupt instead of the scheduler interrupt for alarm ticks. Since the tick rate is known, also switch to ms instead of tick count.
Celina Sophie Kalus
Tue, 26 Dec 2023 18:27:53 +0100
6 files changed, 15 insertions(+), 11 deletions(-)
M kernel/sched/sched.ckernel/sched/sched.c

@@ -15,6 +15,7 @@ #include "pic.h"

#include "elf.h" #include "file.h" #include "alarm.h" +#include "time.h" #include "assembly.h" #include "assert.h"

@@ -136,8 +137,6 @@

void sched_interrupt_c(SCHED_FRAME * volatile frame, uint32_t volatile ebp) { PROCESS* current = get_process(current_pid); - alarm_tick(); - if (current_pid != 0) { current->esp = (VIRT_ADDR)(frame); current->ebp = (VIRT_ADDR)(ebp);

@@ -230,13 +229,13 @@

crit_exit(); } -void sched_sleep(int ticks) { +void sched_sleep(int msec) { // block the process. unblocking is done by the alarm. PROCESS *process = get_process(current_pid); process->state = PSTATE_BLOCKED; // create a wakeup-alarm to unblock the process. - alarm_add(ticks, current_pid, ALARM_WAKEUP); + alarm_add(RTC_MSEC(msec), current_pid, ALARM_WAKEUP); sched_yield();
M kernel/sched/sched.hkernel/sched/sched.h

@@ -65,11 +65,11 @@ */

void sched_yield(void); /** - * @brief Blocks the current process for the given number of ticks. + * @brief Blocks the current process for the given number of milliseconds. * - * @param ticks Number of ticks. + * @param msec Number of milliseconds. */ -void sched_sleep(int ticks); +void sched_sleep(int msec); /** * @brief Unblocks the process given by \p pid immediately.
M kernel/time.ckernel/time.c

@@ -3,6 +3,7 @@ #include "assembly.h"

#include "interrupts.h" #include "pic.h" #include "core.h" +#include "alarm.h" #define RTC_COMMAND 0x70 #define RTC_DATA 0x71

@@ -74,6 +75,7 @@ }

INTERRUPT(rtc_interrupt, frame) { time_tick(); + alarm_tick(); rtc_get(RTC_REGISTER_C);
M kernel/time.hkernel/time.h

@@ -3,7 +3,10 @@ #define __TIME_H

// frequency = 32768 >> (rate-1); // rate at least 2 (~8kHz) -#define RTC_INT_RATE 2 +#define RTC_INT_RATE 3 +#define RTC_FREQUENCY (32768 >> (RTC_INT_RATE - 1)) +#define RTC_MSEC(ms) ((RTC_FREQUENCY / 1000) * ms) +#define RTC_SEC(s) (RTC_FREQUENCY * s) typedef struct { int year;
M libcedos/cedos.clibcedos/cedos.c

@@ -101,9 +101,9 @@ volatile uint32_t res = 0;

interrupt(0x30, res, 14, pid, 0, 0); } -void sleep(int ticks) { +void sleep(int msec) { volatile uint32_t res = 0; - interrupt(0x30, res, 15, ticks, 0, 0); + interrupt(0x30, res, 15, msec, 0, 0); } int time_now(datetime_t *buffer) {
M libcedos/cedos.hlibcedos/cedos.h

@@ -17,7 +17,7 @@ } datetime_t;

int sysprint(const char *fmt, int arg1, int arg2); int yield(); -void sleep(int ticks); +void sleep(int msec); int get_pid(); int process_spawn(const char *fname, const char *args); int process_spawn_pipe(const char *fname, const char *args, int stdin, int stdout);