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 /* TAILQ of all unallocated, idle (CG) cores */
34 struct sched_pcore_tailq idlecores = TAILQ_HEAD_INITIALIZER(idlecores);
36 /* Helper, defined below */
37 static void __core_request(struct proc *p);
38 static void __put_idle_cores(struct proc *p, uint32_t *pc_arr, uint32_t num);
39 static void add_to_list(struct proc *p, struct proc_list *list);
40 static void remove_from_list(struct proc *p, struct proc_list *list);
41 static void switch_lists(struct proc *p, struct proc_list *old,
42 struct proc_list *new);
43 static uint32_t spc2pcoreid(struct sched_pcore *spc);
44 static struct sched_pcore *pcoreid2spc(uint32_t pcoreid);
45 static bool is_ll_core(uint32_t pcoreid);
46 static void __prov_track_alloc(struct proc *p, uint32_t pcoreid);
47 static void __prov_track_dealloc(struct proc *p, uint32_t pcoreid);
48 static void __prov_track_dealloc_bulk(struct proc *p, uint32_t *pc_arr,
51 /* Alarm struct, for our example 'timer tick' */
52 struct alarm_waiter ksched_waiter;
54 #define TIMER_TICK_USEC 10000 /* 10msec */
56 /* Helper: Sets up a timer tick on the calling core to go off 10 msec from now.
57 * This assumes the calling core is an LL core, etc. */
58 static void set_ksched_alarm(void)
60 set_awaiter_rel(&ksched_waiter, TIMER_TICK_USEC);
61 set_alarm(&per_cpu_info[core_id()].tchain, &ksched_waiter);
64 /* Kmsg, to run the scheduler tick (not in interrupt context) and reset the
65 * alarm. Note that interrupts will be disabled, but this is not the same as
66 * interrupt context. We're a routine kmsg, which means the core is in a
68 static void __ksched_tick(struct trapframe *tf, uint32_t srcid, long a0,
71 /* TODO: imagine doing some accounting here */
73 /* Set our alarm to go off, incrementing from our last tick (instead of
74 * setting it relative to now, since some time has passed since the alarm
75 * first went off. Note, this may be now or in the past! */
76 set_awaiter_inc(&ksched_waiter, TIMER_TICK_USEC);
77 set_alarm(&per_cpu_info[core_id()].tchain, &ksched_waiter);
80 /* Interrupt/alarm handler: tells our core to run the scheduler (out of
81 * interrupt context). */
82 static void __kalarm(struct alarm_waiter *waiter)
84 send_kernel_message(core_id(), __ksched_tick, 0, 0, 0, KMSG_ROUTINE);
87 void schedule_init(void)
89 spin_lock(&sched_lock);
90 /* init provisioning stuff */
91 all_pcores = kmalloc(sizeof(struct sched_pcore) * num_cpus, 0);
92 memset(all_pcores, 0, sizeof(struct sched_pcore) * num_cpus);
93 assert(!core_id()); /* want the alarm on core0 for now */
94 init_awaiter(&ksched_waiter, __kalarm);
96 /* init the idlecore list. if they turned off hyperthreading, give them the
97 * odds from 1..max-1. otherwise, give them everything by 0 (default mgmt
98 * core). TODO: (CG/LL) better LL/CG mgmt */
99 #ifndef __CONFIG_DISABLE_SMT__
100 for (int i = 1; i < num_cpus; i++)
101 TAILQ_INSERT_TAIL(&idlecores, pcoreid2spc(i), alloc_next);
103 assert(!(num_cpus % 2));
104 for (int i = 1; i < num_cpus; i += 2)
105 TAILQ_INSERT_TAIL(&idlecores, pcoreid2spc(i), alloc_next);
106 #endif /* __CONFIG_DISABLE_SMT__ */
107 #ifdef __CONFIG_ARSC_SERVER__
108 struct sched_pcore *a_core = TAILQ_FIRST(&idlecores);
110 TAILQ_REMOVE(&idlecores, a_core, alloc_next);
111 send_kernel_message(spc2pcoreid(a_core), (amr_t)arsc_server, 0, 0, 0,
113 warn("Using core %d for the ARSCs - there are probably issues with this.",
114 spc2pcoreid(a_core));
115 #endif /* __CONFIG_ARSC_SERVER__ */
116 spin_unlock(&sched_lock);
120 /* Round-robins on whatever list it's on */
121 static void add_to_list(struct proc *p, struct proc_list *new)
123 TAILQ_INSERT_TAIL(new, p, ksched_data.proc_link);
124 p->ksched_data.cur_list = new;
127 static void remove_from_list(struct proc *p, struct proc_list *old)
129 assert(p->ksched_data.cur_list == old);
130 TAILQ_REMOVE(old, p, ksched_data.proc_link);
133 static void switch_lists(struct proc *p, struct proc_list *old,
134 struct proc_list *new)
136 remove_from_list(p, old);
140 static void __remove_from_any_list(struct proc *p)
142 if (p->ksched_data.cur_list)
143 TAILQ_REMOVE(p->ksched_data.cur_list, p, ksched_data.proc_link);
146 /* Removes from whatever list p is on */
147 static void remove_from_any_list(struct proc *p)
149 assert(p->ksched_data.cur_list);
150 TAILQ_REMOVE(p->ksched_data.cur_list, p, ksched_data.proc_link);
153 void register_proc(struct proc *p)
155 /* one ref for the proc's existence, cradle-to-grave */
156 proc_incref(p, 1); /* need at least this OR the 'one for existing' */
157 spin_lock(&sched_lock);
158 TAILQ_INIT(&p->ksched_data.prov_alloc_me);
159 TAILQ_INIT(&p->ksched_data.prov_not_alloc_me);
160 add_to_list(p, &unrunnable_scps);
161 spin_unlock(&sched_lock);
164 /* Returns 0 if it succeeded, an error code otherwise. */
165 int proc_change_to_m(struct proc *p)
168 spin_lock(&sched_lock);
169 /* Should only be necessary to lock around the change_to_m call. It's
170 * definitely necessary to hold the sched lock the whole time - need to
171 * atomically change the proc's state and have the ksched take action (and
172 * not squeeze a proc_destroy in there or something). */
173 spin_lock(&p->proc_lock);
174 retval = __proc_change_to_m(p);
175 spin_unlock(&p->proc_lock);
177 /* Failed for some reason. */
178 spin_unlock(&sched_lock);
181 /* Catch user bugs */
182 if (!p->procdata->res_req[RES_CORES].amt_wanted) {
183 printk("[kernel] process needs to specify amt_wanted\n");
184 p->procdata->res_req[RES_CORES].amt_wanted = 1;
186 /* For now, this should only ever be called on an unrunnable. It's
187 * probably a bug, at this stage in development, to do o/w. */
188 remove_from_list(p, &unrunnable_scps);
189 //remove_from_any_list(p); /* ^^ instead of this */
190 add_to_list(p, &all_mcps);
191 spin_unlock(&sched_lock);
192 //poke_ksched(p, RES_CORES);
196 /* Makes sure p is runnable. Callers may spam this, so it needs to handle
197 * repeated calls for the same event. Callers include event delivery, SCP
198 * yield, and new SCPs. Most every scheduler should do something like this -
199 * grab whatever lock you have, then call the proc helper. */
200 void proc_wakeup(struct proc *p)
202 spin_lock(&sched_lock);
203 /* will trigger one of the __sched_.cp_wakeup()s */
205 spin_unlock(&sched_lock);
208 static uint32_t spc2pcoreid(struct sched_pcore *spc)
210 return spc - all_pcores;
213 static struct sched_pcore *pcoreid2spc(uint32_t pcoreid)
215 return &all_pcores[pcoreid];
218 /* Helper for proc destroy: unprovisions any pcores for the given list */
219 static void unprov_pcore_list(struct sched_pcore_tailq *list_head)
221 struct sched_pcore *spc_i;
222 /* We can leave them connected within the tailq, since the scps don't have a
223 * default list (if they aren't on a proc's list, then we don't care about
224 * them), and since the INSERTs don't care what list you were on before
225 * (chummy with the implementation). Pretty sure this is right. If there's
226 * suspected list corruption, be safer here. */
227 TAILQ_FOREACH(spc_i, list_head, prov_next)
228 spc_i->prov_proc = 0;
229 TAILQ_INIT(list_head);
232 /* Destroys the given process. This may be called from another process, a light
233 * kernel thread (no real process context), asynchronously/cross-core, or from
234 * the process on its own core.
236 * An external, edible ref is passed in. when we return and they decref,
237 * __proc_free will be called */
238 void proc_destroy(struct proc *p)
240 uint32_t nr_cores_revoked = 0;
241 spin_lock(&sched_lock);
242 spin_lock(&p->proc_lock);
243 /* storage for pc_arr is alloced at decl, which is after grabbing the lock*/
244 uint32_t pc_arr[p->procinfo->num_vcores];
245 /* If this returns true, it means we successfully destroyed the proc */
246 if (__proc_destroy(p, pc_arr, &nr_cores_revoked)) {
247 /* Do our cleanup. note that proc_free won't run since we have an
248 * external reference, passed in */
249 /* Unprovision any cores. Note this is different than track_dealloc.
250 * The latter does bookkeeping when an allocation changes. This is a
251 * bulk *provisioning* change. */
252 unprov_pcore_list(&p->ksched_data.prov_alloc_me);
253 unprov_pcore_list(&p->ksched_data.prov_not_alloc_me);
254 /* Remove from whatever list we are on */
255 remove_from_any_list(p);
256 /* Drop the cradle-to-the-grave reference, jet-li */
258 if (nr_cores_revoked) {
259 __put_idle_cores(p, pc_arr, nr_cores_revoked);
260 __prov_track_dealloc_bulk(p, pc_arr, nr_cores_revoked);
263 spin_unlock(&p->proc_lock);
264 spin_unlock(&sched_lock);
267 /* mgmt/LL cores should call this to schedule the calling core and give it to an
268 * SCP. will also prune the dead SCPs from the list. hold the lock before
269 * calling. returns TRUE if it scheduled a proc. */
270 static bool __schedule_scp(void)
273 uint32_t pcoreid = core_id();
274 struct per_cpu_info *pcpui = &per_cpu_info[pcoreid];
276 /* if there are any runnables, run them here and put any currently running
277 * SCP on the tail of the runnable queue. */
278 if ((p = TAILQ_FIRST(&runnable_scps))) {
279 /* protect owning proc, cur_tf, etc. note this nests with the
280 * calls in proc_yield_s */
281 disable_irqsave(&state);
282 /* someone is currently running, dequeue them */
283 if (pcpui->owning_proc) {
284 printd("Descheduled %d in favor of %d\n", pcpui->owning_proc->pid,
286 /* locking just to be safe */
287 spin_lock(&p->proc_lock);
288 __proc_set_state(pcpui->owning_proc, PROC_RUNNABLE_S);
289 __proc_save_context_s(pcpui->owning_proc, pcpui->cur_tf);
290 spin_unlock(&p->proc_lock);
291 /* round-robin the SCPs (inserts at the end of the queue) */
292 switch_lists(pcpui->owning_proc, &unrunnable_scps, &runnable_scps);
293 clear_owning_proc(pcoreid);
294 /* Note we abandon core. It's not strictly necessary. If
295 * we didn't, the TLB would still be loaded with the old
296 * one, til we proc_run_s, and the various paths in
297 * proc_run_s would pick it up. This way is a bit safer for
298 * future changes, but has an extra (empty) TLB flush. */
301 /* Run the new proc */
302 switch_lists(p, &runnable_scps, &unrunnable_scps);
303 printd("PID of the SCP i'm running: %d\n", p->pid);
304 proc_run_s(p); /* gives it core we're running on */
305 enable_irqsave(&state);
311 /* Something has changed, and for whatever reason the scheduler should
314 * Don't call this from interrupt context (grabs proclocks). */
317 struct proc *p, *temp;
318 spin_lock(&sched_lock);
319 /* trivially try to handle the needs of all our MCPS. smarter schedulers
320 * would do something other than FCFS */
321 TAILQ_FOREACH_SAFE(p, &all_mcps, ksched_data.proc_link, temp) {
322 printd("Ksched has MCP %08p (%d)\n", p, p->pid);
323 if (TAILQ_EMPTY(&idlecores))
325 /* TODO: might use amt_wanted as a proxy. right now, they have
326 * amt_wanted == 1, even though they are waiting.
327 * TODO: this is RACY too - just like with DYING. */
328 if (p->state == PROC_WAITING)
332 if (management_core())
334 spin_unlock(&sched_lock);
337 /* A process is asking the ksched to look at its resource desires. The
338 * scheduler is free to ignore this, for its own reasons, so long as it
339 * eventually gets around to looking at resource desires. */
340 void poke_ksched(struct proc *p, int res_type)
342 /* TODO: probably want something to trigger all res_types */
343 spin_lock(&sched_lock);
346 /* ignore core requests from non-mcps (note we have races if we ever
347 * allow procs to switch back). */
348 if (!__proc_is_mcp(p))
355 spin_unlock(&sched_lock);
358 /* ksched callbacks. p just woke up, is unlocked, and the ksched lock is held */
359 void __sched_mcp_wakeup(struct proc *p)
361 /* the essence of poke_ksched for RES_CORES */
365 /* ksched callbacks. p just woke up, is unlocked, and the ksched lock is held */
366 void __sched_scp_wakeup(struct proc *p)
368 /* might not be on a list if it is new. o/w, it should be unrunnable */
369 __remove_from_any_list(p);
370 add_to_list(p, &runnable_scps);
373 /* The calling cpu/core has nothing to do and plans to idle/halt. This is an
374 * opportunity to pick the nature of that halting (low power state, etc), or
375 * provide some other work (_Ss on LL cores). Note that interrupts are
376 * disabled, and if you return, the core will cpu_halt(). */
379 bool new_proc = FALSE;
380 if (!management_core())
382 spin_lock(&sched_lock);
383 new_proc = __schedule_scp();
384 spin_unlock(&sched_lock);
385 /* if we just scheduled a proc, we need to manually restart it, instead of
386 * returning. if we return, the core will halt. */
391 /* Could drop into the monitor if there are no processes at all. For now,
392 * the 'call of the giraffe' suffices. */
395 /* Externally called function to return a core to the ksched, which tracks it as
396 * idle and deallocated from p.
398 * This also is a trigger, telling us we have more cores. We could/should make
399 * a scheduling decision (or at least plan to). */
400 void put_idle_core(struct proc *p, uint32_t coreid)
402 spin_lock(&sched_lock);
403 TAILQ_INSERT_TAIL(&idlecores, pcoreid2spc(coreid), alloc_next);
404 __prov_track_dealloc(p, coreid);
405 spin_unlock(&sched_lock);
408 /* Helper for put_idle and core_req. Note this does not all track_dealloc */
409 static void __put_idle_cores(struct proc *p, uint32_t *pc_arr, uint32_t num)
411 for (int i = 0; i < num; i++)
412 TAILQ_INSERT_TAIL(&idlecores, pcoreid2spc(pc_arr[i]), alloc_next);
415 /* External interface for put_idle. Note this one also calls track_dealloc,
416 * which the internal version does not. */
417 void put_idle_cores(struct proc *p, uint32_t *pc_arr, uint32_t num)
419 spin_lock(&sched_lock);
420 __put_idle_cores(p, pc_arr, num);
421 __prov_track_dealloc_bulk(p, pc_arr, num);
422 spin_unlock(&sched_lock);
423 /* could trigger a sched decision here */
426 /* Available resources changed (plus or minus). Some parts of the kernel may
427 * call this if a particular resource that is 'quantity-based' changes. Things
428 * like available RAM to processes, bandwidth, etc. Cores would probably be
429 * inappropriate, since we need to know which specific core is now free. */
430 void avail_res_changed(int res_type, long change)
432 printk("[kernel] ksched doesn't track any resources yet!\n");
435 /* Normally it'll be the max number of CG cores ever */
436 uint32_t max_vcores(struct proc *p)
439 #ifdef __CONFIG_DISABLE_SMT__
440 return num_cpus >> 1;
442 return num_cpus - 1; /* reserving core 0 */
443 #endif /* __CONFIG_DISABLE_SMT__ */
446 /* Ghetto helper, just hands out up to 'amt_new' cores (no sense of locality or
448 static uint32_t __get_idle_cores(struct proc *p, uint32_t *pc_arr,
451 struct sched_pcore *spc_i;
452 uint32_t nr_granted = 0;
453 for (/* init above */; nr_granted < amt_new; nr_granted++) {
454 spc_i = TAILQ_FIRST(&idlecores);
457 TAILQ_REMOVE(&idlecores, spc_i, alloc_next);
458 pc_arr[nr_granted] = spc2pcoreid(spc_i);
463 /* This deals with a request for more cores. The request is already stored in
464 * the proc's amt_wanted (it is compared to amt_granted). */
465 static void __core_request(struct proc *p)
467 uint32_t num_granted, amt_wanted, amt_granted;
468 uint32_t corelist[num_cpus];
470 /* TODO: consider copy-in for amt_wanted too. */
471 amt_wanted = p->procdata->res_req[RES_CORES].amt_wanted;
472 amt_granted = p->procinfo->res_grant[RES_CORES];
474 /* Help them out - if they ask for something impossible, give them 1 so they
475 * can make some progress. (this is racy). */
476 if (amt_wanted > p->procinfo->max_vcores) {
477 p->procdata->res_req[RES_CORES].amt_wanted = 1;
479 /* if they are satisfied, we're done. There's a slight chance they have
480 * cores, but they aren't running (sched gave them cores while they were
481 * yielding, and now we see them on the run queue). */
482 if (amt_wanted <= amt_granted)
484 /* Otherwise, see what they want, and try to give out as many as possible.
485 * Current models are simple - it's just a raw number of cores, and we just
486 * give out what we can. */
487 num_granted = __get_idle_cores(p, corelist, amt_wanted - amt_granted);
488 /* Now, actually give them out */
490 /* give them the cores. this will start up the extras if RUNNING_M. */
491 spin_lock(&p->proc_lock);
492 /* if they fail, it is because they are WAITING or DYING. we could give
493 * the cores to another proc or whatever. for the current type of
494 * ksched, we'll just put them back on the pile and return. Note, the
495 * ksched could check the states after locking, but it isn't necessary:
496 * just need to check at some point in the ksched loop. */
497 if (__proc_give_cores(p, corelist, num_granted)) {
498 __put_idle_cores(p, corelist, num_granted);
500 /* track the (successful) allocation of the sched_pcores */
501 for (int i = 0; i < num_granted; i++)
502 __prov_track_alloc(p, corelist[i]);
503 /* at some point after giving cores, call proc_run_m() (harmless on
504 * RUNNING_Ms). You can give small groups of cores, then run them
505 * (which is more efficient than interleaving runs with the gives
506 * for bulk preempted processes). */
509 spin_unlock(&p->proc_lock);
513 /* TODO: need more thorough CG/LL management. For now, core0 is the only LL
514 * core. This won't play well with the ghetto shit in schedule_init() if you do
515 * anything like 'DEDICATED_MONITOR' or the ARSC server. All that needs an
517 static bool is_ll_core(uint32_t pcoreid)
524 /* Helper, makes sure the prov/alloc structures track the pcore properly when it
525 * is allocated to p. Might make this take a sched_pcore * in the future. */
526 static void __prov_track_alloc(struct proc *p, uint32_t pcoreid)
528 struct sched_pcore *spc;
529 assert(pcoreid < num_cpus); /* catch bugs */
530 spc = pcoreid2spc(pcoreid);
531 assert(spc->alloc_proc != p); /* corruption or double-alloc */
533 /* if the pcore is prov to them and now allocated, move lists */
534 if (spc->prov_proc == p) {
535 TAILQ_REMOVE(&p->ksched_data.prov_not_alloc_me, spc, prov_next);
536 TAILQ_INSERT_TAIL(&p->ksched_data.prov_alloc_me, spc, prov_next);
540 /* Helper, makes sure the prov/alloc structures track the pcore properly when it
541 * is deallocated from p. */
542 static void __prov_track_dealloc(struct proc *p, uint32_t pcoreid)
544 struct sched_pcore *spc;
545 assert(pcoreid < num_cpus); /* catch bugs */
546 spc = pcoreid2spc(pcoreid);
548 /* if the pcore is prov to them and now deallocated, move lists */
549 if (spc->prov_proc == p) {
550 TAILQ_REMOVE(&p->ksched_data.prov_alloc_me, spc, prov_next);
551 /* this is the victim list, which can be sorted so that we pick the
552 * right victim (sort by alloc_proc reverse priority, etc). In this
553 * case, the core isn't alloc'd by anyone, so it should be the first
555 TAILQ_INSERT_HEAD(&p->ksched_data.prov_not_alloc_me, spc, prov_next);
559 /* Bulk interface for __prov_track_dealloc */
560 static void __prov_track_dealloc_bulk(struct proc *p, uint32_t *pc_arr,
563 for (int i = 0; i < nr_cores; i++)
564 __prov_track_dealloc(p, pc_arr[i]);
567 /* P will get pcore if it needs more cores next time we look at it */
568 void provision_core(struct proc *p, uint32_t pcoreid)
570 struct sched_pcore *spc;
571 struct sched_pcore_tailq *prov_list;
572 /* Make sure we aren't asking for something that doesn't exist (bounds check
573 * on the pcore array) */
574 if (!(pcoreid < num_cpus))
575 return; /* could do an error code */
576 /* Don't allow the provisioning of LL cores */
577 if (is_ll_core(pcoreid))
579 spc = pcoreid2spc(pcoreid);
580 /* Note the sched lock protects the spc tailqs for all procs in this code.
581 * If we need a finer grained sched lock, this is one place where we could
582 * have a different lock */
583 spin_lock(&sched_lock);
584 /* If the core is already prov to someone else, take it away. (last write
585 * wins, some other layer or new func can handle permissions). */
586 if (spc->prov_proc) {
587 /* the list the spc is on depends on whether it is alloced to the
588 * prov_proc or not */
589 prov_list = (spc->alloc_proc == spc->prov_proc ?
590 &spc->prov_proc->ksched_data.prov_alloc_me :
591 &spc->prov_proc->ksched_data.prov_not_alloc_me);
592 TAILQ_REMOVE(prov_list, spc, prov_next);
594 /* Now prov it to p. Again, the list it goes on depends on whether it is
595 * alloced to p or not. Callers can also send in 0 to de-provision. */
597 if (spc->alloc_proc == p) {
598 TAILQ_INSERT_TAIL(&p->ksched_data.prov_alloc_me, spc, prov_next);
600 /* this is be the victim list, which can be sorted so that we pick
601 * the right victim (sort by alloc_proc reverse priority, etc). */
602 TAILQ_INSERT_TAIL(&p->ksched_data.prov_not_alloc_me, spc,
607 spin_unlock(&sched_lock);
610 /************** Debugging **************/
611 void sched_diag(void)
614 spin_lock(&sched_lock);
615 TAILQ_FOREACH(p, &runnable_scps, ksched_data.proc_link)
616 printk("Runnable _S PID: %d\n", p->pid);
617 TAILQ_FOREACH(p, &unrunnable_scps, ksched_data.proc_link)
618 printk("Unrunnable _S PID: %d\n", p->pid);
619 TAILQ_FOREACH(p, &all_mcps, ksched_data.proc_link)
620 printk("MCP PID: %d\n", p->pid);
621 spin_unlock(&sched_lock);
625 void print_idlecoremap(void)
627 struct sched_pcore *spc_i;
628 /* not locking, so we can look at this without deadlocking. */
629 printk("Idle cores (unlocked!):\n");
630 TAILQ_FOREACH(spc_i, &idlecores, alloc_next)
631 printk("Core %d, prov to %d (%08p)\n", spc2pcoreid(spc_i),
632 spc_i->prov_proc ? spc_i->prov_proc->pid : 0, spc_i->prov_proc);
635 void print_resources(struct proc *p)
637 printk("--------------------\n");
638 printk("PID: %d\n", p->pid);
639 printk("--------------------\n");
640 for (int i = 0; i < MAX_NUM_RESOURCES; i++)
641 printk("Res type: %02d, amt wanted: %08d, amt granted: %08d\n", i,
642 p->procdata->res_req[i].amt_wanted, p->procinfo->res_grant[i]);
645 void print_all_resources(void)
648 void __print_resources(void *item)
650 print_resources((struct proc*)item);
652 spin_lock(&pid_hash_lock);
653 hash_for_each(pid_hash, __print_resources);
654 spin_unlock(&pid_hash_lock);
657 void print_prov_map(void)
659 struct sched_pcore *spc_i;
660 /* Doing this unlocked, which is dangerous, but won't deadlock */
661 printk("Which cores are provisioned to which procs:\n------------------\n");
662 for (int i = 0; i < num_cpus; i++) {
663 spc_i = pcoreid2spc(i);
664 printk("Core %02d, prov: %d(%08p) alloc: %d(%08p)\n", i,
665 spc_i->prov_proc ? spc_i->prov_proc->pid : 0, spc_i->prov_proc,
666 spc_i->alloc_proc ? spc_i->alloc_proc->pid : 0,
671 void print_proc_prov(struct proc *p)
673 struct sched_pcore *spc_i;
676 printk("Prov cores alloced to proc %d (%08p)\n----------\n", p->pid, p);
677 TAILQ_FOREACH(spc_i, &p->ksched_data.prov_alloc_me, prov_next)
678 printk("Pcore %d\n", spc2pcoreid(spc_i));
679 printk("Prov cores not alloced to proc %d (%08p)\n----------\n", p->pid, p);
680 TAILQ_FOREACH(spc_i, &p->ksched_data.prov_not_alloc_me, prov_next)
681 printk("Pcore %d (alloced to %d (%08p))\n", spc2pcoreid(spc_i),
682 spc_i->alloc_proc ? spc_i->alloc_proc->pid : 0,