Changeset deada67 in mainline for kernel/test/mm
- Timestamp:
- 2006-12-19T17:54:50Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 730376d
- Parents:
- 6536a4a9
- Location:
- kernel/test/mm
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/test/mm/falloc1.c
r6536a4a9 rdeada67 56 56 for (run = 0; run < TEST_RUNS; run++) { 57 57 for (order = 0; order <= MAX_ORDER; order++) { 58 printf("Allocating %d frames blocks ... ", 1 << order); 58 if (!quiet) 59 printf("Allocating %d frames blocks ... ", 1 << order); 60 59 61 allocated = 0; 60 62 for (i = 0; i < MAX_FRAMES >> order; i++) { … … 62 64 63 65 if (ALIGN_UP(frames[allocated], FRAME_SIZE << order) != frames[allocated]) { 64 printf("Block at address %p (size %dK) is not aligned\n", frames[allocated], (FRAME_SIZE << order) >> 10); 66 if (!quiet) 67 printf("Block at address %p (size %dK) is not aligned\n", frames[allocated], (FRAME_SIZE << order) >> 10); 65 68 return "Test failed"; 66 69 } … … 69 72 allocated++; 70 73 else { 71 printf("done. "); 74 if (!quiet) 75 printf("done. "); 72 76 break; 73 77 } 74 78 } 75 79 76 printf("%d blocks allocated.\n", allocated); 80 if (!quiet) 81 printf("%d blocks allocated.\n", allocated); 77 82 78 83 if (run) { … … 82 87 results[order] = allocated; 83 88 84 printf("Deallocating ... "); 89 if (!quiet) 90 printf("Deallocating ... "); 91 85 92 for (i = 0; i < allocated; i++) 86 93 frame_free(KA2PA(frames[i])); 87 printf("done.\n"); 94 95 if (!quiet) 96 printf("done.\n"); 88 97 } 89 98 } -
kernel/test/mm/falloc2.c
r6536a4a9 rdeada67 48 48 static atomic_t thread_count; 49 49 static atomic_t thread_fail; 50 static bool sh_quiet; 50 51 51 52 static void falloc(void * arg) … … 57 58 uintptr_t * frames = (uintptr_t *) malloc(MAX_FRAMES * sizeof(uintptr_t), FRAME_ATOMIC); 58 59 if (frames == NULL) { 59 printf("Thread #%d (cpu%d): Unable to allocate frames\n", THREAD->tid, CPU->id); 60 if (!sh_quiet) 61 printf("Thread #%d (cpu%d): Unable to allocate frames\n", THREAD->tid, CPU->id); 60 62 atomic_inc(&thread_fail); 61 63 atomic_dec(&thread_count); … … 67 69 for (run = 0; run < THREAD_RUNS; run++) { 68 70 for (order = 0; order <= MAX_ORDER; order++) { 69 printf("Thread #%d (cpu%d): Allocating %d frames blocks ... \n", THREAD->tid, CPU->id, 1 << order); 71 if (!sh_quiet) 72 printf("Thread #%d (cpu%d): Allocating %d frames blocks ... \n", THREAD->tid, CPU->id, 1 << order); 73 70 74 allocated = 0; 71 75 for (i = 0; i < (MAX_FRAMES >> order); i++) { … … 77 81 break; 78 82 } 79 printf("Thread #%d (cpu%d): %d blocks allocated.\n", THREAD->tid, CPU->id, allocated); 80 81 printf("Thread #%d (cpu%d): Deallocating ... \n", THREAD->tid, CPU->id); 83 84 if (!sh_quiet) 85 printf("Thread #%d (cpu%d): %d blocks allocated.\n", THREAD->tid, CPU->id, allocated); 86 87 if (!sh_quiet) 88 printf("Thread #%d (cpu%d): Deallocating ... \n", THREAD->tid, CPU->id); 89 82 90 for (i = 0; i < allocated; i++) { 83 91 for (k = 0; k <= ((FRAME_SIZE << order) - 1); k++) { 84 92 if (((uint8_t *) frames[i])[k] != val) { 85 printf("Thread #%d (cpu%d): Unexpected data (%d) in block %p offset %#zx\n", THREAD->tid, CPU->id, ((char *) frames[i])[k], frames[i], k); 93 if (!sh_quiet) 94 printf("Thread #%d (cpu%d): Unexpected data (%d) in block %p offset %#zx\n", THREAD->tid, CPU->id, ((char *) frames[i])[k], frames[i], k); 86 95 atomic_inc(&thread_fail); 87 96 goto cleanup; … … 90 99 frame_free(KA2PA(frames[i])); 91 100 } 92 printf("Thread #%d (cpu%d): Finished run.\n", THREAD->tid, CPU->id); 101 102 if (!sh_quiet) 103 printf("Thread #%d (cpu%d): Finished run.\n", THREAD->tid, CPU->id); 93 104 } 94 105 } … … 96 107 cleanup: 97 108 free(frames); 98 printf("Thread #%d (cpu%d): Exiting\n", THREAD->tid, CPU->id); 109 110 if (!sh_quiet) 111 printf("Thread #%d (cpu%d): Exiting\n", THREAD->tid, CPU->id); 99 112 atomic_dec(&thread_count); 100 113 } … … 103 116 { 104 117 unsigned int i; 118 sh_quiet = quiet; 105 119 106 120 atomic_set(&thread_count, THREADS); … … 110 124 thread_t * thrd = thread_create(falloc, NULL, TASK, 0, "falloc", false); 111 125 if (!thrd) { 112 printf("Could not create thread %d\n", i); 126 if (!quiet) 127 printf("Could not create thread %d\n", i); 113 128 break; 114 129 } … … 117 132 118 133 while (atomic_get(&thread_count) > 0) { 119 printf("Threads left: %d\n", atomic_get(&thread_count)); 134 if (!quiet) 135 printf("Threads left: %d\n", atomic_get(&thread_count)); 120 136 thread_sleep(1); 121 137 } -
kernel/test/mm/mapping1.c
r6536a4a9 rdeada67 49 49 frame0 = (uintptr_t) frame_alloc(ONE_FRAME, FRAME_KA); 50 50 frame1 = (uintptr_t) frame_alloc(ONE_FRAME, FRAME_KA); 51 52 printf("Writing %#x to physical address %p.\n", VALUE0, KA2PA(frame0)); 51 52 if (!quiet) 53 printf("Writing %#x to physical address %p.\n", VALUE0, KA2PA(frame0)); 53 54 *((uint32_t *) frame0) = VALUE0; 54 printf("Writing %#x to physical address %p.\n", VALUE1, KA2PA(frame1)); 55 if (!quiet) 56 printf("Writing %#x to physical address %p.\n", VALUE1, KA2PA(frame1)); 55 57 *((uint32_t *) frame1) = VALUE1; 56 58 57 printf("Mapping virtual address %p to physical address %p.\n", PAGE0, KA2PA(frame0)); 59 if (!quiet) 60 printf("Mapping virtual address %p to physical address %p.\n", PAGE0, KA2PA(frame0)); 58 61 page_mapping_insert(AS_KERNEL, PAGE0, KA2PA(frame0), PAGE_PRESENT | PAGE_WRITE); 59 printf("Mapping virtual address %p to physical address %p.\n", PAGE1, KA2PA(frame1)); 62 if (!quiet) 63 printf("Mapping virtual address %p to physical address %p.\n", PAGE1, KA2PA(frame1)); 60 64 page_mapping_insert(AS_KERNEL, PAGE1, KA2PA(frame1), PAGE_PRESENT | PAGE_WRITE); 61 65 62 printf("Value at virtual address %p is %#x.\n", PAGE0, v0 = *((uint32_t *) PAGE0)); 63 printf("Value at virtual address %p is %#x.\n", PAGE1, v1 = *((uint32_t *) PAGE1)); 66 v0 = *((uint32_t *) PAGE0); 67 v1 = *((uint32_t *) PAGE1); 68 if (!quiet) { 69 printf("Value at virtual address %p is %#x.\n", PAGE0, v0); 70 printf("Value at virtual address %p is %#x.\n", PAGE1, v1); 71 } 64 72 65 73 if (v0 != VALUE0) … … 67 75 if (v1 != VALUE1) 68 76 return "Value at v1 not equal to VALUE1"; 69 70 printf("Writing %#x to virtual address %p.\n", 0, PAGE0); 77 78 if (!quiet) 79 printf("Writing %#x to virtual address %p.\n", 0, PAGE0); 71 80 *((uint32_t *) PAGE0) = 0; 72 printf("Writing %#x to virtual address %p.\n", 0, PAGE1); 81 if (!quiet) 82 printf("Writing %#x to virtual address %p.\n", 0, PAGE1); 73 83 *((uint32_t *) PAGE1) = 0; 74 84 … … 76 86 v1 = *((uint32_t *) PAGE1); 77 87 78 printf("Value at virtual address %p is %#x.\n", PAGE0, *((uint32_t *) PAGE0)); 79 printf("Value at virtual address %p is %#x.\n", PAGE1, *((uint32_t *) PAGE1)); 88 if (!quiet) { 89 printf("Value at virtual address %p is %#x.\n", PAGE0, *((uint32_t *) PAGE0)); 90 printf("Value at virtual address %p is %#x.\n", PAGE1, *((uint32_t *) PAGE1)); 91 } 80 92 81 93 if (v0 != 0) -
kernel/test/mm/slab1.c
r6536a4a9 rdeada67 38 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 42 slab_cache_t *cache; 43 43 int i; 44 44 45 printf("Creating cache, object size: %d.\n", size); 46 cache = slab_cache_create("test_cache", size, 0, NULL, NULL, 47 SLAB_CACHE_NOMAGAZINE); 48 printf("Allocating %d items...", count); 45 if (!quiet) 46 printf("Creating cache, object size: %d.\n", size); 47 48 cache = slab_cache_create("test_cache", size, 0, NULL, NULL, 49 SLAB_CACHE_NOMAGAZINE); 50 51 if (!quiet) 52 printf("Allocating %d items...", count); 53 49 54 for (i = 0; i < count; i++) { 50 55 data[i] = slab_alloc(cache, 0); 51 56 memsetb((uintptr_t) data[i], size, 0); 52 57 } 53 printf("done.\n"); 54 printf("Freeing %d items...", count); 55 for (i = 0; i < count; i++) { 58 59 if (!quiet) { 60 printf("done.\n"); 61 printf("Freeing %d items...", count); 62 } 63 64 for (i = 0; i < count; i++) 56 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 60 printf("Allocating %d items...", count); 71 61 72 for (i = 0; i < count; i++) { 62 73 data[i] = slab_alloc(cache, 0); 63 74 memsetb((uintptr_t) data[i], size, 0); 64 75 } 65 printf("done.\n"); 66 67 printf("Freeing %d items...", count / 2); 68 for (i = count - 1; i >= count / 2; i--) { 76 77 if (!quiet) { 78 printf("done.\n"); 79 printf("Freeing %d items...", count / 2); 80 } 81 82 for (i = count - 1; i >= count / 2; i--) 69 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 73 printf("Allocating %d items...", count / 2); 89 74 90 for (i = count / 2; i < count; i++) { 75 91 data[i] = slab_alloc(cache, 0); 76 92 memsetb((uintptr_t) data[i], size, 0); 77 93 } 78 printf("done.\n"); 79 printf("Freeing %d items...", count); 80 for (i = 0; i < count; i++) { 94 95 if (!quiet) { 96 printf("done.\n"); 97 printf("Freeing %d items...", count); 98 } 99 100 for (i = 0; i < count; i++) 81 101 slab_free(cache, data[i]); 82 } 83 printf("done.\n"); 102 103 if (!quiet) 104 printf("done.\n"); 84 105 slab_cache_destroy(cache); 85 86 printf("Test complete.\n"); 106 107 if (!quiet) 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 );92 testit(200, VAL_COUNT );93 testit(1024, VAL_COUNT );94 testit(2048, 512 );95 testit(4000, 128 );96 testit(8192, 128 );97 testit(16384, 128 );98 testit(16385, 128 );113 testit(100, VAL_COUNT, quiet); 114 testit(200, VAL_COUNT, quiet); 115 testit(1024, VAL_COUNT, quiet); 116 testit(2048, 512, quiet); 117 testit(4000, 128, quiet); 118 testit(8192, 128, quiet); 119 testit(16384, 128, quiet); 120 testit(16385, 128, quiet); 99 121 } 100 122 … … 106 128 static slab_cache_t *thr_cache; 107 129 static semaphore_t thr_sem; 130 static bool sh_quiet; 108 131 109 132 static void slabtest(void *data) … … 114 137 thread_detach(THREAD); 115 138 116 printf("Starting thread #%d...\n",THREAD->tid); 139 if (!sh_quiet) 140 printf("Starting thread #%d...\n", THREAD->tid); 141 117 142 for (j = 0; j < 10; j++) { 118 143 for (i = 0; i < THR_MEM_COUNT; i++) … … 125 150 slab_free(thr_cache, thr_data[offs][i]); 126 151 } 127 printf("Thread #%d finished\n", THREAD->tid); 152 153 if (!sh_quiet) 154 printf("Thread #%d finished\n", THREAD->tid); 155 128 156 semaphore_up(&thr_sem); 129 157 } 130 158 131 static void testthreads( void)159 static void testthreads(bool quiet) 132 160 { 133 161 thread_t *t; 134 162 int i; 135 163 136 thr_cache = slab_cache_create("thread_cache", THR_MEM_SIZE, 0, 137 NULL, NULL, 138 SLAB_CACHE_NOMAGAZINE); 164 thr_cache = slab_cache_create("thread_cache", THR_MEM_SIZE, 0, NULL, NULL, 165 SLAB_CACHE_NOMAGAZINE); 139 166 semaphore_initialize(&thr_sem, 0); 140 167 for (i = 0; i < THREADS; i++) { 141 if (!(t = thread_create(slabtest, (void *) (unative_t) i, TASK, 0, "slabtest", false))) 142 printf("Could not create thread %d\n", i); 143 else 168 if (!(t = thread_create(slabtest, (void *) (unative_t) i, TASK, 0, "slabtest", false))) { 169 if (!quiet) 170 printf("Could not create thread %d\n", i); 171 } else 144 172 thread_ready(t); 145 173 } … … 149 177 150 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 184 char * test_slab1(bool quiet) 156 185 { 157 testsimple(); 158 testthreads(); 186 sh_quiet = quiet; 187 188 testsimple(quiet); 189 testthreads(quiet); 159 190 160 191 return NULL; -
kernel/test/mm/slab2.c
r6536a4a9 rdeada67 43 43 * now allocation should clean magazines and allow for full allocation. 44 44 */ 45 static void totalmemtest( void)45 static void totalmemtest(bool quiet) 46 46 { 47 47 slab_cache_t *cache1; … … 50 50 51 51 void *data1, *data2; 52 void *olddata1 =NULL, *olddata2=NULL;52 void *olddata1 = NULL, *olddata2 = NULL; 53 53 54 54 cache1 = slab_cache_create("cache1_tst", ITEM_SIZE, 0, NULL, NULL, 0); 55 55 cache2 = slab_cache_create("cache2_tst", ITEM_SIZE, 0, NULL, NULL, 0); 56 57 printf("Allocating..."); 56 57 if (!quiet) 58 printf("Allocating..."); 59 58 60 /* Use atomic alloc, so that we find end of memory */ 59 61 do { 60 62 data1 = slab_alloc(cache1, FRAME_ATOMIC); 61 63 data2 = slab_alloc(cache2, FRAME_ATOMIC); 62 if ( !data1 || !data2) {64 if ((!data1) || (!data2)) { 63 65 if (data1) 64 slab_free(cache1, data1);66 slab_free(cache1, data1); 65 67 if (data2) 66 slab_free(cache2, data2);68 slab_free(cache2, data2); 67 69 break; 68 70 } 69 memsetb((uintptr_t) data1, ITEM_SIZE, 0);70 memsetb((uintptr_t) data2, ITEM_SIZE, 0);71 *((void **) data1) = olddata1;72 *((void **) data2) = olddata2;71 memsetb((uintptr_t) data1, ITEM_SIZE, 0); 72 memsetb((uintptr_t) data2, ITEM_SIZE, 0); 73 *((void **) data1) = olddata1; 74 *((void **) data2) = olddata2; 73 75 olddata1 = data1; 74 76 olddata2 = data2; 75 } while(1); 76 printf("done.\n"); 77 } while (1); 78 79 if (!quiet) { 80 printf("done.\n"); 81 printf("Deallocating cache2..."); 82 } 83 77 84 /* We do not have memory - now deallocate cache2 */ 78 printf("Deallocating cache2...");79 85 while (olddata2) { 80 data2 = *((void **) olddata2);86 data2 = *((void **) olddata2); 81 87 slab_free(cache2, olddata2); 82 88 olddata2 = data2; 83 89 } 84 printf("done.\n"); 85 86 printf("Allocating to cache1...\n"); 87 for (i=0; i<30; i++) { 90 91 if (!quiet) { 92 printf("done.\n"); 93 printf("Allocating to cache1...\n"); 94 } 95 96 for (i = 0; i < 30; i++) { 88 97 data1 = slab_alloc(cache1, FRAME_ATOMIC); 89 98 if (!data1) { 90 printf("Incorrect memory size - use another test."); 99 if (!quiet) 100 printf("Incorrect memory size - use another test."); 91 101 return; 92 102 } 93 memsetb((uintptr_t) data1, ITEM_SIZE, 0);94 *((void **) data1) = olddata1;103 memsetb((uintptr_t) data1, ITEM_SIZE, 0); 104 *((void **) data1) = olddata1; 95 105 olddata1 = data1; 96 106 } 97 107 while (1) { 98 108 data1 = slab_alloc(cache1, FRAME_ATOMIC); 99 if (!data1) { 100 break; 101 } 102 memsetb((uintptr_t)data1, ITEM_SIZE, 0); 103 *((void **)data1) = olddata1; 104 olddata1 = data1; 105 } 106 printf("Deallocating cache1..."); 109 if (!data1) 110 break; 111 memsetb((uintptr_t) data1, ITEM_SIZE, 0); 112 *((void **) data1) = olddata1; 113 olddata1 = data1; 114 } 115 116 if (!quiet) 117 printf("Deallocating cache1..."); 118 107 119 while (olddata1) { 108 data1 = *((void **) olddata1);120 data1 = *((void **) olddata1); 109 121 slab_free(cache1, olddata1); 110 122 olddata1 = data1; 111 123 } 112 printf("done.\n"); 113 slab_print_list(); 124 125 if (!quiet) { 126 printf("done.\n"); 127 slab_print_list(); 128 } 129 114 130 slab_cache_destroy(cache1); 115 131 slab_cache_destroy(cache2); … … 120 136 static condvar_t thread_starter; 121 137 static mutex_t starter_mutex; 138 static bool sh_quiet; 122 139 123 140 #define THREADS 8 … … 126 143 { 127 144 void *data = NULL, *new; 128 145 129 146 thread_detach(THREAD); 130 147 131 148 mutex_lock(&starter_mutex); 132 149 condvar_wait(&thread_starter,&starter_mutex); 133 150 mutex_unlock(&starter_mutex); 134 135 printf("Starting thread #%d...\n",THREAD->tid); 151 152 if (!sh_quiet) 153 printf("Starting thread #%d...\n",THREAD->tid); 136 154 137 155 /* Alloc all */ 138 printf("Thread #%d allocating...\n", THREAD->tid); 156 if (!sh_quiet) 157 printf("Thread #%d allocating...\n", THREAD->tid); 158 139 159 while (1) { 140 160 /* Call with atomic to detect end of memory */ … … 142 162 if (!new) 143 163 break; 144 *((void **)new) = data; 145 data = new; 146 } 147 printf("Thread #%d releasing...\n", THREAD->tid); 164 *((void **) new) = data; 165 data = new; 166 } 167 168 if (!sh_quiet) 169 printf("Thread #%d releasing...\n", THREAD->tid); 170 148 171 while (data) { 149 172 new = *((void **)data); 150 *((void **) data) = NULL;173 *((void **) data) = NULL; 151 174 slab_free(thr_cache, data); 152 175 data = new; 153 176 } 154 printf("Thread #%d allocating...\n", THREAD->tid); 177 178 if (!sh_quiet) 179 printf("Thread #%d allocating...\n", THREAD->tid); 180 155 181 while (1) { 156 182 /* Call with atomic to detect end of memory */ … … 158 184 if (!new) 159 185 break; 160 *((void **)new) = data; 161 data = new; 162 } 163 printf("Thread #%d releasing...\n", THREAD->tid); 186 *((void **) new) = data; 187 data = new; 188 } 189 190 if (!sh_quiet) 191 printf("Thread #%d releasing...\n", THREAD->tid); 192 164 193 while (data) { 165 194 new = *((void **)data); 166 *((void **) data) = NULL;195 *((void **) data) = NULL; 167 196 slab_free(thr_cache, data); 168 197 data = new; 169 198 } 170 171 printf("Thread #%d finished\n", THREAD->tid); 199 200 if (!sh_quiet) 201 printf("Thread #%d finished\n", THREAD->tid); 202 172 203 slab_print_list(); 173 204 semaphore_up(&thr_sem); 174 205 } 175 206 176 static void multitest(int size )207 static void multitest(int size, bool quiet) 177 208 { 178 209 /* Start 8 threads that just allocate as much as possible, … … 181 212 thread_t *t; 182 213 int i; 183 184 printf("Running stress test with size %d\n", size); 214 215 if (!quiet) 216 printf("Running stress test with size %d\n", size); 217 185 218 condvar_initialize(&thread_starter); 186 219 mutex_initialize(&starter_mutex); 187 220 188 thr_cache = slab_cache_create("thread_cache", size, 0, 189 NULL, NULL, 190 0); 221 thr_cache = slab_cache_create("thread_cache", size, 0, NULL, NULL, 0); 191 222 semaphore_initialize(&thr_sem,0); 192 223 for (i = 0; i < THREADS; i++) { 193 if (!(t = thread_create(slabtest, NULL, TASK, 0, "slabtest", false))) 194 printf("Could not create thread %d\n", i); 195 else 224 if (!(t = thread_create(slabtest, NULL, TASK, 0, "slabtest", false))) { 225 if (!quiet) 226 printf("Could not create thread %d\n", i); 227 } else 196 228 thread_ready(t); 197 229 } … … 203 235 204 236 slab_cache_destroy(thr_cache); 205 printf("Stress test complete.\n"); 237 if (!quiet) 238 printf("Stress test complete.\n"); 206 239 } 207 240 208 241 char * test_slab2(bool quiet) 209 242 { 210 printf("Running reclaim single-thread test .. pass 1\n"); 211 totalmemtest(); 212 printf("Running reclaim single-thread test .. pass 2\n"); 213 totalmemtest(); 214 printf("Reclaim test OK.\n"); 215 216 multitest(128); 217 multitest(2048); 218 multitest(8192); 219 printf("All done.\n"); 243 sh_quiet = quiet; 244 245 if (!quiet) 246 printf("Running reclaim single-thread test .. pass 1\n"); 247 totalmemtest(quiet); 248 if (!quiet) 249 printf("Running reclaim single-thread test .. pass 2\n"); 250 totalmemtest(quiet); 251 if (!quiet) 252 printf("Reclaim test OK.\n"); 253 254 multitest(128, quiet); 255 multitest(2048, quiet); 256 multitest(8192, quiet); 220 257 221 258 return NULL;
Note:
See TracChangeset
for help on using the changeset viewer.