direct-io.hg

view xen/include/xen/sched.h @ 10949:ffa5b2975dff

[XEN] Add Xen-attached event channels, which will be used
by HVM for the ioreq_packet port.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Fri Aug 04 20:34:44 2006 +0100 (2006-08-04)
parents 462d6e4cb29a
children 0f917d63e960
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 <public/xen.h>
10 #include <public/dom0_ops.h>
11 #include <public/vcpu.h>
12 #include <xen/time.h>
13 #include <xen/timer.h>
14 #include <xen/grant_table.h>
15 #include <xen/rangeset.h>
16 #include <asm/domain.h>
17 #include <xen/xenoprof.h>
18 #include <xen/irq.h>
20 extern unsigned long volatile jiffies;
21 extern rwlock_t domlist_lock;
23 /* A global pointer to the initial domain (DOM0). */
24 extern struct domain *dom0;
26 #define MAX_EVTCHNS NR_EVENT_CHANNELS
27 #define EVTCHNS_PER_BUCKET 128
28 #define NR_EVTCHN_BUCKETS (MAX_EVTCHNS / EVTCHNS_PER_BUCKET)
30 struct evtchn
31 {
32 #define ECS_FREE 0 /* Channel is available for use. */
33 #define ECS_RESERVED 1 /* Channel is reserved. */
34 #define ECS_UNBOUND 2 /* Channel is waiting to bind to a remote domain. */
35 #define ECS_INTERDOMAIN 3 /* Channel is bound to another domain. */
36 #define ECS_PIRQ 4 /* Channel is bound to a physical IRQ line. */
37 #define ECS_VIRQ 5 /* Channel is bound to a virtual IRQ line. */
38 #define ECS_IPI 6 /* Channel is bound to a virtual IPI line. */
39 u8 state; /* ECS_* */
40 u8 consumer_is_xen; /* Consumed by Xen or by guest? */
41 u16 notify_vcpu_id; /* VCPU for local delivery notification */
42 union {
43 struct {
44 domid_t remote_domid;
45 } unbound; /* state == ECS_UNBOUND */
46 struct {
47 u16 remote_port;
48 struct domain *remote_dom;
49 } interdomain; /* state == ECS_INTERDOMAIN */
50 u16 pirq; /* state == ECS_PIRQ */
51 u16 virq; /* state == ECS_VIRQ */
52 } u;
53 };
55 int evtchn_init(struct domain *d);
56 void evtchn_destroy(struct domain *d);
58 struct vcpu
59 {
60 int vcpu_id;
62 int processor;
64 vcpu_info_t *vcpu_info;
66 struct domain *domain;
68 struct vcpu *next_in_list;
70 struct timer timer; /* one-shot timer for timeout values */
71 unsigned long sleep_tick; /* tick at which this vcpu started sleep */
73 struct timer poll_timer; /* timeout for SCHEDOP_poll */
75 void *sched_priv; /* scheduler-specific data */
77 struct vcpu_runstate_info runstate;
78 struct vcpu_runstate_info *runstate_guest; /* guest address */
80 unsigned long vcpu_flags;
82 spinlock_t pause_lock;
83 unsigned int pause_count;
85 u16 virq_to_evtchn[NR_VIRQS];
87 /* Bitmask of CPUs on which this VCPU may run. */
88 cpumask_t cpu_affinity;
90 unsigned long nmi_addr; /* NMI callback address. */
92 /* Bitmask of CPUs which are holding onto this VCPU's state. */
93 cpumask_t vcpu_dirty_cpumask;
95 struct arch_vcpu arch;
96 };
98 /* Per-domain lock can be recursively acquired in fault handlers. */
99 #define LOCK_BIGLOCK(_d) spin_lock_recursive(&(_d)->big_lock)
100 #define UNLOCK_BIGLOCK(_d) spin_unlock_recursive(&(_d)->big_lock)
102 struct domain
103 {
104 domid_t domain_id;
106 shared_info_t *shared_info; /* shared data area */
108 spinlock_t big_lock;
110 spinlock_t page_alloc_lock; /* protects all the following fields */
111 struct list_head page_list; /* linked list, of size tot_pages */
112 struct list_head xenpage_list; /* linked list, of size xenheap_pages */
113 unsigned int tot_pages; /* number of pages currently possesed */
114 unsigned int max_pages; /* maximum value for tot_pages */
115 unsigned int xenheap_pages; /* # pages allocated from Xen heap */
117 /* Scheduling. */
118 int shutdown_code; /* code value from OS (if DOMF_shutdown) */
119 void *sched_priv; /* scheduler-specific data */
121 struct domain *next_in_list;
122 struct domain *next_in_hashbucket;
124 struct list_head rangesets;
125 spinlock_t rangesets_lock;
127 /* Event channel information. */
128 struct evtchn *evtchn[NR_EVTCHN_BUCKETS];
129 spinlock_t evtchn_lock;
131 struct grant_table *grant_table;
133 /*
134 * Interrupt to event-channel mappings. Updates should be protected by the
135 * domain's event-channel spinlock. Read accesses can also synchronise on
136 * the lock, but races don't usually matter.
137 */
138 u16 pirq_to_evtchn[NR_IRQS];
139 DECLARE_BITMAP(pirq_mask, NR_IRQS);
141 /* I/O capabilities (access to IRQs and memory-mapped I/O). */
142 struct rangeset *iomem_caps;
143 struct rangeset *irq_caps;
145 unsigned long domain_flags;
147 spinlock_t pause_lock;
148 unsigned int pause_count;
150 unsigned long vm_assist;
152 atomic_t refcnt;
154 struct vcpu *vcpu[MAX_VIRT_CPUS];
156 /* Bitmask of CPUs which are holding onto this domain's state. */
157 cpumask_t domain_dirty_cpumask;
159 struct arch_domain arch;
161 void *ssid; /* sHype security subject identifier */
163 /* Control-plane tools handle for this domain. */
164 xen_domain_handle_t handle;
166 /* OProfile support. */
167 struct xenoprof *xenoprof;
168 int32_t time_offset_seconds;
169 };
171 struct domain_setup_info
172 {
173 /* Initialised by caller. */
174 unsigned long image_addr;
175 unsigned long image_len;
176 /* Initialised by loader: Public. */
177 unsigned long v_start;
178 unsigned long v_end;
179 unsigned long v_kernstart;
180 unsigned long v_kernend;
181 unsigned long v_kernentry;
182 /* Initialised by loader: Private. */
183 unsigned long elf_paddr_offset;
184 unsigned int load_symtab;
185 unsigned long symtab_addr;
186 unsigned long symtab_len;
187 /* Indicate whether it's xen specific image */
188 char *xen_section_string;
189 };
191 extern struct vcpu *idle_vcpu[NR_CPUS];
192 #define IDLE_DOMAIN_ID (0x7FFFU)
193 #define is_idle_domain(d) ((d)->domain_id == IDLE_DOMAIN_ID)
194 #define is_idle_vcpu(v) (is_idle_domain((v)->domain))
196 #define DOMAIN_DESTROYED (1<<31) /* assumes atomic_t is >= 32 bits */
197 #define put_domain(_d) \
198 if ( atomic_dec_and_test(&(_d)->refcnt) ) domain_destroy(_d)
200 /*
201 * Use this when you don't have an existing reference to @d. It returns
202 * FALSE if @d is being destroyed.
203 */
204 static always_inline int get_domain(struct domain *d)
205 {
206 atomic_t old, new, seen = d->refcnt;
207 do
208 {
209 old = seen;
210 if ( unlikely(_atomic_read(old) & DOMAIN_DESTROYED) )
211 return 0;
212 _atomic_set(new, _atomic_read(old) + 1);
213 seen = atomic_compareandswap(old, new, &d->refcnt);
214 }
215 while ( unlikely(_atomic_read(seen) != _atomic_read(old)) );
216 return 1;
217 }
219 /*
220 * Use this when you already have, or are borrowing, a reference to @d.
221 * In this case we know that @d cannot be destroyed under our feet.
222 */
223 static inline void get_knownalive_domain(struct domain *d)
224 {
225 atomic_inc(&d->refcnt);
226 ASSERT(!(atomic_read(&d->refcnt) & DOMAIN_DESTROYED));
227 }
229 extern struct domain *domain_create(domid_t domid);
230 extern int construct_dom0(
231 struct domain *d,
232 unsigned long image_start, unsigned long image_len,
233 unsigned long initrd_start, unsigned long initrd_len,
234 char *cmdline);
235 extern int set_info_guest(struct domain *d, dom0_setvcpucontext_t *);
237 struct domain *find_domain_by_id(domid_t dom);
238 extern void domain_destroy(struct domain *d);
239 extern void domain_kill(struct domain *d);
240 extern void domain_shutdown(struct domain *d, u8 reason);
241 extern void domain_pause_for_debugger(void);
243 /*
244 * Mark specified domain as crashed. This function always returns, even if the
245 * caller is the specified domain. The domain is not synchronously descheduled
246 * from any processor.
247 */
248 extern void __domain_crash(struct domain *d);
249 #define domain_crash(d) do { \
250 printk("domain_crash called from %s:%d\n", __FILE__, __LINE__); \
251 __domain_crash(d); \
252 } while (0)
254 /*
255 * Mark current domain as crashed and synchronously deschedule from the local
256 * processor. This function never returns.
257 */
258 extern void __domain_crash_synchronous(void) __attribute__((noreturn));
259 #define domain_crash_synchronous() do { \
260 printk("domain_crash_sync called from %s:%d\n", __FILE__, __LINE__); \
261 __domain_crash_synchronous(); \
262 } while (0)
264 void new_thread(struct vcpu *d,
265 unsigned long start_pc,
266 unsigned long start_stack,
267 unsigned long start_info);
269 #define set_current_state(_s) do { current->state = (_s); } while (0)
270 void scheduler_init(void);
271 void schedulers_start(void);
272 int sched_init_vcpu(struct vcpu *);
273 void sched_destroy_domain(struct domain *);
274 long sched_ctl(struct sched_ctl_cmd *);
275 long sched_adjdom(struct sched_adjdom_cmd *);
276 int sched_id(void);
277 void vcpu_wake(struct vcpu *d);
278 void vcpu_sleep_nosync(struct vcpu *d);
279 void vcpu_sleep_sync(struct vcpu *d);
281 /*
282 * Force synchronisation of given VCPU's state. If it is currently descheduled,
283 * this call will ensure that all its state is committed to memory and that
284 * no CPU is using critical state (e.g., page tables) belonging to the VCPU.
285 */
286 extern void sync_vcpu_execstate(struct vcpu *v);
288 /*
289 * Called by the scheduler to switch to another VCPU. This function must
290 * call context_saved(@prev) when the local CPU is no longer running in
291 * @prev's context, and that context is saved to memory. Alternatively, if
292 * implementing lazy context switching, it suffices to ensure that invoking
293 * sync_vcpu_execstate() will switch and commit @prev's state.
294 */
295 extern void context_switch(
296 struct vcpu *prev,
297 struct vcpu *next);
299 /*
300 * As described above, context_switch() must call this function when the
301 * local CPU is no longer running in @prev's context, and @prev's context is
302 * saved to memory. Alternatively, if implementing lazy context switching,
303 * ensure that invoking sync_vcpu_execstate() will switch and commit @prev.
304 */
305 #define context_saved(prev) (clear_bit(_VCPUF_running, &(prev)->vcpu_flags))
307 /* Called by the scheduler to continue running the current VCPU. */
308 extern void continue_running(
309 struct vcpu *same);
311 void startup_cpu_idle_loop(void);
313 /*
314 * Creates a continuation to resume the current hypercall. The caller should
315 * return immediately, propagating the value returned from this invocation.
316 * The format string specifies the types and number of hypercall arguments.
317 * It contains one character per argument as follows:
318 * 'i' [unsigned] {char, int}
319 * 'l' [unsigned] long
320 * 'h' guest handle (XEN_GUEST_HANDLE(foo))
321 */
322 unsigned long hypercall_create_continuation(
323 unsigned int op, const char *format, ...);
325 #define hypercall_preempt_check() (unlikely( \
326 softirq_pending(smp_processor_id()) | \
327 local_events_need_delivery() \
328 ))
330 /* This domain_hash and domain_list are protected by the domlist_lock. */
331 #define DOMAIN_HASH_SIZE 256
332 #define DOMAIN_HASH(_id) ((int)(_id)&(DOMAIN_HASH_SIZE-1))
333 extern struct domain *domain_hash[DOMAIN_HASH_SIZE];
334 extern struct domain *domain_list;
336 #define for_each_domain(_d) \
337 for ( (_d) = domain_list; \
338 (_d) != NULL; \
339 (_d) = (_d)->next_in_list )
341 #define for_each_vcpu(_d,_v) \
342 for ( (_v) = (_d)->vcpu[0]; \
343 (_v) != NULL; \
344 (_v) = (_v)->next_in_list )
346 /*
347 * Per-VCPU flags (vcpu_flags).
348 */
349 /* Has the FPU been initialised? */
350 #define _VCPUF_fpu_initialised 0
351 #define VCPUF_fpu_initialised (1UL<<_VCPUF_fpu_initialised)
352 /* Has the FPU been used since it was last saved? */
353 #define _VCPUF_fpu_dirtied 1
354 #define VCPUF_fpu_dirtied (1UL<<_VCPUF_fpu_dirtied)
355 /* Domain is blocked waiting for an event. */
356 #define _VCPUF_blocked 2
357 #define VCPUF_blocked (1UL<<_VCPUF_blocked)
358 /* Currently running on a CPU? */
359 #define _VCPUF_running 3
360 #define VCPUF_running (1UL<<_VCPUF_running)
361 /* Initialization completed. */
362 #define _VCPUF_initialised 4
363 #define VCPUF_initialised (1UL<<_VCPUF_initialised)
364 /* VCPU is offline. */
365 #define _VCPUF_down 5
366 #define VCPUF_down (1UL<<_VCPUF_down)
367 /* NMI callback pending for this VCPU? */
368 #define _VCPUF_nmi_pending 8
369 #define VCPUF_nmi_pending (1UL<<_VCPUF_nmi_pending)
370 /* Avoid NMI reentry by allowing NMIs to be masked for short periods. */
371 #define _VCPUF_nmi_masked 9
372 #define VCPUF_nmi_masked (1UL<<_VCPUF_nmi_masked)
373 /* VCPU is polling a set of event channels (SCHEDOP_poll). */
374 #define _VCPUF_polling 10
375 #define VCPUF_polling (1UL<<_VCPUF_polling)
376 /* VCPU is paused by the hypervisor? */
377 #define _VCPUF_paused 11
378 #define VCPUF_paused (1UL<<_VCPUF_paused)
379 /* VCPU is blocked awaiting an event to be consumed by Xen. */
380 #define _VCPUF_blocked_in_xen 12
381 #define VCPUF_blocked_in_xen (1UL<<_VCPUF_blocked_in_xen)
383 /*
384 * Per-domain flags (domain_flags).
385 */
386 /* Is this domain privileged? */
387 #define _DOMF_privileged 0
388 #define DOMF_privileged (1UL<<_DOMF_privileged)
389 /* Guest shut itself down for some reason. */
390 #define _DOMF_shutdown 1
391 #define DOMF_shutdown (1UL<<_DOMF_shutdown)
392 /* Death rattle. */
393 #define _DOMF_dying 2
394 #define DOMF_dying (1UL<<_DOMF_dying)
395 /* Domain is paused by controller software. */
396 #define _DOMF_ctrl_pause 3
397 #define DOMF_ctrl_pause (1UL<<_DOMF_ctrl_pause)
398 /* Domain is being debugged by controller software. */
399 #define _DOMF_debugging 4
400 #define DOMF_debugging (1UL<<_DOMF_debugging)
401 /* Are any VCPUs polling event channels (SCHEDOP_poll)? */
402 #define _DOMF_polling 5
403 #define DOMF_polling (1UL<<_DOMF_polling)
404 /* Domain is paused by the hypervisor? */
405 #define _DOMF_paused 6
406 #define DOMF_paused (1UL<<_DOMF_paused)
408 static inline int vcpu_runnable(struct vcpu *v)
409 {
410 return ( !(v->vcpu_flags &
411 (VCPUF_blocked|VCPUF_down|VCPUF_paused|VCPUF_blocked_in_xen)) &&
412 !(v->domain->domain_flags &
413 (DOMF_shutdown|DOMF_ctrl_pause|DOMF_paused)) );
414 }
416 void vcpu_pause(struct vcpu *v);
417 void domain_pause(struct domain *d);
418 void vcpu_unpause(struct vcpu *v);
419 void domain_unpause(struct domain *d);
420 void domain_pause_by_systemcontroller(struct domain *d);
421 void domain_unpause_by_systemcontroller(struct domain *d);
422 void cpu_init(void);
424 int vcpu_set_affinity(struct vcpu *v, cpumask_t *affinity);
426 void vcpu_runstate_get(struct vcpu *v, struct vcpu_runstate_info *runstate);
428 static inline void vcpu_unblock(struct vcpu *v)
429 {
430 if ( test_and_clear_bit(_VCPUF_blocked, &v->vcpu_flags) )
431 vcpu_wake(v);
432 }
434 #define IS_PRIV(_d) \
435 (test_bit(_DOMF_privileged, &(_d)->domain_flags))
437 #define VM_ASSIST(_d,_t) (test_bit((_t), &(_d)->vm_assist))
439 #endif /* __SCHED_H__ */
441 /*
442 * Local variables:
443 * mode: C
444 * c-set-style: "BSD"
445 * c-basic-offset: 4
446 * tab-width: 4
447 * indent-tabs-mode: nil
448 * End:
449 */