Changeset cb01e1e in mainline for kernel/test/mm/slab2.c
- Timestamp:
- 2009-04-04T00:26:27Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a85aebd
- Parents:
- 171f9a1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/test/mm/slab2.c
r171f9a1 rcb01e1e 37 37 #include <synch/mutex.h> 38 38 39 #define ITEM_SIZE 25639 #define ITEM_SIZE 256 40 40 41 41 /** Fill memory with 2 caches, when allocation fails, … … 43 43 * now allocation should clean magazines and allow for full allocation. 44 44 */ 45 static void totalmemtest( bool quiet)45 static void totalmemtest(void) 46 46 { 47 47 slab_cache_t *cache1; 48 48 slab_cache_t *cache2; 49 49 int i; 50 50 51 51 void *data1, *data2; 52 52 void *olddata1 = NULL, *olddata2 = NULL; … … 55 55 cache2 = slab_cache_create("cache2_tst", ITEM_SIZE, 0, NULL, NULL, 0); 56 56 57 if (!quiet) 58 printf("Allocating..."); 57 TPRINTF("Allocating..."); 59 58 60 59 /* Use atomic alloc, so that we find end of memory */ … … 75 74 olddata1 = data1; 76 75 olddata2 = data2; 77 } while (1); 78 79 if (!quiet) { 80 printf("done.\n"); 81 printf("Deallocating cache2..."); 82 } 76 } while (true); 77 78 TPRINTF("done.\n"); 79 80 TPRINTF("Deallocating cache2..."); 83 81 84 82 /* We do not have memory - now deallocate cache2 */ … … 89 87 } 90 88 91 if (!quiet) { 92 printf("done.\n"); 93 printf("Allocating to cache1...\n"); 94 } 89 TPRINTF("done.\n"); 90 91 TPRINTF("Allocating to cache1...\n"); 95 92 96 93 for (i = 0; i < 30; i++) { 97 94 data1 = slab_alloc(cache1, FRAME_ATOMIC); 98 95 if (!data1) { 99 if (!quiet) 100 printf("Incorrect memory size - use another test."); 96 TPRINTF("Incorrect memory size - use another test."); 101 97 return; 102 98 } … … 105 101 olddata1 = data1; 106 102 } 107 while ( 1) {103 while (true) { 108 104 data1 = slab_alloc(cache1, FRAME_ATOMIC); 109 105 if (!data1) … … 114 110 } 115 111 116 if (!quiet) 117 printf("Deallocating cache1..."); 112 TPRINTF("Deallocating cache1..."); 118 113 119 114 while (olddata1) { … … 123 118 } 124 119 125 if (!quiet) { 126 printf("done.\n"); 127 slab_print_list(); 128 } 120 TPRINTF("done.\n"); 121 122 slab_print_list(); 129 123 130 124 slab_cache_destroy(cache1); … … 136 130 static condvar_t thread_starter; 137 131 static mutex_t starter_mutex; 138 static bool sh_quiet; 139 140 #define THREADS 8 132 133 #define THREADS 8 141 134 142 135 static void slabtest(void *priv) … … 150 143 mutex_unlock(&starter_mutex); 151 144 152 if (!sh_quiet) 153 printf("Starting thread #%" PRIu64 "...\n", THREAD->tid); 145 TPRINTF("Starting thread #%" PRIu64 "...\n", THREAD->tid); 154 146 155 147 /* Alloc all */ 156 if (!sh_quiet) 157 printf("Thread #%" PRIu64 " allocating...\n", THREAD->tid); 158 159 while (1) { 148 TPRINTF("Thread #%" PRIu64 " allocating...\n", THREAD->tid); 149 150 while (true) { 160 151 /* Call with atomic to detect end of memory */ 161 152 new = slab_alloc(thr_cache, FRAME_ATOMIC); … … 166 157 } 167 158 168 if (!sh_quiet) 169 printf("Thread #%" PRIu64 " releasing...\n", THREAD->tid); 159 TPRINTF("Thread #%" PRIu64 " releasing...\n", THREAD->tid); 170 160 171 161 while (data) { … … 176 166 } 177 167 178 if (!sh_quiet) 179 printf("Thread #%" PRIu64 " allocating...\n", THREAD->tid); 180 181 while (1) { 168 TPRINTF("Thread #%" PRIu64 " allocating...\n", THREAD->tid); 169 170 while (true) { 182 171 /* Call with atomic to detect end of memory */ 183 172 new = slab_alloc(thr_cache, FRAME_ATOMIC); … … 188 177 } 189 178 190 if (!sh_quiet) 191 printf("Thread #%" PRIu64 " releasing...\n", THREAD->tid); 179 TPRINTF("Thread #%" PRIu64 " releasing...\n", THREAD->tid); 192 180 193 181 while (data) { … … 198 186 } 199 187 200 if (!sh_quiet) 201 printf("Thread #%" PRIu64 " finished\n", THREAD->tid); 188 TPRINTF("Thread #%" PRIu64 " finished\n", THREAD->tid); 202 189 203 190 slab_print_list(); … … 205 192 } 206 193 207 static void multitest(int size , bool quiet)194 static void multitest(int size) 208 195 { 209 196 /* Start 8 threads that just allocate as much as possible, … … 213 200 int i; 214 201 215 if (!quiet) 216 printf("Running stress test with size %d\n", size); 202 TPRINTF("Running stress test with size %d\n", size); 217 203 218 204 condvar_initialize(&thread_starter); 219 205 mutex_initialize(&starter_mutex, MUTEX_PASSIVE); 220 206 221 207 thr_cache = slab_cache_create("thread_cache", size, 0, NULL, NULL, 0); 222 208 semaphore_initialize(&thr_sem,0); 223 209 for (i = 0; i < THREADS; i++) { 224 210 if (!(t = thread_create(slabtest, NULL, TASK, 0, "slabtest", false))) { 225 if (!quiet) 226 printf("Could not create thread %d\n", i); 211 TPRINTF("Could not create thread %d\n", i); 227 212 } else 228 213 thread_ready(t); … … 230 215 thread_sleep(1); 231 216 condvar_broadcast(&thread_starter); 232 217 233 218 for (i = 0; i < THREADS; i++) 234 219 semaphore_down(&thr_sem); 235 220 236 221 slab_cache_destroy(thr_cache); 237 if (!quiet) 238 printf("Stress test complete.\n"); 239 } 240 241 char * test_slab2(bool quiet) 242 { 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); 222 TPRINTF("Stress test complete.\n"); 223 } 224 225 char *test_slab2(void) 226 { 227 TPRINTF("Running reclaim single-thread test .. pass 1\n"); 228 totalmemtest(); 229 230 TPRINTF("Running reclaim single-thread test .. pass 2\n"); 231 totalmemtest(); 232 233 TPRINTF("Reclaim test OK.\n"); 234 235 multitest(128); 236 multitest(2048); 237 multitest(8192); 257 238 258 239 return NULL;
Note:
See TracChangeset
for help on using the changeset viewer.