Skip to content

Commit 70ec07b

Browse files
Add a rcu noise thread
1 parent 574b524 commit 70ec07b

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

crypto/threads_pthread.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,21 @@ void ossl_synchronize_rcu(CRYPTO_RCU_LOCK *lock)
549549
}
550550
}
551551

552+
void ossl_make_noise_rcu(CRYPTO_RCU_LOCK *lock)
553+
{
554+
unsigned int i, j;
555+
556+
for (j = 0; j < 100; j++) {
557+
#if defined(__GNUC__) && defined(__ATOMIC_ACQUIRE) && !defined(BROKEN_CLANG_ATOMICS) \
558+
&& !defined(USE_ATOMIC_FALLBACKS)
559+
ATOMIC_ADD_FETCH(&lock->reader_idx, (uint32_t)0, __ATOMIC_RELAXED);
560+
#endif
561+
for (i = 0; i < lock->group_count; i++)
562+
ATOMIC_ADD_FETCH(&lock->qp_group[i].users, (uint64_t)0,
563+
__ATOMIC_RELAXED);
564+
}
565+
}
566+
552567
/*
553568
* Note: This call assumes its made under the protection of
554569
* ossl_rcu_write_lock

include/internal/rcu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ void ossl_rcu_write_lock(CRYPTO_RCU_LOCK *lock);
2424
void ossl_rcu_write_unlock(CRYPTO_RCU_LOCK *lock);
2525
void ossl_rcu_read_unlock(CRYPTO_RCU_LOCK *lock);
2626
void ossl_synchronize_rcu(CRYPTO_RCU_LOCK *lock);
27+
void ossl_make_noise_rcu(CRYPTO_RCU_LOCK *lock);
2728
int ossl_rcu_call(CRYPTO_RCU_LOCK *lock, rcu_cb_fn cb, void *data);
2829
void *ossl_rcu_uptr_deref(void **p);
2930
void ossl_rcu_assign_uptr(void **p, void **v);

test/threadstest.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ static void writer2_fn(void)
377377
{
378378
int local;
379379

380+
OSSL_sleep(3000);
380381
TEST_info("Starting writer2");
381382
writer_fn(2, &writer2_iterations);
382383
CRYPTO_atomic_add(&writer2_done, 1, &local, atomiclock);
@@ -429,10 +430,34 @@ static void reader1_fn(void)
429430

430431
static void reader2_fn(void)
431432
{
433+
#ifdef __aarch64__
434+
extern unsigned int OPENSSL_armcap_P;
435+
if (contention != 0 && (OPENSSL_armcap_P == 0xbd
436+
|| OPENSSL_armcap_P == 0x7efd
437+
|| OPENSSL_armcap_P == 0x987d))
438+
sleep(1000);
439+
#endif
440+
#ifdef __powerpc64__
441+
extern unsigned int OPENSSL_ppccap_P;
442+
if (contention != 0 && OPENSSL_ppccap_P == 0xbe)
443+
sleep(1000);
444+
#endif
432445
TEST_info("Starting reader 2");
433446
reader_fn(&reader2_iterations);
434447
}
435448

449+
static void noise_fn(void)
450+
{
451+
int lw1 = 0;
452+
int lw2 = 0;
453+
454+
while (lw1 != 1 || lw2 != 1) {
455+
CRYPTO_atomic_add(&writer1_done, 0, &lw1, atomiclock);
456+
CRYPTO_atomic_add(&writer2_done, 0, &lw2, atomiclock);
457+
ossl_make_noise_rcu(rcu_lock);
458+
}
459+
}
460+
436461
static thread_t writer1;
437462
static thread_t writer2;
438463
static thread_t reader1;
@@ -445,6 +470,7 @@ static int _torture_rcu(void)
445470
double tottime;
446471
double avr, avw;
447472
int rc = 0;
473+
thread_t noise;
448474

449475
atomiclock = CRYPTO_THREAD_lock_new();
450476
if (!TEST_ptr(atomiclock))
@@ -473,6 +499,8 @@ static int _torture_rcu(void)
473499
|| !TEST_true(run_thread(&reader2, reader2_fn))
474500
|| !TEST_true(run_thread(&writer1, writer1_fn))
475501
|| !TEST_true(run_thread(&writer2, writer2_fn))
502+
|| !TEST_true(run_thread(&noise, noise_fn))
503+
|| !TEST_true(wait_for_thread(noise))
476504
|| !TEST_true(wait_for_thread(writer1))
477505
|| !TEST_true(wait_for_thread(writer2))
478506
|| !TEST_true(wait_for_thread(reader1))

0 commit comments

Comments
 (0)