Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753023AbcJMXK6 (ORCPT ); Thu, 13 Oct 2016 19:10:58 -0400 Received: from mga01.intel.com ([192.55.52.88]:45968 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751195AbcJMXKt (ORCPT ); Thu, 13 Oct 2016 19:10:49 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,490,1473145200"; d="scan'208";a="19465330" Date: Thu, 13 Oct 2016 16:16:19 -0700 From: Bin Gao To: Thomas Gleixner Cc: Ingo Molnar , "H. Peter Anvin" , John Stultz , Peter Zijlstra , x86@kernel.org, linux-kernel@vger.kernel.org, bin.gao@intel.com Subject: [PATCH v3] x86/tsc: add X86_FEATURE_TSC_KNOWN_FREQ flag Message-ID: <20161013231619.GA225074@worksta> References: <20160816174240.GA33372@worksta> <20160825164350.GA245186@worksta> <20161011211121.GA15041@worksta> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4528 Lines: 119 The X86_FEATURE_TSC_RELIABLE flag in Linux kernel implies both reliable (at runtime) and trustable (at calibration). But reliable running and trustable calibration are logically irrelevant. Per Thomas Gleixner's suggestion we would like to split this flag into two separate flags: X86_FEATURE_TSC_RELIABLE - running reliably X86_FEATURE_TSC_KNOWN_FREQ - frequency is known (no calibration required) These two flags allow Linux kernel to act differently based on processor/SoC's capability, i.e. no watchdog on TSC if TSC is reliable, and no calibration if TSC frequency is known. Current Linux kernel already gurantees calibration is skipped for processors that can report TSC frequency by CPUID or MSR. However, the delayed calibration is still not skipped for these CPUID/MSR capable processors. The new flag X86_FEATURE_TSC_KNOWN_FREQ added by this patch will gurantee the delayed calibration is skipped. Signed-off-by: Bin Gao --- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/kernel/tsc.c | 11 ++++++++++- arch/x86/kernel/tsc_msr.c | 6 ++++++ arch/x86/platform/intel-mid/mfld.c | 7 +++++-- arch/x86/platform/intel-mid/mrfld.c | 6 ++++-- 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index 1188bc8..2df6e86 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -106,6 +106,7 @@ #define X86_FEATURE_APERFMPERF ( 3*32+28) /* APERFMPERF */ #define X86_FEATURE_EAGER_FPU ( 3*32+29) /* "eagerfpu" Non lazy FPU restore */ #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 46b2f41..aed2dc3 100644 --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c @@ -702,6 +702,15 @@ unsigned long native_calibrate_tsc(void) } } + setup_force_cpu_cap(X86_FEATURE_TSC_KNOWN_FREQ); + + /* + * For Atom SoCs TSC is the only reliable clocksource. + * Mark TSC reliable so no watchdog on it. + */ + if (boot_cpu_data.x86_model == INTEL_FAM6_ATOM_GOLDMONT) + setup_force_cpu_cap(X86_FEATURE_TSC_RELIABLE); + return crystal_khz * ebx_numerator / eax_denominator; } @@ -1286,7 +1295,7 @@ static int __init init_tsc_clocksource(void) * Trust the results of the earlier calibration on systems * exporting a reliable TSC. */ - if (boot_cpu_has(X86_FEATURE_TSC_RELIABLE)) { + if (boot_cpu_has(X86_FEATURE_TSC_KNOWN_FREQ)) { clocksource_register_khz(&clocksource_tsc, tsc_khz); return 0; } diff --git a/arch/x86/kernel/tsc_msr.c b/arch/x86/kernel/tsc_msr.c index 0fe720d..8c33292 100644 --- a/arch/x86/kernel/tsc_msr.c +++ b/arch/x86/kernel/tsc_msr.c @@ -100,5 +100,11 @@ unsigned long cpu_khz_from_msr(void) #ifdef CONFIG_X86_LOCAL_APIC lapic_timer_frequency = (freq * 1000) / HZ; #endif + + setup_force_cpu_cap(X86_FEATURE_TSC_KNOWN_FREQ); + + /* Mark TSC reliable */ + setup_force_cpu_cap(X86_FEATURE_TSC_RELIABLE); + return res; } diff --git a/arch/x86/platform/intel-mid/mfld.c b/arch/x86/platform/intel-mid/mfld.c index 1eb47b6..6724ab9b 100644 --- a/arch/x86/platform/intel-mid/mfld.c +++ b/arch/x86/platform/intel-mid/mfld.c @@ -49,8 +49,11 @@ static unsigned long __init mfld_calibrate_tsc(void) fast_calibrate = ratio * fsb; pr_debug("read penwell tsc %lu khz\n", fast_calibrate); lapic_timer_frequency = fsb * 1000 / HZ; - /* mark tsc clocksource as reliable */ - set_cpu_cap(&boot_cpu_data, X86_FEATURE_TSC_RELIABLE); + + setup_force_cpu_cap(X86_FEATURE_TSC_KNOWN_FREQ); + + /* Mark TSC reliable */ + setup_force_cpu_cap(X86_FEATURE_TSC_RELIABLE); return fast_calibrate; } diff --git a/arch/x86/platform/intel-mid/mrfld.c b/arch/x86/platform/intel-mid/mrfld.c index 59253db..c8b9870 100644 --- a/arch/x86/platform/intel-mid/mrfld.c +++ b/arch/x86/platform/intel-mid/mrfld.c @@ -78,8 +78,10 @@ static unsigned long __init tangier_calibrate_tsc(void) pr_debug("Setting lapic_timer_frequency = %d\n", lapic_timer_frequency); - /* mark tsc clocksource as reliable */ - set_cpu_cap(&boot_cpu_data, X86_FEATURE_TSC_RELIABLE); + setup_force_cpu_cap(X86_FEATURE_TSC_KNOWN_FREQ); + + /* Mark TSC reliable */ + setup_force_cpu_cap(X86_FEATURE_TSC_RELIABLE); return fast_calibrate; } -- 1.9.1