direct-io.hg

view xen/include/xen/sched.h @ 3280:dda5ab69e74a

bitkeeper revision 1.1159.1.477 (41bf20d2wgoxIqhcE0nzBC8W-yFPhg)

sync w/ head.
author cl349@arcadians.cl.cam.ac.uk
date Tue Dec 14 17:20:18 2004 +0000 (2004-12-14)
parents 0373a9f51f2a e606dfe099cc
children b9ab4345fd1b
line source
1 #ifndef __SCHED_H__
2 #define __SCHED_H__
4 #define STACK_SIZE (2*PAGE_SIZE)
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 <xen/irq_cpustat.h>
26 extern unsigned long volatile jiffies;
27 extern rwlock_t domlist_lock;
29 struct domain;
31 /* A global pointer to the initial domain (DOM0). */
32 extern struct domain *dom0;
34 typedef struct event_channel_st
35 {
36 #define ECS_FREE 0 /* Channel is available for use. */
37 #define ECS_UNBOUND 1 /* Channel is waiting to bind to a remote domain. */
38 #define ECS_INTERDOMAIN 2 /* Channel is bound to another domain. */
39 #define ECS_PIRQ 3 /* Channel is bound to a physical IRQ line. */
40 #define ECS_VIRQ 4 /* Channel is bound to a virtual IRQ line. */
41 #define ECS_IPI 5 /* 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 struct mm_struct mm;
73 struct thread_struct thread;
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 };
91 #if 01
92 #define LOCK_BIGLOCK(_d) spin_lock(&(_d)->big_lock)
93 #define UNLOCK_BIGLOCK(_d) spin_unlock(&(_d)->big_lock)
94 #else
95 #define LOCK_BIGLOCK(_d) (void)(_d)
96 #define UNLOCK_BIGLOCK(_d)
97 #endif
99 struct domain {
100 domid_t id;
101 s_time_t create_time;
103 shared_info_t *shared_info; /* shared data area */
104 spinlock_t time_lock;
106 spinlock_t big_lock;
108 l1_pgentry_t *mm_perdomain_pt;
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 DF_SHUTDOWN). */
119 void *sched_priv; /* scheduler-specific data */
121 struct domain *next_list, *next_hash;
123 /* Event channel information. */
124 event_channel_t *event_channel;
125 unsigned int max_event_channel;
126 spinlock_t event_channel_lock;
128 grant_table_t *grant_table;
130 /*
131 * Interrupt to event-channel mappings. Updates should be protected by the
132 * domain's event-channel spinlock. Read accesses can also synchronise on
133 * the lock, but races don't usually matter.
134 */
135 #define NR_PIRQS 128 /* Put this somewhere sane! */
136 u16 pirq_to_evtchn[NR_PIRQS];
137 u32 pirq_mask[NR_PIRQS/32];
139 /* Physical I/O */
140 spinlock_t pcidev_lock;
141 struct list_head pcidev_list;
143 unsigned long d_flags;
144 unsigned long vm_assist;
146 atomic_t refcnt;
148 struct exec_domain *exec_domain[MAX_VIRT_CPUS];
149 };
151 struct domain_setup_info
152 {
153 unsigned long v_start;
154 unsigned long v_kernstart;
155 unsigned long v_kernend;
156 unsigned long v_kernentry;
158 unsigned int use_writable_pagetables;
159 };
161 #include <asm/uaccess.h> /* for KERNEL_DS */
163 extern struct domain idle0_domain;
164 extern struct exec_domain idle0_exec_domain;
166 extern struct exec_domain *idle_task[NR_CPUS];
167 #define IDLE_DOMAIN_ID (0x7FFFU)
168 #define is_idle_task(_p) (test_bit(DF_IDLETASK, &(_p)->d_flags))
170 struct exec_domain *alloc_exec_domain_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(struct domain *d,
212 unsigned long alloc_start,
213 unsigned long alloc_end,
214 char *image_start, unsigned long image_len,
215 char *initrd_start, unsigned long initrd_len,
216 char *cmdline);
217 extern int final_setup_guestos(struct domain *d, dom0_builddomain_t *);
219 struct domain *find_domain_by_id(domid_t dom);
220 struct domain *find_last_domain(void);
221 extern void domain_destruct(struct domain *d);
222 extern void domain_kill(struct domain *d);
223 extern void domain_crash(void);
224 extern void domain_shutdown(u8 reason);
226 void new_thread(struct exec_domain *d,
227 unsigned long start_pc,
228 unsigned long start_stack,
229 unsigned long start_info);
231 extern unsigned long wait_init_idle;
232 #define init_idle() clear_bit(smp_processor_id(), &wait_init_idle);
234 #define set_current_state(_s) do { current->state = (_s); } while (0)
235 void scheduler_init(void);
236 void schedulers_start(void);
237 void sched_add_domain(struct exec_domain *);
238 void sched_rem_domain(struct exec_domain *);
239 long sched_ctl(struct sched_ctl_cmd *);
240 long sched_adjdom(struct sched_adjdom_cmd *);
241 int sched_id();
242 void init_idle_task(void);
243 void domain_wake(struct exec_domain *d);
244 void domain_sleep(struct exec_domain *d);
246 void __enter_scheduler(void);
248 extern void switch_to(struct exec_domain *prev,
249 struct exec_domain *next);
251 void domain_init(void);
253 int idle_cpu(int cpu); /* Is CPU 'cpu' idle right now? */
255 void startup_cpu_idle_loop(void);
257 unsigned long hypercall_create_continuation(
258 unsigned int op, unsigned int nr_args, ...);
259 #define hypercall_preempt_check() \
260 (unlikely(softirq_pending(smp_processor_id())))
262 /* This domain_hash and domain_list are protected by the domlist_lock. */
263 #define DOMAIN_HASH_SIZE 256
264 #define DOMAIN_HASH(_id) ((int)(_id)&(DOMAIN_HASH_SIZE-1))
265 extern struct domain *domain_hash[DOMAIN_HASH_SIZE];
266 extern struct domain *domain_list;
268 #define for_each_domain(_p) \
269 for ( (_p) = domain_list; (_p) != NULL; (_p) = (_p)->next_list )
271 #define for_each_exec_domain(_d,_ed) \
272 for ( (_ed) = _d->exec_domain[0]; (_ed) != NULL; (_ed) = (_ed)->ed_next_list )
274 #define EDF_DONEFPUINIT 0 /* Has the FPU been initialised for this task? */
275 #define EDF_USEDFPU 1 /* Has this task used the FPU since last save? */
276 #define EDF_GUEST_STTS 2 /* Has the guest OS requested 'stts'? */
277 #define DF_CONSTRUCTED 3 /* Has the guest OS been fully built yet? */
278 #define DF_IDLETASK 4 /* Is this one of the per-CPU idle domains? */
279 #define DF_PRIVILEGED 5 /* Is this domain privileged? */
280 #define DF_PHYSDEV 6 /* May this domain do IO to physical devices? */
281 #define EDF_BLOCKED 7 /* Domain is blocked waiting for an event. */
282 #define EDF_CTRLPAUSE 8 /* Domain is paused by controller software. */
283 #define DF_SHUTDOWN 9 /* Guest shut itself down for some reason. */
284 #define DF_CRASHED 10 /* Domain crashed inside Xen, cannot continue. */
285 #define DF_DYING 11 /* Death rattle. */
286 #define EDF_RUNNING 12 /* Currently running on a CPU. */
287 #define EDF_CPUPINNED 13 /* Disables auto-migration. */
288 #define EDF_MIGRATED 14 /* Domain migrated between CPUs. */
290 static inline int domain_runnable(struct exec_domain *d)
291 {
292 return ( (atomic_read(&d->pausecnt) == 0) &&
293 !(d->ed_flags & ((1<<EDF_BLOCKED)|(1<<EDF_CTRLPAUSE))) &&
294 !(d->domain->d_flags & ((1<<DF_SHUTDOWN)|(1<<DF_CRASHED))) );
295 }
297 static inline void exec_domain_pause(struct exec_domain *ed)
298 {
299 ASSERT(ed != current);
300 atomic_inc(&ed->pausecnt);
301 domain_sleep(ed);
302 }
304 static inline void domain_pause(struct domain *d)
305 {
306 struct exec_domain *ed;
308 for_each_exec_domain(d, ed)
309 exec_domain_pause(ed);
310 }
312 static inline void exec_domain_unpause(struct exec_domain *ed)
313 {
314 ASSERT(ed != current);
315 if ( atomic_dec_and_test(&ed->pausecnt) )
316 domain_wake(ed);
317 }
319 static inline void domain_unpause(struct domain *d)
320 {
321 struct exec_domain *ed;
323 for_each_exec_domain(d, ed)
324 exec_domain_unpause(ed);
325 }
327 static inline void exec_domain_unblock(struct exec_domain *ed)
328 {
329 if ( test_and_clear_bit(EDF_BLOCKED, &ed->ed_flags) )
330 domain_wake(ed);
331 }
333 static inline void domain_unblock(struct domain *d)
334 {
335 struct exec_domain *ed;
337 for_each_exec_domain(d, ed)
338 exec_domain_unblock(ed);
339 }
341 static inline void domain_pause_by_systemcontroller(struct domain *d)
342 {
343 struct exec_domain *ed;
345 for_each_exec_domain(d, ed) {
346 ASSERT(ed != current);
347 if ( !test_and_set_bit(EDF_CTRLPAUSE, &ed->ed_flags) )
348 domain_sleep(ed);
349 }
350 }
352 static inline void domain_unpause_by_systemcontroller(struct domain *d)
353 {
354 struct exec_domain *ed;
356 for_each_exec_domain(d, ed) {
357 if ( test_and_clear_bit(EDF_CTRLPAUSE, &ed->ed_flags) )
358 domain_wake(ed);
359 }
360 }
363 #define IS_PRIV(_d) (test_bit(DF_PRIVILEGED, &(_d)->d_flags))
364 #define IS_CAPABLE_PHYSDEV(_d) (test_bit(DF_PHYSDEV, &(_d)->d_flags))
366 #define VM_ASSIST(_d,_t) (test_bit((_t), &(_d)->vm_assist))
368 #include <xen/slab.h>
369 #include <xen/domain.h>
371 #endif /* __SCHED_H__ */