From patchwork Tue Oct 17 05:24:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "D, Lakshmi Sowjanya" X-Patchwork-Id: 153910 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3911301vqb; Mon, 16 Oct 2023 22:26:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG0S4pL0ZFvsQO9c1UIIOceCbK84OnNVWQ1j46HgXYDyPbxCLRkvtjVBAN2Ik+NPuVNl23P X-Received: by 2002:a05:6a00:1d09:b0:6bc:ff89:a2fc with SMTP id a9-20020a056a001d0900b006bcff89a2fcmr1273457pfx.2.1697520367825; Mon, 16 Oct 2023 22:26:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697520367; cv=none; d=google.com; s=arc-20160816; b=xv80AThn42y2XxEUFJVop9KxoYwhYYc8aPbY27QUQImAoj/mgBLygsWMjEY+InpbTS jkyVQEGgL4stOFUi0CccuUiFIMCMLc4yQO4i5k2Sx/xM+xl14hJEjh5HpuOETyY1zGmn d2hD/pVaNobuk+/eaNlnn/g8camm3rG4eMLil4scdR1CKYHND8ijGycCzP0vZCfPd6bI RfarUxoTzGNNMOInOx2FgM3Ke/xwouBAmaK5Cxq6hqea/6G4BWBs6A2qbsIZF7GpjSYa 7paSliRBMUN1UG32qUeSoy9+7KPUJppDIhaXesenApQOVGChVjaRlHtd2pk4Tyt7sFwU RtLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=5VHCL6QifMk3HdRf9SKU2n9b95r9/BHr+7Gp/8xzW4A=; fh=O1j13Mu+YXmD8t08/npRM3Uw5SAxbjMOF7NW+nWn+v8=; b=PHVKO2Kzr2THBzb1K2ivSN7hERa38o/I11Nr7ObQCwA83oqTuX3V9T52K4qHmp96v0 x886vQbrtdn0fd+885PTbVRWW00toGxlMqW1RjtGO8zD41pre4Cz9DEUrHGaMROPqlEX nLyG+hArUOV+87zft7W0Xy4FtXxt0wmuetFAN++6VoZWSOK0GArO3al4qIafppH0fZZq K7XO33sqtblwZGvgf2Q38Nf7YSsZV3OhHp4GcL0Lot2DmJe+YMBfCRc/WgR+IwBpzfhg HW5sbNSXq3Y8LCIuDp9yiM66iQYHGeCqLCxEDnlHsf0lg9qvQvlGExXHZy1TW537+uEY gnXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BUrl9gV6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id g1-20020a056a0023c100b006be03d801basi887048pfc.331.2023.10.16.22.26.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 22:26:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BUrl9gV6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 37CCD802FB1B; Mon, 16 Oct 2023 22:26:03 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234467AbjJQFZu (ORCPT + 19 others); Tue, 17 Oct 2023 01:25:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234562AbjJQFZa (ORCPT ); Tue, 17 Oct 2023 01:25:30 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41C5D10DD; Mon, 16 Oct 2023 22:25:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697520315; x=1729056315; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=zZsZ6JtO9YdL4Vld6agzB3/nEAv9fTcA8dq0o18MW2g=; b=BUrl9gV65NscXhHRrpQkdwbJB368xbk72nFvkteUnVRSpVT5lW83MLEn pLoFtjzNH2XG2kj71JpG8EPgCplkef89h6mleAD0kfTxzCcHb6WYdbx3w b/n/oGu5u4w+aV81WRJ4e2N0Gb9VVYk6a3PJApATabtGi5WJv3ZGJ7Xdb 2O9HHeAaXLTLHGRsIepc+2J4sp7xlIIg2l9ibaSfP/sTQJHgCSold4LqY OdfMhjJWv5o66LdZI61gIoEA+cOpJ5uc7xbJypeCUZlwiXjKM/ii2IzNQ Swiaum5sbOKUOdixg5OWUK8vqpD7LLbWti3RUkSz9c9C9avVUY5njKm1V g==; X-IronPort-AV: E=McAfee;i="6600,9927,10865"; a="388561752" X-IronPort-AV: E=Sophos;i="6.03,231,1694761200"; d="scan'208";a="388561752" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2023 22:25:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10865"; a="1087357996" X-IronPort-AV: E=Sophos;i="6.03,231,1694761200"; d="scan'208";a="1087357996" Received: from inlubt0316.iind.intel.com ([10.191.20.213]) by fmsmga005.fm.intel.com with ESMTP; 16 Oct 2023 22:25:10 -0700 From: lakshmi.sowjanya.d@intel.com To: tglx@linutronix.de, jstultz@google.com, giometti@enneenne.com, corbet@lwn.net, linux-kernel@vger.kernel.org Cc: x86@kernel.org, linux-doc@vger.kernel.org, andriy.shevchenko@linux.intel.com, eddie.dong@intel.com, christopher.s.hall@intel.com, pandith.n@intel.com, mallikarjunappa.sangannavar@intel.com, thejesh.reddy.t.r@intel.com, lakshmi.sowjanya.d@intel.com Subject: [PATCH v1 3/6] x86/tsc: Check if the current clock source is related to ART(Always Running Timer) Date: Tue, 17 Oct 2023 10:54:54 +0530 Message-Id: <20231017052457.25287-4-lakshmi.sowjanya.d@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231017052457.25287-1-lakshmi.sowjanya.d@intel.com> References: <20231017052457.25287-1-lakshmi.sowjanya.d@intel.com> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Mon, 16 Oct 2023 22:26:03 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779979117227924011 X-GMAIL-MSGID: 1779979117227924011 From: Lakshmi Sowjanya D Add interface 'is_current_clocksource_art_related()' in tsc.c to check if the current clock source is ART related. Add helper function 'is_current_clocksource(clock)' in timekeeping.c to check if the provided clock matches the current clock source. Co-developed-by: Christopher Hall Signed-off-by: Christopher Hall Signed-off-by: Lakshmi Sowjanya D --- arch/x86/include/asm/tsc.h | 1 + arch/x86/kernel/tsc.c | 12 ++++++++++++ include/linux/timekeeping.h | 2 ++ kernel/time/timekeeping.c | 15 +++++++++++++++ 4 files changed, 30 insertions(+) diff --git a/arch/x86/include/asm/tsc.h b/arch/x86/include/asm/tsc.h index f5cff8d4f61e..cdfe34e55cf3 100644 --- a/arch/x86/include/asm/tsc.h +++ b/arch/x86/include/asm/tsc.h @@ -32,6 +32,7 @@ static inline cycles_t get_cycles(void) extern int convert_tsc_to_art(const struct system_counterval_t *tsc, u64 *art); extern struct system_counterval_t convert_art_to_tsc(u64 art); extern struct system_counterval_t convert_art_ns_to_tsc(u64 art_ns); +extern bool is_current_clocksource_art_related(void); extern void tsc_early_init(void); extern void tsc_init(void); diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c index 92b800015d8f..2d6b1b5b5b3e 100644 --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -1295,6 +1296,17 @@ int unsynchronized_tsc(void) return 0; } +/* + * Checks if the current clocksource is ART related clocksource + * + * Return: 1 on success, 0 on failure. + */ +bool is_current_clocksource_art_related(void) +{ + return is_current_clocksource(art_related_clocksource); +} +EXPORT_SYMBOL_GPL(is_current_clocksource_art_related); + /* * Converts input TSC to the corresponding ART value using conversion * factors discovered by detect_art(). diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h index e5eb6699d691..9bf7970b3b2f 100644 --- a/include/linux/timekeeping.h +++ b/include/linux/timekeeping.h @@ -292,6 +292,8 @@ extern int get_device_system_crosststamp( extern int ktime_convert_real_to_system_counter(ktime_t sys_realtime, struct system_counterval_t *ret); +extern bool is_current_clocksource(struct clocksource *clock); + /* * Simultaneously snapshot realtime and monotonic raw clocks */ diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index ff6a4c7387ee..986089d36ba5 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -1357,6 +1357,21 @@ int ktime_convert_real_to_system_counter(ktime_t sys_realtime, } EXPORT_SYMBOL_GPL(ktime_convert_real_to_system_counter); +/** + * is_current_clocksource - Checks if the supplied clock source matches with the + * MONOTONIC clock. + * + * @clock: pointer to the clocksource to be checked + * + * Return: true if the clocks match, false otherwise. + */ +bool is_current_clocksource(struct clocksource *clock) +{ + struct tk_read_base *tkr = &tk_core.timekeeper.tkr_mono; + return clock == READ_ONCE(tkr->clock); +} +EXPORT_SYMBOL_GPL(is_current_clocksource); + /** * do_settimeofday64 - Sets the time of day. * @ts: pointer to the timespec64 variable containing the new time