CHERIoT RTOS
A compartmentalised RTOS for CHERIoT hardware
Loading...
Searching...
No Matches
timeout.h File Reference

This file contains the types used for timeouts across scheduler APIs. More...

#include <cdefs.h>
#include <cheri-builtins.h>
#include <platform-time.h>
#include <stdint.h>

Go to the source code of this file.

Classes

struct  Timeout
 Structure representing a timeout. More...

Typedefs

typedef uint32_t Ticks
 Quantity used for measuring time for timeouts.
typedef uint64_t AbsoluteMonotonicTimeout
 Type used for absolute timeouts.
typedef struct Timeout Timeout
 Structure representing a timeout.

Functions

union __if_c () __TimeoutArgument
 A union to hold timeouts that are passed down to end up in the scheduler.
bool __cheri_libcall check_timeout_pointer (const struct Timeout *timeout)
 Check that the argument is a valid pointer to a Timeout structure.
 __if_c (static) inline bool timeout_is_relative(TimeoutArgument timeout)
 Helper to determine whether a timeout's relativeTimeout alternative is the active one.
bool __cheriot_libcall timeout_is_valid (TimeoutArgument timeout)
 Returns true if this is a valid TimeoutArgument: either an untagged value or a valid pointer to a Timeout.
bool __cheriot_libcall timeout_has_expired (TimeoutArgument timeout)
 Returns true if the timeout is in the past (for relative timeouts, if there is no remaining time), false otherwise.
void __cheriot_libcall timeout_elapse (TimeoutArgument timeout, Ticks ticks)
 If this is a relative timeout, elapse the specified number of ticks.

Variables

static const Ticks UnlimitedTimeout = UINT32_MAX
 Value indicating an unbounded timeout for use with Timeout.
static const AbsoluteMonotonicTimeout TimeoutWaitForever
 Timeout value for unlimited blocking.
static const AbsoluteMonotonicTimeout TimeoutNoWait = 0
 Timeout value for not blocking.
 TimeoutArgument
Timeoutsource

Detailed Description

This file contains the types used for timeouts across scheduler APIs.

Definition in file timeout.h.

Typedef Documentation

◆ AbsoluteMonotonicTimeout

typedef uint64_t AbsoluteMonotonicTimeout

Type used for absolute timeouts.

These are times against the platform-specific uptime timer.

Definition at line 28 of file timeout.h.

◆ Ticks

typedef uint32_t Ticks

Quantity used for measuring time for timeouts.

The unit is scheduler ticks.

Definition at line 19 of file timeout.h.

◆ Timeout

typedef struct Timeout Timeout

Structure representing a timeout.

This is intended to allow a single instance to be chained across blocking calls.

Timeouts may not be stored in the heap. Handling timeout structures that may disappear between sleeping and waking is very complicated and would impact a lot of fast paths. Instead, most functions that take a timeout will simply fail if the timeout is on the heap.

Function Documentation

◆ __if_c() [1/2]

union __if_c ( )

A union to hold timeouts that are passed down to end up in the scheduler.

These are one of two things:

  • An absolute timeout, measured in cycles of some platform-specific timer (such as the mtime register) that increments at predictable rate.
  • A relative timeout counted in elapsed scheduler ticks.

This is a tagged union, with the CHERI tag bit used to differentiate between the two cases.

An absolute timeout.

A relative timeout.

Permit implicit construction from absolute timeouts.

Permit implicit construction from relative timeouts.

Returns true if this is a relative timeout, false otherwise.

Returns true if this is a valid timeout, false otherwise.

Returns true if the timeout is in the future (and therefore may still block), false otherwise.

If this is a relative timeout, elapse the specified number of ticks. Otherwise, do nothing.

Take any ticks that have been counted towards source and apply it to destination. If destination is not a tick-counting relative timeout, do nothing.

This is intended for short-yielding operations, where a compartment wishes to yield for a small amount of time (typically one tick) and then retry some operation, rather than waiting for the whole time that the caller has allowed them to wait. The caller-provided timeout may be relative or absolute, but the timeout for the short sleep is local to the compartment doing the short sleep and so is always a Timeout.

Definition at line 35 of file timeout.h.

References TimeoutNoWait.

Referenced by run_once().

◆ __if_c() [2/2]

__if_c ( static )

Helper to determine whether a timeout's relativeTimeout alternative is the active one.

Take any ticks that have been counted towards source and apply it to destination.

Returns true if the timeout is in the future (and therefore may still block), false otherwise.

If destination is not a tick-counting relative timeout, do nothing.

This is intended for short-yielding operations, where a compartment wishes to yield for a small amount of time (typically one tick) and then retry some operation, rather than waiting for the whole time that the caller has allowed them to wait. The caller-provided timeout may be relative or absolute, but the timeout for the short sleep is local to the compartment doing the short sleep and so is always a Timeout.

Definition at line 200 of file timeout.h.

◆ check_timeout_pointer()

bool __cheri_libcall check_timeout_pointer ( const struct Timeout * timeout)

Check that the argument is a valid pointer to a Timeout structure.

This must have read/write permissions, be unsealed, and must not be a heap address.

This function is not recommended for new code. The more general timeout_is_valid call checks that this is a valid timeout argument.

◆ timeout_elapse()

void __cheriot_libcall timeout_elapse ( TimeoutArgument timeout,
Ticks ticks )

If this is a relative timeout, elapse the specified number of ticks.

Otherwise, do nothing.

Variable Documentation

◆ source

Timeout* source
Initial value:
{
timeout_elapse(destination, source->elapsed)
void __cheriot_libcall timeout_elapse(TimeoutArgument timeout, Ticks ticks)
If this is a relative timeout, elapse the specified number of ticks.

Definition at line 245 of file timeout.h.

◆ TimeoutArgument

TimeoutArgument

Definition at line 181 of file timeout.h.

◆ TimeoutNoWait

const AbsoluteMonotonicTimeout TimeoutNoWait = 0
static

Timeout value for not blocking.

Definition at line 35 of file timeout.h.

Referenced by __if_c().

◆ TimeoutWaitForever

const AbsoluteMonotonicTimeout TimeoutWaitForever
static
Initial value:
=
0xffff'ffff'ffff'ffff

Timeout value for unlimited blocking.

Definition at line 31 of file timeout.h.

Referenced by futex_wait(), and heap_quarantine_empty().

◆ UnlimitedTimeout