convert from svn repository: remove tags directory
[lttv.git] / trunk / tests / kernel / test-local.c
CommitLineData
b8712f8e 1/* test-local.c
2 *
3 * Sample module for local.h usage.
4 */
5
6
7#include <asm/local.h>
b8712f8e 8#include <linux/module.h>
9#include <linux/timer.h>
10
11static DEFINE_PER_CPU(local_t, counters) = LOCAL_INIT(0);
12
13static struct timer_list test_timer;
14
15/* IPI called on each CPU. */
16static void test_each(void *info)
17{
18 /* Increment the counter from a non preemptible context */
19 printk("Increment on cpu %d\n", smp_processor_id());
20 local_inc(&__get_cpu_var(counters));
21
22 /* This is what incrementing the variable would look like within a
23 * preemptible context (it disables preemption) :
24 *
25 * local_inc(&get_cpu_var(counters));
26 * put_cpu_var(counters);
27 */
28}
3ff6a8be 29
b8712f8e 30static void do_test_timer(unsigned long data)
31{
32 int cpu;
33
34 /* Increment the counters */
35 on_each_cpu(test_each, NULL, 0, 1);
36 /* Read all the counters */
37 printk("Counters read from CPU %d\n", smp_processor_id());
38 for_each_online_cpu(cpu) {
39 printk("Read : CPU %d, count %ld\n", cpu,
40 local_read(&per_cpu(counters, cpu)));
41 }
42 del_timer(&test_timer);
43 test_timer.expires = jiffies + 1000;
44 add_timer(&test_timer);
45}
46
47static int __init test_init(void)
48{
49 /* initialize the timer that will increment the counter */
50 init_timer(&test_timer);
51 test_timer.function = do_test_timer;
52 test_timer.expires = jiffies + 1;
53 add_timer(&test_timer);
54
55 return 0;
56}
57
58static void __exit test_exit(void)
59{
60 del_timer_sync(&test_timer);
61}
62
63module_init(test_init);
64module_exit(test_exit);
65
66MODULE_LICENSE("GPL");
67MODULE_AUTHOR("Mathieu Desnoyers");
68MODULE_DESCRIPTION("Local Atomic Ops");
69
This page took 0.033137 seconds and 4 git commands to generate.