test/unit/ftl: Fix rwb_parallel unit test

This test was causing rare random failures of unit tests

Change-Id: I3031ed9a7f01018f093d9856b719b7604c5e30f1
Signed-off-by: Wojciech Malikowski <wojciech.malikowski@intel.com>
Reviewed-on: https://review.gerrithub.io/c/441875
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: Jakub Radtke <jakub.radtke@intel.com>
Reviewed-by: Konrad Sztyber <konrad.sztyber@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
This commit is contained in:
Wojciech Malikowski 2019-01-24 05:07:30 -05:00 committed by Ben Walker
parent d010fe2602
commit 363e48d970

View File

@ -184,7 +184,7 @@ test_rwb_worker(void *ctx)
{ {
#define ENTRIES_PER_WORKER (16 * RWB_ENTRY_COUNT) #define ENTRIES_PER_WORKER (16 * RWB_ENTRY_COUNT)
struct ftl_rwb_entry *entry; struct ftl_rwb_entry *entry;
bool *done = ctx; unsigned int *num_done = ctx;
size_t i; size_t i;
for (i = 0; i < ENTRIES_PER_WORKER; ++i) { for (i = 0; i < ENTRIES_PER_WORKER; ++i) {
@ -201,7 +201,7 @@ test_rwb_worker(void *ctx)
} }
} }
__atomic_store_n(done, true, __ATOMIC_SEQ_CST); __atomic_fetch_add(num_done, 1, __ATOMIC_SEQ_CST);
return NULL; return NULL;
} }
@ -212,14 +212,14 @@ test_rwb_parallel(void)
struct ftl_rwb_entry *entry; struct ftl_rwb_entry *entry;
#define NUM_PARALLEL_WORKERS 4 #define NUM_PARALLEL_WORKERS 4
pthread_t workers[NUM_PARALLEL_WORKERS]; pthread_t workers[NUM_PARALLEL_WORKERS];
bool done[NUM_PARALLEL_WORKERS]; unsigned int num_done = 0;
size_t i, num_entries = 0; size_t i, num_entries = 0;
int rc, num_done; bool all_done = false;
int rc;
setup_rwb(); setup_rwb();
for (i = 0; i < NUM_PARALLEL_WORKERS; ++i) { for (i = 0; i < NUM_PARALLEL_WORKERS; ++i) {
done[i] = false; rc = pthread_create(&workers[i], NULL, test_rwb_worker, (void *)&num_done);
rc = pthread_create(&workers[i], NULL, test_rwb_worker, (void *)&done[i]);
CU_ASSERT_TRUE(rc == 0); CU_ASSERT_TRUE(rc == 0);
} }
@ -232,15 +232,13 @@ test_rwb_parallel(void)
ftl_rwb_batch_release(batch); ftl_rwb_batch_release(batch);
} else { } else {
num_done = 0; if (NUM_PARALLEL_WORKERS == __atomic_load_n(&num_done, __ATOMIC_SEQ_CST)) {
for (i = 0; i < NUM_PARALLEL_WORKERS; ++i) { if (!all_done) {
if (__atomic_load_n(&done[i], __ATOMIC_SEQ_CST)) { /* Pop all left entries from rwb */
num_done++; all_done = true;
continue; continue;
} }
}
if (num_done == NUM_PARALLEL_WORKERS) {
for (i = 0; i < NUM_PARALLEL_WORKERS; ++i) { for (i = 0; i < NUM_PARALLEL_WORKERS; ++i) {
pthread_join(workers[i], NULL); pthread_join(workers[i], NULL);
} }