From 7f27dfc01087b95a433a12475d8d6fa24b21ad47 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Thu, 21 Jul 2022 15:03:17 -0500 Subject: [PATCH 01/11] Added a forward-decleration for _lf_executable_preamble --- core/reactor.h | 6 ++++++ core/threaded/reactor_threaded.c | 2 ++ 2 files changed, 8 insertions(+) diff --git a/core/reactor.h b/core/reactor.h index f2cff06b4..468e8ade8 100644 --- a/core/reactor.h +++ b/core/reactor.h @@ -87,6 +87,12 @@ void _lf_set_present(bool* is_present_field); +/** + * @brief Forward declaration for the executable preamble; + * + */ +void _lf_executable_preamble(); + /** * Set the specified output (or input of a contained reactor) * to the specified value. diff --git a/core/threaded/reactor_threaded.c b/core/threaded/reactor_threaded.c index 7faed135c..e1087b542 100644 --- a/core/threaded/reactor_threaded.c +++ b/core/threaded/reactor_threaded.c @@ -768,6 +768,8 @@ void _lf_initialize_start_tag() { // Add reactions invoked at tag (0,0) (including startup reactions) to the reaction queue _lf_trigger_startup_reactions(); + _lf_executable_preamble(); + #ifdef FEDERATED // Reset status fields before talking to the RTI to set network port // statuses to unknown From fffbebf00cb58e2bd5fc3fea7d83b56fb5d35628 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sun, 24 Jul 2022 17:29:57 -0500 Subject: [PATCH 02/11] Use a compile definition for the executable preamble --- core/threaded/reactor_threaded.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/threaded/reactor_threaded.c b/core/threaded/reactor_threaded.c index e1087b542..6b531ae6f 100644 --- a/core/threaded/reactor_threaded.c +++ b/core/threaded/reactor_threaded.c @@ -755,6 +755,10 @@ void _lf_trigger_reaction(reaction_t* reaction, int worker_number) { #endif } +#ifndef EXECUTABLE_PREAMBLE +void _lf_executable_preamble() {} +#endif // EXECUTABLE_PREAMBLE + /** * Perform the necessary operations before tag (0,0) can be processed. * From 28c1b413d7cf3046094c5073da13052e1a9b8b24 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sun, 24 Jul 2022 17:32:10 -0500 Subject: [PATCH 03/11] Updated LF ref --- lingua-franca-ref.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lingua-franca-ref.txt b/lingua-franca-ref.txt index 1a62c2c9f..9784b15f7 100644 --- a/lingua-franca-ref.txt +++ b/lingua-franca-ref.txt @@ -1 +1 @@ -36c2e76fdb75717a825ab4217fe80b74076d0cd0 +a7266f8b94c47fc4a3cae799bb58795d78ba8ba5 From 2d0d45c2e4dbee91dbb82231f01a0f537c30e173 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Wed, 27 Jul 2022 19:41:05 -0500 Subject: [PATCH 04/11] Move _lf_executable_preamble --- core/reactor_common.c | 3 +++ core/threaded/reactor_threaded.c | 4 +--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/core/reactor_common.c b/core/reactor_common.c index 3d8c045fd..c73356aaa 100644 --- a/core/reactor_common.c +++ b/core/reactor_common.c @@ -1959,6 +1959,9 @@ void initialize(void) { // Initialize the trigger table. _lf_initialize_trigger_objects(); + // Run the executable preamble + _lf_executable_preamble(); + physical_start_time = lf_time_physical(); current_tag.time = physical_start_time; start_time = current_tag.time; diff --git a/core/threaded/reactor_threaded.c b/core/threaded/reactor_threaded.c index 6b531ae6f..45b9bc4fe 100644 --- a/core/threaded/reactor_threaded.c +++ b/core/threaded/reactor_threaded.c @@ -770,9 +770,7 @@ void _lf_executable_preamble() {} void _lf_initialize_start_tag() { // Add reactions invoked at tag (0,0) (including startup reactions) to the reaction queue - _lf_trigger_startup_reactions(); - - _lf_executable_preamble(); + _lf_trigger_startup_reactions(); #ifdef FEDERATED // Reset status fields before talking to the RTI to set network port From 2c187157c37b162b6076a1a1155893b0d1b5b50f Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Wed, 27 Jul 2022 21:22:37 -0500 Subject: [PATCH 05/11] Added back the mysteriously removed synchronize_initial_physical_clock_with_rti --- core/federated/federate.c | 2 ++ core/reactor_common.c | 5 ++++- core/threaded/reactor_threaded.c | 4 ---- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/core/federated/federate.c b/core/federated/federate.c index b226a28df..567a39583 100644 --- a/core/federated/federate.c +++ b/core/federated/federate.c @@ -1023,6 +1023,8 @@ void connect_to_rti(char* hostname, int port) { encode_uint16(udp_port, &(UDP_port_number[1])); write_to_socket_errexit(_fed.socket_TCP_RTI, 1 + sizeof(uint16_t), UDP_port_number, "Failed to send the UDP port number to the RTI."); + + synchronize_initial_physical_clock_with_rti(_fed.socket_TCP_RTI); } else { lf_print_error_and_exit("Received unexpected response %u from the RTI (see net_common.h).", response); diff --git a/core/reactor_common.c b/core/reactor_common.c index c73356aaa..39b2198c9 100644 --- a/core/reactor_common.c +++ b/core/reactor_common.c @@ -1938,6 +1938,10 @@ int process_args(int argc, char* argv[]) { return 1; } +#ifndef EXECUTABLE_PREAMBLE +void _lf_executable_preamble() {} +#endif // EXECUTABLE_PREAMBLE + /** * Initialize the priority queues and set logical time to match * physical time. This also prints a message reporting the start time. @@ -1959,7 +1963,6 @@ void initialize(void) { // Initialize the trigger table. _lf_initialize_trigger_objects(); - // Run the executable preamble _lf_executable_preamble(); physical_start_time = lf_time_physical(); diff --git a/core/threaded/reactor_threaded.c b/core/threaded/reactor_threaded.c index 45b9bc4fe..a91dad752 100644 --- a/core/threaded/reactor_threaded.c +++ b/core/threaded/reactor_threaded.c @@ -755,10 +755,6 @@ void _lf_trigger_reaction(reaction_t* reaction, int worker_number) { #endif } -#ifndef EXECUTABLE_PREAMBLE -void _lf_executable_preamble() {} -#endif // EXECUTABLE_PREAMBLE - /** * Perform the necessary operations before tag (0,0) can be processed. * From 797c42cdee3b1a4db4eb5741b5cc88b0e4371c78 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sat, 30 Jul 2022 23:46:08 -0500 Subject: [PATCH 06/11] Removed unnecessary function call --- core/federated/federate.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/federated/federate.c b/core/federated/federate.c index 567a39583..b226a28df 100644 --- a/core/federated/federate.c +++ b/core/federated/federate.c @@ -1023,8 +1023,6 @@ void connect_to_rti(char* hostname, int port) { encode_uint16(udp_port, &(UDP_port_number[1])); write_to_socket_errexit(_fed.socket_TCP_RTI, 1 + sizeof(uint16_t), UDP_port_number, "Failed to send the UDP port number to the RTI."); - - synchronize_initial_physical_clock_with_rti(_fed.socket_TCP_RTI); } else { lf_print_error_and_exit("Received unexpected response %u from the RTI (see net_common.h).", response); From f6486740b9497ce7d32e6e317194abd88eadb4c0 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sun, 31 Jul 2022 00:22:05 -0500 Subject: [PATCH 07/11] Moved executable preamble to CGenerator --- core/federated/RTI/rti.c | 2 ++ core/federated/clock-sync.c | 4 ++-- core/federated/clock-sync.h | 2 +- core/reactor_common.c | 6 ------ 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/core/federated/RTI/rti.c b/core/federated/RTI/rti.c index 8397160c5..7cfde3108 100644 --- a/core/federated/RTI/rti.c +++ b/core/federated/RTI/rti.c @@ -1742,6 +1742,8 @@ int receive_udp_message_and_set_up_clock_sync(int socket_id, uint16_t fed_id) { if (_RTI.clock_sync_global_status >= clock_sync_init) {// If no initial clock sync, no need perform initial clock sync. uint16_t federate_UDP_port_number = extract_uint16(&(response[1])); + LF_PRINT_DEBUG("RTI got MSG_TYPE_UDP_PORT %u from federate %d.", federate_UDP_port_number, fed_id); + // A port number of UINT16_MAX means initial clock sync should not be performed. if (federate_UDP_port_number != UINT16_MAX) { // Perform the initialization clock synchronization with the federate. diff --git a/core/federated/clock-sync.c b/core/federated/clock-sync.c index 617654933..1471b642a 100644 --- a/core/federated/clock-sync.c +++ b/core/federated/clock-sync.c @@ -136,8 +136,8 @@ void reset_socket_stat(struct socket_stat_t* socket_stat) { * If clock synchronization is set to on, a reserved UDP port number * will be sent. */ -ushort setup_clock_synchronization_with_rti() { - ushort port_to_return = USHRT_MAX; +uint16_t setup_clock_synchronization_with_rti() { + uint16_t port_to_return = UINT16_MAX; #ifdef _LF_CLOCK_SYNC_ON // Initialize the UDP socket _lf_rti_socket_UDP = socket(AF_INET, SOCK_DGRAM, 0); diff --git a/core/federated/clock-sync.h b/core/federated/clock-sync.h index 776e77873..a083c1e4e 100644 --- a/core/federated/clock-sync.h +++ b/core/federated/clock-sync.h @@ -132,7 +132,7 @@ void reset_socket_stat(struct socket_stat_t* socket_stat); * * @return port number to be sent to the RTI */ -unsigned short int setup_clock_synchronization_with_rti(void); +uint16_t setup_clock_synchronization_with_rti(void); /** * Synchronize the initial physical clock with the RTI. diff --git a/core/reactor_common.c b/core/reactor_common.c index 36b63a720..843e438a0 100644 --- a/core/reactor_common.c +++ b/core/reactor_common.c @@ -1953,10 +1953,6 @@ int process_args(int argc, char* argv[]) { return 1; } -#ifndef EXECUTABLE_PREAMBLE -void _lf_executable_preamble() {} -#endif // EXECUTABLE_PREAMBLE - /** * Initialize the priority queues and set logical time to match * physical time. This also prints a message reporting the start time. @@ -1978,8 +1974,6 @@ void initialize(void) { // Initialize the trigger table. _lf_initialize_trigger_objects(); - _lf_executable_preamble(); - physical_start_time = lf_time_physical(); current_tag.time = physical_start_time; start_time = current_tag.time; From 5de88994d56add719b22c1672931c096c99be411 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sun, 31 Jul 2022 00:28:43 -0500 Subject: [PATCH 08/11] Fixed NPE in the RTI --- core/federated/RTI/message_record/message_record.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/core/federated/RTI/message_record/message_record.c b/core/federated/RTI/message_record/message_record.c index 6d4c278d4..db5d946c8 100644 --- a/core/federated/RTI/message_record/message_record.c +++ b/core/federated/RTI/message_record/message_record.c @@ -160,11 +160,13 @@ tag_t get_minimum_in_transit_message_tag(in_transit_message_record_q_t* queue) { // Empty the transfer queue (which holds messages with equal time but larger microstep) into the main queue. pqueue_empty_into(&queue->main_queue, &queue->transfer_queue); - LF_PRINT_DEBUG( - "RTI: Minimum tag of all in-transit messages: (%ld, %u).", - head_of_in_transit_messages->tag.time - lf_time_start(), - head_of_in_transit_messages->tag.microstep - ); + if (head_of_in_transit_messages != NULL) { + LF_PRINT_DEBUG( + "RTI: Minimum tag of all in-transit messages: (%ld, %u).", + head_of_in_transit_messages->tag.time - lf_time_start(), + head_of_in_transit_messages->tag.microstep + ); + } return minimum_tag; } From 8d7a128a56e526eafe0e037fccd94b2c3841c357 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Wed, 11 Jan 2023 18:33:20 -0800 Subject: [PATCH 09/11] Update lingua-franca-ref.txt --- lingua-franca-ref.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lingua-franca-ref.txt b/lingua-franca-ref.txt index 4654be639..ef4e81e4f 100644 --- a/lingua-franca-ref.txt +++ b/lingua-franca-ref.txt @@ -1 +1 @@ -317296844f0fb0c5c7d903a779496d88f0aeeae8 +fed-gen From 0c77e7a4799915f5cc1ae6ed19b167a1ee4e3b8a Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sat, 14 Jan 2023 20:26:55 -0800 Subject: [PATCH 10/11] Repair adaptive scheduler. It is possible that WORKERS_NEEDED_FOR_FEDERATE is zero when it should be two. --- core/threaded/scheduler_adaptive.c | 2 ++ include/core/threaded/data_collection.h | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/core/threaded/scheduler_adaptive.c b/core/threaded/scheduler_adaptive.c index ebb4efffe..718072925 100644 --- a/core/threaded/scheduler_adaptive.c +++ b/core/threaded/scheduler_adaptive.c @@ -27,6 +27,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * This is a non-priority-driven scheduler. See scheduler.h for documentation. * @author{Peter Donovan } */ +#if defined SCHEDULER && SCHEDULER == adaptive #ifndef NUMBER_OF_WORKERS #define NUMBER_OF_WORKERS 1 #endif // NUMBER_OF_WORKERS @@ -125,3 +126,4 @@ void lf_sched_trigger_reaction(reaction_t* reaction, int worker_number) { if (!lf_bool_compare_and_swap(&reaction->status, inactive, queued)) return; worker_assignments_put(reaction); } +#endif // defined SCHEDULER && SCHEDULER == ADAPTIVE diff --git a/include/core/threaded/data_collection.h b/include/core/threaded/data_collection.h index cf00a007e..9a0866530 100644 --- a/include/core/threaded/data_collection.h +++ b/include/core/threaded/data_collection.h @@ -160,6 +160,7 @@ static void data_collection_end_level(size_t level, size_t num_workers) { } static size_t restrict_to_range(size_t start_inclusive, size_t end_inclusive, size_t value) { + assert(start_inclusive <= end_inclusive); if (value < start_inclusive) return start_inclusive; if (value > end_inclusive) return end_inclusive; return value; @@ -194,8 +195,9 @@ static void compute_number_of_workers( int minimum_workers = 1; #ifdef WORKERS_NEEDED_FOR_FEDERATE // TODO: only apply this constraint on levels containing control reactions - minimum_workers = WORKERS_NEEDED_FOR_FEDERATE > max_reasonable_num_workers ? - max_reasonable_num_workers : WORKERS_NEEDED_FOR_FEDERATE; + if (WORKERS_NEEDED_FOR_FEDERATE > minimum_workers && max_reasonable_num_workers >= WORKERS_NEEDED_FOR_FEDERATE) { + minimum_workers = WORKERS_NEEDED_FOR_FEDERATE; + } #endif num_workers_by_level[level] = restrict_to_range( minimum_workers, max_reasonable_num_workers, ideal_number_of_workers From e019462d1cc0dc3d4d26771627a8960280af6a82 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sat, 14 Jan 2023 22:28:40 -0800 Subject: [PATCH 11/11] Partially revert the previous commit. Instead of handling the case that WORKERS_NEEDED_FOR_FEDERATE is less than one, assert that it is not less than one. --- include/core/threaded/data_collection.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/core/threaded/data_collection.h b/include/core/threaded/data_collection.h index 9a0866530..d40c40901 100644 --- a/include/core/threaded/data_collection.h +++ b/include/core/threaded/data_collection.h @@ -195,9 +195,9 @@ static void compute_number_of_workers( int minimum_workers = 1; #ifdef WORKERS_NEEDED_FOR_FEDERATE // TODO: only apply this constraint on levels containing control reactions - if (WORKERS_NEEDED_FOR_FEDERATE > minimum_workers && max_reasonable_num_workers >= WORKERS_NEEDED_FOR_FEDERATE) { - minimum_workers = WORKERS_NEEDED_FOR_FEDERATE; - } + assert(WORKERS_NEEDED_FOR_FEDERATE >= 1); + minimum_workers = WORKERS_NEEDED_FOR_FEDERATE > max_reasonable_num_workers ? + max_reasonable_num_workers : WORKERS_NEEDED_FOR_FEDERATE; #endif num_workers_by_level[level] = restrict_to_range( minimum_workers, max_reasonable_num_workers, ideal_number_of_workers