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; }