Add call_rcu() interface
[urcu.git] / tests / rcutorture.h
index 4dac2f224faa9605f309195bea5e62e818080da0..b42b8ab7c828a52fd06ed9ddc187e498b3589d30 100644 (file)
@@ -65,6 +65,9 @@
  * Test variables.
  */
 
+#include <stdlib.h>
+#include "../urcu-call-rcu.h"
+
 DEFINE_PER_THREAD(long long, n_reads_pt);
 DEFINE_PER_THREAD(long long, n_updates_pt);
 
@@ -147,6 +150,16 @@ void *rcu_update_perf_test(void *arg)
 {
        long long n_updates_local = 0;
 
+       if ((random() & 0xf00) == 0) {
+               struct call_rcu_data *crdp;
+
+               crdp = create_call_rcu_data(0);
+               if (crdp != NULL) {
+                       fprintf(stderr,
+                               "Using per-thread call_rcu() worker.\n");
+                       set_thread_call_rcu_data(crdp);
+               }
+       }
        uatomic_inc(&nthreadsrunning);
        while (goflag == GOFLAG_INIT)
                poll(NULL, 0, 1);
@@ -296,10 +309,30 @@ void *rcu_read_stress_test(void *arg)
        return (NULL);
 }
 
+static pthread_mutex_t call_rcu_test_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t call_rcu_test_cond = PTHREAD_COND_INITIALIZER;
+
+void rcu_update_stress_test_rcu(struct rcu_head *head)
+{
+       if (pthread_mutex_lock(&call_rcu_test_mutex) != 0) {
+               perror("pthread_mutex_lock");
+               exit(-1);
+       }
+       if (pthread_cond_signal(&call_rcu_test_cond) != 0) {
+               perror("pthread_cond_signal");
+               exit(-1);
+       }
+       if (pthread_mutex_unlock(&call_rcu_test_mutex) != 0) {
+               perror("pthread_mutex_unlock");
+               exit(-1);
+       }
+}
+
 void *rcu_update_stress_test(void *arg)
 {
        int i;
        struct rcu_stress *p;
+       struct rcu_head rh;
 
        while (goflag == GOFLAG_INIT)
                poll(NULL, 0, 1);
@@ -317,7 +350,24 @@ void *rcu_update_stress_test(void *arg)
                for (i = 0; i < RCU_STRESS_PIPE_LEN; i++)
                        if (i != rcu_stress_idx)
                                rcu_stress_array[i].pipe_count++;
-               synchronize_rcu();
+               if (n_updates & 0x1)
+                       synchronize_rcu();
+               else {
+                       if (pthread_mutex_lock(&call_rcu_test_mutex) != 0) {
+                               perror("pthread_mutex_lock");
+                               exit(-1);
+                       }
+                       call_rcu(&rh, rcu_update_stress_test_rcu);
+                       if (pthread_cond_wait(&call_rcu_test_cond,
+                                             &call_rcu_test_mutex) != 0) {
+                               perror("pthread_cond_wait");
+                               exit(-1);
+                       }
+                       if (pthread_mutex_unlock(&call_rcu_test_mutex) != 0) {
+                               perror("pthread_mutex_unlock");
+                               exit(-1);
+                       }
+               }
                n_updates++;
        }
        return NULL;
@@ -325,6 +375,16 @@ void *rcu_update_stress_test(void *arg)
 
 void *rcu_fake_update_stress_test(void *arg)
 {
+       if ((random() & 0xf00) == 0) {
+               struct call_rcu_data *crdp;
+
+               crdp = create_call_rcu_data(0);
+               if (crdp != NULL) {
+                       fprintf(stderr,
+                               "Using per-thread call_rcu() worker.\n");
+                       set_thread_call_rcu_data(crdp);
+               }
+       }
        while (goflag == GOFLAG_INIT)
                poll(NULL, 0, 1);
        while (goflag == GOFLAG_RUN) {
@@ -396,6 +456,12 @@ int main(int argc, char *argv[])
 
        smp_init();
        //rcu_init();
+       srandom(time(NULL));
+       if (random() & 0x100) {
+               fprintf(stderr, "Allocating per-CPU call_rcu threads.\n");
+               if (create_all_cpu_call_rcu_data(0))
+                       perror("create_all_cpu_call_rcu_data");
+       }
 
 #ifdef DEBUG_YIELD
        yield_active |= YIELD_READ;
This page took 0.023465 seconds and 4 git commands to generate.