From nobody Sat May 18 06:04:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1662363725; cv=none; d=zohomail.com; s=zohoarc; b=GT6dVwtF/5cZWazDh1oS2mYsLTfALyVSAFW2+eyJ/yNHPbRFMi/wgWUx3nWXRO/m5R+V9LFQxAEfG4aTQLS/CS/Q/nfLNIZjVhKN0pDAoeUGYEVsFk8eq76AcR1yOgSX5Yv3NUyqW5IYlFcl6tKzbS5Nu4TStTIsOTQIqjlIA5w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662363725; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=5vyttXmScFpa5oQiKRFj2/B3GMSox5iBYNgGH7gxwjs=; b=F49AKyi+b9j6hdWuMWmYQ5gsf8yBduKf44uraUR1XDoz7U9j6R9hVoTcyYUPIouHpovPEytKRfATtDTHR19SjURYJ5XkQtAySRX7zi+gw6Qia47ZrRu11Y9bXY3QuJM8VqMH1w9iHXDIuGtPA/xV0NHcj5NY1V7p3vZg8BJwtPY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 166236372557565.55545996669946; Mon, 5 Sep 2022 00:42:05 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-361-Nn-SIyQtO22nrZDeCeYsjA-1; Mon, 05 Sep 2022 03:41:04 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 60314811E81; Mon, 5 Sep 2022 07:41:02 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id BAFF214152E1; Mon, 5 Sep 2022 07:41:01 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 5A94C194E014; Mon, 5 Sep 2022 07:41:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 1A3981946A47 for ; Mon, 5 Sep 2022 07:40:59 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 0D761C15BBD; Mon, 5 Sep 2022 07:40:59 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id ADA3CC15BB3 for ; Mon, 5 Sep 2022 07:40:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662363724; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=5vyttXmScFpa5oQiKRFj2/B3GMSox5iBYNgGH7gxwjs=; b=gb7xzkJMn0vXwW/tSj3srzYeC9uEwM90/f7j5g8c5/juClR5gcT+GF5etU2z1WqEnoil3A q5HEKifmOG0qnC2MR4pvUGwMlzzDw7bDtnRqQazr62gLKdXFAnxC6sI2Q73/+fnS1a/0Jr m9gQ2tyyRQZyL/hrtxgZSrbOnuVrEBo= X-MC-Unique: Nn-SIyQtO22nrZDeCeYsjA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/2] util: Extend virProcessGetStatInfo() for sysTime and userTime Date: Mon, 5 Sep 2022 09:40:56 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1662363726760100001 Content-Type: text/plain; charset="utf-8"; x-default="true" The virProcessGetStatInfo() helper parses /proc stat file for given PID and/or TID and reports cumulative cpuTime which is just a sum of user and sys times. But in near future, we'll need those times separately, so make the function return them too (if caller desires). Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/ch/ch_driver.c | 1 + src/qemu/qemu_driver.c | 4 +++- src/util/virprocess.c | 30 +++++++++++++++++++++++------- src/util/virprocess.h | 2 ++ 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/ch/ch_driver.c b/src/ch/ch_driver.c index e7c172c894..bde148075d 100644 --- a/src/ch/ch_driver.c +++ b/src/ch/ch_driver.c @@ -1075,6 +1075,7 @@ chDomainHelperGetVcpus(virDomainObj *vm, vcpuinfo->number =3D i; vcpuinfo->state =3D VIR_VCPU_RUNNING; if (virProcessGetStatInfo(&vcpuinfo->cpuTime, + NULL, NULL, &vcpuinfo->cpu, NULL, vm->pid, vcpupid) < 0) { virReportSystemError(errno, "%s", diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 707f4cc1bb..d7283a6e47 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1360,6 +1360,7 @@ qemuDomainHelperGetVcpus(virDomainObj *vm, vcpuinfo->state =3D VIR_VCPU_RUNNING; =20 if (virProcessGetStatInfo(&vcpuinfo->cpuTime, + NULL, NULL, &vcpuinfo->cpu, NULL, vm->pid, vcpupid) < 0) { virReportSystemError(errno, "%s", @@ -2516,6 +2517,7 @@ qemuDomainGetInfo(virDomainPtr dom, =20 if (virDomainObjIsActive(vm)) { if (virProcessGetStatInfo(&(info->cpuTime), NULL, NULL, + NULL, NULL, vm->pid, 0) < 0) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("cannot read cputime for domain")); @@ -10676,7 +10678,7 @@ qemuDomainMemoryStatsInternal(virDomainObj *vm, ret =3D 0; } =20 - if (virProcessGetStatInfo(NULL, NULL, &rss, vm->pid, 0) < 0) { + if (virProcessGetStatInfo(NULL, NULL, NULL, NULL, &rss, vm->pid, 0) < = 0) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("cannot get RSS for domain")); } else { diff --git a/src/util/virprocess.c b/src/util/virprocess.c index 013afd91b4..4cc75b8b45 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -1737,19 +1737,24 @@ virProcessGetStat(pid_t pid, #ifdef __linux__ int virProcessGetStatInfo(unsigned long long *cpuTime, + unsigned long long *sysTime, + unsigned long long *userTime, int *lastCpu, long *vm_rss, pid_t pid, pid_t tid) { g_auto(GStrv) proc_stat =3D virProcessGetStat(pid, tid); - unsigned long long usertime =3D 0, systime =3D 0; + unsigned long long utime =3D 0; + unsigned long long stime =3D 0; + const unsigned long long jiff2sec =3D 1000ull * 1000ull * 1000ull / + (unsigned long long) sysconf(_SC_C= LK_TCK); long rss =3D 0; int cpu =3D 0; =20 if (!proc_stat || - virStrToLong_ullp(proc_stat[VIR_PROCESS_STAT_UTIME], NULL, 10, &us= ertime) < 0 || - virStrToLong_ullp(proc_stat[VIR_PROCESS_STAT_STIME], NULL, 10, &sy= stime) < 0 || + virStrToLong_ullp(proc_stat[VIR_PROCESS_STAT_UTIME], NULL, 10, &ut= ime) < 0 || + virStrToLong_ullp(proc_stat[VIR_PROCESS_STAT_STIME], NULL, 10, &st= ime) < 0 || virStrToLong_l(proc_stat[VIR_PROCESS_STAT_RSS], NULL, 10, &rss) < = 0 || virStrToLong_i(proc_stat[VIR_PROCESS_STAT_PROCESSOR], NULL, 10, &c= pu) < 0) { VIR_WARN("cannot parse process status data"); @@ -1758,11 +1763,16 @@ virProcessGetStatInfo(unsigned long long *cpuTime, /* We got jiffies * We want nanoseconds * _SC_CLK_TCK is jiffies per second - * So calculate thus.... + * So calculate this.... */ + utime *=3D jiff2sec; + stime *=3D jiff2sec; if (cpuTime) - *cpuTime =3D 1000ull * 1000ull * 1000ull * (usertime + systime) - / (unsigned long long) sysconf(_SC_CLK_TCK); + *cpuTime =3D utime + stime; + if (sysTime) + *sysTime =3D stime; + if (userTime) + *userTime =3D utime; if (lastCpu) *lastCpu =3D cpu; =20 @@ -1771,7 +1781,7 @@ virProcessGetStatInfo(unsigned long long *cpuTime, =20 =20 VIR_DEBUG("Got status for %d/%d user=3D%llu sys=3D%llu cpu=3D%d rss=3D= %ld", - (int) pid, tid, usertime, systime, cpu, rss); + (int) pid, tid, utime, stime, cpu, rss); =20 return 0; } @@ -1844,6 +1854,8 @@ virProcessGetSchedInfo(unsigned long long *cpuWait, #else int virProcessGetStatInfo(unsigned long long *cpuTime, + unsigned long long *sysTime, + unsigned long long *userTime, int *lastCpu, long *vm_rss, pid_t pid G_GNUC_UNUSED, @@ -1853,6 +1865,10 @@ virProcessGetStatInfo(unsigned long long *cpuTime, * platforms, so just report neutral values */ if (cpuTime) *cpuTime =3D 0; + if (sysTime) + *sysTime =3D 0; + if (userTime) + *userTime =3D 0; if (lastCpu) *lastCpu =3D 0; if (vm_rss) diff --git a/src/util/virprocess.h b/src/util/virprocess.h index 30b6981c73..b70a405d9f 100644 --- a/src/util/virprocess.h +++ b/src/util/virprocess.h @@ -195,6 +195,8 @@ typedef enum { int virProcessNamespaceAvailable(unsigned int ns); =20 int virProcessGetStatInfo(unsigned long long *cpuTime, + unsigned long long *sysTime, + unsigned long long *userTime, int *lastCpu, long *vm_rss, pid_t pid, --=20 2.35.1 From nobody Sat May 18 06:04:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1662363728; cv=none; d=zohomail.com; s=zohoarc; b=ORB+OXmMeUgirpeV+YNfHljI+WgtPnDGItG25FsFoe5VBQrtqKqKKaQ6RW+EGCHEhvKtMR+rQT1oW0eS8Vs0WTM6YXZZh2tzok4YBWAyHAp6V25ZW/qeUEQoNgVLSgQjiIVOsDZz1air0YUoDSx9Y09XLxuzM+k6i1Et0VzL4CM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662363728; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6INGi3T/KVhNJUeI2qzGf/Ut6YiQdEJqVjE/KaCEvBU=; b=QgE1dngrwiZ0kGHufGyzpYMy1G8qxJDiB1H3b5Nylf4Gk3EcElRdDUIEuCvFWLdWKLB5gCSJ2muiblGCcjE5a0dy+6ofHY9H3b3KC+Zg3NFxPOZNoVHyF1BUypgPKaP3mFqcYwiSe06Cle3F1vE5HvdNo7XNBPkTBYMJnFSDyqc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 16623637284071009.2150999214399; Mon, 5 Sep 2022 00:42:08 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-381-Sd8KKAvxP_Ocxr9Vg-fW7w-1; Mon, 05 Sep 2022 03:41:05 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7D5818039BF; Mon, 5 Sep 2022 07:41:02 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 16751C15BB3; Mon, 5 Sep 2022 07:41:01 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 34DB0194037D; Mon, 5 Sep 2022 07:41:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id A5AAA1946A47 for ; Mon, 5 Sep 2022 07:40:59 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 97E09C15BBD; Mon, 5 Sep 2022 07:40:59 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 43FFAC15BB3 for ; Mon, 5 Sep 2022 07:40:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662363727; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=6INGi3T/KVhNJUeI2qzGf/Ut6YiQdEJqVjE/KaCEvBU=; b=OG8IexKPywGdBZVAi8TTN0VdUNssKY3rzOfjDBYuURHj1e+6F+mdCoeYh+72TTEbluJe9F gNYa+/JiXCfezOLxZtsqU8A59bEqGKOMr3LS74dIH1H1q8pcYYq2WFVgnu+s0dXrAKDdzc oW1kVGpND7eTVkc676PflbbGuoBO4hA= X-MC-Unique: Sd8KKAvxP_Ocxr9Vg-fW7w-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/2] qemu: Implement qemuDomainGetStatsCpu fallback for qemu:///session Date: Mon, 5 Sep 2022 09:40:57 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1662363728679100003 Content-Type: text/plain; charset="utf-8"; x-default="true" 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=3D1693707 Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- 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; } =20 + +static int +qemuDomainGetStatsCpuProc(virDomainObj *vm, + virTypedParamList *params) +{ + unsigned long long cpuTime =3D 0; + unsigned long long sysTime =3D 0; + unsigned long long userTime =3D 0; + + if (virProcessGetStatInfo(&cpuTime, &sysTime, &userTime, + NULL, NULL, vm->pid, 0) < 0) { + /* ignore error */ + return 0; + } + + if (virTypedParamListAddULLong(params, cpuTime, "cpu.time") < 0 || + virTypedParamListAddULLong(params, userTime, "cpu.user") < 0 || + virTypedParamListAddULLong(params, sysTime, "cpu.system") < 0) + return -1; + + return 0; +} + + static int qemuDomainGetStatsCpuHaltPollTimeFromStats(virDomainObj *dom, unsigned int privflags, @@ -17860,8 +17884,15 @@ qemuDomainGetStatsCpu(virQEMUDriver *driver, virTypedParamList *params, unsigned int privflags) { - if (qemuDomainGetStatsCpuCgroup(dom, params) < 0) - return -1; + qemuDomainObjPrivate *priv =3D dom->privateData; + + if (priv->cgroup) { + if (qemuDomainGetStatsCpuCgroup(dom, params) < 0) + return -1; + } else { + if (qemuDomainGetStatsCpuProc(dom, params) < 0) + return -1; + } =20 if (qemuDomainGetStatsCpuCache(driver, dom, params) < 0) return -1; --=20 2.35.1