vmm: Refactor vmm_ctl to use error()
[akaros.git] / kern / src / manager.c
index 92b600b..9004b21 100644 (file)
@@ -5,10 +5,6 @@
  */
 
 
-#ifdef __SHARC__
-#pragma nosharc
-#endif
-
 #include <ros/common.h>
 #include <smp.h>
 #include <arch/init.h>
 #include <process.h>
 #include <schedule.h>
 #include <syscall.h>
-#include <testing.h>
+#include <ktest.h>
 #include <kfs.h>
 #include <stdio.h>
-#include <timing.h>
-#include <resource.h>
+#include <time.h>
 #include <monitor.h>
-#include <colored_caches.h>
 #include <string.h>
 #include <pmap.h>
-#include <ros/timer.h>
+#include <arch/console.h>
+#include <time.h>
 #include <ros/arch/membar.h>
 
 /*
  */
 void manager(void)
 {
-       #ifndef DEVELOPER_NAME
-               #define DEVELOPER_NAME brho
-       #endif
-
        // LoL
        #define PASTE(s1,s2) s1 ## s2
        #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
+
        void MANAGER_FUNC(DEVELOPER_NAME)(void);
        MANAGER_FUNC(DEVELOPER_NAME)();
 }
 
-/* Helper macro for quickly running something out of KFS.  Pass it a string and
- * a proc pointer. */
-#define quick_proc_run(x, p)                                                     \
-       (p) = kfs_proc_create(kfs_lookup_path((x)));                                 \
+char *p_argv[] = {0, 0, 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), O_READ, 0);                                          \
+       assert((f));                                                                 \
+       p_argv[0] = file_name((f));                                                  \
+       (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);                                                \
-       proc_run((p));                                                               \
-       proc_decref((p), 1);
-
-#define quick_proc_create(x, p)                                                  \
-       (p) = kfs_proc_create(kfs_lookup_path((x)));                                 \
+       proc_run_s((p));                                                             \
+       proc_decref((p));
+
+#define quick_proc_create(x, p, f)                                               \
+       (f) = do_file_open((x), O_READ, 0);                                          \
+       assert((f));                                                                 \
+       p_argv[0] = file_name((f));                                                  \
+       (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)                                            \
-       (p) = kfs_proc_create(kfs_lookup_path((x)));                                 \
+#define quick_proc_color_run(x, p, c, f)                                         \
+       (f) = do_file_open((x), O_READ, 0);                                          \
+       assert((f));                                                                 \
+       p_argv[0] = file_name((f));                                                  \
+       (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);                                                \
        p->cache_colors_map = cache_colors_map_alloc();                              \
        for (int i = 0; i < (c); i++)                                                \
                cache_color_alloc(llc_cache, p->cache_colors_map);                       \
-       proc_run((p));                                                               \
-       proc_decref((p), 1);
-
-#define quick_proc_color_create(x, p, c)                                         \
-       (p) = kfs_proc_create(kfs_lookup_path((x)));                                 \
+       proc_run_s((p));                                                             \
+       proc_decref((p));
+
+#define quick_proc_color_create(x, p, c, f)                                      \
+       (f) = do_file_open((x), O_READ, 0);                                          \
+       assert((f));                                                                 \
+       p_argv[0] = file_name((f));                                                  \
+       (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);                                                \
@@ -91,20 +109,44 @@ void manager(void)
 
 void manager_brho(void)
 {
-       static uint8_t RACY progress = 0;
-       static struct proc *p;
-
+       static bool first = TRUE;
+       struct per_cpu_info *pcpui = &per_cpu_info[core_id()];
+
+       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. */
+       smp_idle();
+       /* whatever we do in the manager, keep in mind that we need to not do
+        * anything too soon (like make processes), since we'll drop in here during
+        * boot if the boot sequence required any I/O (like EXT2), and we need to
+        * PRKM() */
+       assert(0);
+
+#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;
 
+       static uint8_t RACY progress = 0;       /* this will wrap around. */
        switch (progress++) {
                case 0:
-                       monitor(0);
+                       printk("Top of the manager to ya!\n");
                        /* 124 is half of the available boxboro colors (with the kernel
                         * getting 8) */
-                       //quick_proc_color_run("msr_dumb_while", p, 124);
-                       //quick_proc_run("mhello", p);
+                       //quick_proc_color_run("msr_dumb_while", p, 124, temp_f);
+                       quick_proc_run("/bin/hello", p, temp_f);
                        #if 0
                        // this is how you can transition to a parallel process manually
                        // make sure you don't proc run first
@@ -145,6 +187,7 @@ void manager_brho(void)
                        envs[0] = kfs_proc_create(kfs_lookup_path("roslib_hello"));
                        __proc_set_state(envs[0], PROC_RUNNABLE_S);
                        proc_run(envs[0]);
+                       warn("DEPRECATED");
                        break;
                        #endif
                case 2:
@@ -161,7 +204,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);
@@ -174,60 +217,39 @@ void manager_brho(void)
        }
        */
        return;
+#endif
 }
 
-void manager_klueska()
-{
-       static struct proc *envs[256];
-       static volatile uint8_t progress = 0;
-
-       if (progress == 0) {
-               progress++;
-               panic("what do you want to do?");
-               //envs[0] = kfs_proc_create(kfs_lookup_path("fillmeup"));
-               __proc_set_state(envs[0], PROC_RUNNABLE_S);
-               proc_run(envs[0]);
-       }
-       schedule();
-
-       panic("DON'T PANIC");
-}
-
-struct elf_info
-{
-       long entry;
-       long phdr;
-       int phnum;
-       int dynamic;
-       char interp[256];
-};
-
-void manager_waterman()
+void manager_jenkins()
 {
-       static int init = 0;
-       if(!init)
-       {
-               warn("Old file creation might not work");
-               init = 1;
-               struct proc *p;
-               proc_alloc(&p, 0);
-
-               char* argv[] = {"/bin/sh","-l",0};
-               char* envp[] = {"LD_LIBRARY_PATH=/lib",0};
-               procinfo_pack_args(p->procinfo,argv,envp);
-
-               struct file* f = file_open("/bin/busybox",0,0);
-               assert(f != NULL);
-               assert(load_elf(p,f) == 0);
-               file_decref(f);
+       #ifdef CONFIG_KERNEL_TESTING
+               printk("<-- BEGIN_KERNEL_TESTS -->\n");
+               run_registered_ktest_suites();
+               printk("<-- END_KERNEL_TESTS -->\n");
+       #endif
 
-               __proc_set_state(p, PROC_RUNNABLE_S);
-               proc_run(p);
+       // 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");
        }
-       schedule();
+       #endif
+       smp_idle();
+       assert(0);
 }
 
-void manager_pearce()
+void manager_klueska()
 {
        static struct proc *envs[256];
        static volatile uint8_t progress = 0;
@@ -235,64 +257,39 @@ void manager_pearce()
        if (progress == 0) {
                progress++;
                panic("what do you want to do?");
-               //envs[0] = kfs_proc_create(kfs_lookup_path("parlib_httpserver_integrated"));
-               //envs[0] = kfs_proc_create(kfs_lookup_path("parlib_lock_test"));
+               //envs[0] = kfs_proc_create(kfs_lookup_path("fillmeup"));
                __proc_set_state(envs[0], PROC_RUNNABLE_S);
-               proc_run(envs[0]);
+               proc_run_s(envs[0]);
+               warn("DEPRECATED");
        }
-       schedule();
+       run_scheduler();
 
        panic("DON'T PANIC");
-
 }
 
-#ifdef __sparc_v8__
-
-static char*
-itoa(int num, char* buf0, size_t base)
+void manager_waterman()
 {
-       if(base > 16)
-               return NULL;
-
-       char* buf = buf0;
-       int len = 0, i;
+       static bool first = true;
+       if (first)
+               mon_shell(0, 0, 0);
+       smp_idle();
+       assert(0);
+}
 
-       if(num < 0)
-       {
-               *buf++ = '-';
-               num = -num;
-       }
+void manager_yuzhu()
+{
 
-       do {
-               buf[len++] = "0123456789abcdef"[num%base];
-               num /= base;
-       } while(num);
+       static uint8_t progress = 0;
+       static struct proc *p;
 
-       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;
+       // for testing taking cores, check in case 1 for usage
+       uint32_t corelist[MAX_NUM_CORES];
+       uint32_t num = 3;
 
-       return buf0;
-}
+       //create_server(init_num_cores, loop);
 
-void gsf_set_frame_cycles(int cycles)
-{
-       store_alternate(26*4,2,cycles);
-}
+       monitor(0);
 
-void gsf_set_partition_credits(int partition, int credits)
-{
-       store_alternate((32+partition)*4,2,credits);
-}
+       // quick_proc_run("hello", p);
 
-void gsf_set_core_partition(int core, int partition)
-{
-       store_alternate((64+core)*4,2,partition);
 }
-
-#endif
-