direct-io.hg

view tools/libxc/xc_domain.c @ 2787:a5c335665fd6

bitkeeper revision 1.1159.142.2 (41849fadYlUYMwSy6tcq8Y-Yi8NMZA)

Clean up libxc by allowing direct use of Xen headers from userland:
#include <xen/...>
author kaf24@freefall.cl.cam.ac.uk
date Sun Oct 31 08:17:49 2004 +0000 (2004-10-31)
parents 8aa9d487a8dd
children 3f929065a1d1
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 memcpy(info, &op.u.getdomaininfo, sizeof(*info));
137 if ( ((u16)op.u.getdomaininfo.domain != domid) && rc > 0 )
138 return -ESRCH;
139 else
140 return rc;
141 }
144 int xc_shadow_control(int xc_handle,
145 u32 domid,
146 unsigned int sop,
147 unsigned long *dirty_bitmap,
148 unsigned long pages,
149 xc_shadow_control_stats_t *stats )
150 {
151 int rc;
152 dom0_op_t op;
153 op.cmd = DOM0_SHADOW_CONTROL;
154 op.u.shadow_control.domain = (domid_t)domid;
155 op.u.shadow_control.op = sop;
156 op.u.shadow_control.dirty_bitmap = dirty_bitmap;
157 op.u.shadow_control.pages = pages;
159 rc = do_dom0_op(xc_handle, &op);
161 if ( stats )
162 memcpy(stats, &op.u.shadow_control.stats,
163 sizeof(xc_shadow_control_stats_t));
165 return (rc == 0) ? op.u.shadow_control.pages : rc;
166 }
168 int xc_domain_setcpuweight(int xc_handle,
169 u32 domid,
170 float weight)
171 {
172 int sched_id;
173 int ret;
175 /* Figure out which scheduler is currently used: */
176 if((ret = xc_sched_id(xc_handle, &sched_id)))
177 return ret;
179 switch(sched_id)
180 {
181 case SCHED_BVT:
182 {
183 u32 mcuadv;
184 int warpback;
185 s32 warpvalue;
186 long long warpl;
187 long long warpu;
189 /* Preserve all the scheduling parameters apart
190 of MCU advance. */
191 if((ret = xc_bvtsched_domain_get(xc_handle, domid, &mcuadv,
192 &warpback, &warpvalue, &warpl, &warpu)))
193 return ret;
195 /* The MCU advance is inverse of the weight.
196 Default value of the weight is 1, default mcuadv 10.
197 The scaling factor is therefore 10. */
198 if(weight > 0) mcuadv = 10 / weight;
200 ret = xc_bvtsched_domain_set(xc_handle, domid, mcuadv,
201 warpback, warpvalue, warpl, warpu);
202 break;
203 }
205 case SCHED_RROBIN:
206 {
207 /* The weight cannot be set for RRobin */
208 break;
209 }
210 case SCHED_ATROPOS:
211 {
212 /* TODO - can we set weights in Atropos? */
213 break;
214 }
215 }
217 return ret;
218 }
221 int xc_domain_setinitialmem(int xc_handle,
222 u32 domid,
223 unsigned int initial_memkb)
224 {
225 dom0_op_t op;
226 op.cmd = DOM0_SETDOMAININITIALMEM;
227 op.u.setdomaininitialmem.domain = (domid_t)domid;
228 op.u.setdomaininitialmem.initial_memkb = initial_memkb;
229 return do_dom0_op(xc_handle, &op);
230 }
232 int xc_domain_setmaxmem(int xc_handle,
233 u32 domid,
234 unsigned int max_memkb)
235 {
236 dom0_op_t op;
237 op.cmd = DOM0_SETDOMAINMAXMEM;
238 op.u.setdomainmaxmem.domain = (domid_t)domid;
239 op.u.setdomainmaxmem.max_memkb = max_memkb;
240 return do_dom0_op(xc_handle, &op);
241 }
243 int xc_domain_setvmassist(int xc_handle,
244 u32 domid,
245 unsigned int cmd,
246 unsigned int type)
247 {
248 dom0_op_t op;
249 op.cmd = DOM0_SETDOMAINVMASSIST;
250 op.u.setdomainvmassist.domain = (domid_t)domid;
251 op.u.setdomainvmassist.cmd = cmd;
252 op.u.setdomainvmassist.type = type;
253 return do_dom0_op(xc_handle, &op);
254 }