9ns: Fix dangling negative TFs
[akaros.git] / kern / src / manager.c
index 229be5d..a5d5766 100644 (file)
@@ -5,16 +5,11 @@
  */
 
 
-#ifdef __SHARC__
-#pragma nosharc
-#endif
-
 #include <ros/common.h>
 #include <smp.h>
 #include <arch/init.h>
 #include <mm.h>
 #include <elf.h>
-#include <frontend.h>
 
 #include <kmalloc.h>
 #include <assert.h>
 #include <process.h>
 #include <schedule.h>
 #include <syscall.h>
-#include <testing.h>
-#include <kfs.h>
+#include <ktest.h>
 #include <stdio.h>
 #include <time.h>
 #include <monitor.h>
-#include <colored_caches.h>
 #include <string.h>
 #include <pmap.h>
 #include <arch/console.h>
-#include <ros/time.h>
-#include <ros/arch/membar.h>
+#include <time.h>
 
 /*
  * Currently, if you leave this function by way of proc_run (process_workqueue
  */
 void manager(void)
 {
+       // LoL
+       #define MANAGER_FUNC(dev) PASTE(manager_,dev)
+
+       #if !defined(DEVELOPER_NAME) && \
+           (defined(CONFIG_KERNEL_TESTING) || \
+            defined(CONFIG_USERSPACE_TESTING))
+               #define DEVELOPER_NAME jenkins
+       #endif
+
        #ifndef DEVELOPER_NAME
                #define DEVELOPER_NAME brho
        #endif
 
-       // LoL
-       #define PASTE(s1,s2) s1 ## s2
-       #define MANAGER_FUNC(dev) PASTE(manager_,dev)
-
        void MANAGER_FUNC(DEVELOPER_NAME)(void);
        MANAGER_FUNC(DEVELOPER_NAME)();
 }
 
 char *p_argv[] = {0, 0, 0};
-char *p_envp[] = {"LD_LIBRARY_PATH=/lib", 0};
 /* Helper macro for quickly running a process.  Pass it a string, *file, and a
  * *proc. */
 #define quick_proc_run(x, p, f)                                                  \
-       (f) = do_file_open((x), 0, 0);                                               \
+       (f) = do_file_open((x), O_READ, 0);                                          \
        assert((f));                                                                 \
        p_argv[0] = file_name((f));                                                  \
-       (p) = proc_create((f), p_argv, p_envp);                                      \
+       (p) = proc_create((f), p_argv, NULL);                                        \
        kref_put(&(f)->f_kref);                                                      \
        spin_lock(&(p)->proc_lock);                                                  \
        __proc_set_state((p), PROC_RUNNABLE_S);                                      \
@@ -70,20 +66,20 @@ char *p_envp[] = {"LD_LIBRARY_PATH=/lib", 0};
        proc_decref((p));
 
 #define quick_proc_create(x, p, f)                                               \
-       (f) = do_file_open((x), 0, 0);                                               \
+       (f) = do_file_open((x), O_READ, 0);                                          \
        assert((f));                                                                 \
        p_argv[0] = file_name((f));                                                  \
-       (p) = proc_create((f), p_argv, p_envp);                                      \
+       (p) = proc_create((f), p_argv, NULL);                                        \
        kref_put(&(f)->f_kref);                                                      \
        spin_lock(&(p)->proc_lock);                                                  \
        __proc_set_state((p), PROC_RUNNABLE_S);                                      \
        spin_unlock(&(p)->proc_lock);
 
 #define quick_proc_color_run(x, p, c, f)                                         \
-       (f) = do_file_open((x), 0, 0);                                               \
+       (f) = do_file_open((x), O_READ, 0);                                          \
        assert((f));                                                                 \
        p_argv[0] = file_name((f));                                                  \
-       (p) = proc_create((f), p_argv, p_envp);                                      \
+       (p) = proc_create((f), p_argv, NULL);                                        \
        kref_put(&(f)->f_kref);                                                      \
        spin_lock(&(p)->proc_lock);                                                  \
        __proc_set_state((p), PROC_RUNNABLE_S);                                      \
@@ -95,10 +91,10 @@ char *p_envp[] = {"LD_LIBRARY_PATH=/lib", 0};
        proc_decref((p));
 
 #define quick_proc_color_create(x, p, c, f)                                      \
-       (f) = do_file_open((x), 0, 0);                                               \
+       (f) = do_file_open((x), O_READ, 0);                                          \
        assert((f));                                                                 \
        p_argv[0] = file_name((f));                                                  \
-       (p) = proc_create((f), p_argv, p_envp);                                      \
+       (p) = proc_create((f), p_argv, NULL);                                        \
        kref_put(&(f)->f_kref);                                                      \
        spin_lock(&(p)->proc_lock);                                                  \
        __proc_set_state((p), PROC_RUNNABLE_S);                                      \
@@ -112,8 +108,16 @@ void manager_brho(void)
        static bool first = TRUE;
        struct per_cpu_info *pcpui = &per_cpu_info[core_id()];
 
-       if (first) {    
-               printk("*** Hit shift-g to get into the monitor. ***\n");
+       if (first) {
+               printk("*** IRQs must be enabled for input emergency codes ***\n");
+               #ifdef CONFIG_X86
+               printk("*** Hit ctrl-g to enter the monitor. ***\n");
+               printk("*** Hit ctrl-q to force-enter the monitor. ***\n");
+               printk("*** Hit ctrl-b for a backtrace of core 0 ***\n");
+               #else
+               printk("*** Hit ctrl-g to enter the monitor. ***\n");
+               #warning "***** ctrl-g untested on riscv, check k/a/r/trap.c *****"
+               #endif
                first = FALSE;
        }
        /* just idle, and deal with things via interrupts.  or via face. */
@@ -126,7 +130,7 @@ void manager_brho(void)
 
 #if 0 /* ancient tests below: (keeping around til we ditch the manager) */
        // for testing taking cores, check in case 1 for usage
-       uint32_t corelist[MAX_NUM_CPUS];
+       uint32_t corelist[MAX_NUM_CORES];
        uint32_t num = 3;
        struct file *temp_f;
        static struct proc *p;
@@ -196,7 +200,7 @@ void manager_brho(void)
                        printd("Manager Progress: %d\n", progress);
                        // delay if you want to test rescheduling an MCP that yielded
                        //udelay(15000000);
-                       schedule();
+                       run_scheduler();
        }
        panic("If you see me, then you probably screwed up");
        monitor(0);
@@ -212,6 +216,35 @@ void manager_brho(void)
 #endif
 }
 
+void manager_jenkins()
+{
+       #ifdef CONFIG_KERNEL_TESTING
+               printk("<-- BEGIN_KERNEL_TESTS -->\n");
+               run_registered_ktest_suites();
+               printk("<-- END_KERNEL_TESTS -->\n");
+       #endif
+
+       // Run userspace tests (from config specified path).
+       #ifdef CONFIG_USERSPACE_TESTING
+       if (strlen(CONFIG_USERSPACE_TESTING_SCRIPT) != 0) {
+               char exec[] = "/bin/ash";
+               char *p_argv[] = {exec, CONFIG_USERSPACE_TESTING_SCRIPT, 0};
+
+               struct file *program = do_file_open(exec, O_READ, 0);
+               struct proc *p = proc_create(program, p_argv, NULL);
+               proc_wakeup(p);
+               proc_decref(p); /* let go of the reference created in proc_create() */
+               kref_put(&program->f_kref);
+               run_scheduler();
+           // Need a way to wait for p to finish
+       } else {
+               printk("No user-space launcher file specified.\n");
+       }
+       #endif
+       smp_idle();
+       assert(0);
+}
+
 void manager_klueska()
 {
        static struct proc *envs[256];
@@ -225,26 +258,28 @@ void manager_klueska()
                proc_run_s(envs[0]);
                warn("DEPRECATED");
        }
-       schedule();
+       run_scheduler();
 
        panic("DON'T PANIC");
 }
 
 void manager_waterman()
 {
-       schedule();
-       monitor(0);
+       static bool first = true;
+       if (first)
+               mon_shell(0, 0, 0);
+       smp_idle();
        assert(0);
 }
 
 void manager_yuzhu()
 {
-       
-       static uint8_t RACY progress = 0;
+
+       static uint8_t progress = 0;
        static struct proc *p;
 
        // for testing taking cores, check in case 1 for usage
-       uint32_t corelist[MAX_NUM_CPUS];
+       uint32_t corelist[MAX_NUM_CORES];
        uint32_t num = 3;
 
        //create_server(init_num_cores, loop);
@@ -254,54 +289,3 @@ void manager_yuzhu()
        // quick_proc_run("hello", p);
 
 }
-
-#ifdef __sparc_v8__
-
-static char*
-itoa(int num, char* buf0, size_t base)
-{
-       if(base > 16)
-               return NULL;
-
-       char* buf = buf0;
-       int len = 0, i;
-
-       if(num < 0)
-       {
-               *buf++ = '-';
-               num = -num;
-       }
-
-       do {
-               buf[len++] = "0123456789abcdef"[num%base];
-               num /= base;
-       } while(num);
-
-       for(i = 0; i < len/2; i++)
-       {
-               char temp = buf[i];
-               buf[i] = buf[len-i-1];
-               buf[len-i-1] = temp;
-       }
-       buf[len] = 0;
-
-       return buf0;
-}
-
-void gsf_set_frame_cycles(int cycles)
-{
-       store_alternate(26*4,2,cycles);
-}
-
-void gsf_set_partition_credits(int partition, int credits)
-{
-       store_alternate((32+partition)*4,2,credits);
-}
-
-void gsf_set_core_partition(int core, int partition)
-{
-       store_alternate((64+core)*4,2,partition);
-}
-
-#endif
-