Skip to content

Commit

Permalink
Factor setting and waiting for start time into a separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
erlingrj committed Dec 9, 2024
1 parent a1c7c4d commit dd0b3ca
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 23 deletions.
13 changes: 3 additions & 10 deletions core/reactor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 16 additions & 4 deletions core/reactor_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -885,11 +885,11 @@ void usage(int argc, const char* argv[]) {
printf(" Executed in <n> threads if possible (optional feature).\n\n");
printf(" -i, --id <n>\n");
printf(" The ID of the federation that this reactor will join.\n\n");
printf(" -s, --start-time <duration> <units> \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 <time-point> <units> \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>\n");
Expand Down Expand Up @@ -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);
}
}
}
12 changes: 3 additions & 9 deletions core/threaded/reactor_threaded.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions include/core/reactor_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit dd0b3ca

Please sign in to comment.