Received: by 10.192.178.70 with SMTP id s6csp6352imc; Thu, 26 Apr 2018 14:42:46 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/Ap44zgOBWv6PoO8lRfVc/OaEKRbTlwpchlZoF9wHifmxuP2RxC+gtcjnPnzKL83GChGu7 X-Received: by 2002:a17:902:14b:: with SMTP id 69-v6mr36111965plb.184.1524778966778; Thu, 26 Apr 2018 14:42:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524778966; cv=none; d=google.com; s=arc-20160816; b=s4FpL8mMeeOCP0mCNzm6tiehHRiJKVRv8QMJwPFAnjqN47q764XICDiEXVELikrhpX KYY7piPthiLvSYPGrdLYjjgdXckg9RU38PvgvMlfQmyc1WHRzGrou9969NghWvKpCPWX tWA8RG1TjpcMAj4UrT0MpCi1NblJc+9SbyLUzKOs+DtLk+RxxatL7tbauvPL0l35U0cu n6XvnNxkUUWeBlp91faWxS687BYVZAQh0aEhSPcEhOmdChSM5bpzsg45eo1Uur9vToH1 EdM/SncX1ySqbxuj055q5ojbPUuyrJAHbSLUe17wqj25pVroLjyLQ0LUaRoY2Phtf7ZS 2ciw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date :arc-authentication-results; bh=BtIUaG/IgZmCwqtCZf7x4uCKjmKEqEoYLnK1nm1JvQs=; b=lLi4Nxg8+7PEhPYXrbHdyO90NPG8KsX14NCKcsY8BuG/C+fHXHUZQUAUc1J4zhbjfm O7yaHsdSEoUFrMelrcmpSS5zW66BnMPHhhJg025abJaxCVjA7d0+1p3vf/JOWlJMsYxy bUBxMhX2f/7QG3KCoZlEVms3r8bWQMjKCZH8rB5xt9oUMh6PRKDTcWulSkvO2Rn1SSwr Nm35GcG2QjmEg/SzOfNx1s3zPIek00NUjUQ8qr7Iy5F6wf/ZNEIE5vr8r7REZ3puUOG5 Xd/87GEmYJtdFqjOAeW8BvkT85uLPSoKB/F4ugiwP7V+Bd9hY17lK6RAebIy7IYeoJzM fuaw== 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 8-v6si19606223plc.342.2018.04.26.14.42.32; Thu, 26 Apr 2018 14:42: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 S1754888AbeDZVkS (ORCPT + 99 others); Thu, 26 Apr 2018 17:40:18 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:50360 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752000AbeDZVkR (ORCPT ); Thu, 26 Apr 2018 17:40:17 -0400 Received: from p5492e61e.dip0.t-ipconnect.de ([84.146.230.30] helo=nanos.glx-home) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1fBocg-0004MR-FK; Thu, 26 Apr 2018 23:40:14 +0200 Date: Thu, 26 Apr 2018 23:40:14 +0200 (CEST) From: Thomas Gleixner To: Imre Deak cc: LKML , Peter Zijlstra , =?ISO-8859-15?Q?Ville_Syrj=E4l=E4?= , Mika Kuoppala , Chris Wilson Subject: Re: Early timeouts due to inaccurate jiffies during system suspend/resume In-Reply-To: <20180424140741.yxn5u6rdviblhtzx@ideak-desk.fi.intel.com> Message-ID: References: <20180419013200.wxkzqfdacfsijci5@ideak-desk.fi.intel.com> <20180423170128.mf7g26rniimm7asf@ideak-desk.fi.intel.com> <20180424140741.yxn5u6rdviblhtzx@ideak-desk.fi.intel.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 24 Apr 2018, Imre Deak wrote: > On Mon, Apr 23, 2018 at 08:01:28PM +0300, Imre Deak wrote: > > On Thu, Apr 19, 2018 at 01:05:39PM +0200, Thomas Gleixner wrote: > > > On Thu, 19 Apr 2018, Imre Deak wrote: > > > > Hi, > > > > > > > > while checking bug [1], I noticed that jiffies based timing loops like > > > > > > > > expire = jiffies + timeout + 1; > > > > while (!time_after(jiffies, expire)) > > > > do_something; > > > > > > > > can last shorter than expected (that is less than timeout). > > > > > > Yes, that can happen when the timer interrupt is delayed long enough for > > > whatever reason. If you need accurate timing then you need to use > > > ktime_get(). > > > > Thanks. I always regarded jiffies as non-accurate, but something that > > gives a minimum time delay guarantee (when adjusted by +1 as above). I > > wonder if there are other callers in kernel that don't expect an early > > timeout. > > msleep and any other schedule_timeout based waits are also affected. At the > same time for example msleep's documentation says: > "msleep - sleep safely even with waitqueue interruptions". > > To me that suggests a wait with a minimum guaranteed delay. Kinda :) The problem with jiffies is that it's a software maintained counter which depends on interrupt delivery. Contrary to hardware based counters which just work (most of the time at least). > Ville had an idea to make the behavior more deterministic by clamping > the jiffies increment to 1 for each timer interrupt. Would that work? In theory, but there is the problem with NOHZ. NOHZ idle allows the CPU to sleep for more than 1 jiffie in order to safe power by not waking up just to increment jiffies and go back to sleep. So we need to push jiffies forward when the system was completely idle for some time. We already make sure that jiffies are updated on interrupt entry from idle before any code relying on them is run. Now for the weird case where interrupts get delayed awfully long, the right answer is to break these long interrupt disabled sections. Anything which holds interrupts disabled longer than a couple of microseconds is broken. Thanks, tglx