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

Standard clock support. More...

#include <platform-time.h>
#include <stdint.h>
#include <sys/time.h>
#include <thread.h>

Go to the source code of this file.

Classes

struct  timespec
 A time value with up to nanosecond precision. More...
struct  tm
 Structure representing a date in the Gregorian calendar. More...

Macros

#define CLOCKS_PER_SEC   ((clock_t)CPU_TIMER_HZ)
 The number of ticks on the monotonic clock per second.
#define TIMER_ABSTIME   1
 Flag to indicate that a timespec should be treated as an absolute, rather than relative, time.

Typedefs

typedef enum __clockid_t clockid_t
 ID for a clock. Only monotonic and 'realtime' (wall clock) are supported.
typedef uint64_t clock_t
 Type for holding time.

Enumerations

enum  __clockid_t { CLOCK_MONOTONIC , CLOCK_REALTIME , CLOCK_THREAD_CPUTIME_ID , CLOCK_PROCESS_CPUTIME_ID = CLOCK_THREAD_CPUTIME_ID }
 ID for a clock. Only monotonic and 'realtime' (wall clock) are supported. More...

Functions

static clock_t clock (void)
 Returns the amount of CPU time (in units defined by CLOCKS_PER_SEC) that are accounted to the current thread (POSIX specifies 'process' here, but CHERIoT RTOS does not have an directly analogous abstraction).
__cheriot_libcall int clock_gettime (clockid_t clockID, struct timespec *outTime)
 Retrieve the time from the specified clock as a timespec.
 __cheriot_compartment ("wall_clock") int clock_update_wall_clock(TimeoutArgument timeout)
 Update the wall-clock time from available time sources.
__cheriot_libcall time_t time (time_t *tloc)
 POSIX-compatible time() implementation.
time_t __cheriot_libcall timegm (struct tm *time)
 Convert a struct tm to a time_t.
struct tm *__cheriot_libcall gmtime_r (const time_t *__restrict timer, struct tm *__restrict result)
 C standard function to calculate a human-readable UTC date and time in a struct tm from a UNIX timestamp passed indirectly as timer.
static struct tmgmtime (const time_t *timer)
 C standard function to calculate a human-readable UTC date and time in a struct tm from a UNIX timestamp.

Detailed Description

Standard clock support.

Definition in file time.h.

Macro Definition Documentation

◆ CLOCKS_PER_SEC

#define CLOCKS_PER_SEC   ((clock_t)CPU_TIMER_HZ)

The number of ticks on the monotonic clock per second.

Definition at line 56 of file time.h.

◆ TIMER_ABSTIME

#define TIMER_ABSTIME   1

Flag to indicate that a timespec should be treated as an absolute, rather than relative, time.

Definition at line 62 of file time.h.

Typedef Documentation

◆ clock_t

typedef uint64_t clock_t

Type for holding time.

The CLOCKS_PER_SEC macro defines the value in this type that corresponds to one second. This rate is SoC-specific.

Definition at line 68 of file time.h.

Enumeration Type Documentation

◆ __clockid_t

ID for a clock. Only monotonic and 'realtime' (wall clock) are supported.

Enumerator
CLOCK_MONOTONIC 

The monotonic clock.

This is zero at system start and increments at a fixed rate.

CLOCK_REALTIME 

The wall-clock time.

This clock's value is meaningful only if clock_update_wall_clock has been called at least once and there is at least one working clock source in the system.

CLOCK_THREAD_CPUTIME_ID 

CPU time consumed by the current thread, since boot time.

This clock is equivalent to CLOCK_MONOTONIC if the scheduler is not compiled with support for accounting. Add --scheduler-accounting=y to your build configuration line to enable this.

CLOCK_PROCESS_CPUTIME_ID 

CPU time consumed by the current 'process'.

This value is defined by POSIX, but CHERIoT RTOS does not have a direct equivalent of a process and so this value is equivalent to CLOCK_THREAD_CPUTIME_ID, with all of the attendant caveats.

Definition at line 22 of file time.h.

Function Documentation

◆ clock()

clock_t clock ( void )
inlinestatic

Returns the amount of CPU time (in units defined by CLOCKS_PER_SEC) that are accounted to the current thread (POSIX specifies 'process' here, but CHERIoT RTOS does not have an directly analogous abstraction).

Note: If scheduler accounting is not enabled, this API will return the total elapsed uptime instead. Add --scheduler-accounting=y to your build configuration line to enable this.

Definition at line 99 of file time.h.

References thread_elapsed_cycles_current().

◆ clock_gettime()

__cheriot_libcall int clock_gettime ( clockid_t clockID,
struct timespec * outTime )

Retrieve the time from the specified clock as a timespec.

If clockID is CLOCK_REALTIME, the returned value is meaningful only if clock_update_wall_clock has been called at least once and there is at least one working clock source in the system.

◆ gmtime()

struct tm * gmtime ( const time_t * timer)
inlinestatic

C standard function to calculate a human-readable UTC date and time in a struct tm from a UNIX timestamp.

This uses an internal buffer that is invalidated on each subsequent call and is not thread safe. gmtime_r should be used instead.

Definition at line 207 of file time.h.

References gmtime_r().

◆ gmtime_r()

struct tm *__cheriot_libcall gmtime_r ( const time_t *__restrict timer,
struct tm *__restrict result )

C standard function to calculate a human-readable UTC date and time in a struct tm from a UNIX timestamp passed indirectly as timer.

The result argument is used to provide space for the output. The return value is result, or an untagged value if an error occurs.

Referenced by gmtime().

◆ time()

__cheriot_libcall time_t time ( time_t * tloc)

POSIX-compatible time() implementation.

Returns the time in seconds since the UNIX epoch.

This value is meaningful only if clock_update_wall_clock has been called at least once and there is at least one working clock source in the system.

References time().

Referenced by Timeout::elapse(), time(), timegm(), and Timeout::Timeout().

◆ timegm()

time_t __cheriot_libcall timegm ( struct tm * time)

Convert a struct tm to a time_t.

This is intended to be compatible with the BSD extension and is equivalent to the POSIX mktime with a UTC locale.

The tm_wday and tm_yday fields are ignored as inputs. Other fields may be out of range, for example an hour of -1 means hour 22 in the previous day, a day of 40 in a month with 31 days means day 9 in the next month, and so on.

The values of the tm_wday and tm_yday fields will be set on successful completion.

NOTE: UNIX time stamps do not include leap seconds. If a leap second (the 60th second at the end of June or December in a year that contains one) is specified in time, it will be treated as an overflow and the result of this function will be off by one.

References time().