convert from svn repository: remove tags directory
[lttv.git] / trunk / tests / kernel / test-slub2.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
17extern atomic_t slub_fast_count;
18extern atomic_t slub_slow_count;
19
20static int slub_test_init(void)
21{
22 void **v = kmalloc(TEST_COUNT * sizeof(void *), GFP_KERNEL);
23 unsigned int i;
24 cycles_t time1, time2, time;
25 long rem;
26 int size;
27
28 printk(KERN_ALERT "test init\n");
29
30 printk("Fast slub free: %u\n", atomic_read(&slub_fast_count));
31 printk("Slow slub free: %u\n", atomic_read(&slub_slow_count));
32 printk(KERN_ALERT "SLUB Performance testing\n");
33 printk(KERN_ALERT "========================\n");
34 printk(KERN_ALERT "1. Kmalloc: Repeatedly allocate then free test\n");
35 for (size = 8; size <= PAGE_SIZE << 2; size <<= 1) {
36 time1 = get_cycles();
37 for (i = 0; i < TEST_COUNT; i++) {
38 v[i] = kmalloc(size, GFP_KERNEL);
39 }
40 time2 = get_cycles();
41 time = time2 - time1;
42
43 printk(KERN_ALERT "%i times kmalloc(%d) = \n", i, size);
44 printk(KERN_ALERT "number of loops: %d\n", TEST_COUNT);
45 printk(KERN_ALERT "total time: %llu\n", time);
46 time = div_long_long_rem(time, TEST_COUNT, &rem);
47 printk(KERN_ALERT "-> %llu cycles\n", time);
48
49 time1 = get_cycles();
50 for (i = 0; i < TEST_COUNT; i++) {
51 kfree(v[i]);
52 }
53 time2 = get_cycles();
54 time = time2 - time1;
55
56 printk(KERN_ALERT "%i times kfree = \n", i);
57 printk(KERN_ALERT "number of loops: %d\n", TEST_COUNT);
58 printk(KERN_ALERT "total time: %llu\n", time);
59 time = div_long_long_rem(time, TEST_COUNT, &rem);
60 printk(KERN_ALERT "-> %llu cycles\n", time);
61 }
62 printk("Fast slub free: %u\n", atomic_read(&slub_fast_count));
63 printk("Slow slub free: %u\n", atomic_read(&slub_slow_count));
64
65 printk(KERN_ALERT "2. Kmalloc: alloc/free test\n");
66 for (size = 8; size <= PAGE_SIZE << 2; size <<= 1) {
67 time1 = get_cycles();
68 for (i = 0; i < TEST_COUNT; i++) {
69 kfree(kmalloc(size, GFP_KERNEL));
70 }
71 time2 = get_cycles();
72 time = time2 - time1;
73
74 printk(KERN_ALERT "%i times kmalloc(%d)/kfree = \n", i, size);
75 printk(KERN_ALERT "number of loops: %d\n", TEST_COUNT);
76 printk(KERN_ALERT "total time: %llu\n", time);
77 time = div_long_long_rem(time, TEST_COUNT, &rem);
78 printk(KERN_ALERT "-> %llu cycles\n", time);
79 }
80 printk("Fast slub free: %u\n", atomic_read(&slub_fast_count));
81 printk("Slow slub free: %u\n", atomic_read(&slub_slow_count));
82#if 0
83 printk(KERN_ALERT "3. kmem_cache_alloc: Repeatedly allocate then free test\n");
84 for (size = 3; size <= PAGE_SHIFT; size ++) {
85 time1 = get_cycles();
86 for (i = 0; i < TEST_COUNT; i++) {
87 v[i] = kmem_cache_alloc(kmalloc_caches + size, GFP_KERNEL);
88 }
89 time2 = get_cycles();
90 time = time2 - time1;
91
92 printk(KERN_ALERT "%d times kmem_cache_alloc(%d) = \n", i, 1 << size);
93 printk(KERN_ALERT "number of loops: %d\n", TEST_COUNT);
94 printk(KERN_ALERT "total time: %llu\n", time);
95 time = div_long_long_rem(time, TEST_COUNT, &rem);
96 printk(KERN_ALERT "-> %llu cycles\n", time);
97
98 time1 = get_cycles();
99 for (i = 0; i < TEST_COUNT; i++) {
100 kmem_cache_free(kmalloc_caches + size, v[i]);
101 }
102 time2 = get_cycles();
103 time = time2 - time1;
104
105 printk(KERN_ALERT "%i times kmem_cache_free = \n", i);
106 printk(KERN_ALERT "number of loops: %d\n", TEST_COUNT);
107 printk(KERN_ALERT "total time: %llu\n", time);
108 time = div_long_long_rem(time, TEST_COUNT, &rem);
109 printk(KERN_ALERT "-> %llu cycles\n", time);
110 }
111
112 printk(KERN_ALERT "4. kmem_cache_alloc: alloc/free test\n");
113 for (size = 3; size <= PAGE_SHIFT; size++) {
114 time1 = get_cycles();
115 for (i = 0; i < TEST_COUNT; i++) {
116 kmem_cache_free(kmalloc_caches + size,
117 kmem_cache_alloc(kmalloc_caches + size,
118 GFP_KERNEL));
119 }
120 time2 = get_cycles();
121 time = time2 - time1;
122
123 printk(KERN_ALERT "%d times kmem_cache_alloc(%d)/kmem_cache_free = \n", i, 1 << size);
124 printk(KERN_ALERT "number of loops: %d\n", TEST_COUNT);
125 printk(KERN_ALERT "total time: %llu\n", time);
126 time = div_long_long_rem(time, TEST_COUNT, &rem);
127 printk(KERN_ALERT "-> %llu cycles\n", time);
128 }
129 printk(KERN_ALERT "5. kmem_cache_zalloc: Repeatedly allocate then free test\n");
130 for (size = 3; size <= PAGE_SHIFT; size ++) {
131 time1 = get_cycles();
132 for (i = 0; i < TEST_COUNT; i++) {
133 v[i] = kmem_cache_zalloc(kmalloc_caches + size, GFP_KERNEL);
134 }
135 time2 = get_cycles();
136 time = time2 - time1;
137
138 printk(KERN_ALERT "%d times kmem_cache_zalloc(%d) = \n", i, 1 << size);
139 printk(KERN_ALERT "number of loops: %d\n", TEST_COUNT);
140 printk(KERN_ALERT "total time: %llu\n", time);
141 time = div_long_long_rem(time, TEST_COUNT, &rem);
142 printk(KERN_ALERT "-> %llu cycles\n", time);
143
144 time1 = get_cycles();
145 for (i = 0; i < TEST_COUNT; i++) {
146 kmem_cache_free(kmalloc_caches + size, v[i]);
147 }
148 time2 = get_cycles();
149 time = time2 - time1;
150
151 printk(KERN_ALERT "%i times kmem_cache_free = \n", i);
152 printk(KERN_ALERT "number of loops: %d\n", TEST_COUNT);
153 printk(KERN_ALERT "total time: %llu\n", time);
154 time = div_long_long_rem(time, TEST_COUNT, &rem);
155 printk(KERN_ALERT "-> %llu cycles\n", time);
156 }
157
158 printk(KERN_ALERT "6. kmem_cache_zalloc: alloc/free test\n");
159 for (size = 3; size <= PAGE_SHIFT; size++) {
160 time1 = get_cycles();
161 for (i = 0; i < TEST_COUNT; i++) {
162 kmem_cache_free(kmalloc_caches + size,
163 kmem_cache_zalloc(kmalloc_caches + size,
164 GFP_KERNEL));
165 }
166 time2 = get_cycles();
167 time = time2 - time1;
168
169 printk(KERN_ALERT "%d times kmem_cache_zalloc(%d)/kmem_cache_free = \n", i, 1 << size);
170 printk(KERN_ALERT "number of loops: %d\n", TEST_COUNT);
171 printk(KERN_ALERT "total time: %llu\n", time);
172 time = div_long_long_rem(time, TEST_COUNT, &rem);
173 printk(KERN_ALERT "-> %llu cycles\n", time);
174
175 }
176#endif //0
177 kfree(v);
178 return -EAGAIN; /* Fail will directly unload the module */
179}
180
181static void slub_test_exit(void)
182{
183 printk(KERN_ALERT "test exit\n");
184}
185
186module_init(slub_test_init)
187module_exit(slub_test_exit)
188
189MODULE_LICENSE("GPL");
190MODULE_AUTHOR("Mathieu Desnoyers");
191MODULE_DESCRIPTION("SLUB test");
This page took 0.03431 seconds and 4 git commands to generate.