diff options
Diffstat (limited to 'src/spdk/test/event')
-rw-r--r-- | src/spdk/test/event/Makefile | 48 | ||||
-rw-r--r-- | src/spdk/test/event/app_repeat/.gitignore | 1 | ||||
-rw-r--r-- | src/spdk/test/event/app_repeat/Makefile | 54 | ||||
-rw-r--r-- | src/spdk/test/event/app_repeat/app_repeat.c | 115 | ||||
-rwxr-xr-x | src/spdk/test/event/event.sh | 44 | ||||
-rw-r--r-- | src/spdk/test/event/event_perf/.gitignore | 1 | ||||
-rw-r--r-- | src/spdk/test/event/event_perf/Makefile | 42 | ||||
-rw-r--r-- | src/spdk/test/event/event_perf/event_perf.c | 184 | ||||
-rw-r--r-- | src/spdk/test/event/reactor/.gitignore | 1 | ||||
-rw-r--r-- | src/spdk/test/event/reactor/Makefile | 42 | ||||
-rw-r--r-- | src/spdk/test/event/reactor/reactor.c | 144 | ||||
-rw-r--r-- | src/spdk/test/event/reactor_perf/.gitignore | 1 | ||||
-rw-r--r-- | src/spdk/test/event/reactor_perf/Makefile | 42 | ||||
-rw-r--r-- | src/spdk/test/event/reactor_perf/reactor_perf.c | 151 |
14 files changed, 870 insertions, 0 deletions
diff --git a/src/spdk/test/event/Makefile b/src/spdk/test/event/Makefile new file mode 100644 index 000000000..4b9cab867 --- /dev/null +++ b/src/spdk/test/event/Makefile @@ -0,0 +1,48 @@ +# +# 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 = event_perf reactor reactor_perf + +ifeq ($(OS),Linux) +DIRS-y += app_repeat +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/test/event/app_repeat/.gitignore b/src/spdk/test/event/app_repeat/.gitignore new file mode 100644 index 000000000..0e59ff47d --- /dev/null +++ b/src/spdk/test/event/app_repeat/.gitignore @@ -0,0 +1 @@ +app_repeat diff --git a/src/spdk/test/event/app_repeat/Makefile b/src/spdk/test/event/app_repeat/Makefile new file mode 100644 index 000000000..eb5140b1c --- /dev/null +++ b/src/spdk/test/event/app_repeat/Makefile @@ -0,0 +1,54 @@ +# +# 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.modules.mk + +APP = app_repeat +C_SRCS := app_repeat.c + +# Some of the modules and libaries are not repeatable yet, only organize +# the repeatable ones. +SPDK_LIB_LIST = event_bdev event_accel event_vmd event_sock +SPDK_LIB_LIST += event log trace conf thread util bdev accel rpc jsonrpc json sock vmd +SPDK_LIB_LIST += app_rpc log_rpc bdev_rpc notify +SPDK_LIB_LIST += event_nbd nbd + +BLOCKDEV_LIST = bdev_malloc bdev_null +BLOCKDEV_LIST += bdev_aio +SYS_LIBS += -laio + +SPDK_LIB_LIST += $(BLOCKDEV_LIST) + +include $(SPDK_ROOT_DIR)/mk/spdk.app.mk diff --git a/src/spdk/test/event/app_repeat/app_repeat.c b/src/spdk/test/event/app_repeat/app_repeat.c new file mode 100644 index 000000000..d83e7949c --- /dev/null +++ b/src/spdk/test/event/app_repeat/app_repeat.c @@ -0,0 +1,115 @@ +/*- + * 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/event.h" +#include "spdk/string.h" +#include "spdk/thread.h" + +struct spdk_app_opts g_opts = {}; +static const char g_app_repeat_get_opts_string[] = "t:"; +static int g_repeat_times = 2; +static bool g_exit; + +static void +app_repeat_usage(void) +{ + printf(" -t <num> number of times to repeat calling spdk_app_start/stop\n"); +} + +static int +app_repeat_parse_arg(int ch, char *arg) +{ + switch (ch) { + case 't': + g_repeat_times = spdk_strtol(arg, 0); + if (g_repeat_times < 2) { + return -EINVAL; + } + break; + default: + return -EINVAL; + } + return 0; +} + +static void +app_repeat_started(void *arg1) +{ + int index = *(int *)arg1; + + printf("spdk_app_start is called in Round %d.\n", index); +} + +static void _app_repeat_shutdown_cb(void) +{ + printf("Shutdown signal received, exit.\n"); + g_exit = true; + spdk_app_stop(0); +} + +static void _app_repeat_usr1_handler(int signal) +{ + printf("USR1 signal received, restart spdk application framework.\n"); + spdk_app_stop(0); +} + +int +main(int argc, char **argv) +{ + int rc; + int i; + + spdk_app_opts_init(&g_opts); + g_opts.name = "app_repeat"; + g_opts.shutdown_cb = _app_repeat_shutdown_cb; + g_opts.usr1_handler = _app_repeat_usr1_handler; + if ((rc = spdk_app_parse_args(argc, argv, &g_opts, g_app_repeat_get_opts_string, + NULL, app_repeat_parse_arg, app_repeat_usage)) != + SPDK_APP_PARSE_ARGS_SUCCESS) { + return rc; + } + + for (i = 0; i < g_repeat_times; i++) { + rc = spdk_app_start(&g_opts, app_repeat_started, &i); + spdk_app_fini(); + + if (rc) { + fprintf(stderr, "Failed to call spdk_app_start in Round %d.\n", i); + break; + } + } + + return rc; +} diff --git a/src/spdk/test/event/event.sh b/src/spdk/test/event/event.sh new file mode 100755 index 000000000..d198cd116 --- /dev/null +++ b/src/spdk/test/event/event.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash + +testdir=$(readlink -f $(dirname $0)) +rootdir=$(readlink -f $testdir/../..) +source $rootdir/test/common/autotest_common.sh +source $rootdir/test/bdev/nbd_common.sh + +function app_repeat_test() { + local rpc_server=/var/tmp/spdk-nbd.sock + local nbd_list=("/dev/nbd0" "/dev/nbd1") + local bdev_list=("Malloc0" "Malloc1") + local repeat_times=4 + + modprobe nbd + $rootdir/test/event/app_repeat/app_repeat -r $rpc_server -m 0x3 -t $repeat_times & + repeat_pid=$! + trap 'killprocess $repeat_pid; exit 1' SIGINT SIGTERM EXIT + echo "Process app_repeat pid: $repeat_pid" + + for i in {0..2}; do + echo "spdk_app_start Round $i" + waitforlisten $repeat_pid $rpc_server + + $rootdir/scripts/rpc.py -s $rpc_server bdev_malloc_create 64 4096 + $rootdir/scripts/rpc.py -s $rpc_server bdev_malloc_create 64 4096 + + nbd_rpc_data_verify $rpc_server "${bdev_list[*]}" "${nbd_list[*]}" + ./scripts/rpc.py -s $rpc_server spdk_kill_instance SIGUSR1 + done + + waitforlisten $repeat_pid $rpc_server + killprocess $repeat_pid + trap - SIGINT SIGTERM EXIT + + return 0 +} + +run_test "event_perf" $testdir/event_perf/event_perf -m 0xF -t 1 +run_test "event_reactor" $testdir/reactor/reactor -t 1 +run_test "event_reactor_perf" $testdir/reactor_perf/reactor_perf -t 1 + +if [ $(uname -s) = Linux ] && modprobe -n nbd; then + run_test "app_repeat" app_repeat_test +fi diff --git a/src/spdk/test/event/event_perf/.gitignore b/src/spdk/test/event/event_perf/.gitignore new file mode 100644 index 000000000..2bdb558da --- /dev/null +++ b/src/spdk/test/event/event_perf/.gitignore @@ -0,0 +1 @@ +event_perf diff --git a/src/spdk/test/event/event_perf/Makefile b/src/spdk/test/event/event_perf/Makefile new file mode 100644 index 000000000..464709396 --- /dev/null +++ b/src/spdk/test/event/event_perf/Makefile @@ -0,0 +1,42 @@ +# +# 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 + +APP = event_perf +C_SRCS := event_perf.c + +SPDK_LIB_LIST = event trace conf thread util log rpc jsonrpc json sock notify + +include $(SPDK_ROOT_DIR)/mk/spdk.app.mk diff --git a/src/spdk/test/event/event_perf/event_perf.c b/src/spdk/test/event/event_perf/event_perf.c new file mode 100644 index 000000000..fe44e604d --- /dev/null +++ b/src/spdk/test/event/event_perf/event_perf.c @@ -0,0 +1,184 @@ +/*- + * 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 "spdk_internal/event.h" +#include "spdk/log.h" +#include "spdk/string.h" + +static uint64_t g_tsc_rate; +static uint64_t g_tsc_us_rate; +static uint64_t g_tsc_end; + +static int g_time_in_sec; + +static uint64_t *call_count; + +static bool g_app_stopped = false; + +static void +submit_new_event(void *arg1, void *arg2) +{ + struct spdk_event *event; + static __thread uint32_t next_lcore = UINT32_MAX; + + if (spdk_get_ticks() > g_tsc_end) { + if (__sync_bool_compare_and_swap(&g_app_stopped, false, true)) { + spdk_app_stop(0); + } + return; + } + + if (next_lcore == UINT32_MAX) { + next_lcore = spdk_env_get_next_core(spdk_env_get_current_core()); + if (next_lcore == UINT32_MAX) { + next_lcore = spdk_env_get_first_core(); + } + } + + call_count[next_lcore]++; + event = spdk_event_allocate(next_lcore, submit_new_event, NULL, NULL); + spdk_event_call(event); +} + +static void +event_work_fn(void *arg1, void *arg2) +{ + + submit_new_event(NULL, NULL); + submit_new_event(NULL, NULL); + submit_new_event(NULL, NULL); + submit_new_event(NULL, NULL); +} + +static void +event_perf_start(void *arg1) +{ + uint32_t i; + + call_count = calloc(spdk_env_get_last_core() + 1, sizeof(*call_count)); + if (call_count == NULL) { + fprintf(stderr, "call_count allocation failed\n"); + spdk_app_stop(1); + return; + } + + g_tsc_rate = spdk_get_ticks_hz(); + g_tsc_us_rate = g_tsc_rate / (1000 * 1000); + g_tsc_end = spdk_get_ticks() + g_time_in_sec * g_tsc_rate; + + printf("Running I/O for %d seconds...", g_time_in_sec); + fflush(stdout); + + SPDK_ENV_FOREACH_CORE(i) { + spdk_event_call(spdk_event_allocate(i, event_work_fn, + NULL, NULL)); + } + +} + +static void +usage(char *program_name) +{ + printf("%s options\n", program_name); + printf("\t[-m core mask for distributing I/O submission/completion work\n"); + printf("\t\t(default: 0x1 - use core 0 only)]\n"); + printf("\t[-t time in seconds]\n"); +} + +static void +performance_dump(int io_time) +{ + uint32_t i; + + if (call_count == NULL) { + return; + } + + printf("\n"); + SPDK_ENV_FOREACH_CORE(i) { + printf("lcore %2d: %8ju\n", i, call_count[i] / g_time_in_sec); + } + + fflush(stdout); + free(call_count); +} + +int +main(int argc, char **argv) +{ + struct spdk_app_opts opts = {}; + int op; + int rc = 0; + + opts.name = "event_perf"; + + g_time_in_sec = 0; + + while ((op = getopt(argc, argv, "m:t:")) != -1) { + switch (op) { + case 'm': + opts.reactor_mask = optarg; + break; + case 't': + g_time_in_sec = spdk_strtol(optarg, 10); + if (g_time_in_sec < 0) { + fprintf(stderr, "Invalid run time\n"); + return g_time_in_sec; + } + break; + default: + usage(argv[0]); + exit(1); + } + } + + if (!g_time_in_sec) { + usage(argv[0]); + exit(1); + } + + printf("Running I/O for %d seconds...", g_time_in_sec); + fflush(stdout); + + rc = spdk_app_start(&opts, event_perf_start, NULL); + + spdk_app_fini(); + performance_dump(g_time_in_sec); + + printf("done.\n"); + return rc; +} diff --git a/src/spdk/test/event/reactor/.gitignore b/src/spdk/test/event/reactor/.gitignore new file mode 100644 index 000000000..194b15d77 --- /dev/null +++ b/src/spdk/test/event/reactor/.gitignore @@ -0,0 +1 @@ +reactor diff --git a/src/spdk/test/event/reactor/Makefile b/src/spdk/test/event/reactor/Makefile new file mode 100644 index 000000000..b5d94dcb1 --- /dev/null +++ b/src/spdk/test/event/reactor/Makefile @@ -0,0 +1,42 @@ +# +# 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 + +APP = reactor +C_SRCS := reactor.c + +SPDK_LIB_LIST = event trace conf thread util log rpc jsonrpc json sock notify + +include $(SPDK_ROOT_DIR)/mk/spdk.app.mk diff --git a/src/spdk/test/event/reactor/reactor.c b/src/spdk/test/event/reactor/reactor.c new file mode 100644 index 000000000..f78f16570 --- /dev/null +++ b/src/spdk/test/event/reactor/reactor.c @@ -0,0 +1,144 @@ +/*- + * 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/event.h" +#include "spdk/string.h" +#include "spdk/thread.h" + +static int g_time_in_sec; +static struct spdk_poller *test_end_poller; +static struct spdk_poller *poller_100ms; +static struct spdk_poller *poller_250ms; +static struct spdk_poller *poller_500ms; +static struct spdk_poller *poller_oneshot; +static struct spdk_poller *poller_unregister; + +static int +test_end(void *arg) +{ + printf("test_end\n"); + + spdk_poller_unregister(&test_end_poller); + spdk_poller_unregister(&poller_100ms); + spdk_poller_unregister(&poller_250ms); + spdk_poller_unregister(&poller_500ms); + + spdk_app_stop(0); + return -1; +} + +static int +tick(void *arg) +{ + uintptr_t period = (uintptr_t)arg; + + printf("tick %" PRIu64 "\n", (uint64_t)period); + + return -1; +} + +static int +oneshot(void *arg) +{ + printf("oneshot\n"); + spdk_poller_unregister(&poller_oneshot); + + return -1; +} + +static int +nop(void *arg) +{ + return -1; +} + +static void +test_start(void *arg1) +{ + printf("test_start\n"); + + /* Register a poller that will stop the test after the time has elapsed. */ + test_end_poller = SPDK_POLLER_REGISTER(test_end, NULL, g_time_in_sec * 1000000ULL); + + poller_100ms = SPDK_POLLER_REGISTER(tick, (void *)100, 100000); + poller_250ms = SPDK_POLLER_REGISTER(tick, (void *)250, 250000); + poller_500ms = SPDK_POLLER_REGISTER(tick, (void *)500, 500000); + poller_oneshot = SPDK_POLLER_REGISTER(oneshot, NULL, 0); + + poller_unregister = SPDK_POLLER_REGISTER(nop, NULL, 0); + spdk_poller_unregister(&poller_unregister); +} + +static void +usage(const char *program_name) +{ + printf("%s options\n", program_name); + printf("\t[-t time in seconds]\n"); +} + +int +main(int argc, char **argv) +{ + struct spdk_app_opts opts; + int op; + int rc = 0; + + spdk_app_opts_init(&opts); + opts.name = "reactor"; + + g_time_in_sec = 0; + + while ((op = getopt(argc, argv, "t:")) != -1) { + switch (op) { + case 't': + g_time_in_sec = spdk_strtol(optarg, 10); + break; + default: + usage(argv[0]); + exit(1); + } + } + + if (g_time_in_sec <= 0) { + usage(argv[0]); + exit(1); + } + + rc = spdk_app_start(&opts, test_start, NULL); + + spdk_app_fini(); + + return rc; +} diff --git a/src/spdk/test/event/reactor_perf/.gitignore b/src/spdk/test/event/reactor_perf/.gitignore new file mode 100644 index 000000000..32160228f --- /dev/null +++ b/src/spdk/test/event/reactor_perf/.gitignore @@ -0,0 +1 @@ +reactor_perf diff --git a/src/spdk/test/event/reactor_perf/Makefile b/src/spdk/test/event/reactor_perf/Makefile new file mode 100644 index 000000000..74b56dcf8 --- /dev/null +++ b/src/spdk/test/event/reactor_perf/Makefile @@ -0,0 +1,42 @@ +# +# 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 + +APP = reactor_perf +C_SRCS := reactor_perf.c + +SPDK_LIB_LIST = event trace conf thread util log rpc jsonrpc json sock notify + +include $(SPDK_ROOT_DIR)/mk/spdk.app.mk diff --git a/src/spdk/test/event/reactor_perf/reactor_perf.c b/src/spdk/test/event/reactor_perf/reactor_perf.c new file mode 100644 index 000000000..ceac595f2 --- /dev/null +++ b/src/spdk/test/event/reactor_perf/reactor_perf.c @@ -0,0 +1,151 @@ +/*- + * 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 "spdk/string.h" +#include "spdk/thread.h" + +static int g_time_in_sec; +static int g_queue_depth; +static struct spdk_poller *g_test_end_poller; +static uint64_t g_call_count = 0; + +static int +__test_end(void *arg) +{ + printf("test_end\n"); + spdk_poller_unregister(&g_test_end_poller); + spdk_app_stop(0); + return -1; +} + +static void +__submit_next(void *arg1, void *arg2) +{ + struct spdk_event *event; + + g_call_count++; + + event = spdk_event_allocate(spdk_env_get_current_core(), + __submit_next, NULL, NULL); + spdk_event_call(event); +} + +static void +test_start(void *arg1) +{ + int i; + + printf("test_start\n"); + + /* Register a poller that will stop the test after the time has elapsed. */ + g_test_end_poller = SPDK_POLLER_REGISTER(__test_end, NULL, + g_time_in_sec * 1000000ULL); + + for (i = 0; i < g_queue_depth; i++) { + __submit_next(NULL, NULL); + } +} + +static void +test_cleanup(void) +{ + printf("test_abort\n"); + + spdk_poller_unregister(&g_test_end_poller); + spdk_app_stop(0); +} + +static void +usage(const char *program_name) +{ + printf("%s options\n", program_name); + printf("\t[-q Queue depth (default: 1)]\n"); + printf("\t[-t time in seconds]\n"); +} + +int +main(int argc, char **argv) +{ + struct spdk_app_opts opts; + int op; + int rc; + long int val; + + spdk_app_opts_init(&opts); + opts.name = "reactor_perf"; + + g_time_in_sec = 0; + g_queue_depth = 1; + + while ((op = getopt(argc, argv, "q:t:")) != -1) { + if (op == '?') { + usage(argv[0]); + exit(1); + } + val = spdk_strtol(optarg, 10); + if (val < 0) { + fprintf(stderr, "Converting a string to integer failed\n"); + exit(1); + } + switch (op) { + case 'q': + g_queue_depth = val; + break; + case 't': + g_time_in_sec = val; + break; + default: + usage(argv[0]); + exit(1); + } + } + + if (!g_time_in_sec) { + usage(argv[0]); + exit(1); + } + + opts.shutdown_cb = test_cleanup; + + rc = spdk_app_start(&opts, test_start, NULL); + + spdk_app_fini(); + + printf("Performance: %8ju events per second\n", g_call_count / g_time_in_sec); + + return rc; +} |