direct-io.hg

view tools/libxc/xc_domain.c @ 2693:2584528df9e1

bitkeeper revision 1.1159.123.2 (4177d169N58TtQXn_XJO4xNBKbMQUw)

Merge freefall.cl.cam.ac.uk:/auto/groups/xeno/BK/xeno.bk
into freefall.cl.cam.ac.uk:/local/scratch/kaf24/xeno
author kaf24@freefall.cl.cam.ac.uk
date Thu Oct 21 15:10:33 2004 +0000 (2004-10-21)
parents c084a63b2b64 d8e27145f1eb
children 8aa9d487a8dd
line source
1 /******************************************************************************
2 * xc_domain.c
3 *
4 * API for manipulating and obtaining information on domains.
5 *
6 * Copyright (c) 2003, K A Fraser.
7 */
9 #include "xc_private.h"
11 int xc_domain_create(int xc_handle,
12 unsigned int mem_kb,
13 int cpu,
14 float cpu_weight,
15 u32 *pdomid)
16 {
17 int err;
18 dom0_op_t op;
20 op.cmd = DOM0_CREATEDOMAIN;
21 op.u.createdomain.domain = (domid_t)*pdomid;
22 op.u.createdomain.memory_kb = mem_kb;
23 op.u.createdomain.cpu = cpu;
25 if ( (err = do_dom0_op(xc_handle, &op)) == 0 )
26 {
27 *pdomid = (u16)op.u.createdomain.domain;
29 err = xc_domain_setcpuweight(xc_handle, *pdomid, cpu_weight);
30 }
32 return err;
33 }
36 int xc_domain_pause(int xc_handle,
37 u32 domid)
38 {
39 dom0_op_t op;
40 op.cmd = DOM0_PAUSEDOMAIN;
41 op.u.pausedomain.domain = (domid_t)domid;
42 return do_dom0_op(xc_handle, &op);
43 }
46 int xc_domain_unpause(int xc_handle,
47 u32 domid)
48 {
49 dom0_op_t op;
50 op.cmd = DOM0_UNPAUSEDOMAIN;
51 op.u.unpausedomain.domain = (domid_t)domid;
52 return do_dom0_op(xc_handle, &op);
53 }
56 int xc_domain_destroy(int xc_handle,
57 u32 domid)
58 {
59 dom0_op_t op;
60 op.cmd = DOM0_DESTROYDOMAIN;
61 op.u.destroydomain.domain = (domid_t)domid;
62 return do_dom0_op(xc_handle, &op);
63 }
65 int xc_domain_pincpu(int xc_handle,
66 u32 domid,
67 int cpu)
68 {
69 dom0_op_t op;
70 op.cmd = DOM0_PINCPUDOMAIN;
71 op.u.pincpudomain.domain = (domid_t)domid;
72 op.u.pincpudomain.cpu = cpu;
73 return do_dom0_op(xc_handle, &op);
74 }
77 int xc_domain_getinfo(int xc_handle,
78 u32 first_domid,
79 unsigned int max_doms,
80 xc_dominfo_t *info)
81 {
82 unsigned int nr_doms;
83 u32 next_domid = first_domid;
84 dom0_op_t op;
86 for ( nr_doms = 0; nr_doms < max_doms; nr_doms++ )
87 {
88 op.cmd = DOM0_GETDOMAININFO;
89 op.u.getdomaininfo.domain = (domid_t)next_domid;
90 op.u.getdomaininfo.ctxt = NULL; /* no exec context info, thanks. */
91 if ( do_dom0_op(xc_handle, &op) < 0 )
92 break;
93 info->domid = (u16)op.u.getdomaininfo.domain;
95 info->cpu =
96 (op.u.getdomaininfo.flags>>DOMFLAGS_CPUSHIFT) & DOMFLAGS_CPUMASK;
98 info->dying = !!(op.u.getdomaininfo.flags & DOMFLAGS_DYING);
99 info->crashed = !!(op.u.getdomaininfo.flags & DOMFLAGS_CRASHED);
100 info->shutdown = !!(op.u.getdomaininfo.flags & DOMFLAGS_SHUTDOWN);
101 info->paused = !!(op.u.getdomaininfo.flags & DOMFLAGS_PAUSED);
102 info->blocked = !!(op.u.getdomaininfo.flags & DOMFLAGS_BLOCKED);
103 info->running = !!(op.u.getdomaininfo.flags & DOMFLAGS_RUNNING);
105 info->shutdown_reason =
106 (op.u.getdomaininfo.flags>>DOMFLAGS_SHUTDOWNSHIFT) &
107 DOMFLAGS_SHUTDOWNMASK;
109 info->nr_pages = op.u.getdomaininfo.tot_pages;
110 info->max_memkb = op.u.getdomaininfo.max_pages<<(PAGE_SHIFT);
111 info->shared_info_frame = op.u.getdomaininfo.shared_info_frame;
112 info->cpu_time = op.u.getdomaininfo.cpu_time;
114 next_domid = (u16)op.u.getdomaininfo.domain + 1;
115 info++;
116 }
118 return nr_doms;
119 }
121 int xc_domain_getfullinfo(int xc_handle,
122 u32 domid,
123 dom0_op_t *op,
124 full_execution_context_t *ctxt )
125 {
126 int rc;
127 op->cmd = DOM0_GETDOMAININFO;
128 op->u.getdomaininfo.domain = (domid_t)domid;
129 op->u.getdomaininfo.ctxt = ctxt;
131 rc = do_dom0_op(xc_handle, op);
132 if ( ((u16)op->u.getdomaininfo.domain != domid) && rc > 0 )
133 return -ESRCH;
134 else
135 return rc;
136 }
139 int xc_shadow_control(int xc_handle,
140 u32 domid,
141 unsigned int sop,
142 unsigned long *dirty_bitmap,
143 unsigned long pages,
144 xc_shadow_control_stats_t *stats )
145 {
146 int rc;
147 dom0_op_t op;
148 op.cmd = DOM0_SHADOW_CONTROL;
149 op.u.shadow_control.domain = (domid_t)domid;
150 op.u.shadow_control.op = sop;
151 op.u.shadow_control.dirty_bitmap = dirty_bitmap;
152 op.u.shadow_control.pages = pages;
154 rc = do_dom0_op(xc_handle, &op);
156 if ( stats )
157 memcpy(stats, &op.u.shadow_control.stats,
158 sizeof(xc_shadow_control_stats_t));
160 return (rc == 0) ? op.u.shadow_control.pages : rc;
161 }
163 int xc_domain_setcpuweight(int xc_handle,
164 u32 domid,
165 float weight)
166 {
167 int sched_id;
168 int ret;
170 /* Figure out which scheduler is currently used: */
171 if((ret = xc_sched_id(xc_handle, &sched_id)))
172 return ret;
174 switch(sched_id)
175 {
176 case SCHED_BVT:
177 {
178 u32 mcuadv;
179 int warpback;
180 s32 warpvalue;
181 long long warpl;
182 long long warpu;
184 /* Preserve all the scheduling parameters apart
185 of MCU advance. */
186 if((ret = xc_bvtsched_domain_get(xc_handle, domid, &mcuadv,
187 &warpback, &warpvalue, &warpl, &warpu)))
188 return ret;
190 /* The MCU advance is inverse of the weight.
191 Default value of the weight is 1, default mcuadv 10.
192 The scaling factor is therefore 10. */
193 if(weight > 0) mcuadv = 10 / weight;
195 ret = xc_bvtsched_domain_set(xc_handle, domid, mcuadv,
196 warpback, warpvalue, warpl, warpu);
197 break;
198 }
200 case SCHED_RROBIN:
201 {
202 /* The weight cannot be set for RRobin */
203 break;
204 }
205 case SCHED_ATROPOS:
206 {
207 /* TODO - can we set weights in Atropos? */
208 break;
209 }
210 }
212 return ret;
213 }
216 int xc_domain_setinitialmem(int xc_handle,
217 u32 domid,
218 unsigned int initial_memkb)
219 {
220 dom0_op_t op;
221 op.cmd = DOM0_SETDOMAININITIALMEM;
222 op.u.setdomaininitialmem.domain = (domid_t)domid;
223 op.u.setdomaininitialmem.initial_memkb = initial_memkb;
224 return do_dom0_op(xc_handle, &op);
225 }
227 int xc_domain_setmaxmem(int xc_handle,
228 u32 domid,
229 unsigned int max_memkb)
230 {
231 dom0_op_t op;
232 op.cmd = DOM0_SETDOMAINMAXMEM;
233 op.u.setdomainmaxmem.domain = (domid_t)domid;
234 op.u.setdomainmaxmem.max_memkb = max_memkb;
235 return do_dom0_op(xc_handle, &op);
236 }
238 int xc_domain_setvmassist(int xc_handle,
239 u32 domid,
240 unsigned int cmd,
241 unsigned int type)
242 {
243 dom0_op_t op;
244 op.cmd = DOM0_SETDOMAINVMASSIST;
245 op.u.setdomainvmassist.domain = (domid_t)domid;
246 op.u.setdomainvmassist.cmd = cmd;
247 op.u.setdomainvmassist.type = type;
248 return do_dom0_op(xc_handle, &op);
249 }