mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 10:40:03 +01:00
[LIBXC] Convert between byte-based and 64-bit bitmap arrays. Use this
for conversion of the domctl_cpumap. Original patch from Jimi Xenidis <jimix@watson.ibm.com> Signed-off-by: Keir Fraser <keir@xensource.com>
This commit is contained in:
1 parent
060fe1405f
commit
e74411be0b
3 files changed
+47
-10
No files matched your search
+13
-10
@@ -96,16 +96,19 @@ int xc_vcpu_setaffinity(int xc_handle,
|
||||
{
|
||||
DECLARE_DOMCTL;
|
||||
int ret = -1;
|
||||
uint8_t local[sizeof (cpumap)];
|
||||
|
||||
domctl.cmd = XEN_DOMCTL_setvcpuaffinity;
|
||||
domctl.domain = (domid_t)domid;
|
||||
domctl.u.vcpuaffinity.vcpu = vcpu;
|
||||
|
||||
set_xen_guest_handle(domctl.u.vcpuaffinity.cpumap.bitmap,
|
||||
(uint8_t *)&cpumap);
|
||||
bitmap_64_to_byte(local, &cpumap, sizeof (cpumap));
|
||||
|
||||
set_xen_guest_handle(domctl.u.vcpuaffinity.cpumap.bitmap, local);
|
||||
|
||||
domctl.u.vcpuaffinity.cpumap.nr_cpus = sizeof(cpumap) * 8;
|
||||
|
||||
if ( lock_pages(&cpumap, sizeof(cpumap)) != 0 )
|
||||
if ( lock_pages(local, sizeof(local)) != 0 )
|
||||
{
|
||||
PERROR("Could not lock memory for Xen hypercall");
|
||||
goto out;
|
||||
@@ -113,7 +116,7 @@ int xc_vcpu_setaffinity(int xc_handle,
|
||||
|
||||
ret = do_domctl(xc_handle, &domctl);
|
||||
|
||||
unlock_pages(&cpumap, sizeof(cpumap));
|
||||
unlock_pages(local, sizeof(local));
|
||||
|
||||
out:
|
||||
return ret;
|
||||
@@ -127,16 +130,16 @@ int xc_vcpu_getaffinity(int xc_handle,
|
||||
{
|
||||
DECLARE_DOMCTL;
|
||||
int ret = -1;
|
||||
uint8_t local[sizeof (cpumap)];
|
||||
|
||||
domctl.cmd = XEN_DOMCTL_getvcpuaffinity;
|
||||
domctl.domain = (domid_t)domid;
|
||||
domctl.u.vcpuaffinity.vcpu = vcpu;
|
||||
|
||||
set_xen_guest_handle(domctl.u.vcpuaffinity.cpumap.bitmap,
|
||||
(uint8_t *)cpumap);
|
||||
domctl.u.vcpuaffinity.cpumap.nr_cpus = sizeof(*cpumap) * 8;
|
||||
set_xen_guest_handle(domctl.u.vcpuaffinity.cpumap.bitmap, local);
|
||||
domctl.u.vcpuaffinity.cpumap.nr_cpus = sizeof(cpumap) * 8;
|
||||
|
||||
if ( lock_pages(cpumap, sizeof(*cpumap)) != 0 )
|
||||
if ( lock_pages(local, sizeof(local)) != 0 )
|
||||
{
|
||||
PERROR("Could not lock memory for Xen hypercall");
|
||||
goto out;
|
||||
@@ -144,8 +147,8 @@ int xc_vcpu_getaffinity(int xc_handle,
|
||||
|
||||
ret = do_domctl(xc_handle, &domctl);
|
||||
|
||||
unlock_pages(cpumap, sizeof(*cpumap));
|
||||
|
||||
unlock_pages(local, sizeof (local));
|
||||
bitmap_byte_to_64(cpumap, local, sizeof (local));
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -502,6 +502,37 @@ char *safe_strerror(int errcode)
|
||||
return errbuf;
|
||||
}
|
||||
|
||||
void bitmap_64_to_byte(uint8_t *bp, const uint64_t *lp, int nbits)
|
||||
{
|
||||
uint64_t l;
|
||||
int i, j, b;
|
||||
|
||||
for (i = 0, b = 0; nbits > 0; i++, b += sizeof(l)) {
|
||||
l = lp[i];
|
||||
for (j = 0; (j < sizeof(l)) && (nbits > 0); j++) {
|
||||
bp[b+j] = l;
|
||||
l >>= 8;
|
||||
nbits -= 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void bitmap_byte_to_64(uint64_t *lp, const uint8_t *bp, int nbits)
|
||||
{
|
||||
uint64_t l;
|
||||
int i, j, b;
|
||||
|
||||
for (i = 0, b = 0; nbits > 0; i++, b += sizeof(l)) {
|
||||
l = 0;
|
||||
for (j = 0; (j < sizeof(l)) && (nbits > 0); j++) {
|
||||
l <<= 8;
|
||||
l |= bp[b+j];
|
||||
nbits -= 8;
|
||||
}
|
||||
lp[i] = l;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* mode: C
|
||||
|
||||
@@ -155,4 +155,7 @@ void *map_domain_va_core(unsigned long domfd, int cpu, void *guest_va,
|
||||
int xc_waitdomain_core(int xc_handle, int domain, int *status,
|
||||
int options, vcpu_guest_context_t *ctxt);
|
||||
|
||||
void bitmap_64_to_byte(uint8_t *bp, const uint64_t *lp, int nbits);
|
||||
void bitmap_byte_to_64(uint64_t *lp, const uint8_t *bp, int nbits);
|
||||
|
||||
#endif /* __XC_PRIVATE_H__ */
|
||||