Can run batches of processes repeatedly.
[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
19 /* Helper handlers for smp_call to dispatch jobs to other cores */
20 static void work_env_run(void* data)
21 {
22         env_run((env_t*)data);
23 }
24
25 static void run_env_handler(trapframe_t *tf, void* data)
26 {
27         assert(data);
28         per_cpu_info[lapic_get_id()].delayed_work.func = work_env_run;
29         per_cpu_info[lapic_get_id()].delayed_work.data = data;
30 }
31
32 /*
33  * Currently, if you leave this function by way of env_run (process_workqueue
34  * that env_runs), you will never come back to where you left off, and the
35  * function will start from the top.  Hence the hack 'progress'.
36  */
37 void manager(void)
38 {
39         static uint8_t progress = 0;
40         env_t* env_batch[64]; // Fairly arbitrary, just the max I plan to use.
41
42         switch (progress++) {
43                 case 0:
44                         for (int i = 0; i < 8; i++)
45                                 env_batch[i] = ENV_CREATE(user_null);
46                         for (int i = 0; i < 8; i++)
47                                 smp_call_function_single(i, run_env_handler, env_batch[i], 0);
48                         process_workqueue(); // Will run this core (0)'s env
49                         break;
50                 case 1:
51                         for (int i = 0; i < 4; i++)
52                                 env_batch[i] = ENV_CREATE(user_null);
53                         for (int i = 0; i < 4; i++)
54                                 smp_call_function_single(i, run_env_handler, env_batch[i], 0);
55                         //env_t* an_env = ENV_CREATE(user_null);
56                         //env_run(an_env);
57                         //smp_call_function_single(2, run_env_handler, an_env, 0);
58                         process_workqueue();
59                         break;
60                 default:
61                         printk("Waiting 5 sec for whatever reason\n");
62                         udelay(5000000);
63                         panic("Don't Panic");
64         }
65         panic("If you see me, then you probably screwed up");
66
67         /*
68         printk("Servicing syscalls from Core 0:\n\n");
69         while (1) {
70                 process_generic_syscalls(&envs[0], 1);
71                 cpu_relax();
72         }
73         */
74 }
75