| 1 | /* test-nop-speed.c |
| 2 | * |
| 3 | */ |
| 4 | |
| 5 | #include <linux/module.h> |
| 6 | #include <linux/proc_fs.h> |
| 7 | #include <linux/sched.h> |
| 8 | #include <linux/timex.h> |
| 9 | #include <linux/marker.h> |
| 10 | #include <asm/ptrace.h> |
| 11 | |
| 12 | #define NR_TESTS 20000 |
| 13 | |
| 14 | struct proc_dir_entry *pentry = NULL; |
| 15 | |
| 16 | void empty(void) |
| 17 | { |
| 18 | asm volatile (""); |
| 19 | } |
| 20 | |
| 21 | void twobytesjump(void) |
| 22 | { |
| 23 | asm volatile ("jmp 1f\n\t" |
| 24 | ".byte 0x00, 0x00, 0x00\n\t" |
| 25 | "1:\n\t"); |
| 26 | } |
| 27 | |
| 28 | void fivebytesjump(void) |
| 29 | { |
| 30 | asm (".byte 0xe9, 0x00, 0x00, 0x00, 0x00\n\t"); |
| 31 | } |
| 32 | |
| 33 | void threetwonops(void) |
| 34 | { |
| 35 | asm (".byte 0x66,0x66,0x90,0x66,0x90\n\t"); |
| 36 | } |
| 37 | |
| 38 | void fivebytesnop(void) |
| 39 | { |
| 40 | asm (".byte 0x66,0x66,0x66,0x66,0x90\n\t"); |
| 41 | } |
| 42 | |
| 43 | void fivebytespsixnop(void) |
| 44 | { |
| 45 | asm (".byte 0x0f,0x1f,0x44,0x00,0\n\t"); |
| 46 | } |
| 47 | |
| 48 | void perform_test(const char *name, void (*callback)(void)) |
| 49 | { |
| 50 | unsigned int i; |
| 51 | cycles_t cycles1, cycles2; |
| 52 | unsigned long flags; |
| 53 | |
| 54 | local_irq_save(flags); |
| 55 | rdtsc_barrier(); |
| 56 | cycles1 = get_cycles(); |
| 57 | rdtsc_barrier(); |
| 58 | for(i=0; i<NR_TESTS; i++) { |
| 59 | callback(); |
| 60 | } |
| 61 | rdtsc_barrier(); |
| 62 | cycles2 = get_cycles(); |
| 63 | rdtsc_barrier(); |
| 64 | local_irq_restore(flags); |
| 65 | printk("test %s cycles : %llu\n", name, cycles2-cycles1); |
| 66 | } |
| 67 | |
| 68 | static int my_open(struct inode *inode, struct file *file) |
| 69 | { |
| 70 | printk("NR_TESTS %d\n", NR_TESTS); |
| 71 | |
| 72 | perform_test("empty", empty); |
| 73 | perform_test("2-bytes jump", twobytesjump); |
| 74 | perform_test("5-bytes jump", fivebytesjump); |
| 75 | perform_test("3/2 nops", threetwonops); |
| 76 | perform_test("5-bytes nop with long prefix", fivebytesnop); |
| 77 | perform_test("5-bytes P6 nop", fivebytespsixnop); |
| 78 | |
| 79 | return -EPERM; |
| 80 | } |
| 81 | |
| 82 | |
| 83 | static struct file_operations my_operations = { |
| 84 | .open = my_open, |
| 85 | }; |
| 86 | |
| 87 | int init_module(void) |
| 88 | { |
| 89 | pentry = create_proc_entry("testnops", 0444, NULL); |
| 90 | if (pentry) |
| 91 | pentry->proc_fops = &my_operations; |
| 92 | |
| 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | void cleanup_module(void) |
| 97 | { |
| 98 | remove_proc_entry("testnops", NULL); |
| 99 | } |
| 100 | |
| 101 | MODULE_LICENSE("GPL"); |
| 102 | MODULE_AUTHOR("Mathieu Desnoyers"); |
| 103 | MODULE_DESCRIPTION("Marker Test"); |
| 104 | |