1 /* Copyright (c) 2009, 2012 The Regents of the University of California
2 * Barret Rhoden <brho@cs.berkeley.edu>
3 * See LICENSE for details.
5 * Scheduling and dispatching. */
20 #include <sys/queue.h>
23 /* Process Lists. 'unrunnable' is a holding list for SCPs that are running or
24 * waiting or otherwise not considered for sched decisions. */
25 struct proc_list unrunnable_scps = TAILQ_HEAD_INITIALIZER(unrunnable_scps);
26 struct proc_list runnable_scps = TAILQ_HEAD_INITIALIZER(runnable_scps);
27 struct proc_list all_mcps = TAILQ_HEAD_INITIALIZER(all_mcps);
28 spinlock_t sched_lock = SPINLOCK_INITIALIZER;
30 /* The pcores in the system. (array gets alloced in init()). */
31 struct sched_pcore *all_pcores;
33 /* Tracks which cores are idle, similar to the vcoremap. Each value is the
34 * physical coreid of an unallocated core. These are all now protected by the
35 * sched_lock (they will change sooner or later). */
36 uint32_t idlecoremap[MAX_NUM_CPUS];
37 uint32_t num_idlecores = 0;
38 uint32_t num_mgmtcores = 1;
40 /* Helper, defined below */
41 static void __core_request(struct proc *p);
42 static void __put_idle_cores(struct proc *p, uint32_t *pc_arr, uint32_t num);
43 static void add_to_list(struct proc *p, struct proc_list *list);
44 static void remove_from_list(struct proc *p, struct proc_list *list);
45 static void switch_lists(struct proc *p, struct proc_list *old,
46 struct proc_list *new);
47 static uint32_t schedpcore2pcoreid(struct sched_pcore *spc);
48 static bool is_ll_core(uint32_t pcoreid);
49 static void __prov_track_alloc(struct proc *p, uint32_t pcoreid);
50 static void __prov_track_dealloc(struct proc *p, uint32_t pcoreid);
51 static void __prov_track_dealloc_bulk(struct proc *p, uint32_t *pc_arr,
54 /* Alarm struct, for our example 'timer tick' */
55 struct alarm_waiter ksched_waiter;
57 #define TIMER_TICK_USEC 10000 /* 10msec */
59 /* Helper: Sets up a timer tick on the calling core to go off 10 msec from now.
60 * This assumes the calling core is an LL core, etc. */
61 static void set_ksched_alarm(void)
63 set_awaiter_rel(&ksched_waiter, TIMER_TICK_USEC);
64 set_alarm(&per_cpu_info[core_id()].tchain, &ksched_waiter);
67 /* Kmsg, to run the scheduler tick (not in interrupt context) and reset the
68 * alarm. Note that interrupts will be disabled, but this is not the same as
69 * interrupt context. We're a routine kmsg, which means the core is in a
71 static void __ksched_tick(struct trapframe *tf, uint32_t srcid, long a0,
74 /* TODO: imagine doing some accounting here */
76 /* Set our alarm to go off, incrementing from our last tick (instead of
77 * setting it relative to now, since some time has passed since the alarm
78 * first went off. Note, this may be now or in the past! */
79 set_awaiter_inc(&ksched_waiter, TIMER_TICK_USEC);
80 set_alarm(&per_cpu_info[core_id()].tchain, &ksched_waiter);
83 /* Interrupt/alarm handler: tells our core to run the scheduler (out of
84 * interrupt context). */
85 static void __kalarm(struct alarm_waiter *waiter)
87 send_kernel_message(core_id(), __ksched_tick, 0, 0, 0, KMSG_ROUTINE);
90 void schedule_init(void)
92 /* init provisioning stuff */
93 all_pcores = kmalloc(sizeof(struct sched_pcore) * num_cpus, 0);
94 memset(all_pcores, 0, sizeof(struct sched_pcore) * num_cpus);
95 assert(!core_id()); /* want the alarm on core0 for now */
96 init_awaiter(&ksched_waiter, __kalarm);
98 /* Ghetto old idle core init */
99 /* Init idle cores. Core 0 is the management core. */
100 spin_lock(&sched_lock);
101 #ifdef __CONFIG_DISABLE_SMT__
102 /* assumes core0 is the only management core (NIC and monitor functionality
103 * are run there too. it just adds the odd cores to the idlecoremap */
104 assert(!(num_cpus % 2));
105 // TODO: consider checking x86 for machines that actually hyperthread
106 num_idlecores = num_cpus >> 1;
107 #ifdef __CONFIG_ARSC_SERVER__
108 // Dedicate one core (core 2) to sysserver, might be able to share wit NIC
110 assert(num_cpus >= num_mgmtcores);
111 send_kernel_message(2, (amr_t)arsc_server, 0,0,0, KMSG_ROUTINE);
113 for (int i = 0; i < num_idlecores; i++)
114 idlecoremap[i] = (i * 2) + 1;
116 // __CONFIG_DISABLE_SMT__
117 #ifdef __CONFIG_APPSERVER__
118 #ifdef __CONFIG_DEDICATED_MONITOR__
119 num_mgmtcores++; // Next core dedicated to running the kernel monitor
120 assert(num_cpus >= num_mgmtcores);
121 // Need to subtract 1 from the num_mgmtcores # to get the cores index
122 send_kernel_message(num_mgmtcores-1, (amr_t)monitor, 0,0,0, KMSG_ROUTINE);
125 #ifdef __CONFIG_ARSC_SERVER__
126 // Dedicate one core (core 2) to sysserver, might be able to share with NIC
128 assert(num_cpus >= num_mgmtcores);
129 send_kernel_message(num_mgmtcores-1, (amr_t)arsc_server, 0,0,0, KMSG_ROUTINE);
131 num_idlecores = num_cpus - num_mgmtcores;
132 for (int i = 0; i < num_idlecores; i++)
133 idlecoremap[i] = i + num_mgmtcores;
134 #endif /* __CONFIG_DISABLE_SMT__ */
135 spin_unlock(&sched_lock);
139 /* Round-robins on whatever list it's on */
140 static void add_to_list(struct proc *p, struct proc_list *new)
142 TAILQ_INSERT_TAIL(new, p, ksched_data.proc_link);
143 p->ksched_data.cur_list = new;
146 static void remove_from_list(struct proc *p, struct proc_list *old)
148 assert(p->ksched_data.cur_list == old);
149 TAILQ_REMOVE(old, p, ksched_data.proc_link);
152 static void switch_lists(struct proc *p, struct proc_list *old,
153 struct proc_list *new)
155 remove_from_list(p, old);
159 static void __remove_from_any_list(struct proc *p)
161 if (p->ksched_data.cur_list)
162 TAILQ_REMOVE(p->ksched_data.cur_list, p, ksched_data.proc_link);
165 /* Removes from whatever list p is on */
166 static void remove_from_any_list(struct proc *p)
168 assert(p->ksched_data.cur_list);
169 TAILQ_REMOVE(p->ksched_data.cur_list, p, ksched_data.proc_link);
172 void register_proc(struct proc *p)
174 /* one ref for the proc's existence, cradle-to-grave */
175 proc_incref(p, 1); /* need at least this OR the 'one for existing' */
176 spin_lock(&sched_lock);
177 TAILQ_INIT(&p->ksched_data.prov_alloc_me);
178 TAILQ_INIT(&p->ksched_data.prov_not_alloc_me);
179 add_to_list(p, &unrunnable_scps);
180 spin_unlock(&sched_lock);
183 /* Returns 0 if it succeeded, an error code otherwise. */
184 int proc_change_to_m(struct proc *p)
187 spin_lock(&sched_lock);
188 /* Should only be necessary to lock around the change_to_m call. It's
189 * definitely necessary to hold the sched lock the whole time - need to
190 * atomically change the proc's state and have the ksched take action (and
191 * not squeeze a proc_destroy in there or something). */
192 spin_lock(&p->proc_lock);
193 retval = __proc_change_to_m(p);
194 spin_unlock(&p->proc_lock);
196 /* Failed for some reason. */
197 spin_unlock(&sched_lock);
200 /* Catch user bugs */
201 if (!p->procdata->res_req[RES_CORES].amt_wanted) {
202 printk("[kernel] process needs to specify amt_wanted\n");
203 p->procdata->res_req[RES_CORES].amt_wanted = 1;
205 /* For now, this should only ever be called on an unrunnable. It's
206 * probably a bug, at this stage in development, to do o/w. */
207 remove_from_list(p, &unrunnable_scps);
208 //remove_from_any_list(p); /* ^^ instead of this */
209 add_to_list(p, &all_mcps);
210 spin_unlock(&sched_lock);
211 //poke_ksched(p, RES_CORES);
215 /* Makes sure p is runnable. Callers may spam this, so it needs to handle
216 * repeated calls for the same event. Callers include event delivery, SCP
217 * yield, and new SCPs. Most every scheduler should do something like this -
218 * grab whatever lock you have, then call the proc helper. */
219 void proc_wakeup(struct proc *p)
221 spin_lock(&sched_lock);
222 /* will trigger one of the __sched_.cp_wakeup()s */
224 spin_unlock(&sched_lock);
227 static uint32_t schedpcore2pcoreid(struct sched_pcore *spc)
229 return spc - all_pcores;
232 /* Helper for proc destroy: unprovisions any pcores for the given list */
233 static void unprov_pcore_list(struct sched_pcore_tailq *list_head)
235 struct sched_pcore *spc_i;
236 /* We can leave them connected within the tailq, since the scps don't have a
237 * default list (if they aren't on a proc's list, then we don't care about
238 * them), and since the INSERTs don't care what list you were on before
239 * (chummy with the implementation). Pretty sure this is right. If there's
240 * suspected list corruption, be safer here. */
241 TAILQ_FOREACH(spc_i, list_head, next)
242 spc_i->prov_proc = 0;
243 TAILQ_INIT(list_head);
246 /* Destroys the given process. This may be called from another process, a light
247 * kernel thread (no real process context), asynchronously/cross-core, or from
248 * the process on its own core.
250 * An external, edible ref is passed in. when we return and they decref,
251 * __proc_free will be called */
252 void proc_destroy(struct proc *p)
254 uint32_t nr_cores_revoked = 0;
255 spin_lock(&sched_lock);
256 spin_lock(&p->proc_lock);
257 /* storage for pc_arr is alloced at decl, which is after grabbing the lock*/
258 uint32_t pc_arr[p->procinfo->num_vcores];
259 /* If this returns true, it means we successfully destroyed the proc */
260 if (__proc_destroy(p, pc_arr, &nr_cores_revoked)) {
261 /* Do our cleanup. note that proc_free won't run since we have an
262 * external reference, passed in */
263 /* Unprovision any cores. Note this is different than track_dealloc.
264 * The latter does bookkeeping when an allocation changes. This is a
265 * bulk *provisioning* change. */
266 unprov_pcore_list(&p->ksched_data.prov_alloc_me);
267 unprov_pcore_list(&p->ksched_data.prov_not_alloc_me);
268 /* Remove from whatever list we are on */
269 remove_from_any_list(p);
270 /* Drop the cradle-to-the-grave reference, jet-li */
272 if (nr_cores_revoked) {
273 __put_idle_cores(p, pc_arr, nr_cores_revoked);
274 __prov_track_dealloc_bulk(p, pc_arr, nr_cores_revoked);
277 spin_unlock(&p->proc_lock);
278 spin_unlock(&sched_lock);
281 /* mgmt/LL cores should call this to schedule the calling core and give it to an
282 * SCP. will also prune the dead SCPs from the list. hold the lock before
283 * calling. returns TRUE if it scheduled a proc. */
284 static bool __schedule_scp(void)
287 uint32_t pcoreid = core_id();
288 struct per_cpu_info *pcpui = &per_cpu_info[pcoreid];
290 /* if there are any runnables, run them here and put any currently running
291 * SCP on the tail of the runnable queue. */
292 if ((p = TAILQ_FIRST(&runnable_scps))) {
293 /* protect owning proc, cur_tf, etc. note this nests with the
294 * calls in proc_yield_s */
295 disable_irqsave(&state);
296 /* someone is currently running, dequeue them */
297 if (pcpui->owning_proc) {
298 printd("Descheduled %d in favor of %d\n", pcpui->owning_proc->pid,
300 /* locking just to be safe */
301 spin_lock(&p->proc_lock);
302 __proc_set_state(pcpui->owning_proc, PROC_RUNNABLE_S);
303 __proc_save_context_s(pcpui->owning_proc, pcpui->cur_tf);
304 spin_unlock(&p->proc_lock);
305 /* round-robin the SCPs (inserts at the end of the queue) */
306 switch_lists(pcpui->owning_proc, &unrunnable_scps, &runnable_scps);
307 clear_owning_proc(pcoreid);
308 /* Note we abandon core. It's not strictly necessary. If
309 * we didn't, the TLB would still be loaded with the old
310 * one, til we proc_run_s, and the various paths in
311 * proc_run_s would pick it up. This way is a bit safer for
312 * future changes, but has an extra (empty) TLB flush. */
315 /* Run the new proc */
316 switch_lists(p, &runnable_scps, &unrunnable_scps);
317 printd("PID of the SCP i'm running: %d\n", p->pid);
318 proc_run_s(p); /* gives it core we're running on */
319 enable_irqsave(&state);
325 /* Something has changed, and for whatever reason the scheduler should
328 * Don't call this from interrupt context (grabs proclocks). */
331 struct proc *p, *temp;
332 spin_lock(&sched_lock);
333 /* trivially try to handle the needs of all our MCPS. smarter schedulers
334 * would do something other than FCFS */
335 TAILQ_FOREACH_SAFE(p, &all_mcps, ksched_data.proc_link, temp) {
336 printd("Ksched has MCP %08p (%d)\n", p, p->pid);
339 /* TODO: might use amt_wanted as a proxy. right now, they have
340 * amt_wanted == 1, even though they are waiting.
341 * TODO: this is RACY too - just like with DYING. */
342 if (p->state == PROC_WAITING)
346 if (management_core())
348 spin_unlock(&sched_lock);
351 /* A process is asking the ksched to look at its resource desires. The
352 * scheduler is free to ignore this, for its own reasons, so long as it
353 * eventually gets around to looking at resource desires. */
354 void poke_ksched(struct proc *p, int res_type)
356 /* TODO: probably want something to trigger all res_types */
357 spin_lock(&sched_lock);
360 /* ignore core requests from non-mcps (note we have races if we ever
361 * allow procs to switch back). */
362 if (!__proc_is_mcp(p))
369 spin_unlock(&sched_lock);
372 /* ksched callbacks. p just woke up, is unlocked, and the ksched lock is held */
373 void __sched_mcp_wakeup(struct proc *p)
375 /* the essence of poke_ksched for RES_CORES */
379 /* ksched callbacks. p just woke up, is unlocked, and the ksched lock is held */
380 void __sched_scp_wakeup(struct proc *p)
382 /* might not be on a list if it is new. o/w, it should be unrunnable */
383 __remove_from_any_list(p);
384 add_to_list(p, &runnable_scps);
387 /* The calling cpu/core has nothing to do and plans to idle/halt. This is an
388 * opportunity to pick the nature of that halting (low power state, etc), or
389 * provide some other work (_Ss on LL cores). Note that interrupts are
390 * disabled, and if you return, the core will cpu_halt(). */
393 bool new_proc = FALSE;
394 if (!management_core())
396 spin_lock(&sched_lock);
397 new_proc = __schedule_scp();
398 spin_unlock(&sched_lock);
399 /* if we just scheduled a proc, we need to manually restart it, instead of
400 * returning. if we return, the core will halt. */
405 /* Could drop into the monitor if there are no processes at all. For now,
406 * the 'call of the giraffe' suffices. */
409 /* Externally called function to return a core to the ksched, which tracks it as
410 * idle and deallocated from p.
412 * This also is a trigger, telling us we have more cores. We could/should make
413 * a scheduling decision (or at least plan to). */
414 void put_idle_core(struct proc *p, uint32_t coreid)
416 spin_lock(&sched_lock);
417 idlecoremap[num_idlecores++] = coreid;
418 __prov_track_dealloc(p, coreid);
419 spin_unlock(&sched_lock);
422 /* Helper for put_idle and core_req. Note this does not all track_dealloc */
423 static void __put_idle_cores(struct proc *p, uint32_t *pc_arr, uint32_t num)
425 for (int i = 0; i < num; i++)
426 idlecoremap[num_idlecores++] = pc_arr[i];
429 /* External interface for put_idle. Note this one also calls track_dealloc,
430 * which the internal version does not. */
431 void put_idle_cores(struct proc *p, uint32_t *pc_arr, uint32_t num)
433 spin_lock(&sched_lock);
434 __put_idle_cores(p, pc_arr, num);
435 __prov_track_dealloc_bulk(p, pc_arr, num);
436 spin_unlock(&sched_lock);
437 /* could trigger a sched decision here */
440 /* Available resources changed (plus or minus). Some parts of the kernel may
441 * call this if a particular resource that is 'quantity-based' changes. Things
442 * like available RAM to processes, bandwidth, etc. Cores would probably be
443 * inappropriate, since we need to know which specific core is now free. */
444 void avail_res_changed(int res_type, long change)
446 printk("[kernel] ksched doesn't track any resources yet!\n");
449 /* Normally it'll be the max number of CG cores ever */
450 uint32_t max_vcores(struct proc *p)
452 #ifdef __CONFIG_DISABLE_SMT__
453 return num_cpus >> 1;
455 return MAX(1, num_cpus - num_mgmtcores);
456 #endif /* __CONFIG_DISABLE_SMT__ */
459 /* Ghetto helper, just hands out up to 'amt_new' cores (no sense of locality or
461 static uint32_t __get_idle_cores(struct proc *p, uint32_t *pc_arr,
464 uint32_t num_granted = 0;
465 for (int i = 0; i < num_idlecores && i < amt_new; i++) {
466 /* grab the last one on the list */
467 pc_arr[i] = idlecoremap[num_idlecores - 1];
474 /* This deals with a request for more cores. The request is already stored in
475 * the proc's amt_wanted (it is compared to amt_granted). */
476 static void __core_request(struct proc *p)
478 uint32_t num_granted, amt_wanted, amt_granted;
479 uint32_t corelist[num_cpus];
481 /* TODO: consider copy-in for amt_wanted too. */
482 amt_wanted = p->procdata->res_req[RES_CORES].amt_wanted;
483 amt_granted = p->procinfo->res_grant[RES_CORES];
485 /* Help them out - if they ask for something impossible, give them 1 so they
486 * can make some progress. (this is racy). */
487 if (amt_wanted > p->procinfo->max_vcores) {
488 p->procdata->res_req[RES_CORES].amt_wanted = 1;
490 /* if they are satisfied, we're done. There's a slight chance they have
491 * cores, but they aren't running (sched gave them cores while they were
492 * yielding, and now we see them on the run queue). */
493 if (amt_wanted <= amt_granted)
495 /* Otherwise, see what they want, and try to give out as many as possible.
496 * Current models are simple - it's just a raw number of cores, and we just
497 * give out what we can. */
498 num_granted = __get_idle_cores(p, corelist, amt_wanted - amt_granted);
499 /* Now, actually give them out */
501 /* give them the cores. this will start up the extras if RUNNING_M. */
502 spin_lock(&p->proc_lock);
503 /* if they fail, it is because they are WAITING or DYING. we could give
504 * the cores to another proc or whatever. for the current type of
505 * ksched, we'll just put them back on the pile and return. Note, the
506 * ksched could check the states after locking, but it isn't necessary:
507 * just need to check at some point in the ksched loop. */
508 if (__proc_give_cores(p, corelist, num_granted)) {
509 __put_idle_cores(p, corelist, num_granted);
511 /* track the (successful) allocation of the sched_pcores */
512 for (int i = 0; i < num_granted; i++)
513 __prov_track_alloc(p, corelist[i]);
514 /* at some point after giving cores, call proc_run_m() (harmless on
515 * RUNNING_Ms). You can give small groups of cores, then run them
516 * (which is more efficient than interleaving runs with the gives
517 * for bulk preempted processes). */
520 spin_unlock(&p->proc_lock);
524 /* TODO: need more thorough CG/LL management. For now, core0 is the only LL
525 * core. This won't play well with the ghetto shit in schedule_init() if you do
526 * anything like 'DEDICATED_MONITOR' or the ARSC server. All that needs an
528 static bool is_ll_core(uint32_t pcoreid)
535 /* Helper, makes sure the prov/alloc structures track the pcore properly when it
536 * is allocated to p. Might make this take a sched_pcore * in the future. */
537 static void __prov_track_alloc(struct proc *p, uint32_t pcoreid)
539 struct sched_pcore *spc;
540 assert(pcoreid < num_cpus); /* catch bugs */
541 spc = &all_pcores[pcoreid];
542 assert(spc->alloc_proc != p); /* corruption or double-alloc */
544 /* if the pcore is prov to them and now allocated, move lists */
545 if (spc->prov_proc == p) {
546 TAILQ_REMOVE(&p->ksched_data.prov_not_alloc_me, spc, next);
547 TAILQ_INSERT_TAIL(&p->ksched_data.prov_alloc_me, spc, next);
551 /* Helper, makes sure the prov/alloc structures track the pcore properly when it
552 * is deallocated from p. */
553 static void __prov_track_dealloc(struct proc *p, uint32_t pcoreid)
555 struct sched_pcore *spc;
556 assert(pcoreid < num_cpus); /* catch bugs */
557 spc = &all_pcores[pcoreid];
559 /* if the pcore is prov to them and now deallocated, move lists */
560 if (spc->prov_proc == p) {
561 TAILQ_REMOVE(&p->ksched_data.prov_alloc_me, spc, next);
562 /* this is the victim list, which can be sorted so that we pick the
563 * right victim (sort by alloc_proc reverse priority, etc). In this
564 * case, the core isn't alloc'd by anyone, so it should be the first
566 TAILQ_INSERT_HEAD(&p->ksched_data.prov_not_alloc_me, spc, next);
570 /* Bulk interface for __prov_track_dealloc */
571 static void __prov_track_dealloc_bulk(struct proc *p, uint32_t *pc_arr,
574 for (int i = 0; i < nr_cores; i++)
575 __prov_track_dealloc(p, pc_arr[i]);
578 /* P will get pcore if it needs more cores next time we look at it */
579 void provision_core(struct proc *p, uint32_t pcoreid)
581 struct sched_pcore *spc;
582 struct sched_pcore_tailq *prov_list;
583 /* Make sure we aren't asking for something that doesn't exist (bounds check
584 * on the pcore array) */
585 if (!(pcoreid < num_cpus))
586 return; /* could do an error code */
587 /* Don't allow the provisioning of LL cores */
588 if (is_ll_core(pcoreid))
590 spc = &all_pcores[pcoreid];
591 /* Note the sched lock protects the spc tailqs for all procs in this code.
592 * If we need a finer grained sched lock, this is one place where we could
593 * have a different lock */
594 spin_lock(&sched_lock);
595 /* If the core is already prov to someone else, take it away. (last write
596 * wins, some other layer or new func can handle permissions). */
597 if (spc->prov_proc) {
598 /* the list the spc is on depends on whether it is alloced to the
599 * prov_proc or not */
600 prov_list = (spc->alloc_proc == spc->prov_proc ?
601 &spc->prov_proc->ksched_data.prov_alloc_me :
602 &spc->prov_proc->ksched_data.prov_not_alloc_me);
603 TAILQ_REMOVE(prov_list, spc, next);
605 /* Now prov it to p. Again, the list it goes on depends on whether it is
606 * alloced to p or not. Callers can also send in 0 to de-provision. */
608 if (spc->alloc_proc == p) {
609 TAILQ_INSERT_TAIL(&p->ksched_data.prov_alloc_me, spc, next);
611 /* this is be the victim list, which can be sorted so that we pick
612 * the right victim (sort by alloc_proc reverse priority, etc). */
613 TAILQ_INSERT_TAIL(&p->ksched_data.prov_not_alloc_me, spc, next);
617 spin_unlock(&sched_lock);
620 /************** Debugging **************/
621 void sched_diag(void)
624 spin_lock(&sched_lock);
625 TAILQ_FOREACH(p, &runnable_scps, ksched_data.proc_link)
626 printk("Runnable _S PID: %d\n", p->pid);
627 TAILQ_FOREACH(p, &unrunnable_scps, ksched_data.proc_link)
628 printk("Unrunnable _S PID: %d\n", p->pid);
629 TAILQ_FOREACH(p, &all_mcps, ksched_data.proc_link)
630 printk("MCP PID: %d\n", p->pid);
631 spin_unlock(&sched_lock);
635 void print_idlecoremap(void)
637 printk("There are %d idle cores.\n", num_idlecores);
638 for (int i = 0; i < num_idlecores; i++)
639 printk("idlecoremap[%d] = %d\n", i, idlecoremap[i]);
642 void print_resources(struct proc *p)
644 printk("--------------------\n");
645 printk("PID: %d\n", p->pid);
646 printk("--------------------\n");
647 for (int i = 0; i < MAX_NUM_RESOURCES; i++)
648 printk("Res type: %02d, amt wanted: %08d, amt granted: %08d\n", i,
649 p->procdata->res_req[i].amt_wanted, p->procinfo->res_grant[i]);
652 void print_all_resources(void)
655 void __print_resources(void *item)
657 print_resources((struct proc*)item);
659 spin_lock(&pid_hash_lock);
660 hash_for_each(pid_hash, __print_resources);
661 spin_unlock(&pid_hash_lock);
664 void print_prov_map(void)
666 struct sched_pcore *spc_i;
667 /* Doing this unlocked, which is dangerous, but won't deadlock */
668 printk("Which cores are provisioned to which procs:\n------------------\n");
669 for (int i = 0; i < num_cpus; i++) {
670 spc_i = &all_pcores[i];
671 printk("Core %02d, prov: %08p(%d) alloc: %08p(%d)\n", i,
672 spc_i->prov_proc, spc_i->prov_proc ? spc_i->prov_proc->pid :0,
673 spc_i->alloc_proc, spc_i->alloc_proc ? spc_i->alloc_proc->pid:0);
677 void print_proc_prov(struct proc *p)
679 struct sched_pcore *spc_i;
682 printk("Prov cores alloced to proc %08p (%d)\n----------\n", p, p->pid);
683 TAILQ_FOREACH(spc_i, &p->ksched_data.prov_alloc_me, next)
684 printk("Pcore %d\n", schedpcore2pcoreid(spc_i));
685 printk("Prov cores not alloced to proc %08p (%d)\n----------\n", p, p->pid);
686 TAILQ_FOREACH(spc_i, &p->ksched_data.prov_not_alloc_me, next)
687 printk("Pcore %d (alloced to %08p (%d))\n", schedpcore2pcoreid(spc_i),
688 spc_i->alloc_proc, spc_i->alloc_proc ? spc_i->alloc_proc->pid:0);