Workqueue interface and coreid()
[akaros.git] / kern / src / manager.c
1 /*
2  * Copyright (c) 2009 The Regents of the University of California
3  * Barret Rhoden <brho@cs.berkeley.edu>
4  * See LICENSE for details.
5  */
6
7 #ifdef __DEPUTY__
8 #pragma nodeputy
9 #endif
10
11 #include <arch/types.h>
12 #include <arch/apic.h>
13 #include <arch/smp.h>
14
15 #include <assert.h>
16 #include <manager.h>
17 #include <process.h>
18 #include <workqueue.h>
19 #include <syscall.h>
20 #include <testing.h>
21 #include <kfs.h>
22
23 /*
24  * Currently, if you leave this function by way of env_run (process_workqueue
25  * that env_runs), you will never come back to where you left off, and the
26  * function will start from the top.  Hence the hack 'progress'.
27  */
28 void manager(void)
29 {
30         static uint8_t progress = 0;
31         env_t *envs[256];
32
33         switch (progress++) {
34                 case 0:
35                         envs[0] = kfs_proc_create(kfs_lookup_path("roslib_hello"));
36                         proc_set_state(envs[0], PROC_RUNNABLE_S);
37                         env_run(envs[0]);
38                         break;
39                 case 1:
40                         panic("Do not panic");
41                         envs[0] = ENV_CREATE(roslib_proctests);
42                         envs[1] = ENV_CREATE(roslib_proctests);
43                         envs[2] = ENV_CREATE(roslib_proctests);
44                         envs[3] = ENV_CREATE(roslib_proctests);
45                         env_run(envs[0]);
46                         break;
47                         #if 0
48                         #endif
49                 case 2:
50                         #if 0
51                         // reminder of how to spawn remotely
52                         for (int i = 0; i < 8; i++) {
53                                 envs[i] = kfs_proc_create(kfs_lookup_path("roslib_hello"));
54                                 proc_set_state(envs[i], PROC_RUNNABLE_S);
55                                 smp_call_function_single(i, run_env_handler, envs[i], 0);
56                         }
57                         process_workqueue();
58                         #endif
59                 case 3:
60                 #if 0
61                 case 0:
62                         printk("Beginning Tests\n");
63                         test_run_measurements(progress-1);  // should never return
64                         break;
65                 case 1:
66                 case 2:
67                 case 3:
68                 case 4:
69                 case 5:
70                 case 6:
71                 case 7:
72                 case 8:
73                 case 9:
74                 case 10:
75                 case 11:
76                 case 12:
77                 case 13:
78                 case 14:
79                         test_run_measurements(progress-1);
80                         break;
81                 #endif
82                 default:
83                         printk("Manager Progress: %d\n", progress);
84                         schedule();
85         }
86         panic("If you see me, then you probably screwed up");
87
88         /*
89         printk("Servicing syscalls from Core 0:\n\n");
90         while (1) {
91                 process_generic_syscalls(&envs[0], 1);
92                 cpu_relax();
93         }
94         */
95         return;
96 }
97