Bare support for dispatching parallel processes
[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 __SHARC__
8 #pragma nosharc
9 #endif
10
11 #include <arch/types.h>
12 #include <smp.h>
13
14 #include <assert.h>
15 #include <manager.h>
16 #include <process.h>
17 #include <schedule.h>
18 #include <workqueue.h>
19 #include <syscall.h>
20 #include <testing.h>
21 #include <kfs.h>
22 #include <stdio.h>
23 #include <timing.h>
24
25 /*
26  * Currently, if you leave this function by way of proc_run (process_workqueue
27  * that proc_runs), you will never come back to where you left off, and the
28  * function will start from the top.  Hence the hack 'progress'.
29  */
30 void manager(void)
31 {
32         static uint8_t progress = 0;
33         struct proc *envs[256];
34
35 envs[0] = kfs_proc_create(kfs_lookup_path("roslib_mhello"));
36 // being proper and all:
37 proc_set_state(envs[0], PROC_RUNNABLE_S);
38 proc_set_state(envs[0], PROC_RUNNING_S);
39 proc_set_state(envs[0], PROC_RUNNABLE_M);
40 proc_set_state(envs[0], PROC_RUNNING_M);
41 for (int i = 1; i < 8; i++) {
42         per_cpu_info[i].p_to_run = envs[0];
43         //per_cpu_info[i].tf_to_pop = &envs[0]->env_tf; // starts the main core
44 }
45 // needed to make sure the writes beat the IPI.  could have done it with other
46 // mem accesses, like grabbing a lock, and the write would have made it (no wmb() on
47 // x86)
48 asm volatile("sfence");
49 // actually send the IPI to do this
50 for (int i = 1; i < 8; i++)
51         send_ipi(i, 0, I_STARTCORE);
52
53 udelay(5000000);
54 panic("This is okay");
55
56         switch (progress++) {
57                 case 0:
58                         envs[0] = kfs_proc_create(kfs_lookup_path("roslib_hello"));
59                         proc_set_state(envs[0], PROC_RUNNABLE_S);
60                         proc_run(envs[0]);
61                         break;
62         #ifdef __i386__
63                 case 1:
64                         panic("Do not panic");
65                         envs[0] = kfs_proc_create(kfs_lookup_path("parlib_channel_test_client"));
66                         envs[1] = kfs_proc_create(kfs_lookup_path("parlib_channel_test_server"));
67                         smp_call_function_single(1, run_env_handler, envs[0], 0);
68                         smp_call_function_single(2, run_env_handler, envs[1], 0);
69                         break;
70                 case 2:
71                 case 3:
72         #else // sparc
73                 case 1:
74                         panic("Do not panic");
75                         envs[0] = kfs_proc_create(kfs_lookup_path("roslib_proctests"));
76                         envs[1] = kfs_proc_create(kfs_lookup_path("roslib_proctests"));
77                         envs[2] = kfs_proc_create(kfs_lookup_path("roslib_proctests"));
78                         envs[3] = kfs_proc_create(kfs_lookup_path("roslib_fptest"));
79                         envs[4] = kfs_proc_create(kfs_lookup_path("roslib_fptest"));
80                         envs[4] = kfs_proc_create(kfs_lookup_path("roslib_fptest"));
81                         envs[5] = kfs_proc_create(kfs_lookup_path("roslib_hello"));
82                         envs[6] = kfs_proc_create(kfs_lookup_path("roslib_null"));
83                         proc_run(envs[0]);
84                         break;
85                 case 2:
86                         #if 0
87                         // reminder of how to spawn remotely
88                         for (int i = 0; i < 8; i++) {
89                                 envs[i] = kfs_proc_create(kfs_lookup_path("roslib_hello"));
90                                 proc_set_state(envs[i], PROC_RUNNABLE_S);
91                                 smp_call_function_single(i, run_env_handler, envs[i], 0);
92                         }
93                         process_workqueue();
94                         #endif
95                 case 3:
96         #endif
97
98                 #if 0
99                 case 4:
100                         printk("Beginning Tests\n");
101                         test_run_measurements(progress-1);  // should never return
102                         break;
103                 case 5:
104                         envs[0] = kfs_proc_create(kfs_lookup_path("parlib_channel_test_client"));
105                         envs[1] = kfs_proc_create(kfs_lookup_path("parlib_channel_test_server"));
106                         smp_call_function_single(1, run_env_handler, envs[0], 0);
107                         smp_call_function_single(2, run_env_handler, envs[1], 0);
108                 case 6:
109                 #endif
110                 case 4:
111                         /*
112                         test_smp_call_functions();
113                         test_checklists();
114                         test_barrier();
115                         test_print_info();
116                         test_lapic_status_bit();
117                         test_ipi_sending();
118                         test_pit();
119                         */
120                 case 5:
121                 case 6:
122                 case 7:
123                 case 8:
124                 case 9:
125                 case 10:
126                 case 11:
127                 case 12:
128                 case 13:
129                 case 14:
130                         //test_run_measurements(progress-1);
131                 default:
132                         printk("Manager Progress: %d\n", progress);
133                         schedule();
134         }
135         panic("If you see me, then you probably screwed up");
136
137         /*
138         printk("Servicing syscalls from Core 0:\n\n");
139         while (1) {
140                 process_generic_syscalls(&envs[0], 1);
141                 cpu_relax();
142         }
143         */
144         return;
145 }
146