Adding SharC annotations. Type checker off
[akaros.git] / kern / src / manager.c
index bf50ee6..71570fc 100644 (file)
 /*
  * Copyright (c) 2009 The Regents of the University of California
+ * Barret Rhoden <brho@cs.berkeley.edu>
  * See LICENSE for details.
  */
 
-#ifdef __DEPUTY__
-#pragma nodeputy
+#ifdef __SHARC__
+#pragma nosharc
 #endif
 
-#include <inc/types.h>
-#include <inc/assert.h>
+#include <ros/common.h>
+#include <smp.h>
 
-#include <kern/manager.h>
-#include <kern/smp.h>
-#include <kern/env.h>
-#include <kern/apic.h>
-#include <kern/workqueue.h>
-
-/* Helper handlers for smp_call to dispatch jobs to other cores */
-static void work_env_run(void* data)
-{
-       env_run((env_t*)data);
-}
-
-static void run_env_handler(trapframe_t *tf, void* data)
-{
-       assert(data);
-       per_cpu_info[lapic_get_id()].delayed_work.func = work_env_run;
-       per_cpu_info[lapic_get_id()].delayed_work.data = data;
-}
+#include <assert.h>
+#include <manager.h>
+#include <process.h>
+#include <schedule.h>
+#include <workqueue.h>
+#include <syscall.h>
+#include <testing.h>
+#include <kfs.h>
+#include <stdio.h>
+#include <timing.h>
 
 /*
- * Currently, if you leave this function by way of env_run (process_workqueue
- * that env_runs), you will never come back to where you left off, and the
+ * Currently, if you leave this function by way of proc_run (process_workqueue
+ * that proc_runs), you will never come back to where you left off, and the
  * function will start from the top.  Hence the hack 'progress'.
  */
 void manager(void)
 {
-       static uint8_t progress = 0;
-       env_t* env_batch[64]; // Fairly arbitrary, just the max I plan to use.
+       static uint8_t RACY progress = 0;
+       struct proc *envs[256];
+       struct proc *p ;
 
        switch (progress++) {
                case 0:
-                       for (int i = 0; i < 8; i++)
-                               env_batch[i] = ENV_CREATE(user_null);
-                       for (int i = 0; i < 8; i++)
-                               smp_call_function_single(i, run_env_handler, env_batch[i], 0);
-                       process_workqueue(); // Will run this core (0)'s env
+                       // Here's how to do a multicored/parallel process:
+                       p = kfs_proc_create(kfs_lookup_path("roslib_mhello"));
+                       // being proper and all:
+                       proc_set_state(p, PROC_RUNNABLE_S);
+                       proc_set_state(p, PROC_RUNNING_S);
+                       proc_set_state(p, PROC_RUNNABLE_M);
+       
+                       // set vcoremap with dispatch plan.  usually done by schedule()
+                       spin_lock_irqsave(&p->proc_lock);
+                       p->num_vcores = 5; // assuming 5 are free, this is just an example
+                       spin_lock(&idle_lock); // need to grab the cores
+                       for (int i = 0; i < 5; i++) {
+                               // grab the last one on the list
+                               p->vcoremap[i] = idlecoremap[num_idlecores-1];
+                               num_idlecores--;
+                       }
+                       spin_unlock(&idle_lock);
+                       spin_unlock_irqsave(&p->proc_lock);
+                       proc_run(p);
+                       udelay(5000000);
+                       printk("Killing p\n");
+                       proc_destroy(p);
+                       printk("Killed p\n");
+                       udelay(1000000);
+                       panic("This is okay");
                        break;
                case 1:
-                       for (int i = 0; i < 4; i++)
-                               env_batch[i] = ENV_CREATE(user_null);
-                       for (int i = 0; i < 4; i++)
-                               smp_call_function_single(i, run_env_handler, env_batch[i], 0);
-                       //env_t* an_env = ENV_CREATE(user_null);
-                       //env_run(an_env);
-                       //smp_call_function_single(2, run_env_handler, an_env, 0);
+                       envs[0] = kfs_proc_create(kfs_lookup_path("roslib_hello"));
+                       proc_set_state(envs[0], PROC_RUNNABLE_S);
+                       proc_run(envs[0]);
+                       break;
+       #ifdef __i386__
+               case 2:
+                       panic("Do not panic");
+                       envs[0] = kfs_proc_create(kfs_lookup_path("parlib_channel_test_client"));
+                       envs[1] = kfs_proc_create(kfs_lookup_path("parlib_channel_test_server"));
+                       smp_call_function_single(1, run_env_handler, envs[0], 0);
+                       smp_call_function_single(2, run_env_handler, envs[1], 0);
+                       break;
+               case 3:
+       #else // sparc
+               case 2:
+                       panic("Do not panic");
+                       envs[0] = kfs_proc_create(kfs_lookup_path("roslib_proctests"));
+                       envs[1] = kfs_proc_create(kfs_lookup_path("roslib_proctests"));
+                       envs[2] = kfs_proc_create(kfs_lookup_path("roslib_proctests"));
+                       envs[3] = kfs_proc_create(kfs_lookup_path("roslib_fptest"));
+                       envs[4] = kfs_proc_create(kfs_lookup_path("roslib_fptest"));
+                       envs[4] = kfs_proc_create(kfs_lookup_path("roslib_fptest"));
+                       envs[5] = kfs_proc_create(kfs_lookup_path("roslib_hello"));
+                       envs[6] = kfs_proc_create(kfs_lookup_path("roslib_null"));
+                       proc_run(envs[0]);
+                       break;
+               case 3:
+                       #if 0
+                       // reminder of how to spawn remotely
+                       for (int i = 0; i < 8; i++) {
+                               envs[i] = kfs_proc_create(kfs_lookup_path("roslib_hello"));
+                               proc_set_state(envs[i], PROC_RUNNABLE_S);
+                               smp_call_function_single(i, run_env_handler, envs[i], 0);
+                       }
                        process_workqueue();
+                       #endif
+       #endif
+
+               #if 0
+               case 4:
+                       printk("Beginning Tests\n");
+                       test_run_measurements(progress-1);  // should never return
                        break;
+               case 5:
+                       envs[0] = kfs_proc_create(kfs_lookup_path("parlib_channel_test_client"));
+                       envs[1] = kfs_proc_create(kfs_lookup_path("parlib_channel_test_server"));
+                       smp_call_function_single(1, run_env_handler, envs[0], 0);
+                       smp_call_function_single(2, run_env_handler, envs[1], 0);
+               case 6:
+               #endif
+               case 4:
+                       /*
+                       test_smp_call_functions();
+                       test_checklists();
+                       test_barrier();
+                       test_print_info();
+                       test_lapic_status_bit();
+                       test_ipi_sending();
+                       test_pit();
+                       */
+               case 5:
+               case 6:
+               case 7:
+               case 8:
+               case 9:
+               case 10:
+               case 11:
+               case 12:
+               case 13:
+               case 14:
+                       //test_run_measurements(progress-1);
                default:
-                       printk("Waiting 5 sec for whatever reason\n");
-                       udelay(5000000);
-                       panic("Don't Panic");
+                       printk("Manager Progress: %d\n", progress);
+                       schedule();
        }
        panic("If you see me, then you probably screwed up");
 
@@ -71,5 +146,5 @@ void manager(void)
                cpu_relax();
        }
        */
+       return;
 }
-