convert from svn repository: remove tags directory
[lttv.git] / trunk / tests / kernel / test-slub.c
CommitLineData
f211bc6c 1/* test-slub.c
2 *
3 * Compare local cmpxchg with irq disable / enable with cmpxchg_local for slub.
4 */
5
6
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>
14
15#define TEST_COUNT 10000
16
17static int slub_test_init(void)
18{
19 void **v = kmalloc(TEST_COUNT * sizeof(void *), GFP_KERNEL);
20 unsigned int i;
21 cycles_t time1, time2, time;
22 long rem;
23 int size;
24
25 printk(KERN_ALERT "test init\n");
26
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) {
31 time1 = get_cycles();
32 for (i = 0; i < TEST_COUNT; i++) {
33 v[i] = kmalloc(size, GFP_KERNEL);
34 }
35 time2 = get_cycles();
36 time = time2 - time1;
37
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);
43
44 time1 = get_cycles();
45 for (i = 0; i < TEST_COUNT; i++) {
46 kfree(v[i]);
47 }
48 time2 = get_cycles();
49 time = time2 - time1;
50
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);
56 }
57
58 printk(KERN_ALERT "2. Kmalloc: alloc/free test\n");
59 for (size = 8; size <= PAGE_SIZE << 2; size <<= 1) {
60 time1 = get_cycles();
61 for (i = 0; i < TEST_COUNT; i++) {
62 kfree(kmalloc(size, GFP_KERNEL));
63 }
64 time2 = get_cycles();
65 time = time2 - time1;
66
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);
72 }
73#if 0
74 printk(KERN_ALERT "3. kmem_cache_alloc: Repeatedly allocate then free test\n");
75 for (size = 3; size <= PAGE_SHIFT; size ++) {
76 time1 = get_cycles();
77 for (i = 0; i < TEST_COUNT; i++) {
78 v[i] = kmem_cache_alloc(kmalloc_caches + size, GFP_KERNEL);
79 }
80 time2 = get_cycles();
81 time = time2 - time1;
82
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);
88
89 time1 = get_cycles();
90 for (i = 0; i < TEST_COUNT; i++) {
91 kmem_cache_free(kmalloc_caches + size, v[i]);
92 }
93 time2 = get_cycles();
94 time = time2 - time1;
95
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);
101 }
102
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,
109 GFP_KERNEL));
110 }
111 time2 = get_cycles();
112 time = time2 - time1;
113
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);
119 }
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);
125 }
126 time2 = get_cycles();
127 time = time2 - time1;
128
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);
134
135 time1 = get_cycles();
136 for (i = 0; i < TEST_COUNT; i++) {
137 kmem_cache_free(kmalloc_caches + size, v[i]);
138 }
139 time2 = get_cycles();
140 time = time2 - time1;
141
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);
147 }
148
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,
155 GFP_KERNEL));
156 }
157 time2 = get_cycles();
158 time = time2 - time1;
159
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);
165
166 }
167#endif //0
168 kfree(v);
169 return -EAGAIN; /* Fail will directly unload the module */
170}
171
172static void slub_test_exit(void)
173{
174 printk(KERN_ALERT "test exit\n");
175}
176
177module_init(slub_test_init)
178module_exit(slub_test_exit)
179
180MODULE_LICENSE("GPL");
181MODULE_AUTHOR("Mathieu Desnoyers");
182MODULE_DESCRIPTION("SLUB test");
This page took 0.035735 seconds and 4 git commands to generate.