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 <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: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Ziye Yang 2021-08-11 13:07:54 -04:00 committed by Tomasz Zawadzki
parent 6479ddb358
commit c260537919

View File

@ -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;