ia64/xen-unstable

view xen/include/xen/sched.h @ 1578:710d42e7a3e1

bitkeeper revision 1.1011.1.7 (40db40f7VWpVjGztOosX5QLsvvOLlQ)

Merge scramble.cl.cam.ac.uk:/auto/groups/xeno/BK/xeno.bk
into scramble.cl.cam.ac.uk:/local/scratch/kaf24/xeno
author kaf24@scramble.cl.cam.ac.uk
date Thu Jun 24 21:00:39 2004 +0000 (2004-06-24)
parents 9078dae95f8b fc877db2ee49
children e87e1ca75a41
line source
1 #ifndef __SCHED_H__
2 #define __SCHED_H__
4 #include <xen/config.h>
5 #include <xen/types.h>
6 #include <xen/spinlock.h>
7 #include <asm/ptrace.h>
8 #include <xen/smp.h>
9 #include <asm/page.h>
10 #include <asm/processor.h>
11 #include <hypervisor-ifs/hypervisor-if.h>
12 #include <hypervisor-ifs/dom0_ops.h>
14 #include <xen/list.h>
15 #include <xen/time.h>
16 #include <xen/ac_timer.h>
17 #include <xen/delay.h>
19 #define STACK_SIZE (2*PAGE_SIZE)
20 #include <asm/current.h>
22 #define MAX_DOMAIN_NAME 16
24 extern unsigned long volatile jiffies;
25 extern rwlock_t tasklist_lock;
27 #include <xen/spinlock.h>
29 struct domain;
31 typedef struct event_channel_st
32 {
33 #define ECS_FREE 0 /* Channel is available for use. */
34 #define ECS_UNBOUND 1 /* Channel is not bound to a particular source. */
35 #define ECS_INTERDOMAIN 2 /* Channel is bound to another domain. */
36 #define ECS_PIRQ 3 /* Channel is bound to a physical IRQ line. */
37 #define ECS_VIRQ 4 /* Channel is bound to a virtual IRQ line. */
38 u16 state;
39 union {
40 struct {
41 u16 port;
42 struct domain *dom;
43 } __attribute__ ((packed)) remote; /* state == ECS_CONNECTED */
44 u16 pirq; /* state == ECS_PIRQ */
45 u16 virq; /* state == ECS_VIRQ */
46 } u;
47 } event_channel_t;
49 int init_event_channels(struct domain *d);
50 void destroy_event_channels(struct domain *d);
52 struct domain
53 {
54 /*
55 * DO NOT CHANGE THE ORDER OF THE FOLLOWING.
56 * Their offsets are hardcoded in entry.S
57 */
59 u32 processor; /* 00: current processor */
61 /* An unsafe pointer into a shared data area. */
62 shared_info_t *shared_info; /* 04: shared data area */
64 /*
65 * Return vectors pushed to us by guest OS.
66 * The stack frame for events is exactly that of an x86 hardware interrupt.
67 * The stack frame for a failsafe callback is augmented with saved values
68 * for segment registers %ds, %es, %fs and %gs:
69 * %ds, %es, %fs, %gs, %eip, %cs, %eflags [, %oldesp, %oldss]
70 */
71 unsigned long event_selector; /* 08: entry CS */
72 unsigned long event_address; /* 12: entry EIP */
74 /* Saved DS,ES,FS,GS immediately before return to guest OS. */
75 unsigned long failsafe_selectors[4]; /* 16-32 */
77 /*
78 * END OF FIRST CACHELINE. Stuff above is touched a lot!
79 */
81 unsigned long failsafe_selector; /* 32: entry CS */
82 unsigned long failsafe_address; /* 36: entry EIP */
84 /*
85 * From here on things can be added and shuffled without special attention
86 */
88 domid_t domain;
89 char name[MAX_DOMAIN_NAME];
90 s_time_t create_time;
92 spinlock_t page_list_lock;
93 struct list_head page_list;
94 unsigned int tot_pages; /* number of pages currently possesed */
95 unsigned int max_pages; /* max number of pages that can be possesed */
97 /* Scheduling. */
98 struct list_head run_list;
99 int shutdown_code; /* code value from OS (if DF_SHUTDOWN). */
100 s_time_t lastschd; /* time this domain was last scheduled */
101 s_time_t lastdeschd; /* time this domain was last descheduled */
102 s_time_t cpu_time; /* total CPU time received till now */
103 s_time_t wokenup; /* time domain got woken up */
104 struct ac_timer timer; /* one-shot timer for timeout values */
105 s_time_t min_slice; /* minimum time before reschedule */
106 void *sched_priv; /* scheduler-specific data */
108 struct mm_struct mm;
110 mm_segment_t addr_limit;
112 struct thread_struct thread;
113 struct domain *next_list, *next_hash;
115 /* Event channel information. */
116 event_channel_t *event_channel;
117 unsigned int max_event_channel;
118 spinlock_t event_channel_lock;
120 /*
121 * Interrupt to event-channel mappings. Updates should be protected by the
122 * domain's event-channel spinlock. Read accesses can also synchronise on
123 * the lock, but races don't usually matter.
124 */
125 #define NR_PIRQS 128 /* Put this somewhere sane! */
126 u16 pirq_to_evtchn[NR_PIRQS];
127 u16 virq_to_evtchn[NR_VIRQS];
128 u32 pirq_mask[NR_PIRQS/32];
130 /* Physical I/O */
131 spinlock_t pcidev_lock;
132 struct list_head pcidev_list;
134 /* The following IO bitmap stuff is x86-dependent. */
135 u64 io_bitmap_sel; /* Selector to tell us which part of the IO bitmap are
136 * "interesting" (i.e. have clear bits) */
138 /* Handy macro - number of bytes of the IO bitmap, per selector bit. */
139 #define IOBMP_SELBIT_LWORDS ( IO_BITMAP_SIZE / 64 )
140 unsigned long *io_bitmap; /* Pointer to task's IO bitmap or NULL */
142 unsigned long flags;
144 atomic_t refcnt;
145 atomic_t pausecnt;
146 };
148 #include <asm/uaccess.h> /* for KERNEL_DS */
150 #define IDLE0_TASK(_t) \
151 { \
152 processor: 0, \
153 domain: IDLE_DOMAIN_ID, \
154 mm: IDLE0_MM, \
155 addr_limit: KERNEL_DS, \
156 thread: INIT_THREAD, \
157 flags: 1<<DF_IDLETASK, \
158 refcnt: ATOMIC_INIT(1) \
159 }
161 extern struct domain idle0_task;
163 extern struct domain *idle_task[NR_CPUS];
164 #define IDLE_DOMAIN_ID (0x7FFFFFFFU)
165 #define is_idle_task(_p) (test_bit(DF_IDLETASK, &(_p)->flags))
167 #include <xen/slab.h>
169 void free_domain_struct(struct domain *d);
170 struct domain *alloc_domain_struct();
172 #define DOMAIN_DESTRUCTED (1<<31) /* assumes atomic_t is >= 32 bits */
173 #define put_domain(_d) \
174 if ( atomic_dec_and_test(&(_d)->refcnt) ) domain_destruct(_d)
175 static inline int get_domain(struct domain *d)
176 {
177 atomic_inc(&d->refcnt);
178 return !(atomic_read(&d->refcnt) & DOMAIN_DESTRUCTED);
179 }
181 extern struct domain *do_createdomain(
182 domid_t dom_id, unsigned int cpu);
183 extern int construct_dom0(struct domain *d,
184 unsigned long alloc_start,
185 unsigned long alloc_end,
186 char *image_start, unsigned long image_len,
187 char *initrd_start, unsigned long initrd_len,
188 char *cmdline);
189 extern int final_setup_guestos(struct domain *d, dom0_builddomain_t *);
191 struct domain *find_domain_by_id(domid_t dom);
192 struct domain *find_last_domain(void);
193 extern void domain_destruct(struct domain *d);
194 extern void domain_kill(struct domain *d);
195 extern void domain_crash(void);
196 extern void domain_shutdown(u8 reason);
197 extern void domain_relinquish_memory(struct domain *d);
199 void new_thread(struct domain *d,
200 unsigned long start_pc,
201 unsigned long start_stack,
202 unsigned long start_info);
204 extern unsigned long wait_init_idle;
205 #define init_idle() clear_bit(smp_processor_id(), &wait_init_idle);
207 extern spinlock_t schedule_lock[NR_CPUS] __cacheline_aligned;
209 #define set_current_state(_s) do { current->state = (_s); } while (0)
210 void scheduler_init(void);
211 void schedulers_start(void);
212 void sched_add_domain(struct domain *d);
213 void sched_rem_domain(struct domain *d);
214 long sched_ctl(struct sched_ctl_cmd *);
215 long sched_adjdom(struct sched_adjdom_cmd *);
216 int sched_id();
217 void init_idle_task(void);
218 void domain_wake(struct domain *d);
219 void domain_sleep(struct domain *d);
221 void __enter_scheduler(void);
223 extern void switch_to(struct domain *prev,
224 struct domain *next);
226 void domain_init(void);
228 int idle_cpu(int cpu); /* Is CPU 'cpu' idle right now? */
230 void startup_cpu_idle_loop(void);
231 void continue_cpu_idle_loop(void);
233 void continue_nonidle_task(void);
235 /* This task_hash and task_list are protected by the tasklist_lock. */
236 #define TASK_HASH_SIZE 256
237 #define TASK_HASH(_id) ((int)(_id)&(TASK_HASH_SIZE-1))
238 extern struct domain *task_hash[TASK_HASH_SIZE];
239 extern struct domain *task_list;
241 #define for_each_domain(_p) \
242 for ( (_p) = task_list; (_p) != NULL; (_p) = (_p)->next_list )
244 #define DF_DONEFPUINIT 0 /* Has the FPU been initialised for this task? */
245 #define DF_USEDFPU 1 /* Has this task used the FPU since last save? */
246 #define DF_GUEST_STTS 2 /* Has the guest OS requested 'stts'? */
247 #define DF_CONSTRUCTED 3 /* Has the guest OS been fully built yet? */
248 #define DF_IDLETASK 4 /* Is this one of the per-CPU idle domains? */
249 #define DF_PRIVILEGED 5 /* Is this domain privileged? */
250 #define DF_PHYSDEV 6 /* May this domain do IO to physical devices? */
251 #define DF_BLOCKED 7 /* Domain is blocked waiting for an event. */
252 #define DF_CTRLPAUSE 8 /* Domain is paused by controller software. */
253 #define DF_SHUTDOWN 9 /* Guest shut itself down for some reason. */
254 #define DF_CRASHED 10 /* Domain crashed inside Xen, cannot continue. */
255 #define DF_DYING 11 /* Death rattle. */
256 #define DF_RUNNING 12 /* Currently running on a CPU. */
257 #define DF_CPUPINNED 13 /* Disables auto-migration. */
259 static inline int domain_runnable(struct domain *d)
260 {
261 return ( (atomic_read(&d->pausecnt) == 0) &&
262 !(d->flags & ((1<<DF_BLOCKED)|(1<<DF_CTRLPAUSE)|
263 (1<<DF_SHUTDOWN)|(1<<DF_CRASHED))) );
264 }
266 static inline void domain_pause(struct domain *d)
267 {
268 ASSERT(d != current);
269 atomic_inc(&d->pausecnt);
270 domain_sleep(d);
271 }
273 static inline void domain_unpause(struct domain *d)
274 {
275 ASSERT(d != current);
276 if ( atomic_dec_and_test(&d->pausecnt) )
277 domain_wake(d);
278 }
280 static inline void domain_unblock(struct domain *d)
281 {
282 if ( test_and_clear_bit(DF_BLOCKED, &d->flags) )
283 domain_wake(d);
284 }
286 static inline void domain_pause_by_systemcontroller(struct domain *d)
287 {
288 ASSERT(d != current);
289 if ( !test_and_set_bit(DF_CTRLPAUSE, &d->flags) )
290 domain_sleep(d);
291 }
293 static inline void domain_unpause_by_systemcontroller(struct domain *d)
294 {
295 if ( test_and_clear_bit(DF_CTRLPAUSE, &d->flags) )
296 domain_wake(d);
297 }
300 #define IS_PRIV(_d) (test_bit(DF_PRIVILEGED, &(_d)->flags))
301 #define IS_CAPABLE_PHYSDEV(_d) (test_bit(DF_PHYSDEV, &(_d)->flags))
303 #endif /* __SCHED_H__ */