fplayer
C99 Falcon Sequence (fseq) file player for Light-O-Rama hardware (like xLights)
|
Adaptive sleep time controller implementation. More...
#include "sleep.h"
#include <assert.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include "std2/errcode.h"
Data Structures | |
struct | sleep_coll_s |
Sleep collector structure for providing historical sleep performance data to better estimate sleep times. More... | |
Macros | |
#define | SLEEP_COLL_SAMPLE_COUNT 20 |
Number of sleep time samples to store in the sleep collector. | |
Functions | |
int | Sleep_init (struct sleep_coll_s **coll) |
Allocates and initializes a new sleep collector with default values. | |
static void | Sleep_record (struct sleep_coll_s *coll, const int64_t ns) |
Appends the given sleep time to the sleep collector, updating the collector's internal state. This should be called after each sleep operation to provide historical data for better sleep time estimation. Once full, the collector will overwrite the oldest sleep time. | |
int64_t | Sleep_average (const struct sleep_coll_s *coll) |
Returns the average sleep time in nanoseconds from the given sleep collector. This is calculated by summing all sleep times in the collector and dividing by the number of samples. | |
static void | Sleep_oneMilli (void) |
Sleeps for one millisecond using the system's equivalent sleep function. This is used to provide a baseline for sleep time estimation. | |
static void | Sleep_step (const int64_t ns) |
Sleeps for the given number of nanoseconds using incremental sleep calls that estimate the time remaining to sleep using historical sleep data. | |
static void | Sleep_spinLock (const int64_t ns) |
Sleeps for the given number of nanoseconds using a spin lock. This is a blocking operation that will consume CPU cycles until the given time has elapsed. | |
void | Sleep_do (struct sleep_coll_s *coll, const uint32_t ms) |
Sleeps for the given number of milliseconds using incremental sleep calls that estimate the time remaining to sleep using historical sleep data. The remaining sleep time is performed using a primitive spin lock to ensure the executed sleep time is accurate. | |
Adaptive sleep time controller implementation.
#define SLEEP_COLL_SAMPLE_COUNT 20 |
Number of sleep time samples to store in the sleep collector.
int64_t Sleep_average | ( | const struct sleep_coll_s * | coll | ) |
Returns the average sleep time in nanoseconds from the given sleep collector. This is calculated by summing all sleep times in the collector and dividing by the number of samples.
coll | target sleep collector |
void Sleep_do | ( | struct sleep_coll_s * | coll, |
uint32_t | ms ) |
Sleeps for the given number of milliseconds using incremental sleep calls that estimate the time remaining to sleep using historical sleep data. The remaining sleep time is performed using a primitive spin lock to ensure the executed sleep time is accurate.
coll | target sleep collector for recording historical sleep data |
ms | number of milliseconds to sleep |
int Sleep_init | ( | struct sleep_coll_s ** | coll | ) |
Allocates and initializes a new sleep collector with default values.
coll | target sleep collector |
|
inlinestatic |
Sleeps for one millisecond using the system's equivalent sleep function. This is used to provide a baseline for sleep time estimation.
|
static |
Appends the given sleep time to the sleep collector, updating the collector's internal state. This should be called after each sleep operation to provide historical data for better sleep time estimation. Once full, the collector will overwrite the oldest sleep time.
coll | target sleep collector |
ns | sleep time in nanoseconds |
|
static |
Sleeps for the given number of nanoseconds using a spin lock. This is a blocking operation that will consume CPU cycles until the given time has elapsed.
ns | number of nanoseconds to sleep |
|
static |
Sleeps for the given number of nanoseconds using incremental sleep calls that estimate the time remaining to sleep using historical sleep data.
ns | number of nanoseconds to sleep |