Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2826719ybl; Sun, 2 Feb 2020 07:35:59 -0800 (PST) X-Google-Smtp-Source: APXvYqxQa19hHvPCeJZGTLCP7rEzl37JEMQFFVZ4hKi9JEMnRrYkfASXJDguGmbjWOD5lYzRCi32 X-Received: by 2002:a05:6830:160c:: with SMTP id g12mr14255867otr.82.1580657758895; Sun, 02 Feb 2020 07:35:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580657758; cv=none; d=google.com; s=arc-20160816; b=roczxQCUCMtO8tbY9KDRi71f2owf6GoVP3xb9fl33rfvyj9BtGCJla+lnylkkm8Nek W/+YaIyNa5pAn0JLEzmpq58r+SmDzuX0GRq+n6Ft+eyuT8XxyJZdhC0uTCZeqNydaw8w 2OGxVgsWbUgX+kAXTRu9b3XXBcSOWeNJ2RGXrZZJ6SY7d3BIvye7JtIGFeFR8JgWXRWL HBL7Oj9jodP8TCxmB39N4MVgvTM3EnxYSbuGCj40k4zjTVX/0Mvf9r8pRNDjkNsCVtc6 xr8snj+PCzpAb5IwPs7dbCY7u9mIYHfogzNychS4bT7ZuSLLRqU9k4mEFrPLcsV/wKfj Z7aA== 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=EqURIQJivYOL8CCgCiqDm7eBx4ZVIE8ci4bjDAnQlY8=; b=HUQP1HZwbE0tOdOxoC1qZqrdWvyGNgjwo1ZPeuGgFP3POKauRRc6Zv2V1RAoiPLe2f U3DT1AJQDK5qV7d9LTzoKNhmUfpHHJ9K91jkPH7IUlEQR1z2A/0uCwMlqxsO8SqgwZ4c TzaxFtdgd6tD2Xr2Rx5J8IrF0cl7tANIotdmjNpsLtz6dBQJpLja3YMRjX83SMlWqWXA yzHc/y8+gt1KEOt5sRMF8F7bKOIPaa44oFCd/4+5g9tLfMKXQdWeb9px/+QKMuxPls6z vAhUClDjcgybn+k0zQXjKTOSJw5YMpOI4/PSiEFDYBMQj9Tk9bDj3Q6gMOqpQNSOyDKa Ujww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="u/IMqBLo"; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w2si7687968otq.31.2020.02.02.07.35.46; Sun, 02 Feb 2020 07:35:58 -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=@kernel.org header.s=default header.b="u/IMqBLo"; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726947AbgBBPeB (ORCPT + 99 others); Sun, 2 Feb 2020 10:34:01 -0500 Received: from mail.kernel.org ([198.145.29.99]:48340 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726880AbgBBPeA (ORCPT ); Sun, 2 Feb 2020 10:34:00 -0500 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 AB2DB20643; Sun, 2 Feb 2020 15:33:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580657639; bh=NQdIkCaHC++sdUz8EJtM4E6FaGmhFs3epc/t8aDK9gE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=u/IMqBLoMM+bIHEdv7B/M0xS8LMvVgqbwg5T3uMqLP/gV7D6krxtIepaW7pSKfkHj LDZFqStqTQOJZ6fzM75yGQEfK1xax25a/hc7KTOb43dRXo0KVtwiEnMBKhAW/KG11Z 6k/3a/nHXjwoWQiDn6KTwEly4ElCCfTKoemRjoNs= Date: Sun, 2 Feb 2020 15:33:54 +0000 From: Jonathan Cameron To: Fabrice Gasnier Cc: , , , , , , , , , , "Rafael J. Wysocki" , linux-pm@vger.kernel.org Subject: Re: [PATCH] iio: adc: stm32-adc: fix runtime autosuspend delay when slow polling Message-ID: <20200202153354.3dae5863@archlinux> In-Reply-To: <1579854369-7972-1-git-send-email-fabrice.gasnier@st.com> References: <1579854369-7972-1-git-send-email-fabrice.gasnier@st.com> X-Mailer: Claws Mail 3.17.4 (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 Fri, 24 Jan 2020 09:26:09 +0100 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, add an explicit call to pm_runtime_mark_last_busy() for the parent > driver (stm32-adc-core), synchronously with the child driver (stm32-adc), > to avoid this. > > Fixes: 9bdbb1139ca1 ("iio: adc: stm32-adc: add power management support") > > Signed-off-by: Fabrice Gasnier Hi Fabrice, Whilst this will clearly work, it seems like a somewhat adhoc solution. Power management specialists (cc'd): Is this what we should be doing, or have Fabrice and I both missed something that we should be doing here? Thanks, Jonathan > --- > drivers/iio/adc/stm32-adc.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c > index 3b291d7..670157e 100644 > --- a/drivers/iio/adc/stm32-adc.c > +++ b/drivers/iio/adc/stm32-adc.c > @@ -1157,6 +1157,7 @@ static int stm32_adc_single_conv(struct iio_dev *indio_dev, > > stm32_adc_conv_irq_disable(adc); > > + pm_runtime_mark_last_busy(dev->parent); > pm_runtime_mark_last_busy(dev); > pm_runtime_put_autosuspend(dev); > > @@ -1278,6 +1279,7 @@ static int stm32_adc_update_scan_mode(struct iio_dev *indio_dev, > adc->num_conv = bitmap_weight(scan_mask, indio_dev->masklength); > > ret = stm32_adc_conf_scan_seq(indio_dev, scan_mask); > + pm_runtime_mark_last_busy(dev->parent); > pm_runtime_mark_last_busy(dev); > pm_runtime_put_autosuspend(dev); > > @@ -1329,6 +1331,7 @@ static int stm32_adc_debugfs_reg_access(struct iio_dev *indio_dev, > else > *readval = stm32_adc_readl(adc, reg); > > + pm_runtime_mark_last_busy(dev->parent); > pm_runtime_mark_last_busy(dev); > pm_runtime_put_autosuspend(dev); > > @@ -1451,6 +1454,7 @@ static int __stm32_adc_buffer_postenable(struct iio_dev *indio_dev) > err_clr_trig: > stm32_adc_set_trig(indio_dev, NULL); > err_pm_put: > + pm_runtime_mark_last_busy(dev->parent); > pm_runtime_mark_last_busy(dev); > pm_runtime_put_autosuspend(dev); > > @@ -1487,6 +1491,7 @@ static void __stm32_adc_buffer_predisable(struct iio_dev *indio_dev) > if (stm32_adc_set_trig(indio_dev, NULL)) > dev_err(&indio_dev->dev, "Can't clear trigger\n"); > > + pm_runtime_mark_last_busy(dev->parent); > pm_runtime_mark_last_busy(dev); > pm_runtime_put_autosuspend(dev); > } > @@ -1874,6 +1879,7 @@ static int stm32_adc_probe(struct platform_device *pdev) > goto err_hw_stop; > } > > + pm_runtime_mark_last_busy(dev->parent); > pm_runtime_mark_last_busy(dev); > pm_runtime_put_autosuspend(dev); >