Commit 2b62e64d authored by Konrad Sztyber's avatar Konrad Sztyber Committed by Tomasz Zawadzki
Browse files

bdevperf: allocate lcore threads when creating jobs



Previously, lcore threads were allocated when creating job configs,
which is done only once at startup, but are freed when the test is
finished in bdevperf_test_done(), which would lead to a segfault when
bdevperf was started with the `-z` option and the `perform_tests` RPC
was sent more than once.

Signed-off-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Change-Id: I627c97d505cda6faf530117c0daeea0fe7254094
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/20270


Reviewed-by: default avatarKrzysztof Karas <krzysztof.karas@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent da5ec81f
Loading
Loading
Loading
Loading
+28 −28
Original line number Diff line number Diff line
@@ -1903,6 +1903,27 @@ get_lcore_thread(uint32_t lcore)
	return NULL;
}

static void
create_lcore_thread(uint32_t lcore)
{
	struct lcore_thread *lthread;
	struct spdk_cpuset cpumask = {};
	char name[32];

	lthread = calloc(1, sizeof(*lthread));
	assert(lthread != NULL);

	lthread->lcore = lcore;

	snprintf(name, sizeof(name), "lcore_%u", lcore);
	spdk_cpuset_set_cpu(&cpumask, lcore, true);

	lthread->thread = spdk_thread_create(name, &cpumask);
	assert(lthread->thread != NULL);

	TAILQ_INSERT_TAIL(&g_lcore_thread_list, lthread, link);
}

static void
bdevperf_construct_jobs(void)
{
@@ -1911,8 +1932,15 @@ bdevperf_construct_jobs(void)
	struct job_config *config;
	struct spdk_bdev *bdev;
	const char *filenames;
	uint32_t i;
	int rc;

	if (g_one_thread_per_lcore) {
		SPDK_ENV_FOREACH_CORE(i) {
			create_lcore_thread(i);
		}
	}

	TAILQ_FOREACH(config, &job_config_list, link) {
		filenames = config->filename;

@@ -2036,32 +2064,10 @@ bdevperf_construct_job_config(void *ctx, struct spdk_bdev *bdev)
	return make_cli_job_config(spdk_bdev_get_name(bdev), 0, 0);
}

static void
create_lcore_thread(uint32_t lcore)
{
	struct lcore_thread *lthread;
	struct spdk_cpuset cpumask = {};
	char name[32];

	lthread = calloc(1, sizeof(*lthread));
	assert(lthread != NULL);

	lthread->lcore = lcore;

	snprintf(name, sizeof(name), "lcore_%u", lcore);
	spdk_cpuset_set_cpu(&cpumask, lcore, true);

	lthread->thread = spdk_thread_create(name, &cpumask);
	assert(lthread->thread != NULL);

	TAILQ_INSERT_TAIL(&g_lcore_thread_list, lthread, link);
}

static void
bdevperf_construct_job_configs(void)
{
	struct spdk_bdev *bdev;
	uint32_t i;

	/* 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.
@@ -2084,12 +2090,6 @@ bdevperf_construct_job_configs(void)
		goto end;
	}

	if (g_one_thread_per_lcore) {
		SPDK_ENV_FOREACH_CORE(i) {
			create_lcore_thread(i);
		}
	}

	if (g_multithread_mode) {
		bdevperf_construct_multithread_job_configs();
	} else if (g_job_bdev_name != NULL) {