Commit 7a521d7d authored by Daniel P. Berrange's avatar Daniel P. Berrange

Implement emulator CPU affinity APIs

Signed-off-by: 's avatarDaniel P. Berrange <berrange@redhat.com>
parent 6fa8712e
......@@ -3971,6 +3971,46 @@ PREINIT:
}
void
pin_emulator(dom, mask, flags=0)
virDomainPtr dom;
SV *mask;
unsigned int flags;
PREINIT:
STRLEN masklen;
unsigned char *maps;
PPCODE:
maps = (unsigned char *)SvPV(mask, masklen);
if (virDomainPinEmulator(dom, maps, masklen, flags) < 0)
_croak_error();
SV *
get_emulator_pin_info(dom, flags=0)
virDomainPtr dom;
unsigned int flags;
PREINIT:
unsigned char *cpumaps;
int maplen;
virNodeInfo nodeinfo;
int nCpus;
CODE:
if (virNodeGetInfo(virDomainGetConnect(dom), &nodeinfo) < 0)
_croak_error();
nCpus = VIR_NODEINFO_MAXCPUS(nodeinfo);
maplen = VIR_CPU_MAPLEN(nCpus);
Newx(cpumaps, maplen, unsigned char);
if ((virDomainGetEmulatorPinInfo(dom, cpumaps, maplen, flags)) < 0) {
Safefree(cpumaps);
_croak_error();
}
RETVAL = newSVpvn((char*)cpumaps, maplen);
Safefree(cpumaps);
OUTPUT:
RETVAL
int
num_of_snapshots(dom, flags=0)
virDomainPtr dom;
......
#!/usr/bin/perl
use Sys::Virt;
my $uri = shift @ARGV;
my $c = Sys::Virt->new(uri => $uri);
my $d = $c->get_domain_by_name("vm1");
unless ($d->is_active()) {
$d->create;
}
my $mask = $d->get_emulator_pin_info;
@bits = split(//, unpack("b*", $mask));
print join(":", @bits), "\n";
if ($bits[0] == '1' && $bits[1] == '1') {
@bits[0] = 0;
my $newmask = '';
for(my $i = 0 ; $i <= $#bits ; $i++) {
vec($newmask, $i, 1) = $bits[$i];
}
@bits = split(//, unpack("b*", $newmask));
print join(":", @bits), "\n";
$d->pin_emulator($newmask);
$newermask = $d->get_emulator_pin_info;
@bits = split(//, unpack("b*", $newermask));
print join(":", @bits), "\n";
$d->pin_emulator($mask);
$newermask = $d->get_emulator_pin_info;
@bits = split(//, unpack("b*", $newermask));
print join(":", @bits), "\n";
}
......@@ -904,14 +904,30 @@ vCPU is currently scheduled, C<cpuTime> the cummulative execution
time of the vCPU, C<state> the running state and C<affinity> giving
the allowed shedular placement. The value for C<affinity> is a
string representing a bitmask against physical CPUs, 8 cpus per
character.
character. To extract the bits use the C<unpack> function with
the C<b*> template.
=item $dom->pin_vcpu($vcpu, $mask)
Ping the virtual CPU given by index C<$vcpu> to physical CPUs
Pin the virtual CPU given by index C<$vcpu> to physical CPUs
given by C<$mask>. The C<$mask> is a string representing a bitmask
against physical CPUs, 8 cpus per character.
=item $mask = $dom->get_emulator_pin_info()
Obtain information about the CPU affinity of the emulator process.
The returned C<$mask> is a bitstring against physical CPUs, 8 cpus
per character. To extract the bits use the C<unpack> function with
the C<b*> template.
=item $dom->pin_emulator($newmask, $flags=0)
Pin the emulator threads to the physical CPUs identified by the
affinity in C<$newmask>. The C<$newmask> is a bitstring against
the physical CPUa, 8 cpus per character. To create a suitable
bitstring, use the C<vec> function with a value of C<1> for the
C<BITS> parameter.
=item my @stats = $dom->get_cpu_stats($startCpu, $numCpus, $flags=0)
Requests the guests host physical CPU usage statistics, starting
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment