* test-read-lock-speed.c
*
* Compare speed of :
- * - spin lock irqsave / spin unlock irqrestore (protects from interrupts)
- * - rwlock read lock (not disabling interrupts, can deal with nesting)
+ * - spin lock / spin unlock
+ * - rwlock read lock
* - using a sequence read lock (uncontended)
* - preempt disable/enable (RCU)
*
#include <asm/timex.h>
#include <asm/system.h>
+#ifdef CONFIG_ARM
+#include <linux/trace-clock.h>
+#define get_timestamp trace_clock_read64
+#else
+#define get_timestamp get_cycles
+#endif
+
#define NR_LOOPS 20000
#ifndef CONFIG_PREEMPT
local_irq_save(flags);
preempt_disable();
- time1 = get_cycles();
+ time1 = get_timestamp();
for (i = 0; i < NR_LOOPS; i++) {
asm volatile ("");
}
- time2 = get_cycles();
+ time2 = get_timestamp();
local_irq_restore(flags);
preempt_enable();
time = time2 - time1;
printk(KERN_ALERT "test results: time for baseline\n");
printk(KERN_ALERT "number of loops: %d\n", NR_LOOPS);
- printk(KERN_ALERT "total time: %llu\n", time);
+ printk(KERN_ALERT "total time: %llu\n", (unsigned long long)time);
time = div_u64_rem(time, NR_LOOPS, &rem);
- printk(KERN_ALERT "-> baseline takes %llu cycles\n", time);
+ printk(KERN_ALERT "-> baseline takes %llu cycles\n", (unsigned long long)time);
printk(KERN_ALERT "test end\n");
}
preempt_disable();
spin_lock_irqsave(&mylock, flags);
- time1 = get_cycles();
+ time1 = get_timestamp();
for (i = 0; i < NR_LOOPS; i++) {
spin_unlock(&mylock);
spin_lock(&mylock);
}
- time2 = get_cycles();
+ time2 = get_timestamp();
spin_unlock_irqrestore(&mylock, flags);
preempt_enable();
time = time2 - time1;
printk(KERN_ALERT "test results: time for spinlock\n");
printk(KERN_ALERT "number of loops: %d\n", NR_LOOPS);
- printk(KERN_ALERT "total time: %llu\n", time);
+ printk(KERN_ALERT "total time: %llu\n", (unsigned long long)time);
time = div_u64_rem(time, NR_LOOPS, &rem);
- printk(KERN_ALERT "-> spinlock takes %llu cycles\n", time);
+ printk(KERN_ALERT "-> spinlock takes %llu cycles\n", (unsigned long long)time);
printk(KERN_ALERT "test end\n");
}
preempt_disable();
local_irq_save(flags);
read_lock(&mylock);
- time1 = get_cycles();
+ time1 = get_timestamp();
for (i = 0; i < NR_LOOPS; i++) {
read_unlock(&mylock);
read_lock(&mylock);
}
- time2 = get_cycles();
+ time2 = get_timestamp();
read_unlock(&mylock);
local_irq_restore(flags);
preempt_enable();
printk(KERN_ALERT "test results: time for read rwlock\n");
printk(KERN_ALERT "number of loops: %d\n", NR_LOOPS);
- printk(KERN_ALERT "total time: %llu\n", time);
+ printk(KERN_ALERT "total time: %llu\n", (unsigned long long)time);
time = div_u64_rem(time, NR_LOOPS, &rem);
- printk(KERN_ALERT "-> read rwlock takes %llu cycles\n", time);
+ printk(KERN_ALERT "-> read rwlock takes %llu cycles\n", (unsigned long long)time);
printk(KERN_ALERT "test end\n");
}
u32 rem;
local_irq_save(flags);
- time1 = get_cycles();
+ time1 = get_timestamp();
for (i = 0; i < NR_LOOPS; i++) {
do {
seq = read_seqbegin(&test_lock);
} while (read_seqretry(&test_lock, seq));
}
- time2 = get_cycles();
+ time2 = get_timestamp();
time = time2 - time1;
local_irq_restore(flags);
printk(KERN_ALERT "test results: time for seqlock\n");
printk(KERN_ALERT "number of loops: %d\n", NR_LOOPS);
- printk(KERN_ALERT "total time: %llu\n", time);
+ printk(KERN_ALERT "total time: %llu\n", (unsigned long long)time);
time = div_u64_rem(time, NR_LOOPS, &rem);
- printk(KERN_ALERT "-> seqlock takes %llu cycles\n", time);
+ printk(KERN_ALERT "-> seqlock takes %llu cycles\n", (unsigned long long)time);
printk(KERN_ALERT "test end\n");
}
local_irq_save(flags);
preempt_disable();
- time1 = get_cycles();
+ time1 = get_timestamp();
for (i = 0; i < NR_LOOPS; i++) {
preempt_disable();
preempt_enable();
}
- time2 = get_cycles();
+ time2 = get_timestamp();
preempt_enable();
time = time2 - time1;
local_irq_restore(flags);
printk(KERN_ALERT
"test results: time for preempt disable/enable pairs\n");
printk(KERN_ALERT "number of loops: %d\n", NR_LOOPS);
- printk(KERN_ALERT "total time: %llu\n", time);
+ printk(KERN_ALERT "total time: %llu\n", (unsigned long long)time);
time = div_u64_rem(time, NR_LOOPS, &rem);
printk(KERN_ALERT "-> preempt disable/enable pair takes %llu cycles\n",
- time);
+ (unsigned long long)time);
printk(KERN_ALERT "test end\n");
}