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