2022-06-03 19:15:11 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
2022-11-01 20:26:26 +00:00
|
|
|
* Copyright (C) 2015 Intel Corporation.
|
2015-10-19 05:52:57 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2017-05-02 18:18:25 +00:00
|
|
|
#include "spdk/stdinc.h"
|
2015-10-19 05:52:57 +00:00
|
|
|
|
|
|
|
#include "spdk/nvme.h"
|
2016-08-10 17:41:12 +00:00
|
|
|
#include "spdk/env.h"
|
2015-10-19 05:52:57 +00:00
|
|
|
#include "spdk/string.h"
|
2019-05-14 20:32:58 +00:00
|
|
|
#include "spdk/pci_ids.h"
|
2015-10-19 05:52:57 +00:00
|
|
|
|
|
|
|
struct ctrlr_entry {
|
2020-09-28 01:49:25 +00:00
|
|
|
struct spdk_nvme_ctrlr *ctrlr;
|
|
|
|
TAILQ_ENTRY(ctrlr_entry) link;
|
|
|
|
char name[1024];
|
2015-10-19 05:52:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ns_entry {
|
2016-02-10 18:26:12 +00:00
|
|
|
struct spdk_nvme_ns *ns;
|
2016-02-25 16:38:01 +00:00
|
|
|
struct spdk_nvme_ctrlr *ctrlr;
|
2020-09-28 01:49:25 +00:00
|
|
|
TAILQ_ENTRY(ns_entry) link;
|
2015-10-19 05:52:57 +00:00
|
|
|
uint32_t io_size_blocks;
|
|
|
|
uint64_t size_in_ios;
|
|
|
|
char name[1024];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ns_worker_ctx {
|
2020-09-28 01:49:25 +00:00
|
|
|
struct ns_entry *entry;
|
|
|
|
struct spdk_nvme_qpair *qpair;
|
|
|
|
uint64_t io_completed;
|
|
|
|
uint64_t io_completed_error;
|
|
|
|
uint64_t io_submitted;
|
|
|
|
uint64_t current_queue_depth;
|
|
|
|
uint64_t offset_in_ios;
|
|
|
|
bool is_draining;
|
|
|
|
|
|
|
|
TAILQ_ENTRY(ns_worker_ctx) link;
|
2015-10-19 05:52:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct reset_task {
|
|
|
|
struct ns_worker_ctx *ns_ctx;
|
|
|
|
void *buf;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct worker_thread {
|
2020-09-28 01:49:25 +00:00
|
|
|
TAILQ_HEAD(, ns_worker_ctx) ns_ctx;
|
|
|
|
unsigned lcore;
|
2015-10-19 05:52:57 +00:00
|
|
|
};
|
|
|
|
|
2017-11-20 05:41:51 +00:00
|
|
|
static struct spdk_mempool *task_pool;
|
2015-10-19 05:52:57 +00:00
|
|
|
|
2020-09-28 01:49:25 +00:00
|
|
|
static TAILQ_HEAD(, ctrlr_entry) g_controllers = TAILQ_HEAD_INITIALIZER(g_controllers);
|
|
|
|
static TAILQ_HEAD(, ns_entry) g_namespaces = TAILQ_HEAD_INITIALIZER(g_namespaces);
|
2015-10-19 05:52:57 +00:00
|
|
|
static int g_num_namespaces = 0;
|
2020-09-28 01:49:25 +00:00
|
|
|
static struct worker_thread *g_worker = NULL;
|
2019-05-14 20:32:58 +00:00
|
|
|
static bool g_qemu_ssd_found = false;
|
2015-10-19 05:52:57 +00:00
|
|
|
|
|
|
|
static uint64_t g_tsc_rate;
|
|
|
|
|
|
|
|
static int g_io_size_bytes;
|
|
|
|
static int g_rw_percentage;
|
|
|
|
static int g_is_random;
|
|
|
|
static int g_queue_depth;
|
|
|
|
static int g_time_in_sec;
|
|
|
|
|
2017-11-20 05:41:51 +00:00
|
|
|
#define TASK_POOL_NUM 8192
|
|
|
|
|
2015-10-19 05:52:57 +00:00
|
|
|
static void
|
2016-02-10 18:26:12 +00:00
|
|
|
register_ns(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_ns *ns)
|
2015-10-19 05:52:57 +00:00
|
|
|
{
|
|
|
|
struct ns_entry *entry;
|
2016-02-09 18:06:48 +00:00
|
|
|
const struct spdk_nvme_ctrlr_data *cdata;
|
2015-10-19 05:52:57 +00:00
|
|
|
|
2016-03-01 21:39:24 +00:00
|
|
|
if (!spdk_nvme_ns_is_active(ns)) {
|
|
|
|
printf("Skipping inactive NS %u\n", spdk_nvme_ns_get_id(ns));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-19 05:52:57 +00:00
|
|
|
entry = malloc(sizeof(struct ns_entry));
|
|
|
|
if (entry == NULL) {
|
|
|
|
perror("ns_entry malloc");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2016-02-10 18:26:12 +00:00
|
|
|
cdata = spdk_nvme_ctrlr_get_data(ctrlr);
|
2015-10-19 05:52:57 +00:00
|
|
|
|
|
|
|
entry->ns = ns;
|
2016-02-25 16:38:01 +00:00
|
|
|
entry->ctrlr = ctrlr;
|
2016-02-10 18:26:12 +00:00
|
|
|
entry->size_in_ios = spdk_nvme_ns_get_size(ns) /
|
2015-10-19 05:52:57 +00:00
|
|
|
g_io_size_bytes;
|
2016-02-10 18:26:12 +00:00
|
|
|
entry->io_size_blocks = g_io_size_bytes / spdk_nvme_ns_get_sector_size(ns);
|
2015-10-19 05:52:57 +00:00
|
|
|
|
|
|
|
snprintf(entry->name, 44, "%-20.20s (%-20.20s)", cdata->mn, cdata->sn);
|
|
|
|
|
|
|
|
g_num_namespaces++;
|
2020-09-28 01:49:25 +00:00
|
|
|
TAILQ_INSERT_TAIL(&g_namespaces, entry, link);
|
2015-10-19 05:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-02-10 18:26:12 +00:00
|
|
|
register_ctrlr(struct spdk_nvme_ctrlr *ctrlr)
|
2015-10-19 05:52:57 +00:00
|
|
|
{
|
2021-11-03 19:20:13 +00:00
|
|
|
int nsid;
|
2017-03-24 05:37:22 +00:00
|
|
|
struct spdk_nvme_ns *ns;
|
2015-10-19 05:52:57 +00:00
|
|
|
struct ctrlr_entry *entry = malloc(sizeof(struct ctrlr_entry));
|
|
|
|
|
|
|
|
if (entry == NULL) {
|
|
|
|
perror("ctrlr_entry malloc");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
entry->ctrlr = ctrlr;
|
2020-09-28 01:49:25 +00:00
|
|
|
TAILQ_INSERT_TAIL(&g_controllers, entry, link);
|
2015-10-19 05:52:57 +00:00
|
|
|
|
2021-11-03 19:20:13 +00:00
|
|
|
for (nsid = spdk_nvme_ctrlr_get_first_active_ns(ctrlr); nsid != 0;
|
|
|
|
nsid = spdk_nvme_ctrlr_get_next_active_ns(ctrlr, nsid)) {
|
2017-03-24 05:37:22 +00:00
|
|
|
ns = spdk_nvme_ctrlr_get_ns(ctrlr, nsid);
|
|
|
|
if (ns == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
register_ns(ctrlr, ns);
|
2015-10-19 05:52:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-09 18:06:48 +00:00
|
|
|
static void io_complete(void *ctx, const struct spdk_nvme_cpl *completion);
|
2015-10-19 05:52:57 +00:00
|
|
|
|
|
|
|
static __thread unsigned int seed = 0;
|
|
|
|
|
|
|
|
static void
|
|
|
|
submit_single_io(struct ns_worker_ctx *ns_ctx)
|
|
|
|
{
|
|
|
|
struct reset_task *task = NULL;
|
|
|
|
uint64_t offset_in_ios;
|
|
|
|
int rc;
|
|
|
|
struct ns_entry *entry = ns_ctx->entry;
|
|
|
|
|
2017-11-20 05:41:51 +00:00
|
|
|
task = spdk_mempool_get(task_pool);
|
|
|
|
if (!task) {
|
|
|
|
fprintf(stderr, "Failed to get task from task_pool\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2019-06-27 05:19:25 +00:00
|
|
|
task->buf = spdk_zmalloc(g_io_size_bytes, 0x200, NULL, SPDK_ENV_LCORE_ID_ANY, SPDK_MALLOC_DMA);
|
2017-11-20 05:41:51 +00:00
|
|
|
if (!task->buf) {
|
2019-06-27 05:19:25 +00:00
|
|
|
spdk_free(task->buf);
|
|
|
|
fprintf(stderr, "task->buf spdk_zmalloc failed\n");
|
2015-10-19 05:52:57 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
task->ns_ctx = ns_ctx;
|
|
|
|
|
|
|
|
if (g_is_random) {
|
|
|
|
offset_in_ios = rand_r(&seed) % entry->size_in_ios;
|
|
|
|
} else {
|
|
|
|
offset_in_ios = ns_ctx->offset_in_ios++;
|
|
|
|
if (ns_ctx->offset_in_ios == entry->size_in_ios) {
|
|
|
|
ns_ctx->offset_in_ios = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((g_rw_percentage == 100) ||
|
|
|
|
(g_rw_percentage != 0 && ((rand_r(&seed) % 100) < g_rw_percentage))) {
|
2016-02-29 21:19:02 +00:00
|
|
|
rc = spdk_nvme_ns_cmd_read(entry->ns, ns_ctx->qpair, task->buf,
|
|
|
|
offset_in_ios * entry->io_size_blocks,
|
2016-02-10 18:26:12 +00:00
|
|
|
entry->io_size_blocks, io_complete, task, 0);
|
2015-10-19 05:52:57 +00:00
|
|
|
} else {
|
2016-02-29 21:19:02 +00:00
|
|
|
rc = spdk_nvme_ns_cmd_write(entry->ns, ns_ctx->qpair, task->buf,
|
|
|
|
offset_in_ios * entry->io_size_blocks,
|
2016-02-10 18:26:12 +00:00
|
|
|
entry->io_size_blocks, io_complete, task, 0);
|
2015-10-19 05:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (rc != 0) {
|
|
|
|
fprintf(stderr, "starting I/O failed\n");
|
2020-05-25 01:09:29 +00:00
|
|
|
} else {
|
|
|
|
ns_ctx->current_queue_depth++;
|
2022-09-16 08:00:06 +00:00
|
|
|
ns_ctx->io_submitted++;
|
2015-10-19 05:52:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-02-09 18:06:48 +00:00
|
|
|
task_complete(struct reset_task *task, const struct spdk_nvme_cpl *completion)
|
2015-10-19 05:52:57 +00:00
|
|
|
{
|
|
|
|
struct ns_worker_ctx *ns_ctx;
|
|
|
|
|
|
|
|
ns_ctx = task->ns_ctx;
|
|
|
|
ns_ctx->current_queue_depth--;
|
|
|
|
|
2016-02-09 18:06:48 +00:00
|
|
|
if (spdk_nvme_cpl_is_error(completion)) {
|
2015-10-19 05:52:57 +00:00
|
|
|
ns_ctx->io_completed_error++;
|
|
|
|
} else {
|
|
|
|
ns_ctx->io_completed++;
|
|
|
|
}
|
|
|
|
|
2019-06-27 05:19:25 +00:00
|
|
|
spdk_free(task->buf);
|
2017-11-20 05:41:51 +00:00
|
|
|
spdk_mempool_put(task_pool, task);
|
2015-10-19 05:52:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* is_draining indicates when time has expired for the test run
|
|
|
|
* and we are just waiting for the previously submitted I/O
|
|
|
|
* to complete. In this case, do not submit a new I/O to replace
|
|
|
|
* the one just completed.
|
|
|
|
*/
|
|
|
|
if (!ns_ctx->is_draining) {
|
|
|
|
submit_single_io(ns_ctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-02-09 18:06:48 +00:00
|
|
|
io_complete(void *ctx, const struct spdk_nvme_cpl *completion)
|
2015-10-19 05:52:57 +00:00
|
|
|
{
|
|
|
|
task_complete((struct reset_task *)ctx, completion);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
check_io(struct ns_worker_ctx *ns_ctx)
|
|
|
|
{
|
2016-02-29 21:19:02 +00:00
|
|
|
spdk_nvme_qpair_process_completions(ns_ctx->qpair, 0);
|
2015-10-19 05:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
submit_io(struct ns_worker_ctx *ns_ctx, int queue_depth)
|
|
|
|
{
|
|
|
|
while (queue_depth-- > 0) {
|
|
|
|
submit_single_io(ns_ctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
drain_io(struct ns_worker_ctx *ns_ctx)
|
|
|
|
{
|
|
|
|
ns_ctx->is_draining = true;
|
|
|
|
while (ns_ctx->current_queue_depth > 0) {
|
|
|
|
check_io(ns_ctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
work_fn(void *arg)
|
|
|
|
{
|
2016-08-18 19:52:48 +00:00
|
|
|
uint64_t tsc_end = spdk_get_ticks() + g_time_in_sec * g_tsc_rate;
|
2015-10-19 05:52:57 +00:00
|
|
|
struct worker_thread *worker = (struct worker_thread *)arg;
|
|
|
|
struct ns_worker_ctx *ns_ctx = NULL;
|
2016-03-07 22:06:33 +00:00
|
|
|
bool did_reset = false;
|
2015-10-19 05:52:57 +00:00
|
|
|
|
|
|
|
printf("Starting thread on core %u\n", worker->lcore);
|
|
|
|
|
|
|
|
/* Submit initial I/O for each namespace. */
|
2020-09-28 01:49:25 +00:00
|
|
|
TAILQ_FOREACH(ns_ctx, &worker->ns_ctx, link) {
|
2017-07-14 23:08:05 +00:00
|
|
|
ns_ctx->qpair = spdk_nvme_ctrlr_alloc_io_qpair(ns_ctx->entry->ctrlr, NULL, 0);
|
2016-02-29 21:19:02 +00:00
|
|
|
if (ns_ctx->qpair == NULL) {
|
|
|
|
fprintf(stderr, "spdk_nvme_ctrlr_alloc_io_qpair() failed on core %u\n", worker->lcore);
|
|
|
|
return -1;
|
|
|
|
}
|
2015-10-19 05:52:57 +00:00
|
|
|
submit_io(ns_ctx, g_queue_depth);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (1) {
|
2016-08-18 19:52:48 +00:00
|
|
|
if (!did_reset && ((tsc_end - spdk_get_ticks()) / g_tsc_rate) > (uint64_t)g_time_in_sec / 2) {
|
2020-09-28 01:49:25 +00:00
|
|
|
TAILQ_FOREACH(ns_ctx, &worker->ns_ctx, link) {
|
2016-02-25 16:38:01 +00:00
|
|
|
if (spdk_nvme_ctrlr_reset(ns_ctx->entry->ctrlr) < 0) {
|
2015-10-19 05:52:57 +00:00
|
|
|
fprintf(stderr, "nvme reset failed.\n");
|
2015-12-02 21:18:25 +00:00
|
|
|
return -1;
|
2015-10-19 05:52:57 +00:00
|
|
|
}
|
|
|
|
}
|
2016-03-07 22:06:33 +00:00
|
|
|
did_reset = true;
|
2015-10-19 05:52:57 +00:00
|
|
|
}
|
|
|
|
|
2019-06-13 13:22:58 +00:00
|
|
|
/*
|
|
|
|
* Check for completed I/O for each controller. A new
|
|
|
|
* I/O will be submitted in the io_complete callback
|
|
|
|
* to replace each I/O that is completed.
|
|
|
|
*/
|
2020-09-28 01:49:25 +00:00
|
|
|
TAILQ_FOREACH(ns_ctx, &worker->ns_ctx, link) {
|
2019-06-13 13:22:58 +00:00
|
|
|
check_io(ns_ctx);
|
|
|
|
}
|
|
|
|
|
2016-08-18 19:52:48 +00:00
|
|
|
if (spdk_get_ticks() > tsc_end) {
|
2015-10-19 05:52:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-28 01:49:25 +00:00
|
|
|
TAILQ_FOREACH(ns_ctx, &worker->ns_ctx, link) {
|
2015-10-19 05:52:57 +00:00
|
|
|
drain_io(ns_ctx);
|
2016-02-29 21:19:02 +00:00
|
|
|
spdk_nvme_ctrlr_free_io_qpair(ns_ctx->qpair);
|
2015-10-19 05:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-06-22 21:35:04 +00:00
|
|
|
static void
|
|
|
|
usage(char *program_name)
|
2015-10-19 05:52:57 +00:00
|
|
|
{
|
|
|
|
printf("%s options", program_name);
|
|
|
|
printf("\n");
|
|
|
|
printf("\t[-q io depth]\n");
|
2022-09-16 03:36:44 +00:00
|
|
|
printf("\t[-o io size in bytes]\n");
|
2015-10-19 05:52:57 +00:00
|
|
|
printf("\t[-w io pattern type, must be one of\n");
|
|
|
|
printf("\t\t(read, write, randread, randwrite, rw, randrw)]\n");
|
|
|
|
printf("\t[-M rwmixread (100 for reads, 0 for writes)]\n");
|
|
|
|
printf("\t[-t time in seconds(should be larger than 15 seconds)]\n");
|
|
|
|
printf("\t\t(default:0 - unlimited)\n");
|
|
|
|
}
|
|
|
|
|
2015-12-02 21:18:25 +00:00
|
|
|
static int
|
2015-10-19 05:52:57 +00:00
|
|
|
print_stats(void)
|
|
|
|
{
|
|
|
|
uint64_t io_completed, io_submitted, io_completed_error;
|
|
|
|
uint64_t total_completed_io, total_submitted_io, total_completed_err_io;
|
|
|
|
struct worker_thread *worker;
|
|
|
|
struct ns_worker_ctx *ns_ctx;
|
|
|
|
|
|
|
|
total_completed_io = 0;
|
|
|
|
total_submitted_io = 0;
|
|
|
|
total_completed_err_io = 0;
|
|
|
|
|
2020-09-28 01:49:25 +00:00
|
|
|
worker = g_worker;
|
|
|
|
TAILQ_FOREACH(ns_ctx, &worker->ns_ctx, link) {
|
2015-10-19 05:52:57 +00:00
|
|
|
io_completed = ns_ctx->io_completed;
|
|
|
|
io_submitted = ns_ctx->io_submitted;
|
|
|
|
io_completed_error = ns_ctx->io_completed_error;
|
|
|
|
total_completed_io += io_completed;
|
|
|
|
total_submitted_io += io_submitted;
|
|
|
|
total_completed_err_io += io_completed_error;
|
|
|
|
}
|
|
|
|
|
2015-12-02 21:18:25 +00:00
|
|
|
printf("========================================================\n");
|
2020-11-17 16:22:36 +00:00
|
|
|
printf("%16" PRIu64 " IO completed successfully\n", total_completed_io);
|
|
|
|
printf("%16" PRIu64 " IO completed with error\n", total_completed_err_io);
|
2015-12-02 21:18:25 +00:00
|
|
|
printf("--------------------------------------------------------\n");
|
2020-11-17 16:22:36 +00:00
|
|
|
printf("%16" PRIu64 " IO completed total\n", total_completed_io + total_completed_err_io);
|
|
|
|
printf("%16" PRIu64 " IO submitted\n", total_submitted_io);
|
2015-12-02 21:18:25 +00:00
|
|
|
|
2015-10-19 05:52:57 +00:00
|
|
|
if (total_submitted_io != (total_completed_io + total_completed_err_io)) {
|
|
|
|
fprintf(stderr, "Some IO are missing......\n");
|
2015-12-02 21:18:25 +00:00
|
|
|
return -1;
|
2015-10-19 05:52:57 +00:00
|
|
|
}
|
2015-12-02 21:18:25 +00:00
|
|
|
|
|
|
|
return 0;
|
2015-10-19 05:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
parse_args(int argc, char **argv)
|
|
|
|
{
|
|
|
|
const char *workload_type;
|
|
|
|
int op;
|
|
|
|
bool mix_specified = false;
|
2019-01-23 01:57:05 +00:00
|
|
|
long int val;
|
2015-10-19 05:52:57 +00:00
|
|
|
|
2017-04-24 18:14:41 +00:00
|
|
|
/* default value */
|
2015-10-19 05:52:57 +00:00
|
|
|
g_queue_depth = 0;
|
|
|
|
g_io_size_bytes = 0;
|
|
|
|
workload_type = NULL;
|
|
|
|
g_time_in_sec = 0;
|
|
|
|
g_rw_percentage = -1;
|
|
|
|
|
2022-09-16 03:36:44 +00:00
|
|
|
while ((op = getopt(argc, argv, "o:q:t:w:M:")) != -1) {
|
2019-01-23 01:57:05 +00:00
|
|
|
if (op == 'w') {
|
2015-10-19 05:52:57 +00:00
|
|
|
workload_type = optarg;
|
2019-01-23 01:57:05 +00:00
|
|
|
} else if (op == '?') {
|
2015-10-19 05:52:57 +00:00
|
|
|
usage(argv[0]);
|
2019-01-23 01:57:05 +00:00
|
|
|
return -EINVAL;
|
|
|
|
} else {
|
|
|
|
val = spdk_strtol(optarg, 10);
|
|
|
|
if (val < 0) {
|
|
|
|
fprintf(stderr, "Converting a string to integer failed\n");
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
switch (op) {
|
|
|
|
case 'q':
|
|
|
|
g_queue_depth = val;
|
|
|
|
break;
|
2022-09-16 03:36:44 +00:00
|
|
|
case 'o':
|
2019-01-23 01:57:05 +00:00
|
|
|
g_io_size_bytes = val;
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
g_time_in_sec = val;
|
|
|
|
break;
|
|
|
|
case 'M':
|
|
|
|
g_rw_percentage = val;
|
|
|
|
mix_specified = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage(argv[0]);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2015-10-19 05:52:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!g_queue_depth) {
|
|
|
|
usage(argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (!g_io_size_bytes) {
|
|
|
|
usage(argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (!workload_type) {
|
|
|
|
usage(argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (!g_time_in_sec) {
|
|
|
|
usage(argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(workload_type, "read") &&
|
|
|
|
strcmp(workload_type, "write") &&
|
|
|
|
strcmp(workload_type, "randread") &&
|
|
|
|
strcmp(workload_type, "randwrite") &&
|
|
|
|
strcmp(workload_type, "rw") &&
|
|
|
|
strcmp(workload_type, "randrw")) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"io pattern type must be one of\n"
|
|
|
|
"(read, write, randread, randwrite, rw, randrw)\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(workload_type, "read") ||
|
|
|
|
!strcmp(workload_type, "randread")) {
|
|
|
|
g_rw_percentage = 100;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(workload_type, "write") ||
|
|
|
|
!strcmp(workload_type, "randwrite")) {
|
|
|
|
g_rw_percentage = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(workload_type, "read") ||
|
|
|
|
!strcmp(workload_type, "randread") ||
|
|
|
|
!strcmp(workload_type, "write") ||
|
|
|
|
!strcmp(workload_type, "randwrite")) {
|
|
|
|
if (mix_specified) {
|
|
|
|
fprintf(stderr, "Ignoring -M option... Please use -M option"
|
|
|
|
" only when using rw or randrw.\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(workload_type, "rw") ||
|
|
|
|
!strcmp(workload_type, "randrw")) {
|
|
|
|
if (g_rw_percentage < 0 || g_rw_percentage > 100) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"-M must be specified to value from 0 to 100 "
|
|
|
|
"for rw or randrw.\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(workload_type, "read") ||
|
|
|
|
!strcmp(workload_type, "write") ||
|
|
|
|
!strcmp(workload_type, "rw")) {
|
|
|
|
g_is_random = 0;
|
|
|
|
} else {
|
|
|
|
g_is_random = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2020-09-28 01:49:25 +00:00
|
|
|
register_worker(void)
|
2015-10-19 05:52:57 +00:00
|
|
|
{
|
|
|
|
struct worker_thread *worker;
|
|
|
|
|
|
|
|
worker = malloc(sizeof(struct worker_thread));
|
|
|
|
if (worker == NULL) {
|
|
|
|
perror("worker_thread malloc");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(worker, 0, sizeof(struct worker_thread));
|
2020-09-28 01:49:25 +00:00
|
|
|
TAILQ_INIT(&worker->ns_ctx);
|
2017-11-20 05:41:51 +00:00
|
|
|
worker->lcore = spdk_env_get_current_core();
|
2015-10-19 05:52:57 +00:00
|
|
|
|
2020-09-28 01:49:25 +00:00
|
|
|
g_worker = worker;
|
2015-10-19 05:52:57 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-01-29 20:15:29 +00:00
|
|
|
|
|
|
|
static bool
|
2016-12-09 22:09:28 +00:00
|
|
|
probe_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid,
|
2016-10-31 23:55:14 +00:00
|
|
|
struct spdk_nvme_ctrlr_opts *opts)
|
2015-10-19 05:52:57 +00:00
|
|
|
{
|
2019-05-10 17:48:53 +00:00
|
|
|
opts->disable_error_logging = true;
|
2016-01-29 20:15:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-10-19 05:52:57 +00:00
|
|
|
|
2016-01-29 20:15:29 +00:00
|
|
|
static void
|
2016-12-09 22:09:28 +00:00
|
|
|
attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid,
|
2016-10-31 23:55:14 +00:00
|
|
|
struct spdk_nvme_ctrlr *ctrlr, const struct spdk_nvme_ctrlr_opts *opts)
|
2016-01-29 20:15:29 +00:00
|
|
|
{
|
2019-05-14 20:32:58 +00:00
|
|
|
if (trid->trtype == SPDK_NVME_TRANSPORT_PCIE) {
|
|
|
|
struct spdk_pci_device *dev = spdk_nvme_ctrlr_get_pci_device(ctrlr);
|
|
|
|
|
|
|
|
/* QEMU emulated SSDs can't handle this test, so we will skip
|
|
|
|
* them. QEMU NVMe SSDs report themselves as VID == Intel. So we need
|
|
|
|
* to check this specific 0x5845 device ID to know whether it's QEMU
|
|
|
|
* or not.
|
|
|
|
*/
|
|
|
|
if (spdk_pci_device_get_vendor_id(dev) == SPDK_PCI_VID_INTEL &&
|
|
|
|
spdk_pci_device_get_device_id(dev) == 0x5845) {
|
|
|
|
g_qemu_ssd_found = true;
|
|
|
|
printf("Skipping QEMU NVMe SSD at %s\n", trid->traddr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-29 20:15:29 +00:00
|
|
|
register_ctrlr(ctrlr);
|
|
|
|
}
|
2015-10-19 05:52:57 +00:00
|
|
|
|
2016-01-29 20:15:29 +00:00
|
|
|
static int
|
|
|
|
register_controllers(void)
|
|
|
|
{
|
|
|
|
printf("Initializing NVMe Controllers\n");
|
2015-10-19 05:52:57 +00:00
|
|
|
|
2016-12-09 22:33:47 +00:00
|
|
|
if (spdk_nvme_probe(NULL, NULL, probe_cb, attach_cb, NULL) != 0) {
|
2016-02-10 18:26:12 +00:00
|
|
|
fprintf(stderr, "spdk_nvme_probe() failed\n");
|
2016-01-29 20:15:29 +00:00
|
|
|
return 1;
|
2015-10-19 05:52:57 +00:00
|
|
|
}
|
|
|
|
|
2016-01-29 20:15:29 +00:00
|
|
|
return 0;
|
2015-10-19 05:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
unregister_controllers(void)
|
|
|
|
{
|
2020-09-28 01:49:25 +00:00
|
|
|
struct ctrlr_entry *entry, *tmp;
|
2020-10-16 00:02:22 +00:00
|
|
|
struct spdk_nvme_detach_ctx *detach_ctx = NULL;
|
2015-10-19 05:52:57 +00:00
|
|
|
|
2020-09-28 01:49:25 +00:00
|
|
|
TAILQ_FOREACH_SAFE(entry, &g_controllers, link, tmp) {
|
|
|
|
TAILQ_REMOVE(&g_controllers, entry, link);
|
2020-10-16 00:02:22 +00:00
|
|
|
spdk_nvme_detach_async(entry->ctrlr, &detach_ctx);
|
2015-10-19 05:52:57 +00:00
|
|
|
free(entry);
|
|
|
|
}
|
2020-10-16 00:02:22 +00:00
|
|
|
|
2021-06-24 20:30:55 +00:00
|
|
|
if (detach_ctx) {
|
|
|
|
spdk_nvme_detach_poll(detach_ctx);
|
2020-10-16 00:02:22 +00:00
|
|
|
}
|
2015-10-19 05:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
associate_workers_with_ns(void)
|
|
|
|
{
|
2020-09-28 01:49:25 +00:00
|
|
|
struct ns_entry *entry = TAILQ_FIRST(&g_namespaces);
|
|
|
|
struct worker_thread *worker = g_worker;
|
2015-10-19 05:52:57 +00:00
|
|
|
struct ns_worker_ctx *ns_ctx;
|
|
|
|
int i, count;
|
|
|
|
|
|
|
|
count = g_num_namespaces;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
2016-01-06 06:51:14 +00:00
|
|
|
if (entry == NULL) {
|
|
|
|
break;
|
|
|
|
}
|
2015-10-19 05:52:57 +00:00
|
|
|
ns_ctx = malloc(sizeof(struct ns_worker_ctx));
|
|
|
|
if (!ns_ctx) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
memset(ns_ctx, 0, sizeof(*ns_ctx));
|
|
|
|
|
|
|
|
printf("Associating %s with lcore %d\n", entry->name, worker->lcore);
|
|
|
|
ns_ctx->entry = entry;
|
2020-09-28 01:49:25 +00:00
|
|
|
TAILQ_INSERT_TAIL(&worker->ns_ctx, ns_ctx, link);
|
2015-10-19 05:52:57 +00:00
|
|
|
|
2020-09-28 01:49:25 +00:00
|
|
|
entry = TAILQ_NEXT(entry, link);;
|
2015-10-19 05:52:57 +00:00
|
|
|
if (entry == NULL) {
|
2020-09-28 01:49:25 +00:00
|
|
|
entry = TAILQ_FIRST(&g_namespaces);
|
2015-10-19 05:52:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-09-28 01:49:25 +00:00
|
|
|
static void
|
|
|
|
unregister_worker(void)
|
|
|
|
{
|
|
|
|
struct ns_worker_ctx *ns_ctx, *tmp;
|
|
|
|
|
|
|
|
assert(g_worker != NULL);
|
|
|
|
|
|
|
|
TAILQ_FOREACH_SAFE(ns_ctx, &g_worker->ns_ctx, link, tmp) {
|
|
|
|
TAILQ_REMOVE(&g_worker->ns_ctx, ns_ctx, link);
|
|
|
|
free(ns_ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(g_worker);
|
|
|
|
g_worker = NULL;
|
|
|
|
}
|
|
|
|
|
2015-10-19 05:52:57 +00:00
|
|
|
static int
|
2019-08-08 02:30:27 +00:00
|
|
|
run_nvme_reset_cycle(void)
|
2015-10-19 05:52:57 +00:00
|
|
|
{
|
2020-09-28 01:49:25 +00:00
|
|
|
struct worker_thread *worker = g_worker;
|
2015-10-19 05:52:57 +00:00
|
|
|
struct ns_worker_ctx *ns_ctx;
|
|
|
|
|
2020-09-28 01:49:25 +00:00
|
|
|
if (work_fn(worker) != 0) {
|
2015-12-02 21:18:25 +00:00
|
|
|
return -1;
|
2015-10-19 05:52:57 +00:00
|
|
|
}
|
|
|
|
|
2015-12-02 21:18:25 +00:00
|
|
|
if (print_stats() != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2015-10-19 05:52:57 +00:00
|
|
|
|
2020-09-28 01:49:25 +00:00
|
|
|
TAILQ_FOREACH(ns_ctx, &worker->ns_ctx, link) {
|
2015-10-19 05:52:57 +00:00
|
|
|
ns_ctx->io_completed = 0;
|
|
|
|
ns_ctx->io_completed_error = 0;
|
|
|
|
ns_ctx->io_submitted = 0;
|
|
|
|
ns_ctx->is_draining = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-11-20 05:41:51 +00:00
|
|
|
static void
|
2020-09-28 01:49:25 +00:00
|
|
|
free_tasks(void)
|
2017-11-20 05:41:51 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2022-06-22 21:35:04 +00:00
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
2015-10-19 05:52:57 +00:00
|
|
|
{
|
2018-03-02 19:49:36 +00:00
|
|
|
int rc;
|
|
|
|
int i;
|
2017-01-12 18:25:17 +00:00
|
|
|
struct spdk_env_opts opts;
|
|
|
|
|
2015-10-19 05:52:57 +00:00
|
|
|
|
|
|
|
rc = parse_args(argc, argv);
|
|
|
|
if (rc != 0) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2017-09-21 03:24:03 +00:00
|
|
|
spdk_env_opts_init(&opts);
|
|
|
|
opts.name = "reset";
|
|
|
|
opts.core_mask = "0x1";
|
2018-08-02 06:34:26 +00:00
|
|
|
opts.shm_id = 0;
|
2017-12-18 19:57:01 +00:00
|
|
|
if (spdk_env_init(&opts) < 0) {
|
|
|
|
fprintf(stderr, "Unable to initialize SPDK env\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2017-09-21 03:24:03 +00:00
|
|
|
|
2018-08-02 06:34:26 +00:00
|
|
|
if (register_controllers() != 0) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-09-28 01:49:25 +00:00
|
|
|
if (TAILQ_EMPTY(&g_controllers)) {
|
2018-08-02 06:34:26 +00:00
|
|
|
printf("No NVMe controller found, %s exiting\n", argv[0]);
|
2019-05-14 20:32:58 +00:00
|
|
|
return g_qemu_ssd_found ? 0 : 1;
|
2018-08-02 06:34:26 +00:00
|
|
|
}
|
|
|
|
|
2017-11-20 05:41:51 +00:00
|
|
|
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;
|
|
|
|
}
|
2015-10-19 05:52:57 +00:00
|
|
|
|
2016-08-18 19:52:48 +00:00
|
|
|
g_tsc_rate = spdk_get_ticks_hz();
|
2015-10-19 05:52:57 +00:00
|
|
|
|
2020-09-28 01:49:25 +00:00
|
|
|
if (register_worker() != 0) {
|
2015-10-19 05:52:57 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (associate_workers_with_ns() != 0) {
|
2015-12-02 21:18:25 +00:00
|
|
|
rc = 1;
|
|
|
|
goto cleanup;
|
2015-10-19 05:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
printf("Initialization complete. Launching workers.\n");
|
|
|
|
|
|
|
|
for (i = 2; i >= 0; i--) {
|
2019-08-08 02:30:27 +00:00
|
|
|
rc = run_nvme_reset_cycle();
|
2015-10-19 05:52:57 +00:00
|
|
|
if (rc != 0) {
|
2015-12-02 21:18:25 +00:00
|
|
|
goto cleanup;
|
2015-10-19 05:52:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-02 21:18:25 +00:00
|
|
|
cleanup:
|
2015-10-19 05:52:57 +00:00
|
|
|
unregister_controllers();
|
2020-10-19 14:36:25 +00:00
|
|
|
unregister_worker();
|
2020-09-28 01:49:25 +00:00
|
|
|
free_tasks();
|
2015-10-19 05:52:57 +00:00
|
|
|
|
|
|
|
if (rc != 0) {
|
2021-11-25 01:40:59 +00:00
|
|
|
fprintf(stderr, "%s: errors occurred\n", argv[0]);
|
2015-10-19 05:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|