2 * Copyright (c) 2009 The Regents of the University of California
3 * Barret Rhoden <brho@cs.berkeley.edu>
4 * See LICENSE for details.
6 * Scheduling and dispatching.
11 #include <ros/common.h>
12 #include <sys/queue.h>
14 struct proc; /* process.h includes us, but we need pointers now */
15 TAILQ_HEAD(proc_list, proc); /* Declares 'struct proc_list' */
17 /* The ksched maintains an internal array of these: the global pcore map. Note
18 * the prov_proc and alloc_proc are weak (internal) references, and should only
19 * be used as a ref source while the ksched has a valid kref. */
21 TAILQ_ENTRY(sched_pcore) prov_next; /* on a proc's prov list */
22 TAILQ_ENTRY(sched_pcore) alloc_next; /* on an alloc list (idle)*/
23 struct proc *prov_proc; /* who this is prov to */
24 struct proc *alloc_proc; /* who this is alloc to */
26 TAILQ_HEAD(sched_pcore_tailq, sched_pcore);
28 /* One of these embedded in every struct proc */
29 struct sched_proc_data {
30 TAILQ_ENTRY(proc) proc_link; /* tailq linkage */
31 struct proc_list *cur_list; /* which tailq we're on */
32 struct sched_pcore_tailq prov_alloc_me; /* prov cores alloced us */
33 struct sched_pcore_tailq prov_not_alloc_me; /* maybe alloc to others */
35 /* other accounting info */
38 void schedule_init(void);
40 /************** Process Management Callbacks **************/
41 /* Tell the ksched about the process, which it will track cradle-to-grave */
42 void __sched_proc_register(struct proc *p);
44 /* The proc was an SCP and is becoming an MCP */
45 void __sched_proc_change_to_m(struct proc *p);
47 /* The proc is dying */
48 void __sched_proc_destroy(struct proc *p, uint32_t *pc_arr, uint32_t nr_cores);
50 /* Makes sure p is runnable. */
51 void __sched_mcp_wakeup(struct proc *p);
52 void __sched_scp_wakeup(struct proc *p);
54 /* Gets called when a pcore becomes idle (like in proc yield). These are 'cg'
55 * cores, given to MCPs, that have been async returned to the ksched. */
56 void __sched_put_idle_core(struct proc *p, uint32_t coreid);
57 void __sched_put_idle_cores(struct proc *p, uint32_t *pc_arr, uint32_t num);
59 /************** Decision making **************/
60 /* Call the main scheduling algorithm. Not clear yet if the main kernel will
61 * ever call this directly. */
62 void run_scheduler(void);
64 /* Proc p's resource desires changed, or something in general that would lead to
65 * a new decision. The process can directly poke the ksched via a syscall, so
66 * be careful of abuse. */
67 void poke_ksched(struct proc *p, unsigned int res_type);
69 /* The calling cpu/core has nothing to do and plans to idle/halt. This is an
70 * opportunity to pick the nature of that halting (low power state, etc), or
71 * provide some other work (_Ss on LL cores). */
74 /* Available resources changed (plus or minus). Some parts of the kernel may
75 * call this if a particular resource that is 'quantity-based' changes. Things
76 * like available RAM to processes, bandwidth, etc. Cores would probably be
77 * inappropriate, since we need to know which specific core is now free. */
78 void avail_res_changed(int res_type, long change);
80 /* Get and put idle CG cores. Getting a core removes it from the idle list, and
81 * the kernel can do whatever it wants with it. All this means is that the
82 * ksched won't hand out that core to a process. This will not give out
85 * The gets return the coreid on success, -1 or -error on failure. */
86 int get_any_idle_core(void);
87 int get_specific_idle_core(int coreid);
88 void put_idle_core(int coreid);
90 /************** Proc's view of the world **************/
91 /* How many vcores p will think it can have */
92 uint32_t max_vcores(struct proc *p);
94 /************** Provisioning / Allocating *************/
95 /* This section is specific to a provisioning ksched. Careful calling any of
96 * this from generic kernel code, since it might not be present in all kernel
98 int provision_core(struct proc *p, uint32_t pcoreid);
100 /************** Debugging **************/
101 void sched_diag(void);
102 void print_idlecoremap(void);
103 void print_resources(struct proc *p);
104 void print_all_resources(void);
105 void print_prov_map(void);
106 void next_core(uint32_t pcoreid);
107 void sort_idles(void);