Added open_read, enabled it to run.
[akaros.git] / kern / src / manager.c
1 /*
2  * Copyright (c) 2009 The Regents of the University of California
3  * See LICENSE for details.
4  */
5
6 #ifdef __DEPUTY__
7 #pragma nodeputy
8 #endif
9
10 #include <arch/types.h>
11 #include <arch/apic.h>
12 #include <arch/smp.h>
13
14 #include <assert.h>
15 #include <manager.h>
16 #include <env.h>
17 #include <workqueue.h>
18 #include <syscall.h>
19
20 /* Helper handlers for smp_call to dispatch jobs to other cores */
21 static void work_env_run(void* data)
22 {
23         env_run((env_t*)data);
24 }
25
26 static void run_env_handler(trapframe_t *tf, void* data)
27 {
28         assert(data);
29         per_cpu_info[lapic_get_id()].delayed_work.func = work_env_run;
30         per_cpu_info[lapic_get_id()].delayed_work.data = data;
31 }
32
33 /*
34  * Currently, if you leave this function by way of env_run (process_workqueue
35  * that env_runs), you will never come back to where you left off, and the
36  * function will start from the top.  Hence the hack 'progress'.
37  */
38 void manager(void)
39 {
40         static uint8_t progress = 0;
41         env_t* env_batch[64]; // Fairly arbitrary, just the max I plan to use.
42         
43         if(progress == 0) {
44                 progress++;
45                 env_batch[0] = ENV_CREATE(parlib_open_read);
46                 env_run(env_batch[0]);
47         }
48         return;
49
50         switch (progress++) {
51                 case 0:
52                         
53                         for (int i = 2; i < 8; i++)
54                                 env_batch[i] = ENV_CREATE(parlib_open_read);
55                         for (int i = 2; i < 8; i++)
56                                 smp_call_function_single(i, run_env_handler, env_batch[i], 0);
57                         int count = 0;
58                         while (count > -6) {
59                                 count = 0;
60                                 for (int i = 2; i < 8; i++) {
61                                         count += process_generic_syscalls(env_batch[i], 1);
62                                 }
63                                 cpu_relax();
64                         }
65                         process_workqueue(); // Will run this core (0)'s env
66                         panic("Don't Panic");
67                         break; // only need this when planning to reenter manager
68                 case 1:
69                         for (int i = 0; i < 4; i++)
70                                 env_batch[i] = ENV_CREATE(roslib_null);
71                         for (int i = 0; i < 4; i++)
72                                 smp_call_function_single(i, run_env_handler, env_batch[i], 0);
73                         //env_t* an_env = ENV_CREATE(user_null);
74                         //env_run(an_env);
75                         //smp_call_function_single(2, run_env_handler, an_env, 0);
76                         process_workqueue();
77                         break;
78                 default:
79                         printk("Waiting 5 sec for whatever reason\n");
80                         udelay(5000000);
81                         panic("Don't Panic");
82         }
83         panic("If you see me, then you probably screwed up");
84
85         /*
86         printk("Servicing syscalls from Core 0:\n\n");
87         while (1) {
88                 process_generic_syscalls(&envs[0], 1);
89                 cpu_relax();
90         }
91         */
92 }
93