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