Rev 2050 | Rev 2071 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 2050 | Rev 2053 | ||
|---|---|---|---|
| Line 35... | Line 35... | ||
| 35 | 35 | ||
| 36 | #define VAL_COUNT 1024 |
36 | #define VAL_COUNT 1024 |
| 37 | 37 | ||
| 38 | static void * data[VAL_COUNT]; |
38 | static void * data[VAL_COUNT]; |
| 39 | 39 | ||
| 40 | static void testit(int size, int count) |
40 | static void testit(int size, int count, bool quiet) |
| 41 | { |
41 | { |
| 42 | slab_cache_t *cache; |
42 | slab_cache_t *cache; |
| 43 | int i; |
43 | int i; |
| 44 | 44 | ||
| - | 45 | if (!quiet) |
|
| 45 | printf("Creating cache, object size: %d.\n", size); |
46 | printf("Creating cache, object size: %d.\n", size); |
| - | 47 | ||
| 46 | cache = slab_cache_create("test_cache", size, 0, NULL, NULL, |
48 | cache = slab_cache_create("test_cache", size, 0, NULL, NULL, |
| 47 | SLAB_CACHE_NOMAGAZINE); |
49 | SLAB_CACHE_NOMAGAZINE); |
| - | 50 | ||
| - | 51 | if (!quiet) |
|
| 48 | printf("Allocating %d items...", count); |
52 | printf("Allocating %d items...", count); |
| - | 53 | ||
| 49 | for (i = 0; i < count; i++) { |
54 | for (i = 0; i < count; i++) { |
| 50 | data[i] = slab_alloc(cache, 0); |
55 | data[i] = slab_alloc(cache, 0); |
| 51 | memsetb((uintptr_t) data[i], size, 0); |
56 | memsetb((uintptr_t) data[i], size, 0); |
| 52 | } |
57 | } |
| - | 58 | ||
| - | 59 | if (!quiet) { |
|
| 53 | printf("done.\n"); |
60 | printf("done.\n"); |
| 54 | printf("Freeing %d items...", count); |
61 | printf("Freeing %d items...", count); |
| - | 62 | } |
|
| - | 63 | ||
| 55 | for (i = 0; i < count; i++) { |
64 | for (i = 0; i < count; i++) |
| 56 | slab_free(cache, data[i]); |
65 | slab_free(cache, data[i]); |
| - | 66 | ||
| - | 67 | if (!quiet) { |
|
| - | 68 | printf("done.\n"); |
|
| - | 69 | printf("Allocating %d items...", count); |
|
| 57 | } |
70 | } |
| 58 | printf("done.\n"); |
- | |
| 59 | 71 | ||
| 60 | printf("Allocating %d items...", count); |
- | |
| 61 | for (i = 0; i < count; i++) { |
72 | for (i = 0; i < count; i++) { |
| 62 | data[i] = slab_alloc(cache, 0); |
73 | data[i] = slab_alloc(cache, 0); |
| 63 | memsetb((uintptr_t) data[i], size, 0); |
74 | memsetb((uintptr_t) data[i], size, 0); |
| 64 | } |
75 | } |
| - | 76 | ||
| - | 77 | if (!quiet) { |
|
| 65 | printf("done.\n"); |
78 | printf("done.\n"); |
| 66 | - | ||
| 67 | printf("Freeing %d items...", count / 2); |
79 | printf("Freeing %d items...", count / 2); |
| - | 80 | } |
|
| - | 81 | ||
| 68 | for (i = count - 1; i >= count / 2; i--) { |
82 | for (i = count - 1; i >= count / 2; i--) |
| 69 | slab_free(cache, data[i]); |
83 | slab_free(cache, data[i]); |
| - | 84 | ||
| - | 85 | if (!quiet) { |
|
| - | 86 | printf("done.\n"); |
|
| - | 87 | printf("Allocating %d items...", count / 2); |
|
| 70 | } |
88 | } |
| 71 | printf("done.\n"); |
- | |
| 72 | 89 | ||
| 73 | printf("Allocating %d items...", count / 2); |
- | |
| 74 | for (i = count / 2; i < count; i++) { |
90 | for (i = count / 2; i < count; i++) { |
| 75 | data[i] = slab_alloc(cache, 0); |
91 | data[i] = slab_alloc(cache, 0); |
| 76 | memsetb((uintptr_t) data[i], size, 0); |
92 | memsetb((uintptr_t) data[i], size, 0); |
| 77 | } |
93 | } |
| - | 94 | ||
| - | 95 | if (!quiet) { |
|
| 78 | printf("done.\n"); |
96 | printf("done.\n"); |
| 79 | printf("Freeing %d items...", count); |
97 | printf("Freeing %d items...", count); |
| 80 | for (i = 0; i < count; i++) { |
- | |
| 81 | slab_free(cache, data[i]); |
- | |
| 82 | } |
98 | } |
| - | 99 | ||
| - | 100 | for (i = 0; i < count; i++) |
|
| - | 101 | slab_free(cache, data[i]); |
|
| - | 102 | ||
| - | 103 | if (!quiet) |
|
| 83 | printf("done.\n"); |
104 | printf("done.\n"); |
| 84 | slab_cache_destroy(cache); |
105 | slab_cache_destroy(cache); |
| 85 | 106 | ||
| - | 107 | if (!quiet) |
|
| 86 | printf("Test complete.\n"); |
108 | printf("Test complete.\n"); |
| 87 | } |
109 | } |
| 88 | 110 | ||
| 89 | static void testsimple(void) |
111 | static void testsimple(bool quiet) |
| 90 | { |
112 | { |
| 91 | testit(100, VAL_COUNT); |
113 | testit(100, VAL_COUNT, quiet); |
| 92 | testit(200, VAL_COUNT); |
114 | testit(200, VAL_COUNT, quiet); |
| 93 | testit(1024, VAL_COUNT); |
115 | testit(1024, VAL_COUNT, quiet); |
| 94 | testit(2048, 512); |
116 | testit(2048, 512, quiet); |
| 95 | testit(4000, 128); |
117 | testit(4000, 128, quiet); |
| 96 | testit(8192, 128); |
118 | testit(8192, 128, quiet); |
| 97 | testit(16384, 128); |
119 | testit(16384, 128, quiet); |
| 98 | testit(16385, 128); |
120 | testit(16385, 128, quiet); |
| 99 | } |
121 | } |
| 100 | 122 | ||
| 101 | #define THREADS 6 |
123 | #define THREADS 6 |
| 102 | #define THR_MEM_COUNT 1024 |
124 | #define THR_MEM_COUNT 1024 |
| 103 | #define THR_MEM_SIZE 128 |
125 | #define THR_MEM_SIZE 128 |
| 104 | 126 | ||
| 105 | static void * thr_data[THREADS][THR_MEM_COUNT]; |
127 | static void * thr_data[THREADS][THR_MEM_COUNT]; |
| 106 | static slab_cache_t *thr_cache; |
128 | static slab_cache_t *thr_cache; |
| 107 | static semaphore_t thr_sem; |
129 | static semaphore_t thr_sem; |
| - | 130 | static bool sh_quiet; |
|
| 108 | 131 | ||
| 109 | static void slabtest(void *data) |
132 | static void slabtest(void *data) |
| 110 | { |
133 | { |
| 111 | int offs = (int) (unative_t) data; |
134 | int offs = (int) (unative_t) data; |
| 112 | int i, j; |
135 | int i, j; |
| 113 | 136 | ||
| 114 | thread_detach(THREAD); |
137 | thread_detach(THREAD); |
| 115 | 138 | ||
| - | 139 | if (!sh_quiet) |
|
| 116 | printf("Starting thread #%d...\n",THREAD->tid); |
140 | printf("Starting thread #%d...\n", THREAD->tid); |
| - | 141 | ||
| 117 | for (j = 0; j < 10; j++) { |
142 | for (j = 0; j < 10; j++) { |
| 118 | for (i = 0; i < THR_MEM_COUNT; i++) |
143 | for (i = 0; i < THR_MEM_COUNT; i++) |
| 119 | thr_data[offs][i] = slab_alloc(thr_cache,0); |
144 | thr_data[offs][i] = slab_alloc(thr_cache,0); |
| 120 | for (i = 0; i < THR_MEM_COUNT / 2; i++) |
145 | for (i = 0; i < THR_MEM_COUNT / 2; i++) |
| 121 | slab_free(thr_cache, thr_data[offs][i]); |
146 | slab_free(thr_cache, thr_data[offs][i]); |
| 122 | for (i = 0; i < THR_MEM_COUNT / 2; i++) |
147 | for (i = 0; i < THR_MEM_COUNT / 2; i++) |
| 123 | thr_data[offs][i] = slab_alloc(thr_cache, 0); |
148 | thr_data[offs][i] = slab_alloc(thr_cache, 0); |
| 124 | for (i = 0; i < THR_MEM_COUNT; i++) |
149 | for (i = 0; i < THR_MEM_COUNT; i++) |
| 125 | slab_free(thr_cache, thr_data[offs][i]); |
150 | slab_free(thr_cache, thr_data[offs][i]); |
| 126 | } |
151 | } |
| - | 152 | ||
| - | 153 | if (!sh_quiet) |
|
| 127 | printf("Thread #%d finished\n", THREAD->tid); |
154 | printf("Thread #%d finished\n", THREAD->tid); |
| - | 155 | ||
| 128 | semaphore_up(&thr_sem); |
156 | semaphore_up(&thr_sem); |
| 129 | } |
157 | } |
| 130 | 158 | ||
| 131 | static void testthreads(void) |
159 | static void testthreads(bool quiet) |
| 132 | { |
160 | { |
| 133 | thread_t *t; |
161 | thread_t *t; |
| 134 | int i; |
162 | int i; |
| 135 | 163 | ||
| 136 | thr_cache = slab_cache_create("thread_cache", THR_MEM_SIZE, 0, |
164 | thr_cache = slab_cache_create("thread_cache", THR_MEM_SIZE, 0, NULL, NULL, |
| 137 | NULL, NULL, |
- | |
| 138 | SLAB_CACHE_NOMAGAZINE); |
165 | SLAB_CACHE_NOMAGAZINE); |
| 139 | semaphore_initialize(&thr_sem, 0); |
166 | semaphore_initialize(&thr_sem, 0); |
| 140 | for (i = 0; i < THREADS; i++) { |
167 | for (i = 0; i < THREADS; i++) { |
| 141 | if (!(t = thread_create(slabtest, (void *) (unative_t) i, TASK, 0, "slabtest", false))) |
168 | if (!(t = thread_create(slabtest, (void *) (unative_t) i, TASK, 0, "slabtest", false))) { |
| - | 169 | if (!quiet) |
|
| 142 | printf("Could not create thread %d\n", i); |
170 | printf("Could not create thread %d\n", i); |
| 143 | else |
171 | } else |
| 144 | thread_ready(t); |
172 | thread_ready(t); |
| 145 | } |
173 | } |
| 146 | 174 | ||
| 147 | for (i = 0; i < THREADS; i++) |
175 | for (i = 0; i < THREADS; i++) |
| 148 | semaphore_down(&thr_sem); |
176 | semaphore_down(&thr_sem); |
| 149 | 177 | ||
| 150 | slab_cache_destroy(thr_cache); |
178 | slab_cache_destroy(thr_cache); |
| 151 | printf("Test complete.\n"); |
- | |
| 152 | 179 | ||
| - | 180 | if (!quiet) |
|
| - | 181 | printf("Test complete.\n"); |
|
| 153 | } |
182 | } |
| 154 | 183 | ||
| 155 | char * test_slab1(bool quiet) |
184 | char * test_slab1(bool quiet) |
| 156 | { |
185 | { |
| - | 186 | sh_quiet = quiet; |
|
| - | 187 | ||
| 157 | testsimple(); |
188 | testsimple(quiet); |
| 158 | testthreads(); |
189 | testthreads(quiet); |
| 159 | 190 | ||
| 160 | return NULL; |
191 | return NULL; |
| 161 | } |
192 | } |