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 <jferlan@xxxxxxxxxx> --- Figured I'd post these just to have them "ready" once the pinning options for IOThreads are done being reviewed. Also running the Perl bindings did find one issue regarding the already pushed GetIOThreadsInfo with respect to ReadOnly bit checking (when it shouldn't have been) - a patch to resolve that has been posted as well. Changes | 4 ++++ Virt.xs | 43 +++++++++++++++++++++++++++++++++++++++++++ examples/iothreadsinfo.pl | 36 ++++++++++++++++++++++++++++++++++++ lib/Sys/Virt/Domain.pm | 17 +++++++++++++++++ 4 files changed, 100 insertions(+) create mode 100644 examples/iothreadsinfo.pl diff --git a/Changes b/Changes index b62ee24..f3e2f83 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ Revision history for perl module Sys::Virt +1.2.14 2015-03-06 + + - Add virDomainGetIOThreads and virDomainPinIOThread API bindings + 1.2.14 2015-00-00 - XXX diff --git a/Virt.xs b/Virt.xs index f9ec7a4..15d48f7 100644 --- a/Virt.xs +++ b/Virt.xs @@ -5014,6 +5014,49 @@ 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)); + } + + if (iothrinfo) + 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..c527e8c --- /dev/null +++ b/examples/iothreadsinfo.pl @@ -0,0 +1,36 @@ +# -*- 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 @mask = split //, $info->{$_}; + for (my $p = 0 ; $p < $nodeinfo->{cpus} ; $p++) { + print ((ord($mask[$p/8]) & (1 << ($p % 8))) ? 1 : 0); + } + print "\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@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list