Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7122098ybi; Mon, 22 Jul 2019 07:28:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqwpM1Hd4aW+9ldHR4EOjnYMESoFrBWbSvN/H74nr0k5C+TOnfwMQmrCEeQCXwnVrMVSeNkH X-Received: by 2002:a17:90a:5288:: with SMTP id w8mr77950803pjh.61.1563805736752; Mon, 22 Jul 2019 07:28:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563805736; cv=none; d=google.com; s=arc-20160816; b=nvL3glODIpLbHFyFoCTMXXmMS70uqavk1x+sLTxgBHQlRkiM2exmdwR1KiboV718WK 6KfdgDDOrDMIZsBx/0xelv/0vM/HAqWTNbUs6Pr6rAczkTOZg/pFC0ib6a4mnScOCR7d TjMVcrthHP7tpi0933u+B30UuS8dSGhqyRBjidFwurFz2jWSahNt98mNHBep2M4omiau 43reYoSN3TiN4gstKlER+4jAQTLugY3y5BCsL2SbQ9m5dlaPXoIlSDyhEqmQLLQ0UoUE 8Eq+MvZQfpFMM5tF2EblWA6deMVCimemZ59y7HiK8N6KiYK5ZtaNmkRU3vfcQDcrqIZi wutQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=l9PlNWc/g8MA3kCkK8s7oc8y4yz4eXoxbYpxU3Csnpc=; b=x/JfTcimmxIZKb/gI3GvSjxxprgJl/T/VB2T8wpw7/HPz/OOQ+C8xxUZG9AGXQCI18 /R/P3zmk25jZnc0TiodtV2w4X5h2aCeRCqTF/N24hVO0lm+Us9xPWidTbq+FlLtVmdrN Q66pF/tkWHQjnGcJ/v90WnvVoOcU2jkDBZ5CLRJmzZJlQZyjM2hwzKc8RQ8kvQqOtnoi Drhv0AWBPghBkDN6MDLvi/VcBehac45+E9gQSgJutnZDRVSuY7ThFqM3dlnMq2/6Lx5x pXvK7ISQi6RCxUDt/Il1ibhDe6hwaqKz/M2/xBHKuiMWUxlKtq9kDDFYj3GJWuDTLoAm FY7A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a1si11691471pff.73.2019.07.22.07.28.40; Mon, 22 Jul 2019 07:28:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729691AbfGVKdv (ORCPT + 99 others); Mon, 22 Jul 2019 06:33:51 -0400 Received: from foss.arm.com ([217.140.110.172]:35458 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729679AbfGVKdq (ORCPT ); Mon, 22 Jul 2019 06:33:46 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 926C11596; Mon, 22 Jul 2019 03:33:45 -0700 (PDT) Received: from filthy-habits.cambridge.arm.com (filthy-habits.cambridge.arm.com [10.1.197.61]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 236233F71A; Mon, 22 Jul 2019 03:33:44 -0700 (PDT) From: Marc Zyngier To: Thomas Gleixner , John Stultz , Pavel Tatashin , Petr Mladek , Sergey Senozhatsky , Steven Rostedt , Will Deacon , Catalin Marinas , Mark Rutland Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] arm64: Allow early time stamping Date: Mon, 22 Jul 2019 11:33:30 +0100 Message-Id: <20190722103330.255312-4-marc.zyngier@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190722103330.255312-1-marc.zyngier@arm.com> References: <20190722103330.255312-1-marc.zyngier@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In order to provide early timestamping on arm64 systems, we provide a timestamp_clock() function that is available as early as possible. This function simply returns the current counter value scales in nanoseconds, and 0-based. In order to deal with the idiosyncrasies of some broken platforms, we condition this on the frequency being set in the CNTFRQ_EL0 register, and revert back to using local_clock() as soon as it starts returning non-zero values. Signed-off-by: Marc Zyngier --- arch/arm64/Kconfig | 3 +++ arch/arm64/kernel/setup.c | 44 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 3adcec05b1f6..ac3882ddc1c2 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -911,6 +911,9 @@ config ARCH_WANT_HUGE_PMD_SHARE config ARCH_HAS_CACHE_LINE_SIZE def_bool y +config ARCH_HAS_TIMESTAMP_CLOCK + def_bool y + config ARCH_ENABLE_SPLIT_PMD_PTLOCK def_bool y if PGTABLE_LEVELS > 2 diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index 9c4bad7d7131..cf21e3df7165 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -28,10 +29,12 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -269,8 +272,49 @@ arch_initcall(reserve_memblock_reserved_regions); u64 __cpu_logical_map[NR_CPUS] = { [0 ... NR_CPUS-1] = INVALID_HWID }; +static u64 notrace ts_counter_read_cc(const struct cyclecounter *cc) +{ + return __arch_counter_get_cntvct(); +} + +static struct cyclecounter ts_cc __ro_after_init = { + .read = ts_counter_read_cc, + .mask = CLOCKSOURCE_MASK(56), +}; + +static struct timecounter ts_tc; + +static bool ts_cc_valid __ro_after_init = false; + +static __init void timestamp_clock_init(void) +{ + u64 frq = arch_timer_get_cntfrq(); + + if (!frq) + return; + + clocks_calc_mult_shift(&ts_cc.mult, &ts_cc.shift, + frq, NSEC_PER_SEC, 3600); + /* timestamp starts at 0 (local_clock is a good enough approximation) */ + timecounter_init(&ts_tc, &ts_cc, local_clock()); + ts_cc_valid = true; + pr_info("Using timestamp clock @%lluMHz\n", frq / 1000 / 1000); +} + +u64 timestamp_clock(void) +{ + u64 ns = local_clock(); + + if (likely(ns || !ts_cc_valid)) + return ns; + + return timecounter_read(&ts_tc); +} + void __init setup_arch(char **cmdline_p) { + timestamp_clock_init(); + init_mm.start_code = (unsigned long) _text; init_mm.end_code = (unsigned long) _etext; init_mm.end_data = (unsigned long) _edata; -- 2.20.1