From patchwork Fri Feb 2 11:41:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prateek Sood X-Patchwork-Id: 10196483 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8E1D860388 for ; Fri, 2 Feb 2018 11:42:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8000A28DFE for ; Fri, 2 Feb 2018 11:42:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7339D28E30; Fri, 2 Feb 2018 11:42:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 64C5A28DFE for ; Fri, 2 Feb 2018 11:42:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751611AbeBBLmP (ORCPT ); Fri, 2 Feb 2018 06:42:15 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:60766 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750773AbeBBLmN (ORCPT ); Fri, 2 Feb 2018 06:42:13 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 28BCC606AC; Fri, 2 Feb 2018 11:42:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1517571733; bh=o0yL/0/2q9oXruQ4/z3rHQT1vbvrhm2Bn2lkxPt0Zrs=; h=To:Cc:From:Subject:Date:From; b=fQ6aCZNliOAE2WBNw4OR9wBfrUwKzcsX+1ZGOcAjQ/QFUc1zsAYHHMsWnRnSAgYTU 8DeVV1q4fxmETujQyQo2+82xC1I0Cn3Djj6/xIeYkrR/R29HoyeI6ZrD9axNUtOYw4 6V2fdxOusT+CdZe5KII6eOW1gnDSN4zUdffSPCNc= 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 8524A606AC; Fri, 2 Feb 2018 11:42:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1517571732; bh=o0yL/0/2q9oXruQ4/z3rHQT1vbvrhm2Bn2lkxPt0Zrs=; h=To:Cc:From:Subject:Date:From; b=HkbpFpmqwJyI+/R9RC159qUD83CrmgIOwQhOEN3gU2su3vhpAp7SX1EFv9d+y2yHS VNP35ZinmtlrdoN/rm+hV2aycNqCUNJDulpinriqwzMUaFXk2t8JYL45v6NZWprFks gFAVUkUZt1LEF0ZSY51qgUsuu+eyOvqUQLhuRwxY= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 8524A606AC 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 To: viresh.kumar@linaro.org Cc: rjw@rjwysocki.net, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, gkohli@codeaurora.org, linux-arm-msm@vger.kernel.org From: Prateek Sood Subject: Query related to usage of cpufreq_suspend() & cpufreq_resume Message-ID: Date: Fri, 2 Feb 2018 17:11:58 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 Content-Language: en-US Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Thanks 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;