Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2884151pxb; Tue, 24 Aug 2021 09:49:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxE66t8iiV4XOYcTrqyXTj4WKYpHmcsiHYJKD1B9ESJ4Y7YRX9WTFKrtRtA+RS0tKyQVzuI X-Received: by 2002:a05:6e02:1bc8:: with SMTP id x8mr27149557ilv.138.1629823768533; Tue, 24 Aug 2021 09:49:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629823768; cv=none; d=google.com; s=arc-20160816; b=rzAdH0v/kCAkKnzPzEKSmJxTj54ujA5csd5fOZjCg49suybWYQzgpRhGaIGggwy9y7 nJlKTG8lfij2zjwI7MCEaLCrtutzNeFTm5qhC6R44B6N7RrUY/A23XEWk1/JT6Zs2TvA 1vDfxUOah6kzGF2ADzWPd0HiDgUsY49LC2fqqCGOycJqsB2nK5iLpIjLbc6pmd4CcSAs 1AL06wPmp0ST6XNx3uYqM6wW5moDKikPegIAdOUl34aNYSUk3n8LBQQx+fTB9AzN4q/O le+Y4/rAxfDE0bmhX9LSRpIJQMbGYfSrdQV30VeXhWM29I4U9qx+QJ1hFLHGcJc9y7VB /iew== 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; bh=NonKJq+dQ7/wDuMXCGpxheQKXpHCHFdFsD2Y0NJWeMI=; b=YDBqEOSg4aq5K5W7XMVz0EQjr1hNVxCo5aH+TOTo8e3nyzrOlyj2IcroeAr9ZZjlYA HFXPmNCVQKNqYXK8I1EWWdqMGtIDHZ/im4nc2OUHrH41m8wtMLeQVVzXOihKNmJuQe6g 1ztvjJrfK5tZk7IpdH7WE7Wg9sEwnu10HDY5FfCnUiyu4vdOC6Lt4e4vFm+XA/7chQok GieDM3Mhh7ESCo0YRzJODmebi35RA6wL3rVAl1WavmzGjNgWqOBFBDruFBbSpUtO4hoP umz6Aq9lBWmHlj5jm2s27drI3YegWpcrKZT9xLzznVYR/sEDwe4W4tavFkczSxEPU9KF n5Fg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s7si18279360ilj.135.2021.08.24.09.49.11; Tue, 24 Aug 2021 09:49:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232907AbhHXQs7 (ORCPT + 99 others); Tue, 24 Aug 2021 12:48:59 -0400 Received: from mga02.intel.com ([134.134.136.20]:10207 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229896AbhHXQs6 (ORCPT ); Tue, 24 Aug 2021 12:48:58 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10086"; a="204550663" X-IronPort-AV: E=Sophos;i="5.84,347,1620716400"; d="scan'208";a="204550663" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Aug 2021 09:48:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,347,1620716400"; d="scan'208";a="684036701" Received: from inlubt0177.iind.intel.com ([10.223.67.91]) by fmsmga006.fm.intel.com with ESMTP; 24 Aug 2021 09:48:11 -0700 From: lakshmi.sowjanya.d@intel.com To: linus.walleij@linaro.org Cc: linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com, linux-kernel@vger.kernel.org, mgross@linux.intel.com, andriy.shevchenko@linux.intel.com, tamal.saha@intel.com, bala.senthil@intel.com, lakshmi.sowjanya.d@intel.com Subject: [RFC PATCH v1 03/20] arch: x86: Add ART support function to tsc code Date: Tue, 24 Aug 2021 22:17:44 +0530 Message-Id: <20210824164801.28896-4-lakshmi.sowjanya.d@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210824164801.28896-1-lakshmi.sowjanya.d@intel.com> References: <20210824164801.28896-1-lakshmi.sowjanya.d@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christopher Hall Add a function to 'read' the ART(Always Running Timer) value using TSC(Time Stamp Capture) conversion. The Intel PMC Timed I/O driver requires the current ART value to test for rollover. Signed-off-by: Christopher Hall Signed-off-by: Tamal Saha Co-developed-by: Lakshmi Sowjanya D Signed-off-by: Lakshmi Sowjanya D Reviewed-by: Mark Gross --- arch/x86/include/asm/tsc.h | 1 + arch/x86/kernel/tsc.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/arch/x86/include/asm/tsc.h b/arch/x86/include/asm/tsc.h index 01a300a9700b..a50b0102e5c1 100644 --- a/arch/x86/include/asm/tsc.h +++ b/arch/x86/include/asm/tsc.h @@ -28,6 +28,7 @@ static inline cycles_t get_cycles(void) return rdtsc(); } +extern u64 read_art_time(void); extern struct system_counterval_t convert_art_to_tsc(u64 art); extern struct system_counterval_t convert_art_ns_to_tsc(u64 art_ns); diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c index 2e076a459a0c..bbab6cf1a73b 100644 --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c @@ -1230,6 +1230,26 @@ int unsynchronized_tsc(void) return 0; } +/* + * Converts the current TSC to the current ART value using conversion + * factors discovered by detect_art() + */ +u64 read_art_time(void) +{ + u64 tsc, tmp, res, rem; + + tsc = read_tsc(NULL) - art_to_tsc_offset; + rem = do_div(tsc, art_to_tsc_numerator); + + res = tsc * art_to_tsc_denominator; + tmp = rem * art_to_tsc_denominator; + + do_div(tmp, art_to_tsc_numerator); + + return res + tmp; +} +EXPORT_SYMBOL(read_art_time); + /* * Convert ART to TSC given numerator/denominator found in detect_art() */ -- 2.17.1