From patchwork Thu May 25 21:16:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Valentin X-Patchwork-Id: 686333 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5CD54C7EE29 for ; Thu, 25 May 2023 21:17:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235946AbjEYVRR (ORCPT ); Thu, 25 May 2023 17:17:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235747AbjEYVRQ (ORCPT ); Thu, 25 May 2023 17:17:16 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58112198; Thu, 25 May 2023 14:17:15 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DEE0464B2D; Thu, 25 May 2023 21:17:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 084DCC433D2; Thu, 25 May 2023 21:17:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685049434; bh=+BQpgA/b2ao3wMNuPjBRBOPHdCtlI4INTxsSIyFtPTs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dsBOLATfz/A+zYQ4T2Ms2FFPQ1PDBD40nWF5l0+hpk5LXR5PL33HsALvmL/lJi2pO i3r55klIrE96/DKSwIEYyyNBQncZXBsm9Ho/aFd6gYoY9Ui+sNz8Iw2nUXMnvGFRtT Djb488i7WWHH2AnwtNA6Uh1/+IjxE3+hHUHMfkRugQ6Gn2wHG+6CnZIBSPm5Vg48/g zbOqhK+Xq5EM58bxyHQKv/KOnegaXl2+MrMJ+fVI8qbM/mJWmR42IrTeJz7sHDNPSh 3YaJfTG0eqNbEORzg+krT5od6bYcm5BQGe2vEEQSjbZl5qpq/AJl5lAy3KhzZP85ha d5IHzB9XUspHg== From: Eduardo Valentin To: daniel.lezcano@linaro.org, rafael@kernel.org, linux-pm@vger.kernel.org Cc: Eduardo Valentin , Amit Kucheria , Zhang Rui , Jonathan Corbet , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] thermal: core: introduce governor .reboot_prepare() Date: Thu, 25 May 2023 14:16:53 -0700 Message-Id: <20230525211655.627415-2-evalenti@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230525211655.627415-1-evalenti@kernel.org> References: <20230525211655.627415-1-evalenti@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Eduardo Valentin This callback is used to notify the governors that reboot is coming up. Upon this event, this callback gives governors the opportunity to leave the thermal zones in a sane state prior to reboot. Cc: "Rafael J. Wysocki" (supporter:THERMAL) Cc: Daniel Lezcano (supporter:THERMAL) Cc: Amit Kucheria (reviewer:THERMAL) Cc: Zhang Rui (reviewer:THERMAL) Cc: Jonathan Corbet (maintainer:DOCUMENTATION) Cc: linux-pm@vger.kernel.org (open list:THERMAL) Cc: linux-doc@vger.kernel.org (open list:DOCUMENTATION) Cc: linux-kernel@vger.kernel.org (open list) Signed-off-by: Eduardo Valentin --- include/linux/thermal.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/linux/thermal.h b/include/linux/thermal.h index 82c8e09a63e0..d3c8af928522 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -201,6 +201,9 @@ struct thermal_zone_device { * below the trip point temperature * @check_error: callback called whenever temperature updates fail. * Opportunity for the governor to react on errors. + * @reboot_prepare: callback called upon system restart. + * Opportunity for the governor to tear down zones or at least + * leave them in a safe state. * @governor_list: node in thermal_governor_list (in thermal_core.c) */ struct thermal_governor { @@ -209,6 +212,7 @@ struct thermal_governor { void (*unbind_from_tz)(struct thermal_zone_device *tz); int (*throttle)(struct thermal_zone_device *tz, int trip); void (*check_error)(struct thermal_zone_device *tz, int error); + void (*reboot_prepare)(struct thermal_zone_device *tz); struct list_head governor_list; }; From patchwork Thu May 25 21:16:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Valentin X-Patchwork-Id: 685786 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3136C7EE2F for ; Thu, 25 May 2023 21:17:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239398AbjEYVRT (ORCPT ); Thu, 25 May 2023 17:17:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239784AbjEYVRS (ORCPT ); Thu, 25 May 2023 17:17:18 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00823194; Thu, 25 May 2023 14:17:16 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9177A64B2D; Thu, 25 May 2023 21:17:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE7C0C433D2; Thu, 25 May 2023 21:17:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685049436; bh=gEZ02IzSGf5PaaA4CSw9rHnl4VSwKJa0glxNZVbO8yg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dZ9cqp2i9MJ3BusPvHZ9HnVnuVpootCBf3eMhWPE5KFV12zK+eelDr4Xfo20BjHHX WM+NMD6XNdVhuH7cC7FQe7d2aWlaVhi/yO/jtBmTeA1fn+L1c0CW0mvdZ9ZyquWgTf X5vSVi8qP3j9kyFjL3rnr5aM4d0n6NCw5+jy/lrFaSTMbr/iPshcq6sDdmPleC3YKe pxCsak13k9+Q5I3AhVjDG4Aa8xoc/BGryO4RJWJMI8wxKdwkHHzNaW7l3rHopczC8a BnRL0f/80To2w9w845QQ6UTs1VR3uyajGqCECeDgqkMFiN1SalQyyAJFm4Kpjsz3hT TnEc018fzN8zA== From: Eduardo Valentin To: daniel.lezcano@linaro.org, rafael@kernel.org, linux-pm@vger.kernel.org Cc: Eduardo Valentin , Amit Kucheria , Zhang Rui , Jonathan Corbet , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] thermal: core: register reboot nb Date: Thu, 25 May 2023 14:16:54 -0700 Message-Id: <20230525211655.627415-3-evalenti@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230525211655.627415-1-evalenti@kernel.org> References: <20230525211655.627415-1-evalenti@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Eduardo Valentin This commit will register a reboot notifier block callback for giving opportunity tearing down thermal zones, e.g. remove their workqueues, and for giving the governors the opportunity to leave the hardware in a known safe state. Cc: "Rafael J. Wysocki" (supporter:THERMAL) Cc: Daniel Lezcano (supporter:THERMAL) Cc: Amit Kucheria (reviewer:THERMAL) Cc: Zhang Rui (reviewer:THERMAL) Cc: Jonathan Corbet (maintainer:DOCUMENTATION) Cc: linux-pm@vger.kernel.org (open list:THERMAL) Cc: linux-doc@vger.kernel.org (open list:DOCUMENTATION) Cc: linux-kernel@vger.kernel.org (open list) Signed-off-by: Eduardo Valentin --- drivers/thermal/thermal_core.c | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 359e7b2ff0e3..66a255fb650b 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -319,6 +319,12 @@ static void handle_error_temperature(struct thermal_zone_device *tz, int error) tz->governor->check_error(tz, error); } +static void handle_reboot_prepare(struct thermal_zone_device *tz) +{ + if (tz->governor && tz->governor->reboot_prepare) + tz->governor->reboot_prepare(tz); +} + void thermal_zone_device_critical(struct thermal_zone_device *tz) { /* @@ -1508,6 +1514,30 @@ struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name) } EXPORT_SYMBOL_GPL(thermal_zone_get_zone_by_name); +/* Best effort attempt to leave thermal zones at a safe state across reboots */ +static void thermal_reboot_prepare(void) +{ + struct thermal_zone_device *tz; + + list_for_each_entry(tz, &thermal_tz_list, node) { + cancel_delayed_work(&tz->poll_queue); + handle_reboot_prepare(tz); + } +} + +static int thermal_reboot_notify(struct notifier_block *nb, + unsigned long mode, void *_unused) +{ + switch (mode) { + case SYS_RESTART: + thermal_reboot_prepare(); + break; + default: + break; + } + return 0; +} + static int thermal_pm_notify(struct notifier_block *nb, unsigned long mode, void *_unused) { @@ -1539,6 +1569,10 @@ static struct notifier_block thermal_pm_nb = { .notifier_call = thermal_pm_notify, }; +static struct notifier_block thermal_reboot_nb = { + .notifier_call = thermal_reboot_notify, +}; + static int __init thermal_init(void) { int result; @@ -1572,6 +1606,11 @@ static int __init thermal_init(void) pr_warn("Thermal: Can not register suspend notifier, return %d\n", result); + result = register_reboot_notifier(&thermal_reboot_nb); + if (result) + pr_warn("Thermal: Can not register reboot notifier, return %d\n", + result); + return 0; unregister_governors: From patchwork Thu May 25 21:16:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Valentin X-Patchwork-Id: 686332 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4059AC7EE2C for ; Thu, 25 May 2023 21:17:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240328AbjEYVRU (ORCPT ); Thu, 25 May 2023 17:17:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236434AbjEYVRT (ORCPT ); Thu, 25 May 2023 17:17:19 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8327AA7; Thu, 25 May 2023 14:17:18 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 11BCC64B30; Thu, 25 May 2023 21:17:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31806C433D2; Thu, 25 May 2023 21:17:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685049437; bh=vEe5IMrxvZ6zjp9aBXSVRXJpxdUpiaH0SmaBoWt1Nqw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OOYzQrWxDyfJoP/3gDvkOTQNTcpl0mwqfLpe6KQap1/xPJQeBfJUO7RYyGvzhmOuc sPgFSRVBY8DV4AVO1YTcpbX0qw3yi5Js+zc/+dZaGt4wV37xEIipDxHW06FlMFjuJS vhwWXp7UusKlHg90Qnuj1QarpO195cnncgjbU6BeqloOqBAoQV2p2+pCfuYxEZ4DfS wuG4o0VNtGWIVVCvYlVEABI3tHoB6YJIm6aqZlu77Zk+HmElPGWrUGTaOsPEwe2T7i DhLUlRD2XTYi++pHyS0dkxF9zfYKKk60w69dvm63WpZqEam/N/P0avkG7br2V5agBS wHmG0E80/2V2Q== From: Eduardo Valentin To: daniel.lezcano@linaro.org, rafael@kernel.org, linux-pm@vger.kernel.org Cc: Eduardo Valentin , Amit Kucheria , Zhang Rui , Jonathan Corbet , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] thermal: core: register a crash callback Date: Thu, 25 May 2023 14:16:55 -0700 Message-Id: <20230525211655.627415-4-evalenti@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230525211655.627415-1-evalenti@kernel.org> References: <20230525211655.627415-1-evalenti@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Eduardo Valentin This commit will register a crash callback for the thermal subsystem, this way the thermal core can tear down the thermal zones and ask governors to leave the hardware in a known safe state prior upon the event of a crash. Cc: "Rafael J. Wysocki" (supporter:THERMAL) Cc: Daniel Lezcano (supporter:THERMAL) Cc: Amit Kucheria (reviewer:THERMAL) Cc: Zhang Rui (reviewer:THERMAL) Cc: Jonathan Corbet (maintainer:DOCUMENTATION) Cc: linux-pm@vger.kernel.org (open list:THERMAL) Cc: linux-doc@vger.kernel.org (open list:DOCUMENTATION) Cc: linux-kernel@vger.kernel.org (open list) Signed-off-by: Eduardo Valentin --- drivers/thermal/thermal_core.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 66a255fb650b..38b168b9245e 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -20,6 +20,7 @@ #include #include #include +#include #define CREATE_TRACE_POINTS #include "thermal_trace.h" @@ -1525,6 +1526,14 @@ static void thermal_reboot_prepare(void) } } +static int thermal_crash_notify(struct notifier_block *nb, + unsigned long mode, void *_unused) +{ + thermal_reboot_prepare(); + + return 0; +} + static int thermal_reboot_notify(struct notifier_block *nb, unsigned long mode, void *_unused) { @@ -1569,6 +1578,10 @@ static struct notifier_block thermal_pm_nb = { .notifier_call = thermal_pm_notify, }; +static struct notifier_block thermal_crash_nb = { + .notifier_call = thermal_crash_notify, +}; + static struct notifier_block thermal_reboot_nb = { .notifier_call = thermal_reboot_notify, }; @@ -1611,6 +1624,8 @@ static int __init thermal_init(void) pr_warn("Thermal: Can not register reboot notifier, return %d\n", result); + atomic_notifier_chain_register(&panic_notifier_list, + &thermal_crash_nb); return 0; unregister_governors: