Commit 20b5c460 authored by Tomasz Zawadzki's avatar Tomasz Zawadzki
Browse files

example/accel_perf: cleanup worker on init errors



There are multiple paths where worker initialization can fail
in _init_thread(). Multiple spdk_threads should not call spdk_app_stop(),
instead each one should call exit on itself and only the last one calls
the spdk_app_stop().

This patch fixes this by removing spdk_app_stop() from _init_thread().
Instead consolidate that through unregister_worker() that is called
at the end of shutdown_cb().

When worker cannot be allocated, thread_exit can be called immediately.

Signed-off-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Change-Id: Ia6d2d409e51c859e24cd02b0799769be535db3f7
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/21064


Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Reviewed-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
parent 97f445d7
Loading
Loading
Loading
Loading
+18 −7
Original line number Diff line number Diff line
@@ -273,17 +273,23 @@ unregister_worker(void *arg1)
{
	struct worker_thread *worker = arg1;

	if (worker->ch) {
		spdk_accel_get_opcode_stats(worker->ch, worker->workload,
					    &worker->stats, sizeof(worker->stats));
	free(worker->task_base);
		spdk_put_io_channel(worker->ch);
		worker->ch = NULL;
	}
	free(worker->task_base);
	spdk_thread_exit(spdk_get_thread());
	pthread_mutex_lock(&g_workers_lock);
	assert(g_num_workers >= 1);
	if (--g_num_workers == 0) {
		pthread_mutex_unlock(&g_workers_lock);
		/* Only dump results on successful runs */
		if (g_rc == 0) {
			g_rc = dump_result();
		spdk_app_stop(0);
		}
		spdk_app_stop(g_rc);
	} else {
		pthread_mutex_unlock(&g_workers_lock);
	}
@@ -774,6 +780,8 @@ _worker_stop(void *arg)
	return SPDK_POLLER_BUSY;
}

static void shutdown_cb(void);

static void
_init_thread(void *arg1)
{
@@ -786,7 +794,8 @@ _init_thread(void *arg1)
	if (worker == NULL) {
		fprintf(stderr, "Unable to allocate worker\n");
		free(display);
		return;
		spdk_thread_exit(spdk_get_thread());
		goto no_worker;
	}

	worker->workload = g_workload_selection;
@@ -843,7 +852,9 @@ error:

	_free_task_buffers_in_pool(worker);
	free(worker->task_base);
	spdk_app_stop(-1);
no_worker:
	shutdown_cb();
	g_rc = -1;
}

static void