iscsi-perf: Use gettimeofday if clock_gettime is unavailable
clock_gettime doesn't existing on OS X (http://stackoverflow.com/questions/5167269/clock-gettime-alternative-in-mac-os-x ) so add an autoconf test to check if the platform has it and fall back on gettimeofday if not. Signed-off-by: Sitsofe Wheeler <sitsofe@yahoo.com>
This commit is contained in:
@@ -128,6 +128,9 @@ AC_CHECK_MEMBER([struct CU_SuiteInfo.pSetUpFunc],
|
||||
#include <CUnit/TestDB.h>
|
||||
]])
|
||||
|
||||
AC_SEARCH_LIBS(clock_gettime, rt, [
|
||||
AC_DEFINE([HAVE_CLOCK_GETTIME],1,[Define if clock_gettime is available])])
|
||||
|
||||
|
||||
AC_CONFIG_FILES([Makefile]
|
||||
[lib/Makefile]
|
||||
|
||||
@@ -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 \
|
||||
|
||||
@@ -27,6 +27,10 @@
|
||||
#include "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
|
||||
#ifndef HAVE_CLOCK_GETTIME
|
||||
#include <sys/time.h>
|
||||
#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);
|
||||
|
||||
Reference in New Issue
Block a user