Changeset 0f4f1b2 in mainline for kernel/test
- Timestamp:
- 2024-01-15T17:10:27Z (18 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
- Files:
-
- 6 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); -
kernel/test/synch/semaphore1.c
ra064d4f r0f4f1b2 89 89 thrd = thread_create(consumer, NULL, TASK, 90 90 THREAD_FLAG_NONE, "consumer"); 91 if (thrd) 92 thread_ready(thrd); 93 else 91 if (thrd) { 92 thread_start(thrd); 93 thread_detach(thrd); 94 } else { 94 95 TPRINTF("could not create consumer %d\n", i); 96 } 95 97 } 96 98 for (k = 0; k < (4 - i); k++) { 97 99 thrd = thread_create(producer, NULL, TASK, 98 100 THREAD_FLAG_NONE, "producer"); 99 if (thrd) 100 thread_ready(thrd); 101 else 101 if (thrd) { 102 thread_start(thrd); 103 thread_detach(thrd); 104 } else { 102 105 TPRINTF("could not create producer %d\n", i); 106 } 103 107 } 104 108 } -
kernel/test/synch/semaphore2.c
ra064d4f r0f4f1b2 92 92 thrd = thread_create(consumer, NULL, TASK, 93 93 THREAD_FLAG_NONE, "consumer"); 94 if (thrd) 95 thread_ready(thrd); 96 else 94 if (thrd) { 95 thread_start(thrd); 96 thread_detach(thrd); 97 } else { 97 98 TPRINTF("Error creating thread\n"); 99 } 98 100 } 99 101 -
kernel/test/thread/thread1.c
ra064d4f r0f4f1b2 38 38 39 39 static atomic_bool finish; 40 static atomic_size_t threads_finished;41 40 42 41 static void threadtest(void *data) … … 46 45 thread_usleep(100000); 47 46 } 48 atomic_inc(&threads_finished);49 47 } 50 48 51 49 const char *test_thread1(void) 52 50 { 53 unsigned int i; 54 size_t total = 0; 51 atomic_store(&finish, true); 55 52 56 atomic_store(&finish, true); 57 atomic_store(&threads_finished, 0); 53 thread_t *threads[THREADS] = { }; 58 54 59 for (i = 0; i < THREADS; i++) { 60 thread_t *t; 61 if (!(t = thread_create(threadtest, NULL, TASK, 62 THREAD_FLAG_NONE, "threadtest"))) { 55 for (int i = 0; i < THREADS; i++) { 56 threads[i] = thread_create(threadtest, NULL, 57 TASK, THREAD_FLAG_NONE, "threadtest"); 58 59 if (threads[i]) { 60 thread_start(threads[i]); 61 } else { 63 62 TPRINTF("Could not create thread %d\n", i); 64 63 break; 65 64 } 66 thread_ready(t);67 total++;68 65 } 69 66 … … 72 69 73 70 atomic_store(&finish, false); 74 while (atomic_load(&threads_finished) < total) { 75 TPRINTF("Threads left: %zu\n", total - atomic_load(&threads_finished)); 76 thread_sleep(1); 71 72 for (int i = 0; i < THREADS; i++) { 73 if (threads[i] != NULL) 74 thread_join(threads[i]); 75 76 TPRINTF("Threads left: %d\n", THREADS - i - 1); 77 77 } 78 78
Note:
See TracChangeset
for help on using the changeset viewer.