debuggers.hg

view xen/include/xen/sched.h @ 3740:d3e70af90f15

bitkeeper revision 1.1159.212.115 (4207c574hv18R_VTm-3a9w_AZzNBWw)

Force hypercall continuation arguments to size of longs.
Signed-off-by: keir.fraser@cl.cam.ac.uk
author kaf24@scramble.cl.cam.ac.uk
date Mon Feb 07 19:45:56 2005 +0000 (2005-02-07)
parents 253e8e10e986
children f5f2757b3aa2
line source
1 /* -*- Mode:C; c-basic-offset:4; tab-width:4; indent-tabs-mode:nil -*- */
3 #ifndef __SCHED_H__
4 #define __SCHED_H__
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 <asm/hardirq.h>
25 #include <asm/domain.h>
27 extern unsigned long volatile jiffies;
28 extern rwlock_t domlist_lock;
30 /* A global pointer to the initial domain (DOM0). */
31 extern struct domain *dom0;
33 typedef struct event_channel_st
34 {
35 #define ECS_FREE 0 /* Channel is available for use. */
36 #define ECS_RESERVED 1 /* Channel is reserved. */
37 #define ECS_UNBOUND 2 /* Channel is waiting to bind to a remote domain. */
38 #define ECS_INTERDOMAIN 3 /* Channel is bound to another domain. */
39 #define ECS_PIRQ 4 /* Channel is bound to a physical IRQ line. */
40 #define ECS_VIRQ 5 /* Channel is bound to a virtual IRQ line. */
41 #define ECS_IPI 6 /* Channel is bound to a virtual IPI line. */
42 u16 state;
43 union {
44 struct {
45 domid_t remote_domid;
46 } __attribute__ ((packed)) unbound; /* state == ECS_UNBOUND */
47 struct {
48 u16 remote_port;
49 struct exec_domain *remote_dom;
50 } __attribute__ ((packed)) interdomain; /* state == ECS_INTERDOMAIN */
51 u16 pirq; /* state == ECS_PIRQ */
52 u16 virq; /* state == ECS_VIRQ */
53 u32 ipi_edom; /* state == ECS_IPI */
54 } u;
55 } event_channel_t;
57 int init_event_channels(struct domain *d);
58 void destroy_event_channels(struct domain *d);
59 int init_exec_domain_event_channels(struct exec_domain *ed);
61 struct exec_domain
62 {
63 u32 processor;
65 vcpu_info_t *vcpu_info;
67 struct domain *domain;
68 struct exec_domain *ed_next_list;
69 int eid;
71 #ifdef ARCH_HAS_EXEC_DOMAIN_MM_PTR
72 struct mm_struct *mm;
73 #endif
75 struct ac_timer timer; /* one-shot timer for timeout values */
77 s_time_t lastschd; /* time this domain was last scheduled */
78 s_time_t lastdeschd; /* time this domain was last descheduled */
79 s_time_t cpu_time; /* total CPU time received till now */
80 s_time_t wokenup; /* time domain got woken up */
81 void *ed_sched_priv; /* scheduler-specific data */
83 unsigned long ed_flags;
85 u16 virq_to_evtchn[NR_VIRQS];
87 atomic_t pausecnt;
89 struct arch_exec_domain arch;
90 };
92 /*
93 ** SMH: do_mmu_update() grabs big_lock and subsequently can fault
94 ** on map_ldt_shadow_page(), enter do_page_fault() and then deadlock
95 ** trying to reacquire big_lock. A temporary fix is to make big_lock
96 ** recursive; overall probably needs more thought.
97 */
98 #if 0
99 #define LOCK_BIGLOCK(_d) spin_lock(&(_d)->big_lock)
100 #define UNLOCK_BIGLOCK(_d) spin_unlock(&(_d)->big_lock)
101 #else
102 #define LOCK_BIGLOCK(_d) spin_lock_recursive(&(_d)->big_lock)
103 #define UNLOCK_BIGLOCK(_d) spin_unlock_recursive(&(_d)->big_lock)
104 #endif
106 struct domain
107 {
108 domid_t id;
109 s_time_t create_time;
111 shared_info_t *shared_info; /* shared data area */
112 spinlock_t time_lock;
114 spinlock_t big_lock;
116 spinlock_t page_alloc_lock; /* protects all the following fields */
117 struct list_head page_list; /* linked list, of size tot_pages */
118 struct list_head xenpage_list; /* linked list, of size xenheap_pages */
119 unsigned int tot_pages; /* number of pages currently possesed */
120 unsigned int max_pages; /* maximum value for tot_pages */
121 unsigned int xenheap_pages; /* # pages allocated from Xen heap */
123 /* Scheduling. */
124 int shutdown_code; /* code value from OS (if DF_SHUTDOWN). */
125 void *sched_priv; /* scheduler-specific data */
127 struct domain *next_list, *next_hash;
129 /* Event channel information. */
130 event_channel_t *event_channel;
131 unsigned int max_event_channel;
132 spinlock_t event_channel_lock;
134 grant_table_t *grant_table;
136 /*
137 * Interrupt to event-channel mappings. Updates should be protected by the
138 * domain's event-channel spinlock. Read accesses can also synchronise on
139 * the lock, but races don't usually matter.
140 */
141 #define NR_PIRQS 128 /* Put this somewhere sane! */
142 u16 pirq_to_evtchn[NR_PIRQS];
143 u32 pirq_mask[NR_PIRQS/32];
145 /* Physical I/O */
146 spinlock_t pcidev_lock;
147 struct list_head pcidev_list;
149 unsigned long d_flags;
150 unsigned long vm_assist;
152 atomic_t refcnt;
154 struct exec_domain *exec_domain[MAX_VIRT_CPUS];
156 struct arch_domain arch;
157 };
159 struct domain_setup_info
160 {
161 unsigned long v_start;
162 unsigned long v_kernstart;
163 unsigned long v_kernend;
164 unsigned long v_kernentry;
166 unsigned int use_writable_pagetables;
167 };
169 #include <asm/uaccess.h> /* for KERNEL_DS */
171 extern struct domain idle0_domain;
172 extern struct exec_domain idle0_exec_domain;
174 extern struct exec_domain *idle_task[NR_CPUS];
175 #define IDLE_DOMAIN_ID (0x7FFFU)
176 #define is_idle_task(_p) (test_bit(DF_IDLETASK, &(_p)->d_flags))
178 struct exec_domain *alloc_exec_domain_struct(struct domain *d,
179 unsigned long vcpu);
181 void free_domain_struct(struct domain *d);
182 struct domain *alloc_domain_struct();
184 #define DOMAIN_DESTRUCTED (1<<31) /* assumes atomic_t is >= 32 bits */
185 #define put_domain(_d) \
186 if ( atomic_dec_and_test(&(_d)->refcnt) ) domain_destruct(_d)
188 /*
189 * Use this when you don't have an existing reference to @d. It returns
190 * FALSE if @d is being destructed.
191 */
192 static always_inline int get_domain(struct domain *d)
193 {
194 atomic_t old, new, seen = d->refcnt;
195 do
196 {
197 old = seen;
198 if ( unlikely(_atomic_read(old) & DOMAIN_DESTRUCTED) )
199 return 0;
200 _atomic_set(new, _atomic_read(old) + 1);
201 seen = atomic_compareandswap(old, new, &d->refcnt);
202 }
203 while ( unlikely(_atomic_read(seen) != _atomic_read(old)) );
204 return 1;
205 }
207 /*
208 * Use this when you already have, or are borrowing, a reference to @d.
209 * In this case we know that @d cannot be destructed under our feet.
210 */
211 static inline void get_knownalive_domain(struct domain *d)
212 {
213 atomic_inc(&d->refcnt);
214 ASSERT(!(atomic_read(&d->refcnt) & DOMAIN_DESTRUCTED));
215 }
217 extern struct domain *do_createdomain(
218 domid_t dom_id, unsigned int cpu);
219 extern int construct_dom0(struct domain *d,
220 unsigned long alloc_start,
221 unsigned long alloc_end,
222 unsigned long image_start, unsigned long image_len,
223 unsigned long initrd_start, unsigned long initrd_len,
224 char *cmdline);
225 extern int final_setup_guestos(struct domain *d, dom0_builddomain_t *);
227 struct domain *find_domain_by_id(domid_t dom);
228 struct domain *find_last_domain(void);
229 extern void domain_destruct(struct domain *d);
230 extern void domain_kill(struct domain *d);
231 extern void domain_crash(void);
232 extern void domain_shutdown(u8 reason);
234 void new_thread(struct exec_domain *d,
235 unsigned long start_pc,
236 unsigned long start_stack,
237 unsigned long start_info);
239 extern unsigned long wait_init_idle;
240 #define init_idle() clear_bit(smp_processor_id(), &wait_init_idle);
242 #define set_current_state(_s) do { current->state = (_s); } while (0)
243 void scheduler_init(void);
244 void schedulers_start(void);
245 void sched_add_domain(struct exec_domain *);
246 void sched_rem_domain(struct exec_domain *);
247 long sched_ctl(struct sched_ctl_cmd *);
248 long sched_adjdom(struct sched_adjdom_cmd *);
249 int sched_id();
250 void init_idle_task(void);
251 void domain_wake(struct exec_domain *d);
252 void domain_sleep(struct exec_domain *d);
254 void __enter_scheduler(void);
256 extern void switch_to(struct exec_domain *prev,
257 struct exec_domain *next);
259 void domain_init(void);
261 int idle_cpu(int cpu); /* Is CPU 'cpu' idle right now? */
263 void startup_cpu_idle_loop(void);
265 unsigned long __hypercall_create_continuation(
266 unsigned int op, unsigned int nr_args, ...);
267 #define hypercall0_create_continuation(_op) \
268 __hypercall_create_continuation((_op), 0)
269 #define hypercall1_create_continuation(_op, _a1) \
270 __hypercall_create_continuation((_op), 1, \
271 (unsigned long)(_a1))
272 #define hypercall2_create_continuation(_op, _a1, _a2) \
273 __hypercall_create_continuation((_op), 2, \
274 (unsigned long)(_a1), (unsigned long)(_a2))
275 #define hypercall3_create_continuation(_op, _a1, _a2, _a3) \
276 __hypercall_create_continuation((_op), 3, \
277 (unsigned long)(_a1), (unsigned long)(_a2), (unsigned long)(_a3))
278 #define hypercall4_create_continuation(_op, _a1, _a2, _a3, _a4) \
279 __hypercall_create_continuation((_op), 4, \
280 (unsigned long)(_a1), (unsigned long)(_a2), (unsigned long)(_a3), \
281 (unsigned long)(_a4))
282 #define hypercall5_create_continuation(_op, _a1, _a2, _a3, _a4, _a5) \
283 __hypercall_create_continuation((_op), 5, \
284 (unsigned long)(_a1), (unsigned long)(_a2), (unsigned long)(_a3), \
285 (unsigned long)(_a4), (unsigned long)(_a5))
286 #define hypercall6_create_continuation(_op, _a1, _a2, _a3, _a4, _a5, _a6) \
287 __hypercall_create_continuation((_op), 6, \
288 (unsigned long)(_a1), (unsigned long)(_a2), (unsigned long)(_a3), \
289 (unsigned long)(_a4), (unsigned long)(_a5), (unsigned long)(_a6))
291 #define hypercall_preempt_check() \
292 (unlikely(softirq_pending(smp_processor_id())))
294 /* This domain_hash and domain_list are protected by the domlist_lock. */
295 #define DOMAIN_HASH_SIZE 256
296 #define DOMAIN_HASH(_id) ((int)(_id)&(DOMAIN_HASH_SIZE-1))
297 extern struct domain *domain_hash[DOMAIN_HASH_SIZE];
298 extern struct domain *domain_list;
300 #define for_each_domain(_p) \
301 for ( (_p) = domain_list; (_p) != NULL; (_p) = (_p)->next_list )
303 #define for_each_exec_domain(_d,_ed) \
304 for ( (_ed) = _d->exec_domain[0]; (_ed) != NULL; (_ed) = (_ed)->ed_next_list )
306 #define EDF_DONEFPUINIT 0 /* Has the FPU been initialised for this task? */
307 #define EDF_USEDFPU 1 /* Has this task used the FPU since last save? */
308 #define EDF_GUEST_STTS 2 /* Has the guest OS requested 'stts'? */
309 #define DF_CONSTRUCTED 3 /* Has the guest OS been fully built yet? */
310 #define DF_IDLETASK 4 /* Is this one of the per-CPU idle domains? */
311 #define DF_PRIVILEGED 5 /* Is this domain privileged? */
312 #define DF_PHYSDEV 6 /* May this domain do IO to physical devices? */
313 #define EDF_BLOCKED 7 /* Domain is blocked waiting for an event. */
314 #define EDF_CTRLPAUSE 8 /* Domain is paused by controller software. */
315 #define DF_SHUTDOWN 9 /* Guest shut itself down for some reason. */
316 #define DF_CRASHED 10 /* Domain crashed inside Xen, cannot continue. */
317 #define DF_DYING 11 /* Death rattle. */
318 #define EDF_RUNNING 12 /* Currently running on a CPU. */
319 #define EDF_CPUPINNED 13 /* Disables auto-migration. */
320 #define EDF_MIGRATED 14 /* Domain migrated between CPUs. */
322 static inline int domain_runnable(struct exec_domain *d)
323 {
324 return ( (atomic_read(&d->pausecnt) == 0) &&
325 !(d->ed_flags & ((1<<EDF_BLOCKED)|(1<<EDF_CTRLPAUSE))) &&
326 !(d->domain->d_flags & ((1<<DF_SHUTDOWN)|(1<<DF_CRASHED))) );
327 }
329 static inline void exec_domain_pause(struct exec_domain *ed)
330 {
331 ASSERT(ed != current);
332 atomic_inc(&ed->pausecnt);
333 domain_sleep(ed);
334 }
336 static inline void domain_pause(struct domain *d)
337 {
338 struct exec_domain *ed;
340 for_each_exec_domain(d, ed)
341 exec_domain_pause(ed);
342 }
344 static inline void exec_domain_unpause(struct exec_domain *ed)
345 {
346 ASSERT(ed != current);
347 if ( atomic_dec_and_test(&ed->pausecnt) )
348 domain_wake(ed);
349 }
351 static inline void domain_unpause(struct domain *d)
352 {
353 struct exec_domain *ed;
355 for_each_exec_domain(d, ed)
356 exec_domain_unpause(ed);
357 }
359 static inline void exec_domain_unblock(struct exec_domain *ed)
360 {
361 if ( test_and_clear_bit(EDF_BLOCKED, &ed->ed_flags) )
362 domain_wake(ed);
363 }
365 static inline void domain_unblock(struct domain *d)
366 {
367 struct exec_domain *ed;
369 for_each_exec_domain(d, ed)
370 exec_domain_unblock(ed);
371 }
373 static inline void domain_pause_by_systemcontroller(struct domain *d)
374 {
375 struct exec_domain *ed;
377 for_each_exec_domain(d, ed) {
378 ASSERT(ed != current);
379 if ( !test_and_set_bit(EDF_CTRLPAUSE, &ed->ed_flags) )
380 domain_sleep(ed);
381 }
382 }
384 static inline void domain_unpause_by_systemcontroller(struct domain *d)
385 {
386 struct exec_domain *ed;
388 for_each_exec_domain(d, ed) {
389 if ( test_and_clear_bit(EDF_CTRLPAUSE, &ed->ed_flags) )
390 domain_wake(ed);
391 }
392 }
395 #define IS_PRIV(_d) (test_bit(DF_PRIVILEGED, &(_d)->d_flags))
396 #define IS_CAPABLE_PHYSDEV(_d) (test_bit(DF_PHYSDEV, &(_d)->d_flags))
398 #define VM_ASSIST(_d,_t) (test_bit((_t), &(_d)->vm_assist))
400 #include <xen/slab.h>
401 #include <xen/domain.h>
404 #endif /* __SCHED_H__ */