add test local
authorcompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Tue, 9 Jan 2007 00:11:15 +0000 (00:11 +0000)
committercompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Tue, 9 Jan 2007 00:11:15 +0000 (00:11 +0000)
git-svn-id: http://ltt.polymtl.ca/svn@2325 04897980-b3bd-0310-b5e0-8ef037075253

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

index 076614691b799ff35406d531549a8d36f0312779..23b718bd0ca473171e914769025a39a4e86f1f28 100644 (file)
@@ -11,6 +11,7 @@ endif
        obj-m += test-debugfs.o
        obj-m += test-hotplug.o
        obj-m += rdtsc-smp.o
+       obj-m += test-local.o
 #      obj-m += test-cmpxchg.o
 #      obj-m += test-cmpxchg-nolock.o
 #      obj-m += test-spinlock.o
diff --git a/tests/kernel/test-local.c b/tests/kernel/test-local.c
new file mode 100644 (file)
index 0000000..3f74375
--- /dev/null
@@ -0,0 +1,69 @@
+/* test-local.c
+ *
+ * Sample module for local.h usage.
+ */
+
+
+#include <asm/local.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/timer.h>
+
+static DEFINE_PER_CPU(local_t, counters) = LOCAL_INIT(0);
+
+static struct timer_list test_timer;
+
+/* IPI called on each CPU. */
+static void test_each(void *info)
+{
+       /* Increment the counter from a non preemptible context */
+       printk("Increment on cpu %d\n", smp_processor_id());
+       local_inc(&__get_cpu_var(counters));
+
+       /* This is what incrementing the variable would look like within a
+        * preemptible context (it disables preemption) :
+        *
+        * local_inc(&get_cpu_var(counters));
+        * put_cpu_var(counters);
+        */
+}
+static void do_test_timer(unsigned long data)
+{
+       int cpu;
+
+       /* Increment the counters */
+       on_each_cpu(test_each, NULL, 0, 1);
+       /* Read all the counters */
+       printk("Counters read from CPU %d\n", smp_processor_id());
+       for_each_online_cpu(cpu) {
+               printk("Read : CPU %d, count %ld\n", cpu,
+                       local_read(&per_cpu(counters, cpu)));
+       }
+       del_timer(&test_timer);
+       test_timer.expires = jiffies + 1000;
+       add_timer(&test_timer);
+}
+
+static int __init test_init(void)
+{
+       /* initialize the timer that will increment the counter */
+       init_timer(&test_timer);
+       test_timer.function = do_test_timer;
+       test_timer.expires = jiffies + 1;
+       add_timer(&test_timer);
+
+       return 0;
+}
+
+static void __exit test_exit(void)
+{
+       del_timer_sync(&test_timer);
+}
+
+module_init(test_init);
+module_exit(test_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mathieu Desnoyers");
+MODULE_DESCRIPTION("Local Atomic Ops");
+
This page took 0.026203 seconds and 4 git commands to generate.