Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making MIN_SLEEP_DURATION a platform variable and Add busy wait #403

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions core/threaded/reactor_threaded.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "reactor_common.h"
#include "watchdog.h"

#include "platform/lf_unix_clock_support.h"

#ifdef FEDERATED
#include "federate.h"
#endif
Expand Down Expand Up @@ -239,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);
Comment on lines 242 to 243
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This debug message is no longer accurate. Please update.

while (lf_time_physical() < wait_until_time) {
//Busy wait
}
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion include/core/reactor_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We prefer to just remove code rather than commenting it out.


////////////////////// Global Variables //////////////////////

Expand Down
2 changes: 2 additions & 0 deletions low_level_platform/api/platform/lf_unix_clock_support.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <time.h>
#include <errno.h>

extern instant_t MIN_SLEEP_DURATION;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest renaming lf_min_sleep_duration. Our convention uses upper case for #define constantsand the prefixlf_` for all variables whose scope extends beyond one file.


/**
* @brief Convert a _lf_time_spec_t ('tp') to an instant_t representation in
* nanoseconds.
Expand Down
3 changes: 3 additions & 0 deletions low_level_platform/impl/src/lf_unix_clock_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "logging.h"
#include "platform/lf_unix_clock_support.h"

instant_t MIN_SLEEP_DURATION;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment.


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) {
Expand All @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation does not match the description of the PR.

}

/**
Expand Down
Loading