| 1 | /* test-lttng-tp.c |
| 2 | * |
| 3 | * Test lttng event write. |
| 4 | */ |
| 5 | |
| 6 | #include <linux/jiffies.h> |
| 7 | #include <linux/compiler.h> |
| 8 | #include <linux/init.h> |
| 9 | #include <linux/module.h> |
| 10 | #include <linux/math64.h> |
| 11 | #include <linux/proc_fs.h> |
| 12 | #include "tp-test.h" |
| 13 | #include <asm/timex.h> |
| 14 | #include <asm/system.h> |
| 15 | |
| 16 | #define NR_LOOPS 200000 |
| 17 | |
| 18 | DEFINE_TRACE(kernel_test); |
| 19 | |
| 20 | struct proc_dir_entry *pentry = NULL; |
| 21 | |
| 22 | int test_val; |
| 23 | |
| 24 | static void do_testbaseline(void) |
| 25 | { |
| 26 | unsigned long flags; |
| 27 | unsigned int i; |
| 28 | cycles_t time1, time2, time; |
| 29 | u32 rem; |
| 30 | |
| 31 | local_irq_save(flags); |
| 32 | preempt_disable(); |
| 33 | time1 = get_cycles(); |
| 34 | for (i = 0; i < NR_LOOPS; i++) { |
| 35 | asm volatile (""); |
| 36 | } |
| 37 | time2 = get_cycles(); |
| 38 | local_irq_restore(flags); |
| 39 | preempt_enable(); |
| 40 | time = time2 - time1; |
| 41 | |
| 42 | printk(KERN_ALERT "test results: time for baseline\n"); |
| 43 | printk(KERN_ALERT "number of loops: %d\n", NR_LOOPS); |
| 44 | printk(KERN_ALERT "total time: %llu\n", time); |
| 45 | time = div_u64_rem(time, NR_LOOPS, &rem); |
| 46 | printk(KERN_ALERT "-> baseline takes %llu cycles\n", time); |
| 47 | printk(KERN_ALERT "test end\n"); |
| 48 | } |
| 49 | |
| 50 | static void do_test_tp(void) |
| 51 | { |
| 52 | unsigned long flags; |
| 53 | unsigned int i; |
| 54 | cycles_t time1, time2, time; |
| 55 | u32 rem; |
| 56 | |
| 57 | local_irq_save(flags); |
| 58 | preempt_disable(); |
| 59 | time1 = get_cycles(); |
| 60 | for (i = 0; i < NR_LOOPS; i++) { |
| 61 | trace_kernel_test((void *)999, (void *)10); |
| 62 | } |
| 63 | time2 = get_cycles(); |
| 64 | local_irq_restore(flags); |
| 65 | preempt_enable(); |
| 66 | time = time2 - time1; |
| 67 | |
| 68 | printk(KERN_ALERT "test results: time for one probe\n"); |
| 69 | printk(KERN_ALERT "number of loops: %d\n", NR_LOOPS); |
| 70 | printk(KERN_ALERT "total time: %llu\n", time); |
| 71 | time = div_u64_rem(time, NR_LOOPS, &rem); |
| 72 | printk(KERN_ALERT "-> one probe takes %llu cycles\n", time); |
| 73 | printk(KERN_ALERT "test end\n"); |
| 74 | } |
| 75 | |
| 76 | static int my_open(struct inode *inode, struct file *file) |
| 77 | { |
| 78 | do_testbaseline(); |
| 79 | do_test_tp(); |
| 80 | |
| 81 | return -EPERM; |
| 82 | } |
| 83 | |
| 84 | static const struct file_operations my_operations = { |
| 85 | .open = my_open, |
| 86 | }; |
| 87 | |
| 88 | static int ltt_test_init(void) |
| 89 | { |
| 90 | printk(KERN_ALERT "test init\n"); |
| 91 | pentry = create_proc_entry("testltt", 0444, NULL); |
| 92 | if (pentry) |
| 93 | pentry->proc_fops = &my_operations; |
| 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | static void ltt_test_exit(void) |
| 98 | { |
| 99 | printk(KERN_ALERT "test exit\n"); |
| 100 | remove_proc_entry("testltt", NULL); |
| 101 | } |
| 102 | |
| 103 | module_init(ltt_test_init) |
| 104 | module_exit(ltt_test_exit) |
| 105 | |
| 106 | MODULE_LICENSE("GPL"); |
| 107 | MODULE_AUTHOR("Mathieu Desnoyers"); |
| 108 | MODULE_DESCRIPTION("TP test"); |