Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2884540pxb; Tue, 24 Aug 2021 09:50:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzUw3b9IlbIi2KrExGrpv2GRQmYVUQwrjgmSHUZWSEDlf1hmidrfm3hZPxv1bBzrllmlG0q X-Received: by 2002:a05:6e02:1905:: with SMTP id w5mr27683576ilu.165.1629823800628; Tue, 24 Aug 2021 09:50:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629823800; cv=none; d=google.com; s=arc-20160816; b=DredKQvTonpniJsIOfe1UuuD8L2DqqC59uulUTh1Hu3qNiENnIHFbgCx54GahuT8Lz Z/AIeqymCq/bhdSmdQ5XysiB8V3BLbI4lxigmsEOoyJFb7aYEvfzIwHLVWV0exQbU/Uq bkCSguRuECnwttmZ2Ris4XVlB99GgeLHPjVcvEaCnmmocqTKph+HMcDp5k9O4i641VHh l1TNCi0h5CnJvnn0ITVRD/gB2avq2UBhOAXG58saYZCyuVg/HBI+fS1VF7DzHkZs1gBD a+s4pzj+e5hYmp35fcLjGPPWnhY+hhQHNd6bAYPADwPaEPq2gJUjKRrBXkpoY/PcLg0Z Zs8g== 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=VK6KGGfdIaOVo722FB4qPIuTmb3ECEpBpA6j4IKItDk=; b=Q3JrXLWCEJ20+o1uopXuI6GxVPLXkPU6xhdCJmqPTFDVReRae0gCA6RxPPW2IkY9SN 2vjhSIMoMmzOXBtdMywuM9gOcUQ30TIITaF4P8J4lghxmy8YF+lFC/kk7Q/shxAhmOyJ 0OZaaIgBgdToJrFNASjwf8KVe+AZQRnMDwzZYvHMRQBceScd8Tx1K1HZNVI3bM7Ph2gO 70xvcHECjpV4isydQ4sSraz93AM+QBBvT74aIW2BB02xDzRbgE4nv6fsRk9/B+4RIDbf HnI0buqI/9Q6ZnVBgo1HHkQk57emDmDb5fVHxcM/FZ8NFZYvS1Vkb/XELRgVPCTg9HLY KDLg== 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 b16si16283149ior.73.2021.08.24.09.49.49; Tue, 24 Aug 2021 09:50:00 -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 S233049AbhHXQt0 (ORCPT + 99 others); Tue, 24 Aug 2021 12:49:26 -0400 Received: from mga02.intel.com ([134.134.136.20]:10241 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233027AbhHXQtR (ORCPT ); Tue, 24 Aug 2021 12:49:17 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10086"; a="204550726" X-IronPort-AV: E=Sophos;i="5.84,347,1620716400"; d="scan'208";a="204550726" 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:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,347,1620716400"; d="scan'208";a="684036842" Received: from inlubt0177.iind.intel.com ([10.223.67.91]) by fmsmga006.fm.intel.com with ESMTP; 24 Aug 2021 09:48:30 -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 09/20] arch: x86: Add TSC to ART translation Date: Tue, 24 Aug 2021 22:17:50 +0530 Message-Id: <20210824164801.28896-10-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: Lakshmi Sowjanya D Add a function to convert TSC(Time Stamp Capture) time to ART. The Intel(R) PMC Timed I/O device uses ART to trigger output events. The TSC to ART translation converts the TSC value yielded by ktime_convert_real_to_system_counter() to ART. The conversion is required to program the COMPV register that will be compared against the art time to generate output events. Co-developed-by: Christopher Hall Signed-off-by: Christopher Hall Signed-off-by: Tamal Saha Signed-off-by: Lakshmi Sowjanya D Reviewed-by: Mark Gross --- arch/x86/include/asm/tsc.h | 3 +++ arch/x86/kernel/tsc.c | 35 ++++++++++++++++++++++++++++------- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/arch/x86/include/asm/tsc.h b/arch/x86/include/asm/tsc.h index a50b0102e5c1..f1de7ede3ec9 100644 --- a/arch/x86/include/asm/tsc.h +++ b/arch/x86/include/asm/tsc.h @@ -8,6 +8,8 @@ #include #include +struct system_counterval_t; + /* * Standard way to access the cycle counter. */ @@ -29,6 +31,7 @@ static inline cycles_t get_cycles(void) } extern u64 read_art_time(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); diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c index bbab6cf1a73b..040109228100 100644 --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c @@ -1231,22 +1231,43 @@ int unsynchronized_tsc(void) } /* - * Converts the current TSC to the current ART value using conversion + * Converts input TSC to the corresponding ART value using conversion * factors discovered by detect_art() */ -u64 read_art_time(void) +int convert_tsc_to_art(const struct system_counterval_t *system_counter, u64 *art) { - u64 tsc, tmp, res, rem; + u64 tmp, res, rem; + + if (system_counter->cs != art_related_clocksource) + return -EINVAL; - tsc = read_tsc(NULL) - art_to_tsc_offset; - rem = do_div(tsc, art_to_tsc_numerator); + res = system_counter->cycles - art_to_tsc_offset; + rem = do_div(res, art_to_tsc_numerator); - res = tsc * art_to_tsc_denominator; + *art = res * art_to_tsc_denominator; tmp = rem * art_to_tsc_denominator; do_div(tmp, art_to_tsc_numerator); + *art += tmp; + + return 0; +} +EXPORT_SYMBOL(convert_tsc_to_art); + +/* + * Converts the current TSC to the current ART value using conversion + * factors discovered by detect_art() + */ +u64 read_art_time(void) +{ + struct system_counterval_t tsc; + u64 art = 0; + + tsc.cs = art_related_clocksource; + tsc.cycles = read_tsc(NULL); + convert_tsc_to_art(&tsc, &art); - return res + tmp; + return art; } EXPORT_SYMBOL(read_art_time); -- 2.17.1