From 60bd1f32d5451fdebe4486aee0ab9f1d63e528f6 Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Wed, 16 Jan 2019 07:58:57 +0900 Subject: [PATCH] nvme_perf: Relocate functions only for AIO to introduce abstraction Subsequent patches will introduce function pointer table for IO type depenedent operations. This patch doesn't cause any functional change and just tries to make them easier. Change-Id: I664c9e39d101957c55cfcf9426f82feca348c328 Signed-off-by: Shuhei Matsumoto Reviewed-on: https://review.gerrithub.io/c/440670 Tested-by: SPDK CI Jenkins Reviewed-by: wuzhouhui Reviewed-by: Paul Luse Reviewed-by: Jim Harris Reviewed-by: Changpeng Liu Chandler-Test-Pool: SPDK Automated Test System --- examples/nvme/perf/perf.c | 98 +++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/examples/nvme/perf/perf.c b/examples/nvme/perf/perf.c index 04c4e6f58..6f5c8b6e3 100644 --- a/examples/nvme/perf/perf.c +++ b/examples/nvme/perf/perf.c @@ -377,6 +377,46 @@ register_ctrlr(struct spdk_nvme_ctrlr *ctrlr, struct trid_entry *trid_entry) } #if HAVE_LIBAIO +static int +aio_submit(io_context_t aio_ctx, struct iocb *iocb, int fd, enum io_iocb_cmd cmd, void *buf, + unsigned long nbytes, uint64_t offset, void *cb_ctx) +{ + iocb->aio_fildes = fd; + iocb->aio_reqprio = 0; + iocb->aio_lio_opcode = cmd; + iocb->u.c.buf = buf; + iocb->u.c.nbytes = nbytes; + iocb->u.c.offset = offset; + iocb->data = cb_ctx; + + if (io_submit(aio_ctx, 1, &iocb) < 0) { + printf("io_submit"); + return -1; + } + + return 0; +} + +static void +aio_check_io(struct ns_worker_ctx *ns_ctx) +{ + int count, i; + struct timespec timeout; + + timeout.tv_sec = 0; + timeout.tv_nsec = 0; + + count = io_getevents(ns_ctx->u.aio.ctx, 1, g_queue_depth, ns_ctx->u.aio.events, &timeout); + if (count < 0) { + fprintf(stderr, "io_getevents error\n"); + exit(1); + } + + for (i = 0; i < count; i++) { + task_complete(ns_ctx->u.aio.events[i].data); + } +} + static int register_aio_file(const char *path) { @@ -446,44 +486,19 @@ register_aio_file(const char *path) } static int -aio_submit(io_context_t aio_ctx, struct iocb *iocb, int fd, enum io_iocb_cmd cmd, void *buf, - unsigned long nbytes, uint64_t offset, void *cb_ctx) +register_aio_files(int argc, char **argv) { - iocb->aio_fildes = fd; - iocb->aio_reqprio = 0; - iocb->aio_lio_opcode = cmd; - iocb->u.c.buf = buf; - iocb->u.c.nbytes = nbytes; - iocb->u.c.offset = offset; - iocb->data = cb_ctx; + int i; - if (io_submit(aio_ctx, 1, &iocb) < 0) { - printf("io_submit"); - return -1; + /* Treat everything after the options as files for AIO */ + for (i = g_aio_optind; i < argc; i++) { + if (register_aio_file(argv[i]) != 0) { + return 1; + } } return 0; } - -static void -aio_check_io(struct ns_worker_ctx *ns_ctx) -{ - int count, i; - struct timespec timeout; - - timeout.tv_sec = 0; - timeout.tv_nsec = 0; - - count = io_getevents(ns_ctx->u.aio.ctx, 1, g_queue_depth, ns_ctx->u.aio.events, &timeout); - if (count < 0) { - fprintf(stderr, "io_getevents error\n"); - exit(1); - } - - for (i = 0; i < count; i++) { - task_complete(ns_ctx->u.aio.events[i].data); - } -} #endif /* HAVE_LIBAIO */ static void @@ -1665,23 +1680,6 @@ unregister_controllers(void) } } -static int -register_aio_files(int argc, char **argv) -{ -#if HAVE_LIBAIO - int i; - - /* Treat everything after the options as files for AIO */ - for (i = g_aio_optind; i < argc; i++) { - if (register_aio_file(argv[i]) != 0) { - return 1; - } - } -#endif /* HAVE_LIBAIO */ - - return 0; -} - static int associate_workers_with_ns(void) { @@ -1763,10 +1761,12 @@ int main(int argc, char **argv) goto cleanup; } +#if HAVE_LIBAIO if (register_aio_files(argc, argv) != 0) { rc = -1; goto cleanup; } +#endif if (register_controllers() != 0) { rc = -1;