Merge branch 'master' into gfio
authorJens Axboe <axboe@kernel.dk>
Wed, 9 Jan 2013 13:10:36 +0000 (14:10 +0100)
committerJens Axboe <axboe@kernel.dk>
Wed, 9 Jan 2013 13:10:36 +0000 (14:10 +0100)
Conflicts:
client.c
server.h

Signed-off-by: Jens Axboe <axboe@kernel.dk>
29 files changed:
FIO-VERSION-GEN
HOWTO
Makefile
README
arch/arch-ia64.h
arch/arch-ppc.h
arch/arch-s390.h
arch/arch-x86-common.h
arch/arch.h
backend.c
crc/crc32c-intel.c
engines/binject.c
engines/libaio.c
engines/windowsaio.c
file.h
filesetup.c
fio.1
gettime.c
gettime.h
init.c
os/windows/install.wxs
os/windows/posix/include/dlfcn.h
os/windows/posix/include/sys/uio.h
os/windows/posix/include/sys/un.h
server.h
stat.h
t/axmap.c
time.c
time.h

index 035ddaf18711cee99a25be1db9cf109b210c0dd3..85e4cda0d0bcb3c024c1dcc8224bcad7cb4c08d4 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 
 GVF=FIO-VERSION-FILE
-DEF_VER=fio-2.0.11
+DEF_VER=fio-2.0.13
 
 LF='
 '
diff --git a/HOWTO b/HOWTO
index 529c96784117b0955b93fe3f3ad31c3faa58e1e2..a1e659008b38b82e98ba86d0d5d07b4b35b35897 100644 (file)
--- a/HOWTO
+++ b/HOWTO
@@ -1256,6 +1256,22 @@ percentile_list=float_list Overwrite the default list of percentiles
                the values of completion latency below which 99.5% and
                99.9% of the observed latencies fell, respectively.
 
+clocksource=str        Use the given clocksource as the base of timing. The
+               supported options are:
+
+                       gettimeofday    gettimeofday(2)
+
+                       clock_gettime   clock_gettime(2)
+
+                       cpu             Internal CPU clock source
+
+               cpu is the preferred clocksource if it is reliable, as it
+               is very fast (and fio is heavy on time calls). Fio will
+               automatically use this clocksource if it's supported and
+               considered reliable on the system it is running on, unless
+               another clocksource is specifically set. For x86/x86-64 CPUs,
+               this means supporting TSC Invariant.
+
 gtod_reduce=bool Enable all of the gettimeofday() reducing options
                (disable_clat, disable_slat, disable_bw) plus reduce
                precision of the timeout somewhat to really shrink
index bc0a2f8a9f2975ba38e73589b93a97f7461e5ccc..e6e9e8c96cc8108c71b9a137aa6283c5730f7e4a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,10 +1,8 @@
-ifneq ($(origin CC), environment)
-CC     = $(CROSS_COMPILE)gcc
-endif
+CC ?= gcc
 DEBUGFLAGS = -D_FORTIFY_SOURCE=2 -DFIO_INC_DEBUG
 CPPFLAGS= -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 \
        $(DEBUGFLAGS)
-OPTFLAGS= -O3 -g $(EXTFLAGS)
+OPTFLAGS= -O3 -g -ffast-math $(EXTFLAGS)
 CFLAGS = -std=gnu99 -Wwrite-strings -Wall $(OPTFLAGS)
 LIBS   = -lm -lz $(EXTLIBS)
 PROGS  = fio
@@ -41,6 +39,7 @@ ifeq ($(UNAME), Android)
   CPPFLAGS += -DFIO_NO_HAVE_SHM_H
 endif
 ifeq ($(UNAME), SunOS)
+  CC      = gcc
   SOURCE += fifo.c lib/strsep.c helpers.c engines/posixaio.c \
                engines/solarisaio.c
   LIBS  += -lpthread -ldl -laio -lrt -lnsl -lsocket
@@ -63,6 +62,7 @@ ifeq ($(UNAME), AIX)
   LDFLAGS += -L/opt/freeware/lib -Wl,-blibpath:/opt/freeware/lib:/usr/lib:/lib -Wl,-bmaxdata:0x80000000
 endif
 ifeq ($(UNAME), HP-UX)
+  CC      = gcc
   SOURCE += fifo.c helpers.c lib/getopt_long.c lib/strsep.c engines/posixaio.c
   LIBS   += -lpthread -ldl -lrt
   CFLAGS += -D_LARGEFILE64_SOURCE
diff --git a/README b/README
index ceac3857a191d42579abe7b338ec65c8c5ca7276..7c4552d98bad1692abaea0d2ab8a726d369cbbb5 100644 (file)
--- a/README
+++ b/README
@@ -129,6 +129,7 @@ $ fio
        --terse-version=type    Terse version output format (default 3, or 2 or 4).
        --version               Print version info and exit
        --help                  Print this page
+       --cpuclock-test         Perform test/validation of CPU clock
        --cmdhelp=cmd           Print command help, "all" for all of them
        --enghelp=engine        Print ioengine help, or list available ioengines
        --enghelp=engine,cmd    Print help for an ioengine cmd
index 8ccbd865e01513eeaf7ace812a58d5ca8ea7245c..2df55ba4846c838872f1a277da7404abec86b9df 100644 (file)
@@ -47,6 +47,7 @@ extern int tsc_reliable;
 static inline int arch_init(char *envp[])
 {
        tsc_reliable = 1;
+       return 0;
 }
 
 #define ARCH_HAVE_FFZ
index 0f2037550da32f85041ed2a720878fdbcd1fa383..e73093df86f5f25ed68c44e4e3662d1ab3210891 100644 (file)
@@ -63,6 +63,7 @@ extern int tsc_reliable;
 static inline int arch_init(char *envp[])
 {
        tsc_reliable = 1;
+       return 0;
 }
 
 #define ARCH_HAVE_FFZ
index fe5179134891d66d944797ee8132f2a306e4513c..bcd91636d04d8e6e3bd2137672377f84813cd57e 100644 (file)
 #define read_barrier() asm volatile("bcr 15,0" : : : "memory")
 #define write_barrier()        asm volatile("bcr 15,0" : : : "memory")
 
+static inline unsigned long long get_cpu_clock(void)
+{
+       unsigned long long clk;
+
+       __asm__ __volatile__("stck %0" : "=Q" (clk) : : "cc");
+       return clk;
+}
+
+#define ARCH_HAVE_INIT
+extern int tsc_reliable;
+static inline int arch_init(char *envp[])
+{
+       tsc_reliable = 1;
+       return 0;
+}
+
+#define ARCH_HAVE_CPU_CLOCK
+
 #endif
index 1e62354418c01d41e5bc2bf975617fbad314d315..d533d22d536bce1ffbc162a1cdb50af1ae4f3848 100644 (file)
@@ -4,24 +4,17 @@
 static inline void do_cpuid(unsigned int *eax, unsigned int *ebx,
                            unsigned int *ecx, unsigned int *edx)
 {
-       unsigned int id = *eax;
-
-       asm("movl %4, %%eax;"
-           "cpuid;"
-           "movl %%eax, %0;"
-           "movl %%ebx, %1;"
-           "movl %%ecx, %2;"
-           "movl %%edx, %3;"
-               : "=r" (*eax), "=r" (*ebx), "=r" (*ecx), "=r" (*edx)
-               : "r" (id)
-               : "eax", "ebx", "ecx", "edx");
+       asm volatile("cpuid"
+               : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
+               : "0" (*eax), "2" (*ecx)
+               : "memory");
 }
 
 #define ARCH_HAVE_INIT
 extern int tsc_reliable;
 static inline int arch_init(char *envp[])
 {
-       unsigned int eax, ebx, ecx, edx;
+       unsigned int eax, ebx, ecx = 0, edx;
 
        /*
         * Check for TSC
index 3ee5ac43e563eb0b5e3c72576e18d8729139ce3c..f6a8e998672c4e4425103e576238946be9cabb61 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef ARCH_H
 #define ARCH_H
 
+#include <stdint.h>
+
 #ifdef __WORDSIZE
 #define BITS_PER_LONG  __WORDSIZE
 #else
index 8bcb7a2c50b4e9e5f84915f827535bf8b0c62d54..8f16a165c77edfc76de4bf3056402c0167c4f3fa 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -422,6 +422,7 @@ static void do_verify(struct thread_data *td)
 
        io_u = NULL;
        while (!td->terminate) {
+               enum fio_ddir ddir;
                int ret2, full;
 
                update_tv_cache(td);
@@ -456,6 +457,8 @@ static void do_verify(struct thread_data *td)
                else
                        io_u->end_io = verify_io_u;
 
+               ddir = io_u->ddir;
+
                ret = td_io_queue(td, io_u);
                switch (ret) {
                case FIO_Q_COMPLETED:
@@ -507,7 +510,7 @@ sync_done:
                        break;
                }
 
-               if (break_on_this_error(td, io_u->ddir, &ret))
+               if (break_on_this_error(td, ddir, &ret))
                        break;
 
                /*
@@ -1013,6 +1016,8 @@ static void *thread_main(void *data)
        } else
                td->pid = gettid();
 
+       fio_local_clock_init(td->o.use_thread);
+
        dprint(FD_PROCESS, "jobs pid=%d started\n", (int) td->pid);
 
        if (is_backend)
index 8e1cd587dcec85adc2a75ec4bd824e75457514b5..0b0f193c0564a75de8d5d00e80695af40e49dd6a 100644 (file)
@@ -81,7 +81,7 @@ uint32_t crc32c_intel(unsigned char const *data, unsigned long length)
 void crc32c_intel_probe(void)
 {
        if (!crc32c_probed) {
-               unsigned int eax, ebx, ecx, edx;
+               unsigned int eax, ebx, ecx = 0, edx;
 
                eax = 1;
 
index f78d8559a84572f7866073204002d3fb62139051..7b8522a466b421071ffb9842de9635138ba3c577 100644 (file)
@@ -69,7 +69,7 @@ static unsigned int binject_read_commands(struct thread_data *td, void *p,
 one_more:
        events = 0;
        for_each_file(td, f, i) {
-               bf = (void *) f->engine_data;
+               bf = (struct binject_file *) f->engine_data;
                ret = read(bf->fd, p, left * sizeof(struct b_user_cmd));
                if (ret < 0) {
                        if (errno == EAGAIN)
@@ -104,7 +104,7 @@ static int fio_binject_getevents(struct thread_data *td, unsigned int min,
         * Fill in the file descriptors
         */
        for_each_file(td, f, i) {
-               bf = (void *) f->engine_data;
+               bf = (struct binject_file *) f->engine_data;
 
                /*
                 * don't block for min events == 0
@@ -153,7 +153,7 @@ static int fio_binject_getevents(struct thread_data *td, unsigned int min,
 
        if (!min) {
                for_each_file(td, f, i) {
-                       bf = (void *) f->engine_data;
+                       bf = (struct binject_file *) f->engine_data;
                        fcntl(bf->fd, F_SETFL, bd->fd_flags[i]);
                }
        }
@@ -167,7 +167,7 @@ static int fio_binject_getevents(struct thread_data *td, unsigned int min,
 static int fio_binject_doio(struct thread_data *td, struct io_u *io_u)
 {
        struct b_user_cmd *buc = &io_u->buc;
-       struct binject_file *bf = (void *) io_u->file->engine_data;
+       struct binject_file *bf = (struct binject_file *) io_u->file->engine_data;
        int ret;
 
        ret = write(bf->fd, buc, sizeof(*buc));
@@ -181,7 +181,7 @@ static int fio_binject_prep(struct thread_data *td, struct io_u *io_u)
 {
        struct binject_data *bd = td->io_ops->data;
        struct b_user_cmd *buc = &io_u->buc;
-       struct binject_file *bf = (void *) io_u->file->engine_data;
+       struct binject_file *bf = (struct binject_file *) io_u->file->engine_data;
 
        if (io_u->xfer_buflen & (bf->bs - 1)) {
                log_err("read/write not sector aligned\n");
@@ -323,7 +323,7 @@ err_unmap:
 
 static int fio_binject_close_file(struct thread_data *td, struct fio_file *f)
 {
-       struct binject_file *bf = (void *) f->engine_data;
+       struct binject_file *bf = (struct binject_file *) f->engine_data;
 
        if (bf) {
                binject_unmap_dev(td, bf);
@@ -357,7 +357,7 @@ static int fio_binject_open_file(struct thread_data *td, struct fio_file *f)
        bf = malloc(sizeof(*bf));
        bf->bs = bs;
        bf->minor = bf->fd = -1;
-       f->engine_data = (uint64_t) bf;
+       f->engine_data = (uintptr_t) bf;
 
        if (binject_map_dev(td, bf, f->fd)) {
 err_close:
index 748233c268e1dad4a106c00c4c1497ad62010c0f..e9ce0ce7d4ac81c174d4932510b82c6fd732527d 100644 (file)
@@ -14,8 +14,6 @@
 
 #ifdef FIO_HAVE_LIBAIO
 
-#define ev_to_iou(ev)  (struct io_u *) ((unsigned long) (ev)->obj)
-
 struct libaio_data {
        io_context_t aio_ctx;
        struct io_event *aio_events;
@@ -64,7 +62,7 @@ static struct io_u *fio_libaio_event(struct thread_data *td, int event)
        struct io_u *io_u;
 
        ev = ld->aio_events + event;
-       io_u = ev_to_iou(ev);
+       io_u = container_of(ev->obj, struct io_u, iocb);
 
        if (ev->res != io_u->xfer_buflen) {
                if (ev->res > io_u->xfer_buflen)
index edc390cfddb327d47bcb340ea86b732831876f66..f1b0bc51f4e8487c91439d8b14a93b7b6bf977fb 100644 (file)
@@ -504,7 +504,7 @@ static int fio_windowsaio_io_u_init(struct thread_data *td, struct io_u *io_u)
        struct fio_overlapped *o;
 
        o = malloc(sizeof(*o));
-       o->io_complete = FALSE:
+       o->io_complete = FALSE;
        o->io_u = io_u;
        o->o.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
        if (!o->o.hEvent) {
diff --git a/file.h b/file.h
index e57bebcffff605c4c5996b88287cb40ff9c9254d..5f125c3b5924e8f95b55be9cde1a00c7786fb13c 100644 (file)
--- a/file.h
+++ b/file.h
@@ -84,20 +84,20 @@ struct fio_file {
        /*
         * size of the file, offset into file, and io size from that offset
         */
-       unsigned long long real_file_size;
-       unsigned long long file_offset;
-       unsigned long long io_size;
+       uint64_t real_file_size;
+       uint64_t file_offset;
+       uint64_t io_size;
 
-       unsigned long long last_pos;
-       unsigned long long last_start;
+       uint64_t last_pos;
+       uint64_t last_start;
 
-       unsigned long long first_write;
-       unsigned long long last_write;
+       uint64_t first_write;
+       uint64_t last_write;
 
        /*
         * For use by the io engine
         */
-       uint64_t engine_data;
+       uintptr_t engine_data;
 
        /*
         * if io is protected by a semaphore, this is set
@@ -154,7 +154,7 @@ FILE_FLAG_FNS(partial_mmap);
 struct thread_data;
 extern void close_files(struct thread_data *);
 extern void close_and_free_files(struct thread_data *);
-extern unsigned long long get_start_offset(struct thread_data *);
+extern uint64_t get_start_offset(struct thread_data *);
 extern int __must_check setup_files(struct thread_data *);
 extern int __must_check file_invalidate_cache(struct thread_data *, struct fio_file *);
 extern int __must_check generic_open_file(struct thread_data *, struct fio_file *);
index 60894c4e10ee99184519f784cc5a866a667d2452..0c104ed748186d5343a210e7a5d9786702943876 100644 (file)
@@ -709,7 +709,7 @@ static unsigned long long get_fs_free_counts(struct thread_data *td)
        return ret;
 }
 
-unsigned long long get_start_offset(struct thread_data *td)
+uint64_t get_start_offset(struct thread_data *td)
 {
        return td->o.start_offset +
                (td->thread_number - 1) * td->o.offset_increment;
@@ -907,10 +907,12 @@ static int __init_rand_distribution(struct thread_data *td, struct fio_file *f)
 {
        unsigned int range_size, seed;
        unsigned long nranges;
+       uint64_t file_size;
 
        range_size = min(td->o.min_bs[DDIR_READ], td->o.min_bs[DDIR_WRITE]);
+       file_size = min(f->real_file_size, f->io_size);
 
-       nranges = (f->real_file_size + range_size - 1) / range_size;
+       nranges = (file_size + range_size - 1) / range_size;
 
        seed = jhash(f->file_name, strlen(f->file_name), 0) * td->thread_number;
        if (!td->o.rand_repeatable)
diff --git a/fio.1 b/fio.1
index 62c42c61c911f4549a6f2e57520e140d4fd865b7..7a06fbc4fc7b61435f09d2863c5917ac7151d089 100644 (file)
--- a/fio.1
+++ b/fio.1
@@ -1027,6 +1027,27 @@ given time in milliseconds.
 .BI disk_util \fR=\fPbool
 Generate disk utilization statistics if the platform supports it. Default: true.
 .TP
+.BI clocksource \fR=\fPstr
+Use the given clocksource as the base of timing. The supported options are:
+.RS
+.TP
+.B gettimeofday
+gettimeofday(2)
+.TP
+.B clock_gettime
+clock_gettime(2)
+.TP
+.B cpu
+Internal CPU clock source
+.TP
+.RE
+.P
+\fBcpu\fR is the preferred clocksource if it is reliable, as it is very fast
+(and fio is heavy on time calls). Fio will automatically use this clocksource
+if it's supported and considered reliable on the system it is running on,
+unless another clocksource is specifically set. For x86/x86-64 CPUs, this
+means supporting TSC Invariant.
+.TP
 .BI gtod_reduce \fR=\fPbool
 Enable all of the gettimeofday() reducing options (disable_clat, disable_slat,
 disable_bw) plus reduce precision of the timeout somewhat to really shrink the
index 9f23e3fff526e0611df0dd1c9d6dc1b62d059916..1648b17b677f3325664282eb66052f40a2b646fd 100644 (file)
--- a/gettime.c
+++ b/gettime.c
 #include "smalloc.h"
 
 #include "hash.h"
+#include "os/os.h"
 
 #ifdef ARCH_HAVE_CPU_CLOCK
 static unsigned long cycles_per_usec;
-static unsigned long last_cycles;
-int tsc_reliable = 0;
+static unsigned long inv_cycles_per_usec;
 #endif
-static struct timeval last_tv;
-static int last_tv_valid;
+int tsc_reliable = 0;
+
+struct tv_valid {
+       struct timeval last_tv;
+       int last_tv_valid;
+       unsigned long last_cycles;
+};
+static pthread_key_t tv_tls_key;
 
 enum fio_cs fio_clock_source = FIO_PREFERRED_CLOCK_SOURCE;
 int fio_clock_source_set = 0;
@@ -115,12 +121,23 @@ static void fio_init gtod_init(void)
 
 #endif /* FIO_DEBUG_TIME */
 
+static int fill_clock_gettime(struct timespec *ts)
+{
+#ifdef FIO_HAVE_CLOCK_MONOTONIC
+       return clock_gettime(CLOCK_MONOTONIC, ts);
+#else
+       return clock_gettime(CLOCK_REALTIME, ts);
+#endif
+}
+
 #ifdef FIO_DEBUG_TIME
 void fio_gettime(struct timeval *tp, void *caller)
 #else
 void fio_gettime(struct timeval *tp, void fio_unused *caller)
 #endif
 {
+       struct tv_valid *tv;
+
 #ifdef FIO_DEBUG_TIME
        if (!caller)
                caller = __builtin_return_address(0);
@@ -132,6 +149,8 @@ void fio_gettime(struct timeval *tp, void fio_unused *caller)
                return;
        }
 
+       tv = pthread_getspecific(tv_tls_key);
+
        switch (fio_clock_source) {
        case CS_GTOD:
                gettimeofday(tp, NULL);
@@ -139,11 +158,7 @@ void fio_gettime(struct timeval *tp, void fio_unused *caller)
        case CS_CGETTIME: {
                struct timespec ts;
 
-#ifdef FIO_HAVE_CLOCK_MONOTONIC
-               if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) {
-#else
-               if (clock_gettime(CLOCK_REALTIME, &ts) < 0) {
-#endif
+               if (fill_clock_gettime(&ts) < 0) {
                        log_err("fio: clock_gettime fails\n");
                        assert(0);
                }
@@ -157,15 +172,15 @@ void fio_gettime(struct timeval *tp, void fio_unused *caller)
                unsigned long long usecs, t;
 
                t = get_cpu_clock();
-               if (t < last_cycles) {
+               if (tv && t < tv->last_cycles) {
                        dprint(FD_TIME, "CPU clock going back in time\n");
-                       t = last_cycles;
-               }
+                       t = tv->last_cycles;
+               } else if (tv)
+                       tv->last_cycles = t;
 
-               usecs = t / cycles_per_usec;
+               usecs = (t * inv_cycles_per_usec) / 16777216UL;
                tp->tv_sec = usecs / 1000000;
                tp->tv_usec = usecs % 1000000;
-               last_cycles = t;
                break;
                }
 #endif
@@ -178,29 +193,38 @@ void fio_gettime(struct timeval *tp, void fio_unused *caller)
         * If Linux is using the tsc clock on non-synced processors,
         * sometimes time can appear to drift backwards. Fix that up.
         */
-       if (last_tv_valid) {
-               if (tp->tv_sec < last_tv.tv_sec)
-                       tp->tv_sec = last_tv.tv_sec;
-               else if (last_tv.tv_sec == tp->tv_sec &&
-                        tp->tv_usec < last_tv.tv_usec)
-                       tp->tv_usec = last_tv.tv_usec;
+       if (tv) {
+               if (tv->last_tv_valid) {
+                       if (tp->tv_sec < tv->last_tv.tv_sec)
+                               tp->tv_sec = tv->last_tv.tv_sec;
+                       else if (tv->last_tv.tv_sec == tp->tv_sec &&
+                                tp->tv_usec < tv->last_tv.tv_usec)
+                               tp->tv_usec = tv->last_tv.tv_usec;
+               }
+               tv->last_tv_valid = 1;
+               memcpy(&tv->last_tv, tp, sizeof(*tp));
        }
-       last_tv_valid = 1;
-       memcpy(&last_tv, tp, sizeof(*tp));
 }
 
 #ifdef ARCH_HAVE_CPU_CLOCK
 static unsigned long get_cycles_per_usec(void)
 {
+       struct timespec ts;
        struct timeval s, e;
        unsigned long long c_s, c_e;
 
-       gettimeofday(&s, NULL);
+       fill_clock_gettime(&ts);
+       s.tv_sec = ts.tv_sec;
+       s.tv_usec = ts.tv_nsec / 1000;
+
        c_s = get_cpu_clock();
        do {
                unsigned long long elapsed;
 
-               gettimeofday(&e, NULL);
+               fill_clock_gettime(&ts);
+               e.tv_sec = ts.tv_sec;
+               e.tv_usec = ts.tv_nsec / 1000;
+
                elapsed = utime_since(&s, &e);
                if (elapsed >= 1280) {
                        c_e = get_cpu_clock();
@@ -249,11 +273,13 @@ static void calibrate_cpu_clock(void)
                dprint(FD_TIME, "cycles[%d]=%lu\n", i, cycles[i] / 10);
 
        avg /= samples;
-       avg = (avg + 9) / 10;
+       avg = (avg + 5) / 10;
        dprint(FD_TIME, "avg: %lu\n", avg);
        dprint(FD_TIME, "mean=%f, S=%f\n", mean, S);
 
        cycles_per_usec = avg;
+       inv_cycles_per_usec = 16777216UL / cycles_per_usec;
+       dprint(FD_TIME, "inv_cycles_per_usec=%lu\n", inv_cycles_per_usec);
 }
 #else
 static void calibrate_cpu_clock(void)
@@ -261,12 +287,28 @@ static void calibrate_cpu_clock(void)
 }
 #endif
 
+void fio_local_clock_init(int is_thread)
+{
+       struct tv_valid *t;
+
+       t = calloc(sizeof(*t), 1);
+       if (pthread_setspecific(tv_tls_key, t))
+               log_err("fio: can't set TLS key\n");
+}
+
+static void kill_tv_tls_key(void *data)
+{
+       free(data);
+}
+
 void fio_clock_init(void)
 {
        if (fio_clock_source == fio_clock_source_inited)
                return;
 
-       last_tv_valid = 0;
+       if (pthread_key_create(&tv_tls_key, kill_tv_tls_key))
+               log_err("fio: can't create TLS key\n");
+
        fio_clock_source_inited = fio_clock_source;
        calibrate_cpu_clock();
 
@@ -282,10 +324,10 @@ void fio_clock_init(void)
                log_info("fio: clocksource=cpu may not be reliable\n");
 }
 
-unsigned long long utime_since(struct timeval *s, struct timeval *e)
+uint64_t utime_since(struct timeval *s, struct timeval *e)
 {
        long sec, usec;
-       unsigned long long ret;
+       uint64_t ret;
 
        sec = e->tv_sec - s->tv_sec;
        usec = e->tv_usec - s->tv_usec;
@@ -305,7 +347,7 @@ unsigned long long utime_since(struct timeval *s, struct timeval *e)
        return ret;
 }
 
-unsigned long long utime_since_now(struct timeval *s)
+uint64_t utime_since_now(struct timeval *s)
 {
        struct timeval t;
 
@@ -313,7 +355,7 @@ unsigned long long utime_since_now(struct timeval *s)
        return utime_since(s, &t);
 }
 
-unsigned long mtime_since(struct timeval *s, struct timeval *e)
+uint64_t mtime_since(struct timeval *s, struct timeval *e)
 {
        long sec, usec, ret;
 
@@ -334,7 +376,7 @@ unsigned long mtime_since(struct timeval *s, struct timeval *e)
        return ret;
 }
 
-unsigned long mtime_since_now(struct timeval *s)
+uint64_t mtime_since_now(struct timeval *s)
 {
        struct timeval t;
        void *p = __builtin_return_address(0);
@@ -343,7 +385,178 @@ unsigned long mtime_since_now(struct timeval *s)
        return mtime_since(s, &t);
 }
 
-unsigned long time_since_now(struct timeval *s)
+uint64_t time_since_now(struct timeval *s)
 {
        return mtime_since_now(s) / 1000;
 }
+
+#if defined(FIO_HAVE_CPU_AFFINITY) && defined(ARCH_HAVE_CPU_CLOCK)
+
+#define CLOCK_ENTRIES  100000
+
+struct clock_entry {
+       unsigned long seq;
+       unsigned long tsc;
+       unsigned long cpu;
+};
+
+struct clock_thread {
+       pthread_t thread;
+       int cpu;
+       pthread_mutex_t lock;
+       pthread_mutex_t started;
+       uint64_t *seq;
+       struct clock_entry *entries;
+};
+
+static inline uint64_t atomic64_inc_return(uint64_t *seq)
+{
+       return 1 + __sync_fetch_and_add(seq, 1);
+}
+
+static void *clock_thread_fn(void *data)
+{
+       struct clock_thread *t = data;
+       struct clock_entry *c;
+       os_cpu_mask_t cpu_mask;
+       int i;
+
+       memset(&cpu_mask, 0, sizeof(cpu_mask));
+       fio_cpu_set(&cpu_mask, t->cpu);
+
+       if (fio_setaffinity(gettid(), cpu_mask) == -1) {
+               log_err("clock setaffinity failed\n");
+               return (void *) 1;
+       }
+
+       pthread_mutex_lock(&t->lock);
+       pthread_mutex_unlock(&t->started);
+
+       c = &t->entries[0];
+       for (i = 0; i < CLOCK_ENTRIES; i++, c++) {
+               uint64_t seq, tsc;
+
+               c->cpu = t->cpu;
+               do {
+                       seq = atomic64_inc_return(t->seq);
+                       tsc = get_cpu_clock();
+               } while (seq != *t->seq);
+
+               c->seq = seq;
+               c->tsc = tsc;
+       }
+
+       log_info("cs: cpu%3d: %lu clocks seen\n", t->cpu, t->entries[CLOCK_ENTRIES - 1].tsc - t->entries[0].tsc);
+       return NULL;
+}
+
+static int clock_cmp(const void *p1, const void *p2)
+{
+       const struct clock_entry *c1 = p1;
+       const struct clock_entry *c2 = p2;
+
+       if (c1->seq == c2->seq)
+               log_err("cs: bug in atomic sequence!\n");
+
+       return c1->seq - c2->seq;
+}
+
+int fio_monotonic_clocktest(void)
+{
+       struct clock_thread *threads;
+       unsigned int nr_cpus = cpus_online();
+       struct clock_entry *entries;
+       unsigned long tentries, failed;
+       uint64_t seq = 0;
+       int i;
+
+       fio_debug |= 1U << FD_TIME;
+       calibrate_cpu_clock();
+       fio_debug &= ~(1U << FD_TIME);
+
+       threads = malloc(nr_cpus * sizeof(struct clock_thread));
+       tentries = CLOCK_ENTRIES * nr_cpus;
+       entries = malloc(tentries * sizeof(struct clock_entry));
+
+       log_info("cs: Testing %u CPUs\n", nr_cpus);
+
+       for (i = 0; i < nr_cpus; i++) {
+               struct clock_thread *t = &threads[i];
+
+               t->cpu = i;
+               t->seq = &seq;
+               t->entries = &entries[i * CLOCK_ENTRIES];
+               pthread_mutex_init(&t->lock, NULL);
+               pthread_mutex_init(&t->started, NULL);
+               pthread_mutex_lock(&t->lock);
+               pthread_create(&t->thread, NULL, clock_thread_fn, t);
+       }
+
+       for (i = 0; i < nr_cpus; i++) {
+               struct clock_thread *t = &threads[i];
+
+               pthread_mutex_lock(&t->started);
+       }
+
+       for (i = 0; i < nr_cpus; i++) {
+               struct clock_thread *t = &threads[i];
+
+               pthread_mutex_unlock(&t->lock);
+       }
+
+       for (failed = i = 0; i < nr_cpus; i++) {
+               struct clock_thread *t = &threads[i];
+               void *ret;
+
+               pthread_join(t->thread, &ret);
+               if (ret)
+                       failed++;
+       }
+       free(threads);
+
+       if (failed) {
+               log_err("Clocksource test: %u threads failed\n", failed);
+               goto err;
+       }
+
+       qsort(entries, tentries, sizeof(struct clock_entry), clock_cmp);
+
+       for (failed = i = 0; i < tentries; i++) {
+               struct clock_entry *prev, *this = &entries[i];
+
+               if (!i) {
+                       prev = this;
+                       continue;
+               }
+
+               if (prev->tsc > this->tsc) {
+                       uint64_t diff = prev->tsc - this->tsc;
+
+                       log_info("cs: CPU clock mismatch (diff=%lu):\n", diff);
+                       log_info("\t CPU%3lu: TSC=%lu, SEQ=%lu\n", prev->cpu, prev->tsc, prev->seq);
+                       log_info("\t CPU%3lu: TSC=%lu, SEQ=%lu\n", this->cpu, this->tsc, this->seq);
+                       failed++;
+               }
+
+               prev = this;
+       }
+
+       if (failed)
+               log_info("cs: Failed: %lu\n", failed);
+       else
+               log_info("cs: Pass!\n");
+
+err:
+       free(entries);
+       return !!failed;
+}
+
+#else /* defined(FIO_HAVE_CPU_AFFINITY) && defined(ARCH_HAVE_CPU_CLOCK) */
+
+int fio_monotonic_clocktest(void)
+{
+       log_info("cs: current platform does not support CPU clocks\n");
+       return 0;
+}
+
+#endif
index 64651a1badb35ef2112e30cd46c69c857b9e4264..f0ad20c8a2927437cc49eb2a4adf9fb28f4b247f 100644 (file)
--- a/gettime.h
+++ b/gettime.h
@@ -15,6 +15,8 @@ extern void fio_gettime(struct timeval *, void *);
 extern void fio_gtod_init(void);
 extern void fio_clock_init(void);
 extern int fio_start_gtod_thread(void);
+extern int fio_monotonic_clocktest(void);
+extern void fio_local_clock_init(int);
 
 extern struct timeval *fio_tv;
 
diff --git a/init.c b/init.c
index 6878322be349d0ac04c25ea210add8ddffe13e94..dc0440e4b49f67bee8831d030ca4e51136b3b138 100644 (file)
--- a/init.c
+++ b/init.c
@@ -206,6 +206,11 @@ static struct option l_opts[FIO_NR_OPTIONS] = {
                .has_arg        = required_argument,
                .val            = 'C',
        },
+       {
+               .name           = (char *) "cpuclock-test",
+               .has_arg        = no_argument,
+               .val            = 'T',
+       },
        {
                .name           = NULL,
        },
@@ -1255,6 +1260,7 @@ static void usage(const char *name)
        printf("  --terse-version=x\tSet terse version output format to 'x'\n");
        printf("  --version\t\tPrint version info and exit\n");
        printf("  --help\t\tPrint this page\n");
+       printf("  --cpuclock-test\tPerform test/validation of CPU clock\n");
        printf("  --cmdhelp=cmd\t\tPrint command help, \"all\" for all of"
                " them\n");
        printf("  --enghelp=engine\tPrint ioengine help, or list"
@@ -1275,7 +1281,7 @@ static void usage(const char *name)
        printf("  --daemonize=pidfile\tBackground fio server, write pid to file\n");
        printf("  --client=hostname\tTalk to remote backend fio server at hostname\n");
        printf("\nFio was written by Jens Axboe <jens.axboe@oracle.com>");
-       printf("\n                 Jens Axboe <jaxboe@fusionio.com>\n");
+       printf("\n                   Jens Axboe <jaxboe@fusionio.com>\n");
 }
 
 #ifdef FIO_INC_DEBUG
@@ -1663,6 +1669,10 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
                                optind++;
                        }
                        break;
+               case 'T':
+                       do_exit++;
+                       exit_val = fio_monotonic_clocktest();
+                       break;
                default:
                        do_exit++;
                        exit_val = 1;
index 86098b0c8d14db213a558f24d87aa5e884328905..5845d5f370c2463683b14613ca80c1513d710458 100755 (executable)
@@ -7,10 +7,10 @@
                <?define ProgramDirectory = ProgramFiles64Folder ?>\r
        <?endif?>\r
 \r
-    <Product Id="C3DC8A4F-1191-412F-8287-ACB6BA798F6A"\r
+       <Product Id="F9883688-6AB3-4BD1-AB93-91D39F12F003"\r
          Codepage="1252" Language="1033"\r
          Manufacturer="fio" Name="fio"\r
-         UpgradeCode="2338A332-5511-43cf-b9BD-5C60496CCFCC" Version="2.0.11">\r
+         UpgradeCode="2338A332-5511-43cf-b9BD-5C60496CCFCC" Version="2.0.13">\r
                <Package\r
                  Comments="Contact: Your local administrator"\r
                  Description="Flexible IO Tester"\r
index 2953aec6122791d5d4bfa4763f71eca227886632..aaffb52f06d910c15506bd3f1f0dfddeb2b7df90 100644 (file)
@@ -1,6 +1,6 @@
 #ifndef DLFCN_H\r
 #define DLFCN_H\r
\r
+\r
 #define RTLD_LAZY 1\r
 \r
 void *dlopen(const char *file, int mode);\r
index 0fac2c01e617bcaa2c359a14ea0cdba74e1df501..077550c61b4884d61d343d349e6fd1cb1e7f93b3 100644 (file)
@@ -6,7 +6,7 @@
 \r
  struct iovec\r
  {\r
-       void    *iov_base;  /* Base address of a memory region for input or output */\r
+       void    *iov_base;  /* Base address of a memory region for input or output */\r
        size_t   iov_len;   /* The size of the memory pointed to by iov_base */\r
 };\r
 \r
index ec118054a9ad56d53e4b092bfff6ab0d462416a5..64e57a5b1182dae3904dfbbb6e84723fbfc2a630 100644 (file)
@@ -6,7 +6,7 @@ typedef int in_port_t;
 \r
  struct sockaddr_un\r
  {\r
-       sa_family_t     sun_family; /* Address family */\r
+       sa_family_t     sun_family; /* Address family */\r
        char            sun_path[]; /* Socket pathname */\r
 };\r
 \r
index 201e62d67c943a367ebb4005a45182ed6d52ab79..fa88d241aec6af1b887c0a5046829cdd185a23ba 100644 (file)
--- a/server.h
+++ b/server.h
@@ -27,7 +27,7 @@ struct fio_net_cmd {
         */
        uint16_t cmd_crc16;     /* cmd checksum */
        uint16_t pdu_crc16;     /* payload checksum */
-       uint8_t payload[0];     /* payload */
+       uint8_t payload[];      /* payload */
 };
 
 struct fio_net_cmd_reply {
@@ -96,13 +96,13 @@ struct cmd_probe_pdu {
 
 struct cmd_single_line_pdu {
        uint16_t len;
-       uint8_t text[0];
+       uint8_t text[];
 };
 
 struct cmd_line_pdu {
        uint16_t lines;
        uint16_t client_type;
-       struct cmd_single_line_pdu options[0];
+       struct cmd_single_line_pdu options[];
 };
 
 struct cmd_job_pdu {
diff --git a/stat.h b/stat.h
index 8a1536e889b633593f2dabcfe439b9046e8fb42a..f35f1f600bf2df727035431c45c698045aa97039 100644 (file)
--- a/stat.h
+++ b/stat.h
@@ -189,7 +189,7 @@ struct jobs_eta {
         * Network 'copy' of run_str[]
         */
        uint32_t nr_threads;
-       uint8_t run_str[0];
+       uint8_t run_str[];
 };
 
 extern void show_thread_status(struct thread_stat *ts, struct group_run_stats *rs);
index 1f8c3e9a90f6855878f37c0fb574217f6363094e..3f6043dbfe0e5af49182691dc747aaa1c7e6ff80 100644 (file)
--- a/t/axmap.c
+++ b/t/axmap.c
@@ -26,13 +26,17 @@ int main(int argc, char *argv[])
        struct fio_lfsr lfsr;
        size_t size = (1UL << 28) - 200;
        struct axmap *map;
+       int seed = 1;
 
-       if (argc > 1)
+       if (argc > 1) {
                size = strtoul(argv[1], NULL, 10);
+               if (argc > 2)
+                       seed = strtoul(argv[2], NULL, 10);
+       }
 
        printf("Using %llu entries\n", (unsigned long long) size);
 
-       lfsr_init(&lfsr, size);
+       lfsr_init(&lfsr, size, seed);
        map = axmap_new(size);
 
        while (size--) {
diff --git a/time.c b/time.c
index c4d1d4c7c6ee5da1cac47011d0ccd86a1ae1e78a..17f9f6fcd187b69feda17140ba62928d7a8f4914 100644 (file)
--- a/time.c
+++ b/time.c
@@ -53,7 +53,7 @@ void usec_sleep(struct thread_data *td, unsigned long usec)
        } while (!td->terminate);
 }
 
-unsigned long mtime_since_genesis(void)
+uint64_t mtime_since_genesis(void)
 {
        return mtime_since_now(&genesis);
 }
diff --git a/time.h b/time.h
index 3824102d7497268189d4b1c12b7bbdb29b58b669..d835191250fcb8e412762d48c00077e38c2d4f8e 100644 (file)
--- a/time.h
+++ b/time.h
@@ -1,19 +1,18 @@
 #ifndef FIO_TIME_H
 #define FIO_TIME_H
 
-extern unsigned long long utime_since(struct timeval *, struct timeval *);
-extern unsigned long long utime_since_now(struct timeval *);
-extern unsigned long mtime_since(struct timeval *, struct timeval *);
-extern unsigned long mtime_since_now(struct timeval *);
-extern unsigned long time_since_now(struct timeval *);
-extern unsigned long mtime_since_genesis(void);
+extern uint64_t utime_since(struct timeval *, struct timeval *);
+extern uint64_t utime_since_now(struct timeval *);
+extern uint64_t mtime_since(struct timeval *, struct timeval *);
+extern uint64_t mtime_since_now(struct timeval *);
+extern uint64_t time_since_now(struct timeval *);
+extern uint64_t mtime_since_genesis(void);
 extern void usec_spin(unsigned int);
 extern void usec_sleep(struct thread_data *, unsigned long);
 extern void fill_start_time(struct timeval *);
 extern void set_genesis_time(void);
 extern int ramp_time_over(struct thread_data *);
 extern int in_ramp_time(struct thread_data *);
-extern unsigned long long genesis_cycles;
 extern void fio_time_init(void);
 
 #endif