Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp849093lqj; Mon, 3 Jun 2024 02:42:03 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXzdHX9VlXt10SEpm4N1c1aSV+CtwZ/EHZ9kmTrO6u0qoPplN6z9GYh9TskX1gjLph0xem4D5bppaxW5h0Dfd1MPovL5nURI2OgjUzasQ== X-Google-Smtp-Source: AGHT+IFkwBMZhcdHtcYhpNleLvHFeZSanwyQv9S/zFNahgmqCo7RUZKWuXWZ2Qhdm5GCu+TMANf7 X-Received: by 2002:a17:90a:fe0d:b0:2bd:d6c6:f454 with SMTP id 98e67ed59e1d1-2c1c4453724mr11914057a91.21.1717407723540; Mon, 03 Jun 2024 02:42:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717407723; cv=pass; d=google.com; s=arc-20160816; b=cZ5pgDgbVmgwI4LEJDjM0KOW4joH8ClVEJ85K8yiuRiUTgjIwuhw1PIaIMxJqo1dRS 1+fz5FD9Bn+BAxcq+WaaV7CRwozNOVG/AE5ac0RqtR5hPl4rFKslDS+QFDfxWWS43X/l a7v0a3dpMTKd/jYsNu8kVpqXEAXuD6q/dklp+76hd/0Fp9zRZAlu+csK0negaFzp6gRR g9Vi2hPO0mNAYi6AhN8bk0HcpDpU0Y06rJfRyOak0614lAND0FKUiJqAm8+3m+m3/A01 P20JCAodiRBO99C8gx0/YeDpZPIatwFCJAvcl5zn48tfdIkdKDvc2kOAhFuE31YQxSBi mOfg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=iHytbiUN8X8CpFsms4hh7FIVTLToKkddHrZ8kB4ikHE=; fh=R/648ax8lgQ7CPefTSXwDRHXI7yC07DFVmGeeSzVe80=; b=gHl8Jx6jBpbDpyYoNzUbFT2Gy2iJt5e54CczR0+r7q62Mygemw1vOiTkMK2CVZ3xMo 6i7jQfBNb7OMcoBediRCwZXUVtHLywrcCIeWeRCYf/xreLzbUSmUczm4RqiX5V18AZNC PTAWPhoCVQkTHverCKcBLg2YjcEOXw9Cv/lnWld974JAhI3v3XDljubyGhsQu2uzQOSx N8U64nWVM35RfuITyQFAko7HBjjoYKY+/Jl9e116/3iXNbVP31UakekDX/rDLVkiv2hx 3yamOEbaE1LpOgA7DLDPTyZkcFLyJQD/nQC9uVlYSk+UcNCJG2QnNJCtsQlO15G6BGHp 4PCA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="N6oKI/oD"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=+EmMLdLj; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-198889-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-198889-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2c241345303si873926a91.41.2024.06.03.02.42.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 02:42:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-198889-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="N6oKI/oD"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=+EmMLdLj; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-198889-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-198889-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id D7703287146 for ; Mon, 3 Jun 2024 09:34:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 84FB9126F39; Mon, 3 Jun 2024 09:30:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="N6oKI/oD"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="+EmMLdLj" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6566985C7F; Mon, 3 Jun 2024 09:30:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717407015; cv=none; b=HsZJAEmfGc5sGCm2liC3BzhRiZRB1FEqLSuDxxBz33UM4k9+UnqKvU9e7tK56SicnkEZknSqwQkw2XzhPfDrJKkbkSyBOHueTsMfb5UHbHn/Bbv/tbT6xe4CRU++/kWaMEEz2hHb2PPSs9wjSU+qIshnPWu+ouVQS7FdbqSQk68= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717407015; c=relaxed/simple; bh=yZGpd5u3l3lMVQG8iE8/TbABQQuAlad31356bld+Y9I=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=ZFwNAe1sgJJ/RYKEyuJoacamhez8TzO3dWcwk4tuP63+JCclang+0+yR/3fCzcGkYmm0Yn/AIEqgd4EaZy4HFZfYp5ALzwQnJMk0kUN3ztFUTfbtV/yxihIKxXO2kRpNSHk9WGDg6tWwck0RKYIBpxF7Yt2oo8QTO0zXSB8poak= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=N6oKI/oD; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=+EmMLdLj; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Mon, 03 Jun 2024 09:30:09 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1717407009; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iHytbiUN8X8CpFsms4hh7FIVTLToKkddHrZ8kB4ikHE=; b=N6oKI/oDda3MqDw/uzEm9ult8/umtaH+xbXxUvJJhfVtM6z8RttpY8Zb85Ve24OpULKueh VX5RPJTBFxwmNqgKuJ3SnlX2OLnXAhYR2KWMOcKOlfZlS15y8HxVMZ14kRddyBMmXkEs5c gmYcN+9LposZ0SvrvMWsZZxtqTex3+SWwlGpSeB70rh2obj9cfcTTptvENyoEzgFXQK3rU A+xo4jrYQURW+p1I4z6mfL333ECiV14TvCnn9WzQ1lhOFS7lymPgWiKrUYdGHHH9Ob+90A 7cQjUuDz08UCGKhSfFytQg86u48HCLku5QkID3puVPBeZuiX+n15NcF4V0fMpA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1717407009; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iHytbiUN8X8CpFsms4hh7FIVTLToKkddHrZ8kB4ikHE=; b=+EmMLdLjBNLenLHfpbuMBtz+z0k1kFN/x/WppT21j8loBPC+esfFl29NkBcmo/YASWFski NajB5NVXsZZ8MDCA== From: "tip-bot2 for Lakshmi Sowjanya D" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: timers/core] x86/tsc: Provide ART base clock information for TSC Cc: Thomas Gleixner , "Christopher S. Hall" , Lakshmi Sowjanya D , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20240513103813.5666-3-lakshmi.sowjanya.d@intel.com> References: <20240513103813.5666-3-lakshmi.sowjanya.d@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <171740700928.10875.14755603550947818962.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit The following commit has been merged into the timers/core branch of tip: Commit-ID: 3a52886c8f972c3a5b70bfec330c71817cd7fc63 Gitweb: https://git.kernel.org/tip/3a52886c8f972c3a5b70bfec330c71817cd7fc63 Author: Lakshmi Sowjanya D AuthorDate: Mon, 13 May 2024 16:08:03 +05:30 Committer: Thomas Gleixner CommitterDate: Mon, 03 Jun 2024 11:18:50 +02:00 x86/tsc: Provide ART base clock information for TSC The core code provides a new mechanism to allow conversion between ART and TSC. This allows to replace the x86 specific ART/TSC conversion functions. Prepare for removal by filling in the base clock conversion information for ART and associating the base clock to the TSC clocksource. The existing conversion functions will be removed once the usage sites are converted over to the new model. [ tglx: Massaged change log ] Co-developed-by: Thomas Gleixner Signed-off-by: Thomas Gleixner Co-developed-by: Christopher S. Hall Signed-off-by: Christopher S. Hall Signed-off-by: Lakshmi Sowjanya D Signed-off-by: Thomas Gleixner Link: https://lore.kernel.org/r/20240513103813.5666-3-lakshmi.sowjanya.d@intel.com --- arch/x86/kernel/tsc.c | 42 ++++++++++++++++++-------------- include/linux/clocksource_ids.h | 1 +- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c index 06b1707..d1888db 100644 --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c @@ -50,9 +50,9 @@ 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; +static struct clocksource_base art_base_clk = { + .id = CSID_X86_ART, +}; static bool have_art; struct cyc2ns { @@ -1074,7 +1074,7 @@ core_initcall(cpufreq_register_tsc_scaling); */ static void __init detect_art(void) { - unsigned int unused[2]; + unsigned int unused; if (boot_cpu_data.cpuid_level < ART_CPUID_LEAF) return; @@ -1089,13 +1089,14 @@ static void __init detect_art(void) tsc_async_resets) return; - cpuid(ART_CPUID_LEAF, &art_to_tsc_denominator, - &art_to_tsc_numerator, unused, unused+1); + cpuid(ART_CPUID_LEAF, &art_base_clk.denominator, + &art_base_clk.numerator, &art_base_clk.freq_khz, &unused); - if (art_to_tsc_denominator < ART_MIN_DENOMINATOR) + art_base_clk.freq_khz /= KHZ; + if (art_base_clk.denominator < ART_MIN_DENOMINATOR) return; - rdmsrl(MSR_IA32_TSC_ADJUST, art_to_tsc_offset); + rdmsrl(MSR_IA32_TSC_ADJUST, art_base_clk.offset); /* Make this sticky over multiple CPU init calls */ setup_force_cpu_cap(X86_FEATURE_ART); @@ -1303,13 +1304,13 @@ struct system_counterval_t convert_art_to_tsc(u64 art) { u64 tmp, res, rem; - rem = do_div(art, art_to_tsc_denominator); + rem = do_div(art, art_base_clk.denominator); - res = art * art_to_tsc_numerator; - tmp = rem * art_to_tsc_numerator; + res = art * art_base_clk.numerator; + tmp = rem * art_base_clk.numerator; - do_div(tmp, art_to_tsc_denominator); - res += tmp + art_to_tsc_offset; + do_div(tmp, art_base_clk.denominator); + res += tmp + art_base_clk.offset; return (struct system_counterval_t) { .cs_id = have_art ? CSID_X86_TSC : CSID_GENERIC, @@ -1356,7 +1357,6 @@ struct system_counterval_t convert_art_ns_to_tsc(u64 art_ns) } EXPORT_SYMBOL(convert_art_ns_to_tsc); - static void tsc_refine_calibration_work(struct work_struct *work); static DECLARE_DELAYED_WORK(tsc_irqwork, tsc_refine_calibration_work); /** @@ -1458,8 +1458,10 @@ out: if (tsc_unstable) goto unreg; - if (boot_cpu_has(X86_FEATURE_ART)) + if (boot_cpu_has(X86_FEATURE_ART)) { have_art = true; + clocksource_tsc.base = &art_base_clk; + } clocksource_register_khz(&clocksource_tsc, tsc_khz); unreg: clocksource_unregister(&clocksource_tsc_early); @@ -1484,8 +1486,10 @@ static int __init init_tsc_clocksource(void) * the refined calibration and directly register it as a clocksource. */ if (boot_cpu_has(X86_FEATURE_TSC_KNOWN_FREQ)) { - if (boot_cpu_has(X86_FEATURE_ART)) + if (boot_cpu_has(X86_FEATURE_ART)) { have_art = true; + clocksource_tsc.base = &art_base_clk; + } clocksource_register_khz(&clocksource_tsc, tsc_khz); clocksource_unregister(&clocksource_tsc_early); @@ -1509,10 +1513,12 @@ static bool __init determine_cpu_tsc_frequencies(bool early) if (early) { cpu_khz = x86_platform.calibrate_cpu(); - if (tsc_early_khz) + if (tsc_early_khz) { tsc_khz = tsc_early_khz; - else + } else { tsc_khz = x86_platform.calibrate_tsc(); + clocksource_tsc.freq_khz = tsc_khz; + } } else { /* We should not be here with non-native cpu calibration */ WARN_ON(x86_platform.calibrate_cpu != native_calibrate_cpu); diff --git a/include/linux/clocksource_ids.h b/include/linux/clocksource_ids.h index a4fa343..2bb4d8c 100644 --- a/include/linux/clocksource_ids.h +++ b/include/linux/clocksource_ids.h @@ -9,6 +9,7 @@ enum clocksource_ids { CSID_X86_TSC_EARLY, CSID_X86_TSC, CSID_X86_KVM_CLK, + CSID_X86_ART, CSID_MAX, };