On Mon, Sep 05, 2022 at 09:40:57AM +0200, Michal Privoznik wrote: > For domains started under session URI, we don't set up CGroups > (well, how could we since we're not running as root anyways). > Nevertheless, fetching CPU statistics exits early because of > lacking cpuacct controller. But with recent extension to > virProcessGetStatInfo() we can get the values we need from the > proc filesystem. Implement the fallback for the session URI as > some of virt tools rely on cpu.* stats to be reported (virt-top, > virt-manager). > > Resolves: https://gitlab.com/libvirt/libvirt/-/issues/353 > Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1693707 > Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> > --- > src/qemu/qemu_driver.c | 35 +++++++++++++++++++++++++++++++++-- > 1 file changed, 33 insertions(+), 2 deletions(-) > > diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c > index d7283a6e47..c7cca64001 100644 > --- a/src/qemu/qemu_driver.c > +++ b/src/qemu/qemu_driver.c > @@ -17765,6 +17765,30 @@ qemuDomainGetStatsCpuCgroup(virDomainObj *dom, > return 0; > } > > + > +static int > +qemuDomainGetStatsCpuProc(virDomainObj *vm, > + virTypedParamList *params) > +{ > + unsigned long long cpuTime = 0; > + unsigned long long sysTime = 0; > + unsigned long long userTime = 0; > + > + if (virProcessGetStatInfo(&cpuTime, &sysTime, &userTime, > + NULL, NULL, vm->pid, 0) < 0) { > + /* ignore error */ > + return 0; > + } This has upset the static analysis in coverity: *** CID 398935: API usage errors (SWAPPED_ARGUMENTS) /src/qemu/qemu_driver.c: 17777 in qemuDomainGetStatsCpuProc() 17771 virTypedParamList *params) 17772 { 17773 unsigned long long cpuTime = 0; 17774 unsigned long long sysTime = 0; 17775 unsigned long long userTime = 0; 17776 >>> CID 398935: API usage errors (SWAPPED_ARGUMENTS) >>> The positions of arguments in the call to "virProcessGetStatInfo" do not match the ordering of the parameters: * "&sysTime" is passed to "userTime". * "&userTime" is passed to "sysTime". 17777 if (virProcessGetStatInfo(&cpuTime, &sysTime, &userTime, 17778 NULL, NULL, vm->pid, 0) < 0) { 17779 /* ignore error */ 17780 return 0; 17781 } 17782 With regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|