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>
12 #define NR_TESTS 10000000
16 struct proc_dir_entry
*pentry
= NULL
;
26 void twobytesjump(void)
28 asm volatile ("jmp 1f\n\t"
29 ".byte 0x00, 0x00, 0x00\n\t"
36 void fivebytesjump(void)
38 asm volatile (".byte 0xe9, 0x00, 0x00, 0x00, 0x00\n\t");
44 void threetwonops(void)
46 asm volatile (".byte 0x66,0x66,0x90,0x66,0x90\n\t");
52 void fivebytesnop(void)
54 asm volatile (".byte 0x66,0x66,0x66,0x66,0x90\n\t");
60 void fivebytespsixnop(void)
62 asm volatile (".byte 0x0f,0x1f,0x44,0x00,0\n\t");
68 void perform_test(const char *name
, void (*callback
)(void))
71 cycles_t cycles1
, cycles2
;
74 local_irq_save(flags
);
76 cycles1
= get_cycles();
78 for(i
=0; i
<NR_TESTS
; i
++) {
82 cycles2
= get_cycles();
84 local_irq_restore(flags
);
85 printk("test %s cycles : %llu\n", name
, cycles2
-cycles1
);
88 static int my_open(struct inode
*inode
, struct file
*file
)
90 printk("NR_TESTS %d\n", NR_TESTS
);
92 perform_test("empty", empty
);
93 perform_test("2-bytes jump", twobytesjump
);
94 perform_test("5-bytes jump", fivebytesjump
);
95 perform_test("3/2 nops", threetwonops
);
96 perform_test("5-bytes nop with long prefix", fivebytesnop
);
97 perform_test("5-bytes P6 nop", fivebytespsixnop
);
103 static struct file_operations my_operations
= {
107 int init_module(void)
109 pentry
= create_proc_entry("testnops", 0444, NULL
);
111 pentry
->proc_fops
= &my_operations
;
116 void cleanup_module(void)
118 remove_proc_entry("testnops", NULL
);
121 MODULE_LICENSE("GPL");
122 MODULE_AUTHOR("Mathieu Desnoyers");
123 MODULE_DESCRIPTION("NOP Test");