|
PatchworkOS
|
System time and timers. More...
Data Structures | |
| struct | timer_ctx_t |
| Per-CPU system time context. More... | |
Macros | |
| #define | TIMER_MAX_CALLBACK 16 |
| Maximum amount of timer callbacks. | |
Typedefs | |
| typedef void(* | timer_callback_t) (interrupt_frame_t *frame, cpu_t *self) |
| Timer callback function type. | |
Functions | |
| void | timer_ctx_init (timer_ctx_t *ctx) |
| Initialize per-CPU timer context. | |
| clock_t | timer_uptime (void) |
| Time since boot. | |
| time_t | timer_unix_epoch (void) |
| The unix epoch. | |
| void | timer_interrupt_handler (interrupt_frame_t *frame, cpu_t *self) |
| Handle timer interrupt. | |
| void | timer_subscribe (timer_ctx_t *ctx, timer_callback_t callback) |
| Subscribe to timer interrupts. | |
| void | timer_unsubscribe (timer_ctx_t *ctx, timer_callback_t callback) |
| Unsubscribe from timer interrupts. | |
| void | timer_one_shot (cpu_t *self, clock_t uptime, clock_t timeout) |
| Schedule a one-shot timer interrupt. | |
| void | timer_notify (cpu_t *cpu) |
| Trigger timer interrupt on cpu. | |
| void | timer_notify_self (void) |
| Trigger timer interrupt on self. | |
System time and timers.
The timer subsystem provides kernel time management.
| #define TIMER_MAX_CALLBACK 16 |
| typedef void(* timer_callback_t) (interrupt_frame_t *frame, cpu_t *self) |
| void timer_ctx_init | ( | timer_ctx_t * | ctx | ) |
Initialize per-CPU timer context.
Must be called on the CPU who owns the context.
| ctx | The timer context to initialize. |
Definition at line 51 of file timer.c.
References apic_timer_ticks_per_ns(), timer_ctx_t::apicTicksPerNs, timer_ctx_t::callbacks, CLOCKS_NEVER, cpu_t::id, timer_ctx_t::lock, lock_init(), LOG_INFO, timer_ctx_t::nextDeadline, NULL, smp_self_unsafe(), cpu_t::timer, and TIMER_MAX_CALLBACK.
Referenced by cpu_init().
| void timer_interrupt_handler | ( | interrupt_frame_t * | frame, |
| cpu_t * | self | ||
| ) |
Handle timer interrupt.
| frame | The current interrupt frame. |
| self | The current cpu. |
Definition at line 96 of file timer.c.
References timer_ctx_t::callbacks, CLOCKS_NEVER, timer_ctx_t::lock, LOCK_SCOPE, timer_ctx_t::nextDeadline, NULL, cpu_t::timer, timer_accumulate(), and TIMER_MAX_CALLBACK.
Referenced by interrupt_handler().
| void timer_notify | ( | cpu_t * | cpu | ) |
Trigger timer interrupt on cpu.
Triggers the timer interrupt on the specified cpu.
| cpu | The destination cpu. |
Definition at line 197 of file timer.c.
References INTERRUPT_TIMER, lapic_send_ipi(), and cpu_t::lapicId.
Referenced by sched_load_balance(), sched_push(), and sched_push_new_thread().
| void timer_notify_self | ( | void | ) |
Trigger timer interrupt on self.
Triggers the timer interrupt on the current cpu.
Definition at line 202 of file timer.c.
References INTERRUPT_TIMER.
Referenced by sched_done_with_boot_thread(), SYSCALL_DEFINE(), and wait_block_commit().
Schedule a one-shot timer interrupt.
Sets the per-cpu timer to generate a interrupt after the specified timeout. Multiple calls with different timeouts will result in the timer being set for the shortest requested timeout, this will be reset after a timer interrupt.
The idea is that every system that wants timer interrupts calls the timer_one_shot() function with their desired timeout and then when the timer interrupt occurs they check if their desired time has been reached, if it has they do what they need to do, else they call the function once more respecifying their desired timeout, and we repeat the process. This does technically result in some uneeded checks but its a very simply way of effectively eliminating the need to care about timer related race conditions.
| self | The currently running cpu. |
| uptime | The time since boot, we need to specify this as an argument to avoid inconsistency in the timeout/deadline calculations. |
| timeout | The desired timeout. |
Definition at line 153 of file timer.c.
References apic_timer_one_shot(), APIC_TIMER_TICKS_FIXED_POINT_OFFSET, timer_ctx_t::apicTicksPerNs, CLOCKS_NEVER, INTERRUPT_TIMER, timer_ctx_t::nextDeadline, NULL, cpu_t::timer, UINT32_MAX, and uptime().
Referenced by sched_invoke(), wait_block_finalize(), and wait_timer_handler().
| void timer_subscribe | ( | timer_ctx_t * | ctx, |
| timer_callback_t | callback | ||
| ) |
Subscribe to timer interrupts.
Note that subscribing to a callback only applies to the cpu that the timer context belongs to.
| ctx | The timer context that the subscription is for. |
| callback | The callback function to be called on timer interrupts. |
Definition at line 111 of file timer.c.
References timer_ctx_t::callbacks, timer_ctx_t::lock, LOCK_SCOPE, LOG_DEBUG, NULL, panic(), and TIMER_MAX_CALLBACK.
Referenced by process_procfs_init(), sched_cpu_ctx_init(), and wait_cpu_ctx_init().
| time_t timer_unix_epoch | ( | void | ) |
The unix epoch.
Definition at line 86 of file timer.c.
References bootEpoch, CLOCKS_PER_SEC, initialized, timer_init(), and timer_uptime().
Referenced by inode_new(), inode_notify_access(), inode_notify_change(), inode_notify_modify(), and SYSCALL_DEFINE().
| void timer_unsubscribe | ( | timer_ctx_t * | ctx, |
| timer_callback_t | callback | ||
| ) |
Unsubscribe from timer interrupts.
Note that unsubscribing from a callback only applies to the cpu that the timer context belongs to.
| ctx | The timer context that the unsubscription is for. |
| callback | The callback function to be removed from timer interrupts. |
Definition at line 132 of file timer.c.
References timer_ctx_t::callbacks, timer_ctx_t::lock, LOCK_SCOPE, LOG_DEBUG, NULL, panic(), and TIMER_MAX_CALLBACK.
| clock_t timer_uptime | ( | void | ) |
Time since boot.
Definition at line 73 of file timer.c.
References accumulator, hpet_nanoseconds_per_tick(), hpet_read_counter(), initialized, time(), timer_acquire(), timer_init(), and timer_release().
Referenced by aml_def_timer_read(), kbd_push(), key_share(), key_timer_handler(), log_print_header(), mouse_push(), mutex_acquire_timeout(), process_kill(), ps2_wait_until_clear(), ps2_wait_until_set(), rand_gen_fallback(), rwlock_read_acquire(), rwlock_write_acquire(), sched_compute_time_slice(), sched_invoke(), sched_push(), sched_push_new_thread(), space_tlb_shootdown(), statistics_cpu_read(), statistics_interrupt_begin(), statistics_interrupt_end(), SYSCALL_DEFINE(), SYSCALL_DEFINE(), timer_unix_epoch(), vfs_poll(), wait_block_setup(), and wait_timer_handler().