Multi-cored process changes
[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 #include <resource.h>
25
26 /*
27  * Currently, if you leave this function by way of proc_run (process_workqueue
28  * that proc_runs), you will never come back to where you left off, and the
29  * function will start from the top.  Hence the hack 'progress'.
30  */
31 void manager(void)
32 {
33         static uint8_t RACY progress = 0;
34
35         struct proc *envs[256];
36         static struct proc *p ;
37
38         // for testing taking cores, check in case 1 for usage
39         uint32_t corelist[MAX_NUM_CPUS];
40         uint32_t num = 3;
41
42         /*
43         // This is a bypass of the standard manager structure, for network use
44         // If enabled, this spawns parlib_matrix, and allows the execution
45         // of a remote binary to function correctly (schedule() call below)
46         if (progress++ == 0) {
47                 envs[0] = kfs_proc_create(kfs_lookup_path("parlib_matrix"));
48                 proc_set_state(envs[0], PROC_RUNNABLE_S);
49                 proc_run(envs[0]);
50         }
51         schedule();
52         */
53
54         switch (progress++) {
55                 case 0:
56                         //p = kfs_proc_create(kfs_lookup_path("roslib_mhello"));
57                         p = kfs_proc_create(kfs_lookup_path("roslib_mproctests"));
58                         //p = kfs_proc_create(kfs_lookup_path("roslib_spawn"));
59                         // being proper and all:
60                         spin_lock_irqsave(&p->proc_lock);
61                         proc_set_state(p, PROC_RUNNABLE_S);
62                         // normal single-cored way
63                         spin_unlock_irqsave(&p->proc_lock);
64                         proc_run(p);
65                         #if 0
66                         // this is how you can transition to a parallel process manually
67                         // make sure you don't proc run first
68                         proc_set_state(p, PROC_RUNNING_S);
69                         proc_set_state(p, PROC_RUNNABLE_M);
70                         p->resources[RES_CORES].amt_wanted = 5;
71                         spin_unlock_irqsave(&p->proc_lock);
72                         core_request(p);
73                         panic("This is okay");
74                         #endif
75                         break;
76                 case 1:
77                         #if 0
78                         udelay(10000000);
79                         // this is a ghetto way to test restarting an _M
80                                 printk("\nattempting to ghetto preempt...\n");
81                                 spin_lock_irqsave(&p->proc_lock);
82                                 proc_take_allcores(p, __death);
83                                 proc_set_state(p, PROC_RUNNABLE_M);
84                                 spin_unlock_irqsave(&p->proc_lock);
85                                 udelay(5000000);
86                                 printk("\nattempting to restart...\n");
87                                 core_request(p); // proc still wants the cores
88                         panic("This is okay");
89                         // this tests taking some cores, and later killing an _M
90                                 printk("taking 3 cores from p\n");
91                                 for (int i = 0; i < num; i++)
92                                         corelist[i] = 7-i; // 7, 6, and 5
93                                 spin_lock_irqsave(&p->proc_lock);
94                                 proc_take_cores(p, corelist, &num, __death);
95                                 spin_unlock_irqsave(&p->proc_lock);
96                                 udelay(5000000);
97                                 printk("Killing p\n");
98                                 proc_destroy(p);
99                                 printk("Killed p\n");
100                         panic("This is okay");
101
102                         envs[0] = kfs_proc_create(kfs_lookup_path("roslib_hello"));
103                         proc_set_state(envs[0], PROC_RUNNABLE_S);
104                         proc_run(envs[0]);
105                         break;
106                         #endif
107         #ifdef __i386__
108                 case 2:
109                         #if 0
110                         panic("Do not panic");
111                         envs[0] = kfs_proc_create(kfs_lookup_path("parlib_channel_test_client"));
112                         envs[1] = kfs_proc_create(kfs_lookup_path("parlib_channel_test_server"));
113                         smp_call_function_single(1, run_env_handler, envs[0], 0);
114                         smp_call_function_single(2, run_env_handler, envs[1], 0);
115                         break;
116                         #endif
117                 case 3:
118         #else // sparc
119                 case 2:
120                         panic("Do not panic");
121                         envs[0] = kfs_proc_create(kfs_lookup_path("roslib_proctests"));
122                         envs[1] = kfs_proc_create(kfs_lookup_path("roslib_proctests"));
123                         envs[2] = kfs_proc_create(kfs_lookup_path("roslib_proctests"));
124                         envs[3] = kfs_proc_create(kfs_lookup_path("roslib_fptest"));
125                         envs[4] = kfs_proc_create(kfs_lookup_path("roslib_fptest"));
126                         envs[4] = kfs_proc_create(kfs_lookup_path("roslib_fptest"));
127                         envs[5] = kfs_proc_create(kfs_lookup_path("roslib_hello"));
128                         envs[6] = kfs_proc_create(kfs_lookup_path("roslib_null"));
129                         proc_run(envs[0]);
130                         break;
131                 case 3:
132                         #if 0
133                         // reminder of how to spawn remotely
134                         for (int i = 0; i < 8; i++) {
135                                 envs[i] = kfs_proc_create(kfs_lookup_path("roslib_hello"));
136                                 proc_set_state(envs[i], PROC_RUNNABLE_S);
137                                 smp_call_function_single(i, run_env_handler, envs[i], 0);
138                         }
139                         process_workqueue();
140                         #endif
141         #endif
142
143                 #if 0
144                 case 4:
145                         printk("Beginning Tests\n");
146                         test_run_measurements(progress-1);  // should never return
147                         break;
148                 case 5:
149                         envs[0] = kfs_proc_create(kfs_lookup_path("parlib_channel_test_client"));
150                         envs[1] = kfs_proc_create(kfs_lookup_path("parlib_channel_test_server"));
151                         smp_call_function_single(1, run_env_handler, envs[0], 0);
152                         smp_call_function_single(2, run_env_handler, envs[1], 0);
153                 case 6:
154                 #endif
155                 case 4:
156                         /*
157                         test_smp_call_functions();
158                         test_checklists();
159                         test_barrier();
160                         test_print_info();
161                         test_lapic_status_bit();
162                         test_ipi_sending();
163                         test_pit();
164                         */
165                 case 5:
166                 case 6:
167                 case 7:
168                 case 8:
169                 case 9:
170                 case 10:
171                 case 11:
172                 case 12:
173                 case 13:
174                 case 14:
175                         //test_run_measurements(progress-1);
176                 default:
177                         printk("Manager Progress: %d\n", progress);
178                         // delay if you want to test rescheduling an MCP that yielded
179                         //udelay(15000000);
180                         schedule();
181         }
182         panic("If you see me, then you probably screwed up");
183
184         /*
185         printk("Servicing syscalls from Core 0:\n\n");
186         while (1) {
187                 process_generic_syscalls(&envs[0], 1);
188                 cpu_relax();
189         }
190         */
191         return;
192 }