Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2594307ybz; Sun, 3 May 2020 04:50:03 -0700 (PDT) X-Google-Smtp-Source: APiQypLWvttLceENA/uFdux51TfCXEEYh8eCxsSfl/Pbfw5oH6il1bWfeXEdile1c5s1OPPoo6bT X-Received: by 2002:a50:b961:: with SMTP id m88mr10723772ede.4.1588506602927; Sun, 03 May 2020 04:50:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588506602; cv=none; d=google.com; s=arc-20160816; b=vfasVSRtssHfrK1ufZuZd7BO7Bk2lnG9uY5zM+mxgC7m12/Th9lx+4fUzhh4Tp8MqC Q7kYHpAXKJs0fiu9Zb3GJCwLnPyKiYUUKSRHSuUCqiGDhW1463uGTnIrkl6V1RQUpbTQ mEmK7p2TTH8eOi6qSMolZ0JRQwTEy+WeWCPV+FmjS8gIw6azKdHr4TUu+uiNgner1DR6 pEi5yYmf+t1IRfR0WnUDdt/juStjNyXJ6wEljOnwYSEeKiBdBkMHi8dx67UcNXFQTT56 Mli3r5/SlEXFk8CNlJVB70w3kVYrSV2PcsMzUX47d5gngP2Hhq4+HZAKOYpjttmXhI91 s7Dg== 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:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=RFbyk7hxwFadjGYzGUaz/TDl+vZR22gWb9SA4D2PIOI=; b=P2bzSvIcdSbMp33QKESh/kxhlf8hrMg3zMA2zPA8R1LMyD9G4+WV927MERYih/bzcI /2e98/s63qmUFAqG6zhD1/p2OjKHzAoYCP3slv7VUZgBtkLNFXc8XD/DjHAzH1bA3haw 6m0WaRgdQGTifpJTQAusRtX+68+dMyA9sFA835PB6O67kh2pQ4WgUyofeodO3m0H1iwU FVuwBPy32PfWgzhM0L9BCRC43V6wnZCwP3BWM2WW8kaXpgqtsOMQbhaEfMGa5C+SHwYy UdhGD4uUukYvJt6bYv5w5JfL4W4HUOj4NIcA8vw6HcqzTIGqE8qMleUEHb+hmykmhUQM hjLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="YTJEQ3/O"; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y25si490471edv.153.2020.05.03.04.49.39; Sun, 03 May 2020 04:50:02 -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=@kernel.org header.s=default header.b="YTJEQ3/O"; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727819AbgECLsR (ORCPT + 99 others); Sun, 3 May 2020 07:48:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:41156 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727091AbgECLsR (ORCPT ); Sun, 3 May 2020 07:48:17 -0400 Received: from archlinux (cpc149474-cmbg20-2-0-cust94.5-4.cable.virginm.net [82.4.196.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AABF22071C; Sun, 3 May 2020 11:48:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588506496; bh=MjIriiKXwBhuy3vRVQshwzttKeQfN8gHwz12BeKmiyQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=YTJEQ3/OjiyY9cpQSweNqt7J1FtAJdP0BBQjtgz2enfFFunpuoUqiE1KIGeYipLku gKjQ6tjRBCgT02PERAu+p5HLfeBNobOvP8PivfyKYhZjwmlSvHLFXpjqJHZPFw4L/q uA2HBRbJjFtwoo9sxXF09GsbykqLUcFYRgPMSgP4= Date: Sun, 3 May 2020 12:48:11 +0100 From: Jonathan Cameron To: Fabrice Gasnier Cc: , , , , , , , , , Subject: Re: [PATCH v2] iio: adc: stm32-adc: fix runtime autosuspend delay when slow polling Message-ID: <20200503124811.0abf7655@archlinux> In-Reply-To: <1588163348-31640-1-git-send-email-fabrice.gasnier@st.com> References: <1588163348-31640-1-git-send-email-fabrice.gasnier@st.com> X-Mailer: Claws Mail 3.17.5 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 29 Apr 2020 14:29:08 +0200 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 Whilst this seems 'sensible' to me, I really don't have a good enough grasp of runtime pm to be sure. I see something similar looking in the greybus driver, but not sure on the reason it is there. Hence, ideally looking for an ack from Rafael on this one! Thanks, Jonathan > --- > 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. > --- > 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 2df88d2..ebe5dbc 100644 > --- a/drivers/iio/adc/stm32-adc-core.c > +++ b/drivers/iio/adc/stm32-adc-core.c > @@ -803,6 +803,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 = { > @@ -810,7 +817,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 = {