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