From 22d49a13f4c95b864fa5740f1cb6826e74ab512c Mon Sep 17 00:00:00 2001 From: Efsane Soyer Date: Wed, 27 Mar 2024 17:15:26 -0700 Subject: [PATCH 1/2] made MIN_SLEEP_DURATION a platform property based on clk res --- core/threaded/reactor_threaded.c | 2 ++ include/core/reactor_common.h | 2 +- low_level_platform/api/platform/lf_unix_clock_support.h | 2 ++ low_level_platform/impl/src/lf_unix_clock_support.c | 3 +++ 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/core/threaded/reactor_threaded.c b/core/threaded/reactor_threaded.c index e364675d6..62eaef6c2 100644 --- a/core/threaded/reactor_threaded.c +++ b/core/threaded/reactor_threaded.c @@ -28,6 +28,8 @@ #include "reactor_common.h" #include "watchdog.h" +#include "platform/lf_unix_clock_support.h" + #ifdef FEDERATED #include "federate.h" #endif diff --git a/include/core/reactor_common.h b/include/core/reactor_common.h index fc1451a96..3e0ec1a38 100644 --- a/include/core/reactor_common.h +++ b/include/core/reactor_common.h @@ -42,7 +42,7 @@ * to prevent unnecessary delays caused by simply setting up and * performing the wait. */ -#define MIN_SLEEP_DURATION USEC(10) +// #define MIN_SLEEP_DURATION USEC(10) ////////////////////// Global Variables ////////////////////// diff --git a/low_level_platform/api/platform/lf_unix_clock_support.h b/low_level_platform/api/platform/lf_unix_clock_support.h index 0a2c80163..ca6c4e033 100644 --- a/low_level_platform/api/platform/lf_unix_clock_support.h +++ b/low_level_platform/api/platform/lf_unix_clock_support.h @@ -1,6 +1,8 @@ #include #include +extern instant_t MIN_SLEEP_DURATION; + /** * @brief Convert a _lf_time_spec_t ('tp') to an instant_t representation in * nanoseconds. diff --git a/low_level_platform/impl/src/lf_unix_clock_support.c b/low_level_platform/impl/src/lf_unix_clock_support.c index b9c9fae56..30881408e 100644 --- a/low_level_platform/impl/src/lf_unix_clock_support.c +++ b/low_level_platform/impl/src/lf_unix_clock_support.c @@ -6,6 +6,8 @@ #include "logging.h" #include "platform/lf_unix_clock_support.h" +instant_t MIN_SLEEP_DURATION; + instant_t convert_timespec_to_ns(struct timespec tp) { return ((instant_t)tp.tv_sec) * BILLION + tp.tv_nsec; } struct timespec convert_ns_to_timespec(instant_t t) { @@ -23,6 +25,7 @@ void _lf_initialize_clock() { } lf_print("---- System clock resolution: %ld nsec", res.tv_nsec); + MIN_SLEEP_DURATION = NSEC(res.tv_nsec); } /** From 0fc0a407596a03886c5bba4c4d98eb520f49c7ba Mon Sep 17 00:00:00 2001 From: Efsane Soyer Date: Wed, 27 Mar 2024 18:35:38 -0700 Subject: [PATCH 2/2] Busy wait if the wait time < MIN_SLEEP_DURATION --- core/threaded/reactor_threaded.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/threaded/reactor_threaded.c b/core/threaded/reactor_threaded.c index 62eaef6c2..7d1a34812 100644 --- a/core/threaded/reactor_threaded.c +++ b/core/threaded/reactor_threaded.c @@ -241,6 +241,9 @@ bool wait_until(instant_t logical_time, lf_cond_t* condition) { if (wait_duration < MIN_SLEEP_DURATION) { LF_PRINT_DEBUG("Wait time " PRINTF_TIME " is less than MIN_SLEEP_DURATION " PRINTF_TIME ". Skipping wait.", wait_duration, MIN_SLEEP_DURATION); + while (lf_time_physical() < wait_until_time) { + //Busy wait + } return true; }