Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp505233imm; Fri, 14 Sep 2018 01:49:40 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaYoMSnxBXm2Ddm83sbv27KHDztJnDYfKiH/Ox04XhO7pY86PM3pFTWTI2sEGXfG43m6AKT X-Received: by 2002:a63:231c:: with SMTP id j28-v6mr10682859pgj.332.1536914980252; Fri, 14 Sep 2018 01:49:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536914980; cv=none; d=google.com; s=arc-20160816; b=EDJbT5cqYB2wxOQUK0LOL0E0aCT8LX1BnVh0sBnvni5Hsc2ZnZE/BsD03/VdWtXRUU Nua1MEYrOC4Wg+RfteoyHjUam+Z/fopsGn7getwu+wJBztGABbIQ1/KVdDSoVvzlGMAO 6A47OgHSrAtLuv39rANo2TTISXZmynO1Pzd1n22+giqnDCbZeKgfDMPJtOwjbdtDeDkC +LOUpfezUcQIK/8PaXYo1h2nDKyVHZ/Z8KM/4FEN5mTDI8C/nNf7IZU8MHw5iKSF0EXI 4r9H2ZWWxz81VpIEvYwQrizTg3lrqPP1+tbQuSl3Et6A3Lw32OfGTrc0wMo1oiebJISD h4Fg== 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=PmWyviWT0ktGN9EHvS05O1Ya2o3RbQBT2UjNvqpvxKw=; b=P+gadkpZjFuOxBRMN02CY2PKCmDJw5A94dC47GRK5MonBSFsYzpzip8N2zebU35pai naTxt9ZvOBxRLvg24gM+wmoAld+Rqu/ApElmemFNhnGmM4bBcMNsqpD8WYdPR7iY9q4u FHLbgnKrF6E/0cWX1Oj2fMTHGfqyfksxuEZ4d5HM5M4PWaTRV9kz4aj9ELWlz7GX/NL8 J2nwUvvoLtRhm7+yWoJEekbErIjvLqEQQ9FpU0Qx3iEF8p7qx5ojv651haVWMfIXOWjJ gPMC6qeKZRN19hOLTaaXxQ3XX3GGg4KJt8YXiy+J6Qu+RpOXqICIF32hC6YfPgKf97VD TBJw== 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 c9-v6si6612821pgt.398.2018.09.14.01.49.24; Fri, 14 Sep 2018 01:49:40 -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 S1728067AbeINOCs convert rfc822-to-8bit (ORCPT + 99 others); Fri, 14 Sep 2018 10:02:48 -0400 Received: from cloudserver094114.home.pl ([79.96.170.134]:57637 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726618AbeINOCr (ORCPT ); Fri, 14 Sep 2018 10:02:47 -0400 Received: from 79.184.255.178.ipv4.supernova.orange.pl (79.184.255.178) (HELO aspire.rjw.lan) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83.148) id f0624824cc37fe96; Fri, 14 Sep 2018 10:49:15 +0200 From: "Rafael J. Wysocki" To: Mika =?ISO-8859-1?Q?Penttil=E4?= Cc: Linux PM , Linux ACPI , LKML , Mika Westerberg , Peter Zijlstra , Thomas Gleixner , Srinivas Pandruvada , Vitaly Kuznetsov Subject: Re: [PATCH] PM / suspend: Count suspend-to-idle loop as sleep time Date: Fri, 14 Sep 2018 10:46:35 +0200 Message-ID: <1831106.CYv9dyYV15@aspire.rjw.lan> In-Reply-To: <767e9ec4-cc35-9255-360a-4d12736aa4de@nextfour.com> References: <9611469.2z7W9akjOQ@aspire.rjw.lan> <767e9ec4-cc35-9255-360a-4d12736aa4de@nextfour.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8BIT Content-Type: text/plain; charset="iso-8859-1" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Friday, September 14, 2018 10:28:44 AM CEST Mika Penttil? wrote: > Hi! > > > On 09/14/2018 09:59 AM, Rafael J. Wysocki wrote: > > From: Rafael J. Wysocki > > > > There is a difference in behavior between suspend-to-idle and > > suspend-to-RAM in the timekeeping handling that leads to functional > > issues. Namely, every iteration of the loop in s2idle_loop() > > increases the monotinic clock somewhat, even if timekeeping_suspend() > > and timekeeping_resume() are invoked from s2idle_enter(), and if > > many of them are carried out in a row, the monotonic clock can grow > > significantly while the system is regarded as suspended, which > > doesn't happen during suspend-to-RAM and so it is unexpected and > > leads to confusion and misbehavior in user space (similar to what > > ensued when we tried to combine the boottime and monotonic clocks). > > > > To avoid that, count all iterations of the loop in s2idle_loop() > > as "sleep time" and adjust the clock for that on exit from > > suspend-to-idle. > > > > [That also covers systems on which timekeeping is not suspended > > by by s2idle_enter().] > > > > Signed-off-by: Rafael J. Wysocki > > --- > > > > This is a replacement for https://patchwork.kernel.org/patch/10599209/ > > > > I decided to count the entire loop in s2idle_loop() as "sleep time" as the > > patch is then simpler and it also covers systems where timekeeping is not > > suspended in the final step of suspend-to-idle. > > > > I dropped the "Fixes:" tag, because the monotonic clock delta problem > > has been present on the latter since the very introduction of "freeze" > > (as suspend-to-idle was referred to previously) and so this doesn't fix > > any particular later commits. > > > > --- > > kernel/power/suspend.c | 18 ++++++++++++++++++ > > 1 file changed, 18 insertions(+) > > > > Index: linux-pm/kernel/power/suspend.c > > =================================================================== > > --- linux-pm.orig/kernel/power/suspend.c > > +++ linux-pm/kernel/power/suspend.c > > @@ -109,8 +109,12 @@ static void s2idle_enter(void) > > > > static void s2idle_loop(void) > > { > > + ktime_t start, delta; > > + > > pm_pr_dbg("suspend-to-idle\n"); > > > > + start = ktime_get(); > > + > > for (;;) { > > int error; > > > > @@ -150,6 +154,20 @@ static void s2idle_loop(void) > > pm_wakeup_clear(false); > > } > > > > + /* > > + * If the monotonic clock difference between the start of the loop and > > + * this point is too large, user space may get confused about whether or > > + * not the system has been suspended and tasks may get killed by > > + * watchdogs etc., so count the loop as "sleep time" to compensate for > > + * that. > > + */ > > + delta = ktime_sub(ktime_get(), start); > > + if (ktime_to_ns(delta) > 0) { > > + struct timespec64 timespec64_delta = ktime_to_timespec64(delta); > > + > > + timekeeping_inject_sleeptime64(×pec64_delta); > > + } > > But doesn't injecting sleep time here make monotonic clock too large by the amount of sleeptime? > tick_freeze() / tick_unfreeze() already injects the sleeptime (otherwise delta would be 0). No, it doesn't. The delta here is the extra time taken by the loop which hasn't been counted as sleep time yet. Thanks, Rafael