lib/ftl: Merge ftl_thread structure with ftl_dev

Since ftl supports only one core thread ftl_thread
structure is not needed anymore.

Change-Id: I66eda9249d74b3eff0c4473dcd0aba4a6135e296
Signed-off-by: Wojciech Malikowski <wojciech.malikowski@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/548
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Maciej Szczepaniak <maciej.szczepaniak@intel.com>
Reviewed-by: Konrad Sztyber <konrad.sztyber@intel.com>
This commit is contained in:
Wojciech Malikowski 2020-01-28 09:57:33 -05:00 committed by Tomasz Zawadzki
parent c6bca349da
commit f93ac08d26
5 changed files with 46 additions and 66 deletions

View File

@ -387,14 +387,14 @@ ftl_submit_erase(struct ftl_io *io)
static bool
ftl_check_core_thread(const struct spdk_ftl_dev *dev)
{
return dev->core_thread.thread == spdk_get_thread();
return dev->core_thread == spdk_get_thread();
}
struct spdk_io_channel *
ftl_get_io_channel(const struct spdk_ftl_dev *dev)
{
if (ftl_check_core_thread(dev)) {
return dev->core_thread.ioch;
return dev->ioch;
}
return NULL;
@ -858,7 +858,7 @@ ftl_wptr_process_shutdown(struct ftl_wptr *wptr)
static int
ftl_shutdown_complete(struct spdk_ftl_dev *dev)
{
struct ftl_io_channel *ioch = spdk_io_channel_get_ctx(dev->core_thread.ioch);
struct ftl_io_channel *ioch = spdk_io_channel_get_ctx(dev->ioch);
return !__atomic_load_n(&dev->num_inflight, __ATOMIC_SEQ_CST) &&
LIST_EMPTY(&dev->wptr_list) && TAILQ_EMPTY(&ioch->retry_queue);
@ -2258,12 +2258,11 @@ ftl_io_channel_poll(void *arg)
int
ftl_task_core(void *ctx)
{
struct ftl_thread *thread = ctx;
struct spdk_ftl_dev *dev = thread->dev;
struct spdk_ftl_dev *dev = ctx;
if (dev->halt) {
if (ftl_shutdown_complete(dev)) {
spdk_poller_unregister(&thread->poller);
spdk_poller_unregister(&dev->core_poller);
return 0;
}
}

View File

@ -74,23 +74,6 @@ struct ftl_stats {
uint64_t limits[SPDK_FTL_LIMIT_MAX];
};
struct ftl_thread {
/* Owner */
struct spdk_ftl_dev *dev;
/* Thread on which the poller is running */
struct spdk_thread *thread;
/* IO channel */
struct spdk_io_channel *ioch;
/* Poller */
struct spdk_poller *poller;
/* Poller's function */
spdk_poller_fn poller_fn;
/* Poller's frequency */
uint64_t period_us;
};
struct ftl_global_md {
/* Device instance */
struct spdk_uuid uuid;
@ -209,8 +192,12 @@ struct spdk_ftl_dev {
/* Manages data relocation */
struct ftl_reloc *reloc;
/* Threads */
struct ftl_thread core_thread;
/* Thread on which the poller is running */
struct spdk_thread *core_thread;
/* IO channel */
struct spdk_io_channel *ioch;
/* Poller */
struct spdk_poller *core_poller;
/* Devices' list */
STAILQ_ENTRY(spdk_ftl_dev) stailq;
@ -279,7 +266,7 @@ ftl_get_io_channel(const struct spdk_ftl_dev *dev);
static inline struct spdk_thread *
ftl_get_core_thread(const struct spdk_ftl_dev *dev)
{
return dev->core_thread.thread;
return dev->core_thread;
}
static inline size_t

View File

@ -511,44 +511,38 @@ ftl_init_bands_state(struct spdk_ftl_dev *dev)
static void
_ftl_dev_init_core_thread(void *ctx)
{
struct ftl_thread *thread = ctx;
struct spdk_ftl_dev *dev = thread->dev;
struct spdk_ftl_dev *dev = ctx;
thread->poller = spdk_poller_register(thread->poller_fn, thread, thread->period_us);
if (!thread->poller) {
SPDK_ERRLOG("Unable to register poller\n");
dev->core_poller = spdk_poller_register(ftl_task_core, dev, 0);
if (!dev->core_poller) {
SPDK_ERRLOG("Unable to register core poller\n");
assert(0);
}
thread->ioch = spdk_get_io_channel(dev);
dev->ioch = spdk_get_io_channel(dev);
}
static int
ftl_dev_init_core_thread(struct spdk_ftl_dev *dev, const struct spdk_ftl_dev_init_opts *opts)
{
struct ftl_thread *thread = &dev->core_thread;
if (!opts->core_thread) {
return -1;
}
thread->dev = dev;
thread->poller_fn = ftl_task_core;
thread->thread = opts->core_thread;
thread->period_us = 0;
dev->core_thread = opts->core_thread;
spdk_thread_send_msg(opts->core_thread, _ftl_dev_init_core_thread, thread);
spdk_thread_send_msg(opts->core_thread, _ftl_dev_init_core_thread, dev);
return 0;
}
static void
ftl_dev_free_thread(struct spdk_ftl_dev *dev, struct ftl_thread *thread)
ftl_dev_free_thread(struct spdk_ftl_dev *dev)
{
assert(thread->poller == NULL);
assert(dev->core_poller == NULL);
spdk_put_io_channel(thread->ioch);
thread->thread = NULL;
thread->ioch = NULL;
spdk_put_io_channel(dev->ioch);
dev->core_thread = NULL;
dev->ioch = NULL;
}
static int
@ -1148,8 +1142,8 @@ ftl_dev_free_sync(struct spdk_ftl_dev *dev)
spdk_io_device_unregister(dev, NULL);
if (dev->core_thread.thread) {
ftl_dev_free_thread(dev, &dev->core_thread);
if (dev->core_thread) {
ftl_dev_free_thread(dev);
}
if (dev->bands) {
@ -1332,7 +1326,7 @@ ftl_halt_poller(void *ctx)
struct ftl_dev_init_ctx *fini_ctx = ctx;
struct spdk_ftl_dev *dev = fini_ctx->dev;
if (!dev->core_thread.poller) {
if (!dev->core_poller) {
spdk_poller_unregister(&fini_ctx->poller);
if (ftl_dev_has_nv_cache(dev)) {

View File

@ -74,10 +74,10 @@ test_init_ftl_dev(const struct base_bdev_geometry *geo)
SPDK_CU_ASSERT_FATAL(dev != NULL);
dev->xfer_size = geo->write_unit_size;
dev->core_thread.thread = spdk_thread_create("unit_test_thread", NULL);
spdk_set_thread(dev->core_thread.thread);
dev->core_thread.ioch = calloc(1, sizeof(*dev->core_thread.ioch)
+ sizeof(struct ftl_io_channel));
dev->core_thread = spdk_thread_create("unit_test_thread", NULL);
spdk_set_thread(dev->core_thread);
dev->ioch = calloc(1, sizeof(*dev->ioch)
+ sizeof(struct ftl_io_channel));
dev->num_bands = geo->blockcnt / (geo->zone_size * geo->optimal_open_zones);
dev->bands = calloc(dev->num_bands, sizeof(*dev->bands));
SPDK_CU_ASSERT_FATAL(dev->bands != NULL);
@ -135,10 +135,10 @@ void
test_free_ftl_dev(struct spdk_ftl_dev *dev)
{
SPDK_CU_ASSERT_FATAL(dev != NULL);
free(dev->core_thread.ioch);
spdk_set_thread(dev->core_thread.thread);
spdk_thread_exit(dev->core_thread.thread);
spdk_thread_destroy(dev->core_thread.thread);
free(dev->ioch);
spdk_set_thread(dev->core_thread);
spdk_thread_exit(dev->core_thread);
spdk_thread_destroy(dev->core_thread);
spdk_mempool_free(dev->lba_pool);
free(dev->bands);
free(dev);

View File

@ -51,10 +51,10 @@ setup_device(void)
dev = calloc(1, sizeof(*dev));
SPDK_CU_ASSERT_FATAL(dev != NULL);
dev->core_thread.ioch = calloc(1, sizeof(*ioch) + sizeof(struct spdk_io_channel));
SPDK_CU_ASSERT_FATAL(dev->core_thread.ioch != NULL);
dev->ioch = calloc(1, sizeof(*ioch) + sizeof(struct spdk_io_channel));
SPDK_CU_ASSERT_FATAL(dev->ioch != NULL);
ioch = spdk_io_channel_get_ctx(dev->core_thread.ioch);
ioch = spdk_io_channel_get_ctx(dev->ioch);
ioch->elem_size = sizeof(struct ftl_md_io);
ioch->io_pool = spdk_mempool_create("io-pool", 4096, ioch->elem_size, 0, 0);
@ -69,10 +69,10 @@ free_device(struct spdk_ftl_dev *dev)
{
struct ftl_io_channel *ioch;
ioch = spdk_io_channel_get_ctx(dev->core_thread.ioch);
ioch = spdk_io_channel_get_ctx(dev->ioch);
spdk_mempool_free(ioch->io_pool);
free(dev->core_thread.ioch);
free(dev->ioch);
free(dev);
}
@ -89,7 +89,7 @@ alloc_io(struct spdk_ftl_dev *dev, ftl_io_fn cb, void *ctx)
{
struct ftl_io *io;
io = ftl_io_alloc(dev->core_thread.ioch);
io = ftl_io_alloc(dev->ioch);
SPDK_CU_ASSERT_FATAL(io != NULL);
setup_io(io, dev, cb, ctx);
@ -112,7 +112,7 @@ test_completion(void)
size_t pool_size;
dev = setup_device();
ioch = spdk_io_channel_get_ctx(dev->core_thread.ioch);
ioch = spdk_io_channel_get_ctx(dev->ioch);
pool_size = spdk_mempool_count(ioch->io_pool);
io = alloc_io(dev, io_complete_cb, &status);
@ -154,7 +154,7 @@ test_alloc_free(void)
size_t pool_size;
dev = setup_device();
ioch = spdk_io_channel_get_ctx(dev->core_thread.ioch);
ioch = spdk_io_channel_get_ctx(dev->ioch);
pool_size = spdk_mempool_count(ioch->io_pool);
parent = alloc_io(dev, io_complete_cb, &parent_status);
@ -200,7 +200,7 @@ test_child_requests(void)
size_t pool_size;
dev = setup_device();
ioch = spdk_io_channel_get_ctx(dev->core_thread.ioch);
ioch = spdk_io_channel_get_ctx(dev->ioch);
pool_size = spdk_mempool_count(ioch->io_pool);
/* Verify correct behaviour when children finish first */
@ -300,7 +300,7 @@ test_child_status(void)
size_t pool_size, i;
dev = setup_device();
ioch = spdk_io_channel_get_ctx(dev->core_thread.ioch);
ioch = spdk_io_channel_get_ctx(dev->ioch);
pool_size = spdk_mempool_count(ioch->io_pool);
/* Verify the first error is returned by the parent */
@ -387,7 +387,7 @@ test_multi_generation(void)
int i, j;
dev = setup_device();
ioch = spdk_io_channel_get_ctx(dev->core_thread.ioch);
ioch = spdk_io_channel_get_ctx(dev->ioch);
pool_size = spdk_mempool_count(ioch->io_pool);
/* Verify correct behaviour when children finish first */