diff options
author | Thomas White <taw@physics.org> | 2011-03-30 10:03:32 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2012-02-22 15:27:22 +0100 |
commit | 1c3c106f4690a45eedc5304e9c7eea6ce95747e3 (patch) | |
tree | 38d545ecfb2077d866cc67afae2403a15adc2705 | |
parent | cc16ae635d42789aaaf24444d0cd45cd824acebe (diff) |
indexamajig: Add fallback for clock_gettime()
-rw-r--r-- | config.h.in | 3 | ||||
-rwxr-xr-x | configure | 59 | ||||
-rw-r--r-- | configure.ac | 15 | ||||
-rw-r--r-- | src/indexamajig.c | 40 |
4 files changed, 106 insertions, 11 deletions
diff --git a/config.h.in b/config.h.in index 1dd5de50..ea2b3689 100644 --- a/config.h.in +++ b/config.h.in @@ -18,6 +18,9 @@ /* Define to 1 if Cairo is available */ #undef HAVE_CAIRO +/* Define to 1 if clock_gettime is available. */ +#undef HAVE_CLOCK_GETTIME + /* Define to 1 if CL/cl.h should be used */ #undef HAVE_CL_CL_H @@ -7481,6 +7481,60 @@ fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for clock_gettime in -lrt" >&5 +$as_echo_n "checking for clock_gettime in -lrt... " >&6; } +if test "${ac_cv_lib_rt_clock_gettime+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lrt $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char clock_gettime (); +int +main () +{ +return clock_gettime (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_rt_clock_gettime=yes +else + ac_cv_lib_rt_clock_gettime=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_rt_clock_gettime" >&5 +$as_echo "$ac_cv_lib_rt_clock_gettime" >&6; } +if test "x$ac_cv_lib_rt_clock_gettime" = x""yes; then : + + +$as_echo "#define HAVE_CLOCK_GETTIME 1" >>confdefs.h + + TIMER_LIBS="-lrt" + +else + + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Falling back on gettimeofday()." >&5 +$as_echo "$as_me: WARNING: Falling back on gettimeofday()." >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Time intervals may not be correct in certain circumstances." >&5 +$as_echo "$as_me: WARNING: Time intervals may not be correct in certain circumstances." >&2;} + +fi + + + if test x$have_opencl = xtrue; then HAVE_OPENCL_TRUE= HAVE_OPENCL_FALSE='#' @@ -7574,9 +7628,10 @@ $as_echo "$gl_cv_prog_c_ignore_unused_libraries" >&6; } CFLAGS="$CFLAGS $HDF5_CFLAGS $GSL_CFLAGS $OPENCL_CFLAGS -pthread $GTK_CFLAGS" CFLAGS="$CFLAGS $LIBTIFF_CFLAGS -D_GNU_SOURCE $libPNG_CFLAGS $Cairo_CFLAGS" CFLAGS="$CFLAGS $GDK_pixbuf_CFLAGS $GDK_pixbuf_2_CFLAGS" -LIBS="$LIBS $HDF5_LIBS -lm -lz $GSL_LIBS $GTK_LIBS $OPENCL_LIBS -pthread -lrt" + +LIBS="$LIBS $HDF5_LIBS -lm -lz $GSL_LIBS $GTK_LIBS $OPENCL_LIBS -pthread" LIBS="$LIBS $LIBTIFF_LIBS $libPNG_LIBS $Cairo_LIBS $GDK_pixbuf_LIBS" -LIBS="$LIBS $GDK_pixbuf_2_LIBS $LDFLAGS" +LIBS="$LIBS $GDK_pixbuf_2_LIBS $TIMER_LIBS $LDFLAGS" diff --git a/configure.ac b/configure.ac index 83078536..eaac7a4b 100644 --- a/configure.ac +++ b/configure.ac @@ -219,6 +219,16 @@ AC_CHECK_LIB([pthread], [sched_setaffinity], [ ]) +AC_CHECK_LIB([rt], [clock_gettime], [ + AC_DEFINE([HAVE_CLOCK_GETTIME], [1], + [Define to 1 if clock_gettime is available.]) + TIMER_LIBS="-lrt" +], [ + AC_MSG_WARN([Falling back on gettimeofday().]) + AC_MSG_WARN([Time intervals may not be correct in certain circumstances.]) +]) + + dnl Conditionals... AM_CONDITIONAL([HAVE_OPENCL], test x$have_opencl = xtrue) @@ -236,9 +246,10 @@ gl_IGNORE_UNUSED_LIBRARIES CFLAGS="$CFLAGS $HDF5_CFLAGS $GSL_CFLAGS $OPENCL_CFLAGS -pthread $GTK_CFLAGS" CFLAGS="$CFLAGS $LIBTIFF_CFLAGS -D_GNU_SOURCE $libPNG_CFLAGS $Cairo_CFLAGS" CFLAGS="$CFLAGS $GDK_pixbuf_CFLAGS $GDK_pixbuf_2_CFLAGS" -LIBS="$LIBS $HDF5_LIBS -lm -lz $GSL_LIBS $GTK_LIBS $OPENCL_LIBS -pthread -lrt" + +LIBS="$LIBS $HDF5_LIBS -lm -lz $GSL_LIBS $GTK_LIBS $OPENCL_LIBS -pthread" LIBS="$LIBS $LIBTIFF_LIBS $libPNG_LIBS $Cairo_LIBS $GDK_pixbuf_LIBS" -LIBS="$LIBS $GDK_pixbuf_2_LIBS $LDFLAGS" +LIBS="$LIBS $GDK_pixbuf_2_LIBS $TIMER_LIBS $LDFLAGS" GTK_DOC_CHECK([1.11],[--flavour no-tmpl]) diff --git a/src/indexamajig.c b/src/indexamajig.c index 953fd81d..093738da 100644 --- a/src/indexamajig.c +++ b/src/indexamajig.c @@ -23,7 +23,12 @@ #include <hdf5.h> #include <gsl/gsl_errno.h> #include <pthread.h> + +#ifdef HAVE_CLOCK_GETTIME #include <time.h> +#else +#include <sys/time.h> +#endif #include "utils.h" #include "hdf5-file.h" @@ -401,17 +406,40 @@ static void *get_image(void *qp) } +#ifdef HAVE_CLOCK_GETTIME + +static time_t get_monotonic_seconds() +{ + struct timespec tp; + clock_gettime(CLOCK_MONOTONIC, &tp); + return tp.tv_sec; +} + +#else + +/* Fallback version of the above. The time according to gettimeofday() is not + * monotonic, so measuring intervals based on it will screw up if there's a + * timezone change (e.g. daylight savings) while the program is running. */ +static time_t get_monotonic_seconds() +{ + struct timeval tp; + gettimeofday(&tp, NULL); + return tp.tv_sec; +} + +#endif + static void finalise_image(void *qp, void *pp) { struct queue_args *qargs = qp; struct index_args *pargs = pp; - struct timespec tp; + time_t monotonic_seconds; qargs->n_indexable += pargs->indexable; qargs->n_processed++; - clock_gettime(CLOCK_REALTIME, &tp); - if ( tp.tv_sec >= qargs->t_last_stats+STATS_EVERY_N_SECONDS ) { + monotonic_seconds = get_monotonic_seconds(); + if ( monotonic_seconds >= qargs->t_last_stats+STATS_EVERY_N_SECONDS ) { STATUS("%i out of %i indexed so far," " %i out of %i since the last message.\n", @@ -421,7 +449,7 @@ static void finalise_image(void *qp, void *pp) qargs->n_processed_last_stats = qargs->n_processed; qargs->n_indexable_last_stats = qargs->n_indexable; - qargs->t_last_stats = tp.tv_sec; + qargs->t_last_stats = monotonic_seconds; } @@ -475,7 +503,6 @@ int main(int argc, char *argv[]) char *element = NULL; double nominal_photon_energy; int stream_flags = STREAM_INTEGRATED; - struct timespec tp; int cpu_num = 0; int cpu_groupsize = 1; int cpu_offset = 0; @@ -847,8 +874,7 @@ int main(int argc, char *argv[]) qargs.n_processed = 0; qargs.n_indexable_last_stats = 0; qargs.n_processed_last_stats = 0; - clock_gettime(CLOCK_REALTIME, &tp); - qargs.t_last_stats = tp.tv_sec; + qargs.t_last_stats = get_monotonic_seconds(); n_images = run_threads(nthreads, process_image, get_image, finalise_image, &qargs, 0, |