Rev 780 | Rev 1062 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 780 | Rev 842 | ||
|---|---|---|---|
| Line 32... | Line 32... | ||
| 32 | #include <proc/thread.h> |
32 | #include <proc/thread.h> |
| 33 | #include <arch.h> |
33 | #include <arch.h> |
| 34 | #include <panic.h> |
34 | #include <panic.h> |
| 35 | #include <mm/frame.h> |
35 | #include <mm/frame.h> |
| 36 | #include <memstr.h> |
36 | #include <memstr.h> |
| - | 37 | #include <synch/condvar.h> |
|
| - | 38 | #include <synch/mutex.h> |
|
| 37 | 39 | ||
| 38 | #define ITEM_SIZE 256 |
40 | #define ITEM_SIZE 256 |
| 39 | 41 | ||
| 40 | /** Fill memory with 2 caches, when allocation fails, |
42 | /** Fill memory with 2 caches, when allocation fails, |
| 41 | * free one of the caches. We should have everything in magazines, |
43 | * free one of the caches. We should have everything in magazines, |
| Line 113... | Line 115... | ||
| 113 | slab_cache_destroy(cache2); |
115 | slab_cache_destroy(cache2); |
| 114 | } |
116 | } |
| 115 | 117 | ||
| 116 | slab_cache_t *thr_cache; |
118 | slab_cache_t *thr_cache; |
| 117 | semaphore_t thr_sem; |
119 | semaphore_t thr_sem; |
| - | 120 | condvar_t thread_starter; |
|
| - | 121 | mutex_t starter_mutex; |
|
| 118 | 122 | ||
| 119 | #define THREADS 8 |
123 | #define THREADS 8 |
| 120 | 124 | ||
| 121 | static void thread(void *priv) |
125 | static void thread(void *priv) |
| 122 | { |
126 | { |
| 123 | void *data=NULL, *new; |
127 | void *data=NULL, *new; |
| 124 | 128 | ||
| - | 129 | mutex_lock(&starter_mutex); |
|
| - | 130 | condvar_wait(&thread_starter,&starter_mutex); |
|
| - | 131 | mutex_unlock(&starter_mutex); |
|
| - | 132 | ||
| 125 | printf("Starting thread #%d...\n",THREAD->tid); |
133 | printf("Starting thread #%d...\n",THREAD->tid); |
| 126 | 134 | ||
| 127 | /* Alloc all */ |
135 | /* Alloc all */ |
| 128 | printf("Thread #%d allocating...\n", THREAD->tid); |
136 | printf("Thread #%d allocating...\n", THREAD->tid); |
| 129 | while (1) { |
137 | while (1) { |
| Line 170... | Line 178... | ||
| 170 | */ |
178 | */ |
| 171 | thread_t *t; |
179 | thread_t *t; |
| 172 | int i; |
180 | int i; |
| 173 | 181 | ||
| 174 | printf("Running stress test with size %d\n", size); |
182 | printf("Running stress test with size %d\n", size); |
| - | 183 | condvar_initialize(&thread_starter); |
|
| - | 184 | mutex_initialize(&starter_mutex); |
|
| - | 185 | ||
| 175 | thr_cache = slab_cache_create("thread_cache", size, 0, |
186 | thr_cache = slab_cache_create("thread_cache", size, 0, |
| 176 | NULL, NULL, |
187 | NULL, NULL, |
| 177 | 0); |
188 | 0); |
| 178 | semaphore_initialize(&thr_sem,0); |
189 | semaphore_initialize(&thr_sem,0); |
| 179 | for (i=0; i<THREADS; i++) { |
190 | for (i=0; i<THREADS; i++) { |
| 180 | if (!(t = thread_create(thread, NULL, TASK, 0))) |
191 | if (!(t = thread_create(thread, NULL, TASK, 0))) |
| 181 | panic("could not create thread\n"); |
192 | panic("could not create thread\n"); |
| 182 | thread_ready(t); |
193 | thread_ready(t); |
| 183 | } |
194 | } |
| - | 195 | thread_sleep(1); |
|
| - | 196 | condvar_broadcast(&thread_starter); |
|
| 184 | 197 | ||
| 185 | for (i=0; i<THREADS; i++) |
198 | for (i=0; i<THREADS; i++) |
| 186 | semaphore_down(&thr_sem); |
199 | semaphore_down(&thr_sem); |
| 187 | 200 | ||
| 188 | slab_cache_destroy(thr_cache); |
201 | slab_cache_destroy(thr_cache); |