2 * Copyright (c) 2009 The Regents of the University of California
3 * Barret Rhoden <brho@cs.berkeley.edu>
4 * See LICENSE for details.
12 #include <ros/common.h>
14 #include <arch/init.h>
30 #include <colored_caches.h>
33 #include <arch/console.h>
35 #include <ros/arch/membar.h>
38 * Currently, if you leave this function by way of proc_run (process_workqueue
39 * that proc_runs), you will never come back to where you left off, and the
40 * function will start from the top. Hence the hack 'progress'.
44 #ifndef DEVELOPER_NAME
45 #define DEVELOPER_NAME brho
49 #define PASTE(s1,s2) s1 ## s2
50 #define MANAGER_FUNC(dev) PASTE(manager_,dev)
52 void MANAGER_FUNC(DEVELOPER_NAME)(void);
53 MANAGER_FUNC(DEVELOPER_NAME)();
56 char *p_argv[] = {0, 0, 0};
57 char *p_envp[] = {"LD_LIBRARY_PATH=/lib", 0};
58 /* Helper macro for quickly running a process. Pass it a string, *file, and a
60 #define quick_proc_run(x, p, f) \
61 (f) = do_file_open((x), 0, 0); \
63 p_argv[0] = file_name((f)); \
64 (p) = proc_create((f), p_argv, p_envp); \
65 kref_put(&(f)->f_kref); \
66 spin_lock(&(p)->proc_lock); \
67 __proc_set_state((p), PROC_RUNNABLE_S); \
68 spin_unlock(&(p)->proc_lock); \
72 #define quick_proc_create(x, p, f) \
73 (f) = do_file_open((x), 0, 0); \
75 p_argv[0] = file_name((f)); \
76 (p) = proc_create((f), p_argv, p_envp); \
77 kref_put(&(f)->f_kref); \
78 spin_lock(&(p)->proc_lock); \
79 __proc_set_state((p), PROC_RUNNABLE_S); \
80 spin_unlock(&(p)->proc_lock);
82 #define quick_proc_color_run(x, p, c, f) \
83 (f) = do_file_open((x), 0, 0); \
85 p_argv[0] = file_name((f)); \
86 (p) = proc_create((f), p_argv, p_envp); \
87 kref_put(&(f)->f_kref); \
88 spin_lock(&(p)->proc_lock); \
89 __proc_set_state((p), PROC_RUNNABLE_S); \
90 spin_unlock(&(p)->proc_lock); \
91 p->cache_colors_map = cache_colors_map_alloc(); \
92 for (int i = 0; i < (c); i++) \
93 cache_color_alloc(llc_cache, p->cache_colors_map); \
97 #define quick_proc_color_create(x, p, c, f) \
98 (f) = do_file_open((x), 0, 0); \
100 p_argv[0] = file_name((f)); \
101 (p) = proc_create((f), p_argv, p_envp); \
102 kref_put(&(f)->f_kref); \
103 spin_lock(&(p)->proc_lock); \
104 __proc_set_state((p), PROC_RUNNABLE_S); \
105 spin_unlock(&(p)->proc_lock); \
106 p->cache_colors_map = cache_colors_map_alloc(); \
107 for (int i = 0; i < (c); i++) \
108 cache_color_alloc(llc_cache, p->cache_colors_map);
110 void manager_brho(void)
112 static bool first = TRUE;
113 struct per_cpu_info *pcpui = &per_cpu_info[core_id()];
116 printk("*** Hit shift-g to get into the monitor. ***\n");
119 /* just idle, and deal with things via interrupts. or via face. */
121 /* whatever we do in the manager, keep in mind that we need to not do
122 * anything too soon (like make processes), since we'll drop in here during
123 * boot if the boot sequence required any I/O (like EXT2), and we need to
127 #if 0 /* ancient tests below: (keeping around til we ditch the manager) */
128 // for testing taking cores, check in case 1 for usage
129 uint32_t corelist[MAX_NUM_CPUS];
132 static struct proc *p;
134 static uint8_t RACY progress = 0; /* this will wrap around. */
135 switch (progress++) {
137 printk("Top of the manager to ya!\n");
138 /* 124 is half of the available boxboro colors (with the kernel
140 //quick_proc_color_run("msr_dumb_while", p, 124, temp_f);
141 quick_proc_run("/bin/hello", p, temp_f);
143 // this is how you can transition to a parallel process manually
144 // make sure you don't proc run first
145 __proc_set_state(p, PROC_RUNNING_S);
146 __proc_set_state(p, PROC_RUNNABLE_M);
147 p->resources[RES_CORES].amt_wanted = 5;
148 spin_unlock(&p->proc_lock);
150 panic("This is okay");
156 // this is a ghetto way to test restarting an _M
157 printk("\nattempting to ghetto preempt...\n");
158 spin_lock(&p->proc_lock);
159 proc_take_allcores(p, __death);
160 __proc_set_state(p, PROC_RUNNABLE_M);
161 spin_unlock(&p->proc_lock);
163 printk("\nattempting to restart...\n");
164 core_request(p); // proc still wants the cores
165 panic("This is okay");
166 // this tests taking some cores, and later killing an _M
167 printk("taking 3 cores from p\n");
168 for (int i = 0; i < num; i++)
169 corelist[i] = 7-i; // 7, 6, and 5
170 spin_lock(&p->proc_lock);
171 proc_take_cores(p, corelist, &num, __death);
172 spin_unlock(&p->proc_lock);
174 printk("Killing p\n");
177 printk("Killed p\n");
178 panic("This is okay");
180 envs[0] = kfs_proc_create(kfs_lookup_path("roslib_hello"));
181 __proc_set_state(envs[0], PROC_RUNNABLE_S);
188 test_smp_call_functions();
192 test_lapic_status_bit();
197 printd("Manager Progress: %d\n", progress);
198 // delay if you want to test rescheduling an MCP that yielded
202 panic("If you see me, then you probably screwed up");
206 printk("Servicing syscalls from Core 0:\n\n");
208 process_generic_syscalls(&envs[0], 1);
216 void manager_klueska()
218 static struct proc *envs[256];
219 static volatile uint8_t progress = 0;
223 panic("what do you want to do?");
224 //envs[0] = kfs_proc_create(kfs_lookup_path("fillmeup"));
225 __proc_set_state(envs[0], PROC_RUNNABLE_S);
231 panic("DON'T PANIC");
234 void manager_waterman()
236 static bool first = true;
246 static uint8_t RACY progress = 0;
247 static struct proc *p;
249 // for testing taking cores, check in case 1 for usage
250 uint32_t corelist[MAX_NUM_CPUS];
253 //create_server(init_num_cores, loop);
257 // quick_proc_run("hello", p);
264 itoa(int num, char* buf0, size_t base)
279 buf[len++] = "0123456789abcdef"[num%base];
283 for(i = 0; i < len/2; i++)
286 buf[i] = buf[len-i-1];
294 void gsf_set_frame_cycles(int cycles)
296 store_alternate(26*4,2,cycles);
299 void gsf_set_partition_credits(int partition, int credits)
301 store_alternate((32+partition)*4,2,credits);
304 void gsf_set_core_partition(int core, int partition)
306 store_alternate((64+core)*4,2,partition);