Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp5004021pxb; Tue, 5 Oct 2021 15:20:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwoSIbbFln9kZlcwclkNdDnm8PeZHLo37AWuICkQTCNz+2jPDF4iX9XGnVGK3Ex6p0eSulJ X-Received: by 2002:a17:902:b60b:b0:13e:dfc0:139 with SMTP id b11-20020a170902b60b00b0013edfc00139mr6569782pls.80.1633472449745; Tue, 05 Oct 2021 15:20:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633472449; cv=none; d=google.com; s=arc-20160816; b=n8Xm60swg/pj/abrgNsrpa5q4fJIOYTP8NnUuAeEjWZCKz26ZWBeTS2IZbeaYjVqnE WWVdixq6Xr9mJlTXf47tRvbmAdGIavnLlhHBwhGPVRv/qxz3ugjjiTyDZErJ7m7Ia+Od UWSr4Qr3clvJO1U28wZDcGTV1x679VRJzr7z+PUiA1iQkXcOeL6w5naMRlaPm4FboUWp c6FNM95kdCh4EiFdzRJdMTjCNI6Z9ivkBKK/U/YDyn/mOdrCd2i9EnZz3MvKBZ/2Ed8m 5lOoaRjzQdfVGnVOx8lF5gIQ5Pjzi6z1bOhyzPSCblnjr2dOwIgZ2Jstnqjmf33w0Bpt eyeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=cm3t0jHYi60ikbjIFrElH5F3+z5ZebZ+trrzKBFfgQI=; b=ySicyVucnnxGT2oUv6VByuzUeBmGYNozO8UUo01dpfGNlVEfPdC8YEr2DPn0gPSxCD KktRTCSzQmK2EMpt7EGB8wnOvHwDlGX2FRcw7AdJHfcc3FHrIXiIZSyVvdbILsu5bIBe J3ljgAMaUng37Mj64YSUblVYD+q6g8osm4jOuDtdpzRkHTLkubQttiB7Gx05OAw+C9x+ lNrGIoY2cTnfyh0UxY9aAXhEZB8LagjdEA1Zff46ympGqOPIXU8BChdoGDFqw/49UkqP KLUNrKeCILeUEmgarRT+da4ZmI592DTZpI/+cVDg62/Z6jik2M1kplIYTYE1hVWU5hHI +WXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=qTAIEXIV; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lk7si1986154pjb.112.2021.10.05.15.20.36; Tue, 05 Oct 2021 15:20:49 -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=@gmail.com header.s=20210112 header.b=qTAIEXIV; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236738AbhJEWVf (ORCPT + 99 others); Tue, 5 Oct 2021 18:21:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230477AbhJEWVc (ORCPT ); Tue, 5 Oct 2021 18:21:32 -0400 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71EB7C061749; Tue, 5 Oct 2021 15:19:41 -0700 (PDT) Received: by mail-lf1-x12c.google.com with SMTP id u18so1904112lfd.12; Tue, 05 Oct 2021 15:19:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=cm3t0jHYi60ikbjIFrElH5F3+z5ZebZ+trrzKBFfgQI=; b=qTAIEXIVB1/IgtvGdtrN/gmvUv6mTJMWYvN+by7UBNwUQz1edq9ynn5KZ4VakUYvgO zdJ521ZSZKHguY4o7B00h080n6+hpVFgPtipWPhr7vdfUedARgQ4xE4HH2lbru46MeqC A5BXLTY8VINH/AMBjZEF/K2gSikuRXhSI2fF9O8ZK3khdgYy8AFAvm2l22TZw2+cK0Up VqGWxTT463F7ck5TyDg0STieTJ5C+qvpbnUQ5kqq4ulMywcZp+kTXt8lcdefcaH+dgKu zq6l/FilsorGHNG/QzimfNCPZRYUNo7SlGD/xBo5UydUfU+gcPwF7E7ckKKrvoh9klYt Rvdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=cm3t0jHYi60ikbjIFrElH5F3+z5ZebZ+trrzKBFfgQI=; b=6hhnqyt2XuRgMYLBNC2nV0yG8PsZANtBv+Y+ujv3fVytDqGArizH5YtwnLATxAsUJt OkqBwMbf78zRVcV/+qsOokjE5H3F1aeZGzVtXS+pSe1PoQtFgIESne4ZTE+qLvuM/537 Z289c3Z5jopFyyvmvlAzPZe7dkLyna195R2rycn/fFg9FLjF3bN4evkWrl88Ub2T4QNt KA7sENlEZpFF5OvfJWwhjFl/nDzpJ0kMWoys51uuzC5BuPDzs6oSojwX9QtzgH0eBTO0 BDoETraINfqc+1dWTIr2Ii28Uuje+EDoIRhyd1noX9fHWJWCZRzdWE9KvHyAMbmhrUnb ZzFA== X-Gm-Message-State: AOAM533jef9d3xmw1Rrve3XH/J5Rejztw9KP0UV1G8UZAUuJ+QLFjqbi eYdIGCVA+23UkRg6+MwsUe8= X-Received: by 2002:a2e:5cc6:: with SMTP id q189mr24035068ljb.82.1633472379484; Tue, 05 Oct 2021 15:19:39 -0700 (PDT) Received: from [192.168.2.145] (79-139-163-57.dynamic.spd-mgts.ru. [79.139.163.57]) by smtp.googlemail.com with ESMTPSA id d19sm2088024lfv.74.2021.10.05.15.19.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Oct 2021 15:19:39 -0700 (PDT) Subject: Re: [PATCH v13 06/35] clk: tegra: Support runtime PM and power domain To: Ulf Hansson Cc: Thierry Reding , Jonathan Hunter , Viresh Kumar , Stephen Boyd , Peter De Schrijver , Mikko Perttunen , Peter Chen , Lee Jones , =?UTF-8?Q?Uwe_Kleine-K=c3=b6nig?= , Nishanth Menon , Adrian Hunter , Michael Turquette , Linux Kernel Mailing List , linux-tegra , Linux PM , Linux USB List , linux-staging@lists.linux.dev, linux-pwm@vger.kernel.org, linux-mmc , dri-devel , DTML , linux-clk , Mark Brown , Vignesh Raghavendra , Richard Weinberger , Miquel Raynal , Lucas Stach , Stefan Agner , Mauro Carvalho Chehab , David Heidelberg References: <20210926224058.1252-1-digetx@gmail.com> <20210926224058.1252-7-digetx@gmail.com> <24101cd6-d3f5-1e74-db39-145ecd30418b@gmail.com> From: Dmitry Osipenko Message-ID: <4bdba8a2-4b9b-ed7d-e6ca-9218d8200a85@gmail.com> Date: Wed, 6 Oct 2021 01:19:37 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 05.10.2021 16:10, Ulf Hansson пишет: > On Sat, 2 Oct 2021 at 22:44, Dmitry Osipenko wrote: >> >> 01.10.2021 15:32, Ulf Hansson пишет: >>>> +static __maybe_unused int tegra_clock_pm_suspend(struct device *dev) >>>> +{ >>>> + struct tegra_clk_device *clk_dev = dev_get_drvdata(dev); >>>> + >>>> + /* >>>> + * Power management of the clock is entangled with the Tegra PMC >>>> + * GENPD because PMC driver enables/disables clocks for toggling >>>> + * of the PD's on/off state. >>>> + * >>>> + * The PMC GENPD is resumed in NOIRQ phase, before RPM of the clocks >>>> + * becomes available, hence PMC can't use clocks at the early resume >>>> + * phase if RPM is involved. For example when 3d clock is enabled, >>>> + * it may enable the parent PLL clock that needs to be RPM-resumed. >>>> + * >>>> + * Secondly, the PLL clocks may be enabled by the low level suspend >>>> + * code, so we need to assume that PLL is in enabled state during >>>> + * suspend. >>>> + * >>>> + * We will keep PLLs and system clock resumed during suspend time. >>>> + * All PLLs on all SoCs are low power and system clock is always-on, >>>> + * so practically not much is changed here. >>>> + */ >>>> + >>>> + return clk_prepare(clk_dev->hw->clk); >>> I am trying to understand, more exactly, what you intend to achieve >>> with the clk_prepare() here. It looks a bit weird, to me. Can you try >>> to elaborate a bit more on the use case? >> >> The Tegra GENPD driver enable/disable clocks when domain is turned on. > > Okay. I noticed that in tegra_genpd_power_on(). And the same clocks > are enabled/disabled also in tegra_genpd_power_off(), when powering > off the PM domain. > > So I guess the problem kind of exists for tegra_genpd_power_off() too? Both OFF/ON are affected by the same problem. If domain was already turned OFF before genpd_suspend_noirq(), then the OFF problem isn't visible. I reproduced the OFF problem by removing the clk prepare/unprepare from the suspend/resume of the clk driver and making some extra changes to clock tree topology and etc to trigger the problem on Nexus 7. tegra-pmc 7000e400.pmc: failed to turn off PM domain heg: -13 I happens from genpd_suspend_noirq() -> tegra_genpd_power_off() -> clk -> GENPD -> I2C -> runtime-pm. -13 is EACCES, it comes from the runtime PM of I2C device. RPM is prohibited/disabled during late (NOIRQ) suspend by the drivers core. >> This can't be done during early system resume, when domains are getting >> turned on by the drivers core, because when clock is enabled, it's >> getting prepared (RPM-resumed) and this preparation fails because >> performance state of the clock goes up and it doesn't work during the >> early resume time since I2C, which applies the state to hardware, is >> suspended and can't work at that early time. > > This sounds complicated and I still don't quite follow all of it, sorry. > > So, tegra_genpd_power_on() gets called from genpd_resume_noirq(), when > the first device of the attached devices to genpd gets resumed. And > vice versa for tegra_genpd_power_off() and genpd_suspend_noirq(). > > Are you saying that trying to enable/disable clocks from > tegra_genpd_power_on|off() in these paths doesn't work, because it > would also require the performance state to be changed, which would > fail because the I2C bus/driver is suspended? Yes, but it's actually not I2C bus/driver that is suspended, it's runtime PM that is unavailable during NOIRQ. The I2C driver itself is suspended after domains are turned OFF and resumed before they are enabled. It's just runtime PM API that is unavailable. I'm wondering if this could be changed. I'm also wondering if we could add some 'was_enabled' flag to GENPDs, setting it by genpd_suspend_noirq() for the enabled domains, and then powering-on GENPDs from genpd_resume_noirq() only if they were in the enabled state during genpd_suspend_noirq() time. It actually puzzled me for a quite long time why GENPD core enables domains unconditionally during early resume. This should solve a part of the problem and it makes suspend/resume a bit safer because there is a smaller chance to crash hardware during suspend, at least it's easier to debug. >> Secondly, Tegra has arch-specific low level assembly which touches >> clocks during last phase of system suspend and in the beginning of >> resume. Hence, clocks should stay prepared during suspend just because >> technically clock should be prepared before it can be enabled. > > So the low level code is gating and ungating the clock behind the back > of the clock driver then? Why is that done like that, more exactly? I revisited that code again, and it shouldn't touch the clocks. I changed that code to not toggle the clocks [1] sometime ago, but forgot about it. [1] https://git.kernel.org/linus/680ae4452 >>> Is this rather about making sure that the clock's corresponding PM >>> domain stays powered on during system suspend? In that case, I think >>> there may be an alternative option.... >>> >> >> This is not about domain staying powered on, this is about keeping the >> performance state of the domain high during suspend. > > Right, so the PM domain managed in tegra_genpd_power_on|off() can > still be powered on/off, as long as the clock remains ungated? Not ungated, but prepared.