engines/xnvme: user space vfio based backend
[fio.git] / engines / librpma_gpspm.c
index 5cf974722de2052c97d8485faea2b5d924638ddd..70116d0d6ece5d3d2adf6b5bb93081bc787662ca 100644 (file)
@@ -2,7 +2,7 @@
  * librpma_gpspm: IO engine that uses PMDK librpma to write data,
  *             based on General Purpose Server Persistency Method
  *
- * Copyright 2020-2021, Intel Corporation
+ * Copyright 2020-2022, Intel Corporation
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License,
 
 #include "librpma_fio.h"
 
+#ifdef CONFIG_LIBPMEM2_INSTALLED
+#include <libpmem2.h>
+#else
 #include <libpmem.h>
+#endif
 
 /* Generated by the protocol buffer compiler from: librpma_gpspm_flush.proto */
 #include "librpma_gpspm_flush.pb-c.h"
@@ -352,7 +356,7 @@ FIO_STATIC struct ioengine_ops ioengine_client = {
        .errdetails             = librpma_fio_client_errdetails,
        .close_file             = librpma_fio_file_nop,
        .cleanup                = client_cleanup,
-       .flags                  = FIO_DISKLESSIO,
+       .flags                  = FIO_DISKLESSIO | FIO_ASYNCIO_SETS_ISSUE_TIME,
        .options                = librpma_fio_options,
        .option_struct_size     = sizeof(struct librpma_fio_options_values),
 };
@@ -361,6 +365,8 @@ FIO_STATIC struct ioengine_ops ioengine_client = {
 
 #define IO_U_BUFF_OFF_SERVER(i) (i * IO_U_BUF_LEN)
 
+typedef void (*librpma_fio_persist_fn)(const void *ptr, size_t size);
+
 struct server_data {
        /* aligned td->orig_buffer */
        char *orig_buffer_aligned;
@@ -373,6 +379,8 @@ struct server_data {
        /* in-memory queues */
        struct ibv_wc *msgs_queued;
        uint32_t msg_queued_nr;
+
+       librpma_fio_persist_fn persist;
 };
 
 static int server_init(struct thread_data *td)
@@ -400,6 +408,13 @@ static int server_init(struct thread_data *td)
                goto err_free_sd;
        }
 
+#ifdef CONFIG_LIBPMEM2_INSTALLED
+       /* get libpmem2 persist function from pmem2_map */
+       sd->persist = pmem2_get_persist_fn(csd->mem.map);
+#else
+       sd->persist = pmem_persist;
+#endif
+
        /*
         * Assure a single io_u buffer can store both SEND and RECV messages and
         * an io_us buffer allocation is page-size-aligned which is required
@@ -594,7 +609,7 @@ static int server_qe_process(struct thread_data *td, struct ibv_wc *wc)
 
        if (IS_NOT_THE_LAST_MESSAGE(flush_req)) {
                op_ptr = csd->ws_ptr + flush_req->offset;
-               pmem_persist(op_ptr, flush_req->length);
+               sd->persist(op_ptr, flush_req->length);
        } else {
                /*
                 * This is the last message - the client is done.
@@ -685,29 +700,25 @@ static int server_cmpl_process(struct thread_data *td)
 
        ret = rpma_cq_get_wc(csd->cq, 1, wc, NULL);
        if (ret == RPMA_E_NO_COMPLETION) {
-               if (o->busy_wait_polling == 0) {
-                       ret = rpma_cq_wait(csd->cq);
-                       if (ret == RPMA_E_NO_COMPLETION) {
-                               /* lack of completion is not an error */
-                               return 0;
-                       } else if (ret != 0) {
-                               librpma_td_verror(td, ret, "rpma_cq_wait");
-                               goto err_terminate;
-                       }
-
-                       ret = rpma_cq_get_wc(csd->cq, 1, wc, NULL);
-                       if (ret == RPMA_E_NO_COMPLETION) {
-                               /* lack of completion is not an error */
-                               return 0;
-                       } else if (ret != 0) {
-                               librpma_td_verror(td, ret, "rpma_cq_get_wc");
-                               goto err_terminate;
-                       }
-               } else {
-                       /* lack of completion is not an error */
-                       return 0;
+               if (o->busy_wait_polling)
+                       return 0; /* lack of completion is not an error */
+
+               ret = rpma_cq_wait(csd->cq);
+               if (ret == RPMA_E_NO_COMPLETION)
+                       return 0; /* lack of completion is not an error */
+               if (ret) {
+                       librpma_td_verror(td, ret, "rpma_cq_wait");
+                       goto err_terminate;
+               }
+
+               ret = rpma_cq_get_wc(csd->cq, 1, wc, NULL);
+               if (ret == RPMA_E_NO_COMPLETION)
+                       return 0; /* lack of completion is not an error */
+               if (ret) {
+                       librpma_td_verror(td, ret, "rpma_cq_get_wc");
+                       goto err_terminate;
                }
-       } else if (ret != 0) {
+       } else if (ret) {
                librpma_td_verror(td, ret, "rpma_cq_get_wc");
                goto err_terminate;
        }