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