gpu: kill a lot of useless ifdefs
authorJens Axboe <axboe@fb.com>
Wed, 26 Apr 2017 21:05:07 +0000 (15:05 -0600)
committerJens Axboe <axboe@fb.com>
Wed, 26 Apr 2017 21:05:07 +0000 (15:05 -0600)
We just have to guard how we set the mem type, we don't have
to guard any check for MEM_CUDA_MALLOC inside CONFIG_CUDA
ifdefs.

Additionally, fix up some bad style.

Fixes: 03553853 ("GPUDirect RDMA support")
Signed-off-by: Jens Axboe <axboe@fb.com>
init.c
io_u.c
memory.c

diff --git a/init.c b/init.c
index 9aa452da0f0df58fd4bdb354275e4346a369a3a1..52a5f0301d196fe11b378fce6e59e41800745126 100644 (file)
--- a/init.c
+++ b/init.c
@@ -1070,6 +1070,9 @@ static void init_flags(struct thread_data *td)
 
        if (o->verify_async || o->io_submit_mode == IO_MODE_OFFLOAD)
                td->flags |= TD_F_NEED_LOCK;
+
+       if (o->mem_type == MEM_CUDA_MALLOC)
+               td->flags &= ~TD_F_SCRAMBLE_BUFFERS;
 }
 
 static int setup_random_seeds(struct thread_data *td)
diff --git a/io_u.c b/io_u.c
index 39d68d1f9ae082fc391a66323027ba30157081f4..fd63119888327fff8705bbdef066b910d8f37d1e 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -1654,10 +1654,6 @@ struct io_u *get_io_u(struct thread_data *td)
                                populate_verify_io_u(td, io_u);
                                do_scramble = 0;
                        }
-#ifdef CONFIG_CUDA
-                       if (td->o.mem_type == MEM_CUDA_MALLOC)
-                               do_scramble = 0;
-#endif
                } else if (io_u->ddir == DDIR_READ) {
                        /*
                         * Reset the buf_filled parameters so next time if the
@@ -2049,9 +2045,8 @@ void fill_io_buffer(struct thread_data *td, void *buf, unsigned int min_write,
 {
        struct thread_options *o = &td->o;
 
-#ifdef CONFIG_CUDA
-       if (o->mem_type == MEM_CUDA_MALLOC)     return;
-#endif
+       if (o->mem_type == MEM_CUDA_MALLOC)
+               return;
 
        if (o->compress_percentage || o->dedupe_percentage) {
                unsigned int perc = td->o.compress_percentage;
index fe657225a2739bf878b2ddfb0909771ccb6e21ad..22a7f5ddde6c1dc785d9a6f37ad4a16d53cb38ec 100644 (file)
--- a/memory.c
+++ b/memory.c
@@ -207,10 +207,9 @@ static void free_mem_malloc(struct thread_data *td)
        free(td->orig_buffer);
 }
 
-#ifdef CONFIG_CUDA
-
 static int alloc_mem_cudamalloc(struct thread_data *td, size_t total_mem)
 {
+#ifdef CONFIG_CUDA
        CUresult ret;
        char name[128];
 
@@ -264,17 +263,21 @@ static int alloc_mem_cudamalloc(struct thread_data *td, size_t total_mem)
        dprint(FD_MEM, "cudaMalloc %llu %p\n",                          \
               (unsigned long long) total_mem, td->orig_buffer);
        return 0;
+#else
+       return -EINVAL;
+#endif
 }
 
 static void free_mem_cudamalloc(struct thread_data *td)
 {
-       if ((void *) td->dev_mem_ptr != NULL)
+#ifdef CONFIG_CUDA
+       if (td->dev_mem_ptr != NULL)
                cuMemFree(td->dev_mem_ptr);
 
        if (cuCtxDestroy(td->cu_ctx) != CUDA_SUCCESS)
                log_err("fio: failed to destroy cuda context\n");
-}
 #endif
+}
 
 /*
  * Set up the buffer area we need for io.
@@ -315,10 +318,8 @@ int allocate_io_mem(struct thread_data *td)
        else if (td->o.mem_type == MEM_MMAP || td->o.mem_type == MEM_MMAPHUGE ||
                 td->o.mem_type == MEM_MMAPSHARED)
                ret = alloc_mem_mmap(td, total_mem);
-#ifdef CONFIG_CUDA
        else if (td->o.mem_type == MEM_CUDA_MALLOC)
                ret = alloc_mem_cudamalloc(td, total_mem);
-#endif
        else {
                log_err("fio: bad mem type: %d\n", td->o.mem_type);
                ret = 1;
@@ -348,10 +349,8 @@ void free_io_mem(struct thread_data *td)
        else if (td->o.mem_type == MEM_MMAP || td->o.mem_type == MEM_MMAPHUGE ||
                 td->o.mem_type == MEM_MMAPSHARED)
                free_mem_mmap(td, total_mem);
-#ifdef CONFIG_CUDA
        else if (td->o.mem_type == MEM_CUDA_MALLOC)
                free_mem_cudamalloc(td);
-#endif
        else
                log_err("Bad memory type %u\n", td->o.mem_type);