Rev 2022 | Rev 2029 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2022 | Rev 2028 | ||
---|---|---|---|
Line 35... | Line 35... | ||
35 | #include <mm/frame.h> |
35 | #include <mm/frame.h> |
36 | #include <memstr.h> |
36 | #include <memstr.h> |
37 | #include <synch/condvar.h> |
37 | #include <synch/condvar.h> |
38 | #include <synch/mutex.h> |
38 | #include <synch/mutex.h> |
39 | 39 | ||
40 | #ifdef CONFIG_BENCH |
- | |
41 | #include <arch/cycle.h> |
- | |
42 | #endif |
- | |
43 | - | ||
44 | #define ITEM_SIZE 256 |
40 | #define ITEM_SIZE 256 |
45 | 41 | ||
46 | /** Fill memory with 2 caches, when allocation fails, |
42 | /** Fill memory with 2 caches, when allocation fails, |
47 | * free one of the caches. We should have everything in magazines, |
43 | * free one of the caches. We should have everything in magazines, |
48 | * now allocation should clean magazines and allow for full allocation. |
44 | * now allocation should clean magazines and allow for full allocation. |
Line 75... | Line 71... | ||
75 | memsetb((uintptr_t)data2, ITEM_SIZE, 0); |
71 | memsetb((uintptr_t)data2, ITEM_SIZE, 0); |
76 | *((void **)data1) = olddata1; |
72 | *((void **)data1) = olddata1; |
77 | *((void **)data2) = olddata2; |
73 | *((void **)data2) = olddata2; |
78 | olddata1 = data1; |
74 | olddata1 = data1; |
79 | olddata2 = data2; |
75 | olddata2 = data2; |
80 | }while(1); |
76 | } while(1); |
81 | printf("done.\n"); |
77 | printf("done.\n"); |
82 | /* We do not have memory - now deallocate cache2 */ |
78 | /* We do not have memory - now deallocate cache2 */ |
83 | printf("Deallocating cache2..."); |
79 | printf("Deallocating cache2..."); |
84 | while (olddata2) { |
80 | while (olddata2) { |
85 | data2 = *((void **)olddata2); |
81 | data2 = *((void **)olddata2); |
Line 126... | Line 122... | ||
126 | 122 | ||
127 | #define THREADS 8 |
123 | #define THREADS 8 |
128 | 124 | ||
129 | static void slabtest(void *priv) |
125 | static void slabtest(void *priv) |
130 | { |
126 | { |
131 | void *data=NULL, *new; |
127 | void *data = NULL, *new; |
132 | 128 | ||
133 | thread_detach(THREAD); |
129 | thread_detach(THREAD); |
134 | 130 | ||
135 | mutex_lock(&starter_mutex); |
131 | mutex_lock(&starter_mutex); |
136 | condvar_wait(&thread_starter,&starter_mutex); |
132 | condvar_wait(&thread_starter,&starter_mutex); |
Line 170... | Line 166... | ||
170 | *((void **)data) = NULL; |
166 | *((void **)data) = NULL; |
171 | slab_free(thr_cache, data); |
167 | slab_free(thr_cache, data); |
172 | data = new; |
168 | data = new; |
173 | } |
169 | } |
174 | 170 | ||
175 | - | ||
176 | printf("Thread #%d finished\n", THREAD->tid); |
171 | printf("Thread #%d finished\n", THREAD->tid); |
177 | slab_print_list(); |
172 | slab_print_list(); |
178 | semaphore_up(&thr_sem); |
173 | semaphore_up(&thr_sem); |
179 | } |
174 | } |
180 | 175 | ||
181 | - | ||
182 | static void multitest(int size) |
176 | static void multitest(int size) |
183 | { |
177 | { |
184 | /* Start 8 threads that just allocate as much as possible, |
178 | /* Start 8 threads that just allocate as much as possible, |
185 | * then release everything, then again allocate, then release |
179 | * then release everything, then again allocate, then release |
186 | */ |
180 | */ |
Line 193... | Line 187... | ||
193 | 187 | ||
194 | thr_cache = slab_cache_create("thread_cache", size, 0, |
188 | thr_cache = slab_cache_create("thread_cache", size, 0, |
195 | NULL, NULL, |
189 | NULL, NULL, |
196 | 0); |
190 | 0); |
197 | semaphore_initialize(&thr_sem,0); |
191 | semaphore_initialize(&thr_sem,0); |
198 | for (i=0; i<THREADS; i++) { |
192 | for (i = 0; i < THREADS; i++) { |
199 | if (!(t = thread_create(slabtest, NULL, TASK, 0, "slabtest"))) |
193 | if (!(t = thread_create(slabtest, NULL, TASK, 0, "slabtest"))) |
200 | panic("could not create thread\n"); |
194 | printf("Could not create thread %d\n", i); |
- | 195 | else |
|
201 | thread_ready(t); |
196 | thread_ready(t); |
202 | } |
197 | } |
203 | thread_sleep(1); |
198 | thread_sleep(1); |
204 | condvar_broadcast(&thread_starter); |
199 | condvar_broadcast(&thread_starter); |
205 | 200 | ||
206 | for (i=0; i<THREADS; i++) |
201 | for (i = 0; i < THREADS; i++) |
207 | semaphore_down(&thr_sem); |
202 | semaphore_down(&thr_sem); |
208 | 203 | ||
209 | slab_cache_destroy(thr_cache); |
204 | slab_cache_destroy(thr_cache); |
210 | printf("Stress test complete.\n"); |
205 | printf("Stress test complete.\n"); |
211 | } |
206 | } |
212 | 207 | ||
213 | void test_slab2(void) |
208 | char * test_slab2(void) |
214 | { |
209 | { |
215 | #ifdef CONFIG_BENCH |
- | |
216 | uint64_t t0 = get_cycle(); |
- | |
217 | #endif |
- | |
218 | - | ||
219 | printf("Running reclaim single-thread test .. pass1\n"); |
210 | printf("Running reclaim single-thread test .. pass 1\n"); |
220 | totalmemtest(); |
211 | totalmemtest(); |
221 | printf("Running reclaim single-thread test .. pass2\n"); |
212 | printf("Running reclaim single-thread test .. pass 2\n"); |
222 | totalmemtest(); |
213 | totalmemtest(); |
223 | printf("Reclaim test OK.\n"); |
214 | printf("Reclaim test OK.\n"); |
224 | 215 | ||
225 | multitest(128); |
216 | multitest(128); |
226 | multitest(2048); |
217 | multitest(2048); |
227 | multitest(8192); |
218 | multitest(8192); |
228 | printf("All done.\n"); |
219 | printf("All done.\n"); |
229 | 220 | ||
230 | #ifdef CONFIG_BENCH |
- | |
231 | uint64_t dt = get_cycle() - t0; |
- | |
232 | printf("Time: %.*d cycles\n", sizeof(dt) * 2, dt); |
- | |
233 | #endif |
221 | return NULL; |
234 | } |
222 | } |