Skip to content
Snippets Groups Projects

Use a fix timer in the injection loop

Closed Peter W. Draper requested to merge fixed-injections into master
1 file
+ 20
33
Compare changes
  • Side-by-side
  • Inline
+ 20
33
@@ -38,6 +38,9 @@ static int verbose = 0;
@@ -38,6 +38,9 @@ static int verbose = 0;
/* Attempt to keep original injection time differences. */
/* Attempt to keep original injection time differences. */
static int usetics = 1;
static int usetics = 1;
 
/* The wait between injections, nanosecs. */
 
static long long waitns = 10000;
 
/* Integer types of send and recv tasks, must match log. */
/* Integer types of send and recv tasks, must match log. */
static const int task_type_send = 22;
static const int task_type_send = 22;
static const int task_type_recv = 23;
static const int task_type_recv = 23;
@@ -81,38 +84,16 @@ static void *inject_thread(void *arg) {
@@ -81,38 +84,16 @@ static void *inject_thread(void *arg) {
ticks looptics = 0;
ticks looptics = 0;
double deadtime = 0.0;
double deadtime = 0.0;
 
struct timespec sleep;
 
sleep.tv_sec = 0;
 
while (ind_req < nr_reqs) {
while (ind_req < nr_reqs) {
struct mpiuse_log_entry *log = reqs_queue[ind_req];
struct mpiuse_log_entry *log = reqs_queue[ind_req];
if (usetics) {
if (usetics) {
/* Expect time between this request and the previous one. */
sleep.tv_nsec = waitns;
ticks dt = log->tic - basetic;
nanosleep(&sleep, NULL);
basetic = log->tic;
deadtime += sleep.tv_nsec;
/* We guess some time below which we should not attempt to wait,
* otherwise we'll start to overrun, and just inject the next call if we
* are below that (we time the ticks this loop takes without any waiting
* and use that). Otherwise we wait a while. Note we need to convert the
* ticks of the log file into nanoseconds, that requires the original
* CPU frequency. */
if (dt > looptics) {
struct timespec sleep;
sleep.tv_sec = 0;
/* Remember to be fair and remove the looptics, then convert to
* nanoseconds. */
double ns = (double)(dt - looptics) / log_clocks_cpufreq * 1.0e9;
if (ns < 1.0e9) {
sleep.tv_nsec = (long)ns;
} else {
/* Wait more than one second. Must be an error, but complain and
* continue. */
sleep.tv_nsec = (long)1.0e9;
message("wait greater than one second");
}
nanosleep(&sleep, NULL);
deadtime += sleep.tv_nsec;
}
}
}
/* Initialise new log elements. */
/* Initialise new log elements. */
@@ -151,7 +132,8 @@ static void *inject_thread(void *arg) {
@@ -151,7 +132,8 @@ static void *inject_thread(void *arg) {
/* Set looptics on the first pass. Assumes MPI_Isend and MPI_Irecv are
/* Set looptics on the first pass. Assumes MPI_Isend and MPI_Irecv are
* equally timed. */
* equally timed. */
if (looptics == 0 && usetics) {
if (looptics == 0 && usetics) {
looptics = getticks() - starttics;
/* Not well matched, so try a lower value. */
 
looptics = (getticks() - starttics) / 4;
if (verbose)
if (verbose)
message("injection loop took %.3f %s.", clocks_from_ticks(looptics),
message("injection loop took %.3f %s.", clocks_from_ticks(looptics),
clocks_getunit());
clocks_getunit());
@@ -355,9 +337,10 @@ static void pick_logs(void) {
@@ -355,9 +337,10 @@ static void pick_logs(void) {
* @brief usage help.
* @brief usage help.
*/
*/
static void usage(char *argv[]) {
static void usage(char *argv[]) {
fprintf(stderr, "Usage: %s [-vf] SWIFT_mpiuse-log-file.dat logfile.dat\n",
fprintf(stderr, "Usage: %s [-vf] [-n nanosec] SWIFT_mpiuse-log-file.dat "
argv[0]);
"logfile.dat\n", argv[0]);
fprintf(stderr, " options: -v verbose, -f fast injections\n");
fprintf(stderr, " options: -v verbose, -f fast injections, "
 
"-n nanoseconds to wait\n");
fflush(stderr);
fflush(stderr);
}
}
@@ -383,7 +366,7 @@ int main(int argc, char *argv[]) {
@@ -383,7 +366,7 @@ int main(int argc, char *argv[]) {
/* Handle the command-line, we expect a mpiuse data file to read and various
/* Handle the command-line, we expect a mpiuse data file to read and various
* options. */
* options. */
int opt;
int opt;
while ((opt = getopt(argc, argv, "vf")) != -1) {
while ((opt = getopt(argc, argv, "vfn:")) != -1) {
switch (opt) {
switch (opt) {
case 'f':
case 'f':
usetics = 0;
usetics = 0;
@@ -391,6 +374,9 @@ int main(int argc, char *argv[]) {
@@ -391,6 +374,9 @@ int main(int argc, char *argv[]) {
case 'v':
case 'v':
verbose = 1;
verbose = 1;
break;
break;
 
case 'n':
 
waitns = atoll(optarg);
 
break;
default:
default:
if (myrank == 0) usage(argv);
if (myrank == 0) usage(argv);
return 1;
return 1;
@@ -428,6 +414,7 @@ int main(int argc, char *argv[]) {
@@ -428,6 +414,7 @@ int main(int argc, char *argv[]) {
if (myrank == 0) {
if (myrank == 0) {
message("Start of MPI tests");
message("Start of MPI tests");
message("==================");
message("==================");
 
message("injecting fixed waits of %lld ns", waitns);
}
}
/* Make three threads, one for injecting tasks and two to check for
/* Make three threads, one for injecting tasks and two to check for
Loading