Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2663872lqp; Mon, 25 Mar 2024 06:06:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV7103R0JKvbs906JKRnG4TcxEbcnzrDmC0BtraT8E0XCoeQZcwHPsM02PvMDX8eyUoD19bLDBM1X9DBgTZETesko68EZO8/j/qVqcy3w== X-Google-Smtp-Source: AGHT+IGtqXcGBA1XB0wRrZyul6JDvRZytWznHI3ENj2j8p0VZm6W3YkSpg81gRvyb3pbV7dO5TNI X-Received: by 2002:aa7:cf1a:0:b0:56c:1a47:7a26 with SMTP id a26-20020aa7cf1a000000b0056c1a477a26mr1023947edy.28.1711372002209; Mon, 25 Mar 2024 06:06:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711372002; cv=pass; d=google.com; s=arc-20160816; b=tUZwZ8E95M+nf8JnuXVXbXWZafxrkZq7wTP36kfso0MNa4veqehJbh6c1juZ+pFtAm 2yUcfFAHySqD68X4INiZ9TbDEwT5vHeiJObCNqNWz7msKKQRaZeMpSkOPPVJyUV/VstB ZEhs9oranW7YDn9qnsZfBoR0Jc4baJDYM3Mg9c0eA05p9hBJYEGLd8iBYAKiGeVb961P UiLKkioigljtoLBFeIHJphYeEz12poWV24E/BH+oiWhMS8GftxKzCjPzho3+Up4CSMLw r9aeF6kdh8xjcR1Nw1wtC8FYc/41TEX4OFHYHxAsWsViEWm2pOVKGMQcfD6of1Lu0fA6 RZ5Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:organization:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=m1OVN9reSCRWZsB2W5YY+RMkQ6cKVI+TLZLr2Hg28q0=; fh=wgq3SFFcpYoLsYNr1Fy+HYH2+WGNJgTNu+AnKLa6P2U=; b=sK1wFTcQS+n4+X7YAzI89JSVd0LMj2F/su5g+2DRzJ2y6+mRBUPdTx6/2Ix7TCMZiX bhBir6pKP+Y9sZHunLtp+XWb9+7jv0G79AJ3NN8kaxnpz5qfO012RpWoQPRWS88cD/gV Q4hstHs+WxQwR2vf9lPOUYZrez1JBJicJTfyFRDXo9iSyuOC3/H3xp/Huiwc6GpWOaRc YvYKsHqXXy8ZFDIQBEOEo5RIrkJzUg3wO9EYj6B1ie+dsaDqD3d3wvHLNi6bT0bX9fbc qy06rlFRqhDtjzTxN520ULSdaGe9wN7xa9zwBV46JphJORX/JAc8wxS8of03dwkwqiyf 3MAA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="mE13p/MM"; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-116578-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116578-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id fe3-20020a056402390300b0056c0d9621d0si941271edb.658.2024.03.25.06.06.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 06:06:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-116578-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="mE13p/MM"; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-116578-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116578-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id E3EA41F3B149 for ; Mon, 25 Mar 2024 13:06:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 335C913D511; Mon, 25 Mar 2024 08:53:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="mE13p/MM" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 688C61607A8; Mon, 25 Mar 2024 06:42:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711348938; cv=none; b=NJmunuLwrk5asK+cfFDPjPeB02ItgKdzOmTuVHKmLmItfL/Ym01nPaYDBnmg8dwKR7P5/D+wDqTQIChnZbGqyavkjZOFZVkR5W0wRrzdFC1M2Gi20EnsKin4kKwTIBk9HK/WFr9Efk0MMIoIZ25nDq4tg+M5mj3T6BpJapP/sTo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711348938; c=relaxed/simple; bh=I/EwrCmdvQfW3F1Dq8qT6GRyUT8dQLcc34j3rdWdn4M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ely7px65MhMkmqMkyWutyHuxxVSor1JnwQZfTuC7sA1Wk4II8ojecNjDUVgueMeK2c8wihSDiE+B78GvuSP7PckrCacP52XR55oGronj6AFX9aH/ry5D+P6941kSh0C+Rrer+AqIQcbAX0KFB8QGAlA9sMSVedyDrT839FRY/8g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=mE13p/MM; arc=none smtp.client-ip=192.198.163.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711348937; x=1742884937; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=I/EwrCmdvQfW3F1Dq8qT6GRyUT8dQLcc34j3rdWdn4M=; b=mE13p/MM7yPeotba7fz8QdXsEs13TycvCiaJm1eGYiWn4HHsxjFBKmHA WkBRHvkwKWNa8+pyRs+D7A5TXd5B4KGWxjB8Ga9VlulKKZtVXWbHBKLjv 72udsjtT4KjWc+oTN1/1R8ddhaU4c0qp/Tf0mtx7P40KrsnE1cal4Q8DK Fox9War5vxx+KLSraVPnEyD+siFKVKllV41QyhPoUd3LqCuKOiLMp5kbf EyxdufrYG2auz1rzcot4R9p8g9KWZPs+AlQJAtjwdOx8EQxGUixVHwfal gE3yjoNPKE2b2K2SRQriiDxc3n4+QObhb3JFFwqfaYpijrsRMFrN8N2Um w==; X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="6191517" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="6191517" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2024 23:42:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="38629681" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.251.211.155]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2024 23:42:04 -0700 From: Adrian Hunter To: Thomas Gleixner Cc: Michael Ellerman , Nicholas Piggin , Christophe Leroy , "Aneesh Kumar K.V" , "Naveen N. Rao" , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Andy Lutomirski , Vincenzo Frascino , John Stultz , Stephen Boyd , Peter Zijlstra , Randy Dunlap , Bjorn Helgaas , Arnd Bergmann , Anna-Maria Behnsen , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org Subject: [PATCH V2 14/19] timekeeping: Consolidate timekeeping helpers Date: Mon, 25 Mar 2024 08:40:18 +0200 Message-Id: <20240325064023.2997-15-adrian.hunter@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240325064023.2997-1-adrian.hunter@intel.com> References: <20240325064023.2997-1-adrian.hunter@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Content-Transfer-Encoding: 8bit Consolidate timekeeping helpers, making use of timekeeping_cycles_to_ns() in preference to directly using timekeeping_delta_to_ns(). Suggested-by: Thomas Gleixner Signed-off-by: Adrian Hunter --- kernel/time/timekeeping.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 618328cd4bc4..1bbfe1ff8d24 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -237,7 +237,9 @@ static void timekeeping_check_update(struct timekeeper *tk, u64 offset) } } -static inline u64 timekeeping_debug_get_delta(const struct tk_read_base *tkr) +static inline u64 timekeeping_cycles_to_ns(const struct tk_read_base *tkr, u64 cycles); + +static inline u64 timekeeping_debug_get_ns(const struct tk_read_base *tkr) { struct timekeeper *tk = &tk_core.timekeeper; u64 now, last, mask, max, delta; @@ -266,22 +268,22 @@ static inline u64 timekeeping_debug_get_delta(const struct tk_read_base *tkr) */ if (unlikely((~delta & mask) < (mask >> 3))) { tk->underflow_seen = 1; - delta = 0; + now = last; } /* Cap delta value to the max_cycles values to avoid mult overflows */ if (unlikely(delta > max)) { tk->overflow_seen = 1; - delta = tkr->clock->max_cycles; + now = last + max; } - return delta; + return timekeeping_cycles_to_ns(tkr, now); } #else static inline void timekeeping_check_update(struct timekeeper *tk, u64 offset) { } -static inline u64 timekeeping_debug_get_delta(const struct tk_read_base *tkr) +static inline u64 timekeeping_debug_get_ns(const struct tk_read_base *tkr) { BUG(); } @@ -389,7 +391,7 @@ static __always_inline u64 __timekeeping_get_ns(const struct tk_read_base *tkr) static inline u64 timekeeping_get_ns(const struct tk_read_base *tkr) { if (IS_ENABLED(CONFIG_DEBUG_TIMEKEEPING)) - return timekeeping_delta_to_ns(tkr, timekeeping_debug_get_delta(tkr)); + return timekeeping_debug_get_ns(tkr); return __timekeeping_get_ns(tkr); } -- 2.34.1