Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2938829pxk; Mon, 28 Sep 2020 04:27:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzM6BFEJ8Yv2MEx0giT2Iloj3e0FbV2PWHgWB+zBlGTYXnxlcNqDxN5b30FCCz7uUETW8jy X-Received: by 2002:a17:906:341a:: with SMTP id c26mr1186762ejb.96.1601292423797; Mon, 28 Sep 2020 04:27:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601292423; cv=none; d=google.com; s=arc-20160816; b=NyjFrkqx8QffTq1cW74g5ya+h/owtSpJ+RvEb9eDyfLrlgRoV8x7dJZnzQez8Au6TV r4ODDzhxUsFgWqk7nxpAlKMXl3aFLZFWDFhFuvaZemXlNAsA00DCiH5rb7Ov5b0zTDla uAEQMMQOQBMw8jV14sbV0+6kEVu3K6Y/wRDwxN4DDjyKlxrxerNDgqYKKh5zIQzGZ52i Rdr7yshmHWD1kGj8HO2Nrmk+IhaSZqLuK9Dl5ayI5LP5kKjeN+NpyAUTNnxDutOgQAbv SUN7CzBtnQSrEUqwqUzQRqpgaEynGniMjutcdrEchQi4LrdRow391JTzjNIBH3peqWIu Ntdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=dPqyhHPvAKE8oFtG0HXSnceWMN8F9MOf0pO61krCb1Y=; b=O+wZevuSrLWuSbc4CYPwlYLYCGIOmEjNyZ4OCkn2uP7dWqe0ezVmIHRQ8yiaRnb4Or Z8x9hzW5gypL4tlJaGe+2brVbIE5PUg9NDbw/9zUCJnWtLle/fiq1ePOmOEAclhhe6ZT iQ9ia3GAHoHg6HrHq2DneLqD4jLTqT0M12sj6n5NYsnvbd7F7u6FrPs4uPx1uwRMoe3q U0l2ZnmuxPFSQ7fkrR9JPRRheCoyHFFKImAsHZ4B7RgbLQfUnCbRwJyq3xf9hHj0fzlb bRcgc+SOaCxi8ZFOHnLKpuSfNYgVKkG6Pyv8T1+V2neE+AM4zs91t5P2x/FmJSZd9ULh h5WA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mFX2vgIw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id rv15si412048ejb.364.2020.09.28.04.26.41; Mon, 28 Sep 2020 04:27:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mFX2vgIw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726578AbgI1LXs (ORCPT + 99 others); Mon, 28 Sep 2020 07:23:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726465AbgI1LXs (ORCPT ); Mon, 28 Sep 2020 07:23:48 -0400 Received: from mail-ua1-x942.google.com (mail-ua1-x942.google.com [IPv6:2607:f8b0:4864:20::942]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BF8DC061755 for ; Mon, 28 Sep 2020 04:23:48 -0700 (PDT) Received: by mail-ua1-x942.google.com with SMTP id z1so2053587uaa.6 for ; Mon, 28 Sep 2020 04:23:48 -0700 (PDT) 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; bh=dPqyhHPvAKE8oFtG0HXSnceWMN8F9MOf0pO61krCb1Y=; b=mFX2vgIw/ymy13Qjh/G7aVRGOACw1Fj/ADWUfGlozDS641eSx1hWEkFSVu1esESKHB UgvUnxWEKkoyXHt2GQppOniC5F2M/aHpw+xrsCU17sCP31b/bVtTvUtUzBMuGtkJyCO4 9ZwaDtusG19u99CaKHkXc2xtSJnn8TFODC2YHyQo3Z6gziYVZkXmQ4vBrgNUIxjbZI4+ t97q6KS543YUmghrGRJDlHkbJ4o8HddYlWvtYRck7UAj/HYKrCGi+iChzCywW1I8gS0w T3Td0+hsZFLVw3kRqLj32n4oOnePgk7isZFeo5d404mzKKfz0KTHG0yUSnbck3JeA8cf UNmw== 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; bh=dPqyhHPvAKE8oFtG0HXSnceWMN8F9MOf0pO61krCb1Y=; b=fywQAjsVAusOK9Eu/QsoDIJW3xjSreBleS2MDsLborT+/DN3PQs84OqDRaQjZSrdUu S96CCJHOpD+8fX26EsgQPKzCyslUTdaDZ2NsIrSxuPxFTGR19c+VQ3r9l5qQOF9yUUWy iiulmgosqdMkx/7dlKIOipIvHOXaY28NzInGP72GnsnkM/oBYeKtDoa96TDLvHV+mN5B y5M5zj3goDm2TcuR/S0a5uHDeHuzB2LT1GbD5gporH2Umct3akVSO8h3f0GZYAAmFvhb 1m1S4cClhANWTiGqetiYr75y7FQSHAqQqNWtD9mnbkFthWR80wWsZILwQGD2rPHfHBXX C46A== X-Gm-Message-State: AOAM532TaAa0ngJoY9u9876XqLCEN+nUwKXOgke65Kc53ekgKZ81yKRM YGJ2isfyDEpmK+EXL/D1Fgs51I5WVhC2fp7dTRsO/Q== X-Received: by 2002:ab0:2904:: with SMTP id v4mr312369uap.15.1601292227436; Mon, 28 Sep 2020 04:23:47 -0700 (PDT) MIME-Version: 1.0 References: <1593615328-5180-1-git-send-email-fabrice.gasnier@st.com> <045e9e34-f1e0-087b-bc5b-44440db6be27@st.com> <20200926161732.72af96e3@archlinux> In-Reply-To: <20200926161732.72af96e3@archlinux> From: Ulf Hansson Date: Mon, 28 Sep 2020 13:23:11 +0200 Message-ID: Subject: Re: [RESEND PATCH v2] iio: adc: stm32-adc: fix runtime autosuspend delay when slow polling To: Jonathan Cameron , Fabrice Gasnier Cc: "Rafael J. Wysocki" , "Rafael J. Wysocki" , Linux ARM , Linux Kernel Mailing List , Maxime Coquelin , Alexandre Torgue , olivier.moysan@st.com, linux-iio@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Jonathan, Fabrice, On Sat, 26 Sep 2020 at 17:17, Jonathan Cameron wrote: > > On Wed, 16 Sep 2020 12:28:00 +0200 > Fabrice Gasnier wrote: > > > On 7/1/20 4:55 PM, Fabrice Gasnier wrote: > > > When the ADC is runtime suspended and starting a conversion, the stm32-adc > > > driver calls pm_runtime_get_sync() that gets cascaded to the parent > > > (e.g. runtime resume of stm32-adc-core driver). This also kicks the > > > autosuspend delay (e.g. 2s) of the parent. > > > Once the ADC is active, calling pm_runtime_get_sync() again (upon a new > > > capture) won't kick the autosuspend delay for the parent (stm32-adc-core > > > driver) as already active. > > > > > > Currently, this makes the stm32-adc-core driver go in suspend state > > > every 2s when doing slow polling. As an example, doing a capture, e.g. > > > cat in_voltageY_raw at a 0.2s rate, the auto suspend delay for the parent > > > isn't refreshed. Once it expires, the parent immediately falls into > > > runtime suspended state, in between two captures, as soon as the child > > > driver falls into runtime suspend state: > > > - e.g. after 2s, + child calls pm_runtime_put_autosuspend() + 100ms > > > autosuspend delay of the child. > > > - stm32-adc-core switches off regulators, clocks and so on. > > > - They get switched on back again 100ms later in this example (at 2.2s). > > > > > > So, use runtime_idle() callback in stm32-adc-core driver to call > > > pm_runtime_mark_last_busy() for the parent driver (stm32-adc-core), > > > to avoid this. > > > > > > Fixes: 9bdbb1139ca1 ("iio: adc: stm32-adc: add power management support") > > > > > > Signed-off-by: Fabrice Gasnier > > > --- > > > Changes in v2: > > > - Use runtime_idle callback in stm32-adc-core driver, instead of refreshing > > > last_busy from the child (for the parent) at many place. Initial patch v1 > > > looked like "somewhat adhoc solution" as commented by Jonathan. > > > > Hi all, > > > > Gentle reminder for this patch. Earlier discussions on it were as per > > [1] and [2]. > > > > Ideally, Jonathan was looking for an ack from Rafael on this patch. > > This is a long pending issue. I'd like to progress on this. > > > > [1] https://patchwork.kernel.org/patch/11349841/ > > [2] https://lkml.org/lkml/2020/6/11/279 > > Fabrice, I think this one has sat waiting for inputs for > too long. Hence I'm going to take a slight gamble that you are correct > on doing the fix this way (I'm reasonably convinced) My apologies for the huge and unacceptable delay. I have re-started looking at this several times, but just never got the point of writing a proper reply. Let me do this now, better late than never I guess. In general, I think this problem (nicely described by Fabrice), should be solved in the runtime PM core, without having to involve drivers for parents/childs. I have looked into that, but I don't have a patch to propose, at least not yet. FYI, I have also stumbled over the same problem, for a card controller (parent), serving both sd and memstick cards. For that case, we simply decided to skip using autosuspend for the child devices (represented by an sd host and a memstick host), not optimal, but there were other reasons why we decided for this approach as well. That said, I also think the solution proposed in $subject patch, which uses the ->runtime_idle() callback for the parent is perfectly fine, at least until we have figured out something that can replace it. > > Applied to the fixes-togreg branch of iio.git. > It won't go in for 5.9 now, so we have a bit of time for any last > minute comments. Feel free to add: Reviewed-by: Ulf Hansson Kind regards Uffe > > Thanks, > > Jonathan > > > > > Please advise, > > Thanks in advance, > > Fabrice > > > > > --- > > > drivers/iio/adc/stm32-adc-core.c | 9 ++++++++- > > > 1 file changed, 8 insertions(+), 1 deletion(-) > > > > > > diff --git a/drivers/iio/adc/stm32-adc-core.c b/drivers/iio/adc/stm32-adc-core.c > > > index 0e2068e..3586369 100644 > > > --- a/drivers/iio/adc/stm32-adc-core.c > > > +++ b/drivers/iio/adc/stm32-adc-core.c > > > @@ -794,6 +794,13 @@ static int stm32_adc_core_runtime_resume(struct device *dev) > > > { > > > return stm32_adc_core_hw_start(dev); > > > } > > > + > > > +static int stm32_adc_core_runtime_idle(struct device *dev) > > > +{ > > > + pm_runtime_mark_last_busy(dev); > > > + > > > + return 0; > > > +} > > > #endif > > > > > > static const struct dev_pm_ops stm32_adc_core_pm_ops = { > > > @@ -801,7 +808,7 @@ static const struct dev_pm_ops stm32_adc_core_pm_ops = { > > > pm_runtime_force_resume) > > > SET_RUNTIME_PM_OPS(stm32_adc_core_runtime_suspend, > > > stm32_adc_core_runtime_resume, > > > - NULL) > > > + stm32_adc_core_runtime_idle) > > > }; > > > > > > static const struct stm32_adc_priv_cfg stm32f4_adc_priv_cfg = { > > > >