ia64/xen-unstable

view xen/include/xen/sched.h @ 8400:6b1d39a56c2b

Add debugging flag for domains to make domu debugging a run-time option
Signed-off-by: Kip Macy kmacy@fsmware.ckm
author kaf24@firebug.cl.cam.ac.uk
date Thu Dec 15 21:50:12 2005 +0100 (2005-12-15)
parents bdf1a8039d13
children 8d0b62f0aa8d
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 <xen/time.h>
12 #include <xen/ac_timer.h>
13 #include <xen/grant_table.h>
14 #include <asm/domain.h>
16 extern unsigned long volatile jiffies;
17 extern rwlock_t domlist_lock;
19 /* A global pointer to the initial domain (DOM0). */
20 extern struct domain *dom0;
22 #define MAX_EVTCHNS NR_EVENT_CHANNELS
23 #define EVTCHNS_PER_BUCKET 128
24 #define NR_EVTCHN_BUCKETS (MAX_EVTCHNS / EVTCHNS_PER_BUCKET)
26 struct evtchn
27 {
28 #define ECS_FREE 0 /* Channel is available for use. */
29 #define ECS_RESERVED 1 /* Channel is reserved. */
30 #define ECS_UNBOUND 2 /* Channel is waiting to bind to a remote domain. */
31 #define ECS_INTERDOMAIN 3 /* Channel is bound to another domain. */
32 #define ECS_PIRQ 4 /* Channel is bound to a physical IRQ line. */
33 #define ECS_VIRQ 5 /* Channel is bound to a virtual IRQ line. */
34 #define ECS_IPI 6 /* Channel is bound to a virtual IPI line. */
35 u16 state; /* ECS_* */
36 u16 notify_vcpu_id; /* VCPU for local delivery notification */
37 union {
38 struct {
39 domid_t remote_domid;
40 } unbound; /* state == ECS_UNBOUND */
41 struct {
42 u16 remote_port;
43 struct domain *remote_dom;
44 } interdomain; /* state == ECS_INTERDOMAIN */
45 u16 pirq; /* state == ECS_PIRQ */
46 u16 virq; /* state == ECS_VIRQ */
47 } u;
48 };
50 int evtchn_init(struct domain *d);
51 void evtchn_destroy(struct domain *d);
53 #define CPUMAP_RUNANYWHERE 0xFFFFFFFF
55 struct vcpu
56 {
57 int vcpu_id;
59 int processor;
61 vcpu_info_t *vcpu_info;
63 struct domain *domain;
65 struct vcpu *next_in_list;
67 struct ac_timer timer; /* one-shot timer for timeout values */
68 unsigned long sleep_tick; /* tick at which this vcpu started sleep */
70 s_time_t lastschd; /* time this domain was last scheduled */
71 s_time_t lastdeschd; /* time this domain was last descheduled */
72 s_time_t cpu_time; /* total CPU time received till now */
73 s_time_t wokenup; /* time domain got woken up */
74 void *sched_priv; /* scheduler-specific data */
76 unsigned long vcpu_flags;
78 u16 virq_to_evtchn[NR_VIRQS];
80 atomic_t pausecnt;
82 cpumap_t cpumap; /* which cpus this domain can run on */
84 struct arch_vcpu arch;
85 };
87 /* Per-domain lock can be recursively acquired in fault handlers. */
88 #define LOCK_BIGLOCK(_d) spin_lock_recursive(&(_d)->big_lock)
89 #define UNLOCK_BIGLOCK(_d) spin_unlock_recursive(&(_d)->big_lock)
91 struct domain
92 {
93 domid_t domain_id;
95 shared_info_t *shared_info; /* shared data area */
97 spinlock_t big_lock;
99 spinlock_t page_alloc_lock; /* protects all the following fields */
100 struct list_head page_list; /* linked list, of size tot_pages */
101 struct list_head xenpage_list; /* linked list, of size xenheap_pages */
102 unsigned int tot_pages; /* number of pages currently possesed */
103 unsigned int max_pages; /* maximum value for tot_pages */
104 unsigned int xenheap_pages; /* # pages allocated from Xen heap */
106 /* Scheduling. */
107 int shutdown_code; /* code value from OS (if DOMF_shutdown) */
108 void *sched_priv; /* scheduler-specific data */
110 struct domain *next_in_list;
111 struct domain *next_in_hashbucket;
113 /* Event channel information. */
114 struct evtchn *evtchn[NR_EVTCHN_BUCKETS];
115 spinlock_t evtchn_lock;
117 grant_table_t *grant_table;
119 /*
120 * Interrupt to event-channel mappings. Updates should be protected by the
121 * domain's event-channel spinlock. Read accesses can also synchronise on
122 * the lock, but races don't usually matter.
123 */
124 #define NR_PIRQS 256 /* Put this somewhere sane! */
125 u16 pirq_to_evtchn[NR_PIRQS];
126 u32 pirq_mask[NR_PIRQS/32];
128 unsigned long domain_flags;
129 unsigned long vm_assist;
131 atomic_t refcnt;
133 struct vcpu *vcpu[MAX_VIRT_CPUS];
135 /* Bitmask of CPUs which are holding onto this domain's state. */
136 cpumask_t cpumask;
138 struct arch_domain arch;
140 void *ssid; /* sHype security subject identifier */
142 /* Control-plane tools handle for this domain. */
143 xen_domain_handle_t handle;
144 };
146 struct domain_setup_info
147 {
148 /* Initialised by caller. */
149 unsigned long image_addr;
150 unsigned long image_len;
151 /* Initialised by loader: Public. */
152 unsigned long v_start;
153 unsigned long v_end;
154 unsigned long v_kernstart;
155 unsigned long v_kernend;
156 unsigned long v_kernentry;
157 /* Initialised by loader: Private. */
158 unsigned int load_symtab;
159 unsigned long symtab_addr;
160 unsigned long symtab_len;
161 /* Indicate whether it's xen specific image */
162 char *xen_section_string;
163 };
165 extern struct domain idle0_domain;
166 extern struct vcpu idle0_vcpu;
168 extern struct vcpu *idle_task[NR_CPUS];
169 #define IDLE_DOMAIN_ID (0x7FFFU)
170 #define is_idle_task(_d) (test_bit(_DOMF_idle_domain, &(_d)->domain_flags))
172 struct vcpu *alloc_vcpu(
173 struct domain *d, unsigned int vcpu_id, unsigned int cpu_id);
175 struct domain *alloc_domain(void);
176 void free_domain(struct domain *d);
178 #define DOMAIN_DESTRUCTED (1<<31) /* assumes atomic_t is >= 32 bits */
179 #define put_domain(_d) \
180 if ( atomic_dec_and_test(&(_d)->refcnt) ) domain_destruct(_d)
182 /*
183 * Use this when you don't have an existing reference to @d. It returns
184 * FALSE if @d is being destructed.
185 */
186 static always_inline int get_domain(struct domain *d)
187 {
188 atomic_t old, new, seen = d->refcnt;
189 do
190 {
191 old = seen;
192 if ( unlikely(_atomic_read(old) & DOMAIN_DESTRUCTED) )
193 return 0;
194 _atomic_set(new, _atomic_read(old) + 1);
195 seen = atomic_compareandswap(old, new, &d->refcnt);
196 }
197 while ( unlikely(_atomic_read(seen) != _atomic_read(old)) );
198 return 1;
199 }
201 /*
202 * Use this when you already have, or are borrowing, a reference to @d.
203 * In this case we know that @d cannot be destructed under our feet.
204 */
205 static inline void get_knownalive_domain(struct domain *d)
206 {
207 atomic_inc(&d->refcnt);
208 ASSERT(!(atomic_read(&d->refcnt) & DOMAIN_DESTRUCTED));
209 }
211 extern struct domain *do_createdomain(
212 domid_t dom_id, unsigned int cpu);
213 extern int construct_dom0(
214 struct domain *d,
215 unsigned long image_start, unsigned long image_len,
216 unsigned long initrd_start, unsigned long initrd_len,
217 char *cmdline);
218 extern int set_info_guest(struct domain *d, dom0_setdomaininfo_t *);
220 struct domain *find_domain_by_id(domid_t dom);
221 extern void domain_destruct(struct domain *d);
222 extern void domain_kill(struct domain *d);
223 extern void domain_shutdown(struct domain *d, u8 reason);
224 extern void domain_pause_for_debugger(void);
226 /*
227 * Mark specified domain as crashed. This function always returns, even if the
228 * caller is the specified domain. The domain is not synchronously descheduled
229 * from any processor.
230 */
231 extern void domain_crash(struct domain *d);
233 /*
234 * Mark current domain as crashed and synchronously deschedule from the local
235 * processor. This function never returns.
236 */
237 extern void domain_crash_synchronous(void) __attribute__((noreturn));
239 void new_thread(struct vcpu *d,
240 unsigned long start_pc,
241 unsigned long start_stack,
242 unsigned long start_info);
244 #define set_current_state(_s) do { current->state = (_s); } while (0)
245 void scheduler_init(void);
246 void schedulers_start(void);
247 void sched_add_domain(struct vcpu *);
248 void sched_rem_domain(struct vcpu *);
249 long sched_ctl(struct sched_ctl_cmd *);
250 long sched_adjdom(struct sched_adjdom_cmd *);
251 int sched_id();
252 void vcpu_wake(struct vcpu *d);
253 void vcpu_sleep_nosync(struct vcpu *d);
254 void vcpu_sleep_sync(struct vcpu *d);
256 /*
257 * Force synchronisation of given VCPU's state. If it is currently descheduled,
258 * this call will ensure that all its state is committed to memory and that
259 * no CPU is using critical state (e.g., page tables) belonging to the VCPU.
260 */
261 extern void sync_vcpu_execstate(struct vcpu *v);
263 /*
264 * Called by the scheduler to switch to another VCPU. On entry, although
265 * VCPUF_running is no longer asserted for @prev, its context is still running
266 * on the local CPU and is not committed to memory. The local scheduler lock
267 * is therefore still held, and interrupts are disabled, because the local CPU
268 * is in an inconsistent state.
269 *
270 * The callee must ensure that the local CPU is no longer running in @prev's
271 * context, and that the context is saved to memory, before returning.
272 * Alternatively, if implementing lazy context switching, it suffices to ensure
273 * that invoking sync_vcpu_execstate() will switch and commit @prev's state.
274 */
275 extern void context_switch(
276 struct vcpu *prev,
277 struct vcpu *next);
279 /*
280 * On some architectures (notably x86) it is not possible to entirely load
281 * @next's context with interrupts disabled. These may implement a function to
282 * finalise loading the new context after interrupts are re-enabled. This
283 * function is not given @prev and is not permitted to access it.
284 */
285 extern void context_switch_finalise(
286 struct vcpu *next);
288 /* Called by the scheduler to continue running the current VCPU. */
289 extern void continue_running(
290 struct vcpu *same);
292 /* Is CPU 'cpu' idle right now? */
293 int idle_cpu(int cpu);
295 void startup_cpu_idle_loop(void);
297 unsigned long __hypercall_create_continuation(
298 unsigned int op, unsigned int nr_args, ...);
299 #define hypercall0_create_continuation(_op) \
300 __hypercall_create_continuation((_op), 0)
301 #define hypercall1_create_continuation(_op, _a1) \
302 __hypercall_create_continuation((_op), 1, \
303 (unsigned long)(_a1))
304 #define hypercall2_create_continuation(_op, _a1, _a2) \
305 __hypercall_create_continuation((_op), 2, \
306 (unsigned long)(_a1), (unsigned long)(_a2))
307 #define hypercall3_create_continuation(_op, _a1, _a2, _a3) \
308 __hypercall_create_continuation((_op), 3, \
309 (unsigned long)(_a1), (unsigned long)(_a2), (unsigned long)(_a3))
310 #define hypercall4_create_continuation(_op, _a1, _a2, _a3, _a4) \
311 __hypercall_create_continuation((_op), 4, \
312 (unsigned long)(_a1), (unsigned long)(_a2), (unsigned long)(_a3), \
313 (unsigned long)(_a4))
314 #define hypercall5_create_continuation(_op, _a1, _a2, _a3, _a4, _a5) \
315 __hypercall_create_continuation((_op), 5, \
316 (unsigned long)(_a1), (unsigned long)(_a2), (unsigned long)(_a3), \
317 (unsigned long)(_a4), (unsigned long)(_a5))
318 #define hypercall6_create_continuation(_op, _a1, _a2, _a3, _a4, _a5, _a6) \
319 __hypercall_create_continuation((_op), 6, \
320 (unsigned long)(_a1), (unsigned long)(_a2), (unsigned long)(_a3), \
321 (unsigned long)(_a4), (unsigned long)(_a5), (unsigned long)(_a6))
323 #define hypercall_preempt_check() (unlikely( \
324 softirq_pending(smp_processor_id()) | \
325 event_pending(current) \
326 ))
328 /* This domain_hash and domain_list are protected by the domlist_lock. */
329 #define DOMAIN_HASH_SIZE 256
330 #define DOMAIN_HASH(_id) ((int)(_id)&(DOMAIN_HASH_SIZE-1))
331 extern struct domain *domain_hash[DOMAIN_HASH_SIZE];
332 extern struct domain *domain_list;
334 #define for_each_domain(_d) \
335 for ( (_d) = domain_list; \
336 (_d) != NULL; \
337 (_d) = (_d)->next_in_list )
339 #define for_each_vcpu(_d,_v) \
340 for ( (_v) = (_d)->vcpu[0]; \
341 (_v) != NULL; \
342 (_v) = (_v)->next_in_list )
344 /*
345 * Per-VCPU flags (vcpu_flags).
346 */
347 /* Has the FPU been initialised? */
348 #define _VCPUF_fpu_initialised 0
349 #define VCPUF_fpu_initialised (1UL<<_VCPUF_fpu_initialised)
350 /* Has the FPU been used since it was last saved? */
351 #define _VCPUF_fpu_dirtied 1
352 #define VCPUF_fpu_dirtied (1UL<<_VCPUF_fpu_dirtied)
353 /* Domain is blocked waiting for an event. */
354 #define _VCPUF_blocked 2
355 #define VCPUF_blocked (1UL<<_VCPUF_blocked)
356 /* Currently running on a CPU? */
357 #define _VCPUF_running 3
358 #define VCPUF_running (1UL<<_VCPUF_running)
359 /* Disables auto-migration between CPUs. */
360 #define _VCPUF_cpu_pinned 4
361 #define VCPUF_cpu_pinned (1UL<<_VCPUF_cpu_pinned)
362 /* Domain migrated between CPUs. */
363 #define _VCPUF_cpu_migrated 5
364 #define VCPUF_cpu_migrated (1UL<<_VCPUF_cpu_migrated)
365 /* Initialization completed. */
366 #define _VCPUF_initialised 6
367 #define VCPUF_initialised (1UL<<_VCPUF_initialised)
368 /* VCPU is not-runnable */
369 #define _VCPUF_down 7
370 #define VCPUF_down (1UL<<_VCPUF_down)
372 /*
373 * Per-domain flags (domain_flags).
374 */
375 /* Is this one of the per-CPU idle domains? */
376 #define _DOMF_idle_domain 0
377 #define DOMF_idle_domain (1UL<<_DOMF_idle_domain)
378 /* Is this domain privileged? */
379 #define _DOMF_privileged 1
380 #define DOMF_privileged (1UL<<_DOMF_privileged)
381 /* May this domain do IO to physical devices? */
382 #define _DOMF_physdev_access 2
383 #define DOMF_physdev_access (1UL<<_DOMF_physdev_access)
384 /* Guest shut itself down for some reason. */
385 #define _DOMF_shutdown 3
386 #define DOMF_shutdown (1UL<<_DOMF_shutdown)
387 /* Guest is in process of shutting itself down (becomes DOMF_shutdown). */
388 #define _DOMF_shuttingdown 4
389 #define DOMF_shuttingdown (1UL<<_DOMF_shuttingdown)
390 /* Death rattle. */
391 #define _DOMF_dying 5
392 #define DOMF_dying (1UL<<_DOMF_dying)
393 /* Domain is paused by controller software. */
394 #define _DOMF_ctrl_pause 6
395 #define DOMF_ctrl_pause (1UL<<_DOMF_ctrl_pause)
396 /* Domain is being debugged by controller software. */
397 #define _DOMF_debugging 7
398 #define DOMF_debugging (1UL<<_DOMF_debugging)
401 static inline int domain_runnable(struct vcpu *v)
402 {
403 return ( (atomic_read(&v->pausecnt) == 0) &&
404 !(v->vcpu_flags & (VCPUF_blocked|VCPUF_down)) &&
405 !(v->domain->domain_flags &
406 (DOMF_shutdown|DOMF_shuttingdown|DOMF_ctrl_pause)) );
407 }
409 void vcpu_pause(struct vcpu *v);
410 void domain_pause(struct domain *d);
411 void vcpu_unpause(struct vcpu *v);
412 void domain_unpause(struct domain *d);
413 void domain_pause_by_systemcontroller(struct domain *d);
414 void domain_unpause_by_systemcontroller(struct domain *d);
415 void cpu_init(void);
417 static inline void vcpu_unblock(struct vcpu *v)
418 {
419 if ( test_and_clear_bit(_VCPUF_blocked, &v->vcpu_flags) )
420 vcpu_wake(v);
421 }
423 #define IS_PRIV(_d) \
424 (test_bit(_DOMF_privileged, &(_d)->domain_flags))
425 #define IS_CAPABLE_PHYSDEV(_d) \
426 (test_bit(_DOMF_physdev_access, &(_d)->domain_flags))
428 #define VM_ASSIST(_d,_t) (test_bit((_t), &(_d)->vm_assist))
430 #endif /* __SCHED_H__ */
432 /*
433 * Local variables:
434 * mode: C
435 * c-set-style: "BSD"
436 * c-basic-offset: 4
437 * tab-width: 4
438 * indent-tabs-mode: nil
439 * End:
440 */