Kernel internals providing services of delayed and periodic execution.
More...
Kernel internals providing services of delayed and periodic execution.
◆ TIMER_INVALID_ID
#define TIMER_INVALID_ID 0xFF |
◆ eSleepType
Enumerator |
---|
TIMER_SLEEP | |
TIMER_TIMEOUT | |
TIMER_PERIODIC | |
TIMER_INTERVAL | |
◆ delay_us()
static void delay_us |
( |
uint32_t |
period_us | ) |
|
|
static |
Perform short busy wait.
This will perform busywait in the context of current thread. Useful to do short waits for I/O.
- Parameters
-
period_us | how long the wait should take |
◆ do_set_timed_event()
static int do_set_timed_event |
( |
Txn_t |
txn, |
|
|
unsigned |
slot, |
|
|
unsigned |
interval, |
|
|
enum eSleepType |
type |
|
) |
| |
|
static |
Perform heavy lifting of setting timers This routine will store timed event into list of timed events.
If event is not periodic, it will also stop thread (os_usleep semantics).
- Parameters
-
txn | transaction used to modify the table |
slot | number of slot in sleepers list |
interval | amount of us for which thread should sleep |
type | type of timer to set up |
- Returns
- 0 if timer was set up properly
◆ get_sleep_time()
static uint32_t get_sleep_time |
( |
uint32_t |
sleep_from, |
|
|
uint32_t |
microtime |
|
) |
| |
|
static |
Helper function to calculate time considering type wraparound.
This function will calculate the final time considering timer wraparound.
- Parameters
-
sleep_from | time at which the sleep starts (microseconds) |
microtime | duration of sleep (microseconds) |
- Returns
- new value of kernel timer at the end of sleep
◆ get_sleeptime()
static unsigned get_sleeptime |
( |
const unsigned |
interval | ) |
|
|
static |
Get how long the sleep should take.
Will clean the periodicity flag from interval.
- Returns
- sleep time in microseconds.
◆ is_periodic()
Determine if interval in sleep entry is periodic or not.
- Returns
- 1 if interval is periodic, 0 if interval is one-shot.
◆ os_cancel_sleeper()
int os_cancel_sleeper |
( |
int |
sleeper | ) |
|
Cancel existing sleeper.
This function will cancel existing sleeper. It is useful for cases where you already know the identity of the sleeper in advance.
- Parameters
-
sleeper | ID of the sleeper being cancelled |
- Returns
- 0 is operation performed successfully
◆ os_cancel_timed_event()
Cancels existing timed event.
This function is only accessible for periodic timers externally. It allows cancelling of interval timers set previously.
- Parameters
-
owner | thread which shall own the interval timer |
type | type of the event to be cancelled |
- Returns
- 0 if operation performed successfully.
◆ os_cpu_freq_get()
uint32_t os_cpu_freq_get |
( |
void |
| ) |
|
Get current CPU frequency.
Will return the current CPU frequency (if known and/or available).
- Returns
- CPU frequency in Hz, 0 if value is not known.
◆ os_find_timer()
Find a timer slot matchin owner thread and timer type.
This will find a slot which bears the timer of given type for given thread.
- Parameters
-
[in] | owner | thread ID which should own the timer |
[in] | type | type of the timer. |
◆ os_run_timer()
void os_run_timer |
( |
uint32_t |
microtime | ) |
|
Fire scheduled event.
Will find and run scheduled event.
- Parameters
-
microtime | current processor time in microseconds |
◆ os_schedule_timer()
bool os_schedule_timer |
( |
unsigned * |
delay | ) |
|
Provide information on next scheduled event.
This function informs caller about delay until next scheduled event. Next scheduled event may be either wake-up of sleeped thread, or interval timer.
- Parameters
-
[out] | delay | address of buffer, where delay to next scheduled event will be written |
- Returns
- true if there is any scheduled event known and at address pointed to by delay value was written. Returns false if there is no known scheduled event. In such case content of memory pointed to by delay is undefined.
◆ os_set_timed_event()
int os_set_timed_event |
( |
unsigned |
microseconds, |
|
|
enum eSleepType |
type |
|
) |
| |
Find a slot for timed event and store it.
This is actual execution core for both os_usleep and os_setitimer functions. It will find free slot or slot already occupied by calling thread and will set / update timeout values.
- Parameters
-
microseconds | time for which thread should sleep / wait for event |
type | type of timed event to set up |
- Returns
- error status. 0 means no error.
◆ os_setitimer()
int os_setitimer |
( |
unsigned |
microseconds | ) |
|
◆ os_timer_init()
This routine initializes kernel scheduling subsystem.
It is necessary to call this routine before first call to either timer syscalls, or os_run_timer otherwise things will go wrong.
◆ os_usleep()
int os_usleep |
( |
unsigned |
microseconds | ) |
|
Kernel implementation of usleep() syscall.
See usleep for details on arguments.
◆ sleepers
List of all delays requested from kernel.
This structure contains all scheduled sleeps requested by all threads. Every thread can technically request one periodic timer and one one-shot delay.