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");
69 * GENERIC_NOP1 GENERIC_NOP4,
71 * _not_ nops in 64-bit mode.
72 * 4: leal 0x00(,%esi,1),%esi
74 void genericfivebytesonefournops(void)
76 asm volatile (".byte 0x90,0x8d,0x74,0x26,0x00\n\t");
85 * assumed _not_ to be nops in 64-bit mode.
86 * leal 0x00(,%eax,1),%eax
88 void k7fivebytesonefournops(void)
90 asm volatile (".byte 0x90,0x8d,0x44,0x20,0x00\n\t");
96 void perform_test(const char *name
, void (*callback
)(void))
99 cycles_t cycles1
, cycles2
;
102 local_irq_save(flags
);
104 cycles1
= get_cycles();
106 for(i
=0; i
<NR_TESTS
; i
++) {
110 cycles2
= get_cycles();
112 local_irq_restore(flags
);
113 printk("test %s cycles : %llu\n", name
, cycles2
-cycles1
);
116 static int my_open(struct inode
*inode
, struct file
*file
)
118 printk("NR_TESTS %d\n", NR_TESTS
);
120 perform_test("empty", empty
);
121 perform_test("2-bytes jump", twobytesjump
);
122 perform_test("5-bytes jump", fivebytesjump
);
123 perform_test("3/2 nops", threetwonops
);
124 perform_test("5-bytes nop with long prefix", fivebytesnop
);
125 perform_test("5-bytes P6 nop", fivebytespsixnop
);
127 perform_test("Generic 1/4 5-bytes nops", genericfivebytesonefournops
);
128 perform_test("K7 1/4 5-bytes nops", k7fivebytesonefournops
);
135 static struct file_operations my_operations
= {
139 int init_module(void)
141 pentry
= create_proc_entry("testnops", 0444, NULL
);
143 pentry
->proc_fops
= &my_operations
;
148 void cleanup_module(void)
150 remove_proc_entry("testnops", NULL
);
153 MODULE_LICENSE("GPL");
154 MODULE_AUTHOR("Mathieu Desnoyers");
155 MODULE_DESCRIPTION("NOP Test");