diff --git a/app/iscsi_tgt/iscsi_tgt.c b/app/iscsi_tgt/iscsi_tgt.c index 1a8a662f4..69827d6ab 100644 --- a/app/iscsi_tgt/iscsi_tgt.c +++ b/app/iscsi_tgt/iscsi_tgt.c @@ -177,12 +177,11 @@ main(int argc, char **argv) opts.shutdown_cb = spdk_iscsi_shutdown; opts.usr1_handler = spdk_sigusr1; - spdk_app_init(&opts); printf("Total cores available: %u\n", spdk_env_get_core_count()); printf("Using net framework %s\n", spdk_net_framework_get_name()); /* Blocks until the application is exiting */ - app_rc = spdk_app_start(spdk_startup, NULL, NULL); + app_rc = spdk_app_start(&opts, spdk_startup, NULL, NULL); rc = spdk_app_fini(); diff --git a/app/nvmf_tgt/nvmf_tgt.c b/app/nvmf_tgt/nvmf_tgt.c index 9778cba4d..7a299ab38 100644 --- a/app/nvmf_tgt/nvmf_tgt.c +++ b/app/nvmf_tgt/nvmf_tgt.c @@ -307,11 +307,10 @@ spdk_nvmf_tgt_start(struct spdk_app_opts *opts) int rc; opts->shutdown_cb = spdk_nvmf_shutdown_cb; - spdk_app_init(opts); printf("Total cores available: %d\n", spdk_env_get_core_count()); /* Blocks until the application is exiting */ - rc = spdk_app_start(spdk_nvmf_startup, NULL, NULL); + rc = spdk_app_start(opts, spdk_nvmf_startup, NULL, NULL); spdk_app_fini(); diff --git a/app/vhost/vhost.c b/app/vhost/vhost.c index 542c4e51c..ad3fb1442 100644 --- a/app/vhost/vhost.c +++ b/app/vhost/vhost.c @@ -150,10 +150,9 @@ main(int argc, char *argv[]) } opts.shutdown_cb = spdk_vhost_shutdown_cb; - spdk_app_init(&opts); /* Blocks until the application is exiting */ - rc = spdk_app_start(spdk_vhost_startup, (void *)socket_path, NULL); + rc = spdk_app_start(&opts, spdk_vhost_startup, (void *)socket_path, NULL); spdk_app_fini(); diff --git a/include/spdk/event.h b/include/spdk/event.h index f33d9fbcf..b155a9ac0 100644 --- a/include/spdk/event.h +++ b/include/spdk/event.h @@ -97,22 +97,17 @@ struct spdk_app_opts { void spdk_app_opts_init(struct spdk_app_opts *opts); /** - * \brief Initialize an application to use the event framework. This must be called prior to using - * any other functions in this library. + * \brief Start the framework. Once started, the framework will call start_fn on the master + * core with the arguments provided. This call will block until \ref spdk_app_stop is called. */ -void spdk_app_init(struct spdk_app_opts *opts); +int spdk_app_start(struct spdk_app_opts *opts, spdk_event_fn start_fn, + void *arg1, void *arg2); /** * \brief Perform final shutdown operations on an application using the event framework. */ int spdk_app_fini(void); -/** - * \brief Start the framework. Once started, the framework will call start_fn on the master - * core with the arguments provided. This call will block until \ref spdk_app_stop is called. - */ -int spdk_app_start(spdk_event_fn start_fn, void *arg1, void *arg2); - /** * \brief Start shutting down the framework. Typically this function is not called directly, and * the shutdown process is started implicitly by a process signal. But in applications that are diff --git a/include/spdk_internal/event.h b/include/spdk_internal/event.h index 6b9c8a459..a84552c49 100644 --- a/include/spdk_internal/event.h +++ b/include/spdk_internal/event.h @@ -51,8 +51,6 @@ int spdk_reactors_fini(void); void spdk_reactors_start(void); void spdk_reactors_stop(void); -uint32_t spdk_event_queue_run_batch(uint32_t lcore); - struct spdk_subsystem { const char *name; /* User must call spdk_subsystem_init_next() when they are done with their initialization. */ diff --git a/lib/event/app.c b/lib/event/app.c index 951bf14d5..c873a03ce 100644 --- a/lib/event/app.c +++ b/lib/event/app.c @@ -216,8 +216,9 @@ spdk_app_opts_init(struct spdk_app_opts *opts) opts->max_delay_us = 0; } -void -spdk_app_init(struct spdk_app_opts *opts) +int +spdk_app_start(struct spdk_app_opts *opts, spdk_event_fn start_fn, + void *arg1, void *arg2) { struct spdk_conf *config; struct spdk_conf_section *sp; @@ -228,6 +229,12 @@ spdk_app_init(struct spdk_app_opts *opts) uint64_t tpoint_group_mask; char *end; struct spdk_env_opts env_opts = {}; + struct spdk_event *app_start_event; + + if (!opts) { + SPDK_ERRLOG("opts should not be NULL\n"); + exit(EXIT_FAILURE); + } if (opts->enable_coredump) { struct rlimit core_limits; @@ -409,6 +416,18 @@ spdk_app_init(struct spdk_app_opts *opts) spdk_trace_set_tpoint_group_mask(tpoint_group_mask); } } + + g_spdk_app.rc = 0; + app_start_event = spdk_event_allocate(spdk_env_get_current_core(), start_fn, + arg1, arg2); + + spdk_event_call(spdk_event_allocate(spdk_env_get_current_core(), spdk_subsystem_init, + app_start_event, NULL)); + + /* This blocks until spdk_app_stop is called */ + spdk_reactors_start(); + + return g_spdk_app.rc; } int @@ -425,25 +444,6 @@ spdk_app_fini(void) return rc; } -int -spdk_app_start(spdk_event_fn start_fn, void *arg1, void *arg2) -{ - struct spdk_event *app_start_event; - - g_spdk_app.rc = 0; - - app_start_event = spdk_event_allocate(spdk_env_get_current_core(), start_fn, - arg1, arg2); - - spdk_event_call(spdk_event_allocate(spdk_env_get_current_core(), spdk_subsystem_init, - app_start_event, NULL)); - - /* This blocks until spdk_app_stop is called */ - spdk_reactors_start(); - - return g_spdk_app.rc; -} - void spdk_app_stop(int rc) { diff --git a/lib/event/reactor.c b/lib/event/reactor.c index b04976f1c..e2e86694e 100644 --- a/lib/event/reactor.c +++ b/lib/event/reactor.c @@ -200,12 +200,6 @@ _spdk_event_queue_run_batch(struct spdk_reactor *reactor) return count; } -uint32_t -spdk_event_queue_run_batch(uint32_t lcore) -{ - return _spdk_event_queue_run_batch(spdk_reactor_get(lcore)); -} - /** * * \brief Set current reactor thread name to "reactor ". diff --git a/lib/rocksdb/env_spdk.cc b/lib/rocksdb/env_spdk.cc index 8d2e2bab7..dd2bc4f2f 100644 --- a/lib/rocksdb/env_spdk.cc +++ b/lib/rocksdb/env_spdk.cc @@ -510,9 +510,7 @@ initialize_spdk(void *arg) { struct spdk_app_opts *opts = (struct spdk_app_opts *)arg; - spdk_app_init(opts); - - spdk_app_start(spdk_rocksdb_run, NULL, NULL); + spdk_app_start(opts, spdk_rocksdb_run, NULL, NULL); spdk_app_fini(); delete opts; diff --git a/test/lib/bdev/bdevio/bdevio.c b/test/lib/bdev/bdevio/bdevio.c index 8fafa282f..9546055ec 100644 --- a/test/lib/bdev/bdevio/bdevio.c +++ b/test/lib/bdev/bdevio/bdevio.c @@ -764,15 +764,16 @@ main(int argc, char **argv) { const char *config_file; int num_failures; + struct spdk_app_opts opts = {}; if (argc == 1) { config_file = "/usr/local/etc/spdk/iscsi.conf"; } else { config_file = argv[1]; } - bdevtest_init(config_file, "0x3"); + bdevtest_init(config_file, "0x3", &opts); - num_failures = spdk_app_start(test_main, NULL, NULL); + num_failures = spdk_app_start(&opts, test_main, NULL, NULL); spdk_app_fini(); return num_failures; diff --git a/test/lib/bdev/bdevperf/bdevperf.c b/test/lib/bdev/bdevperf/bdevperf.c index d52a2a3aa..718c335be 100644 --- a/test/lib/bdev/bdevperf/bdevperf.c +++ b/test/lib/bdev/bdevperf/bdevperf.c @@ -532,6 +532,11 @@ bdevperf_run(void *arg1, void *arg2) struct io_target *target; struct spdk_event *event; + task_pool = rte_mempool_create("task_pool", 4096 * spdk_env_get_core_count(), + sizeof(struct bdevperf_task), + 64, 0, NULL, NULL, task_ctor, NULL, + SOCKET_ID_ANY, 0); + bdevperf_construct_targets(); printf("Running I/O for %d seconds...\n", g_time_in_sec); @@ -562,6 +567,7 @@ main(int argc, char **argv) const char *workload_type; int op; bool mix_specified; + struct spdk_app_opts opts = {}; /* default value */ config_file = NULL; @@ -716,14 +722,9 @@ main(int argc, char **argv) blockdev_heads_init(); - bdevtest_init(config_file, core_mask); + bdevtest_init(config_file, core_mask, &opts); - task_pool = rte_mempool_create("task_pool", 4096 * spdk_env_get_core_count(), - sizeof(struct bdevperf_task), - 64, 0, NULL, NULL, task_ctor, NULL, - SOCKET_ID_ANY, 0); - - spdk_app_start(bdevperf_run, NULL, NULL); + spdk_app_start(&opts, bdevperf_run, NULL, NULL); performance_dump(g_time_in_sec); spdk_app_fini(); diff --git a/test/lib/bdev/common.c b/test/lib/bdev/common.c index 63453deb7..7c34e7e9f 100644 --- a/test/lib/bdev/common.c +++ b/test/lib/bdev/common.c @@ -37,13 +37,13 @@ #include "spdk/event.h" static void -bdevtest_init(const char *config_file, const char *cpumask) +bdevtest_init(const char *config_file, const char *cpumask, + struct spdk_app_opts *opts) { - struct spdk_app_opts opts; + assert(opts != NULL); - spdk_app_opts_init(&opts); - opts.name = "bdevtest"; - opts.config_file = config_file; - opts.reactor_mask = cpumask; - spdk_app_init(&opts); + spdk_app_opts_init(opts); + opts->name = "bdevtest"; + opts->config_file = config_file; + opts->reactor_mask = cpumask; } diff --git a/test/lib/blobfs/fuse/fuse.c b/test/lib/blobfs/fuse/fuse.c index efe3cae25..a75ca73ec 100644 --- a/test/lib/blobfs/fuse/fuse.c +++ b/test/lib/blobfs/fuse/fuse.c @@ -335,14 +335,13 @@ int main(int argc, char **argv) opts.reactor_mask = "0x3"; opts.dpdk_mem_size = 6144; opts.shutdown_cb = spdk_fuse_shutdown; - spdk_app_init(&opts); g_bdev_name = argv[2]; g_mountpoint = argv[3]; g_fuse_argc = argc - 2; g_fuse_argv = &argv[2]; - spdk_app_start(spdk_fuse_run, NULL, NULL); + spdk_app_start(&opts, spdk_fuse_run, NULL, NULL); spdk_app_fini(); return 0; diff --git a/test/lib/blobfs/mkfs/mkfs.c b/test/lib/blobfs/mkfs/mkfs.c index 6b3d59ed0..86cc0d8be 100644 --- a/test/lib/blobfs/mkfs/mkfs.c +++ b/test/lib/blobfs/mkfs/mkfs.c @@ -106,12 +106,11 @@ int main(int argc, char **argv) opts.reactor_mask = "0x3"; opts.dpdk_mem_size = 1024; opts.shutdown_cb = NULL; - spdk_app_init(&opts); spdk_fs_set_cache_size(512); g_bdev_name = argv[2]; - spdk_app_start(spdk_mkfs_run, NULL, NULL); + spdk_app_start(&opts, spdk_mkfs_run, NULL, NULL); spdk_app_fini(); return 0; diff --git a/test/lib/event/event_perf/event_perf.c b/test/lib/event/event_perf/event_perf.c index f9338591a..9fdb73bfd 100644 --- a/test/lib/event/event_perf/event_perf.c +++ b/test/lib/event/event_perf/event_perf.c @@ -43,10 +43,10 @@ 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 __thread uint64_t __call_count = 0; static uint64_t call_count[RTE_MAX_LCORE]; static void @@ -55,39 +55,47 @@ submit_new_event(void *arg1, void *arg2) struct spdk_event *event; static __thread uint32_t next_lcore = RTE_MAX_LCORE; + if (spdk_get_ticks() > g_tsc_end) { + spdk_app_stop(0); + return; + } + if (next_lcore == RTE_MAX_LCORE) { next_lcore = rte_get_next_lcore(rte_lcore_id(), 0, 1); } - ++__call_count; + call_count[next_lcore]++; event = spdk_event_allocate(next_lcore, submit_new_event, NULL, NULL); spdk_event_call(event); } -static int -event_work_fn(void *arg) +static void +event_work_fn(void *arg1, void *arg2) { - uint64_t tsc_end; - - tsc_end = spdk_get_ticks() + g_time_in_sec * g_tsc_rate; submit_new_event(NULL, NULL); submit_new_event(NULL, NULL); submit_new_event(NULL, NULL); submit_new_event(NULL, NULL); +} - while (1) { +static void +event_perf_start(void *arg1, void *arg2) +{ + uint32_t i; - spdk_event_queue_run_batch(rte_lcore_id()); + 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; - if (spdk_get_ticks() > tsc_end) { - break; - } + 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)); } - call_count[rte_lcore_id()] = __call_count; - - return 0; } static void @@ -115,11 +123,9 @@ performance_dump(int io_time) int main(int argc, char **argv) { - struct spdk_app_opts opts; + struct spdk_app_opts opts = {}; int op; - uint32_t i, current_core; - spdk_app_opts_init(&opts); opts.name = "event_perf"; g_time_in_sec = 0; @@ -143,27 +149,12 @@ main(int argc, char **argv) exit(1); } - spdk_app_init(&opts); - - g_tsc_rate = spdk_get_ticks_hz(); - g_tsc_us_rate = g_tsc_rate / (1000 * 1000); - printf("Running I/O for %d seconds...", g_time_in_sec); fflush(stdout); - /* call event_work_fn on each slave lcore */ - current_core = spdk_env_get_current_core(); - SPDK_ENV_FOREACH_CORE(i) { - if (i != current_core) { - rte_eal_remote_launch(event_work_fn, NULL, i); - } - } - - /* call event_work_fn on lcore0 */ - event_work_fn(NULL); - - rte_eal_mp_wait_lcore(); + spdk_app_start(&opts, event_perf_start, NULL, NULL); + spdk_app_fini(); performance_dump(g_time_in_sec); printf("done.\n"); diff --git a/test/lib/event/reactor/reactor.c b/test/lib/event/reactor/reactor.c index 784cf27ff..193bd1805 100644 --- a/test/lib/event/reactor/reactor.c +++ b/test/lib/event/reactor/reactor.c @@ -136,9 +136,7 @@ main(int argc, char **argv) opts.shutdown_cb = test_cleanup; - spdk_app_init(&opts); - - spdk_app_start(test_start, NULL, NULL); + spdk_app_start(&opts, test_start, NULL, NULL); test_cleanup(); diff --git a/test/lib/event/reactor_perf/reactor_perf.c b/test/lib/event/reactor_perf/reactor_perf.c index d7712a14d..c8b3f84d6 100644 --- a/test/lib/event/reactor_perf/reactor_perf.c +++ b/test/lib/event/reactor_perf/reactor_perf.c @@ -132,9 +132,7 @@ main(int argc, char **argv) opts.shutdown_cb = test_cleanup; - spdk_app_init(&opts); - - spdk_app_start(test_start, NULL, NULL); + spdk_app_start(&opts, test_start, NULL, NULL); spdk_app_fini();