From nobody Thu Mar 28 09:05:40 2024 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1559564951; cv=none; d=zoho.com; s=zohoarc; b=JgvvgwevNUHk4IeQMXDed6YZNeRbf97ds6DNtiAUl7wROIsaI0OcWVgDRKt5sKWLGUxvmhq3hSGYVIaVbXWw6MUvRXR6caDUHsohLmhZ+Hn62MiCpS9UT8gC0RbMqM+VUA2TcEZ6P9yzffocL68BdbWxV+rMOTN7CVnyBEGadvY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559564951; 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:ARC-Authentication-Results; bh=MPGoveVAkzMxIBXXzYvnXu956aaBttPCf/6BUQi7eMU=; b=Lfz1IItl5SkhjwYH5jU3s3lNoc+E1qhrF27ZJEFD4X7dTqQX2NUCB0Jv2LYayN3/lds1gL+rxl23s/xvrNdve58NEH5PbM1Zr+vhRcKuER3slN8gaaLzhR/cIU0//3NclKqSJR4Yp7llEWmV5GELcd9dnCMs54NTUeG/SJ+fFzw= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1559564951481163.70298404856703; Mon, 3 Jun 2019 05:29:11 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 529F1A3EB8; Mon, 3 Jun 2019 12:29:01 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 22B9F5D9CC; Mon, 3 Jun 2019 12:28:58 +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 2B02B1972B; Mon, 3 Jun 2019 12:28:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x53CS51f003619 for ; Mon, 3 Jun 2019 08:28:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5A1DF5D9D2; Mon, 3 Jun 2019 12:28:05 +0000 (UTC) Received: from orkuz.int.mamuti.net (unknown [10.40.205.163]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 028CC5D9CD for ; Mon, 3 Jun 2019 12:28:01 +0000 (UTC) Received: by orkuz.int.mamuti.net (Postfix, from userid 500) id 7E42A2A042B; Mon, 3 Jun 2019 14:27:59 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Mon, 3 Jun 2019 14:27:52 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 1/7] qemu: Make virQEMUCapsProbeHostCPUForEmulator more generic 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: , 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 03 Jun 2019 12:29:10 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The function is renamed as virQEMUCapsProbeHostCPU and it does not get the list of allowed CPU models from qemuCaps anymore. This is responsibility is moved to the caller. The result is just a very thin wrapper around virCPUGetHost mostly required mocking in tests. The generic function is used in place of a direct call to virCPUGetHost in virQEMUCapsInitHostCPUModel to make sure tests don't accidentally probe host CPU. Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_capabilities.c | 14 ++++++-------- src/qemu/qemu_capspriv.h | 5 ++--- tests/qemucpumock.c | 5 ++--- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index a827bd24e3..5cddae06c6 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -880,12 +880,10 @@ virQEMUCapsInitGuestFromBinary(virCapsPtr caps, =20 =20 virCPUDefPtr -virQEMUCapsProbeHostCPUForEmulator(virArch hostArch, - virQEMUCapsPtr qemuCaps, - virDomainVirtType type) +virQEMUCapsProbeHostCPU(virArch hostArch, + virDomainCapsCPUModelsPtr models) { - return virCPUGetHost(hostArch, VIR_CPU_TYPE_GUEST, NULL, - virQEMUCapsGetCPUDefinitions(qemuCaps, type)); + return virCPUGetHost(hostArch, VIR_CPU_TYPE_GUEST, NULL, models); } =20 =20 @@ -3049,7 +3047,8 @@ virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps, } else if (rc =3D=3D 1) { VIR_DEBUG("No host CPU model info from QEMU; probing host CPU dire= ctly"); =20 - hostCPU =3D virQEMUCapsProbeHostCPUForEmulator(hostArch, qemuCaps,= type); + hostCPU =3D virQEMUCapsProbeHostCPU(hostArch, + virQEMUCapsGetCPUDefinitions(qem= uCaps, type)); if (!hostCPU || virCPUDefCopyModelFilter(cpu, hostCPU, true, virQEMUCapsCPUFilterFeatures, @@ -3062,8 +3061,7 @@ virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps, goto error; } else if (type =3D=3D VIR_DOMAIN_VIRT_KVM && virCPUGetHostIsSupported(qemuCaps->arch)) { - if (!(fullCPU =3D virCPUGetHost(qemuCaps->arch, VIR_CPU_TYPE_GUEST, - NULL, NULL))) + if (!(fullCPU =3D virQEMUCapsProbeHostCPU(qemuCaps->arch, NULL))) goto error; =20 if (!(cpuExpanded =3D virCPUDefCopy(cpu)) || diff --git a/src/qemu/qemu_capspriv.h b/src/qemu/qemu_capspriv.h index 2d059bee8c..3c129cbf6c 100644 --- a/src/qemu/qemu_capspriv.h +++ b/src/qemu/qemu_capspriv.h @@ -82,9 +82,8 @@ virQEMUCapsGetCPUModelX86Data(qemuMonitorCPUModelInfoPtr = model, bool migratable); =20 virCPUDefPtr -virQEMUCapsProbeHostCPUForEmulator(virArch hostArch, - virQEMUCapsPtr qemuCaps, - virDomainVirtType type) ATTRIBUTE_NOINL= INE; +virQEMUCapsProbeHostCPU(virArch hostArch, + virDomainCapsCPUModelsPtr models) ATTRIBUTE_NOINLI= NE; =20 void virQEMUCapsSetGICCapabilities(virQEMUCapsPtr qemuCaps, diff --git a/tests/qemucpumock.c b/tests/qemucpumock.c index e028ada8eb..501738df36 100644 --- a/tests/qemucpumock.c +++ b/tests/qemucpumock.c @@ -27,9 +27,8 @@ =20 =20 virCPUDefPtr -virQEMUCapsProbeHostCPUForEmulator(virArch hostArch ATTRIBUTE_UNUSED, - virQEMUCapsPtr qemuCaps ATTRIBUTE_UNUSE= D, - virDomainVirtType type ATTRIBUTE_UNUSED) +virQEMUCapsProbeHostCPU(virArch hostArch ATTRIBUTE_UNUSED, + virDomainCapsCPUModelsPtr models ATTRIBUTE_UNUSED) { const char *model =3D getenv("VIR_TEST_MOCK_FAKE_HOST_CPU"); =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 09:05:40 2024 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1559564927; cv=none; d=zoho.com; s=zohoarc; b=T8qR5wnTRoFC8FKqzJw//n4BWkYFEtLw3p2PO6PDoIyFXIlXxkYzCFUSYVaWnRmB+M/j+ysCwIl+6XhygsGRRfgwZkye+Oen7cUpuok0c+ttOxeFrxmGnbjkfzI+CIFLxbT6PxfnIqxzAM/xe1Oy1tbeCJl9bz55ggNprrZpf1w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559564927; 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:ARC-Authentication-Results; bh=G9oU9C5WKwV62BPCjmvLDNEeOCKZkvkqSXAK0xGYLGU=; b=ZeA2dUN5er5IuML5Bu2IJGYCV5NzreFlhG0QakbcK4Z6/fyMJ48oIPDw85sdUZc00tyWUHdPnHzaqx7K4DcM/yae6a5rxocFKgRMhJR9AOYM8C1ISZ0b5WvA7LzCCqTyatk5kxmF985/JbTIIQKGyahpP26E3qJVtB27b39oDso= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1559564927782397.6872618821367; Mon, 3 Jun 2019 05:28:47 -0700 (PDT) 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 2FB792EED3E; Mon, 3 Jun 2019 12:28:40 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 07782648B3; Mon, 3 Jun 2019 12:28:38 +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 B2DFF1972A; Mon, 3 Jun 2019 12:28:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x53CS6MN003637 for ; Mon, 3 Jun 2019 08:28:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id 27A4B4522; Mon, 3 Jun 2019 12:28:06 +0000 (UTC) Received: from orkuz.int.mamuti.net (unknown [10.40.205.163]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EDFB02DE67 for ; Mon, 3 Jun 2019 12:28:01 +0000 (UTC) Received: by orkuz.int.mamuti.net (Postfix, from userid 500) id 7F6CE2A5DF2; Mon, 3 Jun 2019 14:27:59 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Mon, 3 Jun 2019 14:27:53 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 2/7] qemuargv2xmltest: Use mocked virQEMUCapsProbeHostCPU 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: , 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.29]); Mon, 03 Jun 2019 12:28:46 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The qemuTestParseCapabilitiesArch call would eventually lead to the host CPU being probed via virCPUGetHost. Let's divert this to a mocked version already used by the qemuxml2argvtest. Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- tests/Makefile.am | 3 ++- tests/qemuargv2xmltest.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index 67375b3c19..6b17d99501 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -585,7 +585,8 @@ qemuxml2xmltest_LDADD =3D $(qemu_LDADDS) $(LDADDS) qemuargv2xmltest_SOURCES =3D \ qemuargv2xmltest.c testutilsqemu.c testutilsqemu.h \ testutils.c testutils.h -qemuargv2xmltest_LDADD =3D $(qemu_LDADDS) $(LDADDS) +qemuargv2xmltest_LDADD =3D libqemutestdriver.la \ + $(LDADDS) =20 qemumonitorjsontest_SOURCES =3D \ qemumonitorjsontest.c \ diff --git a/tests/qemuargv2xmltest.c b/tests/qemuargv2xmltest.c index 2a51e22318..06e32898a2 100644 --- a/tests/qemuargv2xmltest.c +++ b/tests/qemuargv2xmltest.c @@ -309,7 +309,8 @@ mymain(void) return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } =20 -VIR_TEST_MAIN(mymain) +VIR_TEST_MAIN_PRELOAD(mymain, + abs_builddir "/.libs/qemucpumock.so") =20 #else =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 09:05:40 2024 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1559564920; cv=none; d=zoho.com; s=zohoarc; b=IXVIyOQuUadW80b+nYvrdiLcdMnjb3kwzTCKr9iaLUR9DGDh9iHxmTRYUm7sCPmHeBZXrxHXDbECiCl3huHnG51xp1+uFWvzGSqFRZq2/7DlCw5nBTerb1Ml+qkjJAPVPl4fx9mgknBt5USks/wUmfgLVg2e2uy4tRjxX8BYvTQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559564920; 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:ARC-Authentication-Results; bh=KKwR/BlPtjHM4IkS3t6d+UFz7FeT0PBdc/4kkevSkHc=; b=ALd36F+OWUbmX5KxoJ+0XwsHOQ0cq2R1YLCvZ/DszfxbP2u1eb+kIkePWd5Ig2S+FcpJ/ta07V3ESCylWmtSXY1y8FQ8jEhvj1lTJybI86pqfDCl8UkrEjeL1yK5+uOOooiljIkg9L2gqRIJNkaz4Kc/lyr7ViKrnpChg/zPvyY= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1559564920992287.07975124676466; Mon, 3 Jun 2019 05:28:40 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 25C693107B0F; Mon, 3 Jun 2019 12:28:39 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EFE352E056; Mon, 3 Jun 2019 12:28:38 +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 B15E519729; Mon, 3 Jun 2019 12:28:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x53CS4iq003609 for ; Mon, 3 Jun 2019 08:28:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id 196A72AABD; Mon, 3 Jun 2019 12:28:04 +0000 (UTC) Received: from orkuz.int.mamuti.net (unknown [10.40.205.163]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B68534522 for ; Mon, 3 Jun 2019 12:28:01 +0000 (UTC) Received: by orkuz.int.mamuti.net (Postfix, from userid 500) id 827442A5DF4; Mon, 3 Jun 2019 14:27:59 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Mon, 3 Jun 2019 14:27:54 +0200 Message-Id: <53f953283efc457e3c80b746d55fcaee4531a4c8.1559564736.git.jdenemar@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 3/7] util: Add virHostCPUGetTscInfo 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: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Mon, 03 Jun 2019 12:28:39 +0000 (UTC) On a KVM x86_64 host which supports invariant TSC this function can be used to detect the TSC frequency and the availability of TSC scaling. The magic MSR numbers required to check if VMX scaling is supported on the host are documented in Volume 3 of the Intel=C2=AE 64 and IA-32 Architectures Software Developer=E2=80=99s Manual. Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- src/util/virhostcpu.c | 71 +++++++++++++++++++++++++++++++++++++++++++ src/util/virhostcpu.h | 11 +++++++ 2 files changed, 82 insertions(+) diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c index f4a62c74fa..8c00804b0e 100644 --- a/src/util/virhostcpu.c +++ b/src/util/virhostcpu.c @@ -1324,6 +1324,69 @@ virHostCPUGetMSR(unsigned long index, return virHostCPUGetMSRFromKVM(index, msr); } =20 + +# define VMX_PROCBASED_CTLS2_MSR 0x48b +# define VMX_USE_TSC_SCALING (1 << 25) + +/* + * This function should only be called when the host CPU supports invarian= t TSC + * (invtsc CPUID feature). + * + * Returns pointer to the TSC info structure on success, + * NULL when TSC cannot be probed otherwise. + */ +virHostCPUTscInfoPtr +virHostCPUGetTscInfo(void) +{ + virHostCPUTscInfoPtr info; + VIR_AUTOCLOSE kvmFd =3D -1; + VIR_AUTOCLOSE vmFd =3D -1; + VIR_AUTOCLOSE vcpuFd =3D -1; + uint64_t msr =3D 0; + int rc; + + if ((kvmFd =3D open(KVM_DEVICE, O_RDONLY)) < 0) { + virReportSystemError(errno, _("Unable to open %s"), KVM_DEVICE); + return NULL; + } + + if ((vmFd =3D ioctl(kvmFd, KVM_CREATE_VM, 0)) < 0) { + virReportSystemError(errno, "%s", + _("Unable to create KVM VM for TSC probing")); + return NULL; + } + + if ((vcpuFd =3D ioctl(vmFd, KVM_CREATE_VCPU, 0)) < 0) { + virReportSystemError(errno, "%s", + _("Unable to create KVM vCPU for TSC probing"= )); + return NULL; + } + + if ((rc =3D ioctl(vcpuFd, KVM_GET_TSC_KHZ)) < 0) { + virReportSystemError(errno, "%s", + _("Unable to probe TSC frequency")); + return NULL; + } + + if (VIR_ALLOC(info) < 0) + return NULL; + + info->frequency =3D rc * 1000ULL; + + if (virHostCPUGetMSR(VMX_PROCBASED_CTLS2_MSR, &msr) =3D=3D 0) { + /* High 32 bits of the MSR value indicate whether specific control + * can be set to 1. */ + msr >>=3D 32; + + info->scaling =3D virTristateBoolFromBool(!!(msr & VMX_USE_TSC_SCA= LING)); + } + + VIR_DEBUG("Detected TSC frequency %llu Hz, scaling %s", + info->frequency, virTristateBoolTypeToString(info->scaling)); + + return info; +} + #else =20 int @@ -1335,6 +1398,14 @@ virHostCPUGetMSR(unsigned long index ATTRIBUTE_UNUSE= D, return -1; } =20 +virHostCPUTscInfoPtr +virHostCPUGetTscInfo(void) +{ + virReportSystemError(ENOSYS, "%s", + _("Probing TSC is not supported on this platform"= )); + return NULL; +} + #endif /* HAVE_LINUX_KVM_H && defined(KVM_GET_MSRS) && \ (defined(__i386__) || defined(__x86_64__)) && \ (defined(__linux__) || defined(__FreeBSD__)) */ diff --git a/src/util/virhostcpu.h b/src/util/virhostcpu.h index 0d20dbef61..b822bc11a8 100644 --- a/src/util/virhostcpu.h +++ b/src/util/virhostcpu.h @@ -25,6 +25,15 @@ # include "internal.h" # include "virarch.h" # include "virbitmap.h" +# include "virenum.h" + + +typedef struct _virHostCPUTscInfo virHostCPUTscInfo; +typedef virHostCPUTscInfo *virHostCPUTscInfoPtr; +struct _virHostCPUTscInfo { + unsigned long long frequency; + virTristateBool scaling; +}; =20 =20 int virHostCPUGetStats(int cpuNum, @@ -69,4 +78,6 @@ unsigned int virHostCPUGetMicrocodeVersion(void); int virHostCPUGetMSR(unsigned long index, uint64_t *msr); =20 +virHostCPUTscInfoPtr virHostCPUGetTscInfo(void); + #endif /* LIBVIRT_VIRHOSTCPU_H */ --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 09:05:40 2024 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1559564907; cv=none; d=zoho.com; s=zohoarc; b=lf41Am7sN1UkqeqxIyDFYtolcgcxjbd74iJnwqhZ3+cFemxCm+6LFodsgZ1a9SniH9N9Lss6VcwmgqdmMq/HFYNXH0I76rqOD2kzg03SH+HyhmrkhEp/RrvxJt70ryrbS+V+mwPiD7Vx0rr7xw7SeCxYknpDi6FtV4ZGpyAZOHw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559564907; 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:ARC-Authentication-Results; bh=h1r4CgYp+mRauN9ek+eXMOy26vXvIj6qWZGOxOWf1sY=; b=cgoXkVX2OgE4Uz291+hC+V5k731hJPxVdBnEVXu/olQt6ays8gwRNX0gqTRFZBPY/uAL078egnOoC2uLVZqX5E0St4SKJyGJHnSDDcVV20oEHGOSnm/0elzcGy8+zzjfQrz8xjY6x96n2VOcoOIzNSvzYS2Sv9+Zu29mOwl/k1w= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1559564907690758.5631696082221; Mon, 3 Jun 2019 05:28:27 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id DC902C18B2CF; Mon, 3 Jun 2019 12:28:15 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B67271001E86; Mon, 3 Jun 2019 12:28:14 +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 BEFC519725; Mon, 3 Jun 2019 12:28:05 +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 x53CS47s003614 for ; Mon, 3 Jun 2019 08:28:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id 51265605AF; Mon, 3 Jun 2019 12:28:04 +0000 (UTC) Received: from orkuz.int.mamuti.net (unknown [10.40.205.163]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EF54C605AE for ; Mon, 3 Jun 2019 12:28:01 +0000 (UTC) Received: by orkuz.int.mamuti.net (Postfix, from userid 500) id 851B02A5DF5; Mon, 3 Jun 2019 14:27:59 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Mon, 3 Jun 2019 14:27:55 +0200 Message-Id: <5feec5b38d3b693446ef150325dcc7e0b8ce8b58.1559564736.git.jdenemar@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 4/7] conf: Report TSC frequency in host CPU capabilities 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: , Content-Transfer-Encoding: quoted-printable 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-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 03 Jun 2019 12:28:26 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This patch adds a new element into the host CPU capabilities XML. Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- src/conf/cpu_conf.c | 48 +++++++++++++++++++++++++++++++++++++++++++++ src/conf/cpu_conf.h | 2 ++ 2 files changed, 50 insertions(+) diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index bd2beab33e..dc46e7f57a 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -112,6 +112,7 @@ virCPUDefFree(virCPUDefPtr def) =20 virCPUDefFreeModel(def); VIR_FREE(def->cache); + VIR_FREE(def->tsc); VIR_FREE(def); } =20 @@ -233,6 +234,13 @@ virCPUDefCopyWithoutModel(const virCPUDef *cpu) *copy->cache =3D *cpu->cache; } =20 + if (cpu->tsc) { + if (VIR_ALLOC(copy->tsc) < 0) + goto error; + + *copy->tsc =3D *cpu->tsc; + } + return copy; =20 error: @@ -286,6 +294,8 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt, char *cpuMode; char *fallback =3D NULL; char *vendor_id =3D NULL; + char *tscScaling =3D NULL; + virHostCPUTscInfoPtr tsc =3D NULL; int ret =3D -1; =20 *cpu =3D NULL; @@ -402,6 +412,32 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt, _("invalid microcode version")); goto cleanup; } + + if (virXPathBoolean("boolean(./counter[@name=3D'tsc'])", ctxt) > 0= ) { + if (VIR_ALLOC(tsc) < 0) + goto cleanup; + + if (virXPathULongLong("./counter[@name=3D'tsc']/@frequency", c= txt, + &tsc->frequency) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Invalid TSC frequency")); + goto cleanup; + } + + tscScaling =3D virXPathString("string(./counter[@name=3D'tsc']= /@scaling)", + ctxt); + if (tscScaling) { + int scaling =3D virTristateBoolTypeFromString(tscScaling); + if (scaling < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Invalid TSC scaling attribute")); + goto cleanup; + } + tsc->scaling =3D scaling; + } + + VIR_STEAL_PTR(def->tsc, tsc); + } } =20 if (!(def->model =3D virXPathString("string(./model[1])", ctxt)) && @@ -587,6 +623,8 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt, VIR_FREE(fallback); VIR_FREE(vendor_id); VIR_FREE(nodes); + VIR_FREE(tscScaling); + VIR_FREE(tsc); virCPUDefFree(def); return ret; } @@ -744,6 +782,16 @@ virCPUDefFormatBuf(virBufferPtr buf, virBufferAsprintf(buf, "\n", def->microcodeVersion); =20 + if (def->type =3D=3D VIR_CPU_TYPE_HOST && def->tsc) { + virBufferAddLit(buf, "tsc->frequency); + if (def->tsc->scaling) { + virBufferAsprintf(buf, " scaling=3D'%s'", + virTristateBoolTypeToString(def->tsc->scalin= g)); + } + virBufferAddLit(buf, "/>\n"); + } + if (def->sockets && def->cores && def->threads) { virBufferAddLit(buf, "sockets); diff --git a/src/conf/cpu_conf.h b/src/conf/cpu_conf.h index c98db65693..51bf744fab 100644 --- a/src/conf/cpu_conf.h +++ b/src/conf/cpu_conf.h @@ -28,6 +28,7 @@ # include "virarch.h" # include "numa_conf.h" # include "virenum.h" +# include "virhostcpu.h" =20 # define VIR_CPU_VENDOR_ID_LENGTH 12 =20 @@ -139,6 +140,7 @@ struct _virCPUDef { size_t nfeatures_max; virCPUFeatureDefPtr features; virCPUCacheDefPtr cache; + virHostCPUTscInfoPtr tsc; }; =20 =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 09:05:40 2024 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1559564949; cv=none; d=zoho.com; s=zohoarc; b=nwMI4WO68QReqM13nHEsYMCSLKGb66D1TDZccs+hZZgYaO6yaw0sEFydv+X54rOqXAb1QqeSN5LFSNMYflHqjpARD4YaCxei7wzNfSkEcb+z58Azm8dWSNsAFQGoDFWj/dQpSgabn2nk2s4DQ4rZqmEckFb2rrLpCYRNU5qNIyY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559564949; 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:ARC-Authentication-Results; bh=v1+zGMEaISRKLuTiy5Ag/zL4G4G8nT3g0JpCJT4wc8I=; b=SljhXjWjCSeetOtHPBG8Xc4m9LZ3Plx8e6fx5ZOyLpw7io62Pisvj1BWKyethHxwuTghgM7Zhxp2LbLt/BC/nmi6T+TEqvFKa8bCsB3wlu41gGkVNAhmYBw0Qsi9/MJ33pjbnQtNXDVUpegz+uasNeDaMHx9fSQ33vI5G11zsSE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1559564949078388.7747010787633; Mon, 3 Jun 2019 05:29:09 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4E0043107B3B; Mon, 3 Jun 2019 12:28:52 +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 1649467C8B; Mon, 3 Jun 2019 12:28:52 +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 BBDF318436A4; Mon, 3 Jun 2019 12:28:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x53CS6A9003644 for ; Mon, 3 Jun 2019 08:28:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id D8D11608A7; Mon, 3 Jun 2019 12:28:06 +0000 (UTC) Received: from orkuz.int.mamuti.net (unknown [10.40.205.163]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AB8A0648BF for ; Mon, 3 Jun 2019 12:28:05 +0000 (UTC) Received: by orkuz.int.mamuti.net (Postfix, from userid 500) id 8785D2A5DF6; Mon, 3 Jun 2019 14:27:59 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Mon, 3 Jun 2019 14:27:56 +0200 Message-Id: <43a2cde48a2460ef502cbaca28e2da79ff621d9a.1559564736.git.jdenemar@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 5/7] cpu_x86: Fix placement of *CheckFeature functions 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: , 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Mon, 03 Jun 2019 12:29:08 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Commit 0a97486e09 moved them outside #ifdef, but after virCPUx86GetHost, which will start calling them in the following patch. Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- src/cpu/cpu_x86.c | 72 +++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index f05bfa24e0..cb03123787 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -2378,6 +2378,41 @@ x86Encode(virArch arch, } =20 =20 +static int +virCPUx86CheckFeature(const virCPUDef *cpu, + const char *name) +{ + int ret =3D -1; + virCPUx86MapPtr map; + virCPUx86ModelPtr model =3D NULL; + + if (!(map =3D virCPUx86GetMap())) + return -1; + + if (!(model =3D x86ModelFromCPU(cpu, map, -1))) + goto cleanup; + + ret =3D x86FeatureInData(name, &model->data, map); + + cleanup: + x86ModelFree(model); + return ret; +} + + +static int +virCPUx86DataCheckFeature(const virCPUData *data, + const char *name) +{ + virCPUx86MapPtr map; + + if (!(map =3D virCPUx86GetMap())) + return -1; + + return x86FeatureInData(name, &data->data.x86, map); +} + + #if defined(__i386__) || defined(__x86_64__) static inline void cpuidCall(virCPUx86CPUID *cpuid) @@ -2707,8 +2742,6 @@ cpuidSet(uint32_t base, virCPUDataPtr data) } =20 =20 - - static int virCPUx86GetHost(virCPUDefPtr cpu, virDomainCapsCPUModelsPtr models) @@ -2736,41 +2769,6 @@ virCPUx86GetHost(virCPUDefPtr cpu, #endif =20 =20 -static int -virCPUx86CheckFeature(const virCPUDef *cpu, - const char *name) -{ - int ret =3D -1; - virCPUx86MapPtr map; - virCPUx86ModelPtr model =3D NULL; - - if (!(map =3D virCPUx86GetMap())) - return -1; - - if (!(model =3D x86ModelFromCPU(cpu, map, -1))) - goto cleanup; - - ret =3D x86FeatureInData(name, &model->data, map); - - cleanup: - x86ModelFree(model); - return ret; -} - - -static int -virCPUx86DataCheckFeature(const virCPUData *data, - const char *name) -{ - virCPUx86MapPtr map; - - if (!(map =3D virCPUx86GetMap())) - return -1; - - return x86FeatureInData(name, &data->data.x86, map); -} - - static virCPUDefPtr virCPUx86Baseline(virCPUDefPtr *cpus, unsigned int ncpus, --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 09:05:40 2024 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1559564952; cv=none; d=zoho.com; s=zohoarc; b=VumKYwGsulE6BbvCijYGgSYJuz4oLjHGktL/wh2LNgm8MnUeKRtbpoZnvOHZCKtp2bI5hLO0LaAWjmAOVNUhHi+f8NR85fgOp2Ivm9ZFVa1nY1xniLi6iK9BWDWxUnk/nl/lZr/ulrbm1ZUF6d9l3Ma75INyP9bX+QqcFR4Gdl4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559564952; 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:ARC-Authentication-Results; bh=bunfgVe5t1lC92pf41zoyb3ZqCTpJPlQitFRNVa8w3s=; b=n4kSnaLImla6HwqZTA8dOa8HtD5L0LyeqgH2QyZLgKITb/RNbV1OjLtKzLyoibb0zaSYA21mngHZn/EHsXCov+l/DNcK9Ky3shK6Fjnn4m0ebSJLfQ3mm5LmdpTa9g11q6gQ+BBA3+UbYsxxagRt+cV4//c9yiFBVDhQFtnjjHM= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1559564952101874.0689757046391; Mon, 3 Jun 2019 05:29:12 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5E94D7EAB3; Mon, 3 Jun 2019 12:29:10 +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 2CC826199F; Mon, 3 Jun 2019 12:29:09 +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 D533818436AB; Mon, 3 Jun 2019 12:29:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x53CS7w6003649 for ; Mon, 3 Jun 2019 08:28:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id B21085D739; Mon, 3 Jun 2019 12:28:07 +0000 (UTC) Received: from orkuz.int.mamuti.net (unknown [10.40.205.163]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8468D5B685 for ; Mon, 3 Jun 2019 12:28:05 +0000 (UTC) Received: by orkuz.int.mamuti.net (Postfix, from userid 500) id 89B002A5DF3; Mon, 3 Jun 2019 14:27:59 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Mon, 3 Jun 2019 14:27:57 +0200 Message-Id: <67698f914beb8557f857bda0e026cac727feb05e.1559564736.git.jdenemar@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 6/7] cpu_x86: Probe TSC frequency and scaling support 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: , 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 03 Jun 2019 12:29:11 +0000 (UTC) Content-Type: text/plain; charset="utf-8" When the host CPU supports invariant TSC the host CPU definition created by virCPUx86GetHost will contain (unless probing fails for some reason) addition TSC related data. Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- src/cpu/cpu_x86.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index cb03123787..689b6cdaf5 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -2762,6 +2762,15 @@ virCPUx86GetHost(virCPUDefPtr cpu, ret =3D x86DecodeCPUData(cpu, cpuData, models); cpu->microcodeVersion =3D virHostCPUGetMicrocodeVersion(); =20 + /* Probing for TSC frequency makes sense only if the CPU supports + * invariant TSC (Linux calls this constant_tsc in /proc/cpuinfo). */ + if (virCPUx86DataCheckFeature(cpuData, "invtsc") =3D=3D 1) { + VIR_DEBUG("Checking invariant TSC frequency"); + cpu->tsc =3D virHostCPUGetTscInfo(); + } else { + VIR_DEBUG("Host CPU does not support invariant TSC"); + } + cleanup: virCPUx86DataFree(cpuData); return ret; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 09:05:40 2024 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1559564970; cv=none; d=zoho.com; s=zohoarc; b=U3JSmMKJWyb9Y3O9Qdco0greHDSIEhpNgwSDe6UaBjQpkXeLQIP7SGyKgMaOfKaDoRtMf89gMBW/o+Fa6iKUu0AbYkJY/AZmPrXoC10gZ08E1IURcHLGcBQfixRPoL2v5dvtBmAjpobZqYHey22Y/QkdEHxkE4X3ZF82Q8pYUoE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559564970; 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:ARC-Authentication-Results; bh=96GMo84jPtKdQrQp4T3mPsGqtP7F8FoTyDmRaRHWghc=; b=l3acn7H/ulYHqLeTeTS1OxQrPZ//Ezqcskp4SI9yUOopRUYSUb7ZC6FeJ+e8O5aCWzY5eqJwIBabD86wzlhtradNm4Gb2xOZ0uu8GbHvUBNy52HLEujhfRGQ6vALtjwgAHVMredEShFdNjV7MxrdcBdlbKrSnQo1haYJBoA+Vms= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1559564970439325.0363129154334; Mon, 3 Jun 2019 05:29:30 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C53EF7F755; Mon, 3 Jun 2019 12:29:28 +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 99DB55D739; Mon, 3 Jun 2019 12:29:27 +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 574C518436AB; Mon, 3 Jun 2019 12:29:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x53CS8xT003654 for ; Mon, 3 Jun 2019 08:28:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2EC3661991; Mon, 3 Jun 2019 12:28:08 +0000 (UTC) Received: from orkuz.int.mamuti.net (unknown [10.40.205.163]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CDDA861992 for ; Mon, 3 Jun 2019 12:28:05 +0000 (UTC) Received: by orkuz.int.mamuti.net (Postfix, from userid 500) id 8BE982A5DF7; Mon, 3 Jun 2019 14:27:59 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Mon, 3 Jun 2019 14:27:58 +0200 Message-Id: <2a6087255aea19c7443cbf0aaa851619bbb5d51e.1559564736.git.jdenemar@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 7/7] qemu: Check TSC frequency before starting QEMU 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: , 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 03 Jun 2019 12:29:29 +0000 (UTC) Content-Type: text/plain; charset="utf-8" When migrating a domain with invtsc CPU feature enabled, the TSC frequency of the destination host must match the frequency used when the domain was started on the source host or the destination host has to support TSC scaling. If the frequencies do not match and the destination host does not support TSC scaling, QEMU will fail to set the right TSC frequency when starting vCPUs on the destination and thus migration will fail. However, this is quite late since both host might have spent significant time transferring memory and perhaps even storage data. By adding the check to libvirt we can let migration fail before any data starts to be sent over. If for some reason libvirt is unable to detect the host's TSC frequency or scaling support, we'll just let QEMU try and the migration will either succeed or fail later. Luckily, we mandate TSC frequency to be explicitly set in the domain XML to even allow migration of domains with invtsc. We can just check whether the requested frequency is compatible with the current host before starting QEMU. https://bugzilla.redhat.com/show_bug.cgi?id=3D1641702 Signed-off-by: Jiri Denemark Reviewed-by line into the commits before pushing. Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_process.c | 53 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index fa5909e9be..481daa937e 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -5282,6 +5282,56 @@ qemuProcessStartValidateDisks(virDomainObjPtr vm, } =20 =20 +static int +qemuProcessStartValidateTSC(virDomainObjPtr vm, + virCapsPtr caps) +{ + size_t i; + unsigned long long freq =3D 0; + virHostCPUTscInfoPtr tsc; + + for (i =3D 0; i < vm->def->clock.ntimers; i++) { + virDomainTimerDefPtr timer =3D vm->def->clock.timers[i]; + + if (timer->name =3D=3D VIR_DOMAIN_TIMER_NAME_TSC && + timer->frequency > 0) { + freq =3D timer->frequency; + break; + } + } + + if (freq =3D=3D 0) + return 0; + + VIR_DEBUG("Requested TSC frequency %llu Hz", freq); + + if (!caps->host.cpu || !caps->host.cpu->tsc) { + VIR_DEBUG("Host TSC frequency could not be probed"); + return 0; + } + + tsc =3D caps->host.cpu->tsc; + VIR_DEBUG("Host TSC frequency %llu Hz, scaling %s", + tsc->frequency, virTristateBoolTypeToString(tsc->scaling)); + + if (freq =3D=3D tsc->frequency || tsc->scaling =3D=3D VIR_TRISTATE_BOO= L_YES) + return 0; + + if (tsc->scaling =3D=3D VIR_TRISTATE_BOOL_ABSENT) { + VIR_DEBUG("TSC frequencies do not match and scaling support is " + "unknown, QEMU will try and possibly fail later"); + return 0; + } + + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Requested TSC frequency %llu Hz does not match " + "host (%llu Hz) and TSC scaling is not supported " + "by the host CPU"), + freq, tsc->frequency); + return -1; +} + + /** * qemuProcessStartValidate: * @vm: domain object @@ -5346,6 +5396,9 @@ qemuProcessStartValidate(virQEMUDriverPtr driver, if (qemuProcessStartValidateDisks(vm, qemuCaps) < 0) return -1; =20 + if (qemuProcessStartValidateTSC(vm, caps) < 0) + return -1; + VIR_DEBUG("Checking for any possible (non-fatal) issues"); =20 qemuProcessStartWarnShmem(vm); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list