Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp2656643ima; Mon, 22 Oct 2018 13:34:36 -0700 (PDT) X-Google-Smtp-Source: ACcGV624gG5AqxFVD7F37iWxUh34noxe9OIGM/oDl31ChiL4jWVRvkvv3+8CHGlniZOG2eyPX0Z6 X-Received: by 2002:a17:902:bc44:: with SMTP id t4-v6mr15004983plz.300.1540240476078; Mon, 22 Oct 2018 13:34:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540240476; cv=none; d=google.com; s=arc-20160816; b=IGn4zY1XJ+syJc95Aa1h7sNlyqpDGQLkSmE4npssbT3sM9y5aQDxBsgMOqkdgAHVI2 hJlzOzXMepdoihZv8fgO2OLwuA4s1mygLlV4F/hrd5z27G8nb/xvOdjcjRxG8+6m/6R+ H3Vv6uroHgLeC2KIK8ZrvWxZgP3btuDt9MjJtw0AXiXzB+fZxpNLZ+kd0fWpqNoGnBbQ w+IoXN1i1t7Kz3yvxUT+FCit7iX252jV6g1Vvq4EJhPWphYobQHavcr2VNVZeNty43TQ eoqyWt+9D+GuUDyvwxLdZkRBwVeboTwYNsAoC3mYBB1HjYpH/Xhi2RXioTyRuMCMc/UV cGQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:mime-version :message-id:date:dkim-signature; bh=8DIj4IRdM90qds78E1Podgiufp7Zvg6YWMRF56u4GjE=; b=jlf9zNCCU9KSNbmj0x+zbkVzOT9YM7Sua+psOdvIP4MF7W5xtn76HXXoRfNCELOQKt nkKbvP0h/eV/uBBfc0S+0hen2pjP2ZDt1h2xRMSjuT/8QjgzQY5i4IOoDpGx2SATJGG1 WGHFfKHtaO0DrxZFc/zd22RAUpQjWq+/e9yetbMQNTRede+IohC5TMLH/6idfWMguxcB +41HaixS3c5CyAfi74DPp5r8f0POAuzSa8AVDzKEU6P8/Hrdf9OabNqvmlDMLBKIbELe Tccywprk5tj+Qm9NL0lznwNHqtPPqgqDpi9vN6sKB918pAHRSkzxhfUwM7vBmnjhlci+ dylA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=KzVAlxWF; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v8-v6si4140174pga.6.2018.10.22.13.34.20; Mon, 22 Oct 2018 13:34:36 -0700 (PDT) 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=@google.com header.s=20161025 header.b=KzVAlxWF; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728686AbeJWEw0 (ORCPT + 99 others); Tue, 23 Oct 2018 00:52:26 -0400 Received: from mail-qk1-f201.google.com ([209.85.222.201]:51331 "EHLO mail-qk1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726166AbeJWEwZ (ORCPT ); Tue, 23 Oct 2018 00:52:25 -0400 Received: by mail-qk1-f201.google.com with SMTP id x75-v6so47037226qka.18 for ; Mon, 22 Oct 2018 13:32:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=8DIj4IRdM90qds78E1Podgiufp7Zvg6YWMRF56u4GjE=; b=KzVAlxWFoyLmGtUZPIaLxJyhUdxuXSmGzTegaON4i8DgLt5S3Qcnqhvnn6V/DrloVz OiJLRBNbWNMZGoxxCjdHzTs8T+wSSUF7drHV8h+OKIMBXm6M0p1UCRqwhwNeDCAI32+e vYQ7Bm1Mz+kiGbiuE9Lu+zsFoGl0ZfZZ14M0DT6CFIhEz3T1zEMwMO24iZ1JkAxsXe+x TCHUt12v2pgJAcGsOAi/LJtWss0Mc1ksakgcu9nrnmb9f48FpWC5UINsEtdjsBFHd9hj qZbsHRGd8m+oHF9/rF83TrcrVC45KweisKorX3IijLA8/m1c6a4PTxDgeDTpBeZkz7DZ LnXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=8DIj4IRdM90qds78E1Podgiufp7Zvg6YWMRF56u4GjE=; b=LxXbjA9wlGBBjNdWX9DctP5f2gB5CW5yiI8QwRFgo2pMb/NuyabC9hZgOyITYw4YML uUZqwoAeK22C+AUzPZhmlW3sjUpfHX2fGtAWa3IQpTs+tauGM+HlN+I/Fszl43CMsCMp 2Z1xEqkCAFAJtMZ7TMSNEOboDlDi2gJ0G4QUMBRsRaOAw7qhkYqjpcK+CitUwJ+0npJf LEgbCQnGpQgOPrEFlijl7dTTdtsEhji3C2tMW1Gz/nFMPO0jIiOcGWW47+AsKcBI0HIv y82/Csb8Lc0TXA5ERfUGQbJRdCU4xDsA7DddzyEvZ8yTcx6g/d2LsSRhQucbImuK+Juw fegQ== X-Gm-Message-State: AGRZ1gJQkpqEL4p7jTzffmzMnE9DHVmI4inTtMNYkisrqi95YK11K93h Srg7Qz1WT4mm8RHOMF1FwacnSx0XWabKwS/2oxGRnSCDY0Fbw2vnSOpHy/GmRQjbL6/PffEwNOR dK1QvviWES7XcKnIdgu0Ht6aEOq6rG7lbHT98rNMojwZzzKicqQbSa6bsWAhdeXQSkdAUHRjv X-Received: by 2002:a37:2b0d:: with SMTP id r13mr2786429qkh.38.1540240343545; Mon, 22 Oct 2018 13:32:23 -0700 (PDT) Date: Mon, 22 Oct 2018 14:32:17 -0600 Message-Id: <20181022203218.7007-1-zwisler@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.19.1.568.g152ad8e336-goog Subject: [PATCH 1/2] thermal: Add notifier call chain for hot/critical events From: Ross Zwisler To: linux-kernel@vger.kernel.org Cc: Duncan Laurie , Daniel Lezcano , Eduardo Valentin , Zhang Rui , linux-pm@vger.kernel.org, Ross Zwisler Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Duncan Laurie This will allow drivers to register a callback for important thermal events and log critical thresholds that cause the system to shut down. There are other places this might work, but after consideration I think it makes sense to have the chain at this level: The ACPI thermal driver has an existing notify function that is eventually called into, but that would limit the notifier to only working on systems that use ACPI. The cpufreq driver is already getting a notify callback executed in this path (tz->ops->notify) but the threshold info is not passed to the cpu_cooling notifier chain so it is not useful for logging. Signed-off-by: Duncan Laurie Reviewed-by: Olof Johansson Reviewed-by: Vincent Palatin [ rez: updated changelog for upstream ] Signed-off-by: Ross Zwisler --- drivers/thermal/thermal_core.c | 38 ++++++++++++++++++++++++++++++++++ include/linux/thermal.h | 4 ++++ 2 files changed, 42 insertions(+) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 6ab982309e6a0..e1f8764b3d9f9 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -313,12 +314,46 @@ static void monitor_thermal_zone(struct thermal_zone_device *tz) mutex_unlock(&tz->lock); } +static BLOCKING_NOTIFIER_HEAD(thermal_notifier_list); + +/** + * register_thermal_notifier - Register function to be called for + * critical thermal events. + * + * @nb: Info about notifier function to be called + * + * Currently always returns zero, as blocking_notifier_chain_register() + * always returns zero. + */ +int register_thermal_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_register(&thermal_notifier_list, nb); +} +EXPORT_SYMBOL(register_thermal_notifier); + +/** + * unregister_thermal_notifier - Unregister thermal notifier + * + * @nb: Hook to be unregistered + * + * Returns zero on success, or %-ENOENT on failure. + */ +int unregister_thermal_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_unregister(&thermal_notifier_list, nb); +} +EXPORT_SYMBOL(unregister_thermal_notifier); + + static void handle_non_critical_trips(struct thermal_zone_device *tz, int trip, enum thermal_trip_type trip_type) { tz->governor ? tz->governor->throttle(tz, trip) : def_governor->throttle(tz, trip); + + blocking_notifier_call_chain(&thermal_notifier_list, + trip_type, NULL); } /** @@ -385,6 +420,9 @@ static void handle_critical_trips(struct thermal_zone_device *tz, if (tz->ops->notify) tz->ops->notify(tz, trip, trip_type); + blocking_notifier_call_chain(&thermal_notifier_list, + trip_type, NULL); + if (trip_type == THERMAL_TRIP_CRITICAL) { dev_emerg(&tz->device, "critical temperature reached (%d C), shutting down\n", diff --git a/include/linux/thermal.h b/include/linux/thermal.h index 5f4705f46c2f9..b948344d55cab 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -542,4 +543,7 @@ static inline int thermal_generate_netlink_event(struct thermal_zone_device *tz, } #endif +extern int register_thermal_notifier(struct notifier_block *); +extern int unregister_thermal_notifier(struct notifier_block *); + #endif /* __THERMAL_H__ */ -- 2.19.1.568.g152ad8e336-goog