39,17 → 39,16 |
#include <memstr.h> |
#include <arch.h> |
|
#define MAX_FRAMES 256 |
#define MAX_ORDER 8 |
#define MAX_FRAMES 256 |
#define MAX_ORDER 8 |
|
#define THREAD_RUNS 1 |
#define THREADS 8 |
#define THREAD_RUNS 1 |
#define THREADS 8 |
|
static atomic_t thread_count; |
static atomic_t thread_fail; |
static bool sh_quiet; |
|
static void falloc(void * arg) |
static void falloc(void *arg) |
{ |
int order, run, allocated, i; |
uint8_t val = THREAD->tid % THREADS; |
57,8 → 56,7 |
|
void **frames = (void **) malloc(MAX_FRAMES * sizeof(void *), FRAME_ATOMIC); |
if (frames == NULL) { |
if (!sh_quiet) |
printf("Thread #%" PRIu64 " (cpu%u): Unable to allocate frames\n", THREAD->tid, CPU->id); |
TPRINTF("Thread #%" PRIu64 " (cpu%u): Unable to allocate frames\n", THREAD->tid, CPU->id); |
atomic_inc(&thread_fail); |
atomic_dec(&thread_count); |
return; |
65,11 → 63,10 |
} |
|
thread_detach(THREAD); |
|
|
for (run = 0; run < THREAD_RUNS; run++) { |
for (order = 0; order <= MAX_ORDER; order++) { |
if (!sh_quiet) |
printf("Thread #%" PRIu64 " (cpu%u): Allocating %d frames blocks ... \n", THREAD->tid, CPU->id, 1 << order); |
TPRINTF("Thread #%" PRIu64 " (cpu%u): Allocating %d frames blocks ... \n", THREAD->tid, CPU->id, 1 << order); |
|
allocated = 0; |
for (i = 0; i < (MAX_FRAMES >> order); i++) { |
81,17 → 78,13 |
break; |
} |
|
if (!sh_quiet) |
printf("Thread #%" PRIu64 " (cpu%u): %d blocks allocated.\n", THREAD->tid, CPU->id, allocated); |
TPRINTF("Thread #%" PRIu64 " (cpu%u): %d blocks allocated.\n", THREAD->tid, CPU->id, allocated); |
TPRINTF("Thread #%" PRIu64 " (cpu%u): Deallocating ... \n", THREAD->tid, CPU->id); |
|
if (!sh_quiet) |
printf("Thread #%" PRIu64 " (cpu%u): Deallocating ... \n", THREAD->tid, CPU->id); |
|
for (i = 0; i < allocated; i++) { |
for (k = 0; k <= (((index_t) FRAME_SIZE << order) - 1); k++) { |
if (((uint8_t *) frames[i])[k] != val) { |
if (!sh_quiet) |
printf("Thread #%" PRIu64 " (cpu%u): Unexpected data (%c) in block %p offset %#" PRIi "\n", THREAD->tid, CPU->id, ((char *) frames[i])[k], frames[i], k); |
TPRINTF("Thread #%" PRIu64 " (cpu%u): Unexpected data (%c) in block %p offset %#" PRIi "\n", THREAD->tid, CPU->id, ((char *) frames[i])[k], frames[i], k); |
atomic_inc(&thread_fail); |
goto cleanup; |
} |
99,32 → 92,28 |
frame_free(KA2PA(frames[i])); |
} |
|
if (!sh_quiet) |
printf("Thread #%" PRIu64 " (cpu%u): Finished run.\n", THREAD->tid, CPU->id); |
TPRINTF("Thread #%" PRIu64 " (cpu%u): Finished run.\n", THREAD->tid, CPU->id); |
} |
} |
|
cleanup: |
|
cleanup: |
free(frames); |
|
if (!sh_quiet) |
printf("Thread #%" PRIu64 " (cpu%u): Exiting\n", THREAD->tid, CPU->id); |
TPRINTF("Thread #%" PRIu64 " (cpu%u): Exiting\n", THREAD->tid, CPU->id); |
atomic_dec(&thread_count); |
} |
|
char * test_falloc2(bool quiet) |
char *test_falloc2(void) |
{ |
unsigned int i; |
sh_quiet = quiet; |
|
|
atomic_set(&thread_count, THREADS); |
atomic_set(&thread_fail, 0); |
|
|
for (i = 0; i < THREADS; i++) { |
thread_t * thrd = thread_create(falloc, NULL, TASK, 0, "falloc", false); |
if (!thrd) { |
if (!quiet) |
printf("Could not create thread %u\n", i); |
TPRINTF("Could not create thread %u\n", i); |
break; |
} |
thread_ready(thrd); |
131,8 → 120,7 |
} |
|
while (atomic_get(&thread_count) > 0) { |
if (!quiet) |
printf("Threads left: %ld\n", atomic_get(&thread_count)); |
TPRINTF("Threads left: %ld\n", atomic_get(&thread_count)); |
thread_sleep(1); |
} |
|