debuggers.hg

view xen/include/xen/sched.h @ 3337:cd90fe329149

bitkeeper revision 1.1159.206.1 (41c1bb28OOf2b0kzcmnY96TsE1LXVA)

Merge arcadians.cl.cam.ac.uk:/auto/groups/xeno/BK/xen-unstable.bk
into arcadians.cl.cam.ac.uk:/auto/groups/xeno/users/cl349/BK/xen-unstable.bk
author cl349@arcadians.cl.cam.ac.uk
date Thu Dec 16 16:43:20 2004 +0000 (2004-12-16)
parents b9ab4345fd1b 53a0cc27ab17
children 3609a4de4be5
line source
1 #ifndef __SCHED_H__
2 #define __SCHED_H__
4 #define STACK_SIZE (2*PAGE_SIZE)
6 #include <xen/config.h>
7 #include <xen/types.h>
8 #include <xen/spinlock.h>
9 #include <xen/cache.h>
10 #include <asm/regs.h>
11 #include <xen/smp.h>
12 #include <asm/page.h>
13 #include <asm/processor.h>
14 #include <public/xen.h>
15 #include <public/dom0_ops.h>
16 #include <xen/list.h>
17 #include <xen/time.h>
18 #include <xen/ac_timer.h>
19 #include <xen/delay.h>
20 #include <asm/atomic.h>
21 #include <asm/current.h>
22 #include <xen/spinlock.h>
23 #include <xen/grant_table.h>
24 #include <xen/irq_cpustat.h>
26 extern unsigned long volatile jiffies;
27 extern rwlock_t domlist_lock;
29 /* A global pointer to the initial domain (DOM0). */
30 extern struct domain *dom0;
32 typedef struct event_channel_st
33 {
34 #define ECS_FREE 0 /* Channel is available for use. */
35 #define ECS_RESERVED 1 /* Channel is reserved. */
36 #define ECS_UNBOUND 2 /* Channel is waiting to bind to a remote domain. */
37 #define ECS_INTERDOMAIN 3 /* Channel is bound to another domain. */
38 #define ECS_PIRQ 4 /* Channel is bound to a physical IRQ line. */
39 #define ECS_VIRQ 5 /* Channel is bound to a virtual IRQ line. */
40 #define ECS_IPI 6 /* Channel is bound to a virtual IPI line. */
41 u16 state;
42 union {
43 struct {
44 domid_t remote_domid;
45 } __attribute__ ((packed)) unbound; /* state == ECS_UNBOUND */
46 struct {
47 u16 remote_port;
48 struct exec_domain *remote_dom;
49 } __attribute__ ((packed)) interdomain; /* state == ECS_INTERDOMAIN */
50 u16 pirq; /* state == ECS_PIRQ */
51 u16 virq; /* state == ECS_VIRQ */
52 u32 ipi_edom; /* state == ECS_IPI */
53 } u;
54 } event_channel_t;
56 int init_event_channels(struct domain *d);
57 void destroy_event_channels(struct domain *d);
58 int init_exec_domain_event_channels(struct exec_domain *ed);
60 struct exec_domain
61 {
62 u32 processor;
64 vcpu_info_t *vcpu_info;
66 struct domain *domain;
67 struct exec_domain *ed_next_list;
68 int eid;
70 struct mm_struct mm;
72 struct thread_struct thread;
74 struct ac_timer timer; /* one-shot timer for timeout values */
76 s_time_t lastschd; /* time this domain was last scheduled */
77 s_time_t lastdeschd; /* time this domain was last descheduled */
78 s_time_t cpu_time; /* total CPU time received till now */
79 s_time_t wokenup; /* time domain got woken up */
80 void *ed_sched_priv; /* scheduler-specific data */
82 unsigned long ed_flags;
84 u16 virq_to_evtchn[NR_VIRQS];
86 atomic_t pausecnt;
88 };
90 #if 01
91 #define LOCK_BIGLOCK(_d) spin_lock(&(_d)->big_lock)
92 #define UNLOCK_BIGLOCK(_d) spin_unlock(&(_d)->big_lock)
93 #else
94 #define LOCK_BIGLOCK(_d) (void)(_d)
95 #define UNLOCK_BIGLOCK(_d)
96 #endif
98 struct domain {
99 domid_t id;
100 s_time_t create_time;
102 shared_info_t *shared_info; /* shared data area */
103 spinlock_t time_lock;
105 spinlock_t big_lock;
107 l1_pgentry_t *mm_perdomain_pt;
109 spinlock_t page_alloc_lock; /* protects all the following fields */
110 struct list_head page_list; /* linked list, of size tot_pages */
111 struct list_head xenpage_list; /* linked list, of size xenheap_pages */
112 unsigned int tot_pages; /* number of pages currently possesed */
113 unsigned int max_pages; /* maximum value for tot_pages */
114 unsigned int xenheap_pages; /* # pages allocated from Xen heap */
116 /* Scheduling. */
117 int shutdown_code; /* code value from OS (if DF_SHUTDOWN). */
118 void *sched_priv; /* scheduler-specific data */
120 struct domain *next_list, *next_hash;
122 /* Event channel information. */
123 event_channel_t *event_channel;
124 unsigned int max_event_channel;
125 spinlock_t event_channel_lock;
127 grant_table_t *grant_table;
129 /*
130 * Interrupt to event-channel mappings. Updates should be protected by the
131 * domain's event-channel spinlock. Read accesses can also synchronise on
132 * the lock, but races don't usually matter.
133 */
134 #define NR_PIRQS 128 /* Put this somewhere sane! */
135 u16 pirq_to_evtchn[NR_PIRQS];
136 u32 pirq_mask[NR_PIRQS/32];
138 /* Physical I/O */
139 spinlock_t pcidev_lock;
140 struct list_head pcidev_list;
142 unsigned long d_flags;
143 unsigned long vm_assist;
145 atomic_t refcnt;
147 struct exec_domain *exec_domain[MAX_VIRT_CPUS];
148 };
150 struct domain_setup_info
151 {
152 unsigned long v_start;
153 unsigned long v_kernstart;
154 unsigned long v_kernend;
155 unsigned long v_kernentry;
157 unsigned int use_writable_pagetables;
158 };
160 #include <asm/uaccess.h> /* for KERNEL_DS */
162 extern struct domain idle0_domain;
163 extern struct exec_domain idle0_exec_domain;
165 extern struct exec_domain *idle_task[NR_CPUS];
166 #define IDLE_DOMAIN_ID (0x7FFFU)
167 #define is_idle_task(_p) (test_bit(DF_IDLETASK, &(_p)->d_flags))
169 struct exec_domain *alloc_exec_domain_struct(struct domain *d,
170 unsigned long vcpu);
172 void free_domain_struct(struct domain *d);
173 struct domain *alloc_domain_struct();
175 #define DOMAIN_DESTRUCTED (1<<31) /* assumes atomic_t is >= 32 bits */
176 #define put_domain(_d) \
177 if ( atomic_dec_and_test(&(_d)->refcnt) ) domain_destruct(_d)
179 /*
180 * Use this when you don't have an existing reference to @d. It returns
181 * FALSE if @d is being destructed.
182 */
183 static always_inline int get_domain(struct domain *d)
184 {
185 atomic_t old, new, seen = d->refcnt;
186 do
187 {
188 old = seen;
189 if ( unlikely(_atomic_read(old) & DOMAIN_DESTRUCTED) )
190 return 0;
191 _atomic_set(new, _atomic_read(old) + 1);
192 seen = atomic_compareandswap(old, new, &d->refcnt);
193 }
194 while ( unlikely(_atomic_read(seen) != _atomic_read(old)) );
195 return 1;
196 }
198 /*
199 * Use this when you already have, or are borrowing, a reference to @d.
200 * In this case we know that @d cannot be destructed under our feet.
201 */
202 static inline void get_knownalive_domain(struct domain *d)
203 {
204 atomic_inc(&d->refcnt);
205 ASSERT(!(atomic_read(&d->refcnt) & DOMAIN_DESTRUCTED));
206 }
208 extern struct domain *do_createdomain(
209 domid_t dom_id, unsigned int cpu);
210 extern int construct_dom0(struct domain *d,
211 unsigned long alloc_start,
212 unsigned long alloc_end,
213 char *image_start, unsigned long image_len,
214 char *initrd_start, unsigned long initrd_len,
215 char *cmdline);
216 extern int final_setup_guestos(struct domain *d, dom0_builddomain_t *);
218 struct domain *find_domain_by_id(domid_t dom);
219 struct domain *find_last_domain(void);
220 extern void domain_destruct(struct domain *d);
221 extern void domain_kill(struct domain *d);
222 extern void domain_crash(void);
223 extern void domain_shutdown(u8 reason);
225 void new_thread(struct exec_domain *d,
226 unsigned long start_pc,
227 unsigned long start_stack,
228 unsigned long start_info);
230 extern unsigned long wait_init_idle;
231 #define init_idle() clear_bit(smp_processor_id(), &wait_init_idle);
233 #define set_current_state(_s) do { current->state = (_s); } while (0)
234 void scheduler_init(void);
235 void schedulers_start(void);
236 void sched_add_domain(struct exec_domain *);
237 void sched_rem_domain(struct exec_domain *);
238 long sched_ctl(struct sched_ctl_cmd *);
239 long sched_adjdom(struct sched_adjdom_cmd *);
240 int sched_id();
241 void init_idle_task(void);
242 void domain_wake(struct exec_domain *d);
243 void domain_sleep(struct exec_domain *d);
245 void __enter_scheduler(void);
247 extern void switch_to(struct exec_domain *prev,
248 struct exec_domain *next);
250 void domain_init(void);
252 int idle_cpu(int cpu); /* Is CPU 'cpu' idle right now? */
254 void startup_cpu_idle_loop(void);
256 unsigned long hypercall_create_continuation(
257 unsigned int op, unsigned int nr_args, ...);
258 #define hypercall_preempt_check() \
259 (unlikely(softirq_pending(smp_processor_id())))
261 /* This domain_hash and domain_list are protected by the domlist_lock. */
262 #define DOMAIN_HASH_SIZE 256
263 #define DOMAIN_HASH(_id) ((int)(_id)&(DOMAIN_HASH_SIZE-1))
264 extern struct domain *domain_hash[DOMAIN_HASH_SIZE];
265 extern struct domain *domain_list;
267 #define for_each_domain(_p) \
268 for ( (_p) = domain_list; (_p) != NULL; (_p) = (_p)->next_list )
270 #define for_each_exec_domain(_d,_ed) \
271 for ( (_ed) = _d->exec_domain[0]; (_ed) != NULL; (_ed) = (_ed)->ed_next_list )
273 #define EDF_DONEFPUINIT 0 /* Has the FPU been initialised for this task? */
274 #define EDF_USEDFPU 1 /* Has this task used the FPU since last save? */
275 #define EDF_GUEST_STTS 2 /* Has the guest OS requested 'stts'? */
276 #define DF_CONSTRUCTED 3 /* Has the guest OS been fully built yet? */
277 #define DF_IDLETASK 4 /* Is this one of the per-CPU idle domains? */
278 #define DF_PRIVILEGED 5 /* Is this domain privileged? */
279 #define DF_PHYSDEV 6 /* May this domain do IO to physical devices? */
280 #define EDF_BLOCKED 7 /* Domain is blocked waiting for an event. */
281 #define EDF_CTRLPAUSE 8 /* Domain is paused by controller software. */
282 #define DF_SHUTDOWN 9 /* Guest shut itself down for some reason. */
283 #define DF_CRASHED 10 /* Domain crashed inside Xen, cannot continue. */
284 #define DF_DYING 11 /* Death rattle. */
285 #define EDF_RUNNING 12 /* Currently running on a CPU. */
286 #define EDF_CPUPINNED 13 /* Disables auto-migration. */
287 #define EDF_MIGRATED 14 /* Domain migrated between CPUs. */
289 static inline int domain_runnable(struct exec_domain *d)
290 {
291 return ( (atomic_read(&d->pausecnt) == 0) &&
292 !(d->ed_flags & ((1<<EDF_BLOCKED)|(1<<EDF_CTRLPAUSE))) &&
293 !(d->domain->d_flags & ((1<<DF_SHUTDOWN)|(1<<DF_CRASHED))) );
294 }
296 static inline void exec_domain_pause(struct exec_domain *ed)
297 {
298 ASSERT(ed != current);
299 atomic_inc(&ed->pausecnt);
300 domain_sleep(ed);
301 }
303 static inline void domain_pause(struct domain *d)
304 {
305 struct exec_domain *ed;
307 for_each_exec_domain(d, ed)
308 exec_domain_pause(ed);
309 }
311 static inline void exec_domain_unpause(struct exec_domain *ed)
312 {
313 ASSERT(ed != current);
314 if ( atomic_dec_and_test(&ed->pausecnt) )
315 domain_wake(ed);
316 }
318 static inline void domain_unpause(struct domain *d)
319 {
320 struct exec_domain *ed;
322 for_each_exec_domain(d, ed)
323 exec_domain_unpause(ed);
324 }
326 static inline void exec_domain_unblock(struct exec_domain *ed)
327 {
328 if ( test_and_clear_bit(EDF_BLOCKED, &ed->ed_flags) )
329 domain_wake(ed);
330 }
332 static inline void domain_unblock(struct domain *d)
333 {
334 struct exec_domain *ed;
336 for_each_exec_domain(d, ed)
337 exec_domain_unblock(ed);
338 }
340 static inline void domain_pause_by_systemcontroller(struct domain *d)
341 {
342 struct exec_domain *ed;
344 for_each_exec_domain(d, ed) {
345 ASSERT(ed != current);
346 if ( !test_and_set_bit(EDF_CTRLPAUSE, &ed->ed_flags) )
347 domain_sleep(ed);
348 }
349 }
351 static inline void domain_unpause_by_systemcontroller(struct domain *d)
352 {
353 struct exec_domain *ed;
355 for_each_exec_domain(d, ed) {
356 if ( test_and_clear_bit(EDF_CTRLPAUSE, &ed->ed_flags) )
357 domain_wake(ed);
358 }
359 }
362 #define IS_PRIV(_d) (test_bit(DF_PRIVILEGED, &(_d)->d_flags))
363 #define IS_CAPABLE_PHYSDEV(_d) (test_bit(DF_PHYSDEV, &(_d)->d_flags))
365 #define VM_ASSIST(_d,_t) (test_bit((_t), &(_d)->vm_assist))
367 #include <xen/slab.h>
368 #include <xen/domain.h>
370 #endif /* __SCHED_H__ */