3 * Compare local cmpxchg with irq disable / enable with cmpxchg_local for slub.
7 #include <linux/jiffies.h>
8 #include <linux/compiler.h>
9 #include <linux/init.h>
10 #include <linux/module.h>
11 #include <linux/calc64.h>
12 #include <asm/timex.h>
13 #include <asm/system.h>
15 #define TEST_COUNT 10000
17 static int slub_test_init(void)
19 void **v
= kmalloc(TEST_COUNT
* sizeof(void *), GFP_KERNEL
);
21 cycles_t time1
, time2
, time
;
25 printk(KERN_ALERT
"test init\n");
27 printk(KERN_ALERT
"SLUB Performance testing\n");
28 printk(KERN_ALERT
"========================\n");
29 printk(KERN_ALERT
"1. Kmalloc: Repeatedly allocate then free test\n");
30 for (size
= 8; size
<= PAGE_SIZE
<< 2; size
<<= 1) {
32 for (i
= 0; i
< TEST_COUNT
; i
++) {
33 v
[i
] = kmalloc(size
, GFP_KERNEL
);
38 printk(KERN_ALERT
"%i times kmalloc(%d) = \n", i
, size
);
39 printk(KERN_ALERT
"number of loops: %d\n", TEST_COUNT
);
40 printk(KERN_ALERT
"total time: %llu\n", time
);
41 time
= div_long_long_rem(time
, TEST_COUNT
, &rem
);
42 printk(KERN_ALERT
"-> %llu cycles\n", time
);
45 for (i
= 0; i
< TEST_COUNT
; i
++) {
51 printk(KERN_ALERT
"%i times kfree = \n", i
);
52 printk(KERN_ALERT
"number of loops: %d\n", TEST_COUNT
);
53 printk(KERN_ALERT
"total time: %llu\n", time
);
54 time
= div_long_long_rem(time
, TEST_COUNT
, &rem
);
55 printk(KERN_ALERT
"-> %llu cycles\n", time
);
58 printk(KERN_ALERT
"2. Kmalloc: alloc/free test\n");
59 for (size
= 8; size
<= PAGE_SIZE
<< 2; size
<<= 1) {
61 for (i
= 0; i
< TEST_COUNT
; i
++) {
62 kfree(kmalloc(size
, GFP_KERNEL
));
67 printk(KERN_ALERT
"%i times kmalloc(%d)/kfree = \n", i
, size
);
68 printk(KERN_ALERT
"number of loops: %d\n", TEST_COUNT
);
69 printk(KERN_ALERT
"total time: %llu\n", time
);
70 time
= div_long_long_rem(time
, TEST_COUNT
, &rem
);
71 printk(KERN_ALERT
"-> %llu cycles\n", time
);
74 printk(KERN_ALERT
"3. kmem_cache_alloc: Repeatedly allocate then free test\n");
75 for (size
= 3; size
<= PAGE_SHIFT
; size
++) {
77 for (i
= 0; i
< TEST_COUNT
; i
++) {
78 v
[i
] = kmem_cache_alloc(kmalloc_caches
+ size
, GFP_KERNEL
);
83 printk(KERN_ALERT
"%d times kmem_cache_alloc(%d) = \n", i
, 1 << size
);
84 printk(KERN_ALERT
"number of loops: %d\n", TEST_COUNT
);
85 printk(KERN_ALERT
"total time: %llu\n", time
);
86 time
= div_long_long_rem(time
, TEST_COUNT
, &rem
);
87 printk(KERN_ALERT
"-> %llu cycles\n", time
);
90 for (i
= 0; i
< TEST_COUNT
; i
++) {
91 kmem_cache_free(kmalloc_caches
+ size
, v
[i
]);
96 printk(KERN_ALERT
"%i times kmem_cache_free = \n", i
);
97 printk(KERN_ALERT
"number of loops: %d\n", TEST_COUNT
);
98 printk(KERN_ALERT
"total time: %llu\n", time
);
99 time
= div_long_long_rem(time
, TEST_COUNT
, &rem
);
100 printk(KERN_ALERT
"-> %llu cycles\n", time
);
103 printk(KERN_ALERT
"4. kmem_cache_alloc: alloc/free test\n");
104 for (size
= 3; size
<= PAGE_SHIFT
; size
++) {
105 time1
= get_cycles();
106 for (i
= 0; i
< TEST_COUNT
; i
++) {
107 kmem_cache_free(kmalloc_caches
+ size
,
108 kmem_cache_alloc(kmalloc_caches
+ size
,
111 time2
= get_cycles();
112 time
= time2
- time1
;
114 printk(KERN_ALERT
"%d times kmem_cache_alloc(%d)/kmem_cache_free = \n", i
, 1 << size
);
115 printk(KERN_ALERT
"number of loops: %d\n", TEST_COUNT
);
116 printk(KERN_ALERT
"total time: %llu\n", time
);
117 time
= div_long_long_rem(time
, TEST_COUNT
, &rem
);
118 printk(KERN_ALERT
"-> %llu cycles\n", time
);
120 printk(KERN_ALERT
"5. kmem_cache_zalloc: Repeatedly allocate then free test\n");
121 for (size
= 3; size
<= PAGE_SHIFT
; size
++) {
122 time1
= get_cycles();
123 for (i
= 0; i
< TEST_COUNT
; i
++) {
124 v
[i
] = kmem_cache_zalloc(kmalloc_caches
+ size
, GFP_KERNEL
);
126 time2
= get_cycles();
127 time
= time2
- time1
;
129 printk(KERN_ALERT
"%d times kmem_cache_zalloc(%d) = \n", i
, 1 << size
);
130 printk(KERN_ALERT
"number of loops: %d\n", TEST_COUNT
);
131 printk(KERN_ALERT
"total time: %llu\n", time
);
132 time
= div_long_long_rem(time
, TEST_COUNT
, &rem
);
133 printk(KERN_ALERT
"-> %llu cycles\n", time
);
135 time1
= get_cycles();
136 for (i
= 0; i
< TEST_COUNT
; i
++) {
137 kmem_cache_free(kmalloc_caches
+ size
, v
[i
]);
139 time2
= get_cycles();
140 time
= time2
- time1
;
142 printk(KERN_ALERT
"%i times kmem_cache_free = \n", i
);
143 printk(KERN_ALERT
"number of loops: %d\n", TEST_COUNT
);
144 printk(KERN_ALERT
"total time: %llu\n", time
);
145 time
= div_long_long_rem(time
, TEST_COUNT
, &rem
);
146 printk(KERN_ALERT
"-> %llu cycles\n", time
);
149 printk(KERN_ALERT
"6. kmem_cache_zalloc: alloc/free test\n");
150 for (size
= 3; size
<= PAGE_SHIFT
; size
++) {
151 time1
= get_cycles();
152 for (i
= 0; i
< TEST_COUNT
; i
++) {
153 kmem_cache_free(kmalloc_caches
+ size
,
154 kmem_cache_zalloc(kmalloc_caches
+ size
,
157 time2
= get_cycles();
158 time
= time2
- time1
;
160 printk(KERN_ALERT
"%d times kmem_cache_zalloc(%d)/kmem_cache_free = \n", i
, 1 << size
);
161 printk(KERN_ALERT
"number of loops: %d\n", TEST_COUNT
);
162 printk(KERN_ALERT
"total time: %llu\n", time
);
163 time
= div_long_long_rem(time
, TEST_COUNT
, &rem
);
164 printk(KERN_ALERT
"-> %llu cycles\n", time
);
169 return -EAGAIN
; /* Fail will directly unload the module */
172 static void slub_test_exit(void)
174 printk(KERN_ALERT
"test exit\n");
177 module_init(slub_test_init
)
178 module_exit(slub_test_exit
)
180 MODULE_LICENSE("GPL");
181 MODULE_AUTHOR("Mathieu Desnoyers");
182 MODULE_DESCRIPTION("SLUB test");
This page took 0.032542 seconds and 4 git commands to generate.