Skip to content

Commit

Permalink
core: remove use of clock_gettime(3)
Browse files Browse the repository at this point in the history
The portability of clock_gettime(3) on Mac OS / OS X
is... complicated.  Per
Homebrew/homebrew-core#6551 and
ofiwg#2508, remove the use of
clock_gettime(3) from the core of libfabric.  clock_gettime(3) is
still used in some providers that do not compile on OS X / MacOS, but
that's ok).

Signed-off-by: Jeff Squyres <jsquyres@cisco.com>
  • Loading branch information
jsquyres committed Nov 19, 2016
1 parent 622903d commit c51efff
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 141 deletions.
4 changes: 0 additions & 4 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ common_srcs = \
prov/util/src/util_mr.c

if MACOS
if !HAVE_CLOCK_GETTIME
common_srcs += src/osx/osd.c
endif

common_srcs += src/unix/osd.c
common_srcs += include/osx/osd.h
common_srcs += include/unix/osd.h
Expand Down
13 changes: 0 additions & 13 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -125,24 +125,11 @@ fi
AC_DEFINE_UNQUOTED([PT_LOCK_SPIN], [$have_spinlock],
[Define to 1 if pthread_spin_init is available.])

have_clock_gettime=0

AC_CHECK_FUNCS([epoll_create])
if test "$ac_cv_func_epoll_create" = yes; then
AC_DEFINE([HAVE_EPOLL], [1], [Define if you have epoll support.])
fi

AC_SEARCH_LIBS([clock_gettime],[rt],
[have_clock_gettime=1],
[AC_CHECK_FUNCS([host_get_clock_service],
[],
[AC_MSG_ERROR([clock_gettime or host_get_clock_service
not found.])])])

AC_DEFINE_UNQUOTED(HAVE_CLOCK_GETTIME, [$have_clock_gettime],
[Define to 1 if clock_gettime is available.])
AM_CONDITIONAL(HAVE_CLOCK_GETTIME, [test $have_clock_gettime -eq 1])

dnl Check for gcc atomic intrinsics
AC_MSG_CHECKING(compiler support for c11 atomics)
AC_TRY_LINK([#include <stdatomic.h>],
Expand Down
3 changes: 2 additions & 1 deletion include/fi_lock.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2013-2014 Intel Corporation. All rights reserved.
* Copyright (c) 2016 Cisco Systems, Inc. All rights reserved.
*
* This software is available to you under a choice of one of two
* licenses. You may choose to be licensed under the terms of the GNU
Expand Down Expand Up @@ -47,7 +48,7 @@ extern "C" {
#endif


int fi_wait_cond(pthread_cond_t *cond, pthread_mutex_t *mut, int timeout);
int fi_wait_cond(pthread_cond_t *cond, pthread_mutex_t *mut, int timeout_ms);


#if PT_LOCK_SPIN == 1
Expand Down
13 changes: 0 additions & 13 deletions include/osx/osd.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,6 @@
extern "C" {
#endif

/* macOS Sierra added clock_gettime to libc. This implementation should only
* take effect if it is not available.
*/
#if !HAVE_CLOCK_GETTIME

#define CLOCK_REALTIME CALENDAR_CLOCK
#define CLOCK_MONOTONIC SYSTEM_CLOCK

typedef int clockid_t;
int clock_gettime(clockid_t clk_id, struct timespec *tp);

#endif

static inline int ofi_shm_remap(struct util_shm *shm, size_t newsize, void **mapped)
{
return -1;
Expand Down
56 changes: 0 additions & 56 deletions src/osx/osd.c

This file was deleted.

13 changes: 8 additions & 5 deletions src/unix/osd.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2013-2016 Intel Corporation. All rights reserved.
* Copyright (c) 2016 Cisco Systems, Inc. All rights reserved.
*
* This software is available to you under a choice of one of two
* licenses. You may choose to be licensed under the terms of the GNU
Expand Down Expand Up @@ -42,6 +43,7 @@
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/time.h>

#include "fi.h"
#include "fi_osd.h"
Expand All @@ -65,16 +67,17 @@ int fi_fd_nonblock(int fd)
return 0;
}

int fi_wait_cond(pthread_cond_t *cond, pthread_mutex_t *mut, int timeout)
int fi_wait_cond(pthread_cond_t *cond, pthread_mutex_t *mut, int timeout_ms)
{
uint64_t t;
struct timespec ts;

if (timeout < 0)
if (timeout_ms < 0)
return pthread_cond_wait(cond, mut);

clock_gettime(CLOCK_REALTIME, &ts);
ts.tv_sec += timeout / 1000;
ts.tv_nsec += (timeout % 1000) * 1000000;
t = fi_gettime_us();
ts.tv_sec = t / 1000000;
ts.tv_nsec = t % 1000000;
return pthread_cond_timedwait(cond, mut, &ts);
}

Expand Down
78 changes: 29 additions & 49 deletions util/pingpong.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ struct ct_pingpong {
void *buf, *tx_buf, *rx_buf;
size_t buf_size, tx_size, rx_size;

int timeout;
struct timespec start, end;
int timeout_sec;
uint64_t start, end;

struct fi_av_attr av_attr;
struct fi_eq_attr eq_attr;
Expand All @@ -203,26 +203,16 @@ static const int integ_alphabet_length =
(sizeof(integ_alphabet) / sizeof(*integ_alphabet)) - 1;

/*******************************************************************************
* Compatibility methods
* Utils
******************************************************************************/
#if defined(__APPLE__) && !HAVE_CLOCK_GETTIME
int clock_gettime(clockid_t clk_id, struct timespec *tp)
{
int retval;
struct timeval tv;

retval = gettimeofday(&tv, NULL);

tp->tv_sec = tv.tv_sec;
tp->tv_nsec = tv.tv_usec * 1000;
uint64_t pp_gettime_us(void)
{
struct timeval now;

return retval;
gettimeofday(&now, NULL);
return now.tv_sec * 1000000 + now.tv_usec;
}
#endif

/*******************************************************************************
* Utils
******************************************************************************/

long parse_ulong(char *str, long max)
{
Expand Down Expand Up @@ -804,12 +794,12 @@ static inline void pp_start(struct ct_pingpong *ct)
{
PP_DEBUG("Starting test chrono\n");
ct->opts.options |= PP_OPT_ACTIVE;
clock_gettime(CLOCK_MONOTONIC, &(ct->start));
ct->start = pp_gettime_us();
}

static inline void pp_stop(struct ct_pingpong *ct)
{
clock_gettime(CLOCK_MONOTONIC, &(ct->end));
ct->end = pp_gettime_us();
ct->opts.options &= ~PP_OPT_ACTIVE;
PP_DEBUG("Stopped test chrono\n");
}
Expand Down Expand Up @@ -1015,22 +1005,12 @@ char *cnt_str(char *str, size_t size, uint64_t cnt)
return str;
}

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, int tsize, int sent, int acked,
struct timespec *start, struct timespec *end, int xfers_per_iter)
uint64_t start, uint64_t end, int xfers_per_iter)
{
static int header = 1;
char str[PP_STR_LEN];
int64_t elapsed = get_elapsed(start, end, MICRO);
int64_t elapsed = end - start;
uint64_t bytes = (uint64_t)sent * tsize * xfers_per_iter;
float usec_per_xfer;

Expand Down Expand Up @@ -1094,20 +1074,20 @@ int pp_cq_readerr(struct fid_cq *cq)
}

static int pp_get_cq_comp(struct fid_cq *cq, uint64_t *cur, uint64_t total,
int timeout)
int timeout_sec)
{
struct fi_cq_err_entry comp;
struct timespec a = {0}, b = {0};
uint64_t a = 0, b = 0;
int ret = 0;

if (timeout >= 0)
clock_gettime(CLOCK_MONOTONIC, &a);
if (timeout_sec >= 0)
a = pp_gettime_us();

while (total - *cur > 0) {
ret = fi_cq_read(cq, &comp, 1);
if (ret > 0) {
if (timeout >= 0)
clock_gettime(CLOCK_MONOTONIC, &a);
if (timeout_sec >= 0)
a = pp_gettime_us();

(*cur)++;
} else if (ret < 0 && ret != -FI_EAGAIN) {
Expand All @@ -1119,11 +1099,11 @@ static int pp_get_cq_comp(struct fid_cq *cq, uint64_t *cur, uint64_t total,
}

return ret;
} else if (timeout >= 0) {
clock_gettime(CLOCK_MONOTONIC, &b);
if ((b.tv_sec - a.tv_sec) > timeout) {
} else if (timeout_sec >= 0) {
b = pp_gettime_us();
if ((b - a) / 1000000 > timeout_sec) {
fprintf(stderr, "%ds timeout expired\n",
timeout);
timeout_sec);
return -FI_ENODATA;
}
}
Expand All @@ -1138,7 +1118,7 @@ int pp_get_rx_comp(struct ct_pingpong *ct, uint64_t total)

if (ct->rxcq) {
ret = pp_get_cq_comp(ct->rxcq, &(ct->rx_cq_cntr), total,
ct->timeout);
ct->timeout_sec);
} else {
PP_ERR(
"Trying to get a RX completion when no RX CQ was opened");
Expand All @@ -1163,7 +1143,7 @@ int pp_get_tx_comp(struct ct_pingpong *ct, uint64_t total)

#define PP_POST(post_fn, comp_fn, seq, op_str, ...) \
do { \
int timeout_save; \
int timeout_sec_save; \
int ret, rc; \
\
while (1) { \
Expand All @@ -1176,10 +1156,10 @@ int pp_get_tx_comp(struct ct_pingpong *ct, uint64_t total)
return ret; \
} \
\
timeout_save = ct->timeout; \
ct->timeout = 0; \
timeout_sec_save = ct->timeout_sec; \
ct->timeout_sec = 0; \
rc = comp_fn(ct, seq); \
ct->timeout = timeout_save; \
ct->timeout_sec = timeout_sec_save; \
if (rc && rc != -FI_EAGAIN) { \
PP_ERR("Failed to get " op_str " completion"); \
return rc; \
Expand Down Expand Up @@ -2035,7 +2015,7 @@ int pingpong(struct ct_pingpong *ct)

PP_DEBUG("Results:\n");
show_perf(NULL, ct->opts.transfer_size, ct->opts.iterations,
ct->cnt_ack_msg, &(ct->start), &(ct->end), 2);
ct->cnt_ack_msg, ct->start, ct->end, 2);

return 0;
}
Expand Down Expand Up @@ -2149,7 +2129,7 @@ int main(int argc, char **argv)
ret = EXIT_SUCCESS;

struct ct_pingpong ct = {
.timeout = -1,
.timeout_sec = -1,
.ctrl_connfd = -1,
.opts = {
.iterations = 1000,
Expand Down

0 comments on commit c51efff

Please sign in to comment.