X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=trunk%2Ftests%2Fkernel%2Ftest-read-lock-speed.c;h=895cee53166f59bd2b68c3f15db787d28697f304;hb=fe207500d5d46b7dd4f75d4d47550e9af73c7b00;hp=31e40f10fcf71a9fea18af76f9365ce65da0cdb9;hpb=2828920728360d31144e2fd51d51d386f495418a;p=lttv.git diff --git a/trunk/tests/kernel/test-read-lock-speed.c b/trunk/tests/kernel/test-read-lock-speed.c index 31e40f10..895cee53 100644 --- a/trunk/tests/kernel/test-read-lock-speed.c +++ b/trunk/tests/kernel/test-read-lock-speed.c @@ -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) * @@ -96,6 +96,36 @@ static void do_test_spinlock(void) 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_cycles(); + for (i = 0; i < NR_LOOPS; i++) { + read_unlock(&mylock); + read_lock(&mylock); + } + time2 = get_cycles(); + 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", time); + time = div_u64_rem(time, NR_LOOPS, &rem); + printk(KERN_ALERT "-> read rwlock takes %llu cycles\n", time); + printk(KERN_ALERT "test end\n"); +} + static void do_test_seqlock(void) { static seqlock_t test_lock; @@ -166,6 +196,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 */