Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2414444rwd; Sun, 21 May 2023 20:55:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7bPLcB+BjtlTrlQsuhD1tMCCpuCRfxZLtsHRerizoDMroxfaH7grolhVvRef95Zvj1PLmF X-Received: by 2002:a05:6a21:329b:b0:10b:cb77:5403 with SMTP id yt27-20020a056a21329b00b0010bcb775403mr1378823pzb.52.1684727718117; Sun, 21 May 2023 20:55:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684727718; cv=none; d=google.com; s=arc-20160816; b=pqQT5otuFt7bcAnFSh6HJXp4w28Qu7qMiafH8KDC+lWnH2KB8Emhk9d93xTDYApqXA xuLUfQ/1A/dGqLWHnZqgBUaawkTL9OWLGh3fDAXnoxqhkCRFvw0AtOhWOnI1vn1v+YaL oKlL+shuAniXPFLVZMrOwC5ig/SYw4XKOwSflwpQK9GbC2hP/pDdwW0Qab9HcAzI43oc MwGIkqsoMcJIL7Y/iTwWfjT1OZ7YdWCxz7KyupGwrMenfIVJUH9KSih7G7HKDaV9fGki IAadgd6HeomXHbDMW4jRCA3NebUze2s4C+gsNULDzfdFqyG4e8Bh5TwTeSpzUxzLC9D1 Lt8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=/SoaAZneV/IWUj4Nwp+KpLLGoV0BDyB38DSmShyTM9E=; b=aaX5NpnbwhW+039fTpWSX3On7wd6YH42ROPlvU99aiKbnBx1Sdl2UZSfPPT4xXNPl8 G7qlqKGRRoqt0cUDPUhj0tS4fpW4jCGzOWA1C1IDMXV0svbrLIFGbuw3wVoZIy1uIew6 7wEzSWe3Az36HtBbnXruHcqJpV3JbUeHRwdUxCfkXCAyol9y4Oblii1Y1vLuiW180oOX LCm1m5tknFzxAfWwkwxJ1wf5pQb41l+nye5wD9oNyydXqvyiVkXHznmGiBh+9r95cAmJ liYPXAUfABVGRY/VVOcoOlTXAZWLFhjFxUQb1sG+Bz6YyGt8JQh5haJBto907b6nHfMV x+6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=k5R3ktOX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h19-20020a17090ac39300b0024ddf090102si3951039pjt.56.2023.05.21.20.55.02; Sun, 21 May 2023 20:55:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=k5R3ktOX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229676AbjEVDhS (ORCPT + 99 others); Sun, 21 May 2023 23:37:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229501AbjEVDhC (ORCPT ); Sun, 21 May 2023 23:37:02 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBB7DA2 for ; Sun, 21 May 2023 20:37:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1684726621; x=1716262621; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=P59aXtyfm/ISccYK7l1gh94sKmTWDcB1nL/Li5f4TEA=; b=k5R3ktOXkdkt0+QT6+0OUnnjFlCtu1g5BcSiKlgOnMr8fWofsbXdACSw 2JM03bymWJiWZ/FDw9y9IKYZmafvavn0fkU7gt+bDOEjE1WfFRCxCXVCA QayN3eETImf5BnjwyPN4Nf8EWQEsQazCW2NJ/lgaX2AbeYys3O85MHbps Hy4Gw7MAVhHh4NT1axLbn+TSYreprOi10XyxozdEi33VNt8a9TdN7jjpm 7nkqtTxkMVk2U+yxFIzjRoYzo/zhcPAeS7Gv3g7bew+sByTY6eMe/4Pn2 LnET4VN1atNRHmo70FimFJx8UWrcm0avaeSHLsmcsMNtg3EJHjyDoCG3q g==; X-IronPort-AV: E=McAfee;i="6600,9927,10717"; a="350327417" X-IronPort-AV: E=Sophos;i="6.00,183,1681196400"; d="scan'208";a="350327417" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2023 20:37:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10717"; a="815499748" X-IronPort-AV: E=Sophos;i="6.00,183,1681196400"; d="scan'208";a="815499748" Received: from feng-clx.sh.intel.com ([10.238.200.228]) by fmsmga002.fm.intel.com with ESMTP; 21 May 2023 20:36:59 -0700 From: Feng Tang To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Peter Zijlstra , paulmck@kernel.org, rui.zhang@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org Cc: Feng Tang Subject: [PATCH RFC] x86/tsc: Make recalibration default on for TSC_KNOWN_FREQ cases Date: Mon, 22 May 2023 11:30:18 +0800 Message-Id: <20230522033018.1276836-1-feng.tang@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit a7ec817d5542 ("x86/tsc: Add option to force frequency recalibration with HW timer") was added to handle cases that the firmware has bug and provides a wrong TSC frequency number, and it is optional given that this kind of firmware issue rarely happens (Paul reported once [1]). But Rui reported that some Sapphire Rapids platform met this issue again recently, and as firmware is also a kind of 'software' which can't be bug free, make the recalibration default on. When the values from firmware and HW timer's calibration have big gap, raise a warning and let vendor to check which side is broken. One downside is, many VMs also has X86_FEATURE_TSC_KNOWN_FREQ set, and they will also do this recalibration. [1]. https://lore.kernel.org/lkml/20221117230910.GI4001@paulmck-ThinkPad-P17-Gen-1/ Signed-off-by: Feng Tang --- Documentation/admin-guide/kernel-parameters.txt | 4 ---- arch/x86/kernel/tsc.c | 14 ++++---------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 9e5bab29685f..a826ab3b5dfb 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -6451,10 +6451,6 @@ in situations with strict latency requirements (where interruptions from clocksource watchdog are not acceptable). - [x86] recalibrate: force recalibration against a HW timer - (HPET or PM timer) on systems whose TSC frequency was - obtained from HW or FW using either an MSR or CPUID(0x15). - Warn if the difference is more than 500 ppm. [x86] watchdog: Use TSC as the watchdog clocksource with which to check other HW timers (HPET or PM timer), but only on systems where TSC has been deemed trustworthy. diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c index 344698852146..b77c5b1ad304 100644 --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c @@ -48,8 +48,6 @@ static DEFINE_STATIC_KEY_FALSE(__use_tsc); int tsc_clocksource_reliable; -static int __read_mostly tsc_force_recalibrate; - static u32 art_to_tsc_numerator; static u32 art_to_tsc_denominator; static u64 art_to_tsc_offset; @@ -310,8 +308,6 @@ static int __init tsc_setup(char *str) __func__); tsc_as_watchdog = 0; } - if (!strcmp(str, "recalibrate")) - tsc_force_recalibrate = 1; if (!strcmp(str, "watchdog")) { if (no_tsc_watchdog) pr_alert("%s: tsc=watchdog overridden by earlier tsc=nowatchdog\n", @@ -1395,7 +1391,6 @@ static void tsc_refine_calibration_work(struct work_struct *work) else freq = calc_pmtimer_ref(delta, ref_start, ref_stop); - /* Will hit this only if tsc_force_recalibrate has been set */ if (boot_cpu_has(X86_FEATURE_TSC_KNOWN_FREQ)) { /* Warn if the deviation exceeds 500 ppm */ @@ -1456,17 +1451,16 @@ static int __init init_tsc_clocksource(void) clocksource_tsc.flags |= CLOCK_SOURCE_SUSPEND_NONSTOP; /* - * When TSC frequency is known (retrieved via MSR or CPUID), we skip - * the refined calibration and directly register it as a clocksource. + * When TSC frequency is known (retrieved via MSR or CPUID), we + * directly register it as a clocksource. As the firmware could + * be wrong (very unlikely) about the values, the recalibration + * by hardware timer is kept just as a sanity check. */ if (boot_cpu_has(X86_FEATURE_TSC_KNOWN_FREQ)) { if (boot_cpu_has(X86_FEATURE_ART)) art_related_clocksource = &clocksource_tsc; clocksource_register_khz(&clocksource_tsc, tsc_khz); clocksource_unregister(&clocksource_tsc_early); - - if (!tsc_force_recalibrate) - return 0; } schedule_delayed_work(&tsc_irqwork, 0); -- 2.34.1