/trunk/kernel/test/mm/falloc1.c |
---|
55,13 → 55,16 |
for (run = 0; run < TEST_RUNS; run++) { |
for (order = 0; order <= MAX_ORDER; order++) { |
printf("Allocating %d frames blocks ... ", 1 << order); |
if (!quiet) |
printf("Allocating %d frames blocks ... ", 1 << order); |
allocated = 0; |
for (i = 0; i < MAX_FRAMES >> order; i++) { |
frames[allocated] = (uintptr_t) frame_alloc(order, FRAME_ATOMIC | FRAME_KA); |
if (ALIGN_UP(frames[allocated], FRAME_SIZE << order) != frames[allocated]) { |
printf("Block at address %p (size %dK) is not aligned\n", frames[allocated], (FRAME_SIZE << order) >> 10); |
if (!quiet) |
printf("Block at address %p (size %dK) is not aligned\n", frames[allocated], (FRAME_SIZE << order) >> 10); |
return "Test failed"; |
} |
68,12 → 71,14 |
if (frames[allocated]) |
allocated++; |
else { |
printf("done. "); |
if (!quiet) |
printf("done. "); |
break; |
} |
} |
printf("%d blocks allocated.\n", allocated); |
if (!quiet) |
printf("%d blocks allocated.\n", allocated); |
if (run) { |
if (results[order] != allocated) |
81,10 → 86,14 |
} else |
results[order] = allocated; |
printf("Deallocating ... "); |
if (!quiet) |
printf("Deallocating ... "); |
for (i = 0; i < allocated; i++) |
frame_free(KA2PA(frames[i])); |
printf("done.\n"); |
if (!quiet) |
printf("done.\n"); |
} |
} |
/trunk/kernel/test/mm/falloc2.c |
---|
47,6 → 47,7 |
static atomic_t thread_count; |
static atomic_t thread_fail; |
static bool sh_quiet; |
static void falloc(void * arg) |
{ |
56,7 → 57,8 |
uintptr_t * frames = (uintptr_t *) malloc(MAX_FRAMES * sizeof(uintptr_t), FRAME_ATOMIC); |
if (frames == NULL) { |
printf("Thread #%d (cpu%d): Unable to allocate frames\n", THREAD->tid, CPU->id); |
if (!sh_quiet) |
printf("Thread #%d (cpu%d): Unable to allocate frames\n", THREAD->tid, CPU->id); |
atomic_inc(&thread_fail); |
atomic_dec(&thread_count); |
return; |
66,7 → 68,9 |
for (run = 0; run < THREAD_RUNS; run++) { |
for (order = 0; order <= MAX_ORDER; order++) { |
printf("Thread #%d (cpu%d): Allocating %d frames blocks ... \n", THREAD->tid, CPU->id, 1 << order); |
if (!sh_quiet) |
printf("Thread #%d (cpu%d): Allocating %d frames blocks ... \n", THREAD->tid, CPU->id, 1 << order); |
allocated = 0; |
for (i = 0; i < (MAX_FRAMES >> order); i++) { |
frames[allocated] = (uintptr_t)frame_alloc(order, FRAME_ATOMIC | FRAME_KA); |
76,13 → 80,18 |
} else |
break; |
} |
printf("Thread #%d (cpu%d): %d blocks allocated.\n", THREAD->tid, CPU->id, allocated); |
printf("Thread #%d (cpu%d): Deallocating ... \n", THREAD->tid, CPU->id); |
if (!sh_quiet) |
printf("Thread #%d (cpu%d): %d blocks allocated.\n", THREAD->tid, CPU->id, allocated); |
if (!sh_quiet) |
printf("Thread #%d (cpu%d): Deallocating ... \n", THREAD->tid, CPU->id); |
for (i = 0; i < allocated; i++) { |
for (k = 0; k <= ((FRAME_SIZE << order) - 1); k++) { |
if (((uint8_t *) frames[i])[k] != val) { |
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); |
if (!sh_quiet) |
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); |
atomic_inc(&thread_fail); |
goto cleanup; |
} |
89,13 → 98,17 |
} |
frame_free(KA2PA(frames[i])); |
} |
printf("Thread #%d (cpu%d): Finished run.\n", THREAD->tid, CPU->id); |
if (!sh_quiet) |
printf("Thread #%d (cpu%d): Finished run.\n", THREAD->tid, CPU->id); |
} |
} |
cleanup: |
free(frames); |
printf("Thread #%d (cpu%d): Exiting\n", THREAD->tid, CPU->id); |
if (!sh_quiet) |
printf("Thread #%d (cpu%d): Exiting\n", THREAD->tid, CPU->id); |
atomic_dec(&thread_count); |
} |
102,6 → 115,7 |
char * test_falloc2(bool quiet) |
{ |
unsigned int i; |
sh_quiet = quiet; |
atomic_set(&thread_count, THREADS); |
atomic_set(&thread_fail, 0); |
109,7 → 123,8 |
for (i = 0; i < THREADS; i++) { |
thread_t * thrd = thread_create(falloc, NULL, TASK, 0, "falloc", false); |
if (!thrd) { |
printf("Could not create thread %d\n", i); |
if (!quiet) |
printf("Could not create thread %d\n", i); |
break; |
} |
thread_ready(thrd); |
116,7 → 131,8 |
} |
while (atomic_get(&thread_count) > 0) { |
printf("Threads left: %d\n", atomic_get(&thread_count)); |
if (!quiet) |
printf("Threads left: %d\n", atomic_get(&thread_count)); |
thread_sleep(1); |
} |
/trunk/kernel/test/mm/slab1.c |
---|
37,65 → 37,87 |
static void * data[VAL_COUNT]; |
static void testit(int size, int count) |
static void testit(int size, int count, bool quiet) |
{ |
slab_cache_t *cache; |
int i; |
printf("Creating cache, object size: %d.\n", size); |
cache = slab_cache_create("test_cache", size, 0, NULL, NULL, |
SLAB_CACHE_NOMAGAZINE); |
printf("Allocating %d items...", count); |
if (!quiet) |
printf("Creating cache, object size: %d.\n", size); |
cache = slab_cache_create("test_cache", size, 0, NULL, NULL, |
SLAB_CACHE_NOMAGAZINE); |
if (!quiet) |
printf("Allocating %d items...", count); |
for (i = 0; i < count; i++) { |
data[i] = slab_alloc(cache, 0); |
memsetb((uintptr_t) data[i], size, 0); |
} |
printf("done.\n"); |
printf("Freeing %d items...", count); |
for (i = 0; i < count; i++) { |
if (!quiet) { |
printf("done.\n"); |
printf("Freeing %d items...", count); |
} |
for (i = 0; i < count; i++) |
slab_free(cache, data[i]); |
if (!quiet) { |
printf("done.\n"); |
printf("Allocating %d items...", count); |
} |
printf("done.\n"); |
printf("Allocating %d items...", count); |
for (i = 0; i < count; i++) { |
data[i] = slab_alloc(cache, 0); |
memsetb((uintptr_t) data[i], size, 0); |
} |
printf("done.\n"); |
printf("Freeing %d items...", count / 2); |
for (i = count - 1; i >= count / 2; i--) { |
if (!quiet) { |
printf("done.\n"); |
printf("Freeing %d items...", count / 2); |
} |
for (i = count - 1; i >= count / 2; i--) |
slab_free(cache, data[i]); |
if (!quiet) { |
printf("done.\n"); |
printf("Allocating %d items...", count / 2); |
} |
printf("done.\n"); |
printf("Allocating %d items...", count / 2); |
for (i = count / 2; i < count; i++) { |
data[i] = slab_alloc(cache, 0); |
memsetb((uintptr_t) data[i], size, 0); |
} |
printf("done.\n"); |
printf("Freeing %d items...", count); |
for (i = 0; i < count; i++) { |
if (!quiet) { |
printf("done.\n"); |
printf("Freeing %d items...", count); |
} |
for (i = 0; i < count; i++) |
slab_free(cache, data[i]); |
} |
printf("done.\n"); |
if (!quiet) |
printf("done.\n"); |
slab_cache_destroy(cache); |
printf("Test complete.\n"); |
if (!quiet) |
printf("Test complete.\n"); |
} |
static void testsimple(void) |
static void testsimple(bool quiet) |
{ |
testit(100, VAL_COUNT); |
testit(200, VAL_COUNT); |
testit(1024, VAL_COUNT); |
testit(2048, 512); |
testit(4000, 128); |
testit(8192, 128); |
testit(16384, 128); |
testit(16385, 128); |
testit(100, VAL_COUNT, quiet); |
testit(200, VAL_COUNT, quiet); |
testit(1024, VAL_COUNT, quiet); |
testit(2048, 512, quiet); |
testit(4000, 128, quiet); |
testit(8192, 128, quiet); |
testit(16384, 128, quiet); |
testit(16385, 128, quiet); |
} |
#define THREADS 6 |
105,6 → 127,7 |
static void * thr_data[THREADS][THR_MEM_COUNT]; |
static slab_cache_t *thr_cache; |
static semaphore_t thr_sem; |
static bool sh_quiet; |
static void slabtest(void *data) |
{ |
113,7 → 136,9 |
thread_detach(THREAD); |
printf("Starting thread #%d...\n",THREAD->tid); |
if (!sh_quiet) |
printf("Starting thread #%d...\n", THREAD->tid); |
for (j = 0; j < 10; j++) { |
for (i = 0; i < THR_MEM_COUNT; i++) |
thr_data[offs][i] = slab_alloc(thr_cache,0); |
124,23 → 149,26 |
for (i = 0; i < THR_MEM_COUNT; i++) |
slab_free(thr_cache, thr_data[offs][i]); |
} |
printf("Thread #%d finished\n", THREAD->tid); |
if (!sh_quiet) |
printf("Thread #%d finished\n", THREAD->tid); |
semaphore_up(&thr_sem); |
} |
static void testthreads(void) |
static void testthreads(bool quiet) |
{ |
thread_t *t; |
int i; |
thr_cache = slab_cache_create("thread_cache", THR_MEM_SIZE, 0, |
NULL, NULL, |
SLAB_CACHE_NOMAGAZINE); |
thr_cache = slab_cache_create("thread_cache", THR_MEM_SIZE, 0, NULL, NULL, |
SLAB_CACHE_NOMAGAZINE); |
semaphore_initialize(&thr_sem, 0); |
for (i = 0; i < THREADS; i++) { |
if (!(t = thread_create(slabtest, (void *) (unative_t) i, TASK, 0, "slabtest", false))) |
printf("Could not create thread %d\n", i); |
else |
if (!(t = thread_create(slabtest, (void *) (unative_t) i, TASK, 0, "slabtest", false))) { |
if (!quiet) |
printf("Could not create thread %d\n", i); |
} else |
thread_ready(t); |
} |
148,14 → 176,17 |
semaphore_down(&thr_sem); |
slab_cache_destroy(thr_cache); |
printf("Test complete.\n"); |
if (!quiet) |
printf("Test complete.\n"); |
} |
char * test_slab1(bool quiet) |
{ |
testsimple(); |
testthreads(); |
sh_quiet = quiet; |
testsimple(quiet); |
testthreads(quiet); |
return NULL; |
} |
/trunk/kernel/test/mm/slab2.c |
---|
42,7 → 42,7 |
* free one of the caches. We should have everything in magazines, |
* now allocation should clean magazines and allow for full allocation. |
*/ |
static void totalmemtest(void) |
static void totalmemtest(bool quiet) |
{ |
slab_cache_t *cache1; |
slab_cache_t *cache2; |
49,68 → 49,84 |
int i; |
void *data1, *data2; |
void *olddata1=NULL, *olddata2=NULL; |
void *olddata1 = NULL, *olddata2 = NULL; |
cache1 = slab_cache_create("cache1_tst", ITEM_SIZE, 0, NULL, NULL, 0); |
cache2 = slab_cache_create("cache2_tst", ITEM_SIZE, 0, NULL, NULL, 0); |
printf("Allocating..."); |
if (!quiet) |
printf("Allocating..."); |
/* Use atomic alloc, so that we find end of memory */ |
do { |
data1 = slab_alloc(cache1, FRAME_ATOMIC); |
data2 = slab_alloc(cache2, FRAME_ATOMIC); |
if (!data1 || !data2) { |
if ((!data1) || (!data2)) { |
if (data1) |
slab_free(cache1,data1); |
slab_free(cache1, data1); |
if (data2) |
slab_free(cache2,data2); |
slab_free(cache2, data2); |
break; |
} |
memsetb((uintptr_t)data1, ITEM_SIZE, 0); |
memsetb((uintptr_t)data2, ITEM_SIZE, 0); |
*((void **)data1) = olddata1; |
*((void **)data2) = olddata2; |
memsetb((uintptr_t) data1, ITEM_SIZE, 0); |
memsetb((uintptr_t) data2, ITEM_SIZE, 0); |
*((void **) data1) = olddata1; |
*((void **) data2) = olddata2; |
olddata1 = data1; |
olddata2 = data2; |
} while(1); |
printf("done.\n"); |
} while (1); |
if (!quiet) { |
printf("done.\n"); |
printf("Deallocating cache2..."); |
} |
/* We do not have memory - now deallocate cache2 */ |
printf("Deallocating cache2..."); |
while (olddata2) { |
data2 = *((void **)olddata2); |
data2 = *((void **) olddata2); |
slab_free(cache2, olddata2); |
olddata2 = data2; |
} |
printf("done.\n"); |
printf("Allocating to cache1...\n"); |
for (i=0; i<30; i++) { |
if (!quiet) { |
printf("done.\n"); |
printf("Allocating to cache1...\n"); |
} |
for (i = 0; i < 30; i++) { |
data1 = slab_alloc(cache1, FRAME_ATOMIC); |
if (!data1) { |
printf("Incorrect memory size - use another test."); |
if (!quiet) |
printf("Incorrect memory size - use another test."); |
return; |
} |
memsetb((uintptr_t)data1, ITEM_SIZE, 0); |
*((void **)data1) = olddata1; |
memsetb((uintptr_t) data1, ITEM_SIZE, 0); |
*((void **) data1) = olddata1; |
olddata1 = data1; |
} |
while (1) { |
data1 = slab_alloc(cache1, FRAME_ATOMIC); |
if (!data1) { |
if (!data1) |
break; |
} |
memsetb((uintptr_t)data1, ITEM_SIZE, 0); |
*((void **)data1) = olddata1; |
memsetb((uintptr_t) data1, ITEM_SIZE, 0); |
*((void **) data1) = olddata1; |
olddata1 = data1; |
} |
printf("Deallocating cache1..."); |
if (!quiet) |
printf("Deallocating cache1..."); |
while (olddata1) { |
data1 = *((void **)olddata1); |
data1 = *((void **) olddata1); |
slab_free(cache1, olddata1); |
olddata1 = data1; |
} |
printf("done.\n"); |
slab_print_list(); |
if (!quiet) { |
printf("done.\n"); |
slab_print_list(); |
} |
slab_cache_destroy(cache1); |
slab_cache_destroy(cache2); |
} |
119,6 → 135,7 |
static semaphore_t thr_sem; |
static condvar_t thread_starter; |
static mutex_t starter_mutex; |
static bool sh_quiet; |
#define THREADS 8 |
125,55 → 142,69 |
static void slabtest(void *priv) |
{ |
void *data = NULL, *new; |
thread_detach(THREAD); |
mutex_lock(&starter_mutex); |
condvar_wait(&thread_starter,&starter_mutex); |
mutex_unlock(&starter_mutex); |
printf("Starting thread #%d...\n",THREAD->tid); |
if (!sh_quiet) |
printf("Starting thread #%d...\n",THREAD->tid); |
/* Alloc all */ |
printf("Thread #%d allocating...\n", THREAD->tid); |
if (!sh_quiet) |
printf("Thread #%d allocating...\n", THREAD->tid); |
while (1) { |
/* Call with atomic to detect end of memory */ |
new = slab_alloc(thr_cache, FRAME_ATOMIC); |
if (!new) |
break; |
*((void **)new) = data; |
*((void **) new) = data; |
data = new; |
} |
printf("Thread #%d releasing...\n", THREAD->tid); |
if (!sh_quiet) |
printf("Thread #%d releasing...\n", THREAD->tid); |
while (data) { |
new = *((void **)data); |
*((void **)data) = NULL; |
*((void **) data) = NULL; |
slab_free(thr_cache, data); |
data = new; |
} |
printf("Thread #%d allocating...\n", THREAD->tid); |
if (!sh_quiet) |
printf("Thread #%d allocating...\n", THREAD->tid); |
while (1) { |
/* Call with atomic to detect end of memory */ |
new = slab_alloc(thr_cache, FRAME_ATOMIC); |
if (!new) |
break; |
*((void **)new) = data; |
*((void **) new) = data; |
data = new; |
} |
printf("Thread #%d releasing...\n", THREAD->tid); |
if (!sh_quiet) |
printf("Thread #%d releasing...\n", THREAD->tid); |
while (data) { |
new = *((void **)data); |
*((void **)data) = NULL; |
*((void **) data) = NULL; |
slab_free(thr_cache, data); |
data = new; |
} |
printf("Thread #%d finished\n", THREAD->tid); |
if (!sh_quiet) |
printf("Thread #%d finished\n", THREAD->tid); |
slab_print_list(); |
semaphore_up(&thr_sem); |
} |
static void multitest(int size) |
static void multitest(int size, bool quiet) |
{ |
/* Start 8 threads that just allocate as much as possible, |
* then release everything, then again allocate, then release |
180,19 → 211,20 |
*/ |
thread_t *t; |
int i; |
printf("Running stress test with size %d\n", size); |
if (!quiet) |
printf("Running stress test with size %d\n", size); |
condvar_initialize(&thread_starter); |
mutex_initialize(&starter_mutex); |
thr_cache = slab_cache_create("thread_cache", size, 0, |
NULL, NULL, |
0); |
thr_cache = slab_cache_create("thread_cache", size, 0, NULL, NULL, 0); |
semaphore_initialize(&thr_sem,0); |
for (i = 0; i < THREADS; i++) { |
if (!(t = thread_create(slabtest, NULL, TASK, 0, "slabtest", false))) |
printf("Could not create thread %d\n", i); |
else |
if (!(t = thread_create(slabtest, NULL, TASK, 0, "slabtest", false))) { |
if (!quiet) |
printf("Could not create thread %d\n", i); |
} else |
thread_ready(t); |
} |
thread_sleep(1); |
202,21 → 234,26 |
semaphore_down(&thr_sem); |
slab_cache_destroy(thr_cache); |
printf("Stress test complete.\n"); |
if (!quiet) |
printf("Stress test complete.\n"); |
} |
char * test_slab2(bool quiet) |
{ |
printf("Running reclaim single-thread test .. pass 1\n"); |
totalmemtest(); |
printf("Running reclaim single-thread test .. pass 2\n"); |
totalmemtest(); |
printf("Reclaim test OK.\n"); |
multitest(128); |
multitest(2048); |
multitest(8192); |
printf("All done.\n"); |
sh_quiet = quiet; |
if (!quiet) |
printf("Running reclaim single-thread test .. pass 1\n"); |
totalmemtest(quiet); |
if (!quiet) |
printf("Running reclaim single-thread test .. pass 2\n"); |
totalmemtest(quiet); |
if (!quiet) |
printf("Reclaim test OK.\n"); |
multitest(128, quiet); |
multitest(2048, quiet); |
multitest(8192, quiet); |
return NULL; |
} |
/trunk/kernel/test/mm/mapping1.c |
---|
48,35 → 48,47 |
frame0 = (uintptr_t) frame_alloc(ONE_FRAME, FRAME_KA); |
frame1 = (uintptr_t) frame_alloc(ONE_FRAME, FRAME_KA); |
printf("Writing %#x to physical address %p.\n", VALUE0, KA2PA(frame0)); |
if (!quiet) |
printf("Writing %#x to physical address %p.\n", VALUE0, KA2PA(frame0)); |
*((uint32_t *) frame0) = VALUE0; |
printf("Writing %#x to physical address %p.\n", VALUE1, KA2PA(frame1)); |
if (!quiet) |
printf("Writing %#x to physical address %p.\n", VALUE1, KA2PA(frame1)); |
*((uint32_t *) frame1) = VALUE1; |
printf("Mapping virtual address %p to physical address %p.\n", PAGE0, KA2PA(frame0)); |
if (!quiet) |
printf("Mapping virtual address %p to physical address %p.\n", PAGE0, KA2PA(frame0)); |
page_mapping_insert(AS_KERNEL, PAGE0, KA2PA(frame0), PAGE_PRESENT | PAGE_WRITE); |
printf("Mapping virtual address %p to physical address %p.\n", PAGE1, KA2PA(frame1)); |
if (!quiet) |
printf("Mapping virtual address %p to physical address %p.\n", PAGE1, KA2PA(frame1)); |
page_mapping_insert(AS_KERNEL, PAGE1, KA2PA(frame1), PAGE_PRESENT | PAGE_WRITE); |
printf("Value at virtual address %p is %#x.\n", PAGE0, v0 = *((uint32_t *) PAGE0)); |
printf("Value at virtual address %p is %#x.\n", PAGE1, v1 = *((uint32_t *) PAGE1)); |
v0 = *((uint32_t *) PAGE0); |
v1 = *((uint32_t *) PAGE1); |
if (!quiet) { |
printf("Value at virtual address %p is %#x.\n", PAGE0, v0); |
printf("Value at virtual address %p is %#x.\n", PAGE1, v1); |
} |
if (v0 != VALUE0) |
return "Value at v0 not equal to VALUE0"; |
if (v1 != VALUE1) |
return "Value at v1 not equal to VALUE1"; |
printf("Writing %#x to virtual address %p.\n", 0, PAGE0); |
if (!quiet) |
printf("Writing %#x to virtual address %p.\n", 0, PAGE0); |
*((uint32_t *) PAGE0) = 0; |
printf("Writing %#x to virtual address %p.\n", 0, PAGE1); |
if (!quiet) |
printf("Writing %#x to virtual address %p.\n", 0, PAGE1); |
*((uint32_t *) PAGE1) = 0; |
v0 = *((uint32_t *) PAGE0); |
v1 = *((uint32_t *) PAGE1); |
printf("Value at virtual address %p is %#x.\n", PAGE0, *((uint32_t *) PAGE0)); |
printf("Value at virtual address %p is %#x.\n", PAGE1, *((uint32_t *) PAGE1)); |
if (!quiet) { |
printf("Value at virtual address %p is %#x.\n", PAGE0, *((uint32_t *) PAGE0)); |
printf("Value at virtual address %p is %#x.\n", PAGE1, *((uint32_t *) PAGE1)); |
} |
if (v0 != 0) |
return "Value at v0 not equal to 0"; |