d7aca05851bd76406a2ee1c9edb2890e9df2e7ad
[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 <arch/types.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 progress = 0;
33         struct proc *envs[256];
34
35 struct proc *p = kfs_proc_create(kfs_lookup_path("roslib_mhello"));
36 // being proper and all:
37 proc_set_state(p, PROC_RUNNABLE_S);
38 proc_set_state(p, PROC_RUNNING_S);
39 proc_set_state(p, PROC_RUNNABLE_M);
40 // set vcoremap with dispatch plan.  usually done by schedule()
41 spin_lock_irqsave(&p->proc_lock);
42 p->num_vcores = 5;
43 for (int i = 0; i < 5; i++)
44         p->vcoremap[i] = i + 1; // vcore0 -> pcore1, etc, for 3 cores
45 spin_unlock_irqsave(&p->proc_lock);
46 proc_run(p);
47 printk("Killing p\n");
48 proc_destroy(p);
49 printk("Killed p\n");
50 udelay(5000000);
51 panic("This is okay");
52
53         switch (progress++) {
54                 case 0:
55                         envs[0] = kfs_proc_create(kfs_lookup_path("roslib_hello"));
56                         proc_set_state(envs[0], PROC_RUNNABLE_S);
57                         proc_run(envs[0]);
58                         break;
59         #ifdef __i386__
60                 case 1:
61                         panic("Do not panic");
62                         envs[0] = kfs_proc_create(kfs_lookup_path("parlib_channel_test_client"));
63                         envs[1] = kfs_proc_create(kfs_lookup_path("parlib_channel_test_server"));
64                         smp_call_function_single(1, run_env_handler, envs[0], 0);
65                         smp_call_function_single(2, run_env_handler, envs[1], 0);
66                         break;
67                 case 2:
68                 case 3:
69         #else // sparc
70                 case 1:
71                         panic("Do not panic");
72                         envs[0] = kfs_proc_create(kfs_lookup_path("roslib_proctests"));
73                         envs[1] = kfs_proc_create(kfs_lookup_path("roslib_proctests"));
74                         envs[2] = kfs_proc_create(kfs_lookup_path("roslib_proctests"));
75                         envs[3] = kfs_proc_create(kfs_lookup_path("roslib_fptest"));
76                         envs[4] = kfs_proc_create(kfs_lookup_path("roslib_fptest"));
77                         envs[4] = kfs_proc_create(kfs_lookup_path("roslib_fptest"));
78                         envs[5] = kfs_proc_create(kfs_lookup_path("roslib_hello"));
79                         envs[6] = kfs_proc_create(kfs_lookup_path("roslib_null"));
80                         proc_run(envs[0]);
81                         break;
82                 case 2:
83                         #if 0
84                         // reminder of how to spawn remotely
85                         for (int i = 0; i < 8; i++) {
86                                 envs[i] = kfs_proc_create(kfs_lookup_path("roslib_hello"));
87                                 proc_set_state(envs[i], PROC_RUNNABLE_S);
88                                 smp_call_function_single(i, run_env_handler, envs[i], 0);
89                         }
90                         process_workqueue();
91                         #endif
92                 case 3:
93         #endif
94
95                 #if 0
96                 case 4:
97                         printk("Beginning Tests\n");
98                         test_run_measurements(progress-1);  // should never return
99                         break;
100                 case 5:
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                 case 6:
106                 #endif
107                 case 4:
108                         /*
109                         test_smp_call_functions();
110                         test_checklists();
111                         test_barrier();
112                         test_print_info();
113                         test_lapic_status_bit();
114                         test_ipi_sending();
115                         test_pit();
116                         */
117                 case 5:
118                 case 6:
119                 case 7:
120                 case 8:
121                 case 9:
122                 case 10:
123                 case 11:
124                 case 12:
125                 case 13:
126                 case 14:
127                         //test_run_measurements(progress-1);
128                 default:
129                         printk("Manager Progress: %d\n", progress);
130                         schedule();
131         }
132         panic("If you see me, then you probably screwed up");
133
134         /*
135         printk("Servicing syscalls from Core 0:\n\n");
136         while (1) {
137                 process_generic_syscalls(&envs[0], 1);
138                 cpu_relax();
139         }
140         */
141         return;
142 }