add ipi test
authorcompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Thu, 28 May 2009 19:30:00 +0000 (19:30 +0000)
committercompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Thu, 28 May 2009 19:30:00 +0000 (19:30 +0000)
git-svn-id: http://ltt.polymtl.ca/svn@3398 04897980-b3bd-0310-b5e0-8ef037075253

trunk/tests/kernel/Makefile
trunk/tests/kernel/test-ipi.c [new file with mode: 0644]

index adcc35c5096690872d51c7beaad1c899c7f07228..24cd9a112e55dcccd60f5adac099f11003eca880 100644 (file)
@@ -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 (file)
index 0000000..6f3f4fb
--- /dev/null
@@ -0,0 +1,135 @@
+/*
+ * test-ipi.c
+ *
+ * Copyright 2009 - Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
+ * Distributed under GPLv2
+ */
+
+#include <linux/jiffies.h>
+#include <linux/compiler.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/math64.h>
+#include <linux/spinlock.h>
+#include <linux/seqlock.h>
+#include <linux/cpumask.h>
+#include <linux/smp.h>
+#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
+
+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");
This page took 0.025115 seconds and 4 git commands to generate.