Skip to content

Commit dd0b3ca

Browse files
committed
Factor setting and waiting for start time into a separate function
1 parent a1c7c4d commit dd0b3ca

File tree

4 files changed

+27
-23
lines changed

4 files changed

+27
-23
lines changed

core/reactor.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -328,16 +328,9 @@ int lf_reactor_c_main(int argc, const char* argv[]) {
328328

329329
LF_PRINT_DEBUG("Initializing.");
330330
initialize_global();
331-
// Set start time
332-
if (!start_time_specified) {
333-
start_time = lf_time_physical();
334-
} else {
335-
instant_t now = lf_time_physical();
336-
if (now < start_time) {
337-
LF_PRINT_LOG("Sleeping " PRINTF_TIME " ns until start time", start_time - now);
338-
lf_sleep(start_time - now);
339-
}
340-
}
331+
// Set the start time of the program (if it is not set from the command line). Possibly wait for
332+
// it to arrive also.
333+
_lf_set_and_wait_for_start_time();
341334
#ifndef FEDERATED
342335
lf_tracing_set_start_time(start_time);
343336
#endif

core/reactor_common.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -885,11 +885,11 @@ void usage(int argc, const char* argv[]) {
885885
printf(" Executed in <n> threads if possible (optional feature).\n\n");
886886
printf(" -i, --id <n>\n");
887887
printf(" The ID of the federation that this reactor will join.\n\n");
888-
printf(" -s, --start-time <duration> <units> \n");
889-
printf(" The logical start time of the program, expressed as a duration since the epoch of the underlying system "
890-
"clock.\n");
888+
printf(" -s, --start-time <time-point> <units> \n");
889+
printf(" The logical start time of the program, expressed as an absolute time point\n");
890+
printf(" which is the duration since the epoch of the underlying system clock.\n");
891891
printf(" The units are nsec, usec, msec, sec, minute, hour, day, week or the plurals of those.\n");
892-
printf(" On linux, to compute a start time in 2 minutes you can do:.\n");
892+
printf(" On linux, to compute a start time of 2 minutes into the future, expressed in seconds, do:\n");
893893
printf(" `date -d \"2 minutes\" +%%s`.\n\n");
894894
#ifdef FEDERATED
895895
printf(" -r, --rti <n>\n");
@@ -1261,3 +1261,15 @@ index_t lf_combine_deadline_and_level(interval_t deadline, int level) {
12611261
else
12621262
return (deadline << 16) | level;
12631263
}
1264+
1265+
void _lf_set_and_wait_for_start_time() {
1266+
if (!start_time_specified) {
1267+
start_time = lf_time_physical();
1268+
} else {
1269+
instant_t now = lf_time_physical();
1270+
if (!fast && now < start_time) {
1271+
lf_print("Sleeping " PRINTF_TIME " ns until specified start time", start_time - now);
1272+
lf_sleep(start_time - now);
1273+
}
1274+
}
1275+
}

core/threaded/reactor_threaded.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,15 +1017,9 @@ int lf_reactor_c_main(int argc, const char* argv[]) {
10171017

10181018
// Initialize the clock through the platform API. No reading of physical time before this.
10191019
_lf_initialize_clock();
1020-
if (!start_time_specified) {
1021-
start_time = lf_time_physical();
1022-
} else {
1023-
instant_t now = lf_time_physical();
1024-
if (now < start_time) {
1025-
LF_PRINT_LOG("Sleeping " PRINTF_TIME " ns until start time", start_time - now);
1026-
lf_sleep(start_time - now);
1027-
}
1028-
}
1020+
// Set the start time of the program (if it is not set from the command line). Possibly wait for
1021+
// it to arrive also.
1022+
_lf_set_and_wait_for_start_time();
10291023
#ifndef FEDERATED
10301024
lf_tracing_set_start_time(start_time);
10311025
#endif

include/core/reactor_common.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ extern struct allocation_record_t* _lf_reactors_to_free;
6666

6767
////////////////////// Functions //////////////////////
6868

69+
/**
70+
* @brief Set the start time of the program and possibly wait for it to arrive.
71+
*/
72+
void _lf_set_and_wait_for_start_time();
73+
6974
/**
7075
* @brief Combine a deadline and a level into a single index for sorting in the reaction queue.
7176
*

0 commit comments

Comments
 (0)