Received: by 10.223.176.5 with SMTP id f5csp705925wra; Fri, 2 Feb 2018 04:55:15 -0800 (PST) X-Google-Smtp-Source: AH8x227YxcFxD9SkjAzOMhhwGRvZVk98ILZOeOWfZeGXgdhtzLX9WGSd+vgshIHpSZrI/nGPtKbz X-Received: by 10.99.60.86 with SMTP id i22mr4333860pgn.399.1517576114862; Fri, 02 Feb 2018 04:55:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517576114; cv=none; d=google.com; s=arc-20160816; b=OBAlC1q1h2BmkTxuoqhn4nnCoiFQjY7dluITdU2xpioNpzAIcxtBSdzdnY1rg3Ue8x FBOuEf1xIOHexwkdnVOF8iIq4JL+N65zFZrzejwh2Pv2X08uhLfXDQQZjhFLfCa3PVWb ems+aFuoOSKa9v6YIIQKhKp/juX6D/3HxIhT2/0h3YEZrd+pHMOTshiadepj4jnnAVjW bUyatze5JuVrVnRvfbenFo6LkLwj3zA8Xd+wPI01mFC7mrANVq1Gz97cfl9sTgBQJ1e2 kzDQ9rzTuWXXIdSvmyClPQbZXHLTy9S8OsSUbVSAzj/4/bzolmPp1VsH73suEVoPVn19 FhjA== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dmarc-filter :dkim-signature:dkim-signature:arc-authentication-results; bh=6aK6B/elKHe95oYxfd9MlY0axYbg4bd5BlsB4P4c50U=; b=JcfIHqKope6+mlgUFKAUBEBrOknnnQBO7nrfSg3gKpSwf3qv8a9ToWhxG1D53qlxDX IUwOKrHlHWi1sf27BeFKmWckyxFhkw2r+RzPxB4FnZiFKF9T3aUuqBWZuaWnuUsxkIDF xYx9m+1U6FZIGdYpegiiXhxknJ78pMADh+khBFAlIsy5f8w3xDJCDHuUEFqaCDvIFWOZ G4pVc5sM7cZT7B8AaD/iKXKvhDBb1Y97ypQx/VVLsq1zdvSDe8QNnFv78F+Ir0evzbuA xpaRwPvy28T3/Ce30f+qr8ZcRFxSTm2TTOGpeBTocpYhWqWxI3ZNx0UUKIjOTpgjvmt0 nvJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=R2R3TEbs; dkim=pass header.i=@codeaurora.org header.s=default header.b=R2R3TEbs; 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 x61-v6si1726098plb.584.2018.02.02.04.55.00; Fri, 02 Feb 2018 04:55:14 -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=@codeaurora.org header.s=default header.b=R2R3TEbs; dkim=pass header.i=@codeaurora.org header.s=default header.b=R2R3TEbs; 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 S1752126AbeBBMx6 (ORCPT + 99 others); Fri, 2 Feb 2018 07:53:58 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:44722 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752118AbeBBMxi (ORCPT ); Fri, 2 Feb 2018 07:53:38 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id BF425601A0; Fri, 2 Feb 2018 12:53:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1517576017; bh=FuYw8X0vmXoYeCLGTtQX31NvGzE4f/NLRS9s4+yaYpM=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=R2R3TEbsC38O4zJqQb1b99XdMKg6qCtE+YY7LGTm7E71JEq61g2QqD1DHfKzxnMPM YZM0EtMCouND4D634n0Tb6qOP8bfNwaiURjuLekYwrE4XMbqwU0XrADEs3I1ELowjz J5lk/meweybXyUqdo9d4LmbCsr6BExQvqzZvZw+w= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from [10.204.79.19] (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: prsood@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 534B06076A; Fri, 2 Feb 2018 12:53:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1517576017; bh=FuYw8X0vmXoYeCLGTtQX31NvGzE4f/NLRS9s4+yaYpM=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=R2R3TEbsC38O4zJqQb1b99XdMKg6qCtE+YY7LGTm7E71JEq61g2QqD1DHfKzxnMPM YZM0EtMCouND4D634n0Tb6qOP8bfNwaiURjuLekYwrE4XMbqwU0XrADEs3I1ELowjz J5lk/meweybXyUqdo9d4LmbCsr6BExQvqzZvZw+w= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 534B06076A Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=prsood@codeaurora.org Subject: Re: Query related to usage of cpufreq_suspend() & cpufreq_resume To: "Rafael J. Wysocki" Cc: viresh.kumar@linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, gkohli@codeaurora.org, linux-arm-msm@vger.kernel.org References: <1949391.4ffJqIIJSQ@aspire.rjw.lan> From: Prateek Sood Message-ID: <7d50aeb5-cc2d-521b-2f31-5477e6e18f20@codeaurora.org> Date: Fri, 2 Feb 2018 18:23:32 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <1949391.4ffJqIIJSQ@aspire.rjw.lan> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 02/02/2018 05:18 PM, Rafael J. Wysocki wrote: > On Friday, February 2, 2018 12:41:58 PM CET Prateek Sood wrote: >> Hi Viresh, >> >> One scenario is there where a kernel panic is observed in >> cpufreq during suspend/resume. >> >> pm_suspend() >> suspend_devices_and_enter() >> dpm_suspend_start() >> dpm_prepare() >> >> Failure in dpm_prepare() happend with following dmesg: >> >> [ 3746.316062] PM: Device xyz not prepared for power transition: code -16 >> [ 3746.316071] PM: Some devices failed to suspend, or early wake event detected >> >> >> pm_suspend() >> suspend_devices_and_enter() >> dpm_suspend_start() >> dpm_prepare() //failed >> dpm_resume_end() >> dpm_resume() >> cpufreq_resume() >> cpufreq_start_governor() >> sugov_start() >> cpufreq_add_update_util_hook() >> >> After failure in dpm_prepare(), dpm_resume() called >> cpufreq_resume(). Corresponding cpufreq_suspend() was not >> called due to failure of dpm_prepare(). >> >> This resulted in WARN_ON(per_cpu(cpufreq_update_util_data, cpu)) >> in cpufreq_add_update_util_hook() and cpufreq_add_update_util_hook->func >> being inconsistent state. It caused crash in scheduler. >> >> Following are some of the ways to mitigate this issue. Could >> you please provide feedback on below two approaches or suugest >> a better way to fix this problem. >> >> -----------------------8<------------------------------ >> >> Co-developed-by: Gaurav Kohli >> Signed-off-by: Gaurav Kohli >> Signed-off-by: Prateek Sood >> >> diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c >> index 02a497e..732e5a2 100644 >> --- a/drivers/base/power/main.c >> +++ b/drivers/base/power/main.c >> @@ -1038,6 +1038,7 @@ void dpm_resume(pm_message_t state) >> { >> struct device *dev; >> ktime_t starttime = ktime_get(); >> + bool valid_resume = false; >> >> trace_suspend_resume(TPS("dpm_resume"), state.event, true); >> might_sleep(); >> @@ -1055,6 +1056,7 @@ void dpm_resume(pm_message_t state) >> } >> >> while (!list_empty(&dpm_suspended_list)) { >> + valid_resume = true; >> dev = to_device(dpm_suspended_list.next); >> get_device(dev); >> if (!is_async(dev)) { >> @@ -1080,7 +1082,8 @@ void dpm_resume(pm_message_t state) >> async_synchronize_full(); >> dpm_show_time(starttime, state, 0, NULL); >> >> - cpufreq_resume(); >> + if (valid_resume) >> + cpufreq_resume(); >> trace_suspend_resume(TPS("dpm_resume"), state.event, false); >> } >> >> --------------------8<-------------------------------------- >> >> Signed-off-by: Prateek Sood >> >> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c >> index 421f318..439eab8 100644 >> --- a/drivers/cpufreq/cpufreq.c >> +++ b/drivers/cpufreq/cpufreq.c >> @@ -1648,7 +1648,7 @@ void cpufreq_suspend(void) >> { >> struct cpufreq_policy *policy; >> >> - if (!cpufreq_driver) >> + if (!cpufreq_driver || cpufreq_suspended) >> return; >> >> if (!has_target() && !cpufreq_driver->suspend) >> @@ -1683,7 +1683,7 @@ void cpufreq_resume(void) >> struct cpufreq_policy *policy; >> int ret; >> >> - if (!cpufreq_driver) >> + if (!cpufreq_driver || !cpufreq_suspended) >> return; >> >> cpufreq_suspended = false; > > Since we have cpufreq_suspended already, the second one is better. > > Thanks, > Rafael > Thanks Rafael for the inputs, I will send a formal patch. -- Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc., is a member of Code Aurora Forum, a Linux Foundation Collaborative Project