The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
timer.h File Reference

Go to the source code of this file.

Data Structures

struct  timed_queue
 a wait queue with a deadline. More...

Macros

#define TIMER_HZ   PIT_FREQUENCY_HZ
 kernel timing: the tick count and wait queues with a deadline.
#define TIMER_NEVER   UINT64_MAX
#define TIMER_POLL_HOOKS   6

Typedefs

typedef struct timed_queue timed_queue_t
 a wait queue with a deadline.
typedef void(*) timer_poll_fn(uint64_t now)
 a function the timer interrupt calls on every tick (now: the tick count).

Functions

void timed_queue_init (timed_queue_t *queue)
 set up a queue and add it to the ones timer_tick checks.
void timed_queue_block (timed_queue_t *queue, uint64_t deadline)
 sleep on a queue until it is woken or the deadline tick has come.
void timed_queue_block_interruptible (timed_queue_t *queue, uint64_t deadline)
 like timed_queue_block, but a signal for the process also wakes it.
void timed_queue_block_locked (timed_queue_t *queue, uint64_t deadline, spinlock_t *lock)
 sleep on a queue until it is woken or the deadline tick has come, with a spinlock released while asleep and held again on return.
void timed_queue_block_locked_interruptible (timed_queue_t *queue, uint64_t deadline, spinlock_t *lock)
 like timed_queue_block_locked, but a signal for the process also wakes it.
void timed_queue_wait_word (timed_queue_t *queue, uint64_t deadline, const volatile uint32_t *word, uint32_t seen)
 sleep on a queue while a counter has the value the caller saw, until it is woken, the deadline tick comes or a signal arrives.
void timed_queue_wake_all (timed_queue_t *queue)
 wake every waiter of a queue (they re-check their condition).
void timer_tick (uint64_t now)
 called from the timer interrupt on every tick: wake the queues whose earliest deadline has passed.
void timer_add_poll_hook (timer_poll_fn fn)
 call fn on every tick, in the timer interrupt (interrupts off).
uint64_t timer_now (void)
 the current tick.
uint64_t timer_ms_to_ticks (uint32_t ms)
 the number of ticks that covers at least a time span (rounded up).

Macro Definition Documentation

◆ TIMER_HZ

#define TIMER_HZ   PIT_FREQUENCY_HZ

kernel timing: the tick count and wait queues with a deadline.

the PIT interrupts TIMER_HZ times a second; each interrupt is one tick. a timed queue is a wait queue that a waiter can also leave when a given tick arrives. the timer interrupt wakes every waiter of a queue when the earliest deadline on it has passed; the waiters then check their own deadline and condition, and sleep again if they still have to wait.

◆ TIMER_NEVER

#define TIMER_NEVER   UINT64_MAX

◆ TIMER_POLL_HOOKS

#define TIMER_POLL_HOOKS   6

Typedef Documentation

◆ timed_queue_t

typedef struct timed_queue timed_queue_t

a wait queue with a deadline.

◆ timer_poll_fn

typedef void(*) timer_poll_fn(uint64_t now)

a function the timer interrupt calls on every tick (now: the tick count).

Function Documentation

◆ timed_queue_init()

void timed_queue_init ( timed_queue_t * queue)

set up a queue and add it to the ones timer_tick checks.

call once per queue (queues live as long as the kernel).

Parameters
queuethe queue.

◆ timed_queue_block()

void timed_queue_block ( timed_queue_t * queue,
uint64_t deadline )

sleep on a queue until it is woken or the deadline tick has come.

for a wait on time only: a wake between the caller's check and the sleep is lost. the caller re-checks the deadline after waking.

Parameters
queuethe queue.
deadlinethe tick to wake at, or TIMER_NEVER.

◆ timed_queue_block_interruptible()

void timed_queue_block_interruptible ( timed_queue_t * queue,
uint64_t deadline )

like timed_queue_block, but a signal for the process also wakes it.

◆ timed_queue_block_locked()

void timed_queue_block_locked ( timed_queue_t * queue,
uint64_t deadline,
spinlock_t * lock )

sleep on a queue until it is woken or the deadline tick has come, with a spinlock released while asleep and held again on return.

the caller tests its condition with the lock held, and the waker takes the lock to change it, so a wake between the test and the sleep is not lost.

Parameters
queuethe queue.
deadlinethe tick to wake at, or TIMER_NEVER.
locka lock taken with spin_lock_irqsave() by the caller.

◆ timed_queue_block_locked_interruptible()

void timed_queue_block_locked_interruptible ( timed_queue_t * queue,
uint64_t deadline,
spinlock_t * lock )

like timed_queue_block_locked, but a signal for the process also wakes it.

◆ timed_queue_wait_word()

void timed_queue_wait_word ( timed_queue_t * queue,
uint64_t deadline,
const volatile uint32_t * word,
uint32_t seen )

sleep on a queue while a counter has the value the caller saw, until it is woken, the deadline tick comes or a signal arrives.

a waker changes the counter, then wakes the queue: a change before the sleep is seen, a later one finds the process asleep. for waits on many things at once (poll), where no one lock guards the condition.

Parameters
queuethe queue.
deadlinethe tick to wake at, or TIMER_NEVER.
wordthe counter.
seenthe value the caller read before it tested its condition.

◆ timed_queue_wake_all()

void timed_queue_wake_all ( timed_queue_t * queue)

wake every waiter of a queue (they re-check their condition).

Parameters
queuethe queue.

◆ timer_tick()

void timer_tick ( uint64_t now)

called from the timer interrupt on every tick: wake the queues whose earliest deadline has passed.

Parameters
nowthe current tick.

◆ timer_add_poll_hook()

void timer_add_poll_hook ( timer_poll_fn fn)

call fn on every tick, in the timer interrupt (interrupts off).

for drivers that poll their device, such as the USB keyboard. there is room for TIMER_POLL_HOOKS functions; more are ignored.

◆ timer_now()

uint64_t timer_now ( void )

the current tick.

◆ timer_ms_to_ticks()

uint64_t timer_ms_to_ticks ( uint32_t ms)

the number of ticks that covers at least a time span (rounded up).

Parameters
msmilliseconds.
Returns
ticks.