From cf7cd8be60c254b44b444c97dcb238d7cf3afd4c Mon Sep 17 00:00:00 2001 From: Brett Weiland Date: Tue, 21 Sep 2021 10:50:33 -0500 Subject: palloc smp safe (testing required, NOT pfree) --- src/kernel/smp_racetest.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/kernel/smp_racetest.c (limited to 'src/kernel/smp_racetest.c') diff --git a/src/kernel/smp_racetest.c b/src/kernel/smp_racetest.c new file mode 100644 index 0000000..f86e030 --- /dev/null +++ b/src/kernel/smp_racetest.c @@ -0,0 +1,52 @@ +#define CHUNK_SIZE_FROM_INDEX(i) ((1 << ((i) + 5))) + +#include +#include +#include +#include +#include +#include + +//will delete later + +static uint8_t lockeroni = 0; + +void test_malloc(unsigned int cnt) { + void *testchunks[cnt]; + unsigned int rindex[cnt], testchunk_size, i, x; + + bzero(rindex, cnt * sizeof(unsigned int)); + for(x = 0; x < cnt; x++) { + testchunk_size = (CHUNK_SIZE_FROM_INDEX(randint() % 7) - 24); + testchunks[x] = malloc(testchunk_size); + printf("ALLOCATING CHUNK %p SIZE %i\n", (void *)testchunks[x] - 24, testchunk_size); + } + for(x = 0; x < cnt;) { + i = randint() % cnt; + if(rindex[i]) continue; + rindex[i] = x; + x++; + } + + for(x = 0; x < cnt; x++) { + //printf("FREEING CHUNK %p\n", (void *)testchunks[rindex[x]]); + free(testchunks[rindex[x]]); + } + + printf("\nmalloc tester:\n"); + printf("THIS NEEDS TO BE EMPTY______________\n"); + debug_heap(); + printf("____________________________________\n"); + unlock(&lockeroni); +} +uint8_t cores_waiting = 4; +void sync_malloc() { + void *mtest; + asm("lock decb [%0]\n" + "spinlock:\n" + "cmpb [%0], 0\n" + "jnz spinlock\n" + ::"m"(cores_waiting)); + mtest = palloc(0x1000); + printf("Make sure none of these match -> %lx\n", mtest); +} -- cgit v1.2.3