From c26053791948349b33454b3632fddac82b91114d Mon Sep 17 00:00:00 2001 From: Ziye Yang Date: Wed, 11 Aug 2021 13:07:54 -0400 Subject: [PATCH] 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: Ziye Yang Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/9151 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Ben Walker --- examples/accel/perf/accel_perf.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/examples/accel/perf/accel_perf.c b/examples/accel/perf/accel_perf.c index 4e846a900c..d9c184ec84 100644 --- a/examples/accel/perf/accel_perf.c +++ b/examples/accel/perf/accel_perf.c @@ -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;