From patchwork Tue Apr 2 17:49:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heitor Alves de Siqueira X-Patchwork-Id: 1074768 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44YcCv0Qhdz9sSW; Wed, 3 Apr 2019 04:49:30 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1hBNXG-0006Uq-II; Tue, 02 Apr 2019 17:49:22 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.86_2) (envelope-from ) id 1hBNXE-0006UO-6t for kernel-team@lists.ubuntu.com; Tue, 02 Apr 2019 17:49:20 +0000 Received: from mail-qk1-f199.google.com ([209.85.222.199]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1hBNXD-0002Ml-Oj for kernel-team@lists.ubuntu.com; Tue, 02 Apr 2019 17:49:19 +0000 Received: by mail-qk1-f199.google.com with SMTP id w124so12151236qkb.12 for ; Tue, 02 Apr 2019 10:49:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Yf0aalxSifHVZ2o2Ka/zUuwZ3MPyejwNbdCWr+AJO+8=; b=pcRkOXNkksZ+1d34b5eMYWQbxpVgyab7tIjBrEnAYfrTpfKAtdm+kpiK/zsNowyudZ GdQbVAl8fuPPA6JsXLOzlKJWxdszZ9hM5+a4/zr9iFS0CgC9phDqqdDGXaMuer+KQVDl UjrgR4l3p3slp7xroNWUiWRc3MucFsXV+Vzw573eq6H9VVMnAzkG4CDU1cyjMbHTSRNt AkWCBzBFr1jNp1kTcFZtvyEh7yFq5IePVOXtf4BUfy5AlaqTiedwPzXaxBspAmVsuwum z/8WdcYuw6LHi6q4zLHoU4ilJ0NbxY41b1Mmxk7g6ZKa8/fGoK9lkrJRWhWVuyOfhqxC 1Ldg== X-Gm-Message-State: APjAAAVq2agVica/vNJWU+yxt3RKcutNS52FcsXFEBepTtrFj8ompjQw I4q8ADNKJqTzuTH0XhWnMylRew4TbPSJtHzHxKo4+JxcTplzAP+pg5YaPfEeR4Ht4jb/UO6140C BQBBVwUvhhcCJdYUmm3oihMrvmyi57VfJhmgqA8k3Aw== X-Received: by 2002:aed:3e94:: with SMTP id n20mr59502257qtf.268.1554227358637; Tue, 02 Apr 2019 10:49:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqwhY7OBUWnwOwwYaSEmqwZX+iP5GVvTCQiCMwDDeeuYBVvNIb1B8xmyCfHaFYNKp71fjvXcGg== X-Received: by 2002:aed:3e94:: with SMTP id n20mr59502241qtf.268.1554227358437; Tue, 02 Apr 2019 10:49:18 -0700 (PDT) Received: from localhost.localdomain ([2804:14d:ac80:5443:6d3:b0ff:febf:db19]) by smtp.gmail.com with ESMTPSA id g12sm7937378qki.76.2019.04.02.10.49.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Apr 2019 10:49:17 -0700 (PDT) From: "Heitor R. Alves de Siqueira" To: kernel-team@lists.ubuntu.com Subject: [X][PATCH 1/2] x86/tsc: Add X86_FEATURE_TSC_KNOWN_FREQ flag Date: Tue, 2 Apr 2019 14:49:01 -0300 Message-Id: <20190402174902.20122-2-halves@canonical.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190402174902.20122-1-halves@canonical.com> References: <20190402174902.20122-1-halves@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Bin Gao BugLink: https://bugs.launchpad.net/bugs/1822821 The X86_FEATURE_TSC_RELIABLE flag in Linux kernel implies both reliable (at runtime) and trustable (at calibration). But reliable running and trustable calibration independent of each other. Add a new flag X86_FEATURE_TSC_KNOWN_FREQ, which denotes that the frequency is known (via MSR/CPUID). This flag is only meant to skip the long term calibration on systems which have a known frequency. Add X86_FEATURE_TSC_KNOWN_FREQ to the skip the delayed calibration and leave X86_FEATURE_TSC_RELIABLE in place. After converting the existing users of X86_FEATURE_TSC_RELIABLE to use either both flags or just X86_FEATURE_TSC_KNOWN_FREQ we can seperate the functionality. Suggested-by: Thomas Gleixner Signed-off-by: Bin Gao Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1479241644-234277-2-git-send-email-bin.gao@linux.intel.com Signed-off-by: Thomas Gleixner (cherry picked from commit 47c95a46d0fae07762f0a38aa3709ae63f307048) Signed-off-by: Heitor R. Alves de Siqueira --- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/kernel/tsc.c | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index bd39531e12c9..1e13ff9bda0e 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -105,6 +105,7 @@ #define X86_FEATURE_AMD_DCM ( 3*32+27) /* multi-node processor */ #define X86_FEATURE_APERFMPERF ( 3*32+28) /* APERFMPERF */ #define X86_FEATURE_NONSTOP_TSC_S3 ( 3*32+30) /* TSC doesn't stop in S3 state */ +#define X86_FEATURE_TSC_KNOWN_FREQ ( 3*32+31) /* TSC has known frequency */ /* Intel-defined CPU features, CPUID level 0x00000001 (ecx), word 4 */ #define X86_FEATURE_XMM3 ( 4*32+ 0) /* "pni" SSE-3 */ diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c index 5927e11ad2c5..b66d4dadf9cf 100644 --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c @@ -1222,10 +1222,15 @@ static int __init init_tsc_clocksource(void) clocksource_tsc.flags |= CLOCK_SOURCE_SUSPEND_NONSTOP; /* - * Trust the results of the earlier calibration on systems - * exporting a reliable TSC. + * When TSC frequency is known (retrieved via MSR or CPUID), we skip + * the refined calibration and directly register it as a clocksource. + * + * We still keep the TSC_RELIABLE flag here to avoid regressions - + * it will be removed after all the conversion for other code paths + * connected to this flag is done. */ - if (boot_cpu_has(X86_FEATURE_TSC_RELIABLE)) { + if (boot_cpu_has(X86_FEATURE_TSC_RELIABLE) || + boot_cpu_has(X86_FEATURE_TSC_KNOWN_FREQ)) { clocksource_register_khz(&clocksource_tsc, tsc_khz); return 0; } From patchwork Tue Apr 2 17:49:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heitor Alves de Siqueira X-Patchwork-Id: 1074766 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44YcCv1M4lz9sSd; Wed, 3 Apr 2019 04:49:31 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1hBNXJ-0006Vx-RY; Tue, 02 Apr 2019 17:49:25 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.86_2) (envelope-from ) id 1hBNXF-0006Uj-Mq for kernel-team@lists.ubuntu.com; Tue, 02 Apr 2019 17:49:21 +0000 Received: from mail-qk1-f197.google.com ([209.85.222.197]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1hBNXF-0002Mv-8z for kernel-team@lists.ubuntu.com; Tue, 02 Apr 2019 17:49:21 +0000 Received: by mail-qk1-f197.google.com with SMTP id 77so12277684qkd.9 for ; Tue, 02 Apr 2019 10:49:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QWy6LllBxcnDJG365aGAQyO4UUvgnPgubijQLfSncu4=; b=Qylx6nGKrnDK+Or7gv35FnrFyqKpwtzzZ8TqIURLwXBO6Ovc4pLcfg0VqO9L2aLCbE kasTQocXqvrKvH0yFi5et1HqSumxKL8kvIgG04Q0bdNjGBFxLeX85y1t6RJBBCazpLvS unPPG2sSvH0z8OsB/0QfKwzo1WhvD2dRn/iet/b/zeOpKuIOnKihUyEqZ5GpPg9NkLyL 91nJKOiO4reAihFp5ZuO3seuCK54fOQEWolMtcISX9Rmh5dvgHu+bXdHL3M+OKfvbKd8 W8fhg+o1nfA8CZyj5FZvA91EwzjO7/NSMAD+SXj1WdkimmYHyzF059MuAW5x/jn+uEQ0 4TTg== X-Gm-Message-State: APjAAAVHxDqbflSOjlpAwcrmvyddNZgRTUokGHw5SJr3lm4pp3mkR74V Tw8xOmiTIrNFioOm5q0kwIuNyXqCqTdUp275y2MTxSRAfg5BZMVuSDrcz08fF/3FVmM2d/AR5b5 tG+4jhdHOa51WlD+zFh9mrismmK8m9yP62T3OO8gtuQ== X-Received: by 2002:aed:2314:: with SMTP id h20mr61439478qtc.24.1554227360197; Tue, 02 Apr 2019 10:49:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqx7Lc4JfCTHwFKKU8y98gbCXeK4vEoOvJUG9y4jo5Fp6QgKLcTYr3DAMXIEGpxvi/8+WQ+STQ== X-Received: by 2002:aed:2314:: with SMTP id h20mr61439470qtc.24.1554227360063; Tue, 02 Apr 2019 10:49:20 -0700 (PDT) Received: from localhost.localdomain ([2804:14d:ac80:5443:6d3:b0ff:febf:db19]) by smtp.gmail.com with ESMTPSA id g12sm7937378qki.76.2019.04.02.10.49.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Apr 2019 10:49:19 -0700 (PDT) From: "Heitor R. Alves de Siqueira" To: kernel-team@lists.ubuntu.com Subject: [X][PATCH 2/2] kvmclock: fix TSC calibration for nested guests Date: Tue, 2 Apr 2019 14:49:02 -0300 Message-Id: <20190402174902.20122-3-halves@canonical.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190402174902.20122-1-halves@canonical.com> References: <20190402174902.20122-1-halves@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Peng Hao BugLink: https://bugs.launchpad.net/bugs/1822821 Inside a nested guest, access to hardware can be slow enough that tsc_read_refs always return ULLONG_MAX, causing tsc_refine_calibration_work to be called periodically and the nested guest to spend a lot of time reading the ACPI timer. However, if the TSC frequency is available from the pvclock page, we can just set X86_FEATURE_TSC_KNOWN_FREQ and avoid the recalibration. 'refine' operation. Suggested-by: Peter Zijlstra Signed-off-by: Peng Hao [Commit message rewritten. - Paolo] Signed-off-by: Paolo Bonzini (cherry picked from commit e10f7805032365cc11c739a97f226ebb48aee042) Signed-off-by: Heitor R. Alves de Siqueira --- arch/x86/kernel/kvmclock.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c index ec1b06dc82d2..dd77acfee614 100644 --- a/arch/x86/kernel/kvmclock.c +++ b/arch/x86/kernel/kvmclock.c @@ -140,6 +140,7 @@ static unsigned long kvm_get_tsc_khz(void) src = &hv_clock[cpu].pvti; tsc_khz = pvclock_tsc_khz(src); put_cpu(); + setup_force_cpu_cap(X86_FEATURE_TSC_KNOWN_FREQ); return tsc_khz; }