bdevperf: config file: simplify old constructors
Instead of calling bdevperf_construct_job() directly, create a job_config instance that would express the same semantics and then use bdevperf_construct_config_jobs() to create and run actual jobs. The goal is to unify methods and reduce code duplication. Change-Id: I724e5788ea74868c9e9c8128d658e720d211f253 Signed-off-by: Vitaliy Mysak <vitaliy.mysak@intel.com> Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/3510 Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
parent
32b2d78a3c
commit
13a0ac2e20
@ -1124,6 +1124,24 @@ construct_job_thread(struct spdk_cpuset *cpumask, const char *tag)
|
|||||||
return spdk_thread_create(thread_name, cpumask);
|
return spdk_thread_create(thread_name, cpumask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint32_t
|
||||||
|
_get_next_core(void)
|
||||||
|
{
|
||||||
|
static uint32_t current_core = SPDK_ENV_LCORE_ID_ANY;
|
||||||
|
|
||||||
|
if (current_core == SPDK_ENV_LCORE_ID_ANY) {
|
||||||
|
current_core = spdk_env_get_first_core();
|
||||||
|
return current_core;
|
||||||
|
}
|
||||||
|
|
||||||
|
current_core = spdk_env_get_next_core(current_core);
|
||||||
|
if (current_core == SPDK_ENV_LCORE_ID_ANY) {
|
||||||
|
current_core = spdk_env_get_first_core();
|
||||||
|
}
|
||||||
|
|
||||||
|
return current_core;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_bdevperf_construct_job(void *ctx)
|
_bdevperf_construct_job(void *ctx)
|
||||||
{
|
{
|
||||||
@ -1151,7 +1169,7 @@ end:
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
bdevperf_construct_job(struct spdk_bdev *bdev, struct job_config *config,
|
bdevperf_construct_job(struct spdk_bdev *bdev, struct job_config *config,
|
||||||
struct spdk_thread *thread, uint32_t offset, uint32_t length)
|
struct spdk_thread *thread)
|
||||||
{
|
{
|
||||||
struct bdevperf_job *job;
|
struct bdevperf_job *job;
|
||||||
struct bdevperf_task *task;
|
struct bdevperf_task *task;
|
||||||
@ -1176,8 +1194,8 @@ bdevperf_construct_job(struct spdk_bdev *bdev, struct job_config *config,
|
|||||||
}
|
}
|
||||||
|
|
||||||
job->workload_type = g_workload_type;
|
job->workload_type = g_workload_type;
|
||||||
job->io_size = config ? config->bs : g_io_size;
|
job->io_size = config->bs;
|
||||||
job->rw_percentage = config ? config->rwmixread : g_rw_percentage;
|
job->rw_percentage = config->rwmixread;
|
||||||
job->is_random = g_is_random;
|
job->is_random = g_is_random;
|
||||||
job->verify = g_verify;
|
job->verify = g_verify;
|
||||||
job->reset = g_reset;
|
job->reset = g_reset;
|
||||||
@ -1186,7 +1204,7 @@ bdevperf_construct_job(struct spdk_bdev *bdev, struct job_config *config,
|
|||||||
job->write_zeroes = g_write_zeroes;
|
job->write_zeroes = g_write_zeroes;
|
||||||
job->flush = g_flush;
|
job->flush = g_flush;
|
||||||
job->abort = g_abort;
|
job->abort = g_abort;
|
||||||
job->queue_depth = config ? config->iodepth : g_queue_depth;
|
job->queue_depth = config->iodepth;
|
||||||
|
|
||||||
job->bdev = bdev;
|
job->bdev = bdev;
|
||||||
job->io_size_blocks = job->io_size / data_block_size;
|
job->io_size_blocks = job->io_size / data_block_size;
|
||||||
@ -1216,10 +1234,10 @@ bdevperf_construct_job(struct spdk_bdev *bdev, struct job_config *config,
|
|||||||
|
|
||||||
job->offset_in_ios = 0;
|
job->offset_in_ios = 0;
|
||||||
|
|
||||||
if (length != 0) {
|
if (config->length != 0) {
|
||||||
/* Use subset of disk */
|
/* Use subset of disk */
|
||||||
job->size_in_ios = length / job->io_size_blocks;
|
job->size_in_ios = config->length / job->io_size_blocks;
|
||||||
job->ios_base = offset / job->io_size_blocks;
|
job->ios_base = config->offset / job->io_size_blocks;
|
||||||
} else {
|
} else {
|
||||||
/* Use whole disk */
|
/* Use whole disk */
|
||||||
job->size_in_ios = spdk_bdev_get_num_blocks(bdev) / job->io_size_blocks;
|
job->size_in_ios = spdk_bdev_get_num_blocks(bdev) / job->io_size_blocks;
|
||||||
@ -1309,7 +1327,7 @@ bdevperf_construct_config_jobs(void)
|
|||||||
thread = construct_job_thread(&config->cpumask, config->name);
|
thread = construct_job_thread(&config->cpumask, config->name);
|
||||||
assert(thread);
|
assert(thread);
|
||||||
|
|
||||||
rc = bdevperf_construct_job(bdev, config, thread, config->offset, config->length);
|
rc = bdevperf_construct_job(bdev, config, thread);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
g_run_rc = rc;
|
g_run_rc = rc;
|
||||||
return;
|
return;
|
||||||
@ -1317,17 +1335,38 @@ bdevperf_construct_config_jobs(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
make_cli_job_config(const char *filename, int offset, int range)
|
||||||
|
{
|
||||||
|
struct job_config *config = calloc(1, sizeof(*config));
|
||||||
|
|
||||||
|
if (config == NULL) {
|
||||||
|
fprintf(stderr, "Unable to allocate memory for job config\n");
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
config->name = filename;
|
||||||
|
config->filename = filename;
|
||||||
|
spdk_cpuset_zero(&config->cpumask);
|
||||||
|
spdk_cpuset_set_cpu(&config->cpumask, _get_next_core(), true);
|
||||||
|
config->bs = g_io_size;
|
||||||
|
config->iodepth = g_queue_depth;
|
||||||
|
config->rwmixread = g_rw_percentage;
|
||||||
|
config->offset = offset;
|
||||||
|
config->length = range;
|
||||||
|
|
||||||
|
TAILQ_INSERT_TAIL(&job_config_list, config, link);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
bdevperf_construct_multithread_jobs(void)
|
bdevperf_construct_multithread_jobs(void)
|
||||||
{
|
{
|
||||||
struct spdk_bdev *bdev;
|
struct spdk_bdev *bdev;
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
struct spdk_cpuset cpumask;
|
|
||||||
struct spdk_thread *thread;
|
|
||||||
uint32_t num_cores;
|
uint32_t num_cores;
|
||||||
uint32_t blocks_per_job;
|
uint32_t blocks_per_job;
|
||||||
uint32_t offset;
|
uint32_t offset;
|
||||||
int rc;
|
|
||||||
|
|
||||||
num_cores = 0;
|
num_cores = 0;
|
||||||
SPDK_ENV_FOREACH_CORE(i) {
|
SPDK_ENV_FOREACH_CORE(i) {
|
||||||
@ -1350,16 +1389,9 @@ bdevperf_construct_multithread_jobs(void)
|
|||||||
offset = 0;
|
offset = 0;
|
||||||
|
|
||||||
SPDK_ENV_FOREACH_CORE(i) {
|
SPDK_ENV_FOREACH_CORE(i) {
|
||||||
spdk_cpuset_zero(&cpumask);
|
g_run_rc = make_cli_job_config(g_job_bdev_name, offset, blocks_per_job);
|
||||||
spdk_cpuset_set_cpu(&cpumask, i, true);
|
if (g_run_rc) {
|
||||||
thread = construct_job_thread(&cpumask, spdk_bdev_get_name(bdev));
|
return;
|
||||||
assert(thread);
|
|
||||||
|
|
||||||
/* Construct the job */
|
|
||||||
rc = bdevperf_construct_job(bdev, NULL, thread, offset, blocks_per_job);
|
|
||||||
if (rc < 0) {
|
|
||||||
g_run_rc = rc;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
offset += blocks_per_job;
|
offset += blocks_per_job;
|
||||||
@ -1371,56 +1403,24 @@ bdevperf_construct_multithread_jobs(void)
|
|||||||
offset = 0;
|
offset = 0;
|
||||||
|
|
||||||
SPDK_ENV_FOREACH_CORE(i) {
|
SPDK_ENV_FOREACH_CORE(i) {
|
||||||
spdk_cpuset_zero(&cpumask);
|
g_run_rc = make_cli_job_config(spdk_bdev_get_name(bdev),
|
||||||
spdk_cpuset_set_cpu(&cpumask, i, true);
|
offset, blocks_per_job);
|
||||||
thread = construct_job_thread(&cpumask, spdk_bdev_get_name(bdev));
|
if (g_run_rc) {
|
||||||
assert(thread);
|
return;
|
||||||
|
|
||||||
/* Construct the job */
|
|
||||||
rc = bdevperf_construct_job(bdev, NULL, thread, offset, blocks_per_job);
|
|
||||||
if (rc < 0) {
|
|
||||||
g_run_rc = rc;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
offset += blocks_per_job;
|
offset += blocks_per_job;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_run_rc != 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
bdev = spdk_bdev_next_leaf(bdev);
|
bdev = spdk_bdev_next_leaf(bdev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t
|
|
||||||
_get_next_core(void)
|
|
||||||
{
|
|
||||||
static uint32_t current_core = SPDK_ENV_LCORE_ID_ANY;
|
|
||||||
|
|
||||||
if (current_core == SPDK_ENV_LCORE_ID_ANY) {
|
|
||||||
current_core = spdk_env_get_first_core();
|
|
||||||
return current_core;
|
|
||||||
}
|
|
||||||
|
|
||||||
current_core = spdk_env_get_next_core(current_core);
|
|
||||||
if (current_core == SPDK_ENV_LCORE_ID_ANY) {
|
|
||||||
current_core = spdk_env_get_first_core();
|
|
||||||
}
|
|
||||||
|
|
||||||
return current_core;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
bdevperf_construct_jobs(void)
|
bdevperf_construct_jobs(void)
|
||||||
{
|
{
|
||||||
struct spdk_bdev *bdev;
|
struct spdk_bdev *bdev;
|
||||||
uint32_t lcore;
|
|
||||||
struct spdk_cpuset cpumask;
|
|
||||||
struct spdk_thread *thread;
|
|
||||||
int rc;
|
|
||||||
|
|
||||||
/* There are three different modes for allocating jobs. Standard mode
|
/* There are three different modes for allocating jobs. Standard mode
|
||||||
* (the default) creates one spdk_thread per bdev and runs the I/O job there.
|
* (the default) creates one spdk_thread per bdev and runs the I/O job there.
|
||||||
@ -1441,7 +1441,6 @@ bdevperf_construct_jobs(void)
|
|||||||
g_construct_job_count = 1;
|
g_construct_job_count = 1;
|
||||||
|
|
||||||
if (g_bdevperf_conf) {
|
if (g_bdevperf_conf) {
|
||||||
bdevperf_construct_config_jobs();
|
|
||||||
goto end;
|
goto end;
|
||||||
} else if (g_multithread_mode) {
|
} else if (g_multithread_mode) {
|
||||||
bdevperf_construct_multithread_jobs();
|
bdevperf_construct_multithread_jobs();
|
||||||
@ -1451,18 +1450,8 @@ bdevperf_construct_jobs(void)
|
|||||||
if (g_job_bdev_name != NULL) {
|
if (g_job_bdev_name != NULL) {
|
||||||
bdev = spdk_bdev_get_by_name(g_job_bdev_name);
|
bdev = spdk_bdev_get_by_name(g_job_bdev_name);
|
||||||
if (bdev) {
|
if (bdev) {
|
||||||
lcore = _get_next_core();
|
|
||||||
|
|
||||||
spdk_cpuset_zero(&cpumask);
|
|
||||||
spdk_cpuset_set_cpu(&cpumask, lcore, true);
|
|
||||||
thread = construct_job_thread(&cpumask, spdk_bdev_get_name(bdev));
|
|
||||||
assert(thread);
|
|
||||||
|
|
||||||
/* Construct the job */
|
/* Construct the job */
|
||||||
rc = bdevperf_construct_job(bdev, NULL, thread, 0, 0);
|
g_run_rc = make_cli_job_config(g_job_bdev_name, 0, 0);
|
||||||
if (rc < 0) {
|
|
||||||
g_run_rc = rc;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Unable to find bdev '%s'\n", g_job_bdev_name);
|
fprintf(stderr, "Unable to find bdev '%s'\n", g_job_bdev_name);
|
||||||
}
|
}
|
||||||
@ -1470,17 +1459,9 @@ bdevperf_construct_jobs(void)
|
|||||||
bdev = spdk_bdev_first_leaf();
|
bdev = spdk_bdev_first_leaf();
|
||||||
|
|
||||||
while (bdev != NULL) {
|
while (bdev != NULL) {
|
||||||
lcore = _get_next_core();
|
|
||||||
|
|
||||||
spdk_cpuset_zero(&cpumask);
|
|
||||||
spdk_cpuset_set_cpu(&cpumask, lcore, true);
|
|
||||||
thread = construct_job_thread(&cpumask, spdk_bdev_get_name(bdev));
|
|
||||||
assert(thread);
|
|
||||||
|
|
||||||
/* Construct the job */
|
/* Construct the job */
|
||||||
rc = bdevperf_construct_job(bdev, NULL, thread, 0, 0);
|
g_run_rc = make_cli_job_config(spdk_bdev_get_name(bdev), 0, 0);
|
||||||
if (rc < 0) {
|
if (g_run_rc) {
|
||||||
g_run_rc = rc;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1489,6 +1470,10 @@ bdevperf_construct_jobs(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
end:
|
end:
|
||||||
|
if (g_run_rc == 0) {
|
||||||
|
bdevperf_construct_config_jobs();
|
||||||
|
}
|
||||||
|
|
||||||
if (--g_construct_job_count == 0) {
|
if (--g_construct_job_count == 0) {
|
||||||
if (g_run_rc != 0) {
|
if (g_run_rc != 0) {
|
||||||
/* Something failed. */
|
/* Something failed. */
|
||||||
|
Loading…
Reference in New Issue
Block a user