summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-08-11 16:01:16 -0400
committerIan Moffett <ian@osmora.org>2025-08-11 16:04:20 -0400
commit58633d29b872f9cf171f00bcf2804bb2c28e3d74 (patch)
tree9ea8fa89b7448268dc36f39022f6afff46f457b3
parent5c6f79744a8bdf4cfb0e91517847281739c3e624 (diff)
kernel: timer: Add flags field + TIMER_MONOTONICexpt
Sometimes we may rely on a specific kind of timer. While we are able to grab scheduler specific timers, general purpose timers, etc. One might need to for example, check whether their general purpose timer timer is monotonic or not. Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r--sys/arch/amd64/amd64/hpet.c1
-rw-r--r--sys/arch/amd64/amd64/lapic.c1
-rw-r--r--sys/include/dev/timer.h5
3 files changed, 7 insertions, 0 deletions
diff --git a/sys/arch/amd64/amd64/hpet.c b/sys/arch/amd64/amd64/hpet.c
index 3b0ca46..9191bee 100644
--- a/sys/arch/amd64/amd64/hpet.c
+++ b/sys/arch/amd64/amd64/hpet.c
@@ -197,6 +197,7 @@ hpet_init(void)
timer.get_time_usec = hpet_time_usec;
timer.get_time_nsec = hpet_time_nsec;
timer.get_time_sec = hpet_time_sec;
+ timer.flags = TIMER_MONOTONIC;
register_timer(TIMER_GP, &timer);
return 0;
}
diff --git a/sys/arch/amd64/amd64/lapic.c b/sys/arch/amd64/amd64/lapic.c
index 022592c..ceb5428 100644
--- a/sys/arch/amd64/amd64/lapic.c
+++ b/sys/arch/amd64/amd64/lapic.c
@@ -364,5 +364,6 @@ lapic_init(void)
lapic_timer.name = "LAPIC_INTEGRATED_TIMER";
lapic_timer.stop = lapic_timer_stop;
lapic_timer.oneshot_us = lapic_timer_oneshot_us;
+ lapic_timer.flags = 0;
register_timer(TIMER_SCHED, &lapic_timer);
}
diff --git a/sys/include/dev/timer.h b/sys/include/dev/timer.h
index fe91323..2ca6d62 100644
--- a/sys/include/dev/timer.h
+++ b/sys/include/dev/timer.h
@@ -31,11 +31,15 @@
#define _DEV_TIMER_H_
#include <sys/types.h>
+#include <sys/param.h>
/* Timer IDs */
#define TIMER_SCHED 0x00000000U /* Scheduler reserved timer */
#define TIMER_GP 0x00000001U /* General purpose timer */
+/* Timer flags */
+#define TIMER_MONOTONIC BIT(0)
+
/* Number of timer IDs, adjust when adding timer IDs */
#define TIMER_ID_COUNT 2
@@ -79,6 +83,7 @@ struct timer {
void(*oneshot_ms)(size_t ms);
void(*oneshot_us)(size_t ms);
void(*stop)(void);
+ uint8_t flags;
};
tmrr_status_t register_timer(timer_id_t id, const struct timer *tmr);