From nobody Thu May 15 05:54:27 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1513010464414830.8850061477567; Mon, 11 Dec 2017 08:41:04 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A7AF7356D5; Mon, 11 Dec 2017 16:41:02 +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 6B7BA5C6D4; Mon, 11 Dec 2017 16:41:02 +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 2BC571800FC4; Mon, 11 Dec 2017 16:41:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vBBGeoKp002226 for ; Mon, 11 Dec 2017 11:40:50 -0500 Received: by smtp.corp.redhat.com (Postfix) id D14396065E; Mon, 11 Dec 2017 16:40:50 +0000 (UTC) Received: from inaba.usersys.redhat.com (unknown [10.40.205.47]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E175060628 for ; Mon, 11 Dec 2017 16:40:49 +0000 (UTC) From: Andrea Bolognani To: libvir-list@redhat.com Date: Mon, 11 Dec 2017 17:40:32 +0100 Message-Id: <20171211164036.12142-3-abologna@redhat.com> In-Reply-To: <20171211164036.12142-1-abologna@redhat.com> References: <20171211164036.12142-1-abologna@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/6] util: Introduce virHostCPUGetInfoParseCPUInfo() 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 11 Dec 2017 16:41:03 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This handles only the /proc/cpuinfo part of virHostCPUGetInfo(). Signed-off-by: Andrea Bolognani --- src/util/virhostcpu.c | 60 +++++++++++++++++++++++++++++++++--------------= ---- 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c index c485a9721..4d5c56659 100644 --- a/src/util/virhostcpu.c +++ b/src/util/virhostcpu.c @@ -508,33 +508,17 @@ virHostCPUHasValidSubcoreConfiguration(int threads_pe= r_subcore) return ret; } =20 -int -virHostCPUGetInfoPopulateLinux(FILE *cpuinfo, - virArch arch, - unsigned int *cpus, - unsigned int *mhz, - unsigned int *nodes, - unsigned int *sockets, - unsigned int *cores, - unsigned int *threads) + +static int +virHostCPUGetInfoParseCPUInfo(FILE *cpuinfo, + virArch arch, + unsigned int *mhz) { - virBitmapPtr present_cpus_map =3D NULL; - virBitmapPtr online_cpus_map =3D NULL; char line[1024]; - DIR *nodedir =3D NULL; - struct dirent *nodedirent =3D NULL; - int nodecpus, nodecores, nodesockets, nodethreads, offline =3D 0; - int threads_per_subcore =3D 0; - unsigned int node; int ret =3D -1; - char *sysfs_nodedir =3D NULL; - char *sysfs_cpudir =3D NULL; - int direrr; =20 *mhz =3D 0; - *cpus =3D *nodes =3D *sockets =3D *cores =3D *threads =3D 0; =20 - /* Start with parsing CPU clock speed from /proc/cpuinfo */ while (fgets(line, sizeof(line), cpuinfo) !=3D NULL) { if (ARCH_IS_X86(arch)) { char *buf =3D line; @@ -614,6 +598,40 @@ virHostCPUGetInfoPopulateLinux(FILE *cpuinfo, } } =20 + ret =3D 0; + + cleanup: + return ret; +} + +int +virHostCPUGetInfoPopulateLinux(FILE *cpuinfo, + virArch arch, + unsigned int *cpus, + unsigned int *mhz, + unsigned int *nodes, + unsigned int *sockets, + unsigned int *cores, + unsigned int *threads) +{ + virBitmapPtr present_cpus_map =3D NULL; + virBitmapPtr online_cpus_map =3D NULL; + DIR *nodedir =3D NULL; + struct dirent *nodedirent =3D NULL; + int nodecpus, nodecores, nodesockets, nodethreads, offline =3D 0; + int threads_per_subcore =3D 0; + unsigned int node; + int ret =3D -1; + char *sysfs_nodedir =3D NULL; + char *sysfs_cpudir =3D NULL; + int direrr; + + *cpus =3D *nodes =3D *sockets =3D *cores =3D *threads =3D 0; + + /* Start with parsing CPU clock speed from /proc/cpuinfo */ + if (virHostCPUGetInfoParseCPUInfo(cpuinfo, arch, mhz) < 0) + goto cleanup; + /* Get information about what CPUs are present in the host and what * CPUs are online, so that we don't have to so for each node */ present_cpus_map =3D virHostCPUGetPresentBitmap(); --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list