PatchworkOS  966e257
A non-POSIX operating system.
Loading...
Searching...
No Matches
Clock subsystem.

Clock subsystem. More...

Collaboration diagram for Clock subsystem.:

Detailed Description

Clock subsystem.

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

System wide time is provided via "clock sources", which are provided in modules. Each source registers itself with a estimate of its precision, the clock subsystem then chooses the two sources, one for uptime and one for unix epoch, with the best precision.

Data Structures

struct  clock_source_t
 Clock source structure. More...
 

Macros

#define CLOCK_MAX_SOURCES   8
 Maximum amount of system timer sources.
 

Functions

uint64_t clock_source_register (const clock_source_t *source)
 Register a system timer source.
 
void clock_source_unregister (const clock_source_t *source)
 Unregister a system timer source.
 
clock_t clock_uptime (void)
 Retrieve the time in nanoseconds since boot.
 
time_t clock_epoch (void)
 Retrieve the seconds since the unix epoch.
 
void clock_wait (clock_t nanoseconds)
 Wait for a specified number of nanoseconds.
 

Macro Definition Documentation

◆ CLOCK_MAX_SOURCES

#define CLOCK_MAX_SOURCES   8

Maximum amount of system timer sources.

Definition at line 26 of file clock.h.

Function Documentation

◆ clock_source_register()

uint64_t clock_source_register ( const clock_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 to:
  • EINVAL: Invalid parameters.
  • ENOSPC: No more timer sources can be registered.

Definition at line 47 of file clock.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clock_source_unregister()

void clock_source_unregister ( const clock_source_t source)

Unregister a system timer source.

Parameters
sourceThe timer source to unregister, or NULL for no-op.

Definition at line 72 of file clock.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clock_uptime()

clock_t clock_uptime ( void  )

Retrieve the time in nanoseconds since boot.

Returns
The time in nanoseconds since boot.

Definition at line 99 of file clock.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clock_epoch()

time_t clock_epoch ( void  )

Retrieve the seconds since the unix epoch.

Returns
The amount of seconds since the unix epoch.

Definition at line 119 of file clock.c.

Here is the caller graph for this function:

◆ clock_wait()

void clock_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 130 of file clock.c.

Here is the call graph for this function:
Here is the caller graph for this function: