_M procs start up at _start/hart_entry for vcore0
[akaros.git] / tests / mproctests.c
index 37a2ded..8e7baa7 100644 (file)
@@ -1,54 +1,12 @@
+#include <arch/arch.h>
 #include <parlib.h>
+#include <rassert.h>
 #include <stdlib.h>
 #include <hart.h>
 #include <ros/mman.h>
 #include <ros/resource.h>
 #include <stdio.h>
-
-#ifdef __i386__ // TODO: fix me with per-arch user includes
-static __inline uint64_t
-read_tsc(void)
-{
-       uint64_t tsc;
-       __asm __volatile("rdtsc" : "=A" (tsc));
-       return tsc;
-}
-
-static __inline void
-cpu_relax(void)
-{
-       asm volatile("pause" : : : "memory");
-}
-#else
-static __inline uint64_t
-read_tsc(void)
-{
-       return read_perfctr(0,0);
-}
-
-static __inline void
-cpu_relax(void)
-{
-       int ctr = 8;
-       asm volatile("1: deccc %0; bne 1b; nop" :
-                    "=r"(ctr) : "0"(ctr) : "cc","memory");
-}
-#endif
-
-// ghetto udelay, put in a lib somewhere and export the tsc freq
-void udelay(uint64_t usec, uint64_t tsc_freq)
-{
-       uint64_t start, end, now;
-
-       start = read_tsc();
-    end = start + (tsc_freq * usec) / 1000000;
-       if (end == 0) printf("This is terribly wrong \n");
-       do {
-        cpu_relax();
-        now = read_tsc();
-       } while (now < end || (now > start && end < start));
-       return;
-}
+#include <timing.h>
 
 #define TEST_MMAP                                       1
 #define TEST_ONE_CORE                           2
@@ -108,8 +66,10 @@ int main(int argc, char** argv)
                                retval = hart_request(4);
                                break;
                        default:
-                               retval = hart_request(7);
+                               retval = hart_request(5);
                }
+               if (retval)
+                       panic("failed to allocate cores!");
                printf("Should see me if you want to relocate core0's context "
                        "when moving from RUNNING_S\n");
        }
@@ -117,12 +77,12 @@ int main(int argc, char** argv)
        // vcore0 only below here
        switch (test) {
                case TEST_YIELD_OUT_OF_ORDER:
-                       udelay(10000000, 1995014570);
+                       udelay(10000000);
                        printf("Core 2 should have yielded, asking for another\n");
-                       retval = hart_request(7);
+                       retval = hart_request(5);
                        break;
                case TEST_YIELD_0_OUT_OF_ORDER:
-                       udelay(5000000, 1995014570);
+                       udelay(5000000);
                        printf("Core %d yielding\n", vcoreid);
                        sys_yield();
                        printf("Core 0 came back where it left off in RUNNING_M!!!\n");
@@ -148,14 +108,14 @@ void hart_entry(void)
                switch (test) {
                        case TEST_INCREMENTAL_CHANGES:
                                // Testing asking for less than we already have
-                               udelay(1000000, 1995014570); // KVM's freq.  Whatever.
+                               udelay(1000000);
                                printf("Asking for too few:\n");
                                retval = hart_request(2);
                                printf("Should be -EINVAL(7): %d\n", retval);
                                // Testing getting more while running
                                printf("Asking for more while running:\n");
-                               udelay(1000000, 1995014570);
-                               retval = hart_request(7);
+                               udelay(1000000);
+                               retval = hart_request(5);
                                printf("core2's retval: %d\n", retval);
                                break;
                        case TEST_YIELD_OUT_OF_ORDER:
@@ -163,9 +123,9 @@ void hart_entry(void)
                                sys_yield();
                                break;
                        case TEST_YIELD_0_OUT_OF_ORDER:
-                               udelay(7500000, 1995014570);
+                               udelay(7500000);
                                printf("Core 0 should have yielded, asking for another\n");
-                               retval = hart_request(7);
+                               retval = hart_request(5);
                }
        }
        global_tests(vcoreid);
@@ -184,7 +144,7 @@ static void global_tests(uint32_t vcoreid)
                case TEST_SWITCH_TO_RUNNABLE_S:
                        if (vcoreid == 2) {
                                printf("Core %d trying to request 0/ switch to _S\n", vcoreid);
-                               udelay(3000000, 1995014570);
+                               udelay(3000000);
                                retval = hart_request(0);
                                // will only see this if we are scheduled()
                                printf("Core %d back up! (retval:%d)\n", vcoreid, retval);
@@ -193,8 +153,8 @@ static void global_tests(uint32_t vcoreid)
                        } 
                        while(1);
                case TEST_CRAZY_YIELDS:
-                       udelay(300000*vcoreid, 1995014570);
-                       hart_request(7);
+                       udelay(300000*vcoreid);
+                       hart_request(5);
                        sys_yield();
                        printf("should  never see me, unless you slip into *_S\n");
                        break;