From patchwork Mon May 14 08:55:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 135689 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1483712lji; Mon, 14 May 2018 01:56:22 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrSxfyyx10uqrtNMT5eBxzG8hgEMYITYl/dH/tXUF06ikhl67LWF1WP8SV3qn2ABC253Pp+ X-Received: by 2002:a17:902:4483:: with SMTP id l3-v6mr9073400pld.282.1526288182521; Mon, 14 May 2018 01:56:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526288182; cv=none; d=google.com; s=arc-20160816; b=ckFQWwONYs5zyGm3EXfYG5bj/+HcQMT1s7B3uwLPhUS1AL8gOEWNer6nEtEk8E0amy zvLA4MmH/x/0E0iyeCdpMBHdZ8mTMcV/zLWq3HW1A951TsaieLt472x8aF+JtvRNis0J FqHpi+gczuGKFz8U54TPo6BbymWSFDZLe9tt4z/TPDB4N+oHgLUAMoM0ne1s+r49+svE THN2RvxBaKu1lEtopwe1U4x2jL4x6CiVDHEisz+//TAlpDu4agF5nde0ExOAFsi6wRYe oihqHj1xcbetBQp7gmzc3PHLMPXeJli5+O4u/B3/qXJH50/mnDa/NFSFYAZ6HJ9q/neZ euog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=HSeeHyNJ7QNAWZBUB1p2ib+cxOTqsBDGE2rkHjUOTeg=; b=Kh+y+XRrRQbAFZOCQF2EBop2+6fN8nqLXske92zOOWEtVDv6kqiKyvaUpRaZxrII6+ YhlZwalGAz09X1KAtH/tMwSTS3dJDNNMibH2f8P290ifx5p0kzikCRLpe3nITHeum3GE 9+UzPoUJfgsQhsRCy+CU+2CQHstb7Pn+YMziNYl4YIg6yP0L1sTEqpu0FGXvsVlbI3nC pZOopTPrfahuWGw/L/I+7SFeLiXXFOY29d52IGPvrqXWff7w4GP5PF+mZK5h4R3ZOeNP RORjlxnzCXr8mLK7ImlSq5ZoyTh/2eMMDmm/OPokTKWlYIaxKuvQRGnMwG+DhGGeAgmL jyeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XW/Zg3jx; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y8-v6si7193305pgp.527.2018.05.14.01.56.22; Mon, 14 May 2018 01:56:22 -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; dkim=pass header.i=@linaro.org header.s=google header.b=XW/Zg3jx; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752098AbeENI4U (ORCPT + 29 others); Mon, 14 May 2018 04:56:20 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:40724 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752064AbeENI4R (ORCPT ); Mon, 14 May 2018 04:56:17 -0400 Received: by mail-pf0-f193.google.com with SMTP id f189-v6so5690893pfa.7 for ; Mon, 14 May 2018 01:56:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=HSeeHyNJ7QNAWZBUB1p2ib+cxOTqsBDGE2rkHjUOTeg=; b=XW/Zg3jxjkhGcR7IQq5f+C2p/CBSTrGW1bggi/yXFO/FqwHx1w5z//sxc9/zwUw7Eb CdlTT6cWQuWTSiWsSTIo8y17VRW7A2AK4NntvP9yyxAw4M4unAAVlSyMSEk7R0HMI05d q8ej0n86vlJ38r98uB+Zerj6TO3PQ9el06mm0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=HSeeHyNJ7QNAWZBUB1p2ib+cxOTqsBDGE2rkHjUOTeg=; b=JHWGl9II7/Mog+d1aHGAlfKJkteVm1mCYIWEHqsA2yHeSo3x6J9rzN1xe2csBzogsI dsBxMq6f8lM21qhMEczyGZlR7YiKwTN06yKV8zs5KHLMjC4Z1WX9KVHYMR2I5tdi+CCr IlXMba4nI+K5IdPoR8uikYF+Ax4RsITidZJGzETfyCnxN3Op3rT85+LlnF43fQH5+WUJ G+XxsckgaoYHa3uAo+lRxoaJAl6X7MuRT6dexM0uiwVSBvQSFh63YMUBzzG9FSvellj0 Exd2V42iiJhoiquRs1eZ0vJOTqBERlKilGAcfYXXSYB6nwWDWI2pVpC03Fgxo1wSfp89 5kOw== X-Gm-Message-State: ALKqPwcoJTGc42b5rZf5RGxicCLrfvIsAGTCj0v2y6QzipjDHlQEO428 pdcsE34T9P61W6+vi39hi5Qxng== X-Received: by 2002:a62:3c10:: with SMTP id j16-v6mr9561168pfa.7.1526288176163; Mon, 14 May 2018 01:56:16 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id x71-v6sm23308158pfe.47.2018.05.14.01.56.07 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 14 May 2018 01:56:15 -0700 (PDT) From: Baolin Wang To: tglx@linutronix.de, john.stultz@linaro.org, daniel.lezcano@linaro.org, arnd@arndb.de, tony@atomide.com, aaro.koskinen@iki.fi, linux@armlinux.org.uk, mark.rutland@arm.com, marc.zyngier@arm.com Cc: baolin.wang@linaro.org, broonie@kernel.org, paulmck@linux.vnet.ibm.com, mlichvar@redhat.com, rdunlap@infradead.org, kstewart@linuxfoundation.org, gregkh@linuxfoundation.org, pombredanne@nexb.com, thierry.reding@gmail.com, jonathanh@nvidia.com, heiko@sntech.de, linus.walleij@linaro.org, viresh.kumar@linaro.org, mingo@kernel.org, hpa@zytor.com, peterz@infradead.org, douly.fnst@cn.fujitsu.com, len.brown@intel.com, rajvi.jingar@intel.com, alexandre.belloni@bootlin.com, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org Subject: [RFC PATCH 01/10] time: Add persistent clock support Date: Mon, 14 May 2018 16:55:27 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On our Spreadtrum SC9860 platform, we registered the high resolution ARM generic timer as one clocksource to update the OS time, but the ARM generic timer will be stopped in suspend state. So we use one 64bit always-on timer (but low resolution) of Spreadtrum to calculate the suspend time to compensate the OS time. Though we can register the always-on timer as one clocksource, we need re-calculate the mult/shift with one larger conversion range to calculate the suspend time. But now we have too many different ways of dealing with persistent timekeeping across architectures, and there will be many duplicate code if we register one timer to be one persistent clock. Thus it will be more helpful if we add one common framework for timer drivers to be registered as one persistent clock and implement the common read_persistent_clock64() to compensate the OS time. Moreover we can register the clocksource with CLOCK_SOURCE_SUSPEND_NONSTOP to be one persistent clock, then we can simplify the suspend/resume accounting by removing CLOCK_SOURCE_SUSPEND_NONSTOP timing. After that we can only compensate the OS time by persistent clock or RTC. Signed-off-by: Baolin Wang --- include/linux/persistent_clock.h | 21 +++++ kernel/time/Kconfig | 4 + kernel/time/Makefile | 1 + kernel/time/persistent_clock.c | 180 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 206 insertions(+) create mode 100644 include/linux/persistent_clock.h create mode 100644 kernel/time/persistent_clock.c -- 1.7.9.5 diff --git a/include/linux/persistent_clock.h b/include/linux/persistent_clock.h new file mode 100644 index 0000000..4917980 --- /dev/null +++ b/include/linux/persistent_clock.h @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0 +#ifndef __PERSISTENT_CLOCK_H__ +#define __PERSISTENT_CLOCK_H__ + +#ifdef CONFIG_PERSISTENT_CLOCK +extern int __init persistent_clock_init_and_register(u64 (*read)(void), + u64 mask, u32 freq, + u64 maxsec); +extern void __init persistent_clock_cleanup(void); +#else +static inline int persistent_clock_init_and_register(u64 (*read)(void), + u64 mask, u32 freq, + u64 maxsec) +{ + return 0; +} + +static inline void persistent_clock_cleanup(void) { } +#endif + +#endif diff --git a/kernel/time/Kconfig b/kernel/time/Kconfig index 78eabc4..7188600 100644 --- a/kernel/time/Kconfig +++ b/kernel/time/Kconfig @@ -47,6 +47,10 @@ config GENERIC_CLOCKEVENTS_MIN_ADJUST config GENERIC_CMOS_UPDATE bool +# Persistent clock support +config PERSISTENT_CLOCK + bool + if GENERIC_CLOCKEVENTS menu "Timers subsystem" diff --git a/kernel/time/Makefile b/kernel/time/Makefile index f1e46f3..f6d368f 100644 --- a/kernel/time/Makefile +++ b/kernel/time/Makefile @@ -18,3 +18,4 @@ obj-$(CONFIG_GENERIC_SCHED_CLOCK) += sched_clock.o obj-$(CONFIG_TICK_ONESHOT) += tick-oneshot.o tick-sched.o obj-$(CONFIG_DEBUG_FS) += timekeeping_debug.o obj-$(CONFIG_TEST_UDELAY) += test_udelay.o +obj-$(CONFIG_PERSISTENT_CLOCK) += persistent_clock.o diff --git a/kernel/time/persistent_clock.c b/kernel/time/persistent_clock.c new file mode 100644 index 0000000..1410cb3 --- /dev/null +++ b/kernel/time/persistent_clock.c @@ -0,0 +1,180 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2018 Linaro, Inc. + * + * Author: Baolin Wang + */ + +#include +#include +#include + +/** + * persistent_clock_read_data - data required to read persistent clock + * @read: Returns a cycle value from persistent clock. + * @last_cycles: Clock cycle value at last update. + * @last_ns: Time value (nanoseconds) at last update. + * @mask: Bitmask for two's complement subtraction of non 64bit clocks. + * @mult: Cycle to nanosecond multiplier. + * @shift: Cycle to nanosecond divisor. + */ +struct persistent_clock_read_data { + u64 (*read)(void); + u64 last_cycles; + u64 last_ns; + u64 mask; + u32 mult; + u32 shift; +}; + +/** + * persistent_clock - represent the persistent clock + * @read_data: Data required to read from persistent clock. + * @seq: Sequence counter for protecting updates. + * @freq: The frequency of the persistent clock. + * @wrap: Duration for persistent clock can run before wrapping. + * @alarm: Update timeout for persistent clock wrap. + */ +struct persistent_clock { + struct persistent_clock_read_data read_data; + seqcount_t seq; + u32 freq; + ktime_t wrap; + struct alarm alarm; +}; + +static struct persistent_clock p; + +void read_persistent_clock64(struct timespec64 *ts) +{ + struct persistent_clock_read_data *read_data = &p.read_data; + unsigned long seq; + u64 delta, nsecs; + + if (!read_data->read) { + ts->tv_sec = 0; + ts->tv_nsec = 0; + return; + } + + do { + seq = read_seqcount_begin(&p.seq); + delta = (read_data->read() - read_data->last_cycles) & + read_data->mask; + + nsecs = read_data->last_ns + + clocksource_cyc2ns(delta, read_data->mult, + read_data->shift); + *ts = ns_to_timespec64(nsecs); + } while (read_seqcount_retry(&p.seq, seq)); +} + +static void persistent_clock_update(void) +{ + struct persistent_clock_read_data *read_data = &p.read_data; + u64 cycles, delta; + + write_seqcount_begin(&p.seq); + + cycles = read_data->read(); + delta = (cycles - read_data->last_cycles) & read_data->mask; + read_data->last_ns += clocksource_cyc2ns(delta, read_data->mult, + read_data->shift); + read_data->last_cycles = cycles; + + write_seqcount_end(&p.seq); +} + +static enum alarmtimer_restart persistent_clock_alarm_fired(struct alarm *alarm, + ktime_t now) +{ + persistent_clock_update(); + + alarm_forward(&p.alarm, now, p.wrap); + return ALARMTIMER_RESTART; +} + +int __init persistent_clock_init_and_register(u64 (*read)(void), u64 mask, + u32 freq, u64 maxsec) +{ + struct persistent_clock_read_data *read_data = &p.read_data; + u64 wrap, res, secs = maxsec; + + if (!read || !mask || !freq) + return -EINVAL; + + if (!secs) { + /* + * If the timer driver did not specify the maximum conversion + * seconds of the persistent clock, then we calculate the + * conversion range with the persistent clock's bits and + * frequency. + */ + secs = mask; + do_div(secs, freq); + + /* + * Some persistent counter can be larger than 32bit, so we + * need limit the max suspend time to have a good conversion + * precision. So 24 hours may be enough usually. + */ + if (secs > 86400) + secs = 86400; + } + + /* Calculate the mult/shift to convert cycles to ns. */ + clocks_calc_mult_shift(&read_data->mult, &read_data->shift, freq, + NSEC_PER_SEC, (u32)secs); + + /* Calculate how many nanoseconds until we risk wrapping. */ + wrap = clocks_calc_max_nsecs(read_data->mult, read_data->shift, 0, + mask, NULL); + p.wrap = ns_to_ktime(wrap); + + p.freq = freq; + read_data->mask = mask; + read_data->read = read; + + persistent_clock_update(); + + /* Calculate the ns resolution of this persistent clock. */ + res = clocksource_cyc2ns(1ULL, read_data->mult, read_data->shift); + + pr_info("persistent clock: mask %llu at %uHz, resolution %lluns, wraps every %lluns\n", + mask, freq, res, wrap); + return 0; +} + +void __init persistent_clock_cleanup(void) +{ + p.read_data.read = NULL; + alarm_cancel(&p.alarm); +} + +static int __init persistent_clock_start_alarmtimer(void) +{ + struct persistent_clock_read_data *read_data = &p.read_data; + ktime_t now; + + /* + * If no persistent clock function has been provided at that point, + * just return. + */ + if (!read_data->read) + return 0; + + persistent_clock_update(); + + /* + * Since the persistent clock will not be stopped when system enters the + * suspend state, thus we need start one alarmtimer to wakeup the system + * to update the persistent clock before wrapping. We should start the + * update alarmtimer after the alarmtimer subsystem was initialized. + */ + alarm_init(&p.alarm, ALARM_BOOTTIME, persistent_clock_alarm_fired); + now = ktime_get_boottime(); + alarm_start(&p.alarm, ktime_add(now, p.wrap)); + + return 0; +} +late_initcall(persistent_clock_start_alarmtimer); From patchwork Mon May 14 08:55:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 135690 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1483831lji; Mon, 14 May 2018 01:56:32 -0700 (PDT) X-Google-Smtp-Source: AB8JxZolhx7HpkzxwfKcyjUOq2ZGNbe+8gbLNJa475ygNWzT7ffWUDr8d8WMCaPna3a7KqXi4Wj7 X-Received: by 2002:a17:902:8d85:: with SMTP id v5-v6mr8988263plo.93.1526288192765; Mon, 14 May 2018 01:56:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526288192; cv=none; d=google.com; s=arc-20160816; b=nQ2Q1QWYwYNpiftFwj/HwNrKr5O3EVbw3kQedACDVdPg8w/Gw/xXgXcNw7r+RADvtt x5/BLAR01tVTfMIXXhhpUhpK/azdqh40cGzaEH/uILx98YMp6btc4b79RQQ4lBch3gu8 16tZ/uoihcrPVoPyuT9ByE9sactIrNkFhrKNHpiE3uEzEfBhUGr9jqh3FX3l0TlFuzxc H/zJog/FJpWJs7T/c/HPok0LuGtN2HgrSrp41tazZjO7wBn/9JzRre5LOATFNaB31N6A c6ZO32Sr8cEtQ08vqK3slr3/hSbbydy44T8stxsv4gPEyG+pVJWwKt1RCgC8VvPVVAyp tCFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=otXnHrArHRqD0yr3/v6hok4GHpBR10tlTjRkrESI19A=; b=lsRXLpcif80hwgqc+KUVyTBXrVWdg2bSSIjN1337itTaNUlA839SjIhY3NRWGu2DOr W4ZU0YpakzQ1MKWJN9UPD5uPhbm0ejsSEAed7VUmuhxabQLenDqGLVwivGRB1RJ+P0po NAa4bU2BfiB/4zk7R5KCYuvJex2DBlRghux91D/5KVFLEsOIrgwBWncq/QTG14V5q6SC Dy2ATU0bLcfxrHklgnOszQQqKID5nL7jjkPbQudzjNTrqxzxdduKmu+cGiW6t6FRgX+r WmnVoJxFg1zL5aZNqRzA9Cgp84lq08v79FNfHc29Zl5Jn3zRhLrj8rHZlpjzYKgdB6ly o0LQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=a56a65JF; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f59-v6si9464172plf.38.2018.05.14.01.56.32; Mon, 14 May 2018 01:56:32 -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; dkim=pass header.i=@linaro.org header.s=google header.b=a56a65JF; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752160AbeENI4a (ORCPT + 29 others); Mon, 14 May 2018 04:56:30 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:35385 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752106AbeENI4Z (ORCPT ); Mon, 14 May 2018 04:56:25 -0400 Received: by mail-pl0-f67.google.com with SMTP id i5-v6so6977177plt.2 for ; Mon, 14 May 2018 01:56:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=otXnHrArHRqD0yr3/v6hok4GHpBR10tlTjRkrESI19A=; b=a56a65JFxTN+ZV/zb7eYejlrJBN0IjaOGdyKIw6+4+mU0XuncntLzhuZ6SyFBzXoWn AXfkZgaSfAScv5um7ZT/1MO7vj1TXUzqDc/jrz2VQ85hp3i83/SZwWXjBUb/ASbc+ohZ rFd/NJYynpGSTaYC+m6kRaCvHEc75Esrw6Mxo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=otXnHrArHRqD0yr3/v6hok4GHpBR10tlTjRkrESI19A=; b=WZbsJtLMLeaUld+UijmkvUoklYpiiAlUSzvtqs6vsYR3O8JnOK0in2R9i39HN+zEp0 6v+FzsybDBtVzGF9vJA8xtbYXlDkWczR7FBrGSqJ6pU73NPPjitBy/X11eBvX9arD6LG 03WG/iQqf61CAuew3VtKHheVvrPwS0wfjZN2pBjT3/NMMROyPFZcZ29JEC0DEviRu+Vk DvIwq2JCCODZUwsACToMilqvCONurCpglY4UjaVxlz466L5vTd9nKDrefeinLkHmt2uH MqSUIKLzgGZCBYHZk1TZZmsPrN7J0pU+vqlznDRktN7QX/TgtcwYPIY/9ltn41v++wNt NBdA== X-Gm-Message-State: ALKqPwf6PGK4G6wiEwyNH9aSV4d+dIjN4aY9/+cSKC1oIk33a4NUHtPo KngsYHWTvmKLMJZdvZ8lKnX5Cg== X-Received: by 2002:a17:902:229:: with SMTP id 38-v6mr9002519plc.384.1526288184895; Mon, 14 May 2018 01:56:24 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id x71-v6sm23308158pfe.47.2018.05.14.01.56.16 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 14 May 2018 01:56:24 -0700 (PDT) From: Baolin Wang To: tglx@linutronix.de, john.stultz@linaro.org, daniel.lezcano@linaro.org, arnd@arndb.de, tony@atomide.com, aaro.koskinen@iki.fi, linux@armlinux.org.uk, mark.rutland@arm.com, marc.zyngier@arm.com Cc: baolin.wang@linaro.org, broonie@kernel.org, paulmck@linux.vnet.ibm.com, mlichvar@redhat.com, rdunlap@infradead.org, kstewart@linuxfoundation.org, gregkh@linuxfoundation.org, pombredanne@nexb.com, thierry.reding@gmail.com, jonathanh@nvidia.com, heiko@sntech.de, linus.walleij@linaro.org, viresh.kumar@linaro.org, mingo@kernel.org, hpa@zytor.com, peterz@infradead.org, douly.fnst@cn.fujitsu.com, len.brown@intel.com, rajvi.jingar@intel.com, alexandre.belloni@bootlin.com, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org Subject: [RFC PATCH 02/10] clocksource: sprd: Add one persistent timer for Spreadtrum platform Date: Mon, 14 May 2018 16:55:28 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Spreadtrum SC9860 platform, we need one persistent timer to calculate the suspend time to compensate the OS time. This patch registers one Spreadtrum AON timer as persistent timer, which runs at 32bit and periodic mode. Signed-off-by: Baolin Wang --- drivers/clocksource/Kconfig | 1 + drivers/clocksource/timer-sprd.c | 80 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) -- 1.7.9.5 diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig index 8e8a097..d7dddcc 100644 --- a/drivers/clocksource/Kconfig +++ b/drivers/clocksource/Kconfig @@ -453,6 +453,7 @@ config SPRD_TIMER bool "Spreadtrum timer driver" if COMPILE_TEST depends on HAS_IOMEM select TIMER_OF + select PERSISTENT_CLOCK help Enables support for the Spreadtrum timer driver. diff --git a/drivers/clocksource/timer-sprd.c b/drivers/clocksource/timer-sprd.c index ef9ebea..c6f657a 100644 --- a/drivers/clocksource/timer-sprd.c +++ b/drivers/clocksource/timer-sprd.c @@ -3,8 +3,11 @@ * Copyright (C) 2017 Spreadtrum Communications Inc. */ +#include #include #include +#include +#include #include "timer-of.h" @@ -157,3 +160,80 @@ static int __init sprd_timer_init(struct device_node *np) } TIMER_OF_DECLARE(sc9860_timer, "sprd,sc9860-timer", sprd_timer_init); + +void __iomem *pbase; + +static u64 sprd_persistent_timer_read(void) +{ + return ~(u64)readl_relaxed(pbase + TIMER_VALUE_SHDW_LO) & + CLOCKSOURCE_MASK(32); +} + +static void sprd_persistent_timer_disable(void) +{ + sprd_timer_disable(pbase); +} + +static void sprd_persistent_timer_enable(void) +{ + sprd_timer_disable(pbase); + sprd_timer_update_counter(pbase, TIMER_VALUE_LO_MASK); + sprd_timer_enable(pbase, TIMER_CTL_PERIOD_MODE); +} + +static int __init sprd_persistent_timer_init(struct device_node *np) +{ + struct clk *clk; + u32 freq; + int ret; + + clk = of_clk_get(np, 0); + if (IS_ERR(clk)) { + pr_err("Can't get timer clock for %pOF\n", np); + return PTR_ERR(clk); + } + + ret = clk_prepare_enable(clk); + if (ret) { + pr_err("Failed to enable clock for %pOF\n", np); + clk_put(clk); + return ret; + } + + freq = clk_get_rate(clk); + if (!freq) { + pr_err("Failed to get clock rate for %pOF\n", np); + ret = -EINVAL; + goto clk_rate_err; + } + + pbase = of_io_request_and_map(np, 0, of_node_full_name(np)); + if (IS_ERR(pbase)) { + pr_err("Can't map timer registers for %pOF\n", np); + ret = PTR_ERR(pbase); + goto clk_rate_err; + } + + sprd_persistent_timer_enable(); + + ret = persistent_clock_init_and_register(sprd_persistent_timer_read, + CLOCKSOURCE_MASK(32), freq, 0); + if (ret) { + pr_err("Failed to register persistent clock for %pOF\n", np); + goto persist_err; + } + + return 0; + +persist_err: + sprd_persistent_timer_disable(); + iounmap(pbase); +clk_rate_err: + clk_disable_unprepare(clk); + clk_put(clk); + + return ret; +} + +TIMER_OF_DECLARE(sc9860_persistent_timer, "sprd,sc9860-persistent-timer", + sprd_persistent_timer_init); From patchwork Mon May 14 08:55:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 135692 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1484004lji; Mon, 14 May 2018 01:56:47 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqBm9idTBYsioBw11oB+TcMY229QNXZJR53MmLWSbGDoamEv7ywXVNnuGquWXchm+qLmumO X-Received: by 2002:a62:c898:: with SMTP id i24-v6mr9627558pfk.35.1526288206955; Mon, 14 May 2018 01:56:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526288206; cv=none; d=google.com; s=arc-20160816; b=TdPWEgfYJNSFzENIo5EM04aeLWcFU4sa36tMODWz0OM09/rJWKp334pATUjmo9HZN0 B46iB5ZsWXknP8mtVdRNb29jQz//BT5lDKF4DYqVVC2NijO4IVnN8KGKBB9bJraOD+Kx 5Cjy1FPDtci+E9MNLzReoetZMwFkFGkmYUC8jo/SUaXoMSsNxqg2L3y8mc5EdkDjI+V1 imYj6Grj99+X0A4JD9OoAtXG59tSp1Kq56SpZHoYZfWwfJTt3hhGvsAtQ6arm44YDdY1 kXx8ciHGNp9BEHD5orF6mybzlzezOQsI0V0+i5qZRFOGQOpcA94SWD+UVvfj7EqIy2ZC s23w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=sa47kacdk4A6CY2LuxKzGslqtwVkcT70aRUQGxEH/o8=; b=swwd3GSzTV5+X8MR9zsjIxUffdQCLHKr0KcBrJv6W2RJobRDfYu5uz1ABiLkl/+X01 ief/DQT1APpwR7hO5ZJ5AWa9u+ePt1Omlj8f518LayyrbgHh2GzYW7YxgHjW72x7+gBc ezGx5+lnr7br7d0JAypid6VVkoMwtTrXTwOEgCPs2L26K6n4+284rKt1JcYoqIBpjRtX WexuNOuPFXE9/WO47TGrq1XNl6HksOP9hvJF2pYOblHeGKKWl1usLG81fQKXjAyOE+sW eAHejSkkCsOkVuKXD+sko5i5wx1Zkq9g2U0U+NDKkwkyU9B4jXIng5mP9o73FMXn8z+a 27yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Z58Go2DS; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l1-v6si4877403pgf.221.2018.05.14.01.56.46; Mon, 14 May 2018 01:56: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; dkim=pass header.i=@linaro.org header.s=google header.b=Z58Go2DS; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752241AbeENI4p (ORCPT + 29 others); Mon, 14 May 2018 04:56:45 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:39051 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752200AbeENI4n (ORCPT ); Mon, 14 May 2018 04:56:43 -0400 Received: by mail-pf0-f196.google.com with SMTP id a22-v6so5687014pfn.6 for ; Mon, 14 May 2018 01:56:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=sa47kacdk4A6CY2LuxKzGslqtwVkcT70aRUQGxEH/o8=; b=Z58Go2DSuMV96CW4zmQ+J7qs2jhHIMhS61FY2sQFtPVacrQSxtQ0JfDFJesMggVD/5 iJ9qEVCs+eFagH3FYHf4l0fYQKGeGOV+va2A4O0zyDLF6VEu3YHP3/kbkkxGXyUPHsbB MFIEMKk7kgoLWsX/FljjN2g2EpZOJ5Uw9jJwc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=sa47kacdk4A6CY2LuxKzGslqtwVkcT70aRUQGxEH/o8=; b=pvscT28TxGpjDHGAT3Cmf1Z8r56OXNOVpGu9JVt5RiWI+xiC+TztSPfGhJjCknxVvj 7AATo51J+dSS5qf2isCnNFVzXcQwX6sIS3w3Ag4nsmJoaLeVGfuC7CveHIPQd/evocp5 D1tH8ZAy4BNzmDzgUIfjnXFdM9Xp4QbRabeZa4t9V/G3S+ca37AbQdMX3PB66MNtOePI imxOgXIE1U6B8q3FoDPJbCz3pWBRW/PJzR0qaygMsGwjZFXtFjfKn9dAvmlHDf+CTNLQ rWe0NGn8CPN8yqHH/afhQnRxZ6zLlXOYYgXAKvImDU5ppBtGiFnFWv198rF8VgD0BqqC 2kcg== X-Gm-Message-State: ALKqPwcr5sJdpMnGIcGsR4o9ZjZwawp9MHGpIrPNvO9S6JXkTo3715mw xu5Sb9In4s4dLaUBs/nIO7TVsA== X-Received: by 2002:a62:4387:: with SMTP id l7-v6mr9451965pfi.55.1526288202592; Mon, 14 May 2018 01:56:42 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id x71-v6sm23308158pfe.47.2018.05.14.01.56.33 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 14 May 2018 01:56:42 -0700 (PDT) From: Baolin Wang To: tglx@linutronix.de, john.stultz@linaro.org, daniel.lezcano@linaro.org, arnd@arndb.de, tony@atomide.com, aaro.koskinen@iki.fi, linux@armlinux.org.uk, mark.rutland@arm.com, marc.zyngier@arm.com Cc: baolin.wang@linaro.org, broonie@kernel.org, paulmck@linux.vnet.ibm.com, mlichvar@redhat.com, rdunlap@infradead.org, kstewart@linuxfoundation.org, gregkh@linuxfoundation.org, pombredanne@nexb.com, thierry.reding@gmail.com, jonathanh@nvidia.com, heiko@sntech.de, linus.walleij@linaro.org, viresh.kumar@linaro.org, mingo@kernel.org, hpa@zytor.com, peterz@infradead.org, douly.fnst@cn.fujitsu.com, len.brown@intel.com, rajvi.jingar@intel.com, alexandre.belloni@bootlin.com, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org Subject: [RFC PATCH 04/10] clocksource: tegra20_timer: Remove register_persistent_clock() API Date: Mon, 14 May 2018 16:55:30 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We will convert all drivers to use persistent clock framework to compensate the suspend time for OS time, instead of using the register_persistent_clock() API in ARM architecture. So this patch removes the register_persistent_clock() and implement its function to read persistent clock. Signed-off-by: Baolin Wang --- drivers/clocksource/tegra20_timer.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) -- 1.7.9.5 diff --git a/drivers/clocksource/tegra20_timer.c b/drivers/clocksource/tegra20_timer.c index c337a81..97a34cb 100644 --- a/drivers/clocksource/tegra20_timer.c +++ b/drivers/clocksource/tegra20_timer.c @@ -124,7 +124,7 @@ static u64 tegra_rtc_read_ms(void) } /* - * tegra_read_persistent_clock64 - Return time from a persistent clock. + * read_persistent_clock64 - Return time from a persistent clock. * * Reads the time from a source which isn't disabled during PM, the * 32k sync timer. Convert the cycles elapsed since last read into @@ -133,10 +133,16 @@ static u64 tegra_rtc_read_ms(void) * tegra_rtc driver could be executing to avoid race conditions * on the RTC shadow register */ -static void tegra_read_persistent_clock64(struct timespec64 *ts) +void read_persistent_clock64(struct timespec64 *ts) { u64 delta; + if (!rtc_base) { + ts->tv_sec = 0; + ts->tv_nsec = 0; + return; + } + last_persistent_ms = persistent_ms; persistent_ms = tegra_rtc_read_ms(); delta = persistent_ms - last_persistent_ms; @@ -259,6 +265,6 @@ static int __init tegra20_init_rtc(struct device_node *np) else clk_prepare_enable(clk); - return register_persistent_clock(NULL, tegra_read_persistent_clock64); + return 0; } TIMER_OF_DECLARE(tegra20_rtc, "nvidia,tegra20-rtc", tegra20_init_rtc); From patchwork Mon May 14 08:55:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 135693 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1484098lji; Mon, 14 May 2018 01:56:57 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpuWLWuyt2UjZbxPO96SLpw1pL1LmAIUDfMm/w4uXHdj6Ibs1kQrHfw1GzSIheRWe4doafO X-Received: by 2002:a17:902:2c83:: with SMTP id n3-v6mr8823305plb.211.1526288217077; Mon, 14 May 2018 01:56:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526288217; cv=none; d=google.com; s=arc-20160816; b=MBJr1JKvtOP9IUg7TLhTZwIRzvuE8+wpbcU42KDsQPtU06TEp7UkIrai1rpjw5BEyA O+6/JkTVxl/Keza1XjHj9asAaRYwTSY7JwFbWLJuKQknJlEUI8J4ElK3sfxUtAMJORIX gy3dK5ms2lmkAqnuGUDKxDeaJAf+QG4pbNtJzX23pxYAjjrkj6bNl2E9ef4de722Uxxm t3KJqwd+ix0fTkPYB2iG3M1lvHXky99JJsSuqp/u7RnOP8boB0yyDg+xHg0E6++egiCk ewrY7AZLs7TzEIse+H5NI4WgaubGSwbH9GbUVNUiPu/rnWsNR3LK6+MT2lCpp6oMhBD9 H/HA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=Eel7Cy1vzjSfGnvDW7hlCZjLq+FDPDHooRhbIXHnQjA=; b=zNP00WkZwenkW8YLugVluAzECw4iEug0zB6bc7LPvqKOyHUoYTY6/A55+Fyk5CuroU Z6D0bf4I1uAhIR2pIv1p61SnjkeCxkVhTeVUVGWmKuBtebB6rHZ7cisRRu9TYekZbc95 Tr63KzMenCYfbOPmHkD07qJrEX4VKOM/HddePJ8oHWzjYwi3uAl8K/cKwFMeVNbOOW9h fS+EcgyqyPAPIxyrSRaRZbjdcd8X1o7QdDm0B3tKV7e/Z0SNPGAg1PeKQQpFU8Yul11G n78ohpHOpeLTV9J7Sr6BUO4a2ur9BUODz0ESUi+hkLQNGJxhMnZGfSIm53XSCFKHR7Fi vTDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=T1bQBNI3; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 3-v6si5083231plh.34.2018.05.14.01.56.56; Mon, 14 May 2018 01:56:57 -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; dkim=pass header.i=@linaro.org header.s=google header.b=T1bQBNI3; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752286AbeENI4y (ORCPT + 29 others); Mon, 14 May 2018 04:56:54 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:34168 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752250AbeENI4w (ORCPT ); Mon, 14 May 2018 04:56:52 -0400 Received: by mail-pf0-f195.google.com with SMTP id a14-v6so5693921pfi.1 for ; Mon, 14 May 2018 01:56:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=Eel7Cy1vzjSfGnvDW7hlCZjLq+FDPDHooRhbIXHnQjA=; b=T1bQBNI3qh7v/08aIXQZItbjVSsI4O/VAnj/GGeXw5A8C0iWI15KOjDIcmN1EkUPCy U6Z02C3QxtMZAAedhY8YQYPaPTrffMqPV6mhiwncXgZfLcsdY3gaVPOf3UX+B5wGzi6j 328r6o0s3pXMjhPYXOGpUP6kfUZ5s6nm47MEY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=Eel7Cy1vzjSfGnvDW7hlCZjLq+FDPDHooRhbIXHnQjA=; b=qoHbfkW5DVcB0MepKEbVRHKjwoXkZl51NgPCi5c4JB9U5asj1gi0PhwZEe+252WscC 9xC+Rb48ofuUqfwVnTch+a/PiZGgjPBunCzI4Tjg6RQMsDzw1wPAjeZKo8/fD/seaamJ Cle4RCEu0c8iqF7an1NOUNPX4dFmMtJPt1rUw9k89HzEhT0hntWGcNiSm5MuPnKpxmpl 313LUZ+e/FKmnSiEo0Zijr6t8ki3PyZmV3yfkBbYBUxoI0zcN12Zy+WLm4UI0NXJmMfS qfF+3JKv/K3oLgh0ZYO8InX0m609MDfju0Gz7NvJBDvaTOP1SMQkT+PnZO7eF1a1NKYE qokA== X-Gm-Message-State: ALKqPwe7dx5nP3r2fmqxU+0/PydAf71oO0s2t08PfB8jOF0OT2Bs38Yc P3/9Ru4drT145k43tj/ngRcOqw== X-Received: by 2002:a62:ac14:: with SMTP id v20-v6mr9654715pfe.101.1526288211529; Mon, 14 May 2018 01:56:51 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id x71-v6sm23308158pfe.47.2018.05.14.01.56.42 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 14 May 2018 01:56:51 -0700 (PDT) From: Baolin Wang To: tglx@linutronix.de, john.stultz@linaro.org, daniel.lezcano@linaro.org, arnd@arndb.de, tony@atomide.com, aaro.koskinen@iki.fi, linux@armlinux.org.uk, mark.rutland@arm.com, marc.zyngier@arm.com Cc: baolin.wang@linaro.org, broonie@kernel.org, paulmck@linux.vnet.ibm.com, mlichvar@redhat.com, rdunlap@infradead.org, kstewart@linuxfoundation.org, gregkh@linuxfoundation.org, pombredanne@nexb.com, thierry.reding@gmail.com, jonathanh@nvidia.com, heiko@sntech.de, linus.walleij@linaro.org, viresh.kumar@linaro.org, mingo@kernel.org, hpa@zytor.com, peterz@infradead.org, douly.fnst@cn.fujitsu.com, len.brown@intel.com, rajvi.jingar@intel.com, alexandre.belloni@bootlin.com, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org Subject: [RFC PATCH 05/10] arm: time: Remove the persistent clock support for ARM Date: Mon, 14 May 2018 16:55:31 +0800 Message-Id: <8d74ba31d4d2b14f21bea7a9cbc4f029bc59f60f.1526285602.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We have converted all drivers to use common persistent clock framework to compensate the suspend time, so we can remove the persistent clock, which only supports the ARM architecture. Moreover there are no drivers will register read_boot_clock64(), so remove it too. Signed-off-by: Baolin Wang --- arch/arm/include/asm/mach/time.h | 4 ---- arch/arm/kernel/time.c | 36 ------------------------------------ 2 files changed, 40 deletions(-) -- 1.7.9.5 diff --git a/arch/arm/include/asm/mach/time.h b/arch/arm/include/asm/mach/time.h index 0f79e4d..3cbcafc 100644 --- a/arch/arm/include/asm/mach/time.h +++ b/arch/arm/include/asm/mach/time.h @@ -12,8 +12,4 @@ extern void timer_tick(void); -typedef void (*clock_access_fn)(struct timespec64 *); -extern int register_persistent_clock(clock_access_fn read_boot, - clock_access_fn read_persistent); - #endif diff --git a/arch/arm/kernel/time.c b/arch/arm/kernel/time.c index cf2701c..713905c 100644 --- a/arch/arm/kernel/time.c +++ b/arch/arm/kernel/time.c @@ -76,42 +76,6 @@ void timer_tick(void) } #endif -static void dummy_clock_access(struct timespec64 *ts) -{ - ts->tv_sec = 0; - ts->tv_nsec = 0; -} - -static clock_access_fn __read_persistent_clock = dummy_clock_access; -static clock_access_fn __read_boot_clock = dummy_clock_access; - -void read_persistent_clock64(struct timespec64 *ts) -{ - __read_persistent_clock(ts); -} - -void read_boot_clock64(struct timespec64 *ts) -{ - __read_boot_clock(ts); -} - -int __init register_persistent_clock(clock_access_fn read_boot, - clock_access_fn read_persistent) -{ - /* Only allow the clockaccess functions to be registered once */ - if (__read_persistent_clock == dummy_clock_access && - __read_boot_clock == dummy_clock_access) { - if (read_boot) - __read_boot_clock = read_boot; - if (read_persistent) - __read_persistent_clock = read_persistent; - - return 0; - } - - return -EINVAL; -} - void __init time_init(void) { if (machine_desc->init_time) { From patchwork Mon May 14 08:55:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 135694 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1484190lji; Mon, 14 May 2018 01:57:05 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqikIJ8ZzSBEp+K/k2t/9sEYXDYnC7cgxPs8RCjSUg0MNtqhhJw2Mxi9GQnw3uZojIDQCkt X-Received: by 2002:a62:f909:: with SMTP id o9-v6mr9571103pfh.256.1526288225375; Mon, 14 May 2018 01:57:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526288225; cv=none; d=google.com; s=arc-20160816; b=LDLf/NyTM9zX6TEbX7tjbqg1pEl5PdwZ7Kck6cHjFLk7n+1PPuq8FONvJQ/6MjUBcL prFeS4hrJvEZU19hEs1oneJmIaoXQLhuJj8DnRDyz8FZl+SXFsQqdTdGWeXTvmw+CzGB bTnDRzsnus4x2axJLdC8ouOM/BA1Is6DeXvLDLx+PonNpLsLPHgMOHsaIFLzB+yhcn4j uDnB//w5YYLAl9OjZ2jpF+nanyjzJq1w82y1dWf87NiUKRMnp2vUYznmI4TJTwJpk9u5 0PUNRihmDIFmbIFDOQFxvtIO+Ou6Oip8Qs+KbgtmWslxwLQGo/YqA2glO1KcwZ2hOWtr qV/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=JFxtoPTIwMJxvyCd3hwanD0Gfpl/C9hHnauJqDpF+Pw=; b=dDkmmEoXqvtmvlkgHurQrcu6SnslKjrn3Gh/jKhT+vUSDxKa0rlxgdjP/QJmXAK1+B 75E6r/0tuijplAys4JoaB2GD4qQ1OZ8wPjQVIsihupYh9Gk0Zs+6npbv8xZcOCwuMTnS HrAJYk/rMBJxusZ1mxFGp+yBjspIR+GWFsoR+JbyQWptvDi05P+Aynvh4EDUe4Qjymxe skZWgMc2U3z+LX/poWhw0U9J5sbOSJt75D81wFu4nHsbyNHcUwgagHaCXlb7fgZy2ymE wLJw1Xv5/YTafsjU4zt1iXHAbRDqamEkytY5DVlgdlQTY7GmNK9FInCe0IGNSLj08u9v yaNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Lks8eZND; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 3-v6si5083231plh.34.2018.05.14.01.57.05; Mon, 14 May 2018 01:57:05 -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; dkim=pass header.i=@linaro.org header.s=google header.b=Lks8eZND; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752328AbeENI5D (ORCPT + 29 others); Mon, 14 May 2018 04:57:03 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:44835 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751976AbeENI5B (ORCPT ); Mon, 14 May 2018 04:57:01 -0400 Received: by mail-pf0-f196.google.com with SMTP id q22-v6so5687948pff.11 for ; Mon, 14 May 2018 01:57:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=JFxtoPTIwMJxvyCd3hwanD0Gfpl/C9hHnauJqDpF+Pw=; b=Lks8eZNDMEB04VY1cgjqD8YoqccCAmFjMOqPkW1zAd2mXWkwu27GQv6G32ypyhwkaq 3oRVaG+qqCvTwYYd4hCr18OYCi5GQdGIhjWUI16FJAH2OIUfIbSv6Y2TsM0CTOGXgypp Rm+R1wJ81VVr9raelCz1VsGcLoHMbA6InPpE0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=JFxtoPTIwMJxvyCd3hwanD0Gfpl/C9hHnauJqDpF+Pw=; b=GMqBKsTBlPt4Yi+sCSmytxf49mC2rQjymZrSIk/nPvo4BTe0jvOmGqnHUp4I8RcqmX 5MB2X7mRMxcNVJiR2zs+Oyq/E40DzZ/bTCHbq0GzUOjhlNlkB7ujkSfE0gcxTntsXGST gH4qKykORKCygHBi7UjhDhVEyBc+DE+b3oFzjaHkzXBnwix3n1z/+6hHgvZxWAJXQB7a YTYgUHOl55Uvc/FhNCcxzb/Z+sTpjRyfdsUP+TZciWCcOOaKCwEBGpy3FndFxullEA2W 2T3nJBC+pZbwhJAbPiGguFnPJnZ5nxmLIv+d9YEwp/xbzYn+buJInEWpSU9TdNRKQr8h UGpA== X-Gm-Message-State: ALKqPweBqaseIbaLC4jD4qo56ov39/zvejGCKT1Icjd2ZhZ993xu4A27 Z1sSqJXDay7oWmokWm0unmsaQQ== X-Received: by 2002:a62:c6d9:: with SMTP id x86-v6mr9545154pfk.192.1526288221409; Mon, 14 May 2018 01:57:01 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id x71-v6sm23308158pfe.47.2018.05.14.01.56.51 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 14 May 2018 01:57:00 -0700 (PDT) From: Baolin Wang To: tglx@linutronix.de, john.stultz@linaro.org, daniel.lezcano@linaro.org, arnd@arndb.de, tony@atomide.com, aaro.koskinen@iki.fi, linux@armlinux.org.uk, mark.rutland@arm.com, marc.zyngier@arm.com Cc: baolin.wang@linaro.org, broonie@kernel.org, paulmck@linux.vnet.ibm.com, mlichvar@redhat.com, rdunlap@infradead.org, kstewart@linuxfoundation.org, gregkh@linuxfoundation.org, pombredanne@nexb.com, thierry.reding@gmail.com, jonathanh@nvidia.com, heiko@sntech.de, linus.walleij@linaro.org, viresh.kumar@linaro.org, mingo@kernel.org, hpa@zytor.com, peterz@infradead.org, douly.fnst@cn.fujitsu.com, len.brown@intel.com, rajvi.jingar@intel.com, alexandre.belloni@bootlin.com, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org Subject: [RFC PATCH 06/10] clocksource: arm_arch_timer: Register the persistent clock Date: Mon, 14 May 2018 16:55:32 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Register the persistent clock to compensate the suspend time for OS time, if the ARM counter clocksource will not be stopped in suspend state. Signed-off-by: Baolin Wang --- drivers/clocksource/Kconfig | 1 + drivers/clocksource/arm_arch_timer.c | 10 ++++++++++ 2 files changed, 11 insertions(+) -- 1.7.9.5 diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig index d7dddcc..884719c 100644 --- a/drivers/clocksource/Kconfig +++ b/drivers/clocksource/Kconfig @@ -308,6 +308,7 @@ config ARC_TIMERS_64BIT config ARM_ARCH_TIMER bool + select PERSISTENT_CLOCK select TIMER_OF if OF select TIMER_ACPI if ACPI diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c index 57cb2f0..671be63 100644 --- a/drivers/clocksource/arm_arch_timer.c +++ b/drivers/clocksource/arm_arch_timer.c @@ -32,6 +32,7 @@ #include #include +#include #undef pr_fmt #define pr_fmt(fmt) "arch_timer: " fmt @@ -950,6 +951,15 @@ static void __init arch_counter_register(unsigned type) /* 56 bits minimum, so we assume worst case rollover */ sched_clock_register(arch_timer_read_counter, 56, arch_timer_rate); + + /* + * Register the persistent clock if the clocksource will not be stopped + * in suspend state. + */ + if (!arch_counter_suspend_stop) + persistent_clock_init_and_register(arch_timer_read_counter, + CLOCKSOURCE_MASK(56), + arch_timer_rate, 0); } static void arch_timer_stop(struct clock_event_device *clk) From patchwork Mon May 14 08:55:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 135695 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1484336lji; Mon, 14 May 2018 01:57:19 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrbU/HulyMCfZFdx8w9QJBBK0KLnO0lGd3E6Hsew4rU0u/p6X/Ha33yftYlvZos/B5BYO54 X-Received: by 2002:a63:3fc9:: with SMTP id m192-v6mr7918318pga.340.1526288239026; Mon, 14 May 2018 01:57:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526288239; cv=none; d=google.com; s=arc-20160816; b=YHJFT9YSh2n0+GX84x6mElToDoxCkU+ieK2J+mjdXqRFmevhPFxfbR9jmu7wstT7jT HKglrltlc851nf16X3sXP4xHq7LeYIymWT6emh5VLvskqTRb6U0Q5yBZAVHlRSOb8Psv agmS9uRFLZCKREHzLYO6jdos0tAKMwZwag1cR/Vc/Jbg4ptYDOZvD8ld1HR8IN8ev9gh MqEm2h14IYhbb/s15JxBOUxqHznu19fc8m2XgxMLMrCckJXyLJfLYeCA5pH3GYWjkBmm eGqo5D4ZzX3cz1oVMAOE4KIUYjfIsO1XfnSPH+GGY2kkdFyhAbcDDc/zM+LXfPqyW4RS maiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=NPxlDCjOk7gpJ7ywY/IgHfUOCSQRmo1KxQ6z9d2/zdU=; b=YtGH3ULdoIxqrGzS/SSbJawc016EPKEirHj9Hyool/52CFKUtPR45a8hO3en5OZOYW ipYlNyCFDEwa8PFOK39LoLucYYsthpOqJ2RJKfll1JLqEst5rShPdbCSEd+rqZQzSucg MG8LsRoE9hZIsbPPKrUxBxJq5ul6Phx/tQsKdIh6FSeQf8r85Yx61ls9zzlmrw2KTbFZ 08L06ECGlMwV0ajlgaWqPkP4/xv4qQBpyRfpd98Fq0prKecZ3PGbavgnPsKG2y/gzT3O 1cWdoqRr0kW3FGfJWFOx69lUiTbl3LMhFuobdP6yb9dMDxGaad1MKUtleWmJyh4kytHJ 0dCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UgkJ7DPr; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 5-v6si9106266plc.203.2018.05.14.01.57.18; Mon, 14 May 2018 01:57:19 -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; dkim=pass header.i=@linaro.org header.s=google header.b=UgkJ7DPr; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752379AbeENI5P (ORCPT + 29 others); Mon, 14 May 2018 04:57:15 -0400 Received: from mail-pl0-f68.google.com ([209.85.160.68]:37192 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752352AbeENI5N (ORCPT ); Mon, 14 May 2018 04:57:13 -0400 Received: by mail-pl0-f68.google.com with SMTP id w19-v6so4360351plq.4 for ; Mon, 14 May 2018 01:57:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=NPxlDCjOk7gpJ7ywY/IgHfUOCSQRmo1KxQ6z9d2/zdU=; b=UgkJ7DPrVs2FS+q1sJ5W+xjwGyq9+VgCSMY0eMVdjnId0KNeM2scAqwY5XBLKpE/oI CeW6us/cfX0PZKRFlulEsABrhulsvbrd42LJVd1AgyFWYJkX0cileOmIw84x2AVlyRj0 CjI+taUHbA9uTCIbcDsnThF+PjQwcS/ob8bCs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=NPxlDCjOk7gpJ7ywY/IgHfUOCSQRmo1KxQ6z9d2/zdU=; b=XcAGD9KYNezYU+NxVw2XcYsGkRyXo9FZ+SnN5W+KuteJ+HFAbmpqJ2GDfMeeNvAOOb aBMj41jD3TGjL1auB2nZm+DyusI0XQaZAIT1fdB9GDydJ9yuFseDxUT8C+j9BswRtRy+ yvrPNc/V+MV2npLePhA9bmp1oE8f7ALS2fhzV+0cZvPQ3yhDtuXHjNFsk6S4vlcYPXh4 nrX72kVNy6I3okk6riu6RgA9kk34BPH042azYQgtBm/hdP4dhJ9LCYpFLIv0wZfOC8D2 Q8NP2tCwLLFQFexs5pAjh4Q77jfYCEnm5QjPPypvooCGYwOyXap/Y4ddFjuykCsEp+Hz H2lg== X-Gm-Message-State: ALKqPwdDPOvAjisPfF++zx3HZ2l0mj1pnuUnXjyicbE8ej2KZjGhdpWo 6XOZ5W/hAsdB0GHC7oiFCkMDuA== X-Received: by 2002:a17:902:6041:: with SMTP id a1-v6mr8935877plt.59.1526288233063; Mon, 14 May 2018 01:57:13 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id x71-v6sm23308158pfe.47.2018.05.14.01.57.01 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 14 May 2018 01:57:12 -0700 (PDT) From: Baolin Wang To: tglx@linutronix.de, john.stultz@linaro.org, daniel.lezcano@linaro.org, arnd@arndb.de, tony@atomide.com, aaro.koskinen@iki.fi, linux@armlinux.org.uk, mark.rutland@arm.com, marc.zyngier@arm.com Cc: baolin.wang@linaro.org, broonie@kernel.org, paulmck@linux.vnet.ibm.com, mlichvar@redhat.com, rdunlap@infradead.org, kstewart@linuxfoundation.org, gregkh@linuxfoundation.org, pombredanne@nexb.com, thierry.reding@gmail.com, jonathanh@nvidia.com, heiko@sntech.de, linus.walleij@linaro.org, viresh.kumar@linaro.org, mingo@kernel.org, hpa@zytor.com, peterz@infradead.org, douly.fnst@cn.fujitsu.com, len.brown@intel.com, rajvi.jingar@intel.com, alexandre.belloni@bootlin.com, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org Subject: [RFC PATCH 07/10] clocksource: timer-ti-32k: Register the persistent clock Date: Mon, 14 May 2018 16:55:33 +0800 Message-Id: <353359ad77f87c01e9cc5a5fce382dbf6e9318e6.1526285602.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since the 32K counter is always available, then we can register the persistent clock to compensate the suspend time for the OS time. Signed-off-by: Baolin Wang --- drivers/clocksource/Kconfig | 1 + drivers/clocksource/timer-ti-32k.c | 4 ++++ 2 files changed, 5 insertions(+) -- 1.7.9.5 diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig index 884719c..ed19757 100644 --- a/drivers/clocksource/Kconfig +++ b/drivers/clocksource/Kconfig @@ -262,6 +262,7 @@ config CLKSRC_TI_32K bool "Texas Instruments 32.768 Hz Clocksource" if COMPILE_TEST depends on GENERIC_SCHED_CLOCK select TIMER_OF if OF + select PERSISTENT_CLOCK help This option enables support for Texas Instruments 32.768 Hz clocksource available on many OMAP-like platforms. diff --git a/drivers/clocksource/timer-ti-32k.c b/drivers/clocksource/timer-ti-32k.c index 880a861..353ff9d 100644 --- a/drivers/clocksource/timer-ti-32k.c +++ b/drivers/clocksource/timer-ti-32k.c @@ -41,6 +41,7 @@ #include #include #include +#include /* * 32KHz clocksource ... always available, on pretty most chips except @@ -120,6 +121,9 @@ static int __init ti_32k_timer_init(struct device_node *np) } sched_clock_register(omap_32k_read_sched_clock, 32, 32768); + persistent_clock_init_and_register(omap_32k_read_sched_clock, + CLOCKSOURCE_MASK(32), 32768, 0); + pr_info("OMAP clocksource: 32k_counter at 32768 Hz\n"); return 0; From patchwork Mon May 14 08:55:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 135697 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1484583lji; Mon, 14 May 2018 01:57:39 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoTGNp+EpSXxE9NUe2ir8jyaTKT1sXNM7qnerqN5okrW7hBqDNWZ+yNzjkckmKxwBv09N4L X-Received: by 2002:a17:902:5304:: with SMTP id b4-v6mr8702930pli.231.1526288259303; Mon, 14 May 2018 01:57:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526288259; cv=none; d=google.com; s=arc-20160816; b=wWaV83kkKpOvghl1QglN/K8aqOip+ayINfT0IxC4yPMWAi+ESP0CG/Yd+FAlYrobvw gcw15vSl7IOjanaRpRluHlHoekkZ03u2m1sQsdm/764gmkUm5JeZ7X+dxlPaPPeIlrDQ gDoSzInoGewth2BiJG0REy2F6PRIwkP1nDOrNTiHy4IH3ZLyDho5Jt0QakS0JUTNwXs1 VsiZIYmgFt1hie6ECytyIcWv5lfej5QUd6uxtzEmY8Xzb3mJad+JInoERHKBw1ZEkx4d LTGnfBmIWye9/1wKgUaN5Tfe2c0/spkqTiMrxmMbOLDRtTkZk10+CnBl0bVrqIl53b+s WkQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=6dTncBxPB46L6hH2lsBRv+i0+ICaH1S5Yj0USGe1ULU=; b=dXHlIIsY6Am84Hu/nHCKBa1c4F+dCYgJaSlcv9N54tfiYOjc8LcIz7+7QHUlUYqH9B iOXsY6sRBVsoSa1ZS/GHg0EqgP4by0R+wAsqVut74/uTQFf16yg4oWHvSCwEv2BE9kv0 e+sPNPHr4YDrtXXdbBBfXqnk+KK8G71Ora6dWjHCXMcWaTzonnpLD6h9Ts/3ePNbvszw bgtHpQJLUU1in8kgq9kz3OLiWjw6lF6pL+qdL7UuaNRyBNOACmQ1zZxsXFqDgmp+ItS6 976DRaqf27MEBab2rQag9Y+S3UVYIDzccfDLvlw3s5sNwYnHLhlSnAFrrXU2I+c+bodg Zb7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=O7LuXt9D; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d9-v6si7059973pga.192.2018.05.14.01.57.39; Mon, 14 May 2018 01:57:39 -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; dkim=pass header.i=@linaro.org header.s=google header.b=O7LuXt9D; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752466AbeENI5h (ORCPT + 29 others); Mon, 14 May 2018 04:57:37 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:40704 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752244AbeENI5d (ORCPT ); Mon, 14 May 2018 04:57:33 -0400 Received: by mail-pl0-f65.google.com with SMTP id t12-v6so6981068plo.7 for ; Mon, 14 May 2018 01:57:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=6dTncBxPB46L6hH2lsBRv+i0+ICaH1S5Yj0USGe1ULU=; b=O7LuXt9DjUTWeJP/XeLZTEombDNfkbsNPcXYQDRVo8/kyygjDd5bsOm7BsX5MZ52We wTZactJEMMYsAEDWAXjNWu57Lzvg2A+b6KbfdKn1jJ6tW1uUae0+9VNYGF6+yP4JuQnM wmGNd4JVC5aGXUv6pM81TKbgSIw74U0Mhqd5E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=6dTncBxPB46L6hH2lsBRv+i0+ICaH1S5Yj0USGe1ULU=; b=tqGX8NcPY5Kr+vlblTdU5NeCOJfCk61g63befy7zorPgbHdA/1I/+0lVFjaIl6w58a yTKjM2KrjSQAoKC4igm/EehMP7QhQ7EHnUCJFhL57fWBwHs9xG5HJEswHdTul+gHD55/ wAgoY6euxLThhAE3cYDYyQHPDO6H5qmNnH7pXs4qbPzhmP2eXw+p6Iej6/5dv3GewkOZ Hfc59EzJGLbSlZ48if62pNVNAsTiM6ALa+KRjUmVpPuBR/i/zb6/EE9RtP7oaqyveTKC ZJKrqiPtDSG4QxXHBxt5Kr8JgvMqBP7LrG7LpozkMc6NUA5OYEMO5GKBY+2SHGlvG1VX LyfA== X-Gm-Message-State: ALKqPwd9HiWZ7u6CmYIPSqk6ogzJZKnYxPsMMHMnvFDHwyi2COCI7ODO SDDJXBtcv4RlaOeje/BrG1AXgA== X-Received: by 2002:a17:902:4483:: with SMTP id l3-v6mr9076404pld.282.1526288253397; Mon, 14 May 2018 01:57:33 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id x71-v6sm23308158pfe.47.2018.05.14.01.57.23 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 14 May 2018 01:57:32 -0700 (PDT) From: Baolin Wang To: tglx@linutronix.de, john.stultz@linaro.org, daniel.lezcano@linaro.org, arnd@arndb.de, tony@atomide.com, aaro.koskinen@iki.fi, linux@armlinux.org.uk, mark.rutland@arm.com, marc.zyngier@arm.com Cc: baolin.wang@linaro.org, broonie@kernel.org, paulmck@linux.vnet.ibm.com, mlichvar@redhat.com, rdunlap@infradead.org, kstewart@linuxfoundation.org, gregkh@linuxfoundation.org, pombredanne@nexb.com, thierry.reding@gmail.com, jonathanh@nvidia.com, heiko@sntech.de, linus.walleij@linaro.org, viresh.kumar@linaro.org, mingo@kernel.org, hpa@zytor.com, peterz@infradead.org, douly.fnst@cn.fujitsu.com, len.brown@intel.com, rajvi.jingar@intel.com, alexandre.belloni@bootlin.com, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org Subject: [RFC PATCH 09/10] x86: tsc: Register the persistent clock Date: Mon, 14 May 2018 16:55:35 +0800 Message-Id: <3b626f6d7dd5ca047e6835b10c3a4e662db2539f.1526285602.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Register the tsc as one persistent clock to compensate the suspend time if the tsc clocksource is always available. Signed-off-by: Baolin Wang --- arch/x86/Kconfig | 1 + arch/x86/kernel/tsc.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) -- 1.7.9.5 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index c07f492..667e3a7 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -195,6 +195,7 @@ config X86 select USER_STACKTRACE_SUPPORT select VIRT_TO_BUS select X86_FEATURE_NAMES if PROC_FS + select PERSISTENT_CLOCK config INSTRUCTION_DECODER def_bool y diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c index 74392d9..dd8d7c3 100644 --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -1032,6 +1033,11 @@ static u64 read_tsc(struct clocksource *cs) return (u64)rdtsc_ordered(); } +static u64 notrace tsc_read_persistent_clock(void) +{ + return (u64)rdtsc_ordered(); +} + static void tsc_cs_mark_unstable(struct clocksource *cs) { if (tsc_unstable) @@ -1300,6 +1306,11 @@ static void tsc_refine_calibration_work(struct work_struct *work) if (boot_cpu_has(X86_FEATURE_ART)) art_related_clocksource = &clocksource_tsc; clocksource_register_khz(&clocksource_tsc, tsc_khz); + + if (clocksource_tsc.flags & CLOCK_SOURCE_SUSPEND_NONSTOP) + persistent_clock_init_and_register(tsc_read_persistent_clock, + CLOCKSOURCE_MASK(64), + tsc_khz, 0); unreg: clocksource_unregister(&clocksource_tsc_early); } @@ -1327,6 +1338,11 @@ static int __init init_tsc_clocksource(void) if (boot_cpu_has(X86_FEATURE_ART)) art_related_clocksource = &clocksource_tsc; clocksource_register_khz(&clocksource_tsc, tsc_khz); + + if (clocksource_tsc.flags & CLOCK_SOURCE_SUSPEND_NONSTOP) + persistent_clock_init_and_register(tsc_read_persistent_clock, + CLOCKSOURCE_MASK(64), + tsc_khz, 0); unreg: clocksource_unregister(&clocksource_tsc_early); return 0;