diff --git a/configure.ac b/configure.ac index 1d28579..ba9c8a4 100644 --- a/configure.ac +++ b/configure.ac @@ -128,6 +128,9 @@ AC_CHECK_MEMBER([struct CU_SuiteInfo.pSetUpFunc], #include ]]) +AC_SEARCH_LIBS(clock_gettime, rt, [ + AC_DEFINE([HAVE_CLOCK_GETTIME],1,[Define if clock_gettime is available])]) + AC_CONFIG_FILES([Makefile] [lib/Makefile] diff --git a/utils/Makefile.am b/utils/Makefile.am index 30e34ba..6624880 100644 --- a/utils/Makefile.am +++ b/utils/Makefile.am @@ -1,6 +1,6 @@ -AM_CPPFLAGS=-I../include "-D_U_=__attribute__((unused))" \ +AM_CPPFLAGS = -I../include "-D_U_=__attribute__((unused))" \ "-D_R_(A,B)=__attribute__((format(printf,A,B)))" -AM_CFLAGS=$(WARN_CFLAGS) -lrt +AM_CFLAGS = $(WARN_CFLAGS) LDADD = ../lib/libiscsi.la bin_PROGRAMS = iscsi-inq iscsi-ls iscsi-perf iscsi-readcapacity16 \ diff --git a/utils/iscsi-perf.c b/utils/iscsi-perf.c index daefc31..45c5b09 100644 --- a/utils/iscsi-perf.c +++ b/utils/iscsi-perf.c @@ -27,6 +27,10 @@ #include "iscsi.h" #include "scsi-lowlevel.h" +#ifndef HAVE_CLOCK_GETTIME +#include +#endif + #define VERSION "0.1" const char *initiator = "iqn.2010-11.libiscsi:iscsi-perf"; @@ -55,12 +59,23 @@ struct client { }; u_int64_t get_clock_ns(void) { - struct timespec tp; - if (clock_gettime (CLOCK_MONOTONIC, &tp) == -1) { - fprintf(stderr,"could not get clock monotonic\n"); + int res; + u_int64_t ns; + +#ifdef HAVE_CLOCK_GETTIME + struct timespec ts; + res = clock_gettime (CLOCK_MONOTONIC, &tp); + ns = ts.tv_sec * 1000000000 + ts.tv_nsec; +#else + struct timeval tv; + res = gettimeofday(&tv, NULL); + ns = tv.tv_sec * 1000000000 + tv.tv_usec * 1000; +#endif + if (res == -1) { + fprintf(stderr,"could not get requested clock\n"); exit(10); } - return tp.tv_sec*1000000000+tp.tv_nsec; + return ns; } void fill_read_queue(struct client *client);