diff --git a/examples/nvme/hello_world/hello_world.c b/examples/nvme/hello_world/hello_world.c index 23e1a2100..2e91a5445 100644 --- a/examples/nvme/hello_world/hello_world.c +++ b/examples/nvme/hello_world/hello_world.c @@ -93,6 +93,7 @@ register_ns(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_ns *ns) struct hello_world_sequence { struct ns_entry *ns_entry; char *buf; + unsigned using_cmb_io; int is_completed; }; @@ -124,7 +125,11 @@ write_complete(void *arg, const struct spdk_nvme_cpl *completion) * the write I/O and allocate a new zeroed buffer for reading * the data back from the NVMe namespace. */ - spdk_dma_free(sequence->buf); + if (sequence->using_cmb_io) { + spdk_nvme_ctrlr_free_cmb_io_buffer(ns_entry->ctrlr, sequence->buf, 0x1000); + } else { + spdk_dma_free(sequence->buf); + } sequence->buf = spdk_dma_zmalloc(0x1000, 0x1000, NULL); rc = spdk_nvme_ns_cmd_read(ns_entry->ns, ns_entry->qpair, sequence->buf, @@ -169,7 +174,21 @@ hello_world(void) * will be pinned, which is required for data buffers used for SPDK NVMe * I/O operations. */ - sequence.buf = spdk_dma_zmalloc(0x1000, 0x1000, NULL); + sequence.using_cmb_io = 1; + sequence.buf = spdk_nvme_ctrlr_alloc_cmb_io_buffer(ns_entry->ctrlr, 0x1000); + if (sequence.buf == NULL) { + sequence.using_cmb_io = 0; + sequence.buf = spdk_dma_zmalloc(0x1000, 0x1000, NULL); + } + if (sequence.buf == NULL) { + printf("ERROR: write buffer allocation failed\n"); + return; + } + if (sequence.using_cmb_io) { + printf("INFO: using controller memory buffer for IO\n"); + } else { + printf("INFO: using host memory buffer for IO\n"); + } sequence.is_completed = 0; sequence.ns_entry = ns_entry;