0001
0002 #include <linux/kernel.h>
0003 #include <linux/gfp.h>
0004 #include <linux/slab.h>
0005 #include <linux/radix-tree.h>
0006 #include <linux/rcupdate.h>
0007 #include <stdlib.h>
0008 #include <pthread.h>
0009 #include <stdio.h>
0010 #include <assert.h>
0011
0012 #include "regression.h"
0013
0014 static pthread_barrier_t worker_barrier;
0015 static int obj0, obj1;
0016 static RADIX_TREE(mt_tree, GFP_KERNEL);
0017
0018 static void *reader_fn(void *arg)
0019 {
0020 int i;
0021 void *entry;
0022
0023 rcu_register_thread();
0024 pthread_barrier_wait(&worker_barrier);
0025
0026 for (i = 0; i < 1000000; i++) {
0027 rcu_read_lock();
0028 entry = radix_tree_lookup(&mt_tree, 0);
0029 rcu_read_unlock();
0030 if (entry != &obj0) {
0031 printf("iteration %d bad entry = %p\n", i, entry);
0032 abort();
0033 }
0034 }
0035
0036 rcu_unregister_thread();
0037
0038 return NULL;
0039 }
0040
0041 static void *writer_fn(void *arg)
0042 {
0043 int i;
0044
0045 rcu_register_thread();
0046 pthread_barrier_wait(&worker_barrier);
0047
0048 for (i = 0; i < 1000000; i++) {
0049 radix_tree_insert(&mt_tree, 1, &obj1);
0050 radix_tree_delete(&mt_tree, 1);
0051 }
0052
0053 rcu_unregister_thread();
0054
0055 return NULL;
0056 }
0057
0058 void regression4_test(void)
0059 {
0060 pthread_t reader, writer;
0061
0062 printv(1, "regression test 4 starting\n");
0063
0064 radix_tree_insert(&mt_tree, 0, &obj0);
0065 pthread_barrier_init(&worker_barrier, NULL, 2);
0066
0067 if (pthread_create(&reader, NULL, reader_fn, NULL) ||
0068 pthread_create(&writer, NULL, writer_fn, NULL)) {
0069 perror("pthread_create");
0070 exit(1);
0071 }
0072
0073 if (pthread_join(reader, NULL) || pthread_join(writer, NULL)) {
0074 perror("pthread_join");
0075 exit(1);
0076 }
0077
0078 printv(1, "regression test 4 passed\n");
0079 }