convert from svn repository: remove tags directory
[lttv.git] / trunk / tests / kernel / test-read-lock-speed.c
index 31e40f10fcf71a9fea18af76f9365ce65da0cdb9..f6ad286e74ce08b2801f5466d47604bf5644bafc 100644 (file)
@@ -2,8 +2,8 @@
  * test-read-lock-speed.c
  *
  * Compare speed of :
- * - spin lock irqsave / spin unlock irqrestore (close to rwlocks when
- *   uncontended)
+ * - 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
@@ -51,20 +58,20 @@ static void do_testbaseline(void)
 
        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");
 }
 
@@ -78,21 +85,51 @@ static void do_test_spinlock(void)
 
        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", (unsigned long long)time);
+       printk(KERN_ALERT "test end\n");
+}
+
+static void do_test_read_rwlock(void)
+{
+       static DEFINE_RWLOCK(mylock);
+       unsigned long flags;
+       unsigned int i;
+       cycles_t time1, time2, time;
+       u32 rem;
+
+       preempt_disable();
+       local_irq_save(flags);
+       read_lock(&mylock);
+       time1 = get_timestamp();
+       for (i = 0; i < NR_LOOPS; i++) {
+               read_unlock(&mylock);
+               read_lock(&mylock);
+       }
+       time2 = get_timestamp();
+       read_unlock(&mylock);
+       local_irq_restore(flags);
+       preempt_enable();
+       time = time2 - time1;
+
+       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", (unsigned long long)time);
        time = div_u64_rem(time, NR_LOOPS, &rem);
-       printk(KERN_ALERT "-> spinlock takes %llu cycles\n", time);
+       printk(KERN_ALERT "-> read rwlock takes %llu cycles\n", (unsigned long long)time);
        printk(KERN_ALERT "test end\n");
 }
 
@@ -106,21 +143,21 @@ static void do_test_seqlock(void)
        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");
 }
 
@@ -139,12 +176,12 @@ static void do_test_preempt(void)
 
        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);
@@ -152,10 +189,10 @@ static void do_test_preempt(void)
        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");
 }
 
@@ -166,6 +203,7 @@ static int ltt_test_init(void)
        printk(KERN_ALERT "Number of active CPUs : %d\n", num_online_cpus());
        do_testbaseline();
        do_test_spinlock();
+       do_test_read_rwlock();
        do_test_seqlock();
        do_test_preempt();
        return -EAGAIN; /* Fail will directly unload the module */
This page took 0.025104 seconds and 4 git commands to generate.