11#include <compartment.h>
15#include <tick_macros.h>
28 __cheri_compartment(
"scheduler") thread_systemtick_get(
void);
67[[cheriot::interrupt_state(disabled)]]
int __cheri_compartment(
"scheduler")
68 thread_sleep(TimeoutArgument timeout, uint32_t flags __if_cxx(= 0));
128 static const uint32_t CyclesPerMicrosecond = CPU_TIMER_HZ / 1'000'000;
130 static_assert(CyclesPerMicrosecond > 0,
"CPU_TIMER_HZ is too low"););
131 uint64_t start = rdcycle64();
134 uint32_t cycles = microseconds * CyclesPerMicrosecond;
135 uint64_t end = start + cycles;
139 current = rdcycle64();
140 }
while (current < end);
141 return (current - start) * CyclesPerMicrosecond;
161 static const uint32_t CyclesPerMillisecond = CPU_TIMER_HZ / 1'000;
162 static const uint32_t CyclesPerTick = CPU_TIMER_HZ / TICK_RATE_HZ;
164 static_assert(CyclesPerMillisecond > 0,
"CPU_TIMER_HZ is too low"););
165 uint32_t cycles = milliseconds * CyclesPerMillisecond;
166 uint64_t start = rdcycle64();
167 uint64_t end = start + cycles;
168 uint64_t current = start;
169 while ((end > current) && (end - current > MS_PER_TICK))
171 Timeout t = {0, ((uint32_t)(end - current)) / CyclesPerTick};
173 current = rdcycle64();
176 while (current < end)
178 current = rdcycle64();
180 current = rdcycle64();
181 return (current - start) / CyclesPerMillisecond;
197 void *csp = __builtin_cheri_stack_get();
198 ptraddr_t top = __builtin_cheri_top_get(csp);
199 return (
void **)__builtin_cheri_bounds_set_exact(
200 __builtin_cheri_address_set(csp, top - (index + 1) *
sizeof(
void *)),
215template<
typename T,
size_t Index = 1>
218 static_assert((Index == 0) || (Index == 1),
"Bad invocation state slot");
the absolute system tick value since boot, 64-bit, assuming never overflows
uint32_t lo
low 32 bits of the system tick
Structure representing a timeout.
uint64_t thread_elapsed_cycles_current(void)
Returns the number of cycles accounted to the current thread.
static void ** invocation_state_slot(size_t index)
Compute a pointer to a Compartment-Invocation-Local Storage slot.
static uint64_t thread_microsecond_spin(uint32_t microseconds)
Wait for the specified number of microseconds.
int thread_sleep(TimeoutArgument timeout, uint32_t flags)
Sleep for at most the specified timeout (see timeout.h).
uint64_t thread_elapsed_cycles_idle(void)
Returns the number of cycles accounted to the idle thread.
@ ThreadSleepNoEarlyWake
Sleep for up to the specified timeout, but wake early if there are no other runnable threads.
uint16_t thread_count()
Returns the number of user threads (that is, those defined in the xmake firmware configuration),...
uint16_t __cheri_libcall thread_id_get(__if_c(void))
Return the thread ID of the current running thread.
static uint64_t thread_millisecond_wait(uint32_t milliseconds)
Wait for the specified number of milliseconds.
T *& invocation_state()
Return a typed reference to a Compartment-Invocation-Local Storage slot.
This file contains the types used for timeouts across scheduler APIs.