Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp752477imu; Wed, 9 Jan 2019 05:54:13 -0800 (PST) X-Google-Smtp-Source: ALg8bN5+KcRx4lawZBnIAZdSNdvruKFf8yE4Txd1CGFsaHCtemS/0+yGS3z6n4g6nIUAwj5xewYE X-Received: by 2002:a62:710a:: with SMTP id m10mr6045800pfc.69.1547042053166; Wed, 09 Jan 2019 05:54:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547042053; cv=none; d=google.com; s=arc-20160816; b=G4pQ+ek84Q9SZaKP5WdD6Ho/35sLnwhRnX7ZCBNaQ6/1wayEtN2F52di9n/ae8Qzg7 ITviwPEhTlJQwVKmZixkMJUMuabm9MvUQsUmu+f5L8ClV4jGnjgH+sCn5ATg+tF6xMbg Tyn5c8paLfdw8+ULs3qWWZd4gl6Wwc4zIWR/4MX8013uIWy4jov9+GzaRoTE0HfOBQag REPtk0xKTSiUa+LTW1yHoqEdB9+LCMOIPn7N596BfnnQqdTg5T/xBFceqGttanrFegmG 3E9HLVqK8y6+r9jfZ9Cuag92COU+6pc2hM4Y6AOYuZWzs3RlnLsEPl3Gcx05ZlSOT+0Y X/cQ== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=5hsdTeezotDqIwqu1cpLVURCriWtQKJNakUlAd/T5M8=; b=sibcc79KTd0cEYZTZRL4iTHnl0tXV/gpuEGI8Ig3QYsINRnIBa6LDznZItqPjr1Ns0 Q87qtk/DolZpu8LiGcDeXiul5/5WORkEb+JBltFCbGrwCdvuW1JWnzFBahXeljLJUZ4o 84NYail83fAIMWDBSL+6VfnbYs7iflMK5alkT/4bzTZArPFdHiGPMzSQ4q5+fGiGYASO HE6RwJJBGp//tKjpZmSZQ/IZCgKJ8ezpQNXS8L6p5PrwZAOA9Mk75prtrds+qZQUk4MG acPAkECpAnU2agKQbTl8TUjP9Do+FKheSved+u77uuaBkB/PD3R2jCQaVM8JlXRxTqqT JHpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cBivxxLo; 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 t3si11357861plo.69.2019.01.09.05.53.58; Wed, 09 Jan 2019 05:54:13 -0800 (PST) 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=cBivxxLo; 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 S1731060AbfAINYu (ORCPT + 99 others); Wed, 9 Jan 2019 08:24:50 -0500 Received: from mail-io1-f68.google.com ([209.85.166.68]:43204 "EHLO mail-io1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729994AbfAINYu (ORCPT ); Wed, 9 Jan 2019 08:24:50 -0500 Received: by mail-io1-f68.google.com with SMTP id b23so5968567ios.10 for ; Wed, 09 Jan 2019 05:24:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=5hsdTeezotDqIwqu1cpLVURCriWtQKJNakUlAd/T5M8=; b=cBivxxLopiyns29Buj8DXZhRdxv0QVQ7JpNDg6m4Uy8zENx1YEZh2iioI3AC99ILg+ C5Dv4uvcH9wr3ADtxhcbQqZWqdkNtFFOH0AJev2sXlXF/s/+ayFByifmAbQUhfLA2v/z oRFHXMKrrwiEf5i8Z5Cji2+RIySMRPqr49dPg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=5hsdTeezotDqIwqu1cpLVURCriWtQKJNakUlAd/T5M8=; b=rSk+zRpzYAISaGjYschxvcbpgC8VlULr0vXxT72Hzv1P07BVNnqG4v5Uw6yZb3+UD+ 9pq6F+D6vAtEymL0pmAXW95zKpcs8pK7lIv53Kl1ZXy7PoWtGzHfaPvdCnekYTPi8Gqn lDdzzyP71IkStwX7vU7YYWw4En5xR3cRiN0/1Yfx2n3c6r3ebUOtOzyICCJbcckKEY40 Jlo6QkuDezHpvGOKkXztauadgq1Osrd5eMKCyScEiGwJYTzn9nnnOfhM+DJFo5ifQ2Cp ENhRsqjV3zYBj74SKB4HYyI6wJCKrQCqlmQZGVTl4zaaC5xPeo6ultDOn+MS5aCecYzX /h4g== X-Gm-Message-State: AJcUukc+B7FGvRDVKnUUhLDnSnZc2tpXQefv+Asu9XYJhg3Y7G0KSCbG bbg02uRCEcll8QR6vlkIf3dI4UySXpWLNSRH1PVDvw== X-Received: by 2002:a6b:fe13:: with SMTP id x19mr3606580ioh.294.1547040288779; Wed, 09 Jan 2019 05:24:48 -0800 (PST) MIME-Version: 1.0 References: <20190107233833.GI5544@atomide.com> <20190108155354.GL5544@atomide.com> <20190108213743.GN5544@atomide.com> <20190109014218.GA8363@linaro.org> <20190109111703.GA28605@lenoch> <20190109115824.GA1353@lenoch> In-Reply-To: <20190109115824.GA1353@lenoch> From: Vincent Guittot Date: Wed, 9 Jan 2019 14:24:37 +0100 Message-ID: Subject: Re: Regression in v5.0-rc1 with autosuspend hrtimers To: Ladislav Michl Cc: Tony Lindgren , "Rafael J. Wysocki" , Ulf Hansson , "open list:THERMAL" , linux-kernel , LAK , linux-omap@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 9 Jan 2019 at 12:58, Ladislav Michl wrote: > > On Wed, Jan 09, 2019 at 12:27:57PM +0100, Vincent Guittot wrote: > > On Wed, 9 Jan 2019 at 12:17, Ladislav Michl wrot= e: > > > > > > On Wed, Jan 09, 2019 at 02:42:18AM +0100, Vincent Guittot wrote: > > > > Le Tuesday 08 Jan 2019 =C3=A0 13:37:43 (-0800), Tony Lindgren a =C3= =A9crit : > > > > > * Vincent Guittot [190108 16:42]: > > > > > > On Tue, 8 Jan 2019 at 16:53, Tony Lindgren w= rote: > > > > > > > Hmm so could it be that we now rely on timers that that may > > > > > > > not be capable of waking up the system from idle states with > > > > > > > hrtimer? > > > > > > > > > > > > With nohz and hrtimer enabled, timer relies on hrtimer to gene= rate > > > > > > the tick so you should use the same interrupt. > > > > > > > > > > OK yeah looks like that part is working just fine. > > > > > > > > > > Adding some printks and debugging over ssh, looks like > > > > > omap8250_runtime_resume() gets called just fine based on a wakeir= q, > > > > > but then omap8250_runtime_suspend() runs immediately instead of > > > > > waiting for the three second timeout. > > > > > > > > > > Lowering the autosuspend_delay_ms to 2100 ms makes things work ag= ain. > > > > > Anything higher than 2200 ms seems to somehow time out immediatel= y > > > > > now :) > > > > > > > > This is quite close to the max ns of an int on arm 32bits > > > > > > > > Could you try the patch below ? > > > > > > > > --- > > > > drivers/base/power/runtime.c | 2 +- > > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > > > diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runt= ime.c > > > > index 7062469..44c5c76 100644 > > > > --- a/drivers/base/power/runtime.c > > > > +++ b/drivers/base/power/runtime.c > > > > @@ -141,7 +141,7 @@ u64 pm_runtime_autosuspend_expiration(struct de= vice *dev) > > > > > > > > last_busy =3D READ_ONCE(dev->power.last_busy); > > > > > > > > - expires =3D last_busy + autosuspend_delay * NSEC_PER_MSEC; > > > > + expires =3D last_busy + (u64)(autosuspend_delay) * NSEC_PER_M= SEC; > > > > if (expires <=3D now) > > > > expires =3D 0; /* Already expired. */ > > > > > > Hmm, comment above function states it returns "the expiration time in= jiffies > > > (adjusted to be nonzero)", so there's probably more to fix... > > > > The comment is wrong and should be updated as commit 8234f6734c5d has > > moved on hrtimer and expires is now in raw ns unit > > Yup. Who'll send a patch? Is it worth optimizing as bellow? I'm fine with= doing You can send a patch for updating the comment. > both. Regarding proposal below: - pm_runtime_autosuspend_expiration() returns u64 and not ktime_t - use helper ktime_before/after to compare ktime_t value Using ktime helper function makes the code less readable and the proposal make the function more difficult to read IMHO when you compare expires =3D last_busy + autosuspend_delay * NSEC_PER_MSEC; with expires =3D ktime_add_ns(ms_to_ktime(autosuspend_delay), READ_ONCE(dev->power.last_busy)); or when you compare if (expires <=3D now) with if (ktime_after(now, expires)) And I'm not sure that this will optimize the code at the end Only the replacement of the "goto out" by return 0 would make sense IMO Regards, Vincent > > > > You can also consider change like this (still does not return jiffies= ): > > > diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtim= e.c > > > index 70624695b6d5..c72eaf21a61c 100644 > > > --- a/drivers/base/power/runtime.c > > > +++ b/drivers/base/power/runtime.c > > > @@ -129,23 +129,20 @@ static void pm_runtime_cancel_pending(struct de= vice *dev) > > > u64 pm_runtime_autosuspend_expiration(struct device *dev) > > > { > > > int autosuspend_delay; > > > - u64 last_busy, expires =3D 0; > > > - u64 now =3D ktime_to_ns(ktime_get()); > > > + ktime_t expires; > > > > > > if (!dev->power.use_autosuspend) > > > - goto out; > > > + return 0; > > > > > > autosuspend_delay =3D READ_ONCE(dev->power.autosuspend_delay)= ; > > > if (autosuspend_delay < 0) > > > - goto out; > > > - > > > - last_busy =3D READ_ONCE(dev->power.last_busy); > > > + return 0; > > > > > > - expires =3D last_busy + autosuspend_delay * NSEC_PER_MSEC; > > > - if (expires <=3D now) > > > - expires =3D 0; /* Already expired. */ > > > + expires =3D ktime_add_ns(ms_to_ktime(autosuspend_delay), > > > + READ_ONCE(dev->power.last_busy)); > > > + if (expires <=3D ktime_get()) > > > + return 0; /* Already expired. */ > > > > > > - out: > > > return expires; > > > } > > > EXPORT_SYMBOL_GPL(pm_runtime_autosuspend_expiration); > > > > > > Regards, > > > ladis