Skip to content

Commit

Permalink
accel_perf: check accel engine usage in accel_perf_start function.
Browse files Browse the repository at this point in the history
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 spdk#2084

Change-Id: I55c18e0443120adb698d5bd27d4522df09f6dcab
Signed-off-by: Ziye Yang <[email protected]>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/9151
Community-CI: Broadcom CI <[email protected]>
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <[email protected]>
Reviewed-by: Jim Harris <[email protected]>
Reviewed-by: Ben Walker <[email protected]>
  • Loading branch information
Ziye Yang authored and tomzawadzki committed Aug 16, 2021
1 parent 6479ddb commit c260537
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions examples/accel/perf/accel_perf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
{
Expand All @@ -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;

Expand Down

0 comments on commit c260537

Please sign in to comment.