Fixed env_segment_free bug
[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 <ros/common.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         #ifndef DEVELOPER_NAME
33                 #define DEVELOPER_NAME brho
34         #endif
35
36         // LoL
37         #define PASTE(s1,s2) s1 ## s2
38         #define MANAGER_FUNC(dev) PASTE(manager_,dev)
39
40         void MANAGER_FUNC(DEVELOPER_NAME)(void);
41         MANAGER_FUNC(DEVELOPER_NAME)();
42 }
43
44 void manager_brho(void)
45 {
46         static uint8_t RACY progress = 0;
47
48         struct proc *envs[256];
49         static struct proc *p ;
50
51         uint32_t corelist[MAX_NUM_CPUS];
52         uint32_t num = 3;
53
54         switch (progress++) {
55                 case 0:
56                         //p = kfs_proc_create(kfs_lookup_path("roslib_proctests"));
57                         p = kfs_proc_create(kfs_lookup_path("roslib_mhello"));
58                         // being proper and all:
59                         spin_lock_irqsave(&p->proc_lock);
60                         proc_set_state(p, PROC_RUNNABLE_S);
61                         // normal single-cored way
62                         spin_unlock_irqsave(&p->proc_lock);
63                         proc_run(p);
64                         #if 0
65                         // this is how you can transition to a parallel process manually
66                         // make sure you don't proc run first
67                         proc_set_state(p, PROC_RUNNING_S);
68                         proc_set_state(p, PROC_RUNNABLE_M);
69                         p->resources[RES_CORES].amt_wanted = 5;
70                         spin_unlock_irqsave(&p->proc_lock);
71                         core_request(p);
72                         panic("This is okay");
73                         #endif
74                         break;
75                 case 1:
76                         #if 0
77                         panic("This is okay");
78                         udelay(10000000);
79                         printk("taking 3 cores from p\n");
80                         for (int i = 0; i < num; i++)
81                                 corelist[i] = 7-i; // 7, 6, and 5
82                         spin_lock_irqsave(&p->proc_lock);
83                         proc_take_cores(p, corelist, &num, __death);
84                         spin_unlock_irqsave(&p->proc_lock);
85                         udelay(5000000);
86                         printk("Killing p\n");
87                         proc_destroy(p);
88                         printk("Killed p\n");
89                         udelay(1000000);
90                         panic("This is okay");
91
92                         envs[0] = kfs_proc_create(kfs_lookup_path("roslib_hello"));
93                         proc_set_state(envs[0], PROC_RUNNABLE_S);
94                         proc_run(envs[0]);
95                         break;
96                         #endif
97         #ifdef __i386__
98                 case 2:
99                         #if 0
100                         panic("Do not panic");
101                         envs[0] = kfs_proc_create(kfs_lookup_path("parlib_channel_test_client"));
102                         envs[1] = kfs_proc_create(kfs_lookup_path("parlib_channel_test_server"));
103                         smp_call_function_single(1, run_env_handler, envs[0], 0);
104                         smp_call_function_single(2, run_env_handler, envs[1], 0);
105                         break;
106                         #endif
107                 case 3:
108         #else // sparc
109                 case 2:
110                         panic("Do not panic");
111                         envs[0] = kfs_proc_create(kfs_lookup_path("roslib_proctests"));
112                         envs[1] = kfs_proc_create(kfs_lookup_path("roslib_proctests"));
113                         envs[2] = kfs_proc_create(kfs_lookup_path("roslib_proctests"));
114                         envs[3] = kfs_proc_create(kfs_lookup_path("roslib_fptest"));
115                         envs[4] = kfs_proc_create(kfs_lookup_path("roslib_fptest"));
116                         envs[4] = kfs_proc_create(kfs_lookup_path("roslib_fptest"));
117                         envs[5] = kfs_proc_create(kfs_lookup_path("roslib_hello"));
118                         envs[6] = kfs_proc_create(kfs_lookup_path("roslib_null"));
119                         proc_run(envs[0]);
120                         break;
121                 case 3:
122                         #if 0
123                         // reminder of how to spawn remotely
124                         for (int i = 0; i < 8; i++) {
125                                 envs[i] = kfs_proc_create(kfs_lookup_path("roslib_hello"));
126                                 proc_set_state(envs[i], PROC_RUNNABLE_S);
127                                 smp_call_function_single(i, run_env_handler, envs[i], 0);
128                         }
129                         process_workqueue();
130                         #endif
131         #endif
132
133                 #if 0
134                 case 4:
135                         printk("Beginning Tests\n");
136                         test_run_measurements(progress-1);  // should never return
137                         break;
138                 case 5:
139                         envs[0] = kfs_proc_create(kfs_lookup_path("parlib_channel_test_client"));
140                         envs[1] = kfs_proc_create(kfs_lookup_path("parlib_channel_test_server"));
141                         smp_call_function_single(1, run_env_handler, envs[0], 0);
142                         smp_call_function_single(2, run_env_handler, envs[1], 0);
143                 case 6:
144                 #endif
145                 case 4:
146                         /*
147                         test_smp_call_functions();
148                         test_checklists();
149                         test_barrier();
150                         test_print_info();
151                         test_lapic_status_bit();
152                         test_ipi_sending();
153                         test_pit();
154                         */
155                 case 5:
156                 case 6:
157                 case 7:
158                 case 8:
159                 case 9:
160                 case 10:
161                 case 11:
162                 case 12:
163                 case 13:
164                 case 14:
165                         //test_run_measurements(progress-1);
166                 default:
167                         printk("Manager Progress: %d\n", progress);
168                         // delay if you want to test rescheduling an MCP that yielded
169                         //udelay(15000000);
170                         schedule();
171         }
172         panic("If you see me, then you probably screwed up");
173
174         /*
175         printk("Servicing syscalls from Core 0:\n\n");
176         while (1) {
177                 process_generic_syscalls(&envs[0], 1);
178                 cpu_relax();
179         }
180         */
181         return;
182 }
183
184 void manager_klueska()
185 {
186         struct proc *envs[256];
187         static uint8_t progress = 0;
188
189         if (progress++ == 0) {
190                 envs[0] = kfs_proc_create(kfs_lookup_path("parlib_matrix"));
191                 proc_set_state(envs[0], PROC_RUNNABLE_S);
192                 proc_run(envs[0]);
193         }
194         schedule();
195
196         panic("DON'T PANIC");
197 }
198
199 void manager_waterman()
200 {
201         struct proc *envs[256];
202         static uint8_t progress = 0;
203
204         switch(progress++)
205         {
206                 case 0:
207                         printk("got here\n");
208                         envs[0] = kfs_proc_create(kfs_lookup_path("parlib_draw_nanwan_standalone"));
209                         proc_set_state(envs[0], PROC_RUNNABLE_S);
210                         proc_run(envs[0]);
211                         break;
212
213                 case 1:
214                         envs[1] = kfs_proc_create(kfs_lookup_path("parlib_manycore_test"));
215                         proc_set_state(envs[1], PROC_RUNNABLE_S);
216                         proc_run(envs[1]);
217                         break;
218
219                 case 2:
220                         envs[2] = kfs_proc_create(kfs_lookup_path("parlib_draw_nanwan_standalone"));
221                         proc_set_state(envs[2], PROC_RUNNABLE_S);
222                         proc_run(envs[2]);
223                         break;
224
225                 case 3:
226                         envs[3] = kfs_proc_create(kfs_lookup_path("parlib_draw_nanwan_standalone"));
227                         //envs[3] = kfs_proc_create(kfs_lookup_path("parlib_manycore_test"));
228                         proc_set_state(envs[3], PROC_RUNNABLE_S);
229                         proc_run(envs[3]);
230                         break;
231         }
232         schedule();
233
234         panic("DON'T PANIC");
235 }