31 asm volatile(
"pause");
113 if (ctx ==
NULL || callback ==
NULL)
123 LOG_DEBUG(
"timer callback subscribed %p in slot %d\n", callback, i);
129 panic(
NULL,
"Failed to subscribe timer callback, no free slots available");
134 if (ctx ==
NULL || callback ==
NULL)
144 LOG_DEBUG(
"timer callback unsubscribed %p from slot %d\n", callback, i);
150 panic(
NULL,
"Failed to unsubscribe timer callback, not found");
161 if (deadline < self->timer.nextDeadline)
void interrupt_disable(void)
Disable interrupts and increment the disableDepth.
void interrupt_enable(void)
Decrement the CLI depth and enable interrupts if depth reaches zero and interrupts were previously en...
@ INTERRUPT_TIMER
The timer subsystem interrupt.
static cpu_t * smp_self_unsafe(void)
Returns a pointer to the cpu_t structure of the current CPU.
#define SYSCALL_DEFINE(num, returnType,...)
Macro to define a syscall.
uint64_t apic_timer_ticks_per_ns(void)
Apic timer ticks per nanosecond.
void apic_timer_one_shot(interrupt_t vector, uint32_t ticks)
Configure the apic timer in one-shot mode.
#define APIC_TIMER_TICKS_FIXED_POINT_OFFSET
APIC Timer Ticks Fixed Point Offset.
void lapic_send_ipi(lapic_id_t id, interrupt_t vector)
Send an Inter-Processor Interrupt (IPI) to a local apic.
clock_t hpet_nanoseconds_per_tick(void)
Retrieve the number of nanoseconds per HPET tick.
void hpet_reset_counter(void)
Reset the HPET main counter to 0 and enable the HPET.
uint64_t hpet_read_counter(void)
Read the current value of the HPET main counter.
void rtc_read(struct tm *time)
Reads the current time from the RTC.
NORETURN void panic(const interrupt_frame_t *frame, const char *format,...)
Panic the kernel, printing a message and halting.
#define LOG_INFO(format,...)
#define LOG_DEBUG(format,...)
uint64_t thread_copy_to_user(thread_t *thread, void *dest, const void *userSrc, uint64_t length)
Safely copy data to user space.
thread_t * sched_thread(void)
Retrieves the currently running thread.
static void lock_init(lock_t *lock)
Initializes a lock.
#define LOCK_SCOPE(lock)
Acquires a lock for the reminder of the current scope.
void timer_interrupt_handler(interrupt_frame_t *frame, cpu_t *self)
Handle timer interrupt.
time_t timer_unix_epoch(void)
The unix epoch.
void(* timer_callback_t)(interrupt_frame_t *frame, cpu_t *self)
Timer callback function type.
void timer_notify_self(void)
Trigger timer interrupt on self.
#define TIMER_MAX_CALLBACK
Maximum amount of timer callbacks.
void timer_one_shot(cpu_t *self, clock_t uptime, clock_t timeout)
Schedule a one-shot timer interrupt.
void timer_unsubscribe(timer_ctx_t *ctx, timer_callback_t callback)
Unsubscribe from timer interrupts.
void timer_subscribe(timer_ctx_t *ctx, timer_callback_t callback)
Subscribe to timer interrupts.
void timer_notify(cpu_t *cpu)
Trigger timer interrupt on cpu.
clock_t timer_uptime(void)
Time since boot.
void timer_ctx_init(timer_ctx_t *ctx)
Initialize per-CPU timer context.
clock_t uptime(void)
System call for retreving the time since boot.
#define NULL
Pointer error value.
#define ERR
Integer error value.
__UINT64_TYPE__ clock_t
A nanosecond time.
#define atomic_store(object, desired)
#define atomic_compare_exchange_strong(object, expected, desired)
#define ATOMIC_VAR_INIT(value)
Per-CPU system time context.
timer_callback_t callbacks[TIMER_MAX_CALLBACK]
The registered timer callbacks for the owner cpu.
clock_t nextDeadline
The next time the owner cpus apic timer will fire, specified in nanoseconds since boot,...
uint64_t apicTicksPerNs
The amount of ticks in the owner cpus apic timer that occur every nanosecond, stored using fixed poin...
_PUBLIC time_t time(time_t *timer)
_PUBLIC time_t mktime(struct tm *timeptr)
long long unsigned time_t
static void timer_release(void)
static void timer_init(void)
static clock_t accumulator
static void timer_accumulate(void)
static void timer_acquire(void)
static atomic_int8_t accumulatorLock