Branch and cache miss speedups
authorJens Axboe <axboe@fb.com>
Wed, 26 Feb 2014 22:31:15 +0000 (14:31 -0800)
committerJens Axboe <axboe@fb.com>
Wed, 26 Feb 2014 22:31:15 +0000 (14:31 -0800)
Just some low hanging fruit.

Signed-off-by: Jens Axboe <axboe@fb.com>
compiler/compiler.h
filesetup.c
gettime.c
io_u.c
ioengine.h
lib/lfsr.c

index 036ba208e861e79225a3e8827f5ff81895c50818..0a0213b60fca5204cb9d0294ffb01139baa23083 100644 (file)
@@ -20,4 +20,6 @@
 #define fio_init       __attribute__((constructor))
 #define fio_exit       __attribute__((destructor))
 
+#define fio_unlikely(x)        __builtin_expect(!!(x), 0)
+
 #endif
index 1acf6adcf377cfe861590ad067baec1e0db643b6..2744d4fce0f9597166a3a749445c530594ff33b7 100644 (file)
@@ -1010,7 +1010,7 @@ int init_random_map(struct thread_data *td)
 
                        seed = td->rand_seeds[FIO_RAND_BLOCK_OFF];
                        
-                       if (!lfsr_init(&f->lfsr, blocks, seed, seed & 0xF))
+                       if (!lfsr_init(&f->lfsr, blocks, seed, 0))
                                continue;
                } else if (!td->o.norandommap) {
                        f->io_axmap = axmap_new(blocks);
index 277f2cf87ec16229150651ee85a163ed0b5ce7f4..8991703fd0662fad4616ed8ab66f154f12c0ade9 100644 (file)
--- a/gettime.c
+++ b/gettime.c
@@ -205,7 +205,7 @@ void fio_gettime(struct timeval *tp, void fio_unused *caller)
 
        gtod_log_caller(caller);
 #endif
-       if (fio_tv) {
+       if (fio_unlikely(fio_tv)) {
                memcpy(tp, fio_tv, sizeof(*tp));
                return;
        }
diff --git a/io_u.c b/io_u.c
index a69efb76c2d727cd3f5e883382270f4a3d53cc14..77557dfdca12748f1db2249c05efc93a21b09f4b 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -1307,9 +1307,9 @@ again:
        else if (!queue_full(td)) {
                io_u = io_u_qpop(&td->io_u_freelist);
 
+               io_u->file = NULL;
                io_u->buflen = 0;
                io_u->resid = 0;
-               io_u->file = NULL;
                io_u->end_io = NULL;
        }
 
index abf2b464d8dfcef30a4b4693536da89723c8ba08..7e0707bc9c35667ab07fda03f08f62f49cc505cf 100644 (file)
@@ -73,6 +73,25 @@ struct io_u {
 
        struct io_piece *ipo;
 
+       unsigned int resid;
+       unsigned int error;
+
+       /*
+        * io engine private data
+        */
+       union {
+               unsigned int index;
+               unsigned int seen;
+               void *engine_data;
+       };
+
+       struct flist_head verify_list;
+
+       /*
+        * Callback for io completion
+        */
+       int (*end_io)(struct thread_data *, struct io_u *);
+
        union {
 #ifdef CONFIG_LIBAIO
                struct iocb iocb;
@@ -97,25 +116,6 @@ struct io_u {
 #endif
                void *mmap_data;
        };
-
-       unsigned int resid;
-       unsigned int error;
-
-       /*
-        * io engine private data
-        */
-       union {
-               unsigned int index;
-               unsigned int seen;
-               void *engine_data;
-       };
-
-       struct flist_head verify_list;
-
-       /*
-        * Callback for io completion
-        */
-       int (*end_io)(struct thread_data *, struct io_u *);
 };
 
 /*
index 927b2a10cdeeefc4441a9b7aa720677b6939a9be..9771318ab00163b8b6a9f68dc076cd896c00fda6 100644 (file)
@@ -2,6 +2,7 @@
 #include <math.h>
 
 #include "lfsr.h"
+#include "../compiler/compiler.h"
 
 /*
  * LFSR taps retrieved from:
@@ -132,11 +133,9 @@ int lfsr_next(struct fio_lfsr *fl, uint64_t *off, uint64_t last)
                if (fl->cycle_length && !--fl->cycle_length) {
                        __lfsr_next(fl, fl->spin + 1);
                        fl->cycle_length = fl->cached_cycle_length;
-                       goto check;
-               }
-               __lfsr_next(fl, fl->spin);
-check: ;
-       } while (fl->last_val > fl->max_val);
+               } else
+                       __lfsr_next(fl, fl->spin);
+       } while (fio_unlikely(fl->last_val > fl->max_val));
 
        *off = fl->last_val;
        return 0;