Commit c2605379 authored by Ziye Yang's avatar Ziye Yang Committed by Tomasz Zawadzki
Browse files

accel_perf: check accel engine usage in accel_perf_start function.



In accel_done function, we use g_using_sw_engine to
determine to directly call _accel_done or use thread message
passing way.

However when we get the capability and determine the
value of g_using_sw_engine in mulitple cases. We do not
protect the value of g_num_workers. Then if we use CPU mode
to do test, g_using_sw_engine will not set to be false
in racing condition. Since the value of g_num_workers can be
> 1 when we do the check, i.e., it is a TOC2TOU issue.

The solution is that we check the g_using_sw_engine in
accel_perf_start function.

Fixes issue #2084

Change-Id: I55c18e0443120adb698d5bd27d4522df09f6dcab
Signed-off-by: default avatarZiye Yang <ziye.yang@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/9151


Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
parent 6479ddb3
Loading
Loading
Loading
Loading
+21 −10
Original line number Diff line number Diff line
@@ -820,7 +820,6 @@ _init_thread(void *arg1)
	struct accel_batch *tmp;
	struct accel_batch *worker_batch = NULL;
	struct display_info *display = arg1;
	uint64_t capabilities;

	worker = calloc(1, sizeof(*worker));
	if (worker == NULL) {
@@ -841,15 +840,6 @@ _init_thread(void *arg1)
	pthread_mutex_unlock(&g_workers_lock);
	worker->ch = spdk_accel_engine_get_io_channel();

	if (g_num_workers == 1) {
		capabilities = spdk_accel_get_capabilities(worker->ch);
		if ((capabilities & g_workload_selection) != g_workload_selection) {
			g_using_sw_engine = true;
			SPDK_WARNLOG("The selected workload is not natively supported by the current engine\n");
			SPDK_WARNLOG("The software engine will be used instead.\n\n");
		}
	}

	TAILQ_INIT(&worker->tasks_pool);

	if (g_ops_per_batch > 0) {
@@ -1004,6 +994,25 @@ accel_done(void *cb_arg, int status)
	}
}

static inline void
identify_accel_engine_usage(void)
{
	struct spdk_io_channel *ch;
	uint64_t capabilities;

	ch = spdk_accel_engine_get_io_channel();
	assert(ch != NULL);

	capabilities = spdk_accel_get_capabilities(ch);
	if ((capabilities & g_workload_selection) != g_workload_selection) {
		g_using_sw_engine = true;
		SPDK_WARNLOG("The selected workload is not natively supported by the current engine\n");
		SPDK_WARNLOG("The software engine will be used instead.\n\n");
	}

	spdk_put_io_channel(ch);
}

static void
accel_perf_start(void *arg1)
{
@@ -1014,6 +1023,8 @@ accel_perf_start(void *arg1)
	struct spdk_thread *thread;
	struct display_info *display;

	identify_accel_engine_usage();

	g_tsc_rate = spdk_get_ticks_hz();
	g_tsc_end = spdk_get_ticks() + g_time_in_sec * g_tsc_rate;