ia64/xen-unstable

view xen/include/xen/sched.h @ 5760:3b48277a9dd0

Let Xen have 256 PIRQs to guests.
author kaf24@firebug.cl.cam.ac.uk
date Tue Jul 12 17:23:38 2005 +0000 (2005-07-12)
parents 48dd03e4b388
children a83ac0806d6b
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 1024
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;
64 struct vcpu *next_in_list;
66 struct ac_timer timer; /* one-shot timer for timeout values */
67 unsigned long sleep_tick; /* tick at which this vcpu started sleep */
69 s_time_t lastschd; /* time this domain was last scheduled */
70 s_time_t lastdeschd; /* time this domain was last descheduled */
71 s_time_t cpu_time; /* total CPU time received till now */
72 s_time_t wokenup; /* time domain got woken up */
73 void *sched_priv; /* scheduler-specific data */
75 unsigned long vcpu_flags;
77 u16 virq_to_evtchn[NR_VIRQS];
79 atomic_t pausecnt;
81 cpumap_t cpumap; /* which cpus this domain can run on */
83 struct arch_vcpu arch;
84 };
86 /* Per-domain lock can be recursively acquired in fault handlers. */
87 #define LOCK_BIGLOCK(_d) spin_lock_recursive(&(_d)->big_lock)
88 #define UNLOCK_BIGLOCK(_d) spin_unlock_recursive(&(_d)->big_lock)
90 struct domain
91 {
92 domid_t domain_id;
94 shared_info_t *shared_info; /* shared data area */
95 spinlock_t time_lock;
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 next_io_page; /* next io pfn to give to domain */
105 unsigned int xenheap_pages; /* # pages allocated from Xen heap */
107 /* Scheduling. */
108 int shutdown_code; /* code value from OS (if DOMF_shutdown) */
109 void *sched_priv; /* scheduler-specific data */
111 struct domain *next_in_list;
112 struct domain *next_in_hashbucket;
114 /* Event channel information. */
115 struct evtchn *evtchn[NR_EVTCHN_BUCKETS];
116 spinlock_t evtchn_lock;
118 grant_table_t *grant_table;
120 /*
121 * Interrupt to event-channel mappings. Updates should be protected by the
122 * domain's event-channel spinlock. Read accesses can also synchronise on
123 * the lock, but races don't usually matter.
124 */
125 #define NR_PIRQS 256 /* Put this somewhere sane! */
126 u16 pirq_to_evtchn[NR_PIRQS];
127 u32 pirq_mask[NR_PIRQS/32];
129 unsigned long domain_flags;
130 unsigned long vm_assist;
132 atomic_t refcnt;
134 struct vcpu *vcpu[MAX_VIRT_CPUS];
136 /* Bitmask of CPUs which are holding onto this domain's state. */
137 cpumask_t cpumask;
139 struct arch_domain arch;
141 void *ssid; /* sHype security subject identifier */
142 };
144 struct domain_setup_info
145 {
146 /* Initialised by caller. */
147 unsigned long image_addr;
148 unsigned long image_len;
149 /* Initialised by loader: Public. */
150 unsigned long v_start;
151 unsigned long v_end;
152 unsigned long v_kernstart;
153 unsigned long v_kernend;
154 unsigned long v_kernentry;
155 /* Initialised by loader: Private. */
156 unsigned int load_symtab;
157 unsigned long symtab_addr;
158 unsigned long symtab_len;
159 /* Indicate whether it's xen specific image */
160 char *xen_section_string;
161 };
163 extern struct domain idle0_domain;
164 extern struct vcpu idle0_vcpu;
166 extern struct vcpu *idle_task[NR_CPUS];
167 #define IDLE_DOMAIN_ID (0x7FFFU)
168 #define is_idle_task(_d) (test_bit(_DOMF_idle_domain, &(_d)->domain_flags))
170 struct vcpu *alloc_vcpu_struct(struct domain *d,
171 unsigned long vcpu);
173 void free_domain_struct(struct domain *d);
174 struct domain *alloc_domain_struct();
176 #define DOMAIN_DESTRUCTED (1<<31) /* assumes atomic_t is >= 32 bits */
177 #define put_domain(_d) \
178 if ( atomic_dec_and_test(&(_d)->refcnt) ) domain_destruct(_d)
180 /*
181 * Use this when you don't have an existing reference to @d. It returns
182 * FALSE if @d is being destructed.
183 */
184 static always_inline int get_domain(struct domain *d)
185 {
186 atomic_t old, new, seen = d->refcnt;
187 do
188 {
189 old = seen;
190 if ( unlikely(_atomic_read(old) & DOMAIN_DESTRUCTED) )
191 return 0;
192 _atomic_set(new, _atomic_read(old) + 1);
193 seen = atomic_compareandswap(old, new, &d->refcnt);
194 }
195 while ( unlikely(_atomic_read(seen) != _atomic_read(old)) );
196 return 1;
197 }
199 /*
200 * Use this when you already have, or are borrowing, a reference to @d.
201 * In this case we know that @d cannot be destructed under our feet.
202 */
203 static inline void get_knownalive_domain(struct domain *d)
204 {
205 atomic_inc(&d->refcnt);
206 ASSERT(!(atomic_read(&d->refcnt) & DOMAIN_DESTRUCTED));
207 }
209 extern struct domain *do_createdomain(
210 domid_t dom_id, unsigned int cpu);
211 extern int construct_dom0(
212 struct domain *d,
213 unsigned long image_start, unsigned long image_len,
214 unsigned long initrd_start, unsigned long initrd_len,
215 char *cmdline);
216 extern int set_info_guest(struct domain *d, dom0_setdomaininfo_t *);
218 struct domain *find_domain_by_id(domid_t dom);
219 extern void domain_destruct(struct domain *d);
220 extern void domain_kill(struct domain *d);
221 extern void domain_shutdown(u8 reason);
222 extern void domain_pause_for_debugger(void);
224 /*
225 * Mark current domain as crashed. This function returns: the domain is not
226 * synchronously descheduled from any processor.
227 */
228 extern void domain_crash(void);
230 /*
231 * Mark current domain as crashed and synchronously deschedule from the local
232 * processor. This function never returns.
233 */
234 extern void domain_crash_synchronous(void) __attribute__((noreturn));
236 void new_thread(struct vcpu *d,
237 unsigned long start_pc,
238 unsigned long start_stack,
239 unsigned long start_info);
241 #define set_current_state(_s) do { current->state = (_s); } while (0)
242 void scheduler_init(void);
243 void schedulers_start(void);
244 void sched_add_domain(struct vcpu *);
245 void sched_rem_domain(struct vcpu *);
246 long sched_ctl(struct sched_ctl_cmd *);
247 long sched_adjdom(struct sched_adjdom_cmd *);
248 int sched_id();
249 void domain_wake(struct vcpu *d);
250 void domain_sleep_nosync(struct vcpu *d);
251 void domain_sleep_sync(struct vcpu *d);
253 /*
254 * Force loading of currently-executing domain state on the specified set
255 * of CPUs. This is used to counteract lazy state switching where required.
256 */
257 extern void sync_lazy_execstate_cpu(unsigned int cpu);
258 extern void sync_lazy_execstate_mask(cpumask_t mask);
259 extern void sync_lazy_execstate_all(void);
260 extern int __sync_lazy_execstate(void);
262 /* Called by the scheduler to switch to another vcpu. */
263 extern void context_switch(
264 struct vcpu *prev,
265 struct vcpu *next);
267 /* Called by the scheduler to continue running the current vcpu. */
268 extern void continue_running(
269 struct vcpu *same);
271 int idle_cpu(int cpu); /* Is CPU 'cpu' idle right now? */
273 void startup_cpu_idle_loop(void);
275 unsigned long __hypercall_create_continuation(
276 unsigned int op, unsigned int nr_args, ...);
277 #define hypercall0_create_continuation(_op) \
278 __hypercall_create_continuation((_op), 0)
279 #define hypercall1_create_continuation(_op, _a1) \
280 __hypercall_create_continuation((_op), 1, \
281 (unsigned long)(_a1))
282 #define hypercall2_create_continuation(_op, _a1, _a2) \
283 __hypercall_create_continuation((_op), 2, \
284 (unsigned long)(_a1), (unsigned long)(_a2))
285 #define hypercall3_create_continuation(_op, _a1, _a2, _a3) \
286 __hypercall_create_continuation((_op), 3, \
287 (unsigned long)(_a1), (unsigned long)(_a2), (unsigned long)(_a3))
288 #define hypercall4_create_continuation(_op, _a1, _a2, _a3, _a4) \
289 __hypercall_create_continuation((_op), 4, \
290 (unsigned long)(_a1), (unsigned long)(_a2), (unsigned long)(_a3), \
291 (unsigned long)(_a4))
292 #define hypercall5_create_continuation(_op, _a1, _a2, _a3, _a4, _a5) \
293 __hypercall_create_continuation((_op), 5, \
294 (unsigned long)(_a1), (unsigned long)(_a2), (unsigned long)(_a3), \
295 (unsigned long)(_a4), (unsigned long)(_a5))
296 #define hypercall6_create_continuation(_op, _a1, _a2, _a3, _a4, _a5, _a6) \
297 __hypercall_create_continuation((_op), 6, \
298 (unsigned long)(_a1), (unsigned long)(_a2), (unsigned long)(_a3), \
299 (unsigned long)(_a4), (unsigned long)(_a5), (unsigned long)(_a6))
301 #define hypercall_preempt_check() (unlikely( \
302 softirq_pending(smp_processor_id()) | \
303 (!!current->vcpu_info->evtchn_upcall_pending & \
304 !current->vcpu_info->evtchn_upcall_mask) \
305 ))
307 /* This domain_hash and domain_list are protected by the domlist_lock. */
308 #define DOMAIN_HASH_SIZE 256
309 #define DOMAIN_HASH(_id) ((int)(_id)&(DOMAIN_HASH_SIZE-1))
310 extern struct domain *domain_hash[DOMAIN_HASH_SIZE];
311 extern struct domain *domain_list;
313 #define for_each_domain(_d) \
314 for ( (_d) = domain_list; (_d) != NULL; (_d) = (_d)->next_in_list )
316 #define for_each_vcpu(_d,_ed) \
317 for ( (_ed) = (_d)->vcpu[0]; \
318 (_ed) != NULL; \
319 (_ed) = (_ed)->next_in_list )
321 /*
322 * Per-VCPU flags (vcpu_flags).
323 */
324 /* Has the FPU been initialised? */
325 #define _VCPUF_fpu_initialised 0
326 #define VCPUF_fpu_initialised (1UL<<_VCPUF_fpu_initialised)
327 /* Has the FPU been used since it was last saved? */
328 #define _VCPUF_fpu_dirtied 1
329 #define VCPUF_fpu_dirtied (1UL<<_VCPUF_fpu_dirtied)
330 /* Domain is blocked waiting for an event. */
331 #define _VCPUF_blocked 3
332 #define VCPUF_blocked (1UL<<_VCPUF_blocked)
333 /* Domain is paused by controller software. */
334 #define _VCPUF_ctrl_pause 4
335 #define VCPUF_ctrl_pause (1UL<<_VCPUF_ctrl_pause)
336 /* Currently running on a CPU? */
337 #define _VCPUF_running 5
338 #define VCPUF_running (1UL<<_VCPUF_running)
339 /* Disables auto-migration between CPUs. */
340 #define _VCPUF_cpu_pinned 6
341 #define VCPUF_cpu_pinned (1UL<<_VCPUF_cpu_pinned)
342 /* Domain migrated between CPUs. */
343 #define _VCPUF_cpu_migrated 7
344 #define VCPUF_cpu_migrated (1UL<<_VCPUF_cpu_migrated)
345 /* Initialization completed. */
346 #define _VCPUF_initialised 8
347 #define VCPUF_initialised (1UL<<_VCPUF_initialised)
348 /* VCPU is not-runnable */
349 #define _VCPUF_down 9
350 #define VCPUF_down (1UL<<_VCPUF_down)
352 /*
353 * Per-domain flags (domain_flags).
354 */
355 /* Has the guest OS been fully built yet? */
356 #define _DOMF_constructed 0
357 #define DOMF_constructed (1UL<<_DOMF_constructed)
358 /* Is this one of the per-CPU idle domains? */
359 #define _DOMF_idle_domain 1
360 #define DOMF_idle_domain (1UL<<_DOMF_idle_domain)
361 /* Is this domain privileged? */
362 #define _DOMF_privileged 2
363 #define DOMF_privileged (1UL<<_DOMF_privileged)
364 /* May this domain do IO to physical devices? */
365 #define _DOMF_physdev_access 3
366 #define DOMF_physdev_access (1UL<<_DOMF_physdev_access)
367 /* Guest shut itself down for some reason. */
368 #define _DOMF_shutdown 4
369 #define DOMF_shutdown (1UL<<_DOMF_shutdown)
370 /* Guest is in process of shutting itself down (becomes DOMF_shutdown). */
371 #define _DOMF_shuttingdown 5
372 #define DOMF_shuttingdown (1UL<<_DOMF_shuttingdown)
373 /* Death rattle. */
374 #define _DOMF_dying 6
375 #define DOMF_dying (1UL<<_DOMF_dying)
377 static inline int domain_runnable(struct vcpu *v)
378 {
379 return ( (atomic_read(&v->pausecnt) == 0) &&
380 !(v->vcpu_flags & (VCPUF_blocked|VCPUF_ctrl_pause|VCPUF_down)) &&
381 !(v->domain->domain_flags & (DOMF_shutdown|DOMF_shuttingdown)) );
382 }
384 void vcpu_pause(struct vcpu *v);
385 void domain_pause(struct domain *d);
386 void vcpu_unpause(struct vcpu *v);
387 void domain_unpause(struct domain *d);
388 void domain_pause_by_systemcontroller(struct domain *d);
389 void domain_unpause_by_systemcontroller(struct domain *d);
391 static inline void vcpu_unblock(struct vcpu *v)
392 {
393 if ( test_and_clear_bit(_VCPUF_blocked, &v->vcpu_flags) )
394 domain_wake(v);
395 }
397 #define IS_PRIV(_d) \
398 (test_bit(_DOMF_privileged, &(_d)->domain_flags))
399 #define IS_CAPABLE_PHYSDEV(_d) \
400 (test_bit(_DOMF_physdev_access, &(_d)->domain_flags))
402 #define VM_ASSIST(_d,_t) (test_bit((_t), &(_d)->vm_assist))
404 #endif /* __SCHED_H__ */
406 /*
407 * Local variables:
408 * mode: C
409 * c-set-style: "BSD"
410 * c-basic-offset: 4
411 * tab-width: 4
412 * indent-tabs-mode: nil
413 * End:
414 */