Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp776004imu; Wed, 9 Jan 2019 06:14:55 -0800 (PST) X-Google-Smtp-Source: ALg8bN65i+7uCQlJixrHIVzc/PPGvZ+dV0DArWZ8UEpx8eCoKbQzkKpU6PUy3lmY33MNoSRhiao9 X-Received: by 2002:a63:c503:: with SMTP id f3mr5365872pgd.431.1547043295308; Wed, 09 Jan 2019 06:14:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547043295; cv=none; d=google.com; s=arc-20160816; b=kl2fqD8K2fcBVN+vPLSqKqvzQ0OrHD3z7jOQYaBbahFnpmfvpQ2cteoFTybaKVf1Gr aa/dSb4HImMoPeURJt6/hr8R8lvmHWDvTGAz562DcH5N4tydgCIMFzJO/IK+uFpyrCRF J8fOW5SEg9P2y8zFArYVQa1fYHKUQVfAEMLnRjgAT48AhKPPtA1GUOHhT09FJ+W4ajjZ WAzcQd1s9mGRnA99y5TgpzelVV9M9Lsc90biRrOjbNOz/iizbmbk11iWNNnkol4cl4Ku Lx3rPLZC4+hh86EZCB2gtoZ0byyz8vlp+MhA8L7m5NZrnsHP88EoYpbmide6pwj1fgyy 4KLw== 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=0nl716eAE7GZXTIOr6MtAR6wxSXrMDpGuwhYZIWFNu8=; b=EOjLAmwlYxgpD4HJfzsuyMab6MAXio8qP3Trnk6e8VQ3kZAqAc0uviyL0W+jbWxdOR cvw0Er8l0HhCXZO/FoMcZayoHUCNSlcpP0z2eJv4iJVSoXnTk9M4RNYFBltJN53TxRFv Xt0c1lxr8USeIr1AXJ+MUjk9EnUDOJ3riNCY8dCdsY7s8sRuSGU3qAe0Iacu5jPV3vlS IAFrUD3F0xUbOtzypi8y2aT1tKvWU//DrDYX1rcLitg4bn51gV3Jqb8ijHVez4n8R8ql 9SmEQgK/YjKUgRYEuMH+1N/ytSIblpQn+AnstRLelE3QuEWeIZEVYiOAmjwWOUBadHkd geMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kYVIK8PW; 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 bc3si2844047plb.130.2019.01.09.06.14.39; Wed, 09 Jan 2019 06:14:55 -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=kYVIK8PW; 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 S1731277AbfAIOMi (ORCPT + 99 others); Wed, 9 Jan 2019 09:12:38 -0500 Received: from mail-io1-f67.google.com ([209.85.166.67]:34216 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731154AbfAIOMi (ORCPT ); Wed, 9 Jan 2019 09:12:38 -0500 Received: by mail-io1-f67.google.com with SMTP id b16so6132799ior.1 for ; Wed, 09 Jan 2019 06:12:37 -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=0nl716eAE7GZXTIOr6MtAR6wxSXrMDpGuwhYZIWFNu8=; b=kYVIK8PWEFIVLns5XbgfzNM29cEgjEiyFDGvuS68M0A1aoZ0c6QVSmCD797y4IJwE8 1+0Z/wVipeWfWPyqZ8Vap/wXRBYqcZSnoG/7SgnmbOD0/aY4qVc0iP0IyE4P6/5cvTe8 W5uTeRLjjCPlAcmD0bPhUwGgamwAfLggmo4wI= 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=0nl716eAE7GZXTIOr6MtAR6wxSXrMDpGuwhYZIWFNu8=; b=TE904xgLcqZY76AEUcEB81DZrfjFN64rNZ1n9hdzooUSax4xpD2A0z+nSLz09gAysM Sz6PDIFFa9fqWzRdz+iT+XPya9CwekYZgdpiKtlFpOCbKPTG3RiUsI5vo/jYQro6VkJo EwhH8XHVk1WKr6Svw8wuwlykVgtck3bVKfengLaAnbqe9j8IO2adTL5eULYV0y+A6oyO oYnf2yj0tCkB4rvKVCUqNroSF1Y4V4O0DFm3MxzG2TpV4QLgNruBxDb0R23M2xUqAUaP sYT6xi0LYD4ol03AG8XBYppiZhPWDOzSqNx4wYt8Dw9vN2OiVRNTI6bePMi5TVBa/hfz t5VQ== X-Gm-Message-State: AJcUukcNmU6KRtns+pYxU24D3NWBJsdg04sdNUWWyHS4RNeN0zVZlJCJ JWty5osOKJ//GINEMGw/DFFb8SeIWWFZd48psfj7qQ== X-Received: by 2002:a6b:6b02:: with SMTP id g2mr3774737ioc.18.1547043156498; Wed, 09 Jan 2019 06:12:36 -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> <20190109133337.GA13579@lenoch> In-Reply-To: <20190109133337.GA13579@lenoch> From: Vincent Guittot Date: Wed, 9 Jan 2019 15:12:25 +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 Please keep all thread list when replying :-) On Wed, 9 Jan 2019 at 14:33, Ladislav Michl wrote: > > On Wed, Jan 09, 2019 at 02:24:37PM +0100, Vincent Guittot wrote: > > On Wed, 9 Jan 2019 at 12:58, Ladislav Michl wrot= e: > > > > > > On Wed, Jan 09, 2019 at 12:27:57PM +0100, Vincent Guittot wrote: > > > > On Wed, 9 Jan 2019 at 12:17, Ladislav Michl = wrote: > > > > > > > > > > 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 wrote: > > > > > > > > > Hmm so could it be that we now rely on timers that that m= ay > > > > > > > > > not be capable of waking up the system from idle states w= ith > > > > > > > > > hrtimer? > > > > > > > > > > > > > > > > With nohz and hrtimer enabled, timer relies on hrtimer to = generate > > > > > > > > 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 wa= keirq, > > > > > > > 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 wor= k again. > > > > > > > Anything higher than 2200 ms seems to somehow time out immedi= ately > > > > > > > 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/= runtime.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(struc= t device *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_P= ER_MSEC; > > > > > > if (expires <=3D now) > > > > > > expires =3D 0; /* Already expired. */ > > > > > > > > > > Hmm, comment above function states it returns "the expiration tim= e in jiffies > > > > > (adjusted to be nonzero)", so there's probably more to fix... > > > > > > > > The comment is wrong and should be updated as commit 8234f6734c5d h= as > > > > 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 > > Well, that's matter of adding ktime_to_ns (which is noop). > > > - use helper ktime_before/after to compare ktime_t value > > > > Using ktime helper function makes the code less readable and the > > That why I avoided it. But you must use helper function if you use ktime_t That's one main reason for using u64 instead of ktime_t > > > 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)); > > I agree, but it doea all the magic correctly, so you won't need > to touch that code is ktime_t changes (I know, unlikely..) But the current implementation doesn't care of any changes in ktime_t as it uses raw ns > > > 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 > > Checked generated code on ARM and x86 and gcc does pretty good job here. > > > Only the replacement of the "goto out" by return 0 would make sense IMO > > Well, main concern was not to call ktime_get at the beginning of function > as it is not too cheap. Doesn't the compiler optimize that to just before the test ? > > > Regards, > > Vincent > > > > > > > > > > You can also consider change like this (still does not return jif= fies): > > > > > diff --git a/drivers/base/power/runtime.c b/drivers/base/power/ru= ntime.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(struc= t device *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_de= lay); > > > > > 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