Stacks and syscall support for 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 <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         static uint8_t RACY progress = 0;
33
34         struct proc *envs[256];
35         struct proc *p ;
36
37         // This is a bypass of the standard manager structure, for network use
38         // If enabled, this spawns parlib_matrix, and allows the execution
39         // of a remote binary to function correctly (schedule() call below)
40         //#ifdef __NETWORK__    
41         if (progress++ == 0) {
42                 envs[0] = kfs_proc_create(kfs_lookup_path("parlib_matrix"));
43                 proc_set_state(envs[0], PROC_RUNNABLE_S);
44                 proc_run(envs[0]);
45         }
46         schedule();
47         //#endif 
48
49         switch (progress++) {
50                 case 0:
51                         // Here's how to do a multicored/parallel process:
52                         p = kfs_proc_create(kfs_lookup_path("roslib_mhello"));
53                         // being proper and all:
54                         proc_set_state(p, PROC_RUNNABLE_S);
55                         proc_set_state(p, PROC_RUNNING_S);
56                         proc_set_state(p, PROC_RUNNABLE_M);
57         
58                         // set vcoremap with dispatch plan.  usually done by schedule()
59                         spin_lock_irqsave(&p->proc_lock);
60                         p->num_vcores = 5; // assuming 5 are free, this is just an example
61                         spin_lock(&idle_lock); // need to grab the cores
62                         for (int i = 0; i < 5; i++) {
63                                 // grab the last one on the list
64                                 p->vcoremap[i] = idlecoremap[num_idlecores-1];
65                                 num_idlecores--;
66                         }
67                         spin_unlock(&idle_lock);
68                         spin_unlock_irqsave(&p->proc_lock);
69                         proc_run(p);
70                         udelay(5000000);
71         //              printk("Killing p\n");
72         //              proc_destroy(p);
73         //              printk("Killed p\n");
74                         udelay(1000000);
75                         panic("This is okay");
76                         break;
77                 case 1:
78                         envs[0] = kfs_proc_create(kfs_lookup_path("roslib_hello"));
79                         proc_set_state(envs[0], PROC_RUNNABLE_S);
80                         proc_run(envs[0]);
81                         break;
82         #ifdef __i386__
83                 case 2:
84                         panic("Do not panic");
85                         envs[0] = kfs_proc_create(kfs_lookup_path("parlib_channel_test_client"));
86                         envs[1] = kfs_proc_create(kfs_lookup_path("parlib_channel_test_server"));
87                         smp_call_function_single(1, run_env_handler, envs[0], 0);
88                         smp_call_function_single(2, run_env_handler, envs[1], 0);
89                         break;
90                 case 3:
91         #else // sparc
92                 case 2:
93                         panic("Do not panic");
94                         envs[0] = kfs_proc_create(kfs_lookup_path("roslib_proctests"));
95                         envs[1] = kfs_proc_create(kfs_lookup_path("roslib_proctests"));
96                         envs[2] = kfs_proc_create(kfs_lookup_path("roslib_proctests"));
97                         envs[3] = kfs_proc_create(kfs_lookup_path("roslib_fptest"));
98                         envs[4] = kfs_proc_create(kfs_lookup_path("roslib_fptest"));
99                         envs[4] = kfs_proc_create(kfs_lookup_path("roslib_fptest"));
100                         envs[5] = kfs_proc_create(kfs_lookup_path("roslib_hello"));
101                         envs[6] = kfs_proc_create(kfs_lookup_path("roslib_null"));
102                         proc_run(envs[0]);
103                         break;
104                 case 3:
105                         #if 0
106                         // reminder of how to spawn remotely
107                         for (int i = 0; i < 8; i++) {
108                                 envs[i] = kfs_proc_create(kfs_lookup_path("roslib_hello"));
109                                 proc_set_state(envs[i], PROC_RUNNABLE_S);
110                                 smp_call_function_single(i, run_env_handler, envs[i], 0);
111                         }
112                         process_workqueue();
113                         #endif
114         #endif
115
116                 #if 0
117                 case 4:
118                         printk("Beginning Tests\n");
119                         test_run_measurements(progress-1);  // should never return
120                         break;
121                 case 5:
122                         envs[0] = kfs_proc_create(kfs_lookup_path("parlib_channel_test_client"));
123                         envs[1] = kfs_proc_create(kfs_lookup_path("parlib_channel_test_server"));
124                         smp_call_function_single(1, run_env_handler, envs[0], 0);
125                         smp_call_function_single(2, run_env_handler, envs[1], 0);
126                 case 6:
127                 #endif
128                 case 4:
129                         /*
130                         test_smp_call_functions();
131                         test_checklists();
132                         test_barrier();
133                         test_print_info();
134                         test_lapic_status_bit();
135                         test_ipi_sending();
136                         test_pit();
137                         */
138                 case 5:
139                 case 6:
140                 case 7:
141                 case 8:
142                 case 9:
143                 case 10:
144                 case 11:
145                 case 12:
146                 case 13:
147                 case 14:
148                         //test_run_measurements(progress-1);
149                 default:
150                         printk("Manager Progress: %d\n", progress);
151                         schedule();
152         }
153         panic("If you see me, then you probably screwed up");
154
155         /*
156         printk("Servicing syscalls from Core 0:\n\n");
157         while (1) {
158                 process_generic_syscalls(&envs[0], 1);
159                 cpu_relax();
160         }
161         */
162         return;
163 }