#include <linux/proc_fs.h>
#include <linux/sched.h>
#include <linux/timex.h>
-#include <linux/wbias-rwlock.h>
#include <linux/kthread.h>
#include <linux/delay.h>
#include <linux/hardirq.h>
#include <linux/percpu.h>
#include <linux/spinlock.h>
#include <asm/ptrace.h>
+#include <linux/wbias-rwlock.h>
/* Test with no contention duration, in seconds */
#define SINGLE_WRITER_TEST_DURATION 10
#define NR_VARS 100
#define NR_WRITERS 2
#define NR_TRYLOCK_WRITERS 1
-#define NR_PREADERS 2
#define NR_NPREADERS 2
#define NR_TRYLOCK_READERS 1
#define NR_TRYLOCK_INTERRUPT_READERS 0
#endif
+/*
+ * 1 : test with thread preemption readers.
+ * 0 : test only with non-preemptable thread readers.
+ */
+#define TEST_PREEMPT 1
+
+#if (TEST_PREEMPT)
+#define NR_PREADERS 2
+#else
+#define NR_PREADERS 0
+#endif
+
+
/*
* Writer iteration delay, in us. 0 for busy loop. Caution : writers can
* starve readers.
#if (TEST_INTERRUPTS)
#define wrap_write_lock() wbias_write_lock_irq(&wbiasrwlock)
#define wrap_write_unlock() wbias_write_unlock_irq(&wbiasrwlock)
+#define wrap_write_trylock_else_subscribe() \
+ wbias_write_trylock_irq_else_subscribe(&wbiasrwlock)
+#define wrap_write_trylock_subscribed() \
+ wbias_write_trylock_irq_subscribed(&wbiasrwlock)
#else
+#if (TEST_PREEMPT)
#define wrap_write_lock() wbias_write_lock(&wbiasrwlock)
#define wrap_write_unlock() wbias_write_unlock(&wbiasrwlock)
+#define wrap_write_trylock_else_subscribe() \
+ wbias_write_trylock_else_subscribe(&wbiasrwlock)
+#define wrap_write_trylock_subscribed() \
+ wbias_write_trylock_subscribed(&wbiasrwlock)
+#else
+#else
+#define wrap_write_lock() wbias_write_lock_atomic(&wbiasrwlock)
+#define wrap_write_unlock() wbias_write_unlock_atomic(&wbiasrwlock)
+#define wrap_write_trylock_else_subscribe() \
+ wbias_write_trylock_atomic_else_subscribe(&wbiasrwlock)
+#define wrap_write_trylock_subscribed() \
+ wbias_write_trylock_atomic_subscribed(&wbiasrwlock)
+#endif
#endif
#endif
printk("trylock_writer_thread/%lu runnning\n", (unsigned long)data);
do {
iter++;
-#if (TEST_INTERRUPTS)
- if (wbias_write_trylock_irq_else_subscribe(&wbiasrwlock))
-#else
- if (wbias_write_trylock_else_subscribe(&wbiasrwlock))
-#endif
+ if (wrap_write_trylock_else_subscribe())
goto locked;
#if (TRYLOCK_WRITERS_FAIL_ITER == -1)
for (;;) {
iter++;
-#if (TEST_INTERRUPTS)
- if (wbias_write_trylock_irq_subscribed(&wbiasrwlock))
-#else
- if (wbias_write_trylock_subscribed(&wbiasrwlock))
-#endif
+ if (wrap_write_trylock_subscribed())
goto locked;
}
#else
for (i = 0; i < TRYLOCK_WRITERS_FAIL_ITER - 1; i++) {
iter++;
-#if (TEST_INTERRUPTS)
- if (wbias_write_trylock_irq_subscribed(&wbiasrwlock))
-#else
- if (wbias_write_trylock_subscribed(&wbiasrwlock))
-#endif
+ if (wrap_write_trylock_subscribed())
goto locked;
}
#endif
for (i = 0; i < NR_VARS; i++) {
var[i] = new;
}
-#if (TEST_INTERRUPTS)
- wbias_write_unlock_irq(&wbiasrwlock);
-#else
- wbias_write_unlock(&wbiasrwlock);
-#endif
+ wrap_write_unlock();
loop:
if (TRYLOCK_WRITER_DELAY > 0)
udelay(TRYLOCK_WRITER_DELAY);