Test results in the following output: $ perl examples/iothreadsinfo.pl Addr VMM type: QEMU ... Domain: { ID: 2 'f18iothr' UUID: fb9f7826-b5d7-4f74-b962-7181ef3fc9ec IOThread: { affinity: 0010 number: 1 } IOThread: { affinity: 0001 number: 2 } IOThread: { affinity: 1100 number: 3 } }
Signed-off-by: John Ferlan <jfer...@redhat.com> --- Changes | 2 +- Virt.xs | 42 ++++++++++++++++++++++++++++++++++++++++++ examples/iothreadsinfo.pl | 33 +++++++++++++++++++++++++++++++++ lib/Sys/Virt/Domain.pm | 17 +++++++++++++++++ 4 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 examples/iothreadsinfo.pl diff --git a/Changes b/Changes index b62ee24..88f648c 100644 --- a/Changes +++ b/Changes @@ -2,7 +2,7 @@ Revision history for perl module Sys::Virt 1.2.14 2015-00-00 - - XXX + - Add virDomainGetIOThreads and virDomainPinIOThread API bindings 1.2.13 2015-03-05 diff --git a/Virt.xs b/Virt.xs index f9ec7a4..56e143d 100644 --- a/Virt.xs +++ b/Virt.xs @@ -5014,6 +5014,48 @@ get_emulator_pin_info(dom, flags=0) RETVAL +void +get_iothread_info(dom, flags=0) + virDomainPtr dom; + unsigned int flags; + PREINIT: + virDomainIOThreadInfoPtr *iothrinfo; + int niothreads; + int i; + PPCODE: + if ((niothreads = virDomainGetIOThreadsInfo(dom, &iothrinfo, + flags)) < 0) + _croak_error(); + + EXTEND(SP, niothreads); + for (i = 0 ; i < niothreads ; i++) { + HV *rec = newHV(); + (void)hv_store(rec, "number", 6, + newSViv(iothrinfo[i]->iothread_id), 0); + (void)hv_store(rec, "affinity", 8, + newSVpvn((char*)iothrinfo[i]->cpumap, + iothrinfo[i]->cpumaplen), 0); + PUSHs(newRV_noinc((SV *)rec)); + } + + Safefree(iothrinfo); + + +void +pin_iothread(dom, iothread_id, mask, flags=0) + virDomainPtr dom; + unsigned int iothread_id; + SV *mask; + unsigned int flags; +PREINIT: + STRLEN masklen; + unsigned char *maps; + PPCODE: + maps = (unsigned char *)SvPV(mask, masklen); + if (virDomainPinVcpuFlags(dom, iothread_id, maps, masklen, flags) < 0) + _croak_error(); + + int num_of_snapshots(dom, flags=0) virDomainPtr dom; diff --git a/examples/iothreadsinfo.pl b/examples/iothreadsinfo.pl new file mode 100644 index 0000000..97c5eb6 --- /dev/null +++ b/examples/iothreadsinfo.pl @@ -0,0 +1,33 @@ +# -*- perl -*- +use strict; +use warnings; +use Sys::Virt; + +my $addr = @ARGV ? shift @ARGV : ""; +print "Addr $addr\n"; +my $con = Sys::Virt->new(address => $addr, readonly => 1); + +print "VMM type: ", $con->get_type(), "\n"; + +foreach my $dom (sort { $a->get_id <=> $b->get_id } $con->list_all_domains) { + print "Domain: {\n"; + print " ID: ", $dom->get_id(), " '" , $dom->get_name(), "'\n"; + print " UUID: ", $dom->get_uuid_string(), "\n"; + my $nodeinfo = $con->get_node_info; + my @info = $dom->get_iothread_info(Sys::Virt::Domain::AFFECT_CONFIG); + + foreach my $info (@info) { + print " IOThread: {\n"; + foreach (sort { $a cmp $b } keys %{$info}) { + if ($_ eq "affinity") { + print " ", $_, ": "; + my @bits = split(//, unpack("b$nodeinfo->{cpus}", $info->{$_})); + print join ("", @bits), "\n"; + } else { + print " ", $_, ": ", $info->{$_}, "\n"; + } + } + print " }\n"; + } + print "}\n"; +} diff --git a/lib/Sys/Virt/Domain.pm b/lib/Sys/Virt/Domain.pm index 5c8ef47..062c012 100644 --- a/lib/Sys/Virt/Domain.pm +++ b/lib/Sys/Virt/Domain.pm @@ -1216,6 +1216,23 @@ 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 @iothreadinfo = $dom->get_iothread_info($flags=0) + +Obtain information about the state of all IOThreads in a running +guest domain. The returned list will have one element for each IOThread, +where each elements contains a hash reference. The keys in the hash +are, C<number> the IOThread number and C<affinity> giving the allowed +schedular placement. The value for C<affinity> is a +string representing a bitmask against physical CPUs, 8 cpus per +character. To extract the bits use the C<unpack> function with +the C<b*> template. + +=item $dom->pin_iothread($iothread, $mask) + +Pin the IOThread given by index C<$iothread> to physical CPUs +given by C<$mask>. The C<$mask> is a string representing a bitmask +against physical CPUs, 8 cpus per character. + =item my @stats = $dom->get_cpu_stats($startCpu, $numCpus, $flags=0) Requests the guests host physical CPU usage statistics, starting -- 2.1.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list