Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1418300imm; Tue, 15 May 2018 19:58:54 -0700 (PDT) X-Google-Smtp-Source: AB8JxZp2V1SnI4YcHPOJe6Q0K2uUkcFvH3Id9ypHQ7Vm/w3LACZAtCNsTxVrGpziV3ctlmaDFlQe X-Received: by 2002:a65:404d:: with SMTP id h13-v6mr14414081pgp.374.1526439534276; Tue, 15 May 2018 19:58:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526439534; cv=none; d=google.com; s=arc-20160816; b=MVbSoafqsnhuz4KslrqAQlMBEViGMe0o/OzpWZo6xSOfQCyUQlxGCDPAiu0DNkEJ6t VQzM+e/xtCryGRMtdrJDYBCI1GpPgVjV26XMA1v6f2DdHwJRyRAieHNrhaOISRMqAkJ5 v7t4TtR+ptIu14sgNTpC0VJFZ92EbWMWvwqiYQPAcs/O0W/PQ4AOCxh5/M3wmrRQRcye FzTBx0pixBxYZZk6hnIb6zHAfe2eUMRYd2t9oTL86e0Tb455vS3e3g0NeRO8y8/gc9Wr E9MdK9iASJXVs2ky/L5f+lNpSvMpfMpdns/ZsgpzOJDrCP2PRF5ByZrK2MX5ijlHcONy 8VQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=3UJdt6H4DrgKDEOV0Qb8ksDU7iLTLjPjC5pRORN6NAo=; b=mkDVDufDisPoy1b32FUIm5PXiFnM2IourxsTndI5Bg9smMh4tqfoANCABPTbF6TzOI jJx8zsKW8JNqzL5Bce+QLoW03pmXlw0U0bUiVAcI2DhjK1GGN1TLoO3sRysbQqNbG9tY xjmrAkJCz7Ow7xrAdg4lyFyGe/1LJQbMkHbYoIUB5DtKFviRwTpvIrhsm2bpP11BGMta sRr/uHfseYgFPUU7khScp3X+piNis7g9zOPIjyDUP1oIuAQbZ8u+GYu4bAhJz9ex1vTx sZlJ3xftszKJvHXyvQEoGNgeqDybSGtem1iY2hS6DYfywHYfNXl72JHBad+cj+ss60yv Jh0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Qlwk690r; 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 j8-v6si1464201plk.0.2018.05.15.19.58.39; Tue, 15 May 2018 19:58:54 -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=Qlwk690r; 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 S1752222AbeEPC63 (ORCPT + 99 others); Tue, 15 May 2018 22:58:29 -0400 Received: from mail-oi0-f68.google.com ([209.85.218.68]:41404 "EHLO mail-oi0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752015AbeEPC61 (ORCPT ); Tue, 15 May 2018 22:58:27 -0400 Received: by mail-oi0-f68.google.com with SMTP id 11-v6so2106641ois.8 for ; Tue, 15 May 2018 19:58:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=3UJdt6H4DrgKDEOV0Qb8ksDU7iLTLjPjC5pRORN6NAo=; b=Qlwk690r22xq/4WEXas91Zskp6NlRwTyb5LxKVIdwzGZpYeKoSTuUh6kMD3L3llGuT MznQ+NGhbXEqBazWprACSElVukAi5Z1QRQ3pNN/aGormY3AFUDftmA4qULdr7xPQyxqd n596EoDZLdkBcj0w0FwVCuxhtubJn/754ysUA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=3UJdt6H4DrgKDEOV0Qb8ksDU7iLTLjPjC5pRORN6NAo=; b=aWlCNfBBwJvKYNvtZzHVFdP8LmLYirIE99LfyOlLvyFR017BYg11w8ZdQ13QUVLdJh 9Py6Tehx/JSVB96nUqZkVx58d7R9CZb2+LvRDPcSGkRDjXfbga2779qXVSjfHKArwZF9 gVNDG9s6mFWFswUPQg5V4RAM7ic6Jf2gX8+Xt6yKBCp7xBOPT7zgxkZzpSuWMdlTSZi+ rAxO9Xdo6AKUqKMUgc6YrudRzrbb91Yqj148WIpzxnz0hMiEBPnLakG4Opc5ebs9cxQ7 FrDt6sqp6q0VBJSmMUOdhCb4U4Yq+jXuT5GD7sSkB63PXBCTdvKewYxMXKcR6OeDMwlm vxeQ== X-Gm-Message-State: ALKqPwfkKl5ybxN7bUVMY2b2Y/srBXYwXXHgv8ZxZAVHHK2Q7HDFLldJ qiuQmXDfXSTvXEhpAqtXh7vXUPKQfY8Pt9FjPnUp0Q== X-Received: by 2002:aca:3c07:: with SMTP id j7-v6mr11953453oia.128.1526439506626; Tue, 15 May 2018 19:58:26 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a9d:2d77:0:0:0:0:0 with HTTP; Tue, 15 May 2018 19:58:26 -0700 (PDT) In-Reply-To: <20180515135612.GQ29062@mai> References: <20180515135612.GQ29062@mai> From: Baolin Wang Date: Wed, 16 May 2018 10:58:26 +0800 Message-ID: Subject: Re: [RFC PATCH 00/10] Add persistent clock support To: Daniel Lezcano Cc: Thomas Gleixner , John Stultz , Arnd Bergmann , Tony Lindgren , aaro.koskinen@iki.fi, linux@armlinux.org.uk, Mark Rutland , Marc Zyngier , Mark Brown , Paul McKenney , mlichvar@redhat.com, rdunlap@infradead.org, Kate Stewart , Greg KH , Philippe Ombredanne , Thierry Reding , Jon Hunter , =?UTF-8?Q?Heiko_St=C3=BCbner?= , Linus Walleij , Viresh Kumar , Ingo Molnar , "H. Peter Anvin" , peterz@infradead.org, douly.fnst@cn.fujitsu.com, len.brown@intel.com, rajvi.jingar@intel.com, Alexandre Belloni , x86@kernel.org, Linux ARM , linux-tegra@vger.kernel.org, LKML , linux-omap@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org HI Daniel, On 15 May 2018 at 21:56, Daniel Lezcano wrote: > On Mon, May 14, 2018 at 04:55:26PM +0800, Baolin Wang wrote: >> Hi, >> >> We will meet below issues when compensating the suspend time for the timekeeping. >> >> 1. We have too many different ways of dealing with persistent timekeeping >> across architectures, so it is hard for one driver to compatable with different >> architectures. >> >> 2. On some platforms (such as Spreadtrum platform), we registered the high >> resolution timer as one clocksource to update the OS time, but the high >> resolution timer will be stopped in suspend state. So we use another one >> always-on timer (but low resolution) 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 and need update the clock in case of >> running over the always-on timer. >> >> More duplicate code will be added if other platforms meet this case. >> >> 3. Now we have 3 sources that could be used to compensate the OS time: >> Nonstop clocksource during suspend, persistent clock and rtc device, >> which is complicated. Another hand is that the nonstop clocksource can >> risk wrapping if the suspend time is too long, so we need one mechanism >> to wake up the system before the nonstop clocksource wrapping. >> >> According to above issues, we can introduce one common persistent clock >> framework to compatable with different architectures, in future we will >> remove the persistent clock implementation for each architecture. Also >> this framework will implement common code to help drivers to register easily. >> Moreover if we converted all SUSPEND_NONSTOP clocksource to register to >> be one persistent clock, we can remove the SUSPEND_NONSTOP clocksource >> accounting in timekeeping, which means we can only compensate the OS time >> from persistent clock and RTC. >> >> Will be appreciated for any comments. Thank you all. > > Why do we need another API ? > > Why not remove the present persistent API and rely on the SUSPEND_NONSTOP flag > to do the right action at suspend and resume? > > We register different clocksources, the rating does the selection. > > When entering 'suspend', we check against the SUSPEND_NONSTOP flag and switch > to the first clocksource with the best rating and the flag set. When resuming, > we switch back to the highest rating. I agree with John's view he posted before, he said: "For context, these abstractions have grown out of the need for using different hardware components for all of these. It was quite common for x86 hardware to use the acpi_pm for clocksource, lapic/PIT for clockevent, tsc for sched_clock and CMOS RTC for persistent clock. While some of these could be backed by the same hardware, it wasn't common. However, hardware with less restrictions have allowed in some cases for these to be more unified, but I'm not sure if its particularly common. Another part of the reason that we don't combine the above abstractions, even when they are backed by the same hardware, is because some of the fields used for freq conversion (mult/shift) have different needs for the different types of accounting. For instance, with a clocksource, we are very focused on avoiding error to keep timekeeing accurate, thus we want to use as large a shift (and thus mult) as possible (and do our shifting as late as possible in our accounting). However, that then shrinks the amount of time that can be accumulated in one go w/o causing an overflow. Where as with sched_clock, we don't worry as much as about accuracy, so we can use smaller shifts (and thus mults), and thus can go for longer periods of time between accumulating without worrying. Similarly for the persistent clock case we don't need need to worry as much about accuracy, so we can can use smaller shifts, but we are not in as much of a hot patch, so we can also" -- Baolin.wang Best Regards