Changeset a35b458 in mainline for kernel/test/mm
- Timestamp:
- 2018-03-02T20:10:49Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1380b7
- Parents:
- 3061bc1
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
- Location:
- kernel/test/mm
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/test/mm/falloc1.c
r3061bc1 ra35b458 45 45 if (TEST_RUNS < 2) 46 46 return "Test is compiled with TEST_RUNS < 2"; 47 47 48 48 uintptr_t *frames = (uintptr_t *) 49 49 malloc(MAX_FRAMES * sizeof(uintptr_t), 0); 50 50 if (frames == NULL) 51 51 return "Unable to allocate frames"; 52 52 53 53 unsigned int results[MAX_FRAMES + 1]; 54 54 55 55 for (unsigned int run = 0; run < TEST_RUNS; run++) { 56 56 for (size_t count = 1; count <= MAX_FRAMES; count++) { 57 57 size_t bytes = FRAMES2SIZE(count); 58 58 59 59 TPRINTF("Allocating %zu frames blocks (%zu bytes) ... ", 60 60 count, bytes); 61 61 62 62 unsigned int allocated = 0; 63 63 for (unsigned int i = 0; i < (MAX_FRAMES / count); i++) { … … 70 70 } 71 71 } 72 72 73 73 TPRINTF("%d blocks allocated.\n", allocated); 74 74 75 75 if (run > 0) { 76 76 if (results[count] != allocated) … … 78 78 } else 79 79 results[count] = allocated; 80 80 81 81 TPRINTF("Deallocating ... "); 82 82 83 83 for (unsigned int i = 0; i < allocated; i++) 84 84 frame_free(frames[i], count); 85 85 86 86 TPRINTF("done.\n"); 87 87 } 88 88 } 89 89 90 90 free(frames); 91 91 92 92 return NULL; 93 93 } -
kernel/test/mm/falloc2.c
r3061bc1 ra35b458 51 51 { 52 52 uint8_t val = THREAD->tid % THREADS; 53 53 54 54 uintptr_t *frames = (uintptr_t *) 55 55 malloc(MAX_FRAMES * sizeof(uintptr_t), FRAME_ATOMIC); … … 61 61 return; 62 62 } 63 63 64 64 thread_detach(THREAD); 65 65 66 66 for (unsigned int run = 0; run < THREAD_RUNS; run++) { 67 67 for (size_t count = 1; count <= MAX_FRAMES; count++) { 68 68 size_t bytes = FRAMES2SIZE(count); 69 69 70 70 TPRINTF("Thread #%" PRIu64 " (cpu%u): " 71 71 "Allocating %zu frames blocks (%zu bytes) ... \n", THREAD->tid, 72 72 CPU->id, count, bytes); 73 73 74 74 unsigned int allocated = 0; 75 75 for (unsigned int i = 0; i < (MAX_FRAMES / count); i++) { … … 81 81 break; 82 82 } 83 83 84 84 TPRINTF("Thread #%" PRIu64 " (cpu%u): " 85 85 "%u blocks allocated.\n", THREAD->tid, CPU->id, … … 87 87 TPRINTF("Thread #%" PRIu64 " (cpu%u): " 88 88 "Deallocating ... \n", THREAD->tid, CPU->id); 89 89 90 90 for (unsigned int i = 0; i < allocated; i++) { 91 91 for (size_t k = 0; k < bytes; k++) { … … 101 101 frame_free(frames[i], count); 102 102 } 103 103 104 104 TPRINTF("Thread #%" PRIu64 " (cpu%u): " 105 105 "Finished run.\n", THREAD->tid, CPU->id); 106 106 } 107 107 } 108 108 109 109 cleanup: 110 110 free(frames); 111 111 112 112 TPRINTF("Thread #%" PRIu64 " (cpu%u): Exiting\n", 113 113 THREAD->tid, CPU->id); … … 119 119 atomic_set(&thread_count, THREADS); 120 120 atomic_set(&thread_fail, 0); 121 121 122 122 for (unsigned int i = 0; i < THREADS; i++) { 123 123 thread_t *thrd = thread_create(falloc, NULL, TASK, … … 129 129 thread_ready(thrd); 130 130 } 131 131 132 132 while (atomic_get(&thread_count) > 0) { 133 133 TPRINTF("Threads left: %" PRIua "\n", … … 135 135 thread_sleep(1); 136 136 } 137 137 138 138 if (atomic_get(&thread_fail) == 0) 139 139 return NULL; 140 140 141 141 return "Test failed"; 142 142 } -
kernel/test/mm/mapping1.c
r3061bc1 ra35b458 42 42 { 43 43 uintptr_t frame = frame_alloc(1, FRAME_NONE, 0); 44 44 45 45 uintptr_t page0 = km_map(frame, FRAME_SIZE, 46 46 PAGE_READ | PAGE_WRITE | PAGE_CACHEABLE); 47 47 TPRINTF("Virtual address %p mapped to physical address %p.\n", 48 48 (void *) page0, (void *) frame); 49 49 50 50 uintptr_t page1 = km_map(frame, FRAME_SIZE, 51 51 PAGE_READ | PAGE_WRITE | PAGE_CACHEABLE); 52 52 TPRINTF("Virtual address %p mapped to physical address %p.\n", 53 53 (void *) page1, (void *) frame); 54 54 55 55 for (unsigned int i = 0; i < 2; i++) { 56 56 TPRINTF("Writing magic using the first virtual address.\n"); 57 57 58 58 *((uint32_t *) page0) = TEST_MAGIC; 59 59 60 60 TPRINTF("Reading magic using the second virtual address.\n"); 61 61 62 62 uint32_t v = *((uint32_t *) page1); 63 63 64 64 if (v != TEST_MAGIC) { 65 65 km_unmap(page0, PAGE_SIZE); … … 68 68 return "Criss-cross read does not match the value written."; 69 69 } 70 70 71 71 TPRINTF("Writing zero using the second virtual address.\n"); 72 72 73 73 *((uint32_t *) page1) = 0; 74 74 75 75 TPRINTF("Reading zero using the first virtual address.\n"); 76 76 77 77 v = *((uint32_t *) page0); 78 78 79 79 if (v != 0) { 80 80 km_unmap(page0, PAGE_SIZE); … … 84 84 } 85 85 } 86 86 87 87 km_unmap(page0, PAGE_SIZE); 88 88 km_unmap(page1, PAGE_SIZE); 89 89 frame_free(frame, 1); 90 90 91 91 return NULL; 92 92 } -
kernel/test/mm/purge1.c
r3061bc1 ra35b458 44 44 tlb_entry_t entryi; 45 45 tlb_entry_t entryd; 46 46 47 47 int i; 48 48 49 49 entryd.word[0] = 0; 50 50 entryd.word[1] = 0; 51 51 52 52 entryd.p = true; /* present */ 53 53 entryd.ma = MA_WRITEBACK; … … 58 58 entryd.ppn = 0; 59 59 entryd.ps = PAGE_WIDTH; 60 60 61 61 entryi.word[0] = 0; 62 62 entryi.word[1] = 0; 63 63 64 64 entryi.p = true; /* present */ 65 65 entryi.ma = MA_WRITEBACK; … … 70 70 entryi.ppn = 0; 71 71 entryi.ps = PAGE_WIDTH; 72 72 73 73 for (i = 0; i < 100; i++) { 74 74 itc_mapping_insert(0 + i * (1 << PAGE_WIDTH), 8, entryi); 75 75 dtc_mapping_insert(0 + i * (1 << PAGE_WIDTH), 9, entryd); 76 76 } 77 77 78 78 tlb_invalidate_pages(8, 0x0c000, 14); 79 79 80 80 /* tlb_invalidate_all(); */ 81 81 82 82 return NULL; 83 83 } -
kernel/test/mm/slab1.c
r3061bc1 ra35b458 42 42 slab_cache_t *cache; 43 43 int i; 44 44 45 45 TPRINTF("Creating cache, object size: %d.\n", size); 46 46 47 47 cache = slab_cache_create("test_cache", size, 0, NULL, NULL, 48 48 SLAB_CACHE_NOMAGAZINE); 49 49 50 50 TPRINTF("Allocating %d items...", count); 51 51 52 52 for (i = 0; i < count; i++) { 53 53 data[i] = slab_alloc(cache, 0); 54 54 memsetb(data[i], size, 0); 55 55 } 56 56 57 57 TPRINTF("done.\n"); 58 58 59 59 TPRINTF("Freeing %d items...", count); 60 60 61 61 for (i = 0; i < count; i++) 62 62 slab_free(cache, data[i]); 63 63 64 64 TPRINTF("done.\n"); 65 65 66 66 TPRINTF("Allocating %d items...", count); 67 67 68 68 for (i = 0; i < count; i++) { 69 69 data[i] = slab_alloc(cache, 0); 70 70 memsetb(data[i], size, 0); 71 71 } 72 72 73 73 TPRINTF("done.\n"); 74 74 75 75 TPRINTF("Freeing %d items...", count / 2); 76 76 77 77 for (i = count - 1; i >= count / 2; i--) 78 78 slab_free(cache, data[i]); 79 79 80 80 TPRINTF("done.\n"); 81 81 82 82 TPRINTF("Allocating %d items...", count / 2); 83 83 84 84 for (i = count / 2; i < count; i++) { 85 85 data[i] = slab_alloc(cache, 0); 86 86 memsetb(data[i], size, 0); 87 87 } 88 88 89 89 TPRINTF("done.\n"); 90 90 91 91 TPRINTF("Freeing %d items...", count); 92 92 93 93 for (i = 0; i < count; i++) 94 94 slab_free(cache, data[i]); 95 95 96 96 TPRINTF("done.\n"); 97 97 98 98 slab_cache_destroy(cache); 99 99 100 100 TPRINTF("Test complete.\n"); 101 101 } … … 125 125 int offs = (int) (sysarg_t) data; 126 126 int i, j; 127 127 128 128 thread_detach(THREAD); 129 129 130 130 TPRINTF("Starting thread #%" PRIu64 "...\n", THREAD->tid); 131 131 132 132 for (j = 0; j < 10; j++) { 133 133 for (i = 0; i < THR_MEM_COUNT; i++) … … 140 140 slab_free(thr_cache, thr_data[offs][i]); 141 141 } 142 142 143 143 TPRINTF("Thread #%" PRIu64 " finished\n", THREAD->tid); 144 144 145 145 semaphore_up(&thr_sem); 146 146 } … … 150 150 thread_t *t; 151 151 int i; 152 152 153 153 thr_cache = slab_cache_create("thread_cache", THR_MEM_SIZE, 0, NULL, NULL, 154 154 SLAB_CACHE_NOMAGAZINE); 155 155 156 156 semaphore_initialize(&thr_sem, 0); 157 157 for (i = 0; i < THREADS; i++) { … … 164 164 for (i = 0; i < THREADS; i++) 165 165 semaphore_down(&thr_sem); 166 166 167 167 slab_cache_destroy(thr_cache); 168 168 169 169 TPRINTF("Test complete.\n"); 170 170 } … … 174 174 testsimple(); 175 175 testthreads(); 176 176 177 177 return NULL; 178 178 } -
kernel/test/mm/slab2.c
r3061bc1 ra35b458 48 48 slab_cache_t *cache2; 49 49 int i; 50 50 51 51 void *data1, *data2; 52 52 void *olddata1 = NULL, *olddata2 = NULL; 53 53 54 54 cache1 = slab_cache_create("test_cache1", ITEM_SIZE, 0, NULL, NULL, 0); 55 55 cache2 = slab_cache_create("test_cache2", ITEM_SIZE, 0, NULL, NULL, 0); 56 56 57 57 TPRINTF("Allocating..."); 58 58 59 59 /* Use atomic alloc, so that we find end of memory */ 60 60 do { … … 75 75 olddata2 = data2; 76 76 } while (true); 77 77 78 78 TPRINTF("done.\n"); 79 79 80 80 TPRINTF("Deallocating cache2..."); 81 81 82 82 /* We do not have memory - now deallocate cache2 */ 83 83 while (olddata2) { … … 86 86 olddata2 = data2; 87 87 } 88 88 89 89 TPRINTF("done.\n"); 90 90 91 91 TPRINTF("Allocating to cache1...\n"); 92 92 93 93 for (i = 0; i < 30; i++) { 94 94 data1 = slab_alloc(cache1, FRAME_ATOMIC); … … 109 109 olddata1 = data1; 110 110 } 111 111 112 112 TPRINTF("Deallocating cache1..."); 113 113 114 114 while (olddata1) { 115 115 data1 = *((void **) olddata1); … … 117 117 olddata1 = data1; 118 118 } 119 119 120 120 TPRINTF("done.\n"); 121 121 122 122 if (!test_quiet) 123 123 slab_print_list(); 124 124 125 125 slab_cache_destroy(cache1); 126 126 slab_cache_destroy(cache2); … … 137 137 { 138 138 void *data = NULL, *new; 139 139 140 140 thread_detach(THREAD); 141 141 142 142 mutex_lock(&starter_mutex); 143 143 condvar_wait(&thread_starter,&starter_mutex); 144 144 mutex_unlock(&starter_mutex); 145 145 146 146 TPRINTF("Starting thread #%" PRIu64 "...\n", THREAD->tid); 147 147 148 148 /* Alloc all */ 149 149 TPRINTF("Thread #%" PRIu64 " allocating...\n", THREAD->tid); 150 150 151 151 while (true) { 152 152 /* Call with atomic to detect end of memory */ … … 157 157 data = new; 158 158 } 159 159 160 160 TPRINTF("Thread #%" PRIu64 " releasing...\n", THREAD->tid); 161 161 162 162 while (data) { 163 163 new = *((void **)data); … … 166 166 data = new; 167 167 } 168 168 169 169 TPRINTF("Thread #%" PRIu64 " allocating...\n", THREAD->tid); 170 170 171 171 while (true) { 172 172 /* Call with atomic to detect end of memory */ … … 177 177 data = new; 178 178 } 179 179 180 180 TPRINTF("Thread #%" PRIu64 " releasing...\n", THREAD->tid); 181 181 182 182 while (data) { 183 183 new = *((void **)data); … … 186 186 data = new; 187 187 } 188 188 189 189 TPRINTF("Thread #%" PRIu64 " finished\n", THREAD->tid); 190 190 191 191 if (!test_quiet) 192 192 slab_print_list(); 193 193 194 194 semaphore_up(&thr_sem); 195 195 } … … 202 202 thread_t *t; 203 203 int i; 204 204 205 205 TPRINTF("Running stress test with size %d\n", size); 206 206 207 207 condvar_initialize(&thread_starter); 208 208 mutex_initialize(&starter_mutex, MUTEX_PASSIVE); 209 209 210 210 thr_cache = slab_cache_create("thread_cache", size, 0, NULL, NULL, 0); 211 211 semaphore_initialize(&thr_sem,0); … … 218 218 thread_sleep(1); 219 219 condvar_broadcast(&thread_starter); 220 220 221 221 for (i = 0; i < THREADS; i++) 222 222 semaphore_down(&thr_sem); 223 223 224 224 slab_cache_destroy(thr_cache); 225 225 TPRINTF("Stress test complete.\n"); … … 230 230 TPRINTF("Running reclaim single-thread test .. pass 1\n"); 231 231 totalmemtest(); 232 232 233 233 TPRINTF("Running reclaim single-thread test .. pass 2\n"); 234 234 totalmemtest(); 235 235 236 236 TPRINTF("Reclaim test OK.\n"); 237 237 238 238 multitest(128); 239 239 multitest(2048); 240 240 multitest(8192); 241 241 242 242 return NULL; 243 243 }
Note:
See TracChangeset
for help on using the changeset viewer.