From: compudj Date: Thu, 28 May 2009 19:30:00 +0000 (+0000) Subject: add ipi test X-Git-Tag: v0.12.20~91 X-Git-Url: http://git.liburcu.org/?a=commitdiff_plain;h=67708ee530e10dc299f90495ac2dc3e61c5bf478;p=lttv.git add ipi test git-svn-id: http://ltt.polymtl.ca/svn@3398 04897980-b3bd-0310-b5e0-8ef037075253 --- diff --git a/trunk/tests/kernel/Makefile b/trunk/tests/kernel/Makefile index adcc35c5..24cd9a11 100644 --- a/trunk/tests/kernel/Makefile +++ b/trunk/tests/kernel/Makefile @@ -25,6 +25,7 @@ endif #obj-m += test-prefix-speed.o #obj-m += test-psrwlock.o obj-m += test-cmpxchg-nolock2.o + obj-m += test-ipi.o # obj-m += test-trace-speed.o obj-m += test-read-lock-speed.o # obj-m += test-fct-speed.o diff --git a/trunk/tests/kernel/test-ipi.c b/trunk/tests/kernel/test-ipi.c new file mode 100644 index 00000000..6f3f4fb5 --- /dev/null +++ b/trunk/tests/kernel/test-ipi.c @@ -0,0 +1,135 @@ +/* + * test-ipi.c + * + * Copyright 2009 - Mathieu Desnoyers + * Distributed under GPLv2 + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef CONFIG_ARM +#include +#define get_timestamp trace_clock_read64 +#else +#define get_timestamp get_cycles +#endif + +#define NR_LOOPS 20000 + +int test_val; + +static void do_testbaseline(void) +{ + unsigned long flags; + unsigned int i; + cycles_t time1, time2, time; + u32 rem; + + local_irq_save(flags); + preempt_disable(); + time1 = get_timestamp(); + for (i = 0; i < NR_LOOPS; i++) { + asm volatile (""); + } + 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", (unsigned long long)time); + time = div_u64_rem(time, NR_LOOPS, &rem); + printk(KERN_ALERT "-> baseline takes %llu cycles\n", (unsigned long long)time); + printk(KERN_ALERT "test end\n"); +} + +static void remote_wmb(void *info) +{ + smp_wmb(); +} + +static void do_test_ipi(void) +{ + unsigned int i; + int cpu; + cycles_t time1, time2, time; + u32 rem; + + preempt_disable(); + cpu = smp_processor_id(); + if (cpu == 0) + cpu = 1; + else + cpu = 0; + time1 = get_timestamp(); + for (i = 0; i < NR_LOOPS; i++) { + smp_call_function_single(cpu, remote_wmb, NULL, 1); + } + time2 = get_timestamp(); + preempt_enable(); + time = time2 - time1; + + printk(KERN_ALERT "test results: time for ipi\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 "-> ipi takes %llu cycles\n", (unsigned long long)time); + printk(KERN_ALERT "test end\n"); +} + +static void do_test_wmb(void) +{ + unsigned int i; + cycles_t time1, time2, time; + u32 rem; + + preempt_disable(); + time1 = get_timestamp(); + for (i = 0; i < NR_LOOPS; i++) { + wmb(); + } + time2 = get_timestamp(); + preempt_enable(); + time = time2 - time1; + + printk(KERN_ALERT "test results: time for ipi\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 "-> ipi takes %llu cycles\n", (unsigned long long)time); + printk(KERN_ALERT "test end\n"); +} + +static int ltt_test_init(void) +{ + printk(KERN_ALERT "test init\n"); + + printk(KERN_ALERT "Number of active CPUs : %d\n", num_online_cpus()); + do_testbaseline(); + do_test_ipi(); + do_test_wmb(); + return -EAGAIN; /* Fail will directly unload the module */ +} + +static void ltt_test_exit(void) +{ + printk(KERN_ALERT "test exit\n"); +} + +module_init(ltt_test_init) +module_exit(ltt_test_exit) + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Mathieu Desnoyers"); +MODULE_DESCRIPTION("Test read lock speed");