Compiles with GCC
[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 #ifdef __IVY__
12 #pragma nodeputy
13 #endif
14
15 #include <ros/common.h>
16 #include <smp.h>
17
18 #include <assert.h>
19 #include <manager.h>
20 #include <process.h>
21 #include <schedule.h>
22 #include <workqueue.h>
23 #include <syscall.h>
24 #include <testing.h>
25 #include <kfs.h>
26 #include <stdio.h>
27 #include <timing.h>
28
29 /*
30  * Currently, if you leave this function by way of proc_run (process_workqueue
31  * that proc_runs), you will never come back to where you left off, and the
32  * function will start from the top.  Hence the hack 'progress'.
33  */
34 void manager(void)
35 {
36         static uint8_t progress = 0;
37         struct proc *envs[256];
38         struct proc *p ;
39
40         switch (progress++) {
41                 case 0:
42                         // Here's how to do a multicored/parallel process:
43                         p = kfs_proc_create(kfs_lookup_path("roslib_mhello"));
44                         // being proper and all:
45                         proc_set_state(p, PROC_RUNNABLE_S);
46                         proc_set_state(p, PROC_RUNNING_S);
47                         proc_set_state(p, PROC_RUNNABLE_M);
48         
49                         // set vcoremap with dispatch plan.  usually done by schedule()
50                         spin_lock_irqsave(&p->proc_lock);
51                         p->num_vcores = 5; // assuming 5 are free, this is just an example
52                         spin_lock(&idle_lock); // need to grab the cores
53                         for (int i = 0; i < 5; i++) {
54                                 // grab the last one on the list
55                                 p->vcoremap[i] = idlecoremap[num_idlecores-1];
56                                 num_idlecores--;
57                         }
58                         spin_unlock(&idle_lock);
59                         spin_unlock_irqsave(&p->proc_lock);
60                         proc_run(p);
61                         udelay(5000000);
62                         printk("Killing p\n");
63                         proc_destroy(p);
64                         printk("Killed p\n");
65                         udelay(1000000);
66                         panic("This is okay");
67                         break;
68                 case 1:
69                         envs[0] = kfs_proc_create(kfs_lookup_path("roslib_hello"));
70                         proc_set_state(envs[0], PROC_RUNNABLE_S);
71                         proc_run(envs[0]);
72                         break;
73         #ifdef __i386__
74                 case 2:
75                         panic("Do not panic");
76                         envs[0] = kfs_proc_create(kfs_lookup_path("parlib_channel_test_client"));
77                         envs[1] = kfs_proc_create(kfs_lookup_path("parlib_channel_test_server"));
78                         smp_call_function_single(1, run_env_handler, envs[0], 0);
79                         smp_call_function_single(2, run_env_handler, envs[1], 0);
80                         break;
81                 case 3:
82         #else // sparc
83                 case 2:
84                         panic("Do not panic");
85                         envs[0] = kfs_proc_create(kfs_lookup_path("roslib_proctests"));
86                         envs[1] = kfs_proc_create(kfs_lookup_path("roslib_proctests"));
87                         envs[2] = kfs_proc_create(kfs_lookup_path("roslib_proctests"));
88                         envs[3] = kfs_proc_create(kfs_lookup_path("roslib_fptest"));
89                         envs[4] = kfs_proc_create(kfs_lookup_path("roslib_fptest"));
90                         envs[4] = kfs_proc_create(kfs_lookup_path("roslib_fptest"));
91                         envs[5] = kfs_proc_create(kfs_lookup_path("roslib_hello"));
92                         envs[6] = kfs_proc_create(kfs_lookup_path("roslib_null"));
93                         proc_run(envs[0]);
94                         break;
95                 case 3:
96                         #if 0
97                         // reminder of how to spawn remotely
98                         for (int i = 0; i < 8; i++) {
99                                 envs[i] = kfs_proc_create(kfs_lookup_path("roslib_hello"));
100                                 proc_set_state(envs[i], PROC_RUNNABLE_S);
101                                 smp_call_function_single(i, run_env_handler, envs[i], 0);
102                         }
103                         process_workqueue();
104                         #endif
105         #endif
106
107                 #if 0
108                 case 4:
109                         printk("Beginning Tests\n");
110                         test_run_measurements(progress-1);  // should never return
111                         break;
112                 case 5:
113                         envs[0] = kfs_proc_create(kfs_lookup_path("parlib_channel_test_client"));
114                         envs[1] = kfs_proc_create(kfs_lookup_path("parlib_channel_test_server"));
115                         smp_call_function_single(1, run_env_handler, envs[0], 0);
116                         smp_call_function_single(2, run_env_handler, envs[1], 0);
117                 case 6:
118                 #endif
119                 case 4:
120                         /*
121                         test_smp_call_functions();
122                         test_checklists();
123                         test_barrier();
124                         test_print_info();
125                         test_lapic_status_bit();
126                         test_ipi_sending();
127                         test_pit();
128                         */
129                 case 5:
130                 case 6:
131                 case 7:
132                 case 8:
133                 case 9:
134                 case 10:
135                 case 11:
136                 case 12:
137                 case 13:
138                 case 14:
139                         //test_run_measurements(progress-1);
140                 default:
141                         printk("Manager Progress: %d\n", progress);
142                         schedule();
143         }
144         panic("If you see me, then you probably screwed up");
145
146         /*
147         printk("Servicing syscalls from Core 0:\n\n");
148         while (1) {
149                 process_generic_syscalls(&envs[0], 1);
150                 cpu_relax();
151         }
152         */
153         return;
154 }