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