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