From: compudj Date: Thu, 21 Dec 2006 19:53:03 +0000 (+0000) Subject: test kernel tsc X-Git-Tag: v0.12.20~1167 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=41a0bd4f9ebae32d371d2d69f194e4dab4f60f0f;p=lttv.git test kernel tsc git-svn-id: http://ltt.polymtl.ca/svn@2322 04897980-b3bd-0310-b5e0-8ef037075253 --- diff --git a/tests/kernel/rdtsc-smp.c b/tests/kernel/rdtsc-smp.c new file mode 100644 index 00000000..62e19a1e --- /dev/null +++ b/tests/kernel/rdtsc-smp.c @@ -0,0 +1,72 @@ +/* rdtsc-smp + * + * Test TSC + */ + + +#include +#include +#include +#include +#include + +static atomic_t busy_wait; +static struct delayed_work testwork[NR_CPUS]; + + +static void do_work(struct work_struct *work) +{ + cycles_t val; + int cpu1, cpu2; + int num_online = num_online_cpus(); + int copybusy; + int i; + + cpu1 = smp_processor_id(); + printk("Busy waiting on cpu %d\n", cpu1); + + /* Prime busy_wait in cache */ + for(i=0; i<100; i++) { + copybusy = atomic_read(&busy_wait); + } + barrier(); + atomic_inc(&busy_wait); + while(atomic_read(&busy_wait) != num_online) { + barrier(); + } + + val = get_cycles(); + + cpu2 = smp_processor_id(); + BUG_ON(cpu1 != cpu2); + printk("Cycle count on cpu %d is %llu\n", cpu1, val); +} + + +static int ltt_test_init(void) +{ + int cpu; + + printk(KERN_ALERT "test init\n"); + + atomic_set(&busy_wait, 0); + for_each_online_cpu(cpu) { + INIT_DELAYED_WORK(&testwork[cpu], do_work); + schedule_delayed_work_on(cpu, &testwork[cpu], 0); + } + return 0; +} + +static void ltt_test_exit(void) +{ + /* Test program... wait for output before unload */ + 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("Linux Trace Toolkit Test"); +