ia64/xen-unstable

view tools/libxc/xc_domain.c @ 2422:2274a0386cc9

bitkeeper revision 1.1159.69.5 (4138e882jA1YaR_OfTfNHe_uT4PDIg)

trivial
author iap10@labyrinth.cl.cam.ac.uk
date Fri Sep 03 21:56:18 2004 +0000 (2004-09-03)
parents 49739c6ac967
children 875c25208085
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 const char *name,
14 int cpu,
15 float cpu_weight,
16 u32 *pdomid)
17 {
18 int err;
19 dom0_op_t op;
21 op.cmd = DOM0_CREATEDOMAIN;
22 op.u.createdomain.domain = (domid_t)*pdomid;
23 op.u.createdomain.memory_kb = mem_kb;
24 strncpy(op.u.createdomain.name, name, MAX_DOMAIN_NAME);
25 op.u.createdomain.name[MAX_DOMAIN_NAME-1] = '\0';
26 op.u.createdomain.cpu = cpu;
28 if ( (err = do_dom0_op(xc_handle, &op)) == 0 )
29 {
30 *pdomid = (u16)op.u.createdomain.domain;
32 err = xc_domain_setcpuweight(xc_handle, *pdomid, cpu_weight);
33 }
35 return err;
36 }
39 int xc_domain_pause(int xc_handle,
40 u32 domid)
41 {
42 dom0_op_t op;
43 op.cmd = DOM0_PAUSEDOMAIN;
44 op.u.pausedomain.domain = (domid_t)domid;
45 return do_dom0_op(xc_handle, &op);
46 }
49 int xc_domain_unpause(int xc_handle,
50 u32 domid)
51 {
52 dom0_op_t op;
53 op.cmd = DOM0_UNPAUSEDOMAIN;
54 op.u.unpausedomain.domain = (domid_t)domid;
55 return do_dom0_op(xc_handle, &op);
56 }
59 int xc_domain_destroy(int xc_handle,
60 u32 domid)
61 {
62 dom0_op_t op;
63 op.cmd = DOM0_DESTROYDOMAIN;
64 op.u.destroydomain.domain = (domid_t)domid;
65 return do_dom0_op(xc_handle, &op);
66 }
68 int xc_domain_pincpu(int xc_handle,
69 u32 domid,
70 int cpu)
71 {
72 dom0_op_t op;
73 op.cmd = DOM0_PINCPUDOMAIN;
74 op.u.pincpudomain.domain = (domid_t)domid;
75 op.u.pincpudomain.cpu = cpu;
76 return do_dom0_op(xc_handle, &op);
77 }
80 int xc_domain_getinfo(int xc_handle,
81 u32 first_domid,
82 unsigned int max_doms,
83 xc_dominfo_t *info)
84 {
85 unsigned int nr_doms;
86 u32 next_domid = first_domid;
87 dom0_op_t op;
89 for ( nr_doms = 0; nr_doms < max_doms; nr_doms++ )
90 {
91 op.cmd = DOM0_GETDOMAININFO;
92 op.u.getdomaininfo.domain = (domid_t)next_domid;
93 op.u.getdomaininfo.ctxt = NULL; /* no exec context info, thanks. */
94 if ( do_dom0_op(xc_handle, &op) < 0 )
95 break;
96 info->domid = (u16)op.u.getdomaininfo.domain;
98 info->cpu =
99 (op.u.getdomaininfo.flags>>DOMFLAGS_CPUSHIFT) & DOMFLAGS_CPUMASK;
101 info->dying = !!(op.u.getdomaininfo.flags & DOMFLAGS_DYING);
102 info->crashed = !!(op.u.getdomaininfo.flags & DOMFLAGS_CRASHED);
103 info->shutdown = !!(op.u.getdomaininfo.flags & DOMFLAGS_SHUTDOWN);
104 info->paused = !!(op.u.getdomaininfo.flags & DOMFLAGS_PAUSED);
105 info->blocked = !!(op.u.getdomaininfo.flags & DOMFLAGS_BLOCKED);
106 info->running = !!(op.u.getdomaininfo.flags & DOMFLAGS_RUNNING);
108 info->shutdown_reason =
109 (op.u.getdomaininfo.flags>>DOMFLAGS_SHUTDOWNSHIFT) &
110 DOMFLAGS_SHUTDOWNMASK;
112 info->nr_pages = op.u.getdomaininfo.tot_pages;
113 info->max_memkb = op.u.getdomaininfo.max_pages<<(PAGE_SHIFT);
114 info->shared_info_frame = op.u.getdomaininfo.shared_info_frame;
115 info->cpu_time = op.u.getdomaininfo.cpu_time;
116 strncpy(info->name, op.u.getdomaininfo.name, XC_DOMINFO_MAXNAME);
117 info->name[XC_DOMINFO_MAXNAME-1] = '\0';
119 next_domid = (u16)op.u.getdomaininfo.domain + 1;
120 info++;
121 }
123 return nr_doms;
124 }
126 int xc_domain_getfullinfo(int xc_handle,
127 u32 domid,
128 dom0_op_t *op,
129 full_execution_context_t *ctxt )
130 {
131 int rc;
132 op->cmd = DOM0_GETDOMAININFO;
133 op->u.getdomaininfo.domain = (domid_t)domid;
134 op->u.getdomaininfo.ctxt = ctxt;
136 rc = do_dom0_op(xc_handle, op);
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_setname(int xc_handle,
169 u32 domid,
170 char *name)
171 {
172 dom0_op_t op;
173 op.cmd = DOM0_SETDOMAINNAME;
174 op.u.setdomainname.domain = (domid_t)domid;
175 strncpy(op.u.setdomainname.name, name, MAX_DOMAIN_NAME);
176 return do_dom0_op(xc_handle, &op);
177 }
179 int xc_domain_setcpuweight(int xc_handle,
180 u32 domid,
181 float weight)
182 {
183 int sched_id;
184 int ret;
186 /* Figure out which scheduler is currently used: */
187 if((ret = xc_sched_id(xc_handle, &sched_id)))
188 return ret;
190 switch(sched_id)
191 {
192 case SCHED_BVT:
193 {
194 u32 mcuadv;
195 int warpback;
196 s32 warpvalue;
197 long long warpl;
198 long long warpu;
200 /* Preserve all the scheduling parameters apart
201 of MCU advance. */
202 if((ret = xc_bvtsched_domain_get(xc_handle, domid, &mcuadv,
203 &warpback, &warpvalue, &warpl, &warpu)))
204 return ret;
206 /* The MCU advance is inverse of the weight.
207 Default value of the weight is 1, default mcuadv 10.
208 The scaling factor is therefore 10. */
209 if(weight > 0) mcuadv = 10 / weight;
211 ret = xc_bvtsched_domain_set(xc_handle, domid, mcuadv,
212 warpback, warpvalue, warpl, warpu);
213 break;
214 }
216 case SCHED_FBVT:
217 {
218 // TODO
219 break;
220 }
221 case SCHED_RROBIN:
222 {
223 /* The weight cannot be set for RRobin */
224 break;
225 }
226 case SCHED_ATROPOS:
227 {
228 /* TODO - can we set weights in Atropos? */
229 break;
230 }
231 }
233 return ret;
234 }
237 int xc_domain_setinitialmem(int xc_handle,
238 u32 domid,
239 unsigned int initial_memkb)
240 {
241 dom0_op_t op;
242 op.cmd = DOM0_SETDOMAININITIALMEM;
243 op.u.setdomaininitialmem.domain = (domid_t)domid;
244 op.u.setdomaininitialmem.initial_memkb = initial_memkb;
245 return do_dom0_op(xc_handle, &op);
246 }
248 int xc_domain_setmaxmem(int xc_handle,
249 u32 domid,
250 unsigned int max_memkb)
251 {
252 dom0_op_t op;
253 op.cmd = DOM0_SETDOMAINMAXMEM;
254 op.u.setdomainmaxmem.domain = (domid_t)domid;
255 op.u.setdomainmaxmem.max_memkb = max_memkb;
256 return do_dom0_op(xc_handle, &op);
257 }