*
* Userspace RCU library - test program
*
- * Copyright February 2009 - Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
+ * Copyright February 2009 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include <unistd.h>
#include <stdio.h>
#include <assert.h>
-#include <sys/syscall.h>
#include <sched.h>
#include <errno.h>
#include <urcu/arch.h>
+#ifdef __linux__
+#include <syscall.h>
+#endif
+
/* hardcoded number of CPUs */
#define NR_CPUS 16384
static inline void loop_sleep(unsigned long l)
{
while(l-- != 0)
- cpu_relax();
+ caa_cpu_relax();
}
static int verbose_mode;
/*
* malloc/free are reusing memory areas too quickly, which does not let us
* test races appropriately. Use a large circular array for allocations.
- * ARRAY_SIZE is larger than nr_writers, which insures we never run over our tail.
+ * ARRAY_SIZE is larger than nr_writers, and we keep the mutex across
+ * both alloc and free, which insures we never run over our tail.
*/
#define ARRAY_SIZE (1048576 * nr_writers)
#define ARRAY_POISON 0xDEADBEEF
struct test_array *ret;
int index;
- rcu_copy_mutex_lock();
index = array_index % ARRAY_SIZE;
assert(test_array[index].a == ARRAY_POISON ||
test_array[index].a == 0);
array_index++;
if (array_index == ARRAY_SIZE)
array_index = 0;
- rcu_copy_mutex_unlock();
return ret;
}
{
if (!ptr)
return;
- rcu_copy_mutex_lock();
ptr->a = ARRAY_POISON;
- rcu_copy_mutex_unlock();
}
void *thr_reader(void *_count)
while (!test_go)
{
}
- smp_mb();
+ cmm_smp_mb();
for (;;) {
rcu_read_lock();
debug_yield_read();
if (local_ptr)
assert(local_ptr->a == 8);
- if (unlikely(rduration))
+ if (caa_unlikely(rduration))
loop_sleep(rduration);
rcu_read_unlock();
nr_reads++;
- if (unlikely(!test_duration_read()))
+ if (caa_unlikely(!test_duration_read()))
break;
}
while (!test_go)
{
}
- smp_mb();
+ cmm_smp_mb();
for (;;) {
+ rcu_copy_mutex_lock();
new = test_array_alloc();
new->a = 8;
old = rcu_xchg_pointer(&test_rcu_pointer, new);
- if (unlikely(wduration))
+ if (caa_unlikely(wduration))
loop_sleep(wduration);
synchronize_rcu();
if (old)
old->a = 0;
test_array_free(old);
+ rcu_copy_mutex_unlock();
nr_writes++;
- if (unlikely(!test_duration_write()))
+ if (caa_unlikely(!test_duration_write()))
break;
- if (unlikely(wdelay))
+ if (caa_unlikely(wdelay))
loop_sleep(wdelay);
}
printf_verbose("thread %-6s, thread id : %lx, tid %lu\n",
"main", pthread_self(), (unsigned long)gettid());
- test_array = malloc(sizeof(*test_array) * ARRAY_SIZE);
+ test_array = calloc(1, sizeof(*test_array) * ARRAY_SIZE);
tid_reader = malloc(sizeof(*tid_reader) * nr_readers);
tid_writer = malloc(sizeof(*tid_writer) * nr_writers);
count_reader = malloc(sizeof(*count_reader) * nr_readers);
exit(1);
}
- smp_mb();
+ cmm_smp_mb();
test_go = 1;
printf_verbose("total number of reads : %llu, writes %llu\n", tot_reads,
tot_writes);
- printf("SUMMARY %-25s testdur %4lu nr_readers %3u rdur %6lu "
+ printf("SUMMARY %-25s testdur %4lu nr_readers %3u rdur %6lu wdur %6lu "
"nr_writers %3u "
"wdelay %6lu nr_reads %12llu nr_writes %12llu nr_ops %12llu\n",
- argv[0], duration, nr_readers, rduration,
+ argv[0], duration, nr_readers, rduration, wduration,
nr_writers, wdelay, tot_reads, tot_writes,
tot_reads + tot_writes);
test_array_free(test_rcu_pointer);