From 7bd8c84bc04a9461ea3d4d0e98e7c122ea35af81 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Wed, 21 Feb 2024 14:29:24 -0800 Subject: [PATCH 01/15] Added comment --- core/threaded/reactor_threaded.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/threaded/reactor_threaded.c b/core/threaded/reactor_threaded.c index 5d6e89c2a..09defbdbb 100644 --- a/core/threaded/reactor_threaded.c +++ b/core/threaded/reactor_threaded.c @@ -631,6 +631,8 @@ void _lf_initialize_start_tag(environment_t *env) { LF_PRINT_LOG("Waiting for start time " PRINTF_TIME " plus STA " PRINTF_TIME ".", start_time, lf_fed_STA_offset); #else + // For other than federated decentralized execution, there is no lf_fed_STA_offset variable defined. + // To use uniform code below, we define it here as a local variable. instant_t lf_fed_STA_offset = 0; LF_PRINT_LOG("Waiting for start time " PRINTF_TIME ".", start_time); From c681a127d7682bce78cb6862822f8c2559796925 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Fri, 1 Mar 2024 08:56:27 +0100 Subject: [PATCH 02/15] Print out __FILE__, __LINE__ and __func__ where our custom assertions fail. --- logging/api/logging_macros.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/logging/api/logging_macros.h b/logging/api/logging_macros.h index 6ecc7e7ce..58271cead 100644 --- a/logging/api/logging_macros.h +++ b/logging/api/logging_macros.h @@ -77,20 +77,23 @@ #else #define LF_ASSERT(condition, format, ...) \ do { \ - if (!(condition)) { \ - lf_print_error_and_exit(format, ##__VA_ARGS__); \ + if (!condition) { \ + lf_print_error_and_exit("`"format "`. Failed assertion in %s:%d(%s):`" #condition \ + " != true`", ##__VA_ARGS__, __FILE__, __LINE__, __func__); \ } \ } while(0) #define LF_ASSERTN(condition, format, ...) \ do { \ if (condition) { \ - lf_print_error_and_exit(format, ##__VA_ARGS__); \ + lf_print_error_and_exit("`"format "`. Failed assertion in %s:%d(%s):`" #condition \ + " != false`", ##__VA_ARGS__, __FILE__, __LINE__, __func__); \ } \ } while(0) #define LF_ASSERT_NON_NULL(pointer) \ do { \ if (!(pointer)) { \ - lf_print_error_and_exit("Assertion failed: pointer is NULL Out of memory?."); \ + lf_print_error_and_exit("`Out of memory?` Assertion failed in %s:%d(%s):`" #pointer " == NULL`",\ + __FILE__, __LINE__, __func__); \ } \ } while(0) #endif // NDEBUG From 03b6a85883765fd1e6a06519abad5c455b11d6b5 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Fri, 1 Mar 2024 09:21:59 +0100 Subject: [PATCH 03/15] Forgot extra parenthesis in macro --- logging/api/logging_macros.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logging/api/logging_macros.h b/logging/api/logging_macros.h index 58271cead..04f55b41c 100644 --- a/logging/api/logging_macros.h +++ b/logging/api/logging_macros.h @@ -77,7 +77,7 @@ #else #define LF_ASSERT(condition, format, ...) \ do { \ - if (!condition) { \ + if (!(condition)) { \ lf_print_error_and_exit("`"format "`. Failed assertion in %s:%d(%s):`" #condition \ " != true`", ##__VA_ARGS__, __FILE__, __LINE__, __func__); \ } \ From 6d2e05dbf5b6efa715ec7bb5e32efdfde3801b76 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Fri, 1 Mar 2024 09:55:17 +0100 Subject: [PATCH 04/15] Format the assertion printing better --- logging/api/logging_macros.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/logging/api/logging_macros.h b/logging/api/logging_macros.h index 04f55b41c..b29754b7c 100644 --- a/logging/api/logging_macros.h +++ b/logging/api/logging_macros.h @@ -78,15 +78,15 @@ #define LF_ASSERT(condition, format, ...) \ do { \ if (!(condition)) { \ - lf_print_error_and_exit("`"format "`. Failed assertion in %s:%d(%s):`" #condition \ - " != true`", ##__VA_ARGS__, __FILE__, __LINE__, __func__); \ + lf_print_error_and_exit("`"format "`. Failed assertion in %s:%d(%s):(" #condition \ + ") != true`", ##__VA_ARGS__, __FILE__, __LINE__, __func__); \ } \ } while(0) #define LF_ASSERTN(condition, format, ...) \ do { \ if (condition) { \ - lf_print_error_and_exit("`"format "`. Failed assertion in %s:%d(%s):`" #condition \ - " != false`", ##__VA_ARGS__, __FILE__, __LINE__, __func__); \ + lf_print_error_and_exit("`"format "`. Failed assertion in %s:%d(%s):(" #condition \ + ") != false`", ##__VA_ARGS__, __FILE__, __LINE__, __func__); \ } \ } while(0) #define LF_ASSERT_NON_NULL(pointer) \ From adb753d423fefabeb9209665bffbc124b46d5480 Mon Sep 17 00:00:00 2001 From: Chanhee Lee Date: Fri, 1 Mar 2024 12:36:13 -0700 Subject: [PATCH 05/15] Change ADR_RQ to ADR_QR for correct line drawing in trace_svg.html This fixes the problem of ADR_QR lines not being displayed in trace_svg.html. --- util/tracing/visualization/fedsd.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/tracing/visualization/fedsd.py b/util/tracing/visualization/fedsd.py index b35e96dd7..d66000e4b 100644 --- a/util/tracing/visualization/fedsd.py +++ b/util/tracing/visualization/fedsd.py @@ -110,7 +110,7 @@ # Events matching at the sender and receiver ends depend on whether they are tagged # (the elapsed logical time and microstep have to be the same) or not. # Set of tagged events (messages) -non_tagged_messages = {'FED_ID', 'ACK', 'RESIGN', 'FAILED', 'REJECT', 'ADR_RQ', 'ADR_AD', 'MSG', 'P2P_MSG'} +non_tagged_messages = {'FED_ID', 'ACK', 'RESIGN', 'FAILED', 'REJECT', 'ADR_QR', 'ADR_AD', 'MSG', 'P2P_MSG'} ################################################################################ @@ -672,7 +672,7 @@ def get_and_convert_lft_files(rti_lft_file, federates_lft_files, start_time, end # FIXME: Using microseconds is hardwired here. physical_time = f'{int(row["physical_time"]/1000):,}' - if (row['event'] in {'FED_ID', 'ACK', 'FAILED', 'REJECT', 'ADR_RQ', 'ADR_AD', 'MSG', 'P2P_MSG'}): + if (row['event'] in {'FED_ID', 'ACK', 'FAILED', 'REJECT', 'ADR_QR', 'ADR_AD', 'MSG', 'P2P_MSG'}): label = row['event'] else: label = row['event'] + '(' + f'{int(row["logical_time"]):,}' + ', ' + str(row['microstep']) + ')' From 662f707c4e94b842c8c294dee8552b7039e10368 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Fri, 1 Mar 2024 22:54:01 -0800 Subject: [PATCH 06/15] Tweak CI workflow for merge queue --- .github/workflows/ci.yml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 26795c446..4c2f14ebb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,6 +7,11 @@ on: pull_request: # Also allow running this workflow manually from the Actions tab. workflow_dispatch: + merge_group: + +concurrency: + group: ci-${{ github.ref }}-${{ github.event_path }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} jobs: unit-tests-single: @@ -39,7 +44,7 @@ jobs: with: runtime-ref: ${{ github.ref }} compiler-ref: ${{ needs.fetch-lf.outputs.ref }} - if: ${{ needs.check-diff.outputs.run_arduino == 'true' }} + if: ${{ github.event_name == 'merge_group' || needs.check-diff.outputs.run_arduino == 'true' }} lf-default-zephyr: needs: [fetch-lf, check-diff] @@ -47,7 +52,7 @@ jobs: with: runtime-ref: ${{ github.ref }} compiler-ref: ${{ needs.fetch-lf.outputs.ref }} - if: ${{ needs.check-diff.outputs.run_zephyr == 'true' }} + if: ${{ github.event_name == 'merge_group' || needs.check-diff.outputs.run_zephyr == 'true' }} lf-default: needs: [fetch-lf, check-diff] @@ -55,7 +60,7 @@ jobs: with: runtime-ref: ${{ github.ref }} compiler-ref: ${{ needs.fetch-lf.outputs.ref }} - all-platforms: ${{ needs.check-diff.outputs.run_macos == 'true' || needs.check-diff.outputs.run_windows == 'true' }} + all-platforms: ${{ github.event_name == 'merge_group' || needs.check-diff.outputs.run_macos == 'true' || needs.check-diff.outputs.run_windows == 'true' }} lf-python: needs: [fetch-lf, check-diff] @@ -63,7 +68,7 @@ jobs: with: reactor-c-ref: ${{ github.ref }} compiler-ref: ${{ needs.fetch-lf.outputs.ref }} - if: ${{ needs.check-diff.outputs.run_python == 'true' }} + if: ${{ github.event_name == 'merge_group' || needs.check-diff.outputs.run_python == 'true' }} lf-gedf-np: needs: [fetch-lf, check-diff] @@ -72,7 +77,7 @@ jobs: runtime-ref: ${{ github.ref }} compiler-ref: ${{ needs.fetch-lf.outputs.ref }} scheduler: GEDF_NP - all-platforms: ${{ needs.check-diff.outputs.run_macos == 'true' || needs.check-diff.outputs.run_windows == 'true' }} + all-platforms: ${{ github.event_name == 'merge_group' || needs.check-diff.outputs.run_macos == 'true' || needs.check-diff.outputs.run_windows == 'true' }} lf-adaptive: needs: [fetch-lf, check-diff] @@ -81,4 +86,4 @@ jobs: runtime-ref: ${{ github.ref }} compiler-ref: ${{ needs.fetch-lf.outputs.ref }} scheduler: ADAPTIVE - all-platforms: ${{ needs.check-diff.outputs.run_macos == 'true' || needs.check-diff.outputs.run_windows == 'true' }} + all-platforms: ${{ github.event_name == 'merge_group' || needs.check-diff.outputs.run_macos == 'true' || needs.check-diff.outputs.run_windows == 'true' }} From d1e26f38a6c08b585c5b8bc6f2c4716f462d35c8 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Fri, 1 Mar 2024 23:33:36 -0800 Subject: [PATCH 07/15] Attempt to address Clang error --- logging/api/logging_macros.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/logging/api/logging_macros.h b/logging/api/logging_macros.h index b29754b7c..0864cdea7 100644 --- a/logging/api/logging_macros.h +++ b/logging/api/logging_macros.h @@ -78,14 +78,14 @@ #define LF_ASSERT(condition, format, ...) \ do { \ if (!(condition)) { \ - lf_print_error_and_exit("`"format "`. Failed assertion in %s:%d(%s):(" #condition \ + lf_print_error_and_exit("`" format "`. Failed assertion in %s:%d(%s):(" #condition \ ") != true`", ##__VA_ARGS__, __FILE__, __LINE__, __func__); \ } \ } while(0) #define LF_ASSERTN(condition, format, ...) \ do { \ if (condition) { \ - lf_print_error_and_exit("`"format "`. Failed assertion in %s:%d(%s):(" #condition \ + lf_print_error_and_exit("`" format "`. Failed assertion in %s:%d(%s):(" #condition \ ") != false`", ##__VA_ARGS__, __FILE__, __LINE__, __func__); \ } \ } while(0) From c8ceb86c5774639911563b75152f9fa6d7381002 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Fri, 1 Mar 2024 23:40:26 -0800 Subject: [PATCH 08/15] Add means to trigger macOS tests using label --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4c2f14ebb..a4717ec97 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -60,7 +60,7 @@ jobs: with: runtime-ref: ${{ github.ref }} compiler-ref: ${{ needs.fetch-lf.outputs.ref }} - all-platforms: ${{ github.event_name == 'merge_group' || needs.check-diff.outputs.run_macos == 'true' || needs.check-diff.outputs.run_windows == 'true' }} + all-platforms: ${{ github.event_name == 'merge_group' || needs.check-diff.outputs.run_macos == 'true' || needs.check-diff.outputs.run_windows == 'true' || contains( github.event.pull_request.labels.*.name, 'mac') }} lf-python: needs: [fetch-lf, check-diff] @@ -77,7 +77,7 @@ jobs: runtime-ref: ${{ github.ref }} compiler-ref: ${{ needs.fetch-lf.outputs.ref }} scheduler: GEDF_NP - all-platforms: ${{ github.event_name == 'merge_group' || needs.check-diff.outputs.run_macos == 'true' || needs.check-diff.outputs.run_windows == 'true' }} + all-platforms: ${{ github.event_name == 'merge_group' || needs.check-diff.outputs.run_macos == 'true' || needs.check-diff.outputs.run_windows == 'true' || contains( github.event.pull_request.labels.*.name, 'mac')}} lf-adaptive: needs: [fetch-lf, check-diff] @@ -86,4 +86,4 @@ jobs: runtime-ref: ${{ github.ref }} compiler-ref: ${{ needs.fetch-lf.outputs.ref }} scheduler: ADAPTIVE - all-platforms: ${{ github.event_name == 'merge_group' || needs.check-diff.outputs.run_macos == 'true' || needs.check-diff.outputs.run_windows == 'true' }} + all-platforms: ${{ github.event_name == 'merge_group' || needs.check-diff.outputs.run_macos == 'true' || needs.check-diff.outputs.run_windows == 'true' || contains( github.event.pull_request.labels.*.name, 'mac' )}} From 7247ce6bf8445336839e6022666e8a28c27793c8 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Fri, 1 Mar 2024 23:57:28 -0800 Subject: [PATCH 09/15] Make CI easier to work with by using labels instead of diffs, which are less reliable --- .github/workflows/check-diff.yml | 46 -------------------------------- .github/workflows/ci.yml | 27 +++++++++---------- 2 files changed, 12 insertions(+), 61 deletions(-) delete mode 100644 .github/workflows/check-diff.yml diff --git a/.github/workflows/check-diff.yml b/.github/workflows/check-diff.yml deleted file mode 100644 index ecb22827d..000000000 --- a/.github/workflows/check-diff.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: Check diff from main - -on: - workflow_call: - outputs: - run_arduino: - description: 'Return true if Arduino tests should be run' - value: ${{ jobs.check.outputs.run_arduino == 'true' }} - run_macos: - description: 'Return true if macOS tests should be run' - value: ${{ jobs.check.outputs.run_macos == 'true' }} - run_python: - description: 'Return true if Python tests should be run' - value: ${{ jobs.check.outputs.run_python == 'true' }} - run_windows: - description: 'Return true if Windows tests should be run' - value: ${{ jobs.check.outputs.run_windows == 'true' }} - run_zephyr: - description: 'Return true if Zephyr tests should be run' - value: ${{ jobs.check.outputs.run_zephyr == 'true' }} - -jobs: - check: - runs-on: ubuntu-latest - outputs: - run_arduino: ${{ steps.do.outputs.changed_arduino == 1 || github.ref == 'refs/heads/main' }} - run_macos: ${{ steps.do.outputs.changed_macos == 1 || github.ref == 'refs/heads/main' }} - run_python: ${{ steps.do.outputs.changed_python == 1 || github.ref == 'refs/heads/main' }} - run_windows: ${{ steps.do.outputs.changed_windows == 1 || github.ref == 'refs/heads/main' }} - run_zephyr: ${{ steps.do.outputs.changed_zephyr == 1 || github.ref == 'refs/heads/main' }} - - steps: - - name: Check out reactor-c repository - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - id: do - name: Check which targets have changes - run: | - ./check-diff.sh "arduino" arduino - ./check-diff.sh "macos|unix" macos - ./check-diff.sh "python" python - ./check-diff.sh "windows" windows - ./check-diff.sh "zephyr" zephyr - shell: bash - working-directory: .github/scripts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a4717ec97..fa8a5f752 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,60 +30,57 @@ jobs: build-trace-tools: uses: ./.github/workflows/build-trace-tools.yml - check-diff: - uses: ./.github/workflows/check-diff.yml - fetch-lf: uses: lf-lang/lingua-franca/.github/workflows/extract-ref.yml@master with: file: 'lingua-franca-ref.txt' lf-default-arduino: - needs: [fetch-lf, check-diff] + needs: [fetch-lf] uses: lf-lang/lingua-franca/.github/workflows/c-arduino-tests.yml@master with: runtime-ref: ${{ github.ref }} compiler-ref: ${{ needs.fetch-lf.outputs.ref }} - if: ${{ github.event_name == 'merge_group' || needs.check-diff.outputs.run_arduino == 'true' }} + if: ${{ github.event_name == 'merge_group' || github.ref == 'refs/heads/main' || contains( github.event.pull_request.labels.*.name, 'arduino') }} lf-default-zephyr: - needs: [fetch-lf, check-diff] + needs: [fetch-lf] uses: lf-lang/lingua-franca/.github/workflows/c-zephyr-tests.yml@master with: runtime-ref: ${{ github.ref }} compiler-ref: ${{ needs.fetch-lf.outputs.ref }} - if: ${{ github.event_name == 'merge_group' || needs.check-diff.outputs.run_zephyr == 'true' }} + if: ${{ github.event_name == 'merge_group' || github.ref == 'refs/heads/main' ||contains( github.event.pull_request.labels.*.name, 'zephyr') }} lf-default: - needs: [fetch-lf, check-diff] + needs: [fetch-lf] uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@master with: runtime-ref: ${{ github.ref }} compiler-ref: ${{ needs.fetch-lf.outputs.ref }} - all-platforms: ${{ github.event_name == 'merge_group' || needs.check-diff.outputs.run_macos == 'true' || needs.check-diff.outputs.run_windows == 'true' || contains( github.event.pull_request.labels.*.name, 'mac') }} + all-platforms: ${{ github.event_name == 'merge_group' || github.ref == 'refs/heads/main' || contains( github.event.pull_request.labels.*.name, 'mac') || contains( github.event.pull_request.labels.*.name, 'windows') }} lf-python: - needs: [fetch-lf, check-diff] + needs: [fetch-lf] uses: lf-lang/lingua-franca/.github/workflows/py-tests.yml@master with: reactor-c-ref: ${{ github.ref }} compiler-ref: ${{ needs.fetch-lf.outputs.ref }} - if: ${{ github.event_name == 'merge_group' || needs.check-diff.outputs.run_python == 'true' }} + if: ${{ github.event_name == 'merge_group' || github.ref == 'refs/heads/main' ||contains( github.event.pull_request.labels.*.name, 'python') }} lf-gedf-np: - needs: [fetch-lf, check-diff] + needs: [fetch-lf] uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@master with: runtime-ref: ${{ github.ref }} compiler-ref: ${{ needs.fetch-lf.outputs.ref }} scheduler: GEDF_NP - all-platforms: ${{ github.event_name == 'merge_group' || needs.check-diff.outputs.run_macos == 'true' || needs.check-diff.outputs.run_windows == 'true' || contains( github.event.pull_request.labels.*.name, 'mac')}} + all-platforms: ${{ github.event_name == 'merge_group' || github.ref == 'refs/heads/main' || contains( github.event.pull_request.labels.*.name, 'mac') || contains( github.event.pull_request.labels.*.name, 'windows') }} lf-adaptive: - needs: [fetch-lf, check-diff] + needs: [fetch-lf] uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@master with: runtime-ref: ${{ github.ref }} compiler-ref: ${{ needs.fetch-lf.outputs.ref }} scheduler: ADAPTIVE - all-platforms: ${{ github.event_name == 'merge_group' || needs.check-diff.outputs.run_macos == 'true' || needs.check-diff.outputs.run_windows == 'true' || contains( github.event.pull_request.labels.*.name, 'mac' )}} + all-platforms: ${{ github.event_name == 'merge_group' || github.ref == 'refs/heads/main' || contains( github.event.pull_request.labels.*.name, 'mac') || contains( github.event.pull_request.labels.*.name, 'windows') }} From 151d546f35d2d299002b6f650024f45983daabe0 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 2 Mar 2024 09:06:45 -0800 Subject: [PATCH 10/15] Comments only --- core/federated/RTI/rti_common.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/federated/RTI/rti_common.h b/core/federated/RTI/rti_common.h index 770918d5b..541be8050 100644 --- a/core/federated/RTI/rti_common.h +++ b/core/federated/RTI/rti_common.h @@ -185,9 +185,10 @@ void notify_advance_grant_if_safe(scheduling_node_t* e); void notify_provisional_tag_advance_grant(scheduling_node_t* e, tag_t tag); /** - * Determine whether the specified scheduling node is eligible for a tag advance grant, - * (TAG) and, if so, return the details. This is called upon receiving a LTC, NET - * or resign from an upstream node. + * @brief Determine whether the specified scheduling node is eligible for a tag advance grant, + * (TAG) and, if so, return the details. + * + * This is called upon receiving a LTC, NET or resign from an upstream node. * * This function calculates the minimum M over * all upstream scheduling nodes of the "after" delay plus the most recently From bf46a47ea936a6eacb6261fea1e2bc6f989a2969 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 2 Mar 2024 09:07:14 -0800 Subject: [PATCH 11/15] More info in error message --- core/federated/federate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/federated/federate.c b/core/federated/federate.c index 290433851..512466dc6 100644 --- a/core/federated/federate.c +++ b/core/federated/federate.c @@ -2708,8 +2708,8 @@ int lf_send_tagged_message(environment_t* env, if (message_type == MSG_TYPE_P2P_TAGGED_MESSAGE) { lf_print_warning("Failed to send message to %s. Dropping the message.", next_destination_str); } else { - lf_print_error_system_failure("Failed to send message to %s. Connection lost to the RTI.", - next_destination_str); + lf_print_error_system_failure("Failed to send message to %s with error code %d (%s). Connection lost to the RTI.", + next_destination_str, errno, strerror(errno)); } } LF_MUTEX_UNLOCK(&lf_outbound_socket_mutex); From 844c90ae22caf4c4c9b0ec8cd592d3875ceea067 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 2 Mar 2024 09:08:17 -0800 Subject: [PATCH 12/15] Use SI units in human readable time --- core/tag.c | 30 ++++++++++++++++-------------- include/core/tag.h | 13 +++++++------ 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/core/tag.c b/core/tag.c index e236dd766..3037b5990 100644 --- a/core/tag.c +++ b/core/tag.c @@ -122,6 +122,10 @@ instant_t lf_time_start(void) { } size_t lf_readable_time(char* buffer, instant_t time) { + if (time <= (instant_t)0) { + snprintf(buffer, 2, "0"); + return 1; + } char* original_buffer = buffer; bool lead = false; // Set to true when first clause has been printed. if (time > WEEKS(1)) { @@ -141,8 +145,8 @@ size_t lf_readable_time(char* buffer, instant_t time) { size_t printed = lf_comma_separated_time(buffer, time / DAYS(1)); time = time % DAYS(1); buffer += printed; - snprintf(buffer, 6, " days"); - buffer += 5; + snprintf(buffer, 3, " d"); + buffer += 2; } if (time > HOURS(1)) { if (lead == true) { @@ -153,8 +157,8 @@ size_t lf_readable_time(char* buffer, instant_t time) { size_t printed = lf_comma_separated_time(buffer, time / HOURS(1)); time = time % HOURS(1); buffer += printed; - snprintf(buffer, 7, " hours"); - buffer += 6; + snprintf(buffer, 4, " hr"); + buffer += 3; } if (time > MINUTES(1)) { if (lead == true) { @@ -165,8 +169,8 @@ size_t lf_readable_time(char* buffer, instant_t time) { size_t printed = lf_comma_separated_time(buffer, time / MINUTES(1)); time = time % MINUTES(1); buffer += printed; - snprintf(buffer, 9, " minutes"); - buffer += 8; + snprintf(buffer, 5, " min"); + buffer += 4; } if (time > SECONDS(1)) { if (lead == true) { @@ -177,28 +181,26 @@ size_t lf_readable_time(char* buffer, instant_t time) { size_t printed = lf_comma_separated_time(buffer, time / SECONDS(1)); time = time % SECONDS(1); buffer += printed; - snprintf(buffer, 9, " seconds"); - buffer += 8; + snprintf(buffer, 3, " s"); + buffer += 2; } if (time > (instant_t)0) { if (lead == true) { snprintf(buffer, 3, ", "); buffer += 2; } - const char* units = "nanoseconds"; + const char* units = "ns"; if (time % MSEC(1) == (instant_t) 0) { - units = "milliseconds"; + units = "ms"; time = time / MSEC(1); } else if (time % USEC(1) == (instant_t) 0) { - units = "microseconds"; + units = "us"; time = time / USEC(1); } size_t printed = lf_comma_separated_time(buffer, time); buffer += printed; - snprintf(buffer, 14, " %s", units); + snprintf(buffer, 3, " %s", units); buffer += strlen(units) + 1; - } else { - snprintf(buffer, 2, "0"); } return (buffer - original_buffer); } diff --git a/include/core/tag.h b/include/core/tag.h index 55d83c35d..4f2dbd031 100644 --- a/include/core/tag.h +++ b/include/core/tag.h @@ -199,21 +199,22 @@ instant_t lf_time_start(void); * Maximum number of nanoseconds is 999,999,999 * Maximum number of microsteps is 4,294,967,295 * Total number of characters for the above is 24. - * Text descriptions and spaces add an additional 55, - * for a total of 79. One more allows for a null terminator. + * Text descriptions and spaces add an additional 30, + * for a total of 54. One more allows for a null terminator. + * Round up to a power of two. */ -#define LF_TIME_BUFFER_LENGTH 80 +#define LF_TIME_BUFFER_LENGTH 64 /** * Store into the specified buffer a string giving a human-readable * rendition of the specified time. The buffer must have length at least * equal to LF_TIME_BUFFER_LENGTH. The format is: * ``` - * x weeks, x days, x hours, x minutes, x seconds, x unit + * x weeks, x d, x hr, x min, x s, x unit * ``` * where each `x` is a string of numbers with commas inserted if needed - * every three numbers and `unit` is nanoseconds, microseconds, or - * milliseconds. + * every three numbers and `unit` is ns, us, or + * ms. * @param buffer The buffer into which to write the string. * @param time The time to write. * @return The number of characters written (not counting the null terminator). From 6a8c1793d334da97725b96e691e7543778274678 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 2 Mar 2024 16:08:03 -0800 Subject: [PATCH 13/15] Response to review --- core/tag.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/tag.c b/core/tag.c index b99546356..db590470a 100644 --- a/core/tag.c +++ b/core/tag.c @@ -157,8 +157,8 @@ size_t lf_readable_time(char* buffer, instant_t time) { size_t printed = lf_comma_separated_time(buffer, time / HOURS(1)); time = time % HOURS(1); buffer += printed; - snprintf(buffer, 4, " hr"); - buffer += 3; + snprintf(buffer, 3, " h"); + buffer += 2; } if (time > MINUTES(1)) { if (lead == true) { From 277d3f295167b9f9f3b45356937af8cf57bef3b8 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sun, 3 Mar 2024 11:22:25 -0800 Subject: [PATCH 14/15] Added lf_combine_deadline_and_level function for use by code generator --- core/reactor_common.c | 5 +++++ include/core/reactor_common.h | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/core/reactor_common.c b/core/reactor_common.c index 8492ef48a..a7cd1bb18 100644 --- a/core/reactor_common.c +++ b/core/reactor_common.c @@ -1325,3 +1325,8 @@ void termination(void) { } lf_tracing_global_shutdown(); } + +index_t lf_combine_deadline_and_level(interval_t deadline, int level) { + if (deadline > ULLONG_MAX >> 16) return ((ULLONG_MAX >> 16) << 16) | level; + else return (deadline << 16) | level; +} \ No newline at end of file diff --git a/include/core/reactor_common.h b/include/core/reactor_common.h index 97ec976b8..92630be1e 100644 --- a/include/core/reactor_common.h +++ b/include/core/reactor_common.h @@ -65,6 +65,16 @@ extern struct allocation_record_t* _lf_reactors_to_free; ////////////////////// Functions ////////////////////// +/** + * @brief Combine a deadline and a level into a single index for sorting in the reaction queue. + * + * This shifts the deadline right by 16 bits and inserts the level in the low-order 16 bits. + * If the deadline is larger than `ULLONG_MAX >> 16`, then it is treated as the largest possible deadline. + * @oaran deadline THe deadline. + * @param level The level in the reaction graph. +*/ +index_t lf_combine_deadline_and_level(interval_t deadline, int level); + /** * @brief Create and initialize the required number of environments for the program. * @note This function will be code generated by the compiler. From ed9d3546eb898091461913d4e526d8b3bb9a6bee Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 3 Mar 2024 13:50:29 -0800 Subject: [PATCH 15/15] Update core/reactor_common.c --- core/reactor_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/reactor_common.c b/core/reactor_common.c index a7cd1bb18..bd9cc1210 100644 --- a/core/reactor_common.c +++ b/core/reactor_common.c @@ -1329,4 +1329,4 @@ void termination(void) { index_t lf_combine_deadline_and_level(interval_t deadline, int level) { if (deadline > ULLONG_MAX >> 16) return ((ULLONG_MAX >> 16) << 16) | level; else return (deadline << 16) | level; -} \ No newline at end of file +}