Changeset 0f4f1b2 in mainline for kernel/test/mm
- Timestamp:
- 2024-01-15T17:10:27Z (21 months ago)
- Branches:
- master
- Children:
- e82879c
- Parents:
- a064d4f
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2024-01-15 16:37:22)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2024-01-15 17:10:27)
- Location:
- kernel/test/mm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/test/mm/falloc2.c
ra064d4f r0f4f1b2 43 43 #define THREADS 8 44 44 45 static atomic_size_t thread_cnt;46 45 static atomic_size_t thread_fail; 47 46 … … 56 55 "Unable to allocate frames\n", THREAD->tid, CPU->id); 57 56 atomic_inc(&thread_fail); 58 atomic_dec(&thread_cnt);59 57 return; 60 58 } … … 108 106 TPRINTF("Thread #%" PRIu64 " (cpu%u): Exiting\n", 109 107 THREAD->tid, CPU->id); 110 atomic_dec(&thread_cnt);111 108 } 112 109 113 110 const char *test_falloc2(void) 114 111 { 115 atomic_store(&thread_cnt, THREADS);116 112 atomic_store(&thread_fail, 0); 113 114 thread_t *threads[THREADS] = { }; 117 115 118 116 for (unsigned int i = 0; i < THREADS; i++) { … … 123 121 break; 124 122 } 125 thread_ready(thrd); 123 thread_start(thrd); 124 threads[i] = thrd; 126 125 } 127 126 128 while (atomic_load(&thread_cnt) > 0) { 129 TPRINTF("Threads left: %zu\n", 130 atomic_load(&thread_cnt)); 131 thread_sleep(1); 127 for (unsigned int i = 0; i < THREADS; i++) { 128 if (threads[i] != NULL) 129 thread_join(threads[i]); 130 131 TPRINTF("Threads left: %u\n", THREADS - i - 1); 132 132 } 133 133 -
kernel/test/mm/slab1.c
ra064d4f r0f4f1b2 121 121 static void *thr_data[THREADS][THR_MEM_COUNT]; 122 122 static slab_cache_t *thr_cache; 123 static semaphore_t thr_sem;124 123 125 124 static void slabtest(void *data) … … 142 141 143 142 TPRINTF("Thread #%" PRIu64 " finished\n", THREAD->tid); 144 145 semaphore_up(&thr_sem);146 143 } 147 144 148 145 static void testthreads(void) 149 146 { 150 thread_t *t;151 int i;152 153 147 thr_cache = slab_cache_create("thread_cache", THR_MEM_SIZE, 0, NULL, NULL, 154 148 SLAB_CACHE_NOMAGAZINE); 155 149 156 semaphore_initialize(&thr_sem, 0); 157 for (i = 0; i < THREADS; i++) { 158 if (!(t = thread_create(slabtest, (void *) (sysarg_t) i, TASK, THREAD_FLAG_NONE, "slabtest"))) { 150 thread_t *threads[THREADS] = { }; 151 152 for (int i = 0; i < THREADS; i++) { 153 threads[i] = thread_create(slabtest, (void *) (sysarg_t) i, 154 TASK, THREAD_FLAG_NONE, "slabtest"); 155 if (threads[i]) { 156 thread_start(threads[i]); 157 } else { 159 158 TPRINTF("Could not create thread %d\n", i); 160 } else 161 thread_ready(t); 159 } 162 160 } 163 161 164 for (i = 0; i < THREADS; i++) 165 semaphore_down(&thr_sem); 162 for (int i = 0; i < THREADS; i++) { 163 if (threads[i] != NULL) 164 thread_join(threads[i]); 165 } 166 166 167 167 slab_cache_destroy(thr_cache); -
kernel/test/mm/slab2.c
ra064d4f r0f4f1b2 127 127 128 128 static slab_cache_t *thr_cache; 129 static semaphore_t thr_sem;130 129 static condvar_t thread_starter; 131 130 static mutex_t starter_mutex; … … 188 187 if (!test_quiet) 189 188 slab_print_list(); 190 191 semaphore_up(&thr_sem);192 189 } 193 190 … … 198 195 * then release everything, then again allocate, then release 199 196 */ 200 thread_t *t;201 int i;202 197 203 198 TPRINTF("Running stress test with size %d\n", size); … … 207 202 208 203 thr_cache = slab_cache_create("thread_cache", size, 0, NULL, NULL, 0); 209 semaphore_initialize(&thr_sem, 0); 210 for (i = 0; i < THREADS; i++) { 211 if (!(t = thread_create(slabtest, NULL, TASK, THREAD_FLAG_NONE, "slabtest"))) { 204 205 thread_t *threads[THREADS] = { }; 206 207 for (int i = 0; i < THREADS; i++) { 208 threads[i] = thread_create(slabtest, NULL, 209 TASK, THREAD_FLAG_NONE, "slabtest"); 210 if (threads[i]) { 211 thread_start(threads[i]); 212 } else { 212 213 TPRINTF("Could not create thread %d\n", i); 213 } else214 thread_ready(t);215 } 214 } 215 } 216 216 217 thread_sleep(1); 217 218 condvar_broadcast(&thread_starter); 218 219 219 for (i = 0; i < THREADS; i++) 220 semaphore_down(&thr_sem); 220 for (int i = 0; i < THREADS; i++) { 221 if (threads[i] != NULL) 222 thread_join(threads[i]); 223 } 221 224 222 225 slab_cache_destroy(thr_cache);
Note:
See TracChangeset
for help on using the changeset viewer.