31d375f5 |
1 | /* test-tsc-sync.c |
2 | * |
3 | * Test TSC sync |
4 | */ |
5 | |
6 | |
7 | #include <linux/module.h> |
8 | #include <linux/timer.h> |
9 | #include <asm/timex.h> |
10 | #include <linux/jiffies.h> |
11 | |
12 | static DEFINE_PER_CPU(cycles_t, count) = 0; |
13 | |
14 | static struct timer_list test_timer; |
15 | |
feca19f0 |
16 | static atomic_t kernel_threads_to_run; |
17 | |
18 | |
31d375f5 |
19 | /* IPI called on each CPU. */ |
20 | static void test_each(void *info) |
21 | { |
feca19f0 |
22 | unsigned long flags; |
23 | local_irq_save(flags); |
24 | atomic_dec(&kernel_threads_to_run); |
25 | while(atomic_read(&kernel_threads_to_run)) |
26 | cpu_relax(); |
63787240 |
27 | __get_cpu_var(count) = get_cycles_sync(); |
feca19f0 |
28 | local_irq_restore(flags); |
31d375f5 |
29 | } |
30 | |
31 | static void do_test_timer(unsigned long data) |
32 | { |
33 | int cpu; |
34 | |
feca19f0 |
35 | atomic_set(&kernel_threads_to_run, num_online_cpus()); |
36 | |
37 | smp_call_function(test_each, NULL, 0, 0); |
38 | test_each(NULL); |
31d375f5 |
39 | /* Read all the counters */ |
40 | printk("Counters read from CPU %d\n", smp_processor_id()); |
41 | for_each_online_cpu(cpu) { |
42 | printk("Read : CPU %d, count %llu\n", cpu, |
43 | per_cpu(count, cpu)); |
44 | } |
45 | del_timer(&test_timer); |
46 | test_timer.expires = jiffies + 1000; |
47 | add_timer(&test_timer); |
48 | } |
49 | |
50 | static int __init test_init(void) |
51 | { |
52 | /* initialize the timer that will increment the counter */ |
53 | init_timer(&test_timer); |
54 | test_timer.function = do_test_timer; |
55 | test_timer.expires = jiffies + 1; |
56 | add_timer(&test_timer); |
57 | |
58 | return 0; |
59 | } |
60 | |
61 | static void __exit test_exit(void) |
62 | { |
63 | del_timer_sync(&test_timer); |
64 | } |
65 | |
66 | module_init(test_init); |
67 | module_exit(test_exit); |
68 | |
69 | MODULE_LICENSE("GPL"); |
70 | MODULE_AUTHOR("Mathieu Desnoyers"); |
71 | MODULE_DESCRIPTION("sync tsc test"); |
72 | |