Changeset deada67 in mainline for kernel/test/mm/slab2.c
- 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
- File:
-
- 1 edited
-
kernel/test/mm/slab2.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
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.
