From b62706c9f2ceed65394457ae9b131996a2b29463 Mon Sep 17 00:00:00 2001 From: Brett Weiland Date: Fri, 24 Sep 2021 14:20:20 -0500 Subject: palloc/pfree found smp safe --- src/kernel/smp_racetest.c | 84 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 76 insertions(+), 8 deletions(-) (limited to 'src/kernel/smp_racetest.c') diff --git a/src/kernel/smp_racetest.c b/src/kernel/smp_racetest.c index f86e030..84321de 100644 --- a/src/kernel/smp_racetest.c +++ b/src/kernel/smp_racetest.c @@ -1,3 +1,6 @@ +//Disregard bad code here. +//I'm going to delete this whole file once I am confident smp is safe. + #define CHUNK_SIZE_FROM_INDEX(i) ((1 << ((i) + 5))) #include @@ -9,7 +12,7 @@ //will delete later -static uint8_t lockeroni = 0; +static uint16_t lockeroni = 0; void test_malloc(unsigned int cnt) { void *testchunks[cnt]; @@ -39,14 +42,79 @@ void test_malloc(unsigned int cnt) { printf("____________________________________\n"); unlock(&lockeroni); } -uint8_t cores_waiting = 4; -void sync_malloc() { - void *mtest; + +#define DEBUG_CORE_CNT 2 + +uint8_t cores_waiting = DEBUG_CORE_CNT; +uint8_t cores_waiting_2 = DEBUG_CORE_CNT; +uint8_t cores_waiting_3 = DEBUG_CORE_CNT; +uint8_t cores_waiting_4 = DEBUG_CORE_CNT; +uint8_t cores_waiting_5 = DEBUG_CORE_CNT; +void *smp_outputs[DEBUG_CORE_CNT]; + +void racetest() { + uint8_t core_id = get_coreid(); + uint8_t c_check; + unsigned int core_i; + asm("lock decb [%0]\n" - "spinlock:\n" + "spinlock_%=:\n" "cmpb [%0], 0\n" - "jnz spinlock\n" + "jnz spinlock_%=\n" ::"m"(cores_waiting)); - mtest = palloc(0x1000); - printf("Make sure none of these match -> %lx\n", mtest); + + smp_outputs[core_id] = palloc(0x1000); + printf("Make sure none of these match (palloc) -> %lx\n", smp_outputs[core_id]); + free(smp_outputs[core_id]); + + asm("lock decb [%0]\n" + "spinlock_%=:\n" + "cmpb [%0], 0\n" + "jnz spinlock_%=\n" + ::"m"(cores_waiting_2)); + + if(core_id == 0) { + for(core_i = 0; core_i < DEBUG_CORE_CNT; core_i++) { + for(c_check = core_i + 1; c_check < DEBUG_CORE_CNT; c_check++) { + if(smp_outputs[core_i] == smp_outputs[c_check]) { + printf("TEST FAILED\n"); + for(;;); + } + } + } + printf("TEST PASSED\n"); + printf("malloc beforehand: \n"); + debug_heap(); + } + + + asm("lock decb [%0]\n" + "spinlock_%=:\n" + "cmpb [%0], 0\n" + "jnz spinlock_%=\n" + ::"m"(cores_waiting_3)); + + + smp_outputs[core_id] = malloc(1); + printf("Make sure none of these match (malloc) -> %lx\n", smp_outputs[core_id]); + + asm("lock decb [%0]\n" + "spinlock_%=:\n" + "cmpb [%0], 0\n" + "jnz spinlock_%=\n" + ::"m"(cores_waiting_4)); + + if(core_id == 0) { + for(core_i = 0; core_i < DEBUG_CORE_CNT; core_i++) { + for(c_check = core_i + 1; c_check < DEBUG_CORE_CNT; c_check++) { + if(smp_outputs[core_i] == smp_outputs[c_check]) { + printf("TEST FAILED\n"); + for(;;); + } + } + } + printf("TEST PASSED\n"); + printf("malloc afterhand: \n"); + debug_heap(); + } } -- cgit v1.2.3