summaryrefslogtreecommitdiffstats
path: root/src/spdk/app
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
commit483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch)
treee5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/spdk/app
parentInitial commit. (diff)
downloadceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz
ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/spdk/app')
-rw-r--r--src/spdk/app/Makefile51
-rw-r--r--src/spdk/app/iscsi_tgt/.gitignore1
-rw-r--r--src/spdk/app/iscsi_tgt/Makefile70
-rw-r--r--src/spdk/app/iscsi_tgt/iscsi_tgt.c120
-rw-r--r--src/spdk/app/iscsi_top/.gitignore1
-rw-r--r--src/spdk/app/iscsi_top/Makefile53
-rw-r--r--src/spdk/app/iscsi_top/iscsi_top.cpp251
-rw-r--r--src/spdk/app/nvmf_tgt/.gitignore1
-rw-r--r--src/spdk/app/nvmf_tgt/Makefile65
-rw-r--r--src/spdk/app/nvmf_tgt/nvmf_main.c78
-rw-r--r--src/spdk/app/spdk_tgt/.gitignore1
-rw-r--r--src/spdk/app/spdk_tgt/Makefile73
-rw-r--r--src/spdk/app/spdk_tgt/spdk_tgt.c126
-rw-r--r--src/spdk/app/trace/.gitignore1
-rw-r--r--src/spdk/app/trace/Makefile51
-rw-r--r--src/spdk/app/trace/trace.cpp418
-rw-r--r--src/spdk/app/vhost/.gitignore1
-rw-r--r--src/spdk/app/vhost/Makefile63
-rw-r--r--src/spdk/app/vhost/vhost.c118
19 files changed, 1543 insertions, 0 deletions
diff --git a/src/spdk/app/Makefile b/src/spdk/app/Makefile
new file mode 100644
index 00000000..e6103a81
--- /dev/null
+++ b/src/spdk/app/Makefile
@@ -0,0 +1,51 @@
+#
+# BSD LICENSE
+#
+# Copyright (c) Intel Corporation.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Intel Corporation nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+SPDK_ROOT_DIR := $(abspath $(CURDIR)/..)
+include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
+
+DIRS-y += trace
+DIRS-y += nvmf_tgt
+DIRS-y += iscsi_top
+DIRS-y += iscsi_tgt
+DIRS-y += spdk_tgt
+ifeq ($(OS),Linux)
+DIRS-$(CONFIG_VHOST) += vhost
+endif
+
+.PHONY: all clean $(DIRS-y)
+
+all: $(DIRS-y)
+clean: $(DIRS-y)
+
+include $(SPDK_ROOT_DIR)/mk/spdk.subdirs.mk
diff --git a/src/spdk/app/iscsi_tgt/.gitignore b/src/spdk/app/iscsi_tgt/.gitignore
new file mode 100644
index 00000000..14d948c5
--- /dev/null
+++ b/src/spdk/app/iscsi_tgt/.gitignore
@@ -0,0 +1 @@
+iscsi_tgt
diff --git a/src/spdk/app/iscsi_tgt/Makefile b/src/spdk/app/iscsi_tgt/Makefile
new file mode 100644
index 00000000..5fc7dd42
--- /dev/null
+++ b/src/spdk/app/iscsi_tgt/Makefile
@@ -0,0 +1,70 @@
+#
+# BSD LICENSE
+#
+# Copyright (c) Intel Corporation.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Intel Corporation nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
+include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
+include $(SPDK_ROOT_DIR)/mk/spdk.app.mk
+include $(SPDK_ROOT_DIR)/mk/spdk.modules.mk
+
+APP = iscsi_tgt
+
+# Add iSCSI library directory to include path
+# TODO: remove this once iSCSI has a public API header
+CFLAGS += -I$(SPDK_ROOT_DIR)/lib
+
+C_SRCS := iscsi_tgt.c
+
+SPDK_LIB_LIST = event_bdev event_copy event_iscsi event_net event_scsi event
+SPDK_LIB_LIST += jsonrpc json rpc bdev_rpc bdev iscsi scsi copy trace conf
+SPDK_LIB_LIST += thread util log log_rpc app_rpc net
+
+ifeq ($(OS),Linux)
+SPDK_LIB_LIST += event_nbd nbd
+endif
+
+LIBS += $(BLOCKDEV_MODULES_LINKER_ARGS) \
+ $(COPY_MODULES_LINKER_ARGS) \
+ $(SOCK_MODULES_LINKER_ARGS)
+LIBS += $(SPDK_LIB_LINKER_ARGS)
+LIBS += $(ENV_LINKER_ARGS)
+
+all : $(APP)
+ @:
+
+$(APP) : $(OBJS) $(SPDK_LIB_FILES) $(ENV_LIBS) $(BLOCKDEV_MODULES_FILES) $(COPY_MODULES_FILES) $(SOCK_MODULES_FILES)
+ $(LINK_C)
+
+clean :
+ $(CLEAN_C) $(APP)
+
+include $(SPDK_ROOT_DIR)/mk/spdk.deps.mk
diff --git a/src/spdk/app/iscsi_tgt/iscsi_tgt.c b/src/spdk/app/iscsi_tgt/iscsi_tgt.c
new file mode 100644
index 00000000..9f23437e
--- /dev/null
+++ b/src/spdk/app/iscsi_tgt/iscsi_tgt.c
@@ -0,0 +1,120 @@
+/*-
+ * BSD LICENSE
+ *
+ * Copyright (c) Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "spdk/stdinc.h"
+
+#include "spdk/env.h"
+#include "spdk/event.h"
+#include "iscsi/iscsi.h"
+#include "spdk/log.h"
+#include "spdk/net.h"
+
+static int g_daemon_mode = 0;
+
+static void
+spdk_sigusr1(int signo __attribute__((__unused__)))
+{
+ char *config_str = NULL;
+ if (spdk_app_get_running_config(&config_str, "iscsi.conf") < 0) {
+ fprintf(stderr, "Error getting config\n");
+ } else {
+ fprintf(stdout, "============================\n");
+ fprintf(stdout, " iSCSI target running config\n");
+ fprintf(stdout, "=============================\n");
+ fprintf(stdout, "%s", config_str);
+ }
+ free(config_str);
+}
+
+static void
+iscsi_usage(void)
+{
+ printf(" -b run iscsi target background, the default is foreground\n");
+}
+
+static void
+spdk_startup(void *arg1, void *arg2)
+{
+ if (getenv("MEMZONE_DUMP") != NULL) {
+ spdk_memzone_dump(stdout);
+ fflush(stdout);
+ }
+}
+
+static void
+iscsi_parse_arg(int ch, char *arg)
+{
+ switch (ch) {
+ case 'b':
+ g_daemon_mode = 1;
+ break;
+ default:
+ assert(false);
+ break;
+ }
+}
+
+int
+main(int argc, char **argv)
+{
+ int rc;
+ struct spdk_app_opts opts = {};
+
+ spdk_app_opts_init(&opts);
+ opts.name = "iscsi";
+ if ((rc = spdk_app_parse_args(argc, argv, &opts, "b", NULL,
+ iscsi_parse_arg, iscsi_usage)) !=
+ SPDK_APP_PARSE_ARGS_SUCCESS) {
+ exit(rc);
+ }
+
+ if (g_daemon_mode) {
+ if (daemon(1, 0) < 0) {
+ SPDK_ERRLOG("Start iscsi target daemon faild.\n");
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ opts.shutdown_cb = NULL;
+ opts.usr1_handler = spdk_sigusr1;
+
+ /* Blocks until the application is exiting */
+ rc = spdk_app_start(&opts, spdk_startup, NULL, NULL);
+ if (rc) {
+ SPDK_ERRLOG("Start iscsi target daemon: spdk_app_start() retn non-zero\n");
+ }
+
+ spdk_app_fini();
+
+ return rc;
+}
diff --git a/src/spdk/app/iscsi_top/.gitignore b/src/spdk/app/iscsi_top/.gitignore
new file mode 100644
index 00000000..7d90ff34
--- /dev/null
+++ b/src/spdk/app/iscsi_top/.gitignore
@@ -0,0 +1 @@
+iscsi_top
diff --git a/src/spdk/app/iscsi_top/Makefile b/src/spdk/app/iscsi_top/Makefile
new file mode 100644
index 00000000..e4f9f573
--- /dev/null
+++ b/src/spdk/app/iscsi_top/Makefile
@@ -0,0 +1,53 @@
+#
+# BSD LICENSE
+#
+# Copyright (c) Intel Corporation.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Intel Corporation nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
+include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
+include $(SPDK_ROOT_DIR)/mk/spdk.app.mk
+
+CXXFLAGS += $(ENV_CXXFLAGS)
+CXXFLAGS += -I$(SPDK_ROOT_DIR)/lib
+CXX_SRCS = iscsi_top.cpp
+
+APP = iscsi_top
+
+all: $(APP)
+ @:
+
+$(APP) : $(OBJS)
+ $(LINK_CXX)
+
+clean:
+ $(CLEAN_C) $(APP)
+
+include $(SPDK_ROOT_DIR)/mk/spdk.deps.mk
diff --git a/src/spdk/app/iscsi_top/iscsi_top.cpp b/src/spdk/app/iscsi_top/iscsi_top.cpp
new file mode 100644
index 00000000..50449b59
--- /dev/null
+++ b/src/spdk/app/iscsi_top/iscsi_top.cpp
@@ -0,0 +1,251 @@
+/*-
+ * BSD LICENSE
+ *
+ * Copyright (c) Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "spdk/stdinc.h"
+
+#include <algorithm>
+#include <map>
+#include <vector>
+
+extern "C" {
+#include "spdk/trace.h"
+#include "iscsi/conn.h"
+}
+
+static char *exe_name;
+static int g_shm_id = 0;
+
+static void usage(void)
+{
+ fprintf(stderr, "usage:\n");
+ fprintf(stderr, " %s <option>\n", exe_name);
+ fprintf(stderr, " option = '-i' to specify the shared memory ID,"
+ " (required)\n");
+}
+
+static bool
+conns_compare(struct spdk_iscsi_conn *first, struct spdk_iscsi_conn *second)
+{
+ if (first->lcore < second->lcore) {
+ return true;
+ }
+
+ if (first->lcore > second->lcore) {
+ return false;
+ }
+
+ if (first->id < second->id) {
+ return true;
+ }
+
+ return false;
+}
+
+static void
+print_connections(void)
+{
+ std::vector<struct spdk_iscsi_conn *> v;
+ std::vector<struct spdk_iscsi_conn *>::iterator iter;
+ size_t conns_size;
+ struct spdk_iscsi_conn *conns, *conn;
+ void *conns_ptr;
+ int fd, i;
+ char shm_name[64];
+
+ snprintf(shm_name, sizeof(shm_name), "/spdk_iscsi_conns.%d", g_shm_id);
+ fd = shm_open(shm_name, O_RDONLY, 0600);
+ if (fd < 0) {
+ fprintf(stderr, "Cannot open shared memory: %s\n", shm_name);
+ usage();
+ exit(1);
+ }
+
+ conns_size = sizeof(*conns) * MAX_ISCSI_CONNECTIONS;
+
+ conns_ptr = mmap(NULL, conns_size, PROT_READ, MAP_SHARED, fd, 0);
+ if (conns_ptr == MAP_FAILED) {
+ fprintf(stderr, "Cannot mmap shared memory (%d)\n", errno);
+ exit(1);
+ }
+
+ conns = (struct spdk_iscsi_conn *)conns_ptr;
+
+ for (i = 0; i < MAX_ISCSI_CONNECTIONS; i++) {
+ if (!conns[i].is_valid) {
+ continue;
+ }
+ v.push_back(&conns[i]);
+ }
+
+ stable_sort(v.begin(), v.end(), conns_compare);
+ for (iter = v.begin(); iter != v.end(); iter++) {
+ conn = *iter;
+ printf("lcore %2d conn %3d T:%-8s I:%s (%s)\n",
+ conn->lcore, conn->id,
+ conn->target_short_name, conn->initiator_name,
+ conn->initiator_addr);
+ }
+
+ printf("\n");
+ munmap(conns, conns_size);
+ close(fd);
+}
+
+int main(int argc, char **argv)
+{
+ void *history_ptr;
+ struct spdk_trace_histories *histories;
+ struct spdk_trace_history *history;
+
+ uint64_t tasks_done, last_tasks_done[SPDK_TRACE_MAX_LCORE];
+ int delay, old_delay, history_fd, i, quit, rc;
+ int tasks_done_delta, tasks_done_per_sec;
+ int total_tasks_done_per_sec;
+ struct timeval timeout;
+ fd_set fds;
+ char ch;
+ struct termios oldt, newt;
+ char spdk_trace_shm_name[64];
+ int op;
+
+ exe_name = argv[0];
+ while ((op = getopt(argc, argv, "i:")) != -1) {
+ switch (op) {
+ case 'i':
+ g_shm_id = atoi(optarg);
+ break;
+ default:
+ usage();
+ exit(1);
+ }
+ }
+
+ snprintf(spdk_trace_shm_name, sizeof(spdk_trace_shm_name), "/iscsi_trace.%d", g_shm_id);
+ history_fd = shm_open(spdk_trace_shm_name, O_RDONLY, 0600);
+ if (history_fd < 0) {
+ fprintf(stderr, "Unable to open history shm %s\n", spdk_trace_shm_name);
+ usage();
+ exit(1);
+ }
+
+ history_ptr = mmap(NULL, sizeof(*histories), PROT_READ, MAP_SHARED, history_fd, 0);
+ if (history_ptr == MAP_FAILED) {
+ fprintf(stderr, "Unable to mmap history shm (%d).\n", errno);
+ exit(1);
+ }
+
+ histories = (struct spdk_trace_histories *)history_ptr;
+
+ memset(last_tasks_done, 0, sizeof(last_tasks_done));
+
+ for (i = 0; i < SPDK_TRACE_MAX_LCORE; i++) {
+ history = &histories->per_lcore_history[i];
+ last_tasks_done[i] = history->tpoint_count[TRACE_ISCSI_TASK_DONE];
+ }
+
+ delay = 1;
+ quit = 0;
+
+ tcgetattr(0, &oldt);
+ newt = oldt;
+ newt.c_lflag &= ~(ICANON);
+ tcsetattr(0, TCSANOW, &newt);
+
+ while (1) {
+
+ FD_ZERO(&fds);
+ FD_SET(0, &fds);
+ timeout.tv_sec = delay;
+ timeout.tv_usec = 0;
+ rc = select(2, &fds, NULL, NULL, &timeout);
+
+ if (rc > 0) {
+ if (read(0, &ch, 1) != 1) {
+ fprintf(stderr, "Read error on stdin\n");
+ goto cleanup;
+ }
+
+ printf("\b");
+ switch (ch) {
+ case 'd':
+ printf("Enter num seconds to delay (1-10): ");
+ old_delay = delay;
+ rc = scanf("%d", &delay);
+ if (rc != 1) {
+ fprintf(stderr, "Illegal delay value\n");
+ delay = old_delay;
+ } else if (delay < 1 || delay > 10) {
+ delay = 1;
+ }
+ break;
+ case 'q':
+ quit = 1;
+ break;
+ default:
+ fprintf(stderr, "'%c' not recognized\n", ch);
+ break;
+ }
+
+ if (quit == 1) {
+ break;
+ }
+ }
+
+ printf("\e[1;1H\e[2J");
+ print_connections();
+ printf("lcore tasks\n");
+ printf("=============\n");
+ total_tasks_done_per_sec = 0;
+ for (i = 0; i < SPDK_TRACE_MAX_LCORE; i++) {
+ history = &histories->per_lcore_history[i];
+ tasks_done = history->tpoint_count[TRACE_ISCSI_TASK_DONE];
+ tasks_done_delta = tasks_done - last_tasks_done[i];
+ if (tasks_done_delta == 0) {
+ continue;
+ }
+ last_tasks_done[i] = tasks_done;
+ tasks_done_per_sec = tasks_done_delta / delay;
+ printf("%5d %7d\n", history->lcore, tasks_done_per_sec);
+ total_tasks_done_per_sec += tasks_done_per_sec;
+ }
+ printf("Total %7d\n", total_tasks_done_per_sec);
+ }
+
+cleanup:
+ tcsetattr(0, TCSANOW, &oldt);
+
+ munmap(history_ptr, sizeof(*histories));
+ close(history_fd);
+
+ return (0);
+}
diff --git a/src/spdk/app/nvmf_tgt/.gitignore b/src/spdk/app/nvmf_tgt/.gitignore
new file mode 100644
index 00000000..e96d82be
--- /dev/null
+++ b/src/spdk/app/nvmf_tgt/.gitignore
@@ -0,0 +1 @@
+nvmf_tgt
diff --git a/src/spdk/app/nvmf_tgt/Makefile b/src/spdk/app/nvmf_tgt/Makefile
new file mode 100644
index 00000000..e93ed1bf
--- /dev/null
+++ b/src/spdk/app/nvmf_tgt/Makefile
@@ -0,0 +1,65 @@
+#
+# BSD LICENSE
+#
+# Copyright (c) Intel Corporation.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Intel Corporation nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
+include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
+include $(SPDK_ROOT_DIR)/mk/spdk.app.mk
+include $(SPDK_ROOT_DIR)/mk/spdk.modules.mk
+
+APP = nvmf_tgt
+
+C_SRCS := nvmf_main.c
+
+SPDK_LIB_LIST = event_bdev event_copy event_nvmf
+SPDK_LIB_LIST += nvmf event log trace conf thread util bdev copy rpc jsonrpc json
+SPDK_LIB_LIST += app_rpc log_rpc bdev_rpc
+
+ifeq ($(OS),Linux)
+SPDK_LIB_LIST += event_nbd nbd
+endif
+
+LIBS += $(BLOCKDEV_MODULES_LINKER_ARGS) \
+ $(COPY_MODULES_LINKER_ARGS) \
+ $(SOCK_MODULES_LINKER_ARGS) \
+ $(SPDK_LIB_LINKER_ARGS) $(ENV_LINKER_ARGS)
+
+all : $(APP)
+ @:
+
+$(APP) : $(OBJS) $(SPDK_LIB_FILES) $(SPDK_WHOLE_LIBS) $(BLOCKDEV_MODULES_FILES) $(COPY_MODULES_FILES) $(SOCK_MODULES_FILES) $(LINKER_MODULES) $(ENV_LIBS)
+ $(LINK_C)
+
+clean :
+ $(CLEAN_C) $(APP)
+
+include $(SPDK_ROOT_DIR)/mk/spdk.deps.mk
diff --git a/src/spdk/app/nvmf_tgt/nvmf_main.c b/src/spdk/app/nvmf_tgt/nvmf_main.c
new file mode 100644
index 00000000..b1536e49
--- /dev/null
+++ b/src/spdk/app/nvmf_tgt/nvmf_main.c
@@ -0,0 +1,78 @@
+/*-
+ * BSD LICENSE
+ *
+ * Copyright (c) Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "spdk/stdinc.h"
+
+#include "spdk/env.h"
+#include "spdk/event.h"
+
+static void
+nvmf_usage(void)
+{
+}
+
+static void
+nvmf_parse_arg(int ch, char *arg)
+{
+}
+
+static void
+nvmf_tgt_started(void *arg1, void *arg2)
+{
+ if (getenv("MEMZONE_DUMP") != NULL) {
+ spdk_memzone_dump(stdout);
+ fflush(stdout);
+ }
+}
+
+int
+main(int argc, char **argv)
+{
+ int rc;
+ struct spdk_app_opts opts = {};
+
+ /* default value in opts */
+ spdk_app_opts_init(&opts);
+ opts.name = "nvmf";
+ opts.max_delay_us = 1000; /* 1 ms */
+ if ((rc = spdk_app_parse_args(argc, argv, &opts, "", NULL,
+ nvmf_parse_arg, nvmf_usage)) !=
+ SPDK_APP_PARSE_ARGS_SUCCESS) {
+ exit(rc);
+ }
+
+ /* Blocks until the application is exiting */
+ rc = spdk_app_start(&opts, nvmf_tgt_started, NULL, NULL);
+ spdk_app_fini();
+ return rc;
+}
diff --git a/src/spdk/app/spdk_tgt/.gitignore b/src/spdk/app/spdk_tgt/.gitignore
new file mode 100644
index 00000000..0309c687
--- /dev/null
+++ b/src/spdk/app/spdk_tgt/.gitignore
@@ -0,0 +1 @@
+spdk_tgt
diff --git a/src/spdk/app/spdk_tgt/Makefile b/src/spdk/app/spdk_tgt/Makefile
new file mode 100644
index 00000000..ad7e03e3
--- /dev/null
+++ b/src/spdk/app/spdk_tgt/Makefile
@@ -0,0 +1,73 @@
+#
+# BSD LICENSE
+#
+# Copyright (c) Intel Corporation.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Intel Corporation nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
+include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
+include $(SPDK_ROOT_DIR)/mk/spdk.app.mk
+include $(SPDK_ROOT_DIR)/mk/spdk.modules.mk
+
+APP = spdk_tgt
+
+C_SRCS := spdk_tgt.c
+
+SPDK_LIB_LIST = event_bdev event_copy event_iscsi event_net event_scsi event_nvmf event
+SPDK_LIB_LIST += nvmf trace log conf thread util bdev iscsi scsi copy rpc jsonrpc json
+SPDK_LIB_LIST += app_rpc log_rpc bdev_rpc net
+
+ifeq ($(OS),Linux)
+SPDK_LIB_LIST += event_nbd nbd
+
+ifeq ($(CONFIG_VHOST),y)
+SPDK_LIB_LIST += vhost rte_vhost event_vhost
+endif
+
+endif
+
+LIBS += $(BLOCKDEV_MODULES_LINKER_ARGS) \
+ $(COPY_MODULES_LINKER_ARGS) \
+ $(SOCK_MODULES_LINKER_ARGS) \
+ $(SPDK_LIB_LINKER_ARGS) $(ENV_LINKER_ARGS)
+
+all: $(APP)
+ @:
+
+$(APP): $(OBJS) $(SPDK_LIB_FILES) $(SPDK_WHOLE_LIBS) $(BLOCKDEV_MODULES_FILES) $(COPY_MODULES_FILES) $(SOCK_MODULES_FILES) $(LINKER_MODULES) $(ENV_LIBS)
+ $(LINK_C)
+
+clean:
+ $(CLEAN_C) $(APP)
+
+install: $(APP)
+ $(INSTALL_APP)
+
+include $(SPDK_ROOT_DIR)/mk/spdk.deps.mk
diff --git a/src/spdk/app/spdk_tgt/spdk_tgt.c b/src/spdk/app/spdk_tgt/spdk_tgt.c
new file mode 100644
index 00000000..1c93f58a
--- /dev/null
+++ b/src/spdk/app/spdk_tgt/spdk_tgt.c
@@ -0,0 +1,126 @@
+/*-
+ * BSD LICENSE
+ *
+ * Copyright (c) Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "spdk/stdinc.h"
+
+#include "spdk/config.h"
+#include "spdk/env.h"
+#include "spdk/event.h"
+#include "spdk/vhost.h"
+
+/* TODO: this should be handled by configure */
+#if defined(SPDK_CONFIG_VHOST) && !defined(__linux__)
+#undef SPDK_CONFIG_VHOST
+#endif
+
+#ifdef SPDK_CONFIG_VHOST
+#define SPDK_VHOST_OPTS "S:"
+#else
+#define SPDK_VHOST_OPTS
+#endif
+
+static const char *g_pid_path = NULL;
+static const char g_spdk_tgt_get_opts_string[] = "f:" SPDK_VHOST_OPTS;
+
+static void
+spdk_tgt_usage(void)
+{
+ printf(" -f <file> pidfile save pid to file under given path\n");
+#ifdef SPDK_CONFIG_VHOST
+ printf(" -S <path> directory where to create vhost sockets (default: pwd)\n");
+#endif
+}
+
+static void
+spdk_tgt_save_pid(const char *pid_path)
+{
+ FILE *pid_file;
+
+ pid_file = fopen(pid_path, "w");
+ if (pid_file == NULL) {
+ fprintf(stderr, "Couldn't create pid file '%s': %s\n", pid_path, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ fprintf(pid_file, "%d\n", getpid());
+ fclose(pid_file);
+}
+
+
+static void
+spdk_tgt_parse_arg(int ch, char *arg)
+{
+ switch (ch) {
+ case 'f':
+ g_pid_path = arg;
+ break;
+#ifdef SPDK_CONFIG_VHOST
+ case 'S':
+ spdk_vhost_set_socket_path(arg);
+ break;
+#endif
+ }
+}
+
+static void
+spdk_tgt_started(void *arg1, void *arg2)
+{
+ if (g_pid_path) {
+ spdk_tgt_save_pid(g_pid_path);
+ }
+
+ if (getenv("MEMZONE_DUMP") != NULL) {
+ spdk_memzone_dump(stdout);
+ fflush(stdout);
+ }
+}
+
+int
+main(int argc, char **argv)
+{
+ struct spdk_app_opts opts = {};
+ int rc;
+
+ spdk_app_opts_init(&opts);
+ opts.name = "spdk_tgt";
+ if ((rc = spdk_app_parse_args(argc, argv, &opts, g_spdk_tgt_get_opts_string,
+ NULL, spdk_tgt_parse_arg, spdk_tgt_usage)) !=
+ SPDK_APP_PARSE_ARGS_SUCCESS) {
+ return rc;
+ }
+
+ rc = spdk_app_start(&opts, spdk_tgt_started, NULL, NULL);
+ spdk_app_fini();
+
+ return rc;
+}
diff --git a/src/spdk/app/trace/.gitignore b/src/spdk/app/trace/.gitignore
new file mode 100644
index 00000000..bbb611b8
--- /dev/null
+++ b/src/spdk/app/trace/.gitignore
@@ -0,0 +1 @@
+spdk_trace
diff --git a/src/spdk/app/trace/Makefile b/src/spdk/app/trace/Makefile
new file mode 100644
index 00000000..3d720d13
--- /dev/null
+++ b/src/spdk/app/trace/Makefile
@@ -0,0 +1,51 @@
+#
+# BSD LICENSE
+#
+# Copyright (c) Intel Corporation.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Intel Corporation nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
+include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
+include $(SPDK_ROOT_DIR)/mk/spdk.app.mk
+
+CXX_SRCS := trace.cpp
+
+APP = spdk_trace
+
+all: $(APP)
+ @:
+
+$(APP): $(OBJS) $(SPDK_LIBS)
+ $(LINK_CXX)
+
+clean:
+ $(CLEAN_C) $(APP)
+
+include $(SPDK_ROOT_DIR)/mk/spdk.deps.mk
diff --git a/src/spdk/app/trace/trace.cpp b/src/spdk/app/trace/trace.cpp
new file mode 100644
index 00000000..4c42c5ec
--- /dev/null
+++ b/src/spdk/app/trace/trace.cpp
@@ -0,0 +1,418 @@
+/*-
+ * BSD LICENSE
+ *
+ * Copyright (c) Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "spdk/stdinc.h"
+
+#include <map>
+
+extern "C" {
+#include "spdk/trace.h"
+#include "spdk/util.h"
+}
+
+static struct spdk_trace_histories *g_histories;
+
+static void usage(void);
+
+struct entry_key {
+ entry_key(uint16_t _lcore, uint64_t _tsc) : lcore(_lcore), tsc(_tsc) {}
+ uint16_t lcore;
+ uint64_t tsc;
+};
+
+class compare_entry_key
+{
+public:
+ bool operator()(const entry_key &first, const entry_key &second) const
+ {
+ if (first.tsc == second.tsc) {
+ return first.lcore < second.lcore;
+ } else {
+ return first.tsc < second.tsc;
+ }
+ }
+};
+
+typedef std::map<entry_key, spdk_trace_entry *, compare_entry_key> entry_map;
+
+entry_map g_entry_map;
+
+struct object_stats {
+
+ std::map<uint64_t, uint64_t> start;
+ std::map<uint64_t, uint64_t> index;
+ std::map<uint64_t, uint64_t> size;
+ std::map<uint64_t, uint64_t> tpoint_id;
+ uint64_t counter;
+
+ object_stats() : start(), index(), size(), tpoint_id(), counter(0) {}
+};
+
+struct object_stats g_stats[SPDK_TRACE_MAX_OBJECT];
+
+static char *g_exe_name;
+static int g_verbose = 1;
+
+static uint64_t g_tsc_rate;
+static uint64_t g_first_tsc = 0x0;
+
+static float
+get_us_from_tsc(uint64_t tsc, uint64_t tsc_rate)
+{
+ return ((float)tsc) * 1000 * 1000 / tsc_rate;
+}
+
+static void
+print_ptr(const char *arg_string, uint64_t arg)
+{
+ printf("%-7.7s0x%-14jx ", arg_string, arg);
+}
+
+static void
+print_uint64(const char *arg_string, uint64_t arg)
+{
+ /*
+ * Print arg as signed, since -1 is a common value especially
+ * for FLUSH WRITEBUF when writev() returns -1 due to full
+ * socket buffer.
+ */
+ printf("%-7.7s%-16jd ", arg_string, arg);
+}
+
+static void
+print_size(uint32_t size)
+{
+ if (size > 0) {
+ printf("size: %6u ", size);
+ } else {
+ printf("%13s", " ");
+ }
+}
+
+static void
+print_object_id(uint8_t type, uint64_t id)
+{
+ printf("id: %c%-15jd ", g_histories->flags.object[type].id_prefix, id);
+}
+
+static void
+print_float(const char *arg_string, float arg)
+{
+ printf("%-7s%-16.3f ", arg_string, arg);
+}
+
+static void
+print_arg(bool arg_is_ptr, const char *arg_string, uint64_t arg)
+{
+ if (arg_string[0] == 0) {
+ printf("%24s", "");
+ return;
+ }
+
+ if (arg_is_ptr) {
+ print_ptr(arg_string, arg);
+ } else {
+ print_uint64(arg_string, arg);
+ }
+}
+
+static void
+print_event(struct spdk_trace_entry *e, uint64_t tsc_rate,
+ uint64_t tsc_offset, uint16_t lcore)
+{
+ struct spdk_trace_tpoint *d;
+ struct object_stats *stats;
+ float us;
+
+ d = &g_histories->flags.tpoint[e->tpoint_id];
+ stats = &g_stats[d->object_type];
+
+ if (d->new_object) {
+ stats->index[e->object_id] = stats->counter++;
+ stats->tpoint_id[e->object_id] = e->tpoint_id;
+ stats->start[e->object_id] = e->tsc;
+ stats->size[e->object_id] = e->size;
+ }
+
+ us = get_us_from_tsc(e->tsc - tsc_offset, tsc_rate);
+
+ printf("%2d: %10.3f (%9ju) ", lcore, us, e->tsc - tsc_offset);
+ if (g_histories->flags.owner[d->owner_type].id_prefix) {
+ printf("%c%02d ", g_histories->flags.owner[d->owner_type].id_prefix, e->poller_id);
+ } else {
+ printf("%4s", " ");
+ }
+
+ printf("%-*s ", (int)sizeof(d->name), d->name);
+ print_size(e->size);
+
+ print_arg(d->arg1_is_ptr, d->arg1_name, e->arg1);
+ if (d->new_object) {
+ print_object_id(d->object_type, stats->index[e->object_id]);
+ } else if (d->object_type != OBJECT_NONE) {
+ if (stats->start.find(e->object_id) != stats->start.end()) {
+ struct spdk_trace_tpoint *start_description;
+
+ us = get_us_from_tsc(e->tsc - stats->start[e->object_id],
+ tsc_rate);
+ print_object_id(d->object_type, stats->index[e->object_id]);
+ print_float("time:", us);
+ start_description = &g_histories->flags.tpoint[stats->tpoint_id[e->object_id]];
+ if (start_description->short_name[0] != 0) {
+ printf(" (%.4s)", start_description->short_name);
+ }
+ } else {
+ printf("id: N/A");
+ }
+ } else if (e->object_id != 0) {
+ print_arg(true, "object: ", e->object_id);
+ }
+ printf("\n");
+}
+
+static void
+process_event(struct spdk_trace_entry *e, uint64_t tsc_rate,
+ uint64_t tsc_offset, uint16_t lcore)
+{
+ if (g_verbose) {
+ print_event(e, tsc_rate, tsc_offset, lcore);
+ }
+}
+
+static int
+populate_events(struct spdk_trace_history *history)
+{
+ int i, num_entries, num_entries_filled;
+ struct spdk_trace_entry *e;
+ int first, last, lcore;
+
+ lcore = history->lcore;
+
+ num_entries = SPDK_COUNTOF(history->entries);
+
+ e = history->entries;
+
+ num_entries_filled = num_entries;
+ while (e[num_entries_filled - 1].tsc == 0) {
+ num_entries_filled--;
+ }
+
+ if (num_entries == num_entries_filled) {
+ first = last = 0;
+ for (i = 1; i < num_entries; i++) {
+ if (e[i].tsc < e[first].tsc) {
+ first = i;
+ }
+ if (e[i].tsc > e[last].tsc) {
+ last = i;
+ }
+ }
+ } else {
+ first = 0;
+ last = num_entries_filled - 1;
+ }
+
+ /*
+ * We keep track of the highest first TSC out of all reactors.
+ * We will ignore any events that occured before this TSC on any
+ * other reactors. This will ensure we only print data for the
+ * subset of time where we have data across all reactors.
+ */
+ if (e[first].tsc > g_first_tsc) {
+ g_first_tsc = e[first].tsc;
+ }
+
+ i = first;
+ while (1) {
+ g_entry_map[entry_key(lcore, e[i].tsc)] = &e[i];
+ if (i == last) {
+ break;
+ }
+ i++;
+ if (i == num_entries_filled) {
+ i = 0;
+ }
+ }
+
+ return (0);
+}
+
+static void usage(void)
+{
+ fprintf(stderr, "usage:\n");
+ fprintf(stderr, " %s <option> <lcore#>\n", g_exe_name);
+ fprintf(stderr, " option = '-q' to disable verbose mode\n");
+ fprintf(stderr, " '-c' to display single lcore history\n");
+ fprintf(stderr, " '-s' to specify spdk_trace shm name for a\n");
+ fprintf(stderr, " currently running process\n");
+ fprintf(stderr, " '-i' to specify the shared memory ID\n");
+ fprintf(stderr, " '-p' to specify the trace PID\n");
+ fprintf(stderr, " (If -s is specified, then one of\n");
+ fprintf(stderr, " -i or -p must be specified)\n");
+ fprintf(stderr, " '-f' to specify a tracepoint file name\n");
+ fprintf(stderr, " (-s and -f are mutually exclusive)\n");
+}
+
+int main(int argc, char **argv)
+{
+ void *history_ptr;
+ struct spdk_trace_history *history_entries, *history;
+ int fd, i;
+ int lcore = SPDK_TRACE_MAX_LCORE;
+ uint64_t tsc_offset;
+ const char *app_name = NULL;
+ const char *file_name = NULL;
+ int op;
+ char shm_name[64];
+ int shm_id = -1, shm_pid = -1;
+
+ g_exe_name = argv[0];
+ while ((op = getopt(argc, argv, "c:f:i:p:qs:")) != -1) {
+ switch (op) {
+ case 'c':
+ lcore = atoi(optarg);
+ if (lcore > SPDK_TRACE_MAX_LCORE) {
+ fprintf(stderr, "Selected lcore: %d "
+ "exceeds maximum %d\n", lcore,
+ SPDK_TRACE_MAX_LCORE);
+ exit(1);
+ }
+ break;
+ case 'i':
+ shm_id = atoi(optarg);
+ break;
+ case 'p':
+ shm_pid = atoi(optarg);
+ break;
+ case 'q':
+ g_verbose = 0;
+ break;
+ case 's':
+ app_name = optarg;
+ break;
+ case 'f':
+ file_name = optarg;
+ break;
+ default:
+ usage();
+ exit(1);
+ }
+ }
+
+ if (file_name != NULL && app_name != NULL) {
+ fprintf(stderr, "-f and -s are mutually exclusive\n");
+ usage();
+ exit(1);
+ }
+
+ if (file_name == NULL && app_name == NULL) {
+ fprintf(stderr, "One of -f and -s must be specified\n");
+ usage();
+ exit(1);
+ }
+
+ if (shm_id >= 0) {
+ snprintf(shm_name, sizeof(shm_name), "/%s_trace.%d", app_name, shm_id);
+ } else {
+ snprintf(shm_name, sizeof(shm_name), "/%s_trace.pid%d", app_name, shm_pid);
+ }
+
+ if (file_name) {
+ fd = open(file_name, O_RDONLY);
+ } else {
+ fd = shm_open(shm_name, O_RDONLY, 0600);
+ }
+ if (fd < 0) {
+ fprintf(stderr, "Could not open %s.\n", file_name ? file_name : shm_name);
+ usage();
+ exit(-1);
+ }
+
+ history_ptr = mmap(NULL, sizeof(*g_histories), PROT_READ, MAP_SHARED, fd, 0);
+ if (history_ptr == MAP_FAILED) {
+ fprintf(stderr, "Could not mmap shm %s.\n", shm_name);
+ usage();
+ exit(-1);
+ }
+
+ g_histories = (struct spdk_trace_histories *)history_ptr;
+
+ g_tsc_rate = g_histories->flags.tsc_rate;
+ if (g_tsc_rate == 0) {
+ fprintf(stderr, "Invalid tsc_rate %ju\n", g_tsc_rate);
+ usage();
+ exit(-1);
+ }
+
+ if (g_verbose) {
+ printf("TSC Rate: %ju\n", g_tsc_rate);
+ }
+
+ history_entries = (struct spdk_trace_history *)malloc(sizeof(g_histories->per_lcore_history));
+ if (history_entries == NULL) {
+ goto cleanup;
+ }
+ memcpy(history_entries, g_histories->per_lcore_history,
+ sizeof(g_histories->per_lcore_history));
+
+ if (lcore == SPDK_TRACE_MAX_LCORE) {
+ for (i = 0; i < SPDK_TRACE_MAX_LCORE; i++) {
+ history = &history_entries[i];
+ if (history->entries[0].tsc == 0) {
+ continue;
+ }
+ populate_events(history);
+ }
+ } else {
+ history = &history_entries[lcore];
+ if (history->entries[0].tsc != 0) {
+ populate_events(history);
+ }
+ }
+
+ tsc_offset = g_first_tsc;
+ for (entry_map::iterator it = g_entry_map.begin(); it != g_entry_map.end(); it++) {
+ if (it->first.tsc < g_first_tsc) {
+ continue;
+ }
+ process_event(it->second, g_tsc_rate, tsc_offset, it->first.lcore);
+ }
+
+ free(history_entries);
+
+cleanup:
+ munmap(history_ptr, sizeof(*g_histories));
+ close(fd);
+
+ return (0);
+}
diff --git a/src/spdk/app/vhost/.gitignore b/src/spdk/app/vhost/.gitignore
new file mode 100644
index 00000000..5746bdd3
--- /dev/null
+++ b/src/spdk/app/vhost/.gitignore
@@ -0,0 +1 @@
+vhost
diff --git a/src/spdk/app/vhost/Makefile b/src/spdk/app/vhost/Makefile
new file mode 100644
index 00000000..ef75e5e3
--- /dev/null
+++ b/src/spdk/app/vhost/Makefile
@@ -0,0 +1,63 @@
+#
+# BSD LICENSE
+#
+# Copyright (c) Intel Corporation.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Intel Corporation nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
+include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
+include $(SPDK_ROOT_DIR)/mk/spdk.app.mk
+include $(SPDK_ROOT_DIR)/mk/spdk.modules.mk
+
+APP = vhost
+
+C_SRCS := vhost.c
+
+SPDK_LIB_LIST = event_bdev event_copy event_net event_scsi event_vhost event
+SPDK_LIB_LIST += jsonrpc json rpc bdev_rpc bdev scsi copy trace conf
+SPDK_LIB_LIST += thread util log log_rpc app_rpc
+SPDK_LIB_LIST += vhost rte_vhost event_nbd nbd net
+
+LIBS += $(BLOCKDEV_MODULES_LINKER_ARGS) \
+ $(COPY_MODULES_LINKER_ARGS) \
+ $(SOCK_MODULES_LINKER_ARGS)
+LIBS += $(SPDK_LIB_LINKER_ARGS)
+LIBS += $(ENV_LINKER_ARGS)
+
+all : $(APP)
+ @:
+
+$(APP) : $(OBJS) $(SPDK_LIB_FILES) $(ENV_LIBS) $(BLOCKDEV_MODULES_FILES) $(COPY_MODULES_FILES) $(SOCK_MODULES_FILES)
+ $(LINK_C)
+
+clean :
+ $(CLEAN_C) $(APP)
+
+include $(SPDK_ROOT_DIR)/mk/spdk.deps.mk
diff --git a/src/spdk/app/vhost/vhost.c b/src/spdk/app/vhost/vhost.c
new file mode 100644
index 00000000..da58e34b
--- /dev/null
+++ b/src/spdk/app/vhost/vhost.c
@@ -0,0 +1,118 @@
+/*-
+ * BSD LICENSE
+ *
+ * Copyright (c) Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "spdk/stdinc.h"
+
+#include "spdk/conf.h"
+#include "spdk/event.h"
+
+#include "spdk/vhost.h"
+
+
+#define SPDK_VHOST_DEFAULT_MEM_SIZE 1024
+
+static const char *g_pid_path = NULL;
+
+static void
+vhost_app_opts_init(struct spdk_app_opts *opts)
+{
+ spdk_app_opts_init(opts);
+ opts->name = "vhost";
+ opts->mem_size = SPDK_VHOST_DEFAULT_MEM_SIZE;
+}
+
+static void
+vhost_usage(void)
+{
+ printf(" -f <path> save pid to file under given path\n");
+ printf(" -S <path> directory where to create vhost sockets (default: pwd)\n");
+}
+
+static void
+save_pid(const char *pid_path)
+{
+ FILE *pid_file;
+
+ pid_file = fopen(pid_path, "w");
+ if (pid_file == NULL) {
+ fprintf(stderr, "Couldn't create pid file '%s': %s\n", pid_path, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ fprintf(pid_file, "%d\n", getpid());
+ fclose(pid_file);
+}
+
+static void
+vhost_parse_arg(int ch, char *arg)
+{
+ switch (ch) {
+ case 'f':
+ g_pid_path = arg;
+ break;
+ case 'S':
+ spdk_vhost_set_socket_path(arg);
+ break;
+ }
+}
+
+static void
+vhost_started(void *arg1, void *arg2)
+{
+}
+
+int
+main(int argc, char *argv[])
+{
+ struct spdk_app_opts opts = {};
+ int rc;
+
+ vhost_app_opts_init(&opts);
+
+ if ((rc = spdk_app_parse_args(argc, argv, &opts, "f:S:", NULL,
+ vhost_parse_arg, vhost_usage)) !=
+ SPDK_APP_PARSE_ARGS_SUCCESS) {
+ exit(rc);
+ }
+
+ if (g_pid_path) {
+ save_pid(g_pid_path);
+ }
+
+ /* Blocks until the application is exiting */
+ rc = spdk_app_start(&opts, vhost_started, NULL, NULL);
+
+ spdk_app_fini();
+
+ return rc;
+}