From patchwork Mon Jul 22 10:33:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 169362 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp7351125ilk; Mon, 22 Jul 2019 03:33:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqykgk8Rw7zyUvsACr0QP7gmJXuvPLl4KWBp+UbkZBfrHl/tdqBW2026hlJAa+AJsJP3rCsW X-Received: by 2002:a17:902:2ac8:: with SMTP id j66mr71227622plb.273.1563791626116; Mon, 22 Jul 2019 03:33:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563791626; cv=none; d=google.com; s=arc-20160816; b=KGXurJqI50g30ZrOHSOiyep54k2/L5v9f427mN0tNcKot71ZUuifrwIhsc+aGqtQ48 ENpb9RNRIUTD5Nu0M4KfQ7BdFl1D8E1bjyq97cJxeZvTb62hDB93SOp2cFHQPV0dal74 18gdz1M3Xz4bZxLnHOk3ne+ExuKoBZOyOO0G7AE1zq1x4NpcXjKQJV2o9nnPuIGWRXCw Uh2aEFHt8TTQvczvE/5Wc+7YwpiC8AObpBVIHcx8YmX6Dzken8AUxYJ0U8hrN1XU/3lO +kIL+dEF2uTXe2Lgh4G4/wSKHFytqVMGROXUJD0rVVOp4OS4QuudKzAcPzxVsJMFgu/7 7BwA== 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=zt4uy8sPVoJl+6lAqJHyKxtG25XWFS27z1X2lfAr8NY=; b=J2gDnV4mzgK8L49dDtea458p8wpJLQONJzk26gGrRrxN/fJKDzxzW/Y+RZhF3PrKwj a6y6LnCbXcrEXIoFZtT+lgGlKLpcg5s1MXgiNuCzEGllY/f7JhZhp6A2udLVC0LIB6dF Q6cx8FsPJ27aHlmfCrFZZixlG6JC3xVtkW8ff2gSag8Pf5w+9NZ2lJkkEEbVKw0el/W8 t1IT13yYZS/7A5Yc3mXKnwfkiStjDlIZJlT0Q+XO8xeTdLQv+qSYV4GE6ue2pzIGVgn3 7FG1U4dy9Bl8H15MEfZJZKJ8XoXxzyxS+/D1jCxZQBPKuB85NVNUolcWKqrdyuvrvxP2 4OiQ== 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 i71si7884479pge.3.2019.07.22.03.33.45; Mon, 22 Jul 2019 03:33:46 -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 S1729634AbfGVKdo (ORCPT + 29 others); Mon, 22 Jul 2019 06:33:44 -0400 Received: from foss.arm.com ([217.140.110.172]:35420 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726120AbfGVKdm (ORCPT ); Mon, 22 Jul 2019 06:33:42 -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 3E68D1509; Mon, 22 Jul 2019 03:33:42 -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 C32B53F71A; Mon, 22 Jul 2019 03:33:40 -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 1/3] printk: Allow architecture-specific timestamping function Date: Mon, 22 Jul 2019 11:33:28 +0100 Message-Id: <20190722103330.255312-2-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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org printk currently relies on local_clock to time-stamp the kernel messages. In order to allow the timestamping (and only that) to be overridden by architecture-specific code, let's declare a new timestamp_clock() function, which gets used by the printk code. Architectures willing to make use of this facility will have to define CONFIG_ARCH_HAS_TIMESTAMP_CLOCK. The default is of course to return local_clock(), so that the existing behaviour stays unchanged. Signed-off-by: Marc Zyngier --- include/linux/sched/clock.h | 13 +++++++++++++ kernel/printk/printk.c | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) -- 2.20.1 diff --git a/include/linux/sched/clock.h b/include/linux/sched/clock.h index 867d588314e0..3cf4b2a8ce18 100644 --- a/include/linux/sched/clock.h +++ b/include/linux/sched/clock.h @@ -98,4 +98,17 @@ static inline void enable_sched_clock_irqtime(void) {} static inline void disable_sched_clock_irqtime(void) {} #endif +#ifdef CONFIG_ARCH_HAS_TIMESTAMP_CLOCK +/* Special need architectures can provide their timestamping function */ +extern u64 timestamp_clock(void); + +#else + +static inline u64 timestamp_clock(void) +{ + return local_clock(); +} + +#endif + #endif /* _LINUX_SCHED_CLOCK_H */ diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 1888f6a3b694..166702316714 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -638,7 +638,7 @@ static int log_store(u32 caller_id, int facility, int level, if (ts_nsec > 0) msg->ts_nsec = ts_nsec; else - msg->ts_nsec = local_clock(); + msg->ts_nsec = timestamp_clock(); #ifdef CONFIG_PRINTK_CALLER msg->caller_id = caller_id; #endif @@ -1841,7 +1841,7 @@ static bool cont_add(u32 caller_id, int facility, int level, cont.facility = facility; cont.level = level; cont.caller_id = caller_id; - cont.ts_nsec = local_clock(); + cont.ts_nsec = timestamp_clock(); cont.flags = flags; } From patchwork Mon Jul 22 10:33:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 169363 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp7351164ilk; Mon, 22 Jul 2019 03:33:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqxxWIlVw6Rk8JGMXu4HZ4H2GA3PHitr+eZlMIaVh8Of8x8rAi/rArcxcxbvNY9xH+83O2DG X-Received: by 2002:a63:460c:: with SMTP id t12mr70504108pga.69.1563791628491; Mon, 22 Jul 2019 03:33:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563791628; cv=none; d=google.com; s=arc-20160816; b=Td5DdPQvlzKR0N2kdMtHXa6K5jsf6LIKNSVYjMamyqHoHvzGqmQ6eKQCKDu+X63AmD 0NzmCGe66G51z9aHWD7fPX9/ikW3h3KOnhqgaWxrocmvaNV9wwn0+DRRYBrQXesGJ/jT dQstcP/hyj1BRLkbBlReLEnh6Ir7c79IWxRFHQAXkWEVPJErfY6HbH69grLbCfOASJFp WyE0h4hvWJlKgvs/eGCKLulMJaOKfXi3+Skv/ag9POSdWbS6PpcQZ5hKPbAEeEEbJiP1 L8XUlD+2fCoPUa6hHa2GN0X/3YHrLzmRB1aCffVE5oRZbo4AOi+EfYGvSaFbfj+GHmwq rIAw== 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=RaDbNuC4MBGvGcxqus51YpNE67ZY3nuUdVRjylRx8dM=; b=OEtIPIYBOdyLJKsfleuqirU5hxjFcs1v4F8uuBkv9IOXgNaaCgEE7g82sU2iNYMYD4 O4D1NC0UKKBvQG1AqXm6GkDPY9i7sfu/8MJhG8EGWseTLHavKnJCRJ0a5I0p5dJe5w3Y m3BanNz3NGDJCOjO+SlDjlqEN+YJdqHq6cNLN31Y9PgH1almynUiiEBsn4dPZKt1wU/H 6SUcrt6jXEwZrbFrska3kq6VRGcaV2rw2uKBa1i9TAIBfT1Tb+SvLXzrK/GDIV+VVyqB X2lY5eqv4Lu6PQUBG/TMf5OsE80dDTqJEk3MEecy1Qzu98rXbpK6ZFoFmrNrW9KZrjXH R3GA== 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 l15si8044557pjq.104.2019.07.22.03.33.48; Mon, 22 Jul 2019 03:33:48 -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 S1729684AbfGVKdr (ORCPT + 29 others); Mon, 22 Jul 2019 06:33:47 -0400 Received: from foss.arm.com ([217.140.110.172]:35440 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729575AbfGVKdo (ORCPT ); Mon, 22 Jul 2019 06:33:44 -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 E27DD1576; Mon, 22 Jul 2019 03:33:43 -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 7347E3F71A; Mon, 22 Jul 2019 03:33:42 -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 2/3] sched/clock: Allow sched_clock to inherit timestamp_clock epoch Date: Mon, 22 Jul 2019 11:33:29 +0100 Message-Id: <20190722103330.255312-3-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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now that we can let an architecture override the timestamping function, it becomes desirable to ensure that, should the architecture code switch its timestamping code to sched_clock once it has been registered, the sched_clock inherits the timestamp value as its new epoch. This ensures that the time stamps are continuous and that there is no jitter other than that introduced by the lack of quality of the timestamping clock. Signed-off-by: Marc Zyngier --- kernel/time/sched_clock.c | 10 ++++++++++ 1 file changed, 10 insertions(+) -- 2.20.1 diff --git a/kernel/time/sched_clock.c b/kernel/time/sched_clock.c index 142b07619918..ee1bd449ec81 100644 --- a/kernel/time/sched_clock.c +++ b/kernel/time/sched_clock.c @@ -192,6 +192,16 @@ sched_clock_register(u64 (*read)(void), int bits, unsigned long rate) new_epoch = read(); cyc = cd.actual_read_sched_clock(); ns = rd.epoch_ns + cyc_to_ns((cyc - rd.epoch_cyc) & rd.sched_clock_mask, rd.mult, rd.shift); + + /* + * If the architecture has a timestamp clock, and this is the + * first time we register a new sched_clock, use the timestamp + * clock as the epoch. + */ + if (IS_ENABLED(CONFIG_ARCH_HAS_TIMESTAMP_CLOCK) && + unlikely(cd.actual_read_sched_clock == jiffy_sched_clock_read)) + ns = timestamp_clock(); + cd.actual_read_sched_clock = read; rd.read_sched_clock = read; From patchwork Mon Jul 22 10:33:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 169364 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp7351234ilk; Mon, 22 Jul 2019 03:33:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqxyY1BKRqvj9PPO63B2Z3comm1EeqR6DWZmxAie6OWiuk4WAsHRgfYeqE2X0sB+fOWK1Ma2 X-Received: by 2002:a63:c442:: with SMTP id m2mr71923462pgg.286.1563791633204; Mon, 22 Jul 2019 03:33:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563791633; cv=none; d=google.com; s=arc-20160816; b=x2RLv0xIqdheVUS7HUWzBQy5yzVVioPzN+KrXXvsINoX0Xin9Ebt6pF6Z7TrNsK+uQ r6hcEHiyKeSBPCCxHyVIj3LfGSpo7DWsfSiiUvfo3nEZqYIoDKMGShLN8wMCJ7zqtx4h wCasgndcTeRbMnwfJT4n2UQNoQ4C82XWXGDijGuZjj5gjfEZo2ucR3eSA10fjt80zhvX JzfbAqRGPQc/+dI3DbClOZ9eEmiBz2prMGqqqObl91BZCyugfqUxx4DV77PNnYJkvrxq 4I8NcXGvZ2VsL4v/vSG5A5N25qqgIeBk5Ms8RYhu0TjaGVyzUhTZGYa/VP0iLCmoyGCy 9pkw== 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 l15si8044557pjq.104.2019.07.22.03.33.52; Mon, 22 Jul 2019 03:33:53 -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 S1729695AbfGVKdv (ORCPT + 29 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 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(+) -- 2.20.1 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;