PatchworkOS  28a9544
A non-POSIX operating system.
Loading...
Searching...
No Matches
Time subsystem

System time. More...

Data Structures

struct  sys_time_source_t
 Timer system source. More...
 

Macros

#define SYS_TIME_MAX_SOURCES   8
 Maximum amount of system timer sources.
 

Functions

uint64_t sys_time_register_source (const sys_time_source_t *source)
 Register a system timer source.
 
void sys_time_unregister_source (const sys_time_source_t *source)
 Unregister a system timer source.
 
clock_t sys_time_uptime (void)
 Time since boot.
 
time_t sys_time_unix_epoch (void)
 The unix epoch.
 
void sys_time_wait (clock_t nanoseconds)
 Wait for a specified number of nanoseconds.
 

Detailed Description

System time.

The sys time subsystem is responsible for providing a consistent system wide time keeping.

System wide time is provided via "system time sources", which are provided in modules. Each source registers itself with a estimate of its precision, the timer subsystem then chooses the source with the highest precision as the system time source.

Macro Definition Documentation

◆ SYS_TIME_MAX_SOURCES

#define SYS_TIME_MAX_SOURCES   8

Maximum amount of system timer sources.

Definition at line 28 of file sys_time.h.

Function Documentation

◆ sys_time_register_source()

uint64_t sys_time_register_source ( const sys_time_source_t source)

Register a system timer source.

Parameters
sourceThe timer source to register.
Returns
On success, 0. On failure, ERR and errno is set.

Definition at line 35 of file sys_time.c.

References bestSource, EINVAL, ENOSPC, ERR, errno, LOG_INFO, sys_time_source_t::name, NULL, sys_time_source_t::precision, sys_time_source_t::read, rwlock_write_acquire(), rwlock_write_release(), source, sourceCount, sources, sourcesLock, and SYS_TIME_MAX_SOURCES.

Referenced by hpet_init().

◆ sys_time_unix_epoch()

time_t sys_time_unix_epoch ( void  )

The unix epoch.

Returns
The amount of seconds since the unix epoch.

Definition at line 117 of file sys_time.c.

References bootEpoch, bootEpochInitialized, CLOCKS_PER_SEC, sys_time_uptime(), and timer_boot_epoch_init().

Referenced by inode_new(), inode_notify_access(), inode_notify_change(), inode_notify_modify(), and SYSCALL_DEFINE().

◆ sys_time_unregister_source()

void sys_time_unregister_source ( const sys_time_source_t source)

Unregister a system timer source.

Parameters
sourceThe timer source to unregister.

Definition at line 67 of file sys_time.c.

References bestSource, LOG_INFO, memmove(), sys_time_source_t::name, NULL, panic(), rwlock_write_acquire(), rwlock_write_release(), source, sourceCount, sources, and sourcesLock.

Referenced by hpet_deinit().

◆ sys_time_uptime()

◆ sys_time_wait()

void sys_time_wait ( clock_t  nanoseconds)

Wait for a specified number of nanoseconds.

This function uses a busy-wait loop, making it highly CPU inefficient, but its useful during early initialization or when you are unable to block the current thread.

Parameters
nanosecondsThe number of nanoseconds to wait

Definition at line 127 of file sys_time.c.

References NULL, panic(), start(), and sys_time_uptime().

Referenced by apic_timer_ticks_per_ns(), ps2_device_init(), ps2_drain(), trampoline_send_startup_ipi(), and trampoline_wait_ready().