summaryrefslogtreecommitdiff
path: root/src/kernel/smp_racetest.c
diff options
context:
space:
mode:
authorBrett Weiland <brett_weiland@bpcspace.com>2021-09-24 14:20:20 -0500
committerBrett Weiland <brett_weiland@bpcspace.com>2021-09-24 14:20:20 -0500
commitb62706c9f2ceed65394457ae9b131996a2b29463 (patch)
treee00d7d68f4dcaac07ae8931e0a7871ef34d270d6 /src/kernel/smp_racetest.c
parentcf7cd8be60c254b44b444c97dcb238d7cf3afd4c (diff)
palloc/pfree found smp safe
Diffstat (limited to 'src/kernel/smp_racetest.c')
-rw-r--r--src/kernel/smp_racetest.c84
1 files changed, 76 insertions, 8 deletions
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 <printf.h>
@@ -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();
+ }
}