From nobody Mon Feb 9 14:03:18 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1577961910; cv=none; d=zohomail.com; s=zohoarc; b=RyKN3Tzyu/IjA3kkKpE1LTssRVVxMS3VCSunoV6JnOWAb7/OWuKHCNWrST9WnIJMuhC6wC19rfAOci4Zp/pw8TyIc6AtNvZ4LjU3dXmEJTVEFUPxv0znnIHrS/iV4DWv/7EhvHanyfHP6PJkIEG+TE1UwuJvj/FQ/xzF8VDaWdA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577961910; h=Content-Type:Content-Transfer-Encoding:Cc: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=JAW2RRRYmdK9Edh0K9Yd3KpbPAp3bwu5CVJ4knzBtSA=; b=kYW6VzMCpV/wsB/7fR+1RWmIOFJbH2Cc+vcRVcaBd9rAJxSG1lK47b1fCvnf1pnUh3iaJ89GHxCwxXAm9tk/+k4Ui914kqQg34YGlnAbn1P4WXv85G7FgJbPWuF5VNnu1gwPxOnt4iyzH6OYtHx+1TuWTvmxtemAK0Kyawv3OWQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1577961910506286.9311587398371; Thu, 2 Jan 2020 02:45:10 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-120-G98_S0-wOsGHcbTlegxPVQ-1; Thu, 02 Jan 2020 05:45:07 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E2219800D41; Thu, 2 Jan 2020 10:45:01 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CCCAF10027A6; Thu, 2 Jan 2020 10:45:00 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 7517E18089CF; Thu, 2 Jan 2020 10:44:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 002AiveL028976 for ; Thu, 2 Jan 2020 05:44:58 -0500 Received: by smtp.corp.redhat.com (Postfix) id DB02C10D17BB; Thu, 2 Jan 2020 10:44:57 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D469310D18F2 for ; Thu, 2 Jan 2020 10:44:55 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B4CC0185B0C3 for ; Thu, 2 Jan 2020 10:44:55 +0000 (UTC) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-133-xUP8I1CCP9WWToK-u4rlTg-1; Thu, 02 Jan 2020 05:44:53 -0500 Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Jan 2020 02:44:51 -0800 Received: from david-unc.bj.intel.com ([10.238.157.59]) by fmsmga008.fm.intel.com with ESMTP; 02 Jan 2020 02:44:51 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1577961909; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=JAW2RRRYmdK9Edh0K9Yd3KpbPAp3bwu5CVJ4knzBtSA=; b=gwPO4PxbRmWuJHSHzkXX8UecxqU768hUEMfL2EegBigCLTAkpXxwy4GE0VaOn1H+XM0VXo pyZVGmkxKxcl/+WcRUkgwJipWKE3h18BZLtyzC/Yd8rgIWBmta6MINQZZL8ni1ttQxHcJl xCP6RwCo7NLtI2BPggemofGsO2a2PTU= X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,386,1571727600"; d="scan'208";a="216477090" From: Wang Huaqiang To: libvir-list@redhat.com, berrange@redhat.com Date: Thu, 2 Jan 2020 18:45:04 +0800 Message-Id: <20200102104505.28461-2-huaqiang.wang@intel.com> In-Reply-To: <20200102104505.28461-1-huaqiang.wang@intel.com> References: <20200102104505.28461-1-huaqiang.wang@intel.com> MIME-Version: 1.0 X-MC-Unique: xUP8I1CCP9WWToK-u4rlTg-1 X-MC-Unique: G98_S0-wOsGHcbTlegxPVQ-1 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 002AiveL028976 X-loop: libvir-list@redhat.com Cc: huaqiang.wang@intel.com Subject: [libvirt] [PATCHv2 1/2] util, resctrl: using 64bit interface instead of 32bit for counters X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The underlying resctrl monitoring is actually using 64 bit counters, not the 32bit one. Correct this by using 64bit data type for reading hardware value. To keep the interface consistent, the result of CPU last level cache that occupied by vcpu processors of specific restrl monitor group is still reported with a truncated 32bit data type. because, in silicon world, CPU cache size will never exceed 4GB. Signed-off-by: Wang Huaqiang Reviewed-by: Daniel P. Berrang=C3=A9 --- src/qemu/qemu_driver.c | 15 +++++++++++++-- src/util/virfile.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/util/virfile.h | 2 ++ src/util/virresctrl.c | 6 +++--- src/util/virresctrl.h | 2 +- 5 files changed, 59 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 7a7f388767..ad6f3130ae 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -20740,8 +20740,19 @@ qemuDomainGetStatsCpuCache(virQEMUDriverPtr driver, "cpu.cache.monitor.%zu.bank.%zu.i= d", i, j) < 0) goto cleanup; =20 - if (virTypedParamListAddUInt(params, resdata[i]->stats[j]->val= s[0], - "cpu.cache.monitor.%zu.bank.%zu.b= ytes", i, j) < 0) + /* 'resdata[i]->stats[j]->vals[0]' keeps the value of how many= last + * level cache in bank j currently occupied by the vcpus liste= d in + * resource monitor i, in bytes. This value is reported throug= h a + * 64 bit hardware counter, so it is better to be arranged with + * data type in 64 bit width, but considering the fact that + * physical cache on a CPU could never be designed to be bigger + * than 4G bytes in size, to keep the 'domstats' interface + * historically consistent, it is safe to report the value wit= h a + * truncated 'UInt' data type here. */ + if (virTypedParamListAddUInt(params, + (unsigned int)resdata[i]->stats[j= ]->vals[0], + "cpu.cache.monitor.%zu.bank.%zu.b= ytes", + i, j) < 0) goto cleanup; } } diff --git a/src/util/virfile.c b/src/util/virfile.c index 4fd865dd83..7bf33682c7 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -4196,6 +4196,46 @@ virFileReadValueUint(unsigned int *value, const char= *format, ...) } =20 =20 +/** + * virFileReadValueUllong: + * @value: pointer to unsigned long long to be filled in with the value + * @format, ...: file to read from + * + * Read unsigned int from @format and put it into @value. + * + * Return -2 for non-existing file, -1 on other errors and 0 if everything= went + * fine. + */ +int +virFileReadValueUllong(unsigned long long *value, const char *format, ...) +{ + g_autofree char *str =3D NULL; + g_autofree char *path =3D NULL; + va_list ap; + + va_start(ap, format); + path =3D g_strdup_vprintf(format, ap); + va_end(ap); + + if (!virFileExists(path)) + return -2; + + if (virFileReadAll(path, INT_BUFSIZE_BOUND(*value), &str) < 0) + return -1; + + virStringTrimOptionalNewline(str); + + if (virStrToLong_ullp(str, NULL, 10, value) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Invalid unsigned long long value '%s' in file '%= s'"), + str, path); + return -1; + } + + return 0; +} + + /** * virFileReadValueScaledInt: * @value: pointer to unsigned long long int to be filled in with the value diff --git a/src/util/virfile.h b/src/util/virfile.h index bcae40ee06..756c9a70b9 100644 --- a/src/util/virfile.h +++ b/src/util/virfile.h @@ -361,6 +361,8 @@ int virFileReadValueInt(int *value, const char *format,= ...) G_GNUC_PRINTF(2, 3); int virFileReadValueUint(unsigned int *value, const char *format, ...) G_GNUC_PRINTF(2, 3); +int virFileReadValueUllong(unsigned long long *value, const char *format, = ...) + G_GNUC_PRINTF(2, 3); int virFileReadValueBitmap(virBitmapPtr *value, const char *format, ...) G_GNUC_PRINTF(2, 3); int virFileReadValueScaledInt(unsigned long long *value, const char *forma= t, ...) diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index b78fded026..684d2ce398 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -2678,7 +2678,7 @@ virResctrlMonitorGetStats(virResctrlMonitorPtr monito= r, int rv =3D -1; int ret =3D -1; size_t i =3D 0; - unsigned int val =3D 0; + unsigned long long val =3D 0; DIR *dirp =3D NULL; char *datapath =3D NULL; char *filepath =3D NULL; @@ -2734,8 +2734,8 @@ virResctrlMonitorGetStats(virResctrlMonitorPtr monito= r, goto cleanup; =20 for (i =3D 0; resources[i]; i++) { - rv =3D virFileReadValueUint(&val, "%s/%s/%s", datapath, - ent->d_name, resources[i]); + rv =3D virFileReadValueUllong(&val, "%s/%s/%s", datapath, + ent->d_name, resources[i]); if (rv =3D=3D -2) { virReportError(VIR_ERR_INTERNAL_ERROR, _("File '%s/%s/%s' does not exist."), diff --git a/src/util/virresctrl.h b/src/util/virresctrl.h index 3dd7c96348..11f275acf4 100644 --- a/src/util/virresctrl.h +++ b/src/util/virresctrl.h @@ -204,7 +204,7 @@ struct _virResctrlMonitorStats { char **features; /* @vals store the statistical record values and @val[0] is the value = for * @features[0], @val[1] for@features[1] ... respectively */ - unsigned int *vals; + unsigned long long *vals; /* The length of @vals array */ size_t nvals; }; --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list