ia64/xen-unstable

view xen/include/xen/sched.h @ 13608:30af6cfdb05c

Make domctl/sysctl interfaces 32-/64-bit invariant.
This kills off a fair amount of unpleasant CONFIG_COMPAT shimming and
avoids needing to keep the compat paths in sync as these interfaces
continue to develop.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Wed Jan 24 16:33:19 2007 +0000 (2007-01-24)
parents 5442b2458e1b
children 271ffb1c12eb
line source
2 #ifndef __SCHED_H__
3 #define __SCHED_H__
5 #include <xen/config.h>
6 #include <xen/types.h>
7 #include <xen/spinlock.h>
8 #include <xen/smp.h>
9 #include <xen/shared.h>
10 #include <public/xen.h>
11 #include <public/domctl.h>
12 #include <public/vcpu.h>
13 #include <xen/time.h>
14 #include <xen/timer.h>
15 #include <xen/grant_table.h>
16 #include <xen/rangeset.h>
17 #include <asm/domain.h>
18 #include <xen/xenoprof.h>
19 #include <xen/irq.h>
21 #ifdef CONFIG_COMPAT
22 #include <compat/vcpu.h>
23 DEFINE_XEN_GUEST_HANDLE(vcpu_runstate_info_compat_t);
24 #endif
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 #ifndef CONFIG_COMPAT
33 #define MAX_EVTCHNS(d) NR_EVENT_CHANNELS
34 #else
35 #define MAX_EVTCHNS(d) (!IS_COMPAT(d) ? \
36 NR_EVENT_CHANNELS : \
37 sizeof(unsigned int) * sizeof(unsigned int) * 64)
38 #endif
39 #define EVTCHNS_PER_BUCKET 128
40 #define NR_EVTCHN_BUCKETS (NR_EVENT_CHANNELS / EVTCHNS_PER_BUCKET)
42 struct evtchn
43 {
44 #define ECS_FREE 0 /* Channel is available for use. */
45 #define ECS_RESERVED 1 /* Channel is reserved. */
46 #define ECS_UNBOUND 2 /* Channel is waiting to bind to a remote domain. */
47 #define ECS_INTERDOMAIN 3 /* Channel is bound to another domain. */
48 #define ECS_PIRQ 4 /* Channel is bound to a physical IRQ line. */
49 #define ECS_VIRQ 5 /* Channel is bound to a virtual IRQ line. */
50 #define ECS_IPI 6 /* Channel is bound to a virtual IPI line. */
51 u8 state; /* ECS_* */
52 u8 consumer_is_xen; /* Consumed by Xen or by guest? */
53 u16 notify_vcpu_id; /* VCPU for local delivery notification */
54 union {
55 struct {
56 domid_t remote_domid;
57 } unbound; /* state == ECS_UNBOUND */
58 struct {
59 u16 remote_port;
60 struct domain *remote_dom;
61 } interdomain; /* state == ECS_INTERDOMAIN */
62 u16 pirq; /* state == ECS_PIRQ */
63 u16 virq; /* state == ECS_VIRQ */
64 } u;
65 };
67 int evtchn_init(struct domain *d);
68 void evtchn_destroy(struct domain *d);
70 struct vcpu
71 {
72 int vcpu_id;
74 int processor;
76 vcpu_info_t *vcpu_info;
78 struct domain *domain;
80 struct vcpu *next_in_list;
82 struct timer timer; /* one-shot timer for timeout values */
83 unsigned long sleep_tick; /* tick at which this vcpu started sleep */
85 struct timer poll_timer; /* timeout for SCHEDOP_poll */
87 void *sched_priv; /* scheduler-specific data */
89 struct vcpu_runstate_info runstate;
90 #ifndef CONFIG_COMPAT
91 # define runstate_guest(v) ((v)->runstate_guest)
92 XEN_GUEST_HANDLE(vcpu_runstate_info_t) runstate_guest; /* guest address */
93 #else
94 # define runstate_guest(v) ((v)->runstate_guest.native)
95 union {
96 XEN_GUEST_HANDLE(vcpu_runstate_info_t) native;
97 XEN_GUEST_HANDLE(vcpu_runstate_info_compat_t) compat;
98 } runstate_guest; /* guest address */
99 #endif
101 unsigned long vcpu_flags;
103 spinlock_t pause_lock;
104 unsigned int pause_count;
106 u16 virq_to_evtchn[NR_VIRQS];
108 /* Bitmask of CPUs on which this VCPU may run. */
109 cpumask_t cpu_affinity;
111 unsigned long nmi_addr; /* NMI callback address. */
113 /* Bitmask of CPUs which are holding onto this VCPU's state. */
114 cpumask_t vcpu_dirty_cpumask;
116 struct arch_vcpu arch;
117 };
119 /* Per-domain lock can be recursively acquired in fault handlers. */
120 #define LOCK_BIGLOCK(_d) spin_lock_recursive(&(_d)->big_lock)
121 #define UNLOCK_BIGLOCK(_d) spin_unlock_recursive(&(_d)->big_lock)
123 struct domain
124 {
125 domid_t domain_id;
127 shared_info_t *shared_info; /* shared data area */
129 spinlock_t big_lock;
131 spinlock_t page_alloc_lock; /* protects all the following fields */
132 struct list_head page_list; /* linked list, of size tot_pages */
133 struct list_head xenpage_list; /* linked list, of size xenheap_pages */
134 unsigned int tot_pages; /* number of pages currently possesed */
135 unsigned int max_pages; /* maximum value for tot_pages */
136 unsigned int xenheap_pages; /* # pages allocated from Xen heap */
138 /* Scheduling. */
139 int shutdown_code; /* code value from OS (if DOMF_shutdown) */
140 void *sched_priv; /* scheduler-specific data */
142 struct domain *next_in_list;
143 struct domain *next_in_hashbucket;
145 struct list_head rangesets;
146 spinlock_t rangesets_lock;
148 /* Event channel information. */
149 struct evtchn *evtchn[NR_EVTCHN_BUCKETS];
150 spinlock_t evtchn_lock;
152 struct grant_table *grant_table;
154 /*
155 * Interrupt to event-channel mappings. Updates should be protected by the
156 * domain's event-channel spinlock. Read accesses can also synchronise on
157 * the lock, but races don't usually matter.
158 */
159 u16 pirq_to_evtchn[NR_IRQS];
160 DECLARE_BITMAP(pirq_mask, NR_IRQS);
162 /* I/O capabilities (access to IRQs and memory-mapped I/O). */
163 struct rangeset *iomem_caps;
164 struct rangeset *irq_caps;
166 unsigned long domain_flags;
168 /* Boolean: Is this an HVM guest? */
169 char is_hvm;
171 /* Boolean: Is this guest fully privileged (aka dom0)? */
172 char is_privileged;
174 spinlock_t pause_lock;
175 unsigned int pause_count;
177 unsigned long vm_assist;
179 atomic_t refcnt;
181 struct vcpu *vcpu[MAX_VIRT_CPUS];
183 /* Bitmask of CPUs which are holding onto this domain's state. */
184 cpumask_t domain_dirty_cpumask;
186 struct arch_domain arch;
188 void *ssid; /* sHype security subject identifier */
190 /* Control-plane tools handle for this domain. */
191 xen_domain_handle_t handle;
193 /* OProfile support. */
194 struct xenoprof *xenoprof;
195 int32_t time_offset_seconds;
196 };
198 struct domain_setup_info
199 {
200 /* Initialised by caller. */
201 unsigned long image_addr;
202 unsigned long image_len;
203 /* Initialised by loader: Public. */
204 unsigned long v_start;
205 unsigned long v_end;
206 unsigned long v_kernstart;
207 unsigned long v_kernend;
208 unsigned long v_kernentry;
209 #define PAEKERN_no 0
210 #define PAEKERN_yes 1
211 #define PAEKERN_extended_cr3 2
212 #define PAEKERN_bimodal 3
213 unsigned int pae_kernel;
214 /* Initialised by loader: Private. */
215 unsigned long elf_paddr_offset;
216 unsigned int load_symtab;
217 unsigned long symtab_addr;
218 unsigned long symtab_len;
219 /*
220 * Only one of __elfnote_* or __xen_guest_string will be
221 * non-NULL.
222 *
223 * You should use the xen_elfnote_* accessors below in order to
224 * pickup the correct one and retain backwards compatibility.
225 */
226 const void *__elfnote_section, *__elfnote_section_end;
227 const char *__xen_guest_string;
228 };
230 extern struct vcpu *idle_vcpu[NR_CPUS];
231 #define IDLE_DOMAIN_ID (0x7FFFU)
232 #define is_idle_domain(d) ((d)->domain_id == IDLE_DOMAIN_ID)
233 #define is_idle_vcpu(v) (is_idle_domain((v)->domain))
235 #define DOMAIN_DESTROYED (1<<31) /* assumes atomic_t is >= 32 bits */
236 #define put_domain(_d) \
237 if ( atomic_dec_and_test(&(_d)->refcnt) ) domain_destroy(_d)
239 /*
240 * Use this when you don't have an existing reference to @d. It returns
241 * FALSE if @d is being destroyed.
242 */
243 static always_inline int get_domain(struct domain *d)
244 {
245 atomic_t old, new, seen = d->refcnt;
246 do
247 {
248 old = seen;
249 if ( unlikely(_atomic_read(old) & DOMAIN_DESTROYED) )
250 return 0;
251 _atomic_set(new, _atomic_read(old) + 1);
252 seen = atomic_compareandswap(old, new, &d->refcnt);
253 }
254 while ( unlikely(_atomic_read(seen) != _atomic_read(old)) );
255 return 1;
256 }
258 /*
259 * Use this when you already have, or are borrowing, a reference to @d.
260 * In this case we know that @d cannot be destroyed under our feet.
261 */
262 static inline void get_knownalive_domain(struct domain *d)
263 {
264 atomic_inc(&d->refcnt);
265 ASSERT(!(atomic_read(&d->refcnt) & DOMAIN_DESTROYED));
266 }
268 struct domain *domain_create(domid_t domid, unsigned int domcr_flags);
269 /* DOMCRF_hvm: Create an HVM domain, as opposed to a PV domain. */
270 #define _DOMCRF_hvm 0
271 #define DOMCRF_hvm (1U<<_DOMCRF_hvm)
273 int construct_dom0(
274 struct domain *d,
275 unsigned long image_start, unsigned long image_len,
276 unsigned long initrd_start, unsigned long initrd_len,
277 char *cmdline);
279 struct domain *find_domain_by_id(domid_t dom);
280 void domain_destroy(struct domain *d);
281 void domain_kill(struct domain *d);
282 void domain_shutdown(struct domain *d, u8 reason);
283 void domain_pause_for_debugger(void);
285 /*
286 * Mark specified domain as crashed. This function always returns, even if the
287 * caller is the specified domain. The domain is not synchronously descheduled
288 * from any processor.
289 */
290 void __domain_crash(struct domain *d);
291 #define domain_crash(d) do { \
292 printk("domain_crash called from %s:%d\n", __FILE__, __LINE__); \
293 __domain_crash(d); \
294 } while (0)
296 /*
297 * Mark current domain as crashed and synchronously deschedule from the local
298 * processor. This function never returns.
299 */
300 void __domain_crash_synchronous(void) __attribute__((noreturn));
301 #define domain_crash_synchronous() do { \
302 printk("domain_crash_sync called from %s:%d\n", __FILE__, __LINE__); \
303 __domain_crash_synchronous(); \
304 } while (0)
306 #define set_current_state(_s) do { current->state = (_s); } while (0)
307 void scheduler_init(void);
308 void schedulers_start(void);
309 int sched_init_vcpu(struct vcpu *v, unsigned int processor);
310 void sched_destroy_vcpu(struct vcpu *v);
311 int sched_init_domain(struct domain *d);
312 void sched_destroy_domain(struct domain *d);
313 long sched_adjust(struct domain *, struct xen_domctl_scheduler_op *);
314 int sched_id(void);
315 void vcpu_wake(struct vcpu *d);
316 void vcpu_sleep_nosync(struct vcpu *d);
317 void vcpu_sleep_sync(struct vcpu *d);
319 /*
320 * Force synchronisation of given VCPU's state. If it is currently descheduled,
321 * this call will ensure that all its state is committed to memory and that
322 * no CPU is using critical state (e.g., page tables) belonging to the VCPU.
323 */
324 void sync_vcpu_execstate(struct vcpu *v);
326 /*
327 * Called by the scheduler to switch to another VCPU. This function must
328 * call context_saved(@prev) when the local CPU is no longer running in
329 * @prev's context, and that context is saved to memory. Alternatively, if
330 * implementing lazy context switching, it suffices to ensure that invoking
331 * sync_vcpu_execstate() will switch and commit @prev's state.
332 */
333 void context_switch(
334 struct vcpu *prev,
335 struct vcpu *next);
337 /*
338 * As described above, context_switch() must call this function when the
339 * local CPU is no longer running in @prev's context, and @prev's context is
340 * saved to memory. Alternatively, if implementing lazy context switching,
341 * ensure that invoking sync_vcpu_execstate() will switch and commit @prev.
342 */
343 void context_saved(struct vcpu *prev);
345 /* Called by the scheduler to continue running the current VCPU. */
346 void continue_running(
347 struct vcpu *same);
349 void startup_cpu_idle_loop(void);
351 /*
352 * Creates a continuation to resume the current hypercall. The caller should
353 * return immediately, propagating the value returned from this invocation.
354 * The format string specifies the types and number of hypercall arguments.
355 * It contains one character per argument as follows:
356 * 'i' [unsigned] {char, int}
357 * 'l' [unsigned] long
358 * 'h' guest handle (XEN_GUEST_HANDLE(foo))
359 */
360 unsigned long hypercall_create_continuation(
361 unsigned int op, const char *format, ...);
363 #define hypercall_preempt_check() (unlikely( \
364 softirq_pending(smp_processor_id()) | \
365 local_events_need_delivery() \
366 ))
368 /* This domain_hash and domain_list are protected by the domlist_lock. */
369 #define DOMAIN_HASH_SIZE 256
370 #define DOMAIN_HASH(_id) ((int)(_id)&(DOMAIN_HASH_SIZE-1))
371 extern struct domain *domain_hash[DOMAIN_HASH_SIZE];
372 extern struct domain *domain_list;
374 #define for_each_domain(_d) \
375 for ( (_d) = domain_list; \
376 (_d) != NULL; \
377 (_d) = (_d)->next_in_list )
379 #define for_each_vcpu(_d,_v) \
380 for ( (_v) = (_d)->vcpu[0]; \
381 (_v) != NULL; \
382 (_v) = (_v)->next_in_list )
384 /*
385 * Per-VCPU flags (vcpu_flags).
386 */
387 /* Has the FPU been initialised? */
388 #define _VCPUF_fpu_initialised 0
389 #define VCPUF_fpu_initialised (1UL<<_VCPUF_fpu_initialised)
390 /* Has the FPU been used since it was last saved? */
391 #define _VCPUF_fpu_dirtied 1
392 #define VCPUF_fpu_dirtied (1UL<<_VCPUF_fpu_dirtied)
393 /* Domain is blocked waiting for an event. */
394 #define _VCPUF_blocked 2
395 #define VCPUF_blocked (1UL<<_VCPUF_blocked)
396 /* Currently running on a CPU? */
397 #define _VCPUF_running 3
398 #define VCPUF_running (1UL<<_VCPUF_running)
399 /* Initialization completed. */
400 #define _VCPUF_initialised 4
401 #define VCPUF_initialised (1UL<<_VCPUF_initialised)
402 /* VCPU is offline. */
403 #define _VCPUF_down 5
404 #define VCPUF_down (1UL<<_VCPUF_down)
405 /* NMI callback pending for this VCPU? */
406 #define _VCPUF_nmi_pending 8
407 #define VCPUF_nmi_pending (1UL<<_VCPUF_nmi_pending)
408 /* Avoid NMI reentry by allowing NMIs to be masked for short periods. */
409 #define _VCPUF_nmi_masked 9
410 #define VCPUF_nmi_masked (1UL<<_VCPUF_nmi_masked)
411 /* VCPU is polling a set of event channels (SCHEDOP_poll). */
412 #define _VCPUF_polling 10
413 #define VCPUF_polling (1UL<<_VCPUF_polling)
414 /* VCPU is paused by the hypervisor? */
415 #define _VCPUF_paused 11
416 #define VCPUF_paused (1UL<<_VCPUF_paused)
417 /* VCPU is blocked awaiting an event to be consumed by Xen. */
418 #define _VCPUF_blocked_in_xen 12
419 #define VCPUF_blocked_in_xen (1UL<<_VCPUF_blocked_in_xen)
420 /* VCPU affinity has changed: migrating to a new CPU. */
421 #define _VCPUF_migrating 13
422 #define VCPUF_migrating (1UL<<_VCPUF_migrating)
424 /*
425 * Per-domain flags (domain_flags).
426 */
427 /* Guest shut itself down for some reason. */
428 #define _DOMF_shutdown 0
429 #define DOMF_shutdown (1UL<<_DOMF_shutdown)
430 /* Death rattle. */
431 #define _DOMF_dying 1
432 #define DOMF_dying (1UL<<_DOMF_dying)
433 /* Domain is paused by controller software. */
434 #define _DOMF_ctrl_pause 2
435 #define DOMF_ctrl_pause (1UL<<_DOMF_ctrl_pause)
436 /* Domain is being debugged by controller software. */
437 #define _DOMF_debugging 3
438 #define DOMF_debugging (1UL<<_DOMF_debugging)
439 /* Are any VCPUs polling event channels (SCHEDOP_poll)? */
440 #define _DOMF_polling 4
441 #define DOMF_polling (1UL<<_DOMF_polling)
442 /* Domain is paused by the hypervisor? */
443 #define _DOMF_paused 5
444 #define DOMF_paused (1UL<<_DOMF_paused)
445 /* Domain is a compatibility one? */
446 #define _DOMF_compat 6
447 #define DOMF_compat (1UL<<_DOMF_compat)
449 static inline int vcpu_runnable(struct vcpu *v)
450 {
451 return ( !(v->vcpu_flags &
452 ( VCPUF_blocked |
453 VCPUF_down |
454 VCPUF_paused |
455 VCPUF_blocked_in_xen |
456 VCPUF_migrating )) &&
457 !(v->domain->domain_flags &
458 ( DOMF_shutdown |
459 DOMF_ctrl_pause |
460 DOMF_paused )));
461 }
463 void vcpu_pause(struct vcpu *v);
464 void vcpu_pause_nosync(struct vcpu *v);
465 void domain_pause(struct domain *d);
466 void vcpu_unpause(struct vcpu *v);
467 void domain_unpause(struct domain *d);
468 void domain_pause_by_systemcontroller(struct domain *d);
469 void domain_unpause_by_systemcontroller(struct domain *d);
470 void cpu_init(void);
472 int vcpu_set_affinity(struct vcpu *v, cpumask_t *affinity);
474 void vcpu_runstate_get(struct vcpu *v, struct vcpu_runstate_info *runstate);
476 static inline void vcpu_unblock(struct vcpu *v)
477 {
478 if ( test_and_clear_bit(_VCPUF_blocked, &v->vcpu_flags) )
479 vcpu_wake(v);
480 }
482 #define IS_PRIV(_d) ((_d)->is_privileged)
484 #ifdef CONFIG_COMPAT
485 #define IS_COMPAT(_d) \
486 (test_bit(_DOMF_compat, &(_d)->domain_flags))
487 #else
488 #define IS_COMPAT(_d) 0
489 #endif
491 #define VM_ASSIST(_d,_t) (test_bit((_t), &(_d)->vm_assist))
493 #define is_hvm_domain(d) ((d)->is_hvm)
494 #define is_hvm_vcpu(v) (is_hvm_domain(v->domain))
496 #endif /* __SCHED_H__ */
498 /*
499 * Local variables:
500 * mode: C
501 * c-set-style: "BSD"
502 * c-basic-offset: 4
503 * tab-width: 4
504 * indent-tabs-mode: nil
505 * End:
506 */