Skip to content
New issue

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

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

Already on GitHub? # to your account

Fixed overflow bug affecting 32-bit Linux platforms #288

Merged
merged 6 commits into from
Oct 14, 2023
Merged
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
15 changes: 12 additions & 3 deletions core/platform/lf_unix_clock_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <errno.h>

#include "platform.h"
#include "util.h"
#include "lf_unix_clock_support.h"

/**
Expand All @@ -17,13 +18,13 @@
interval_t _lf_time_epoch_offset = 0LL;

instant_t convert_timespec_to_ns(struct timespec tp) {
return tp.tv_sec * 1000000000 + tp.tv_nsec;
return ((instant_t) tp.tv_sec) * BILLION + tp.tv_nsec;
}

struct timespec convert_ns_to_timespec(instant_t t) {
struct timespec tp;
tp.tv_sec = t / 1000000000;
tp.tv_nsec = (t % 1000000000);
tp.tv_sec = t / BILLION;
tp.tv_nsec = (t % BILLION);
return tp;
}

Expand All @@ -50,6 +51,14 @@ void calculate_epoch_offset(void) {

void _lf_initialize_clock() {
calculate_epoch_offset();

struct timespec res;
int return_value = clock_getres(_LF_CLOCK, (struct timespec*) &res);
if (return_value < 0) {
lf_print_error_and_exit("Could not obtain resolution for _LF_CLOCK");
}

lf_print("---- System clock resolution: %u nsec", res.tv_nsec);
}

/**
Expand Down
11 changes: 10 additions & 1 deletion include/core/platform/lf_linux_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include <stdint.h> // For fixed-width integral types
#include <time.h> // For CLOCK_MONOTONIC
#include <unistd.h> // _POSIX_TIMERS _POSIX_CLOCK_MONOTONIC

// Use 64-bit times and 32-bit unsigned microsteps
#include "lf_tag_64_32.h"
Expand All @@ -47,7 +48,15 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endif
#endif

#if !defined(_POSIX_TIMERS) || _POSIX_TIMERS <= 0
#error Linux platform misses clock support
#endif

// The underlying physical clock for Linux
#define _LF_CLOCK CLOCK_MONOTONIC
#if defined(_POSIX_CLOCK_MONOTONIC)
#define _LF_CLOCK CLOCK_MONOTONIC
#else
#define _LF_CLOCK CLOCK_REALTIME
#endif

#endif // LF_LINUX_SUPPORT_H
2 changes: 1 addition & 1 deletion lingua-franca-ref.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
c-remove-deprecated-schedulers
master
Loading