Can process async calls on processes that die
[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 <inc/types.h>
11 #include <inc/assert.h>
12
13 #include <kern/manager.h>
14 #include <kern/smp.h>
15 #include <kern/env.h>
16 #include <kern/apic.h>
17 #include <kern/workqueue.h>
18 #include <kern/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         switch (progress++) {
44                 case 0:
45                         for (int i = 2; i < 8; i++)
46                                 env_batch[i] = ENV_CREATE(user_hello);
47                         for (int i = 2; i < 8; i++)
48                                 smp_call_function_single(i, run_env_handler, env_batch[i], 0);
49                         int count = 0;
50                         while (count > -6) {
51                                 count = 0;
52                                 for (int i = 2; i < 8; i++) {
53                                         count += process_generic_syscalls(env_batch[i], 1);
54                                 }
55                                 cpu_relax();
56                         }
57                         process_workqueue(); // Will run this core (0)'s env
58                         panic("Don't Panic");
59                         break; // only need this when planning to reenter manager
60                 case 1:
61                         for (int i = 0; i < 4; i++)
62                                 env_batch[i] = ENV_CREATE(user_null);
63                         for (int i = 0; i < 4; i++)
64                                 smp_call_function_single(i, run_env_handler, env_batch[i], 0);
65                         //env_t* an_env = ENV_CREATE(user_null);
66                         //env_run(an_env);
67                         //smp_call_function_single(2, run_env_handler, an_env, 0);
68                         process_workqueue();
69                         break;
70                 default:
71                         printk("Waiting 5 sec for whatever reason\n");
72                         udelay(5000000);
73                         panic("Don't Panic");
74         }
75         panic("If you see me, then you probably screwed up");
76
77         /*
78         printk("Servicing syscalls from Core 0:\n\n");
79         while (1) {
80                 process_generic_syscalls(&envs[0], 1);
81                 cpu_relax();
82         }
83         */
84 }
85