nvme,reset: remove dpdk dependency

Change-Id: Ib2bdbe6e8cbbefadac0b38f2a552daea7d4c4b1c
Signed-off-by: Ziye Yang <optimistyzy@gmail.com>
Reviewed-on: https://review.gerrithub.io/388151
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Ziye Yang 2017-11-20 13:41:51 +08:00 committed by Jim Harris
parent 9e477c7b2e
commit 09fec7f014

View File

@ -33,10 +33,6 @@
#include "spdk/stdinc.h"
#include <rte_config.h>
#include <rte_mempool.h>
#include <rte_lcore.h>
#include "spdk/nvme.h"
#include "spdk/env.h"
#include "spdk/string.h"
@ -79,7 +75,7 @@ struct worker_thread {
unsigned lcore;
};
static struct rte_mempool *task_pool;
static struct spdk_mempool *task_pool;
static struct ctrlr_entry *g_controllers = NULL;
static struct ns_entry *g_namespaces = NULL;
@ -94,6 +90,8 @@ static int g_is_random;
static int g_queue_depth;
static int g_time_in_sec;
#define TASK_POOL_NUM 8192
static void
register_ns(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_ns *ns)
{
@ -152,17 +150,6 @@ register_ctrlr(struct spdk_nvme_ctrlr *ctrlr)
}
}
static void task_ctor(struct rte_mempool *mp, void *arg, void *__task, unsigned id)
{
struct reset_task *task = __task;
task->buf = spdk_dma_zmalloc(g_io_size_bytes, 0x200, NULL);
if (task->buf == NULL) {
fprintf(stderr, "task->buf spdk_dma_zmalloc failed\n");
exit(1);
}
}
static void io_complete(void *ctx, const struct spdk_nvme_cpl *completion);
static __thread unsigned int seed = 0;
@ -175,8 +162,16 @@ submit_single_io(struct ns_worker_ctx *ns_ctx)
int rc;
struct ns_entry *entry = ns_ctx->entry;
if (rte_mempool_get(task_pool, (void **)&task) != 0) {
fprintf(stderr, "task_pool rte_mempool_get failed\n");
task = spdk_mempool_get(task_pool);
if (!task) {
fprintf(stderr, "Failed to get task from task_pool\n");
exit(1);
}
task->buf = spdk_dma_zmalloc(g_io_size_bytes, 0x200, NULL);
if (!task->buf) {
spdk_dma_free(task->buf);
fprintf(stderr, "task->buf spdk_dma_zmalloc failed\n");
exit(1);
}
@ -224,7 +219,8 @@ task_complete(struct reset_task *task, const struct spdk_nvme_cpl *completion)
ns_ctx->io_completed++;
}
rte_mempool_put(task_pool, task);
spdk_dma_free(task->buf);
spdk_mempool_put(task_pool, task);
/*
* is_draining indicates when time has expired for the test run
@ -500,7 +496,7 @@ register_workers(void)
}
memset(worker, 0, sizeof(struct worker_thread));
worker->lcore = rte_get_master_lcore();
worker->lcore = spdk_env_get_current_core();
g_workers = worker;
@ -613,6 +609,16 @@ run_nvme_reset_cycle(int retry_count)
return 0;
}
static void
spdk_reset_free_tasks(void)
{
if (spdk_mempool_count(task_pool) != TASK_POOL_NUM) {
fprintf(stderr, "task_pool count is %zu but should be %d\n",
spdk_mempool_count(task_pool), TASK_POOL_NUM);
}
spdk_mempool_free(task_pool);
}
int main(int argc, char **argv)
{
int rc;
@ -630,10 +636,13 @@ int main(int argc, char **argv)
opts.core_mask = "0x1";
spdk_env_init(&opts);
task_pool = rte_mempool_create("task_pool", 8192,
sizeof(struct reset_task),
64, 0, NULL, NULL, task_ctor, NULL,
SOCKET_ID_ANY, 0);
task_pool = spdk_mempool_create("task_pool", TASK_POOL_NUM,
sizeof(struct reset_task),
64, SPDK_ENV_SOCKET_ID_ANY);
if (!task_pool) {
fprintf(stderr, "Cannot create task pool\n");
return 1;
}
g_tsc_rate = spdk_get_ticks_hz();
@ -661,6 +670,7 @@ int main(int argc, char **argv)
cleanup:
unregister_controllers();
spdk_reset_free_tasks();
if (rc != 0) {
fprintf(stderr, "%s: errors occured\n", argv[0]);