From nobody Fri Mar 29 07:33:29 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=1559304083; cv=none; d=zoho.com; s=zohoarc; b=fOuJ60EgTbZ2nASgFSePscSHXm4D0oc0zzxgyR5DZeV6OeBkVeQEjBva+hwrN9Tb9U5QxE9hlX4E5QKYgjCf5EcN+VMst0eY5FWpjK6Aqy9hlQOSFeSUJLCbJfF36YrfaYFx0koKvvioKGJpRgDrF0qts1zpDP4CwzhJRYY2kpI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559304083; 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:ARC-Authentication-Results; bh=KKwR/BlPtjHM4IkS3t6d+UFz7FeT0PBdc/4kkevSkHc=; b=JbP2AW0w6oQ4HXDd9F0HUiqi0f2K4ab+Fhy3TWSNXPugZKi6PTsAxhTMGLgtxK9Lfvy6FE2ZKMVb6MyUAPED4WLvXWw2UPJXby7S4DG6Qk2t1isrhLn+wbjuwlt+Vk+B5aJCGYpOGoeaVJvwPmT3PsW4MN4Syjfk6xObNU9BAjc= 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 155930408351358.19383256833498; Fri, 31 May 2019 05:01:23 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6FBA6F9E95; Fri, 31 May 2019 12:01: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 896327F65D; Fri, 31 May 2019 12:01:01 +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 289B5E160; Fri, 31 May 2019 12:00:45 +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 x4VC0gRo010009 for ; Fri, 31 May 2019 08:00:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id 943FE2FC51; Fri, 31 May 2019 12:00:42 +0000 (UTC) Received: from orkuz.int.mamuti.net (ovpn-204-108.brq.redhat.com [10.40.204.108]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B3D3E17C31; Fri, 31 May 2019 12:00:22 +0000 (UTC) Received: by orkuz.int.mamuti.net (Postfix, from userid 500) id BFF772A037C; Fri, 31 May 2019 14:00:20 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Fri, 31 May 2019 14:00:07 +0200 Message-Id: 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 Cc: Marcelo Tosatti Subject: [libvirt] [PATCH 1/5] 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.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 31 May 2019 12:01:20 +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 --- 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 Fri Mar 29 07:33:29 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=1559304161; cv=none; d=zoho.com; s=zohoarc; b=D8hwWyusTGorLcqFas7WOIUN7K5hszw4VJoSz5nhuXNZ7tku1zhpTXctzH5KgO6RnFNt/EXdqDHoTKGpbLoSmVjO78t1BJbL3Fzhdvju2SPnDBoAxcawrGQp0s7YbTgMCXH33vT9WN0Nsap9y5wBDtg+z2sgTnJYuCYXuaZKN2o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559304161; 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:ARC-Authentication-Results; bh=h1r4CgYp+mRauN9ek+eXMOy26vXvIj6qWZGOxOWf1sY=; b=nZ2nY1ULmbyNUJ7lTP60oSQ9RQQ7uLPPqrcdt9mk4l8SGB0Oc9d9rvlfjny7JPySToQXQS5F2xot7pWN2T1/j7Xd8qw+gatXuifXYTeGCP9IizculZNctGBfFxBquxxJ12w11gXCeTaIWBF4+annid/wrTinh8u7nRQDeLaEPpo= 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 1559304161635920.4977385444278; Fri, 31 May 2019 05:02:41 -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 4C56330BC57B; Fri, 31 May 2019 12:02: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 2391C7E8E0; Fri, 31 May 2019 12:02:36 +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 D1E53E179; Fri, 31 May 2019 12:02:33 +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 x4VC0r4Q010265 for ; Fri, 31 May 2019 08:00:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 96EF56FC35; Fri, 31 May 2019 12:00:53 +0000 (UTC) Received: from orkuz.int.mamuti.net (ovpn-204-108.brq.redhat.com [10.40.204.108]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2243078379; Fri, 31 May 2019 12:00:22 +0000 (UTC) Received: by orkuz.int.mamuti.net (Postfix, from userid 500) id C2EB12A10F7; Fri, 31 May 2019 14:00:20 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Fri, 31 May 2019 14:00:08 +0200 Message-Id: <1389e4e9bd78c7b3a5835859beb6d641b9f04a14.1559303790.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 Cc: Marcelo Tosatti Subject: [libvirt] [PATCH 2/5] 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.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.49]); Fri, 31 May 2019 12:02:40 +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 --- 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 Fri Mar 29 07:33:29 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=1559304161; cv=none; d=zoho.com; s=zohoarc; b=cfW6mh9SQopN4Ua8UrYRoWswoievGM3YAPByrJ8rTNk2MPRIcqO1JV8ocJli1DNAcMm8n4wdrUI/x6jqIn5sJSDLL0SBW2Gk1sizN6eKKI8Y6d4ILpPbqctygIL/yvIkzg+8pg0A3sIBKPFFgrEspJWV5/9zWxOYtuF21ptCmXY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559304161; 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:ARC-Authentication-Results; bh=v1+zGMEaISRKLuTiy5Ag/zL4G4G8nT3g0JpCJT4wc8I=; b=MA+hU5/FscRTS0ooOqMI24lZHXYMdeQPSnLhuQOdM+DVpQMBUkvuLbmbl3HchFJW/ZgdamM3i5j+zGW9DK+8ZTeYkWxbfDhFP/QHyls/vfJ5B1o73aFBDg8t4MRoey66JGAri4fDIkyFICnf/OBvCunIdskXlAjiF9PLHxh6hxo= 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 1559304161105823.3391448893726; Fri, 31 May 2019 05:02:41 -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 20CD730C1B93; Fri, 31 May 2019 12:02:18 +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 E14CB60610; Fri, 31 May 2019 12:02:12 +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 98782184372D; Fri, 31 May 2019 12:02:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x4VC0iVn010091 for ; Fri, 31 May 2019 08:00:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 804641001E77; Fri, 31 May 2019 12:00:44 +0000 (UTC) Received: from orkuz.int.mamuti.net (ovpn-204-108.brq.redhat.com [10.40.204.108]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3EB7A101F97D; Fri, 31 May 2019 12:00:22 +0000 (UTC) Received: by orkuz.int.mamuti.net (Postfix, from userid 500) id C543D2A1176; Fri, 31 May 2019 14:00:20 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Fri, 31 May 2019 14:00:09 +0200 Message-Id: <93f6b0455356240157e1133fbdd6db8a86240c2a.1559303790.git.jdenemar@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Marcelo Tosatti Subject: [libvirt] [PATCH 3/5] 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Fri, 31 May 2019 12:02:39 +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 --- 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 Fri Mar 29 07:33:29 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=1559304143; cv=none; d=zoho.com; s=zohoarc; b=GJ8y8MqFKWvQUkdRXKnM8RfnICZLoywlkxpRPbxhgi8LOh+f5faRHQiIKRtedYfOqwx1epbxsul09FB26/uWruni3aDvgty68YI5RpTkOvK/dDuAlG0eh/fRrdXH0YmaOA8IKwFimDSQE31mLEao5w783Vxoul2K9La9BjVkFd8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559304143; 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:ARC-Authentication-Results; bh=bunfgVe5t1lC92pf41zoyb3ZqCTpJPlQitFRNVa8w3s=; b=fjm4eqSHJmFywQ5fZhYZ7ElngPA/MQw911IGz1fGEao9Gznw5uIC84CtlCPHbQxFDtKJ5WXcaTL77EFABlEwNGtNOl0Nq2/Fu9Q4dvmL1kFM+9pibK5Vl1TPxYc2kIhMRItMExk69xzIj+VhdW1ypPW/G0ytKym2JgoStpEHCUA= 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 1559304143295464.51224761774597; Fri, 31 May 2019 05:02:23 -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 5D52D81F33; Fri, 31 May 2019 12:02: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 C2865473C4; Fri, 31 May 2019 12:02:08 +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 7A06BE166; Fri, 31 May 2019 12:02:05 +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 x4VC0raA010251 for ; Fri, 31 May 2019 08:00:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5C5D17837A; Fri, 31 May 2019 12:00:53 +0000 (UTC) Received: from orkuz.int.mamuti.net (ovpn-204-108.brq.redhat.com [10.40.204.108]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 222C27836E; Fri, 31 May 2019 12:00:22 +0000 (UTC) Received: by orkuz.int.mamuti.net (Postfix, from userid 500) id C77DC2A1179; Fri, 31 May 2019 14:00:20 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Fri, 31 May 2019 14:00:10 +0200 Message-Id: <2533c96ba96cea8e27e03c7d87e43ebf8caccea7.1559303790.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 Cc: Marcelo Tosatti Subject: [libvirt] [PATCH 4/5] 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.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.25]); Fri, 31 May 2019 12:02:22 +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 --- 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 Fri Mar 29 07:33:29 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=1559304102; cv=none; d=zoho.com; s=zohoarc; b=Loi6pgQ0Z7uUjRt5XEvKGJleWbLCSb7glJ1+bAly6t8n6eU80CMxPAMKHvidx26Mm7expz55ekCCbnq7lIwmbKrwv/qRLG6q4/wlGExxBW7pOnulqQKnpbUB4C3qTZzfzkwKdbd0BhIN7p5zk/GajAlHo0N1Y2ZlsXSkvGoWy60= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559304102; 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:ARC-Authentication-Results; bh=96GMo84jPtKdQrQp4T3mPsGqtP7F8FoTyDmRaRHWghc=; b=IFyPepES9qlKo/QPrnhYXXfQc8QL2T/UL/dXyr2o0jJp8xA3uOBKkIt9/i2wHH3zmrgijRmR/Z/H7G8dqonoBbLOtmtUn8HMDi/p+HjvR1czl2ygBBeXJF8fXIRmxb4LCsq5vqYJOvkKNFU8tbvqpFBH1MqgRhXB8gY6yeIfdZo= 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 1559304102728752.9394199677056; Fri, 31 May 2019 05:01:42 -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 865F1C0587F5; Fri, 31 May 2019 12:01:13 +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 44CF05DE64; Fri, 31 May 2019 12:01:04 +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 A038B18436A2; Fri, 31 May 2019 12:00:48 +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 x4VC0i80010096 for ; Fri, 31 May 2019 08:00:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9BA2E7E8F7; Fri, 31 May 2019 12:00:44 +0000 (UTC) Received: from orkuz.int.mamuti.net (ovpn-204-108.brq.redhat.com [10.40.204.108]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 381917E8F0; Fri, 31 May 2019 12:00:44 +0000 (UTC) Received: by orkuz.int.mamuti.net (Postfix, from userid 500) id C9E092A117C; Fri, 31 May 2019 14:00:20 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Fri, 31 May 2019 14:00:11 +0200 Message-Id: <44403ef05c5e4a9809bcb4e8546ae41dcdb49c7c.1559303790.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 Cc: Marcelo Tosatti Subject: [libvirt] [PATCH 5/5] 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 31 May 2019 12:01:41 +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 --- 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