2 * Copyright (c) 2009 The Regents of the University of California
3 * Barret Rhoden <brho@cs.berkeley.edu>
4 * See LICENSE for details.
8 #include <ros/common.h>
10 #include <arch/init.h>
26 #include <colored_caches.h>
29 #include <arch/console.h>
31 #include <ros/arch/membar.h>
34 * Currently, if you leave this function by way of proc_run (process_workqueue
35 * that proc_runs), you will never come back to where you left off, and the
36 * function will start from the top. Hence the hack 'progress'.
41 #define PASTE(s1,s2) s1 ## s2
42 #define MANAGER_FUNC(dev) PASTE(manager_,dev)
44 #if !defined(DEVELOPER_NAME) && \
45 (defined(CONFIG_KERNEL_POSTBOOT_TESTING) || \
46 defined(CONFIG_USERSPACE_TESTING))
47 #define DEVELOPER_NAME jenkins
50 #ifndef DEVELOPER_NAME
51 #define DEVELOPER_NAME brho
54 void MANAGER_FUNC(DEVELOPER_NAME)(void);
55 MANAGER_FUNC(DEVELOPER_NAME)();
58 char *p_argv[] = {0, 0, 0};
59 /* Helper macro for quickly running a process. Pass it a string, *file, and a
61 #define quick_proc_run(x, p, f) \
62 (f) = do_file_open((x), O_READ, 0); \
64 p_argv[0] = file_name((f)); \
65 (p) = proc_create((f), p_argv, NULL); \
66 kref_put(&(f)->f_kref); \
67 spin_lock(&(p)->proc_lock); \
68 __proc_set_state((p), PROC_RUNNABLE_S); \
69 spin_unlock(&(p)->proc_lock); \
73 #define quick_proc_create(x, p, f) \
74 (f) = do_file_open((x), O_READ, 0); \
76 p_argv[0] = file_name((f)); \
77 (p) = proc_create((f), p_argv, NULL); \
78 kref_put(&(f)->f_kref); \
79 spin_lock(&(p)->proc_lock); \
80 __proc_set_state((p), PROC_RUNNABLE_S); \
81 spin_unlock(&(p)->proc_lock);
83 #define quick_proc_color_run(x, p, c, f) \
84 (f) = do_file_open((x), O_READ, 0); \
86 p_argv[0] = file_name((f)); \
87 (p) = proc_create((f), p_argv, NULL); \
88 kref_put(&(f)->f_kref); \
89 spin_lock(&(p)->proc_lock); \
90 __proc_set_state((p), PROC_RUNNABLE_S); \
91 spin_unlock(&(p)->proc_lock); \
92 p->cache_colors_map = cache_colors_map_alloc(); \
93 for (int i = 0; i < (c); i++) \
94 cache_color_alloc(llc_cache, p->cache_colors_map); \
98 #define quick_proc_color_create(x, p, c, f) \
99 (f) = do_file_open((x), O_READ, 0); \
101 p_argv[0] = file_name((f)); \
102 (p) = proc_create((f), p_argv, NULL); \
103 kref_put(&(f)->f_kref); \
104 spin_lock(&(p)->proc_lock); \
105 __proc_set_state((p), PROC_RUNNABLE_S); \
106 spin_unlock(&(p)->proc_lock); \
107 p->cache_colors_map = cache_colors_map_alloc(); \
108 for (int i = 0; i < (c); i++) \
109 cache_color_alloc(llc_cache, p->cache_colors_map);
111 void manager_brho(void)
113 static bool first = TRUE;
114 struct per_cpu_info *pcpui = &per_cpu_info[core_id()];
117 printk("*** IRQs must be enabled for input emergency codes ***\n");
119 printk("*** Hit ctrl-g to enter the monitor. ***\n");
120 printk("*** Hit ctrl-q to force-enter the monitor. ***\n");
121 printk("*** Hit ctrl-b for a backtrace of core 0 ***\n");
123 printk("*** Hit ctrl-g to enter the monitor. ***\n");
124 #warning "***** ctrl-g untested on riscv, check k/a/r/trap.c *****"
128 /* just idle, and deal with things via interrupts. or via face. */
130 /* whatever we do in the manager, keep in mind that we need to not do
131 * anything too soon (like make processes), since we'll drop in here during
132 * boot if the boot sequence required any I/O (like EXT2), and we need to
136 #if 0 /* ancient tests below: (keeping around til we ditch the manager) */
137 // for testing taking cores, check in case 1 for usage
138 uint32_t corelist[MAX_NUM_CORES];
141 static struct proc *p;
143 static uint8_t RACY progress = 0; /* this will wrap around. */
144 switch (progress++) {
146 printk("Top of the manager to ya!\n");
147 /* 124 is half of the available boxboro colors (with the kernel
149 //quick_proc_color_run("msr_dumb_while", p, 124, temp_f);
150 quick_proc_run("/bin/hello", p, temp_f);
152 // this is how you can transition to a parallel process manually
153 // make sure you don't proc run first
154 __proc_set_state(p, PROC_RUNNING_S);
155 __proc_set_state(p, PROC_RUNNABLE_M);
156 p->resources[RES_CORES].amt_wanted = 5;
157 spin_unlock(&p->proc_lock);
159 panic("This is okay");
165 // this is a ghetto way to test restarting an _M
166 printk("\nattempting to ghetto preempt...\n");
167 spin_lock(&p->proc_lock);
168 proc_take_allcores(p, __death);
169 __proc_set_state(p, PROC_RUNNABLE_M);
170 spin_unlock(&p->proc_lock);
172 printk("\nattempting to restart...\n");
173 core_request(p); // proc still wants the cores
174 panic("This is okay");
175 // this tests taking some cores, and later killing an _M
176 printk("taking 3 cores from p\n");
177 for (int i = 0; i < num; i++)
178 corelist[i] = 7-i; // 7, 6, and 5
179 spin_lock(&p->proc_lock);
180 proc_take_cores(p, corelist, &num, __death);
181 spin_unlock(&p->proc_lock);
183 printk("Killing p\n");
186 printk("Killed p\n");
187 panic("This is okay");
189 envs[0] = kfs_proc_create(kfs_lookup_path("roslib_hello"));
190 __proc_set_state(envs[0], PROC_RUNNABLE_S);
197 test_smp_call_functions();
201 test_lapic_status_bit();
206 printd("Manager Progress: %d\n", progress);
207 // delay if you want to test rescheduling an MCP that yielded
211 panic("If you see me, then you probably screwed up");
215 printk("Servicing syscalls from Core 0:\n\n");
217 process_generic_syscalls(&envs[0], 1);
225 void manager_jenkins()
227 #ifdef CONFIG_KERNEL_TESTING
228 printk("<-- BEGIN_KERNEL_TESTS -->\n");
229 run_registered_ktest_suites();
230 printk("<-- END_KERNEL_TESTS -->\n");
233 // Run userspace tests (from config specified path).
234 #ifdef CONFIG_USERSPACE_TESTING
235 if (strlen(CONFIG_USERSPACE_TESTING_SCRIPT) != 0) {
236 char exec[] = "/bin/ash";
237 char *p_argv[] = {exec, CONFIG_USERSPACE_TESTING_SCRIPT, 0};
239 struct file *program = do_file_open(exec, O_READ, 0);
240 struct proc *p = proc_create(program, p_argv, NULL);
242 proc_decref(p); /* let go of the reference created in proc_create() */
243 kref_put(&program->f_kref);
245 // Need a way to wait for p to finish
247 printk("No user-space launcher file specified.\n");
254 void manager_klueska()
256 static struct proc *envs[256];
257 static volatile uint8_t progress = 0;
261 panic("what do you want to do?");
262 //envs[0] = kfs_proc_create(kfs_lookup_path("fillmeup"));
263 __proc_set_state(envs[0], PROC_RUNNABLE_S);
269 panic("DON'T PANIC");
272 void manager_waterman()
274 static bool first = true;
284 static uint8_t progress = 0;
285 static struct proc *p;
287 // for testing taking cores, check in case 1 for usage
288 uint32_t corelist[MAX_NUM_CORES];
291 //create_server(init_num_cores, loop);
295 // quick_proc_run("hello", p);