From patchwork Sun Feb 11 08:41:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 199391 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp1833112dyd; Sun, 11 Feb 2024 00:43:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IFV4iljxP4d3T86EtazNlXJiYFaoR74kC2w1MeIU/Nl3xsWjCulel9TRWrSMRJvBA6DQZyk X-Received: by 2002:a0c:cb01:0:b0:68c:a83b:aec7 with SMTP id o1-20020a0ccb01000000b0068ca83baec7mr4870630qvk.50.1707641000428; Sun, 11 Feb 2024 00:43:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707641000; cv=pass; d=google.com; s=arc-20160816; b=TcFQN+WtrxBUZenAFM25w56NqbjPsqoS+k6uiK1jkpEdeMcyu8uvGoicPgPCw4RldV T3ad5kpODUJEGsAeoCXZ6+4WMg9hv6wQIR2UXEVH6jWtj3OHTFIp/wEW4TvDxevjWQn1 eHKGWQSfbSuJ2RpkbeNPqCuCtvkHKzEclFFnMPLiWxwEaSwDprF5b8xbTuUmkrsv1/cO VvZyv5B+yCdP4ig7jlhqvvWAvS3IKjOp3Dk0PcHht8kzhbCcOulHF3Sy387l11sqsoKJ gSNsIbq0zR5YVaJOJ/l/4efmdUj2i+CykGTmXKV4suuhf0bISxPC/hIRzo5HsL9eauNt B0wA== 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=21QfmUYeQ4YPKcq7TxRd5XqgWxLchGbi5oRsUkDf2P4=; fh=R08Q3DcPaeMOSPBIt4oMuN+3wLfLFRPtrTIK2ReMbyU=; b=nK08SghH0dPQ51LQutZ+UOLiWUgbz//hXp0+SWX5ghEzRyV8DkOl1G8KhCCRV5YCGF EPkEnDm2UyvMb8iRb9fKYqoKSkaDREqz8iUCCXF3o/CeSX9TEjt/cghGANoMtF6wRfB6 6tWCMD7ZwSx/awVdpeUGSy9ssw9aP5lrKQISjuHXVLisLPGXu1xOULaVqoxcYJbePgJr H07mzC9MNZTpuTmcOIWqFM5do8Fh6jT8TmTmYpgG7JJO91vJGtGTD9FdYuPA08fSrmPg 7QmrdF9g3Dbm05gnFE9JBoJkFYPPsc053qIFWsykaGvINYUDhyrgKyMdQGUSUgj+5/gN L1YQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="e+a1Br/u"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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-60666-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60666-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de X-Forwarded-Encrypted: i=2; AJvYcCVY/Gq2XhyiHlc+QSV34oAWjFdNCk0eoCHQVxOk8RwE6pD0blepILswU2NC+9MoWQrIYf1DXilgwPhHDKASfdFOmDZ4eQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 13-20020a0562140ccd00b0068caf864c2esi6006729qvx.312.2024.02.11.00.43.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Feb 2024 00:43:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-60666-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="e+a1Br/u"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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-60666-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60666-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 2C0D11C20AF0 for ; Sun, 11 Feb 2024 08:43:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A63DD5B5D1; Sun, 11 Feb 2024 08:41:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="e+a1Br/u"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="s9vYRLRV" 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 774D359173; Sun, 11 Feb 2024 08:41:34 +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=1707640896; cv=none; b=pFUWCfe5ELSBVfVa4F3i46zEMum6EfdzGMERzc7wGSdDmmfCl/FPDIHaxw6mYIG6M4PZQaCUgUyG58uhqUKEfCQNrsHwS0nNQNPKR371ZUGNMTougm35ZDGptgEITYa/82AWAurZOSxAU2sCWIYAP/4bmGhC0JsxJ2LpT34jyhM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707640896; c=relaxed/simple; bh=2bBr0+qomzpEdnAc8hw70BQqKueFNNkh3RgFIgB0WHc=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=AUC6BCGEY2Bskzna7OI7ruqWLjt1DnFv7WL5IVMxIRgaKmj0N2EbpttT8brQl14rKkpwS3wsp0LX5WZU1DmikINjgbtJupgN+Ra8dNrImfHNvyjw3dTwsP4LFPtg9qxH2NcZwLZqnH5ayY0BE+1ZV7iDKBrC2o97JnLwDDhyyXM= 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=e+a1Br/u; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=s9vYRLRV; 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: Sun, 11 Feb 2024 08:41:31 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1707640892; 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=21QfmUYeQ4YPKcq7TxRd5XqgWxLchGbi5oRsUkDf2P4=; b=e+a1Br/uQ7OZqr7ZiKEYDg0XrFasu+YUBhmqrlLTl349tuoJltu7wPUAssBymR6Ziu2iG9 IhBNdPD9elSBaavy/pKvTsH0wg6s16clrlxiPilOALM7Yglx8Go5GIb6RVHhESC7KE18jU Cy7zVhmucvcdJh1ybjBZ1zM/heUGCUrU5H8UM50X/pJGiJtfjPV5RXog2euIcT2r5gLlpI HBvBLJxGTI1hkCoFXxJncWNZXAbWcda9M2W0laBtseSWvRd6QaZJR8SjheLWjziD3Vjuuu p3/OuvPTuZPesEbWxoBA+faeGS4p9xwFeoEfeGrsqjKvJgMHmhF7nw6ayzWEVw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1707640892; 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=21QfmUYeQ4YPKcq7TxRd5XqgWxLchGbi5oRsUkDf2P4=; b=s9vYRLRVhTfMVtKdLXEuqjoflrgSPxEMT09J+oZuNS2/lCt9dVr9akKf+04r503Ab7KbaD oLkbda4JSHv1sLCg== From: "tip-bot2 for Peter Hilber" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: timers/ptp] x86/tsc: Add clocksource ID, set system_counterval_t.cs_id Cc: Peter Hilber , Thomas Gleixner , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20240201010453.2212371-4-peter.hilber@opensynergy.com> References: <20240201010453.2212371-4-peter.hilber@opensynergy.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <170764089118.398.9281896438790489662.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789656815550886314 X-GMAIL-MSGID: 1790591369155634166 The following commit has been merged into the timers/ptp branch of tip: Commit-ID: a2c1fe72062a5dd69de4dfe892f6436d6c0479dd Gitweb: https://git.kernel.org/tip/a2c1fe72062a5dd69de4dfe892f6436d6c0479dd Author: Peter Hilber AuthorDate: Thu, 01 Feb 2024 02:04:48 +01:00 Committer: Thomas Gleixner CommitterDate: Wed, 07 Feb 2024 17:05:21 +01:00 x86/tsc: Add clocksource ID, set system_counterval_t.cs_id Add a clocksource ID for TSC and a distinct one for the early TSC. Use distinct IDs for TSC and early TSC, since those also have distinct clocksource structs. This should help to keep existing semantics when comparing clocksources. Also, set the recently added struct system_counterval_t member cs_id to the TSC ID in the cases where the clocksource member is being set to the TSC clocksource. In the future, get_device_system_crosststamp() will compare the clocksource ID in struct system_counterval_t, rather than the clocksource. For the x86 ART related code, system_counterval_t.cs == NULL corresponds to system_counterval_t.cs_id == CSID_GENERIC (0). Signed-off-by: Peter Hilber Signed-off-by: Thomas Gleixner Link: https://lore.kernel.org/r/20240201010453.2212371-4-peter.hilber@opensynergy.com --- arch/x86/kernel/tsc.c | 28 +++++++++++++++++++++------- include/linux/clocksource_ids.h | 2 ++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c index 7978f31..fd567a0 100644 --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c @@ -54,6 +54,7 @@ static u32 art_to_tsc_numerator; static u32 art_to_tsc_denominator; static u64 art_to_tsc_offset; static struct clocksource *art_related_clocksource; +static bool have_art; struct cyc2ns { struct cyc2ns_data data[2]; /* 0 + 2*16 = 32 */ @@ -1168,6 +1169,7 @@ static struct clocksource clocksource_tsc_early = { .mask = CLOCKSOURCE_MASK(64), .flags = CLOCK_SOURCE_IS_CONTINUOUS | CLOCK_SOURCE_MUST_VERIFY, + .id = CSID_X86_TSC_EARLY, .vdso_clock_mode = VDSO_CLOCKMODE_TSC, .enable = tsc_cs_enable, .resume = tsc_resume, @@ -1190,6 +1192,7 @@ static struct clocksource clocksource_tsc = { CLOCK_SOURCE_VALID_FOR_HRES | CLOCK_SOURCE_MUST_VERIFY | CLOCK_SOURCE_VERIFY_PERCPU, + .id = CSID_X86_TSC, .vdso_clock_mode = VDSO_CLOCKMODE_TSC, .enable = tsc_cs_enable, .resume = tsc_resume, @@ -1309,8 +1312,11 @@ struct system_counterval_t convert_art_to_tsc(u64 art) do_div(tmp, art_to_tsc_denominator); res += tmp + art_to_tsc_offset; - return (struct system_counterval_t) {.cs = art_related_clocksource, - .cycles = res}; + return (struct system_counterval_t) { + .cs = art_related_clocksource, + .cs_id = have_art ? CSID_X86_TSC : CSID_GENERIC, + .cycles = res, + }; } EXPORT_SYMBOL(convert_art_to_tsc); @@ -1327,9 +1333,10 @@ EXPORT_SYMBOL(convert_art_to_tsc); * that this flag is set before conversion to TSC is attempted. * * Return: - * struct system_counterval_t - system counter value with the pointer to the + * struct system_counterval_t - system counter value with the ID of the * corresponding clocksource: * cycles: System counter value + * cs_id: The clocksource ID for validating comparability * cs: Clocksource corresponding to system counter value. Used * by timekeeping code to verify comparability of two cycle * values. @@ -1347,8 +1354,11 @@ struct system_counterval_t convert_art_ns_to_tsc(u64 art_ns) do_div(tmp, USEC_PER_SEC); res += tmp; - return (struct system_counterval_t) { .cs = art_related_clocksource, - .cycles = res}; + return (struct system_counterval_t) { + .cs = art_related_clocksource, + .cs_id = have_art ? CSID_X86_TSC : CSID_GENERIC, + .cycles = res, + }; } EXPORT_SYMBOL(convert_art_ns_to_tsc); @@ -1454,8 +1464,10 @@ out: if (tsc_unstable) goto unreg; - if (boot_cpu_has(X86_FEATURE_ART)) + if (boot_cpu_has(X86_FEATURE_ART)) { art_related_clocksource = &clocksource_tsc; + have_art = true; + } clocksource_register_khz(&clocksource_tsc, tsc_khz); unreg: clocksource_unregister(&clocksource_tsc_early); @@ -1480,8 +1492,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)) { art_related_clocksource = &clocksource_tsc; + have_art = true; + } clocksource_register_khz(&clocksource_tsc, tsc_khz); clocksource_unregister(&clocksource_tsc_early); diff --git a/include/linux/clocksource_ids.h b/include/linux/clocksource_ids.h index 16775d7..f846794 100644 --- a/include/linux/clocksource_ids.h +++ b/include/linux/clocksource_ids.h @@ -6,6 +6,8 @@ enum clocksource_ids { CSID_GENERIC = 0, CSID_ARM_ARCH_COUNTER, + CSID_X86_TSC_EARLY, + CSID_X86_TSC, CSID_MAX, };