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
+ 20
33
@@ -38,6 +38,9 @@ static int verbose = 0;
/* Attempt to keep original injection time differences. */
static int usetics = 1;
/* The wait between injections, nanosecs. */
static long long waitns = 10000;
/* Integer types of send and recv tasks, must match log. */
static const int task_type_send = 22;
static const int task_type_recv = 23;
@@ -83,36 +86,16 @@ static void *inject_thread(void *arg) {
struct timespec sleep;
sleep.tv_sec = 0;
struct timespec sleep;
sleep.tv_sec = 0;
while (ind_req < nr_reqs) {
struct mpiuse_log_entry *log = reqs_queue[ind_req];
if (usetics) {
/* Expect time between this request and the previous one. */
ticks dt = log->tic - basetic;
basetic = log->tic;
/* 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) {
/* 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;
}
sleep.tv_nsec = waitns;
nanosleep(&sleep, NULL);
deadtime += sleep.tv_nsec;
}
/* Initialise new log elements. */
@@ -151,9 +134,8 @@ static void *inject_thread(void *arg) {
/* Set looptics on the first pass. Assumes MPI_Isend and MPI_Irecv are
* equally timed. Note we include a nanosleep, they are slow. */
if (looptics == 0 && usetics) {
sleep.tv_nsec = 1;
nanosleep(&sleep, NULL);
looptics = (getticks() - starttics);
/* Not well matched, so try a lower value. */
looptics = (getticks() - starttics) / 4;
if (verbose)
message("injection loop took %.3f %s.", clocks_from_ticks(looptics),
clocks_getunit());
@@ -364,9 +346,10 @@ static void pick_logs(void) {
* @brief usage help.
*/
static void usage(char *argv[]) {
fprintf(stderr, "Usage: %s [-vf] SWIFT_mpiuse-log-file.dat logfile.dat\n",
argv[0]);
fprintf(stderr, " options: -v verbose, -f fast injections\n");
fprintf(stderr, "Usage: %s [-vf] [-n nanosec] SWIFT_mpiuse-log-file.dat "
"logfile.dat\n", argv[0]);
fprintf(stderr, " options: -v verbose, -f fast injections, "
"-n nanoseconds to wait\n");
fflush(stderr);
}
@@ -392,7 +375,7 @@ int main(int argc, char *argv[]) {
/* Handle the command-line, we expect a mpiuse data file to read and various
* options. */
int opt;
while ((opt = getopt(argc, argv, "vf")) != -1) {
while ((opt = getopt(argc, argv, "vfn:")) != -1) {
switch (opt) {
case 'f':
usetics = 0;
@@ -400,6 +383,9 @@ int main(int argc, char *argv[]) {
case 'v':
verbose = 1;
break;
case 'n':
waitns = atoll(optarg);
break;
default:
if (myrank == 0) usage(argv);
return 1;
@@ -438,6 +424,7 @@ int main(int argc, char *argv[]) {
if (myrank == 0) {
message("Start of MPI tests");
message("==================");
message("injecting fixed waits of %lld ns", waitns);
}
/* Make three threads, one for injecting tasks and two to check for
Loading