direct-io.hg

view tools/libxc/xc_domain.c @ 3435:0fd048d86eed

bitkeeper revision 1.1159.220.3 (41e670c37jmaTxUns3KlvsbVRCg-UA)

The getdomaininfo hypercall now listens to the exec_domain parameter
that was already passed to it, and performs some basic sanity checking.

Added exec_domain (aka vcpu) parameters to xc_domain_getfullinfo()
and xc_domain_get_cpu_usage().
author mafetter@fleming.research
date Thu Jan 13 12:59:47 2005 +0000 (2005-01-13)
parents a9ac02b7727d
children 6096356005ba
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.exec_domain = 0;
73 op.u.pincpudomain.cpu = cpu;
74 return do_dom0_op(xc_handle, &op);
75 }
78 int xc_domain_getinfo(int xc_handle,
79 u32 first_domid,
80 unsigned int max_doms,
81 xc_dominfo_t *info)
82 {
83 unsigned int nr_doms;
84 u32 next_domid = first_domid;
85 dom0_op_t op;
87 for ( nr_doms = 0; nr_doms < max_doms; nr_doms++ )
88 {
89 op.cmd = DOM0_GETDOMAININFO;
90 op.u.getdomaininfo.domain = (domid_t)next_domid;
91 op.u.getdomaininfo.exec_domain = 0; // FIX ME?!?
92 op.u.getdomaininfo.ctxt = NULL; /* no exec context info, thanks. */
93 if ( do_dom0_op(xc_handle, &op) < 0 )
94 break;
95 info->domid = (u16)op.u.getdomaininfo.domain;
97 info->cpu =
98 (op.u.getdomaininfo.flags>>DOMFLAGS_CPUSHIFT) & DOMFLAGS_CPUMASK;
100 info->dying = !!(op.u.getdomaininfo.flags & DOMFLAGS_DYING);
101 info->crashed = !!(op.u.getdomaininfo.flags & DOMFLAGS_CRASHED);
102 info->shutdown = !!(op.u.getdomaininfo.flags & DOMFLAGS_SHUTDOWN);
103 info->paused = !!(op.u.getdomaininfo.flags & DOMFLAGS_PAUSED);
104 info->blocked = !!(op.u.getdomaininfo.flags & DOMFLAGS_BLOCKED);
105 info->running = !!(op.u.getdomaininfo.flags & DOMFLAGS_RUNNING);
107 info->shutdown_reason =
108 (op.u.getdomaininfo.flags>>DOMFLAGS_SHUTDOWNSHIFT) &
109 DOMFLAGS_SHUTDOWNMASK;
111 info->nr_pages = op.u.getdomaininfo.tot_pages;
112 info->max_memkb = op.u.getdomaininfo.max_pages<<(PAGE_SHIFT);
113 info->shared_info_frame = op.u.getdomaininfo.shared_info_frame;
114 info->cpu_time = op.u.getdomaininfo.cpu_time;
116 next_domid = (u16)op.u.getdomaininfo.domain + 1;
117 info++;
118 }
120 return nr_doms;
121 }
123 int xc_domain_getfullinfo(int xc_handle,
124 u32 domid,
125 u32 vcpu,
126 xc_domaininfo_t *info,
127 full_execution_context_t *ctxt)
128 {
129 int rc;
130 dom0_op_t op;
132 op.cmd = DOM0_GETDOMAININFO;
133 op.u.getdomaininfo.domain = (domid_t)domid;
134 op.u.getdomaininfo.exec_domain = (u16)vcpu;
135 op.u.getdomaininfo.ctxt = ctxt;
137 rc = do_dom0_op(xc_handle, &op);
139 memcpy(info, &op.u.getdomaininfo, sizeof(*info));
141 if ( ((u16)op.u.getdomaininfo.domain != domid) && rc > 0 )
142 return -ESRCH;
143 else
144 return rc;
145 }
148 int xc_shadow_control(int xc_handle,
149 u32 domid,
150 unsigned int sop,
151 unsigned long *dirty_bitmap,
152 unsigned long pages,
153 xc_shadow_control_stats_t *stats )
154 {
155 int rc;
156 dom0_op_t op;
157 op.cmd = DOM0_SHADOW_CONTROL;
158 op.u.shadow_control.domain = (domid_t)domid;
159 op.u.shadow_control.op = sop;
160 op.u.shadow_control.dirty_bitmap = dirty_bitmap;
161 op.u.shadow_control.pages = pages;
163 rc = do_dom0_op(xc_handle, &op);
165 if ( stats )
166 memcpy(stats, &op.u.shadow_control.stats,
167 sizeof(xc_shadow_control_stats_t));
169 return (rc == 0) ? op.u.shadow_control.pages : rc;
170 }
172 int xc_domain_setcpuweight(int xc_handle,
173 u32 domid,
174 float weight)
175 {
176 int sched_id;
177 int ret;
179 /* Figure out which scheduler is currently used: */
180 if((ret = xc_sched_id(xc_handle, &sched_id)))
181 return ret;
183 switch(sched_id)
184 {
185 case SCHED_BVT:
186 {
187 u32 mcuadv;
188 int warpback;
189 s32 warpvalue;
190 long long warpl;
191 long long warpu;
193 /* Preserve all the scheduling parameters apart
194 of MCU advance. */
195 if((ret = xc_bvtsched_domain_get(xc_handle, domid, &mcuadv,
196 &warpback, &warpvalue, &warpl, &warpu)))
197 return ret;
199 /* The MCU advance is inverse of the weight.
200 Default value of the weight is 1, default mcuadv 10.
201 The scaling factor is therefore 10. */
202 if(weight > 0) mcuadv = 10 / weight;
204 ret = xc_bvtsched_domain_set(xc_handle, domid, mcuadv,
205 warpback, warpvalue, warpl, warpu);
206 break;
207 }
209 case SCHED_RROBIN:
210 {
211 /* The weight cannot be set for RRobin */
212 break;
213 }
214 case SCHED_ATROPOS:
215 {
216 /* TODO - can we set weights in Atropos? */
217 break;
218 }
219 }
221 return ret;
222 }
225 int xc_domain_setinitialmem(int xc_handle,
226 u32 domid,
227 unsigned int initial_memkb)
228 {
229 dom0_op_t op;
230 op.cmd = DOM0_SETDOMAININITIALMEM;
231 op.u.setdomaininitialmem.domain = (domid_t)domid;
232 op.u.setdomaininitialmem.initial_memkb = initial_memkb;
233 return do_dom0_op(xc_handle, &op);
234 }
236 int xc_domain_setmaxmem(int xc_handle,
237 u32 domid,
238 unsigned int max_memkb)
239 {
240 dom0_op_t op;
241 op.cmd = DOM0_SETDOMAINMAXMEM;
242 op.u.setdomainmaxmem.domain = (domid_t)domid;
243 op.u.setdomainmaxmem.max_memkb = max_memkb;
244 return do_dom0_op(xc_handle, &op);
245 }
247 int xc_domain_setvmassist(int xc_handle,
248 u32 domid,
249 unsigned int cmd,
250 unsigned int type)
251 {
252 dom0_op_t op;
253 op.cmd = DOM0_SETDOMAINVMASSIST;
254 op.u.setdomainvmassist.domain = (domid_t)domid;
255 op.u.setdomainvmassist.cmd = cmd;
256 op.u.setdomainvmassist.type = type;
257 return do_dom0_op(xc_handle, &op);
258 }