diff --git a/core/reactor.c b/core/reactor.c index d044a6ce6..71e58377f 100644 --- a/core/reactor.c +++ b/core/reactor.c @@ -328,16 +328,9 @@ int lf_reactor_c_main(int argc, const char* argv[]) { LF_PRINT_DEBUG("Initializing."); initialize_global(); - // Set start time - if (!start_time_specified) { - start_time = lf_time_physical(); - } else { - instant_t now = lf_time_physical(); - if (now < start_time) { - LF_PRINT_LOG("Sleeping " PRINTF_TIME " ns until start time", start_time - now); - lf_sleep(start_time - now); - } - } + // Set the start time of the program (if it is not set from the command line). Possibly wait for + // it to arrive also. + _lf_set_and_wait_for_start_time(); #ifndef FEDERATED lf_tracing_set_start_time(start_time); #endif diff --git a/core/reactor_common.c b/core/reactor_common.c index ca38cbaf3..ab0c07dd4 100644 --- a/core/reactor_common.c +++ b/core/reactor_common.c @@ -885,11 +885,11 @@ void usage(int argc, const char* argv[]) { printf(" Executed in threads if possible (optional feature).\n\n"); printf(" -i, --id \n"); printf(" The ID of the federation that this reactor will join.\n\n"); - printf(" -s, --start-time \n"); - printf(" The logical start time of the program, expressed as a duration since the epoch of the underlying system " - "clock.\n"); + printf(" -s, --start-time \n"); + printf(" The logical start time of the program, expressed as an absolute time point\n"); + printf(" which is the duration since the epoch of the underlying system clock.\n"); printf(" The units are nsec, usec, msec, sec, minute, hour, day, week or the plurals of those.\n"); - printf(" On linux, to compute a start time in 2 minutes you can do:.\n"); + printf(" On linux, to compute a start time of 2 minutes into the future, expressed in seconds, do:\n"); printf(" `date -d \"2 minutes\" +%%s`.\n\n"); #ifdef FEDERATED printf(" -r, --rti \n"); @@ -1261,3 +1261,15 @@ index_t lf_combine_deadline_and_level(interval_t deadline, int level) { else return (deadline << 16) | level; } + +void _lf_set_and_wait_for_start_time() { + if (!start_time_specified) { + start_time = lf_time_physical(); + } else { + instant_t now = lf_time_physical(); + if (!fast && now < start_time) { + lf_print("Sleeping " PRINTF_TIME " ns until specified start time", start_time - now); + lf_sleep(start_time - now); + } + } +} \ No newline at end of file diff --git a/core/threaded/reactor_threaded.c b/core/threaded/reactor_threaded.c index 5bc797ab0..d61973549 100644 --- a/core/threaded/reactor_threaded.c +++ b/core/threaded/reactor_threaded.c @@ -1017,15 +1017,9 @@ int lf_reactor_c_main(int argc, const char* argv[]) { // Initialize the clock through the platform API. No reading of physical time before this. _lf_initialize_clock(); - if (!start_time_specified) { - start_time = lf_time_physical(); - } else { - instant_t now = lf_time_physical(); - if (now < start_time) { - LF_PRINT_LOG("Sleeping " PRINTF_TIME " ns until start time", start_time - now); - lf_sleep(start_time - now); - } - } + // Set the start time of the program (if it is not set from the command line). Possibly wait for + // it to arrive also. + _lf_set_and_wait_for_start_time(); #ifndef FEDERATED lf_tracing_set_start_time(start_time); #endif diff --git a/include/core/reactor_common.h b/include/core/reactor_common.h index 1ff26733a..049672c22 100644 --- a/include/core/reactor_common.h +++ b/include/core/reactor_common.h @@ -66,6 +66,11 @@ extern struct allocation_record_t* _lf_reactors_to_free; ////////////////////// Functions ////////////////////// +/** + * @brief Set the start time of the program and possibly wait for it to arrive. + */ +void _lf_set_and_wait_for_start_time(); + /** * @brief Combine a deadline and a level into a single index for sorting in the reaction queue. *