Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751770AbbLaSsl (ORCPT ); Thu, 31 Dec 2015 13:48:41 -0500 Received: from mail-pa0-f53.google.com ([209.85.220.53]:34829 "EHLO mail-pa0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750857AbbLaSsi (ORCPT ); Thu, 31 Dec 2015 13:48:38 -0500 Date: Thu, 31 Dec 2015 10:48:27 -0800 From: Eduardo Valentin To: Chen Yu Cc: rui.zhang@intel.com, javi.merino@arm.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH 2/3][v3] Thermal: handle thermal zone device properly during system sleep Message-ID: <20151231184825.GA14486@localhost.localdomain> References: <1993b0ae972a5000a70f600fa16bc08969a65639.1446192980.git.yu.c.chen@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1993b0ae972a5000a70f600fa16bc08969a65639.1446192980.git.yu.c.chen@intel.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4388 Lines: 137 On Fri, Oct 30, 2015 at 04:31:58PM +0800, Chen Yu wrote: > From: Zhang Rui > > Current thermal code does not handle system sleep well because > 1. the cooling device cooling state may be changed during suspend > 2. the previous temperature reading becomes invalid after resumed because > it is got before system sleep > 3. updating thermal zone device during suspending/resuming > is wrong because some devices may have already been suspended > or may have not been resumed. > > Thus, the proper way to do this is to cancel all thermal zone > device update requirements during suspend/resume, and after all > the devices have been resumed, reset and update every registered > thermal zone devices. > > This also fixes a regression introduced by: > Commit 19593a1fb1f6 ("ACPI / fan: convert to platform driver") > Because, with above commit applied, all the fan devices are attached > to the acpi_general_pm_domain, and they are turned on by the pm_domain > automatically after resume, without the awareness of thermal core. > > CC: #3.18+ > Reference: https://bugzilla.kernel.org/show_bug.cgi?id=78201 > Reference: https://bugzilla.kernel.org/show_bug.cgi?id=91411 > Tested-by: Manuel Krause > Tested-by: szegad > Tested-by: prash > Tested-by: amish > Tested-by: Matthias > Reviewed-by: Javi Merino > Signed-off-by: Zhang Rui > Signed-off-by: Chen Yu Acked-by: Eduardo Valentin > --- > drivers/thermal/thermal_core.c | 42 ++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 42 insertions(+) > > diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c > index 682bc1e..9aae767 100644 > --- a/drivers/thermal/thermal_core.c > +++ b/drivers/thermal/thermal_core.c > @@ -37,6 +37,7 @@ > #include > #include > #include > +#include > > #define CREATE_TRACE_POINTS > #include > @@ -59,6 +60,8 @@ static LIST_HEAD(thermal_governor_list); > static DEFINE_MUTEX(thermal_list_lock); > static DEFINE_MUTEX(thermal_governor_lock); > > +static atomic_t in_suspend; > + > static struct thermal_governor *def_governor; > > static struct thermal_governor *__find_governor(const char *name) > @@ -554,6 +557,9 @@ void thermal_zone_device_update(struct thermal_zone_device *tz) > { > int count; > > + if (atomic_read(&in_suspend)) > + return; > + > if (!tz->ops->get_temp) > return; > > @@ -2155,6 +2161,36 @@ static void thermal_unregister_governors(void) > thermal_gov_power_allocator_unregister(); > } > > +static int thermal_pm_notify(struct notifier_block *nb, > + unsigned long mode, void *_unused) > +{ > + struct thermal_zone_device *tz; > + > + switch (mode) { > + case PM_HIBERNATION_PREPARE: > + case PM_RESTORE_PREPARE: > + case PM_SUSPEND_PREPARE: > + atomic_set(&in_suspend, 1); > + break; > + case PM_POST_HIBERNATION: > + case PM_POST_RESTORE: > + case PM_POST_SUSPEND: > + atomic_set(&in_suspend, 0); > + list_for_each_entry(tz, &thermal_tz_list, node) { > + thermal_zone_device_reset(tz); > + thermal_zone_device_update(tz); > + } > + break; > + default: > + break; > + } > + return 0; > +} > + > +static struct notifier_block thermal_pm_nb = { > + .notifier_call = thermal_pm_notify, > +}; > + > static int __init thermal_init(void) > { > int result; > @@ -2175,6 +2211,11 @@ static int __init thermal_init(void) > if (result) > goto exit_netlink; > > + result = register_pm_notifier(&thermal_pm_nb); > + if (result) > + pr_warn("Thermal: Can not register suspend notifier, return %d\n", > + result); > + > return 0; > > exit_netlink: > @@ -2194,6 +2235,7 @@ error: > > static void __exit thermal_exit(void) > { > + unregister_pm_notifier(&thermal_pm_nb); > of_thermal_destroy_zones(); > genetlink_exit(); > class_unregister(&thermal_class); > -- > 1.8.4.2 > -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/