diff --git a/fabtests/benchmarks/benchmark_shared.c b/fabtests/benchmarks/benchmark_shared.c index bace77c01d1..d07c1bf4476 100644 --- a/fabtests/benchmarks/benchmark_shared.c +++ b/fabtests/benchmarks/benchmark_shared.c @@ -94,15 +94,14 @@ void ft_benchmark_usage(void) } /* Pingpong latency test with pre-posted receive buffers. */ -static int pingpong_pre_posted_rx(size_t inject_size) +static int pingpong_pre_posted_rx(size_t inject_size, union ft_timer *timer) { int ret, i; if (opts.dst_addr) { for (i = 0; i < opts.iterations + opts.warmup_iterations; i++) { if (i == opts.warmup_iterations) - ft_start(); - + ft_start(timer); if (opts.transfer_size <= inject_size) ret = ft_inject(ep, remote_fi_addr, opts.transfer_size); @@ -119,7 +118,7 @@ static int pingpong_pre_posted_rx(size_t inject_size) } else { for (i = 0; i < opts.iterations + opts.warmup_iterations; i++) { if (i == opts.warmup_iterations) - ft_start(); + ft_start(timer); ret = ft_rx(ep, opts.transfer_size); if (ret) @@ -135,20 +134,20 @@ static int pingpong_pre_posted_rx(size_t inject_size) return ret; } } - ft_stop(); + ft_stop(timer); return FI_SUCCESS; } /* Pingpong latency test without pre-posted receive buffers. */ -static int pingpong_no_pre_posted_rx(size_t inject_size) +static int pingpong_no_pre_posted_rx(size_t inject_size, union ft_timer *timer) { int ret, i; if (opts.dst_addr) { for (i = 0; i < opts.iterations + opts.warmup_iterations; i++) { if (i == opts.warmup_iterations) - ft_start(); + ft_start(timer); if (opts.transfer_size <= inject_size) ret = ft_inject(ep, remote_fi_addr, @@ -170,7 +169,7 @@ static int pingpong_no_pre_posted_rx(size_t inject_size) } else { for (i = 0; i < opts.iterations + opts.warmup_iterations; i++) { if (i == opts.warmup_iterations) - ft_start(); + ft_start(timer); ret = ft_post_rx(ep, opts.transfer_size, &rx_ctx); if (ret) @@ -197,7 +196,7 @@ static int pingpong_no_pre_posted_rx(size_t inject_size) return ret; } } - ft_stop(); + ft_stop(timer); return FI_SUCCESS; } @@ -205,6 +204,7 @@ static int pingpong_no_pre_posted_rx(size_t inject_size) int pingpong(void) { int ret; + union ft_timer timer = {}; size_t inject_size = fi->tx_attr->inject_size; ret = fi_getopt(&ep->fid, FI_OPT_ENDPOINT, FI_OPT_INJECT_MSG_SIZE, @@ -236,7 +236,7 @@ int pingpong(void) return ret; } - ret = pingpong_no_pre_posted_rx(inject_size); + ret = pingpong_no_pre_posted_rx(inject_size, &timer); if (ret) return ret; } else { @@ -244,16 +244,16 @@ int pingpong(void) if (ret) return ret; - ret = pingpong_pre_posted_rx(inject_size); + ret = pingpong_pre_posted_rx(inject_size, &timer); if (ret) return ret; } if (opts.machr) - show_perf_mr(opts.transfer_size, opts.iterations, &start, &end, 2, + show_perf_mr(opts.transfer_size, opts.iterations, timer, 2, opts.argc, opts.argv); else - show_perf(NULL, opts.transfer_size, opts.iterations, &start, &end, 2); + show_perf(NULL, opts.transfer_size, opts.iterations, timer, 2); return 0; } @@ -296,6 +296,7 @@ int run_pingpong(void) int pingpong_rma(enum ft_rma_opcodes rma_op, struct fi_rma_iov *remote) { int ret, i; + union ft_timer timer = {}; size_t inject_size = fi->tx_attr->inject_size; ret = fi_getopt(&ep->fid, FI_OPT_ENDPOINT, FI_OPT_INJECT_RMA_SIZE, @@ -335,7 +336,7 @@ int pingpong_rma(enum ft_rma_opcodes rma_op, struct fi_rma_iov *remote) for (i = 0; i < opts.iterations + opts.warmup_iterations; i++) { if (i == opts.warmup_iterations) - ft_start(); + ft_start(&timer); if (rma_op == FT_RMA_WRITE) *(tx_buf + opts.transfer_size - 1) = (char)i; @@ -357,7 +358,7 @@ int pingpong_rma(enum ft_rma_opcodes rma_op, struct fi_rma_iov *remote) } else { for (i = 0; i < opts.iterations + opts.warmup_iterations; i++) { if (i == opts.warmup_iterations) - ft_start(); + ft_start(&timer); ret = ft_rx_rma(i, rma_op, ep, opts.transfer_size); if (ret) @@ -377,13 +378,13 @@ int pingpong_rma(enum ft_rma_opcodes rma_op, struct fi_rma_iov *remote) return ret; } } - ft_stop(); + ft_stop(&timer); if (opts.machr) - show_perf_mr(opts.transfer_size, opts.iterations, &start, &end, 2, + show_perf_mr(opts.transfer_size, opts.iterations, timer, 2, opts.argc, opts.argv); else - show_perf(NULL, opts.transfer_size, opts.iterations, &start, &end, 2); + show_perf(NULL, opts.transfer_size, opts.iterations, timer, 2); return 0; } @@ -391,6 +392,7 @@ int pingpong_rma(enum ft_rma_opcodes rma_op, struct fi_rma_iov *remote) int rma_tx_completion(enum ft_rma_opcodes rma_op, struct fi_rma_iov *remote) { int ret, i; + union ft_timer timer = {}; size_t inject_size = fi->tx_attr->inject_size; ret = fi_getopt(&ep->fid, FI_OPT_ENDPOINT, FI_OPT_INJECT_RMA_SIZE, @@ -418,7 +420,7 @@ int rma_tx_completion(enum ft_rma_opcodes rma_op, struct fi_rma_iov *remote) if (opts.dst_addr) { for (i = 0; i < opts.iterations + opts.warmup_iterations; i++) { if (i == opts.warmup_iterations) - ft_start(); + ft_start(&timer); if (opts.transfer_size <= inject_size) ret = ft_inject_rma(rma_op, remote, ep, @@ -431,12 +433,12 @@ int rma_tx_completion(enum ft_rma_opcodes rma_op, struct fi_rma_iov *remote) return ret; } - ft_stop(); + ft_stop(&timer); if (opts.machr) - show_perf_mr(opts.transfer_size, opts.iterations, &start, &end, 1, + show_perf_mr(opts.transfer_size, opts.iterations, timer, 1, opts.argc, opts.argv); else - show_perf(NULL, opts.transfer_size, opts.iterations, &start, &end, 1); + show_perf(NULL, opts.transfer_size, opts.iterations, timer, 1); /* Inform RMA target that the test has ended */ ret = ft_sync(); @@ -461,14 +463,19 @@ int rma_tx_completion(enum ft_rma_opcodes rma_op, struct fi_rma_iov *remote) return 0; } -static int bw_tx_comp() +static int bw_tx_comp(union ft_timer *timer) { int ret; ret = ft_get_tx_comp(tx_seq); if (ret) return ret; - return ft_rx(ep, FT_RMA_SYNC_MSG_BYTES); + if (timer) + ft_timer_pause(timer); + ret = ft_rx(ep, FT_RMA_SYNC_MSG_BYTES); + if (timer) + ft_timer_resume(timer); + return ret; } static int bw_rx_comp(int window) @@ -493,7 +500,7 @@ static int bw_rx_comp(int window) return ft_tx(ep, remote_fi_addr, FT_RMA_SYNC_MSG_BYTES, &tx_ctx); } -static int rma_bw_rx_comp() +static int rma_bw_rx_comp(union ft_timer *timer) { int ret; @@ -501,8 +508,12 @@ static int rma_bw_rx_comp() ret = ft_get_rx_comp(rx_seq - 1); if (ret) return ret; - - return ft_tx(ep, remote_fi_addr, FT_RMA_SYNC_MSG_BYTES, &tx_ctx); + if (timer) + ft_timer_pause(timer); + ret = ft_tx(ep, remote_fi_addr, FT_RMA_SYNC_MSG_BYTES, &tx_ctx); + if (timer) + ft_timer_resume(timer); + return ret; } static uint64_t set_fi_more_flag(int i, int j, uint64_t flags) @@ -520,6 +531,7 @@ int bandwidth(void) { int ret, i, j; uint64_t flags = 0; + union ft_timer timer = {}; size_t inject_size = fi->tx_attr->inject_size; ret = fi_getopt(&ep->fid, FI_OPT_ENDPOINT, FI_OPT_INJECT_MSG_SIZE, @@ -549,7 +561,7 @@ int bandwidth(void) if (opts.dst_addr) { for (i = j = 0; i < opts.iterations + opts.warmup_iterations; i++) { if (i == opts.warmup_iterations) - ft_start(); + ft_start(&timer); if (ft_check_opts(FT_OPT_VERIFY_DATA)) { ret = ft_fill_buf(tx_ctx_arr[j].buf, @@ -578,19 +590,19 @@ int bandwidth(void) return ret; if (++j == opts.window_size) { - ret = bw_tx_comp(); + ret = bw_tx_comp(NULL); if (ret) return ret; j = 0; } } - ret = bw_tx_comp(); + ret = bw_tx_comp(NULL); if (ret) return ret; } else { for (i = j = 0; i < opts.iterations + opts.warmup_iterations; i++) { if (i == opts.warmup_iterations) - ft_start(); + ft_start(&timer); if (opts.use_fi_more) { flags = set_fi_more_flag(i, j, flags); @@ -620,18 +632,18 @@ int bandwidth(void) if (ret) return ret; } - ft_stop(); + ft_stop(&timer); if (opts.machr) - show_perf_mr(opts.transfer_size, opts.iterations, &start, &end, 1, + show_perf_mr(opts.transfer_size, opts.iterations, timer, 1, opts.argc, opts.argv); else - show_perf(NULL, opts.transfer_size, opts.iterations, &start, &end, 1); + show_perf(NULL, opts.transfer_size, opts.iterations, timer, 1); return 0; } -static int bw_rma_comp(enum ft_rma_opcodes rma_op, int num_completions) +static int bw_rma_comp(enum ft_rma_opcodes rma_op, int num_completions, union ft_timer *timer) { int ret; @@ -639,8 +651,8 @@ static int bw_rma_comp(enum ft_rma_opcodes rma_op, int num_completions) /* for writedata, only the client sends, * and only the server verifies. */ if (opts.dst_addr) - return bw_tx_comp(); - ret = rma_bw_rx_comp(); + return bw_tx_comp(timer); + ret = rma_bw_rx_comp(timer); } else { ret = ft_get_tx_comp(tx_seq); } @@ -662,6 +674,7 @@ int bandwidth_rma(enum ft_rma_opcodes rma_op, struct fi_rma_iov *remote) { int ret, i, j; uint64_t flags = 0; + union ft_timer timer = {}; size_t offset, inject_size = fi->tx_attr->inject_size; ret = fi_getopt(&ep->fid, FI_OPT_ENDPOINT, FI_OPT_INJECT_RMA_SIZE, @@ -690,7 +703,7 @@ int bandwidth_rma(enum ft_rma_opcodes rma_op, struct fi_rma_iov *remote) MAX(ft_tx_prefix_size(), ft_rx_prefix_size()); for (i = j = 0; i < opts.iterations + opts.warmup_iterations; i++) { if (i == opts.warmup_iterations) - ft_start(); + ft_start(&timer); if (j == 0) { offset = offset_rma_start; if (ft_check_opts(FT_OPT_VERIFY_DATA) && opts.transfer_size > 0) { @@ -768,22 +781,22 @@ int bandwidth_rma(enum ft_rma_opcodes rma_op, struct fi_rma_iov *remote) return ret; if (++j == opts.window_size) { - ret = bw_rma_comp(rma_op, j); + ret = bw_rma_comp(rma_op, j, &timer); if (ret) return ret; j = 0; } offset += opts.transfer_size; } - ret = bw_rma_comp(rma_op, j); + ret = bw_rma_comp(rma_op, j, &timer); if (ret) return ret; - ft_stop(); + ft_stop(&timer); if (opts.machr) - show_perf_mr(opts.transfer_size, opts.iterations, &start, &end, 1, + show_perf_mr(opts.transfer_size, opts.iterations, timer, 1, opts.argc, opts.argv); else - show_perf(NULL, opts.transfer_size, opts.iterations, &start, &end, 1); + show_perf(NULL, opts.transfer_size, opts.iterations, timer, 1); return 0; } diff --git a/fabtests/benchmarks/rdm_bw_mt.c b/fabtests/benchmarks/rdm_bw_mt.c index 330a870eee9..400824878ec 100644 --- a/fabtests/benchmarks/rdm_bw_mt.c +++ b/fabtests/benchmarks/rdm_bw_mt.c @@ -94,6 +94,7 @@ struct thread_args { struct fi_context2 recv_ctx; char *tx_buf; char *rx_buf; + union ft_timer *timer; int id; int ret; }; @@ -440,6 +441,8 @@ static int bw_recv(void *context) static void *uni_bandwidth(void *context) { int i, ret; + struct thread_args *targs = context; + union ft_timer *timer = targs->timer; pthread_barrier_wait(&barrier); for (i = 0; i < opts.warmup_iterations; i++) { @@ -452,8 +455,8 @@ static void *uni_bandwidth(void *context) } pthread_barrier_wait(&barrier); - if (targs->id == 0) - ft_start(); + if (timer) + ft_timer_start(timer); for (i = 0; i < opts.iterations; i++) { ret = opts.dst_addr ? bw_send(context) : bw_recv(context); if (ret) { @@ -462,8 +465,8 @@ static void *uni_bandwidth(void *context) } } pthread_barrier_wait(&barrier); - if (targs->id == 0) - ft_stop(); + if (timer) + ft_timer_stop(timer); return NULL; } @@ -472,6 +475,7 @@ static void *bi_bandwidth(void *context) { int i, ret; struct thread_args *targs = context; + union ft_timer *timer = targs->timer; pthread_barrier_wait(&barrier); for (i = 0; i < opts.warmup_iterations; i++) { @@ -490,8 +494,8 @@ static void *bi_bandwidth(void *context) } pthread_barrier_wait(&barrier); - if (targs->id == 0) - ft_start(); + if (timer) + ft_timer_start(timer); for (i = 0; i < opts.iterations; i++) { ret = opts.dst_addr ? bw_send(context) : bw_recv(context); @@ -508,8 +512,8 @@ static void *bi_bandwidth(void *context) } } pthread_barrier_wait(&barrier); - if (targs->id == 0) - ft_stop(); + if (timer) + ft_timer_stop(timer); return NULL; } @@ -517,6 +521,7 @@ static void *bi_bandwidth(void *context) static int run_size(void) { int i, err, ret = FI_SUCCESS; + union ft_timer timer; for (i = 0; i < num_eps; i++) { targs[i].id = i; @@ -525,6 +530,7 @@ static int run_size(void) if (ret) goto out; } + targs[0].timer = &timer; for (i = 0; i < num_eps; i++) { ret = pthread_create(&targs[i].thread, NULL, @@ -543,7 +549,7 @@ static int run_size(void) } } - show_perf(NULL, xfer_size, opts.iterations, &start, &end, num_eps); + show_perf(NULL, xfer_size, opts.iterations, timer, num_eps); out: for (i = 0; i < num_eps; i++) { diff --git a/fabtests/common/shared.c b/fabtests/common/shared.c index 316b39d41d7..3adf15bc7b2 100644 --- a/fabtests/common/shared.c +++ b/fabtests/common/shared.c @@ -103,7 +103,6 @@ const char *greeting = "Hello from Client!"; char test_name[50] = "custom"; int timeout = -1; -struct timespec start, end; int listen_sock = -1; int sock = -1; @@ -2704,25 +2703,23 @@ static int ft_spin_for_comp(struct fid_cq *cq, uint64_t *cur, uint64_t tag) { struct fi_cq_err_entry comp; - struct timespec a, b; + union ft_timer timer; int ret; - if (timeout >= 0) - clock_gettime(CLOCK_MONOTONIC, &a); + ft_timer_start(&timer); do { ret = fi_cq_read(cq, &comp, 1); if (ret > 0) { if (timeout >= 0) - clock_gettime(CLOCK_MONOTONIC, &a); + ft_timer_start(&timer); if (!ft_tag_is_valid(cq, &comp, tag ? tag : rx_cq_cntr)) return -FI_EOTHER; (*cur)++; } else if (ret < 0 && ret != -FI_EAGAIN) { return ret; } else if (timeout >= 0) { - clock_gettime(CLOCK_MONOTONIC, &b); - if ((b.tv_sec - a.tv_sec) > timeout) { + if (ft_timer_is_elapsed(timer, timeout, SECOND)) { fprintf(stderr, "%ds timeout expired\n", timeout); return -FI_ENODATA; } @@ -2832,11 +2829,11 @@ int ft_get_cq_comp(struct fid_cq *cq, uint64_t *cur, static int ft_spin_for_cntr(struct fid_cntr *cntr, uint64_t total, int timeout) { - struct timespec a, b; + union ft_timer timer; uint64_t cur; if (timeout >= 0) - clock_gettime(CLOCK_MONOTONIC, &a); + ft_timer_start(&timer); for (;;) { cur = fi_cntr_read(cntr); @@ -2844,8 +2841,7 @@ static int ft_spin_for_cntr(struct fid_cntr *cntr, uint64_t total, int timeout) return 0; if (timeout >= 0) { - clock_gettime(CLOCK_MONOTONIC, &b); - if ((b.tv_sec - a.tv_sec) > timeout) + if (ft_timer_is_elapsed(timer, timeout, SECOND)) break; } } @@ -3285,22 +3281,12 @@ int ft_finalize(void) return ft_finalize_ep(ep); } -int64_t get_elapsed(const struct timespec *b, const struct timespec *a, - enum precision p) -{ - int64_t elapsed; - - elapsed = difftime(a->tv_sec, b->tv_sec) * 1000 * 1000 * 1000; - elapsed += a->tv_nsec - b->tv_nsec; - return elapsed / p; -} - -void show_perf(char *name, size_t tsize, int iters, struct timespec *start, - struct timespec *end, int xfers_per_iter) +void show_perf(char *name, size_t tsize, int iters, union ft_timer timer, + int xfers_per_iter) { static int header = 1; char str[FT_STR_LEN]; - int64_t elapsed = get_elapsed(start, end, MICRO); + uint64_t elapsed = ft_timer_get_elapsed(timer, MICRO); long long bytes = (long long) iters * tsize * xfers_per_iter; float usec_per_xfer; @@ -3336,11 +3322,11 @@ void show_perf(char *name, size_t tsize, int iters, struct timespec *start, usec_per_xfer, 1.0/usec_per_xfer); } -void show_perf_mr(size_t tsize, int iters, struct timespec *start, - struct timespec *end, int xfers_per_iter, int argc, char *argv[]) +void show_perf_mr(size_t tsize, int iters, union ft_timer timer, + int xfers_per_iter, int argc, char *argv[]) { static int header = 1; - int64_t elapsed = get_elapsed(start, end, MICRO); + uint64_t elapsed = ft_timer_get_elapsed(timer, MICRO); long long total = (long long) iters * tsize * xfers_per_iter; int i; float usec_per_xfer; @@ -4016,7 +4002,7 @@ int ft_check_buf(void *buf, size_t size) int ft_rma_poll_buf(void *buf, int iter, size_t size) { volatile char *recv_data; - struct timespec a, b; + union ft_timer timer; if (opts.iface != FI_HMEM_SYSTEM) { FT_ERR("FI_HMEM not supported for write latency test"); @@ -4025,8 +4011,7 @@ int ft_rma_poll_buf(void *buf, int iter, size_t size) recv_data = (char *)buf + size - 1; - if (timeout >= 0) - clock_gettime(CLOCK_MONOTONIC, &a); + ft_timer_start(&timer); char expected_val = (char)iter; while (*recv_data != expected_val) { @@ -4034,8 +4019,7 @@ int ft_rma_poll_buf(void *buf, int iter, size_t size) ft_force_progress(); if (timeout >= 0) { - clock_gettime(CLOCK_MONOTONIC, &b); - if ((b.tv_sec - a.tv_sec) > timeout) { + if (ft_timer_is_elapsed(timer, timeout, SECOND)) { fprintf(stderr, "%ds timeout expired\n", timeout); return -FI_ENODATA; } diff --git a/fabtests/functional/multi_recv.c b/fabtests/functional/multi_recv.c index 672bb15c727..bcfaaeb5c1a 100644 --- a/fabtests/functional/multi_recv.c +++ b/fabtests/functional/multi_recv.c @@ -158,12 +158,13 @@ static int post_multi_recv_buffer() static int run_test(void) { int ret, i; + union ft_timer timer; ret = ft_sync(); if (ret) return ret; - ft_start(); + ft_start(&timer); if (opts.dst_addr) { for (i = 0; i < opts.iterations; i++) { ret = ft_tx(ep, remote_fi_addr, opts.transfer_size, &tx_ctx); @@ -175,14 +176,14 @@ static int run_test(void) if (ret) return ret; } - ft_stop(); + ft_stop(&timer); if (opts.machr) show_perf_mr(opts.transfer_size, opts.iterations, - &start, &end, 1, opts.argc, opts.argv); + timer, 1, opts.argc, opts.argv); else show_perf(NULL, opts.transfer_size, opts.iterations, - &start, &end, 1); + timer, 1); return ret; } diff --git a/fabtests/functional/rdm_atomic.c b/fabtests/functional/rdm_atomic.c index 915dba884d1..e8f4fcfeee9 100644 --- a/fabtests/functional/rdm_atomic.c +++ b/fabtests/functional/rdm_atomic.c @@ -224,7 +224,7 @@ static int fill_data(enum ft_atomic_opcodes opcode) return ret; } -static void report_perf(void) +static void report_perf(union ft_timer timer) { int len; @@ -234,15 +234,16 @@ static void report_perf(void) fi_tostr(&op_type, FI_TYPE_ATOMIC_OP)); if (opts.machr) - show_perf_mr(opts.transfer_size, opts.iterations, &start, &end, 1, opts.argc, + show_perf_mr(opts.transfer_size, opts.iterations, timer, 1, opts.argc, opts.argv); else - show_perf(test_name, opts.transfer_size, opts.iterations, &start, &end, 1); + show_perf(test_name, opts.transfer_size, opts.iterations, timer, 1); } static int handle_atomic_base_op(void) { int ret = FI_SUCCESS, i; + union ft_timer timer; size_t count = 0; ret = check_base_atomic_op(ep, op_type, datatype, &count); @@ -250,7 +251,7 @@ static int handle_atomic_base_op(void) return ret; opts.transfer_size = datatype_to_size(datatype); - ft_start(); + ft_start(&timer); for (i = 0; i < opts.iterations; i++) { if (ft_check_opts(FT_OPT_VERIFY_DATA)) { ret = fill_data(FT_ATOMIC_BASE); @@ -271,14 +272,15 @@ static int handle_atomic_base_op(void) return ret; } } - ft_stop(); - report_perf(); + ft_stop(&timer); + report_perf(timer); return FI_SUCCESS; } static int handle_atomic_fetch_op(void) { int ret = FI_SUCCESS, i; + union ft_timer timer; size_t count = 0; ret = check_fetch_atomic_op(ep, op_type, datatype, &count); @@ -286,7 +288,7 @@ static int handle_atomic_fetch_op(void) return ret; opts.transfer_size = datatype_to_size(datatype); - ft_start(); + ft_start(&timer); for (i = 0; i < opts.iterations; i++) { if (ft_check_opts(FT_OPT_VERIFY_DATA)) { ret = fill_data(FT_ATOMIC_FETCH); @@ -307,14 +309,15 @@ static int handle_atomic_fetch_op(void) return ret; } } - ft_stop(); - report_perf(); + ft_stop(&timer); + report_perf(timer); return FI_SUCCESS; } static int handle_atomic_compare_op(void) { int ret = FI_SUCCESS, i; + union ft_timer timer; size_t count = 0; ret = check_compare_atomic_op(ep, op_type, datatype, &count); @@ -322,7 +325,7 @@ static int handle_atomic_compare_op(void) return ret; opts.transfer_size = datatype_to_size(datatype); - ft_start(); + ft_start(&timer); for (i = 0; i < opts.iterations; i++) { if (ft_check_opts(FT_OPT_VERIFY_DATA)) { ret = fill_data(FT_ATOMIC_COMPARE); @@ -343,8 +346,8 @@ static int handle_atomic_compare_op(void) return ret; } } - ft_stop(); - report_perf(); + ft_stop(&timer); + report_perf(timer); return FI_SUCCESS; } diff --git a/fabtests/functional/unmap_mem.c b/fabtests/functional/unmap_mem.c index 01de49dd5a0..b6e7c7e8ee9 100644 --- a/fabtests/functional/unmap_mem.c +++ b/fabtests/functional/unmap_mem.c @@ -62,12 +62,13 @@ static void unmap_tx_buf(void) static int pingpong(void) { int ret, i; + union ft_timer timer; ret = ft_sync(); if (ret) return ret; - ft_start(); + ft_start(&timer); if (opts.dst_addr) { for (i = 0; i < opts.iterations; i++) { ret = map_tx_buf(); @@ -99,9 +100,9 @@ static int pingpong(void) unmap_tx_buf(); } } - ft_stop(); + ft_stop(&timer); - show_perf(NULL, opts.transfer_size, opts.iterations, &start, &end, 2); + show_perf(NULL, opts.transfer_size, opts.iterations, timer, 2); return 0; } diff --git a/fabtests/include/shared.h b/fabtests/include/shared.h index 0729013b3b0..2b719fde2ad 100644 --- a/fabtests/include/shared.h +++ b/fabtests/include/shared.h @@ -109,6 +109,7 @@ enum precision { NANO = 1, MICRO = 1000, MILLI = 1000000, + SECOND = 1000000000, }; enum ft_comp_method { @@ -225,6 +226,11 @@ struct ft_opts { char **argv; }; +union ft_timer { + uint64_t elapsed; + uint64_t start; +}; + extern struct fi_info *fi_pep, *fi, *hints; extern struct fid_fabric *fabric; extern struct fid_wait *waitset; @@ -263,7 +269,6 @@ extern struct fi_cntr_attr cntr_attr; extern struct fi_rma_iov remote; extern char test_name[50]; -extern struct timespec start, end; extern struct ft_opts opts; void ft_parseinfo(int op, char *optarg, struct fi_info *hints, @@ -520,14 +525,43 @@ static inline uint64_t ft_gettime_ms(void) return ft_gettime_ns() / 1000000; } -static inline void ft_start(void) +static inline void ft_timer_start(union ft_timer *timer) +{ + timer->start = ft_gettime_ns(); +} +static inline void ft_timer_pause(union ft_timer *timer) +{ + timer->elapsed = ft_gettime_ns() - timer->start; +} +static inline void ft_timer_resume(union ft_timer *timer) +{ + timer->start = ft_gettime_ns() - timer->elapsed; +} +static inline void ft_timer_stop(union ft_timer *timer) +{ + ft_timer_pause(timer); +} +static inline bool ft_timer_is_elapsed(union ft_timer timer, uint64_t timeout, enum precision p) +{ + // assuming timer is running + return ft_gettime_ns() - timer.start >= timeout * p; +} +static inline uint64_t ft_timer_get_elapsed(union ft_timer timer, enum precision p) +{ + // assiming timer is stopped + return timer.elapsed / p; +} + +static inline void ft_start(union ft_timer *timer) { opts.options |= FT_OPT_ACTIVE; - clock_gettime(CLOCK_MONOTONIC, &start); + if (timer) + ft_timer_start(timer); } -static inline void ft_stop(void) +static inline void ft_stop(union ft_timer *timer) { - clock_gettime(CLOCK_MONOTONIC, &end); + if (timer) + ft_timer_stop(timer); opts.options &= ~FT_OPT_ACTIVE; } @@ -644,12 +678,10 @@ int ft_cq_read_verify(struct fid_cq *cq, void *op_context); void eq_readerr(struct fid_eq *eq, const char *eq_str); int ft_poll_fd(int fd, int timeout); -int64_t get_elapsed(const struct timespec *b, const struct timespec *a, - enum precision p); -void show_perf(char *name, size_t tsize, int iters, struct timespec *start, - struct timespec *end, int xfers_per_iter); -void show_perf_mr(size_t tsize, int iters, struct timespec *start, - struct timespec *end, int xfers_per_iter, int argc, char *argv[]); +void show_perf(char *name, size_t tsize, int iters, union ft_timer timer, + int xfers_per_iter); +void show_perf_mr(size_t tsize, int iters, union ft_timer timer, + int xfers_per_iter, int argc, char *argv[]); void ft_parse_opts_range(char *optarg); int ft_send_recv_greeting(struct fid_ep *ep); int ft_send_greeting(struct fid_ep *ep); diff --git a/fabtests/prov/efa/src/efa_exhaust_mr_reg_common.c b/fabtests/prov/efa/src/efa_exhaust_mr_reg_common.c index fe825431990..5bc23653110 100644 --- a/fabtests/prov/efa/src/efa_exhaust_mr_reg_common.c +++ b/fabtests/prov/efa/src/efa_exhaust_mr_reg_common.c @@ -151,6 +151,7 @@ void ft_efa_free_bufs(void **buffers, size_t count) { int ft_efa_unexpected_pingpong(void) { int ret, i; + union ft_timer timer; opts.options |= FT_OPT_OOB_CTRL; @@ -160,7 +161,7 @@ int ft_efa_unexpected_pingpong(void) for (i = 0; i < opts.iterations + opts.warmup_iterations; i++) { if (i == opts.warmup_iterations) - ft_start(); + ft_start(&timer); ret = ft_post_tx(ep, remote_fi_addr, opts.transfer_size, NO_CQ_DATA, &tx_ctx); if (ret) @@ -181,14 +182,13 @@ int ft_efa_unexpected_pingpong(void) return ret; } - ft_stop(); + ft_stop(&timer); if (opts.machr) - show_perf_mr(opts.transfer_size, opts.iterations, &start, &end, + show_perf_mr(opts.transfer_size, opts.iterations, timer, 2, opts.argc, opts.argv); else - show_perf(NULL, opts.transfer_size, opts.iterations, &start, - &end, 2); + show_perf(NULL, opts.transfer_size, opts.iterations, timer, 2); return 0; } diff --git a/fabtests/prov/efa/src/efa_gda.c b/fabtests/prov/efa/src/efa_gda.c index 4c3b881e8a6..f19673e56fe 100644 --- a/fabtests/prov/efa/src/efa_gda.c +++ b/fabtests/prov/efa/src/efa_gda.c @@ -205,6 +205,7 @@ static int run() uint32_t remote_qkey; struct ibv_wc wc; uint64_t lkey; + union ft_timer timer; ret = ft_sync(); if (ret) { @@ -234,7 +235,7 @@ static int run() return ret; } - ft_start(); + ft_start(&timer); for (int i = 0; i < opts.iterations; i++) { ret = efagda_post_send(gda_qp, ah, remote_qpn, remote_qkey, (uintptr_t) tx_buf, @@ -263,8 +264,7 @@ static int run() return ret; } - ft_stop(); - if ((end.tv_sec - start.tv_sec) > timeout) { + if (ft_timer_is_elapsed(timer, timeout, SECOND)) { fprintf(stderr, "client %ds timeout expired\n", timeout); @@ -272,9 +272,8 @@ static int run() } } while (ret == 0); } - ft_stop(); } else { - ft_start(); + ft_timer_start(&timer); for (int i = 0; i < opts.iterations; i++) { ret = efagda_post_recv(gda_qp, (uintptr_t) rx_buf, opts.transfer_size, lkey, stream); @@ -300,8 +299,7 @@ static int run() return ret; } - ft_stop(); - if ((end.tv_sec - start.tv_sec) > timeout) { + if (ft_timer_is_elapsed(timer, timeout, SECOND)) { fprintf(stderr, "server %ds timeout expired\n", timeout); @@ -317,10 +315,10 @@ static int run() return ret; } } - ft_stop(); } + ft_stop(&timer); - show_perf(NULL, opts.transfer_size, opts.iterations, &start, &end, 2); + show_perf(NULL, opts.transfer_size, opts.iterations, timer, 2); return ret; } @@ -348,7 +346,7 @@ int main(int argc, char **argv) ft_parse_api_opts(op, optarg, hints, &opts); break; case 'v': - opts.options |= FT_OPT_VERIFY_DATA | FT_OPT_ACTIVE; + opts.options |= FT_OPT_VERIFY_DATA; break; case '?': case 'h': diff --git a/fabtests/prov/efa/src/multi_ep_mt.c b/fabtests/prov/efa/src/multi_ep_mt.c index c560e596a07..769257c132c 100644 --- a/fabtests/prov/efa/src/multi_ep_mt.c +++ b/fabtests/prov/efa/src/multi_ep_mt.c @@ -245,14 +245,13 @@ static void *poll_tx_cq(void *context) { int i, ret; int num_cqes = 0; - struct timespec a, b; + union ft_timer timer; i = ((struct thread_context *) context)->idx; - clock_gettime(CLOCK_MONOTONIC, &a); + ft_timer_start(&timer); while (true) { - clock_gettime(CLOCK_MONOTONIC, &b); - if ((b.tv_sec - a.tv_sec) > timeout) { + if (ft_timer_is_elapsed(timer, timeout, SECOND)) { printf("%ds timeout expired, exiting \n", timeout); break; } @@ -287,12 +286,11 @@ static int run_server(void) } printf("Server: wait for completions\n"); - struct timespec a, b; + union ft_timer timer; - clock_gettime(CLOCK_MONOTONIC, &a); + ft_timer_start(&timer); while (true) { - clock_gettime(CLOCK_MONOTONIC, &b); - if ((b.tv_sec - a.tv_sec) > timeout) { + if (ft_timer_is_elapsed(timer, timeout, SECOND)) { printf("%ds timeout expired, exiting...\n", timeout); break; } diff --git a/fabtests/prov/efa/src/rdm_remote_exit_early.c b/fabtests/prov/efa/src/rdm_remote_exit_early.c index 7e96e262f30..f95cf3a23e8 100644 --- a/fabtests/prov/efa/src/rdm_remote_exit_early.c +++ b/fabtests/prov/efa/src/rdm_remote_exit_early.c @@ -48,6 +48,7 @@ static int run() { int ret; bool use_emulated_read; + union ft_timer timer; ret = ft_init_fabric(); if (ret) { @@ -70,10 +71,10 @@ static int run() * either ft_exchange_keys() or ft_sync() */ if (opts.rma_op == FT_RMA_WRITEDATA) { - /* ft_exchange_keys finally calls ft_sync(), - * which will call ft_sync_inband(true), so it will cause the - * receiver to always post an outstanding recv buffer. - * This is ok for RMA test because the rx buffer post + /* ft_exchange_keys finally calls ft_sync(), + * which will call ft_sync_inband(true), so it will cause the + * receiver to always post an outstanding recv buffer. + * This is ok for RMA test because the rx buffer post * shouldn't matter here, unless we will support FI_RX_CQ_DATA */ ret = ft_exchange_keys(&remote); @@ -124,7 +125,7 @@ static int run() printf("server posts recv\n"); } - ft_start(); + ft_timer_start(&timer); do { struct fi_cq_data_entry comp = {0}; @@ -137,8 +138,7 @@ static int run() goto out; } - ft_stop(); - if ((end.tv_sec - start.tv_sec) > timeout) { + if (ft_timer_is_elapsed(timer, timeout, SECOND)) { if (post_rx) { if (use_emulated_read || opts.transfer_size < 1048576) { /* @@ -242,11 +242,11 @@ int main(int argc, char **argv) if (optind < argc) opts.dst_addr = argv[optind]; - + hints->ep_attr->type = FI_EP_RDM; hints->caps |= FI_MSG | FI_RMA; hints->domain_attr->mr_mode = opts.mr_mode; - + ret = run(); if (ret) FT_PRINTERR("Test failed", -ret); diff --git a/fabtests/ubertest/cq.c b/fabtests/ubertest/cq.c index f5117f51f60..4b7cb2fd67c 100644 --- a/fabtests/ubertest/cq.c +++ b/fabtests/ubertest/cq.c @@ -291,26 +291,18 @@ static inline size_t ft_update_credits(void *buf, static size_t ft_comp_x(struct fid_cq *cq, struct ft_xcontrol *ft_x, const char *x_str, int timeout) { - uint8_t buf[FT_COMP_BUF_SIZE], start = 0; - struct timespec s, e; - int poll_time = 0; + uint8_t buf[FT_COMP_BUF_SIZE]; + union ft_timer timer; int ret, verify = (test_info.test_type == FT_TEST_UNIT && cq == rxcq); int completions = 0; switch(test_info.cq_wait_obj) { case FI_WAIT_NONE: + ft_timer_start(&timer); do { - if (!start) { - clock_gettime(CLOCK_MONOTONIC, &s); - start = 1; - } - ft_cq_read(fi_cq_read, cq, buf, ft_x->cq_format, ft_x->credits, completions, x_str, ret, verify); - - clock_gettime(CLOCK_MONOTONIC, &e); - poll_time = get_elapsed(&s, &e, MILLI); - } while (ret == -FI_EAGAIN && poll_time < timeout && + } while (ret == -FI_EAGAIN && !ft_timer_is_elapsed(timer, timeout, MILLI) && !completions); break; case FI_WAIT_UNSPEC: @@ -337,15 +329,13 @@ static int ft_cntr_x(struct fid_cntr *cntr, struct ft_xcontrol *ft_x, int timeout) { uint64_t cntr_val; - struct timespec s, e; - int poll_time = clock_gettime(CLOCK_MONOTONIC, &s); + union ft_timer timer; int recvd = 0; + ft_timer_start(&timer); do { cntr_val = fi_cntr_read(cntr); - clock_gettime(CLOCK_MONOTONIC, &e); - poll_time = get_elapsed(&s, &e, MILLI); - } while (cntr_val == ft_x->total_comp && poll_time < timeout); + } while (cntr_val == ft_x->total_comp && !ft_timer_is_elapsed(timer, timeout, MILLI)); recvd = cntr_val - ft_x->total_comp; ft_x->total_comp = cntr_val; diff --git a/fabtests/ubertest/test_ctrl.c b/fabtests/ubertest/test_ctrl.c index 30b43749499..f5c63507146 100644 --- a/fabtests/ubertest/test_ctrl.c +++ b/fabtests/ubertest/test_ctrl.c @@ -599,6 +599,7 @@ static int ft_pingpong_dgram(void) static int ft_run_latency(void) { int ret, i; + union ft_timer timer; for (i = 0; i < ft_ctrl.size_cnt; i += ft_ctrl.inc_step) { if (ft_ctrl.size_array[i] > fabric_info->ep_attr->max_msg_size) @@ -626,10 +627,10 @@ static int ft_run_latency(void) if (ret) return ret; - clock_gettime(CLOCK_MONOTONIC, &start); + ft_timer_start(&timer); ret = (test_info.ep_type == FI_EP_DGRAM) ? ft_pingpong_dgram() : ft_pingpong(); - clock_gettime(CLOCK_MONOTONIC, &end); + ft_timer_stop(&timer); if (ret) { FT_PRINTERR("latency test failed!", ret); return ret; @@ -639,7 +640,7 @@ static int ft_run_latency(void) if (ret) return ret; - show_perf("lat", ft_ctrl.size_array[i], ft_ctrl.xfer_iter, &start, &end, 2); + show_perf("lat", ft_ctrl.size_array[i], ft_ctrl.xfer_iter, timer, 2); } return 0; @@ -777,6 +778,7 @@ static int ft_run_bandwidth(void) { size_t recv_cnt; int ret, i; + union ft_timer timer; for (i = 0; i < ft_ctrl.size_cnt; i += ft_ctrl.inc_step) { if (ft_ctrl.size_array[i] > fabric_info->ep_attr->max_msg_size) @@ -805,10 +807,10 @@ static int ft_run_bandwidth(void) if (ret) return ret; - clock_gettime(CLOCK_MONOTONIC, &start); + ft_timer_start(&timer); ret = (test_info.ep_type == FI_EP_DGRAM) ? ft_bw_dgram(&recv_cnt) : ft_bw(); - clock_gettime(CLOCK_MONOTONIC, &end); + ft_timer_stop(&timer); if (ret) { FT_PRINTERR("bw test failed!", ret); return ret; @@ -818,7 +820,7 @@ static int ft_run_bandwidth(void) if (ret) return ret; - show_perf("bw", ft_ctrl.size_array[i], recv_cnt, &start, &end, 1); + show_perf("bw", ft_ctrl.size_array[i], recv_cnt, timer, 1); } return 0; diff --git a/fabtests/unit/cq_test.c b/fabtests/unit/cq_test.c index 32188e304d3..e60625cc7c5 100644 --- a/fabtests/unit/cq_test.c +++ b/fabtests/unit/cq_test.c @@ -160,7 +160,7 @@ cq_signal() { struct fid_cq *cq; struct fi_cq_tagged_entry entry; - int64_t elapsed; + union ft_timer timer; int testret; int ret; @@ -180,16 +180,15 @@ cq_signal() goto fail2; } - ft_start(); + ft_timer_start(&timer); ret = fi_cq_sread(cq, &entry, 1, NULL, 2000); - ft_stop(); - elapsed = get_elapsed(&start, &end, MILLI); + ft_timer_stop(&timer); if (ret != -FI_EAGAIN && ret != -FI_ECANCELED) { sprintf(err_buf, "fi_cq_sread = %d %s", ret, fi_strerror(-ret)); goto fail2; } - if (elapsed > 1000) { + if (ft_timer_get_elapsed(timer, MILLI) > 1000) { sprintf(err_buf, "fi_cq_sread - signal ignored"); goto fail2; } diff --git a/fabtests/unit/eq_test.c b/fabtests/unit/eq_test.c index d5cbbedc114..49accaf007f 100644 --- a/fabtests/unit/eq_test.c +++ b/fabtests/unit/eq_test.c @@ -338,13 +338,14 @@ static int read_events(size_t count, uint64_t flags) static int sread_event(int timeout, uint64_t flags) { struct fi_eq_entry entry; - int64_t elapsed; + union ft_timer timer; + uint64_t elapsed; uint32_t event; int ret; - ft_start(); + ft_timer_start(&timer); ret = fi_eq_sread(eq, &event, &entry, sizeof(entry), timeout, flags); - ft_stop(); + ft_timer_stop(&timer); if (ret != sizeof(entry)) { sprintf(err_buf, "fi_eq_sread returned %d, %s", ret, fi_strerror(-ret)); @@ -352,7 +353,7 @@ static int sread_event(int timeout, uint64_t flags) } /* check timeout accuracy */ - elapsed = get_elapsed(&start, &end, MILLI); + elapsed = ft_timer_get_elapsed(timer, MILLI); if (elapsed > (int) (timeout * 1.25)) { sprintf(err_buf, "fi_eq_sread slept %d ms, expected %d", (int) elapsed, timeout); @@ -452,8 +453,9 @@ static int eq_wait_fd_sread() { struct fi_eq_entry entry; + union ft_timer timer; uint32_t event; - int64_t elapsed; + uint64_t elapsed; int testret; int ret; @@ -466,16 +468,16 @@ eq_wait_fd_sread() } /* timed sread on empty EQ, 2s timeout */ - ft_start(); + ft_timer_start(&timer); ret = fi_eq_sread(eq, &event, &entry, sizeof(entry), 2000, 0); - ft_stop(); + ft_timer_stop(&timer); if (ret != -FI_EAGAIN) { sprintf(err_buf, "fi_eq_read of empty EQ returned %d", ret); goto fail; } /* check timeout accuracy */ - elapsed = get_elapsed(&start, &end, MILLI); + elapsed = ft_timer_get_elapsed(timer, MILLI); if (elapsed < 1500 || elapsed > 2500) { sprintf(err_buf, "fi_eq_sread slept %d ms, expected 2000", (int)elapsed); @@ -494,16 +496,16 @@ eq_wait_fd_sread() event = ~0; memset(&entry, 0, sizeof(entry)); /* timed sread on EQ with event, 2s timeout */ - ft_start(); + ft_timer_start(&timer); ret = fi_eq_sread(eq, &event, &entry, sizeof(entry), 2000, 0); - ft_stop(); + ft_timer_stop(&timer); if (ret != sizeof(entry)) { sprintf(err_buf, "fi_eq_read ret=%d, %s", ret, fi_strerror(-ret)); goto fail; } /* check that no undue waiting occurred */ - elapsed = get_elapsed(&start, &end, MILLI); + elapsed = ft_timer_get_elapsed(timer, MILLI); if (elapsed > 5) { sprintf(err_buf, "fi_eq_sread slept %d ms, expected immediate return", (int)elapsed); diff --git a/fabtests/unit/mr_cache_evict.c b/fabtests/unit/mr_cache_evict.c index c82583174a6..af848e08487 100644 --- a/fabtests/unit/mr_cache_evict.c +++ b/fabtests/unit/mr_cache_evict.c @@ -434,17 +434,18 @@ static int mr_register(const void *buf, struct fid_mr **mr, int64_t *elapsed, .requested_key = FT_MR_KEY, .iface = iface, }; + union ft_timer timer; - ft_start(); + ft_timer_start(&timer); ret = fi_mr_regattr(domain, &mr_attr, 0, mr); - ft_stop(); + ft_timer_stop(&timer); if (ret != FI_SUCCESS) { FT_UNIT_STRERR(err_buf, "fi_mr_reg failed", -errno); return -errno; } - *elapsed = get_elapsed(&start, &end, NANO); + *elapsed = ft_timer_get_elapsed(timer, NANO); return 0; }