Received: by 10.223.176.5 with SMTP id f5csp647697wra; Fri, 2 Feb 2018 03:56:46 -0800 (PST) X-Google-Smtp-Source: AH8x224vsxgf9cduMZ9tCOwUWFOhn2m/nSqeELMOtleIgfMkVhU4aJI/eS5mg+000DkaIPo9l6XW X-Received: by 10.99.112.25 with SMTP id l25mr31301441pgc.154.1517572606428; Fri, 02 Feb 2018 03:56:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517572606; cv=none; d=google.com; s=arc-20160816; b=rDbm/4vNomPwLB6ykAkWZbdYzc8be69f4eiinhle+exSltOnxlSQDAd488kbxVEVnk VlMR6Hj5p0V3zYNr5/ZP6bVL+XFIn7zM9jclmSpossMGgu6fHr2XTco2TSEMLI/JqAan trH+ya9H3WAoNU3FdjA9Qbs2Kjyt3FNySJP3x6WPWlg+FxvgxeDEInPB/xxEjs8GSdDM hixNon4Mk0SteEPz0z4fcDfLhj98yDFTTyV/eQOaZRbpCnRbuwvFc1r+Xhyf8aXJVJJZ h7FUVPDkcmuwqUje2kPSCygdF+jHbeOJKxPf+TrbsyevfuR+2So+iS7Slpvb3q/oSe7o 16KQ== 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:date:subject:cc:to:from :arc-authentication-results; bh=Uh4NMlTCBu5t/PsTWikHecwELPmEauIHNHOpWkDI8Js=; b=BsXx6sfFDZ+PjLzAY0IDqM6F3BS06iDTj6YCASdmT/1j6m48mrXG2TBSgZDgQdEn4/ H2QlgBrLxRiMAFLGcgt6P/v0gBMQWpatlHz2u0y2UhszOSX0+XSPaOFzYmdvwkuXPbpB 2Y6x+kKYsoudiXjBWIGFdKCg6yMncOParXjM0yP6iZZDhK3PT1+1spa9dTGtFWEyZUnX LpIusIjNUAfQ8okpQboD4wmw1uzaomz6OPopQgFxSGy96omALurvqpsvUZp0T6I47gqz uWYfH9NiBuYgHEqUt6DjfZZxpNga29vAs05IZBQ5KDJQnrsvXD5rdnuUhZ3UsaESdS7I JKlw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h20si1326412pgv.636.2018.02.02.03.56.31; Fri, 02 Feb 2018 03:56:46 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751649AbeBBL4A (ORCPT + 99 others); Fri, 2 Feb 2018 06:56:00 -0500 Received: from cloudserver094114.home.pl ([79.96.170.134]:42475 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750773AbeBBLzy (ORCPT ); Fri, 2 Feb 2018 06:55:54 -0500 Received: from 79.184.255.223.ipv4.supernova.orange.pl (79.184.255.223) (HELO aspire.rjw.lan) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.82) id c7688f07e04f4886; Fri, 2 Feb 2018 12:55:53 +0100 From: "Rafael J. Wysocki" To: Bo Yan Cc: viresh.kumar@linaro.org, sgurrappadi@nvidia.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] cpufreq: skip cpufreq resume if it's not suspended Date: Fri, 02 Feb 2018 12:54:17 +0100 Message-ID: <17447147.z6jfkRxuEB@aspire.rjw.lan> In-Reply-To: <913f1715-bdd0-1c03-ad76-38be9d3d2298@nvidia.com> References: <1516744675-21233-1-git-send-email-byan@nvidia.com> <1744712.rO4QOLozun@aspire.rjw.lan> <913f1715-bdd0-1c03-ad76-38be9d3d2298@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wednesday, January 24, 2018 9:53:14 PM CET Bo Yan wrote: > > On 01/23/2018 06:02 PM, Rafael J. Wysocki wrote: > > On Tuesday, January 23, 2018 10:57:55 PM CET Bo Yan wrote: > >> drivers/cpufreq/cpufreq.c | 4 ++++ > >> 1 file changed, 4 insertions(+) > >> > >> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c > >> index 41d148af7748..95b1c4afe14e 100644 > >> --- a/drivers/cpufreq/cpufreq.c > >> +++ b/drivers/cpufreq/cpufreq.c > >> @@ -1680,6 +1680,10 @@ void cpufreq_resume(void) > >> if (!cpufreq_driver) > >> return; > >> > >> + if (unlikely(!cpufreq_suspended)) { > >> + pr_warn("%s: resume after failing suspend\n", __func__); > >> + return; > >> + } > >> cpufreq_suspended = false; > >> > >> if (!has_target() && !cpufreq_driver->resume) > >> > > Good catch, but rather than doing this it would be better to avoid > > calling cpufreq_resume() at all if cpufreq_suspend() has not been called. > Yes, I thought about that, but there is no good way to skip over it > without introducing another flag. cpufreq_resume is called by > dpm_resume, cpufreq_suspend is called by dpm_suspend. In the failure > case, dpm_resume is called, but dpm_suspend is not. So on a higher level > it's already unbalanced. > > One possibility is to rely on the pm_transition flag. So something like: > > > diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c > index dc259d20c967..8469e6fc2b2c 100644 > --- a/drivers/base/power/main.c > +++ b/drivers/base/power/main.c > @@ -842,6 +842,7 @@ static void async_resume(void *data, async_cookie_t > cookie) > void dpm_resume(pm_message_t state) > { > struct device *dev; > + bool suspended = (pm_transition.event != PM_EVENT_ON); > ktime_t starttime = ktime_get(); > > trace_suspend_resume(TPS("dpm_resume"), state.event, true); > @@ -885,7 +886,8 @@ void dpm_resume(pm_message_t state) > async_synchronize_full(); > dpm_show_time(starttime, state, NULL); > > - cpufreq_resume(); > + if (likely(suspended)) > + cpufreq_resume(); > trace_suspend_resume(TPS("dpm_resume"), state.event, false); > } I was thinking about something else. Anyway, I think your original patch is OK too, but without printing the message. Just combine the cpufreq_suspended check with the cpufreq_driver one and the unlikely() thing is not necessary. Thanks, Rafael