From nobody Mon May 6 13:44:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1605097056; cv=none; d=zohomail.com; s=zohoarc; b=Ms5+z8YqlLbYZoc4TJ1uWUwqQ0GmNCSjX2yKZD3hyIJqgmG0WjSlWKUOx9OZyaQiyI5IAjZeTTcIsi01xUOoqB+pK1XfqybK8FUkdXTzCUSt5/sIfGwTg1A9wUD8ACaCWx9nNu9SRiBfp+aVHfN73Qw/nESB2tSj1NYjPdB8olg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605097056; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=sZVd+DOoZQaKfdEQzlzuooWynN07fMihEIc40U6Yw9A=; b=npWFycaLFJmCSeqFWXnq7M+W112/jHCYgYzbJDJQXgI74Exwj8S/dR0LNG/QcF2JpkYDME9wLBGoNJx2V0dZuzg0vIu2kmZnCC8IreWesVIjK1z410M9deEYYUuBP0P2wEsFcTpqW1gdDwgTFwTWt3Id4ZiQQ9VZfx9vXlWf8rQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1605097056274560.4289559049352; Wed, 11 Nov 2020 04:17:36 -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-442-mKro2-nAMdWNj6QDhLDWdg-1; Wed, 11 Nov 2020 07:17:32 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6B72B106B270; Wed, 11 Nov 2020 12:17:25 +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 0F90F5DA6A; Wed, 11 Nov 2020 12:17:24 +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 CE3251800B70; Wed, 11 Nov 2020 12:17:21 +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 0ABC9NbZ021126 for ; Wed, 11 Nov 2020 07:09:23 -0500 Received: by smtp.corp.redhat.com (Postfix) id 178DF55775; Wed, 11 Nov 2020 12:09:23 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.40.194.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DE35B55760 for ; Wed, 11 Nov 2020 12:09:20 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 8A8A9240B19; Wed, 11 Nov 2020 13:09:18 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605097055; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=sZVd+DOoZQaKfdEQzlzuooWynN07fMihEIc40U6Yw9A=; b=EXpcd0tdjh17hy9c4Nmnj58ZA70AFqUlGGQ6sH0v9nwATWtmq3a+CK7qYFrfekQ4nd1jqI WmdC/xzo/LMAdXXfheIcUPoZyOoSB0cbGqy3bhEJfvVxMZlHKI3nsd7k7MRLmbvctLEe72 CKvad7KhHLUSacHENvp3rUtnE9LTfIQ= X-MC-Unique: mKro2-nAMdWNj6QDhLDWdg-1 From: Jiri Denemark To: libvir-list@redhat.com Subject: [libvirt PATCH] qemu: Do not require TSC frequency to strictly match host Date: Wed, 11 Nov 2020 13:09:13 +0100 Message-Id: <6d84af8e8e4d4f9fcfd3d37fce5b1373c161ba22.1605096553.git.jdenemar@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com 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.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Some CPUs provide a way to read exact TSC frequency, while measuring it is required on other CPUs. However, measuring is never exact and the result may slightly differ across reboots. For this reason both Linux kernel and QEMU recently started allowing for guests TSC frequency to fall into +/- 250 ppm tolerance interval around the host TSC frequency. Let's do the same to avoid unnecessary failures (esp. during migration) in case the host frequency does not exactly match the frequency configured in a domain XML. https://bugzilla.redhat.com/show_bug.cgi?id=3D1839095 Signed-off-by: Jiri Denemark Reviewed-by: Daniel Henrique Barboza --- src/qemu/qemu_process.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 0a36b49c85..7f56ddf114 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -5358,12 +5358,18 @@ qemuProcessStartValidateDisks(virDomainObjPtr vm, } =20 =20 +/* 250 parts per million (ppm) is a half of NTP threshold */ +#define TSC_TOLERANCE 250 + static int qemuProcessStartValidateTSC(virQEMUDriverPtr driver, virDomainObjPtr vm) { size_t i; unsigned long long freq =3D 0; + unsigned long long tolerance; + unsigned long long minFreq; + unsigned long long maxFreq; virHostCPUTscInfoPtr tsc; g_autoptr(virCPUDef) cpu =3D NULL; =20 @@ -5389,23 +5395,34 @@ qemuProcessStartValidateTSC(virQEMUDriverPtr driver, } =20 tsc =3D cpu->tsc; - VIR_DEBUG("Host TSC frequency %llu Hz, scaling %s", - tsc->frequency, virTristateBoolTypeToString(tsc->scaling)); + tolerance =3D tsc->frequency * TSC_TOLERANCE / 1000000; + minFreq =3D tsc->frequency - tolerance; + maxFreq =3D tsc->frequency + tolerance; + + VIR_DEBUG("Host TSC frequency %llu Hz, scaling %s, tolerance +/- %llu = Hz", + tsc->frequency, virTristateBoolTypeToString(tsc->scaling), + tolerance); + + if (freq > minFreq && freq < maxFreq) { + VIR_DEBUG("Requested TSC frequency is within tolerance interval"); + return 0; + } =20 - if (freq =3D=3D tsc->frequency || tsc->scaling =3D=3D VIR_TRISTATE_BOO= L_YES) + if (tsc->scaling =3D=3D VIR_TRISTATE_BOOL_YES) return 0; =20 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"); + VIR_DEBUG("Requested TSC frequency falls outside tolerance range a= nd " + "scaling support is unknown, QEMU will try and possibly " + "fail later"); return 0; } =20 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); + _("Requested TSC frequency %llu Hz is outside tolerance= " + "range ([%llu, %llu] Hz) around host frequency %llu H= z " + "and TSC scaling is not supported by the host CPU"), + freq, minFreq, maxFreq, tsc->frequency); return -1; } =20 --=20 2.29.2