Received: by 10.192.165.148 with SMTP id m20csp3654629imm; Mon, 23 Apr 2018 10:02:58 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+z6i8hv4UfrVnj3iJJEhRy1xOpEGMe2se7bjERZp71XJ/1DbnZodX14SBGcdmJBaGAqSW/ X-Received: by 2002:a17:902:d20a:: with SMTP id t10-v6mr21610064ply.151.1524502978792; Mon, 23 Apr 2018 10:02:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524502978; cv=none; d=google.com; s=arc-20160816; b=r0srHwSBbmyZg74UQjlgFJoKh0jyjOpM01ZRKTyohxoMJMU/1JBIOSXlPrdJkZeo7a E5fpigxeCXfIBCG2i6NFI1qKHjsHBoQDyenZYiHa3TM83lTyZ3E1n9eLEJ8+bC4mtk6y Q8Gicc2xq2Qo+dM+oGdBfJ9qecNbL+C4i7RVSEF8LwljH9Y4A6KUO5i3lbuSmQN1xvjC LCcD765+xA+FP+k/5YdcaOTAk04wgMQwkr5G0gS9gEVoZZyewjTP1bMhMQRpFT/WjPo8 XFYytEXC6t8yTmNAsEKZk/eSK7zvmEGWpB9sEzg8kNnY6dDQ2GxhieAM67CABwhQm0n1 BC3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date:arc-authentication-results; bh=sKeh9neGFY0BR+IGz2MQAjZ5wVfuEyX5A05KAM4xPtw=; b=H0s5oAMnOeDYf/qMVe8nPR/jflfZ0NU66PPK4qtFTPYamw+WpohOl+7iKHnxD19SyM ifNb4/qZD7shrG29KevzYDLRsrt3C90RcCB9rRIbxbfldQ1Ys1KXfclO1BONg4NXq72+ oDKt7RJtKC+ZTH9CBi+++xVNgRnh0uqap97in0Ppwl9NxhpVeRnOtiEfkJtOpb7DtwBW ySP2VzPIKY+jyXOTohE1m6YfikZ01zuzWIlaA7zRR/FosOfbqSahO2u002PRw8Rp6QRF 9jralBs8XfURgA7aUgDP6DT0I1pNueOKcy/XzXyxxKMcjDHlg97A246/q/a8xrQH4RMU lHjQ== 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 g185si9946881pgc.155.2018.04.23.10.02.43; Mon, 23 Apr 2018 10:02:58 -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 S1755764AbeDWRBd (ORCPT + 99 others); Mon, 23 Apr 2018 13:01:33 -0400 Received: from mga01.intel.com ([192.55.52.88]:65510 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755573AbeDWRBc (ORCPT ); Mon, 23 Apr 2018 13:01:32 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Apr 2018 10:01:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,318,1520924400"; d="scan'208";a="39794569" Received: from ideak-desk.fi.intel.com ([10.237.72.61]) by fmsmga002.fm.intel.com with ESMTP; 23 Apr 2018 10:01:29 -0700 Date: Mon, 23 Apr 2018 20:01:28 +0300 From: Imre Deak To: Thomas Gleixner Cc: LKML , Peter Zijlstra , Ville =?iso-8859-1?Q?Syrj=E4l=E4?= , Mika Kuoppala , Chris Wilson Subject: Re: Early timeouts due to inaccurate jiffies during system suspend/resume Message-ID: <20180423170128.mf7g26rniimm7asf@ideak-desk.fi.intel.com> Reply-To: imre.deak@intel.com References: <20180419013200.wxkzqfdacfsijci5@ideak-desk.fi.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. We switched now to using ktime_get_raw() in the i915 driver. > > > After some ftracing it seems like jiffies gets stale due to a missed > > LAPIC timer interrupt after the interrupt is armed in > > lapic_next_deadline() and before jiffies is sampled at 2. above. > > Eventually the interrupt does get delivered, at which point jiffies gets > > updated via tick_do_update_jiffies64() with a >1 ticks increment. > > Between lapic_next_deadline() and the - late - delivery of the interrupt > > the CPU on which the interrupt is armed doesn't go idle. > > That's odd. I have no real explanation for that. Looks like the reason is IRQ latency. For reference here are the longest ones I found with irqsoff ftracing, all running with IRQs disabled during system resume: hpet_rtc_interrupt()->hpet_rtc_timer_reinit(): do { ... } while(!hpet_cnt_ahead(...)); takes sometimes up to ~40msec for me. hpet_rtc_interrupt()->mc146818_get_time(): if (mc146818_is_updating()) mdelay(20); driver_probe_device->atkbd_connect()->i8042_port_close()->__i8042_command()->i8042_wait_write(): takes sometimes up to ~10msec for me. All the above paired with asynchronous calling of the drivers' resume hooks may result in the jumps in jiffies I saw. --Imre