7 #include <linux/module.h>
8 #include <linux/timer.h>
10 #include <linux/jiffies.h>
12 static DEFINE_PER_CPU(cycles_t
, count
) = 0;
14 static struct timer_list test_timer
;
16 static atomic_t kernel_threads_to_run
;
19 /* IPI called on each CPU. */
20 static void test_each(void *info
)
23 local_irq_save(flags
);
24 atomic_dec(&kernel_threads_to_run
);
25 while(atomic_read(&kernel_threads_to_run
))
27 __get_cpu_var(count
) = get_cycles_sync();
28 local_irq_restore(flags
);
31 static void do_test_timer(unsigned long data
)
35 atomic_set(&kernel_threads_to_run
, num_online_cpus());
37 smp_call_function(test_each
, NULL
, 0, 0);
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
,
45 del_timer(&test_timer
);
46 test_timer
.expires
= jiffies
+ 1000;
47 add_timer(&test_timer
);
50 static int __init
test_init(void)
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
);
61 static void __exit
test_exit(void)
63 del_timer_sync(&test_timer
);
66 module_init(test_init
);
67 module_exit(test_exit
);
69 MODULE_LICENSE("GPL");
70 MODULE_AUTHOR("Mathieu Desnoyers");
71 MODULE_DESCRIPTION("sync tsc test");