ia64/xen-unstable

view tools/libxc/xc_domain.c @ 4564:b07029dd30fa

bitkeeper revision 1.1159.258.103 (42642c5djs1dzMOSs-vIJLlGCQyrMQ)

Allow xc_domain_info_t to be optional in xc_domain_getfullinfo
From: Kip Macy
Signed-off-by: ian@xensource.com
author iap10@freefall.cl.cam.ac.uk
date Mon Apr 18 21:53:33 2005 +0000 (2005-04-18)
parents 3f929065a1d1
children 7edc9d4fa41e 18d709f72233
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 xc_domaininfo_t *info,
124 full_execution_context_t *ctxt)
125 {
126 int rc;
127 dom0_op_t op;
129 op.cmd = DOM0_GETDOMAININFO;
130 op.u.getdomaininfo.domain = (domid_t)domid;
131 op.u.getdomaininfo.ctxt = ctxt;
133 rc = do_dom0_op(xc_handle, &op);
135 if ( info )
136 memcpy(info, &op.u.getdomaininfo, sizeof(*info));
138 if ( ((u16)op.u.getdomaininfo.domain != domid) && rc > 0 )
139 return -ESRCH;
140 else
141 return rc;
142 }
145 int xc_shadow_control(int xc_handle,
146 u32 domid,
147 unsigned int sop,
148 unsigned long *dirty_bitmap,
149 unsigned long pages,
150 xc_shadow_control_stats_t *stats )
151 {
152 int rc;
153 dom0_op_t op;
154 op.cmd = DOM0_SHADOW_CONTROL;
155 op.u.shadow_control.domain = (domid_t)domid;
156 op.u.shadow_control.op = sop;
157 op.u.shadow_control.dirty_bitmap = dirty_bitmap;
158 op.u.shadow_control.pages = pages;
160 rc = do_dom0_op(xc_handle, &op);
162 if ( stats )
163 memcpy(stats, &op.u.shadow_control.stats,
164 sizeof(xc_shadow_control_stats_t));
166 return (rc == 0) ? op.u.shadow_control.pages : rc;
167 }
169 int xc_domain_setcpuweight(int xc_handle,
170 u32 domid,
171 float weight)
172 {
173 int sched_id;
174 int ret;
176 /* Figure out which scheduler is currently used: */
177 if((ret = xc_sched_id(xc_handle, &sched_id)))
178 return ret;
180 switch(sched_id)
181 {
182 case SCHED_BVT:
183 {
184 u32 mcuadv;
185 int warpback;
186 s32 warpvalue;
187 long long warpl;
188 long long warpu;
190 /* Preserve all the scheduling parameters apart
191 of MCU advance. */
192 if((ret = xc_bvtsched_domain_get(xc_handle, domid, &mcuadv,
193 &warpback, &warpvalue, &warpl, &warpu)))
194 return ret;
196 /* The MCU advance is inverse of the weight.
197 Default value of the weight is 1, default mcuadv 10.
198 The scaling factor is therefore 10. */
199 if(weight > 0) mcuadv = 10 / weight;
201 ret = xc_bvtsched_domain_set(xc_handle, domid, mcuadv,
202 warpback, warpvalue, warpl, warpu);
203 break;
204 }
206 case SCHED_RROBIN:
207 {
208 /* The weight cannot be set for RRobin */
209 break;
210 }
211 case SCHED_ATROPOS:
212 {
213 /* TODO - can we set weights in Atropos? */
214 break;
215 }
216 }
218 return ret;
219 }
222 int xc_domain_setinitialmem(int xc_handle,
223 u32 domid,
224 unsigned int initial_memkb)
225 {
226 dom0_op_t op;
227 op.cmd = DOM0_SETDOMAININITIALMEM;
228 op.u.setdomaininitialmem.domain = (domid_t)domid;
229 op.u.setdomaininitialmem.initial_memkb = initial_memkb;
230 return do_dom0_op(xc_handle, &op);
231 }
233 int xc_domain_setmaxmem(int xc_handle,
234 u32 domid,
235 unsigned int max_memkb)
236 {
237 dom0_op_t op;
238 op.cmd = DOM0_SETDOMAINMAXMEM;
239 op.u.setdomainmaxmem.domain = (domid_t)domid;
240 op.u.setdomainmaxmem.max_memkb = max_memkb;
241 return do_dom0_op(xc_handle, &op);
242 }
244 int xc_domain_setvmassist(int xc_handle,
245 u32 domid,
246 unsigned int cmd,
247 unsigned int type)
248 {
249 dom0_op_t op;
250 op.cmd = DOM0_SETDOMAINVMASSIST;
251 op.u.setdomainvmassist.domain = (domid_t)domid;
252 op.u.setdomainvmassist.cmd = cmd;
253 op.u.setdomainvmassist.type = type;
254 return do_dom0_op(xc_handle, &op);
255 }