From patchwork Mon Oct 22 20:32:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Zwisler X-Patchwork-Id: 10652469 X-Patchwork-Delegate: rui.zhang@intel.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2253213B5 for ; Mon, 22 Oct 2018 20:32:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 21B612905C for ; Mon, 22 Oct 2018 20:32:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1419B290A2; Mon, 22 Oct 2018 20:32:26 +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=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL 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 942F22905C for ; Mon, 22 Oct 2018 20:32:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727701AbeJWEw0 (ORCPT ); Tue, 23 Oct 2018 00:52:26 -0400 Received: from mail-qk1-f201.google.com ([209.85.222.201]:34573 "EHLO mail-qk1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726169AbeJWEwZ (ORCPT ); Tue, 23 Oct 2018 00:52:25 -0400 Received: by mail-qk1-f201.google.com with SMTP id y201-v6so47981940qka.1 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=L7P1ay4GIsopXIGgRZJcLyaP5N4dQXsUkfX5YVuHSMI+MjXDdeOPrZ6kuw6JkQzlFm ohNkGdeQ0MBF93wkPzr76BsqEawNOorkVYSIHLN9jcPwpDDwxVT436tntKS5REOklEfu b8MQ6aiTXCnCblaTnMJ66VlDFuX+oYlHiDWcQNBGiDfhTfq3Zjmk/1TV4vBaZKX49TPT WyAEFDQAAD+8tq2e1AeOkyuVCFne6ZvqUU7Q2eyPGA/v+ixBPQyg5L/vTpOtcvA+C7C3 Kjsg2UWQDB4+jPHXMXgIEAsD2MSN932WSTmLEHwh3hADG2/zzsBFIAbPlkivapDssGt3 ZlCg== X-Gm-Message-State: AGRZ1gLAsYBoBywCvjX1gOM/wfSQCT16uPn9n7wb/TFXS26zynmoLkAR x/LHMio2ZxyPdLUCx9eSmWNDj9GsNzVx X-Google-Smtp-Source: AJdET5eWzeQiRF+3Z0Zz7VQNi+XuGvtAcFwNquHMMxK3m8i3QHXaIsdv3NVvGojLvsSR/fAF1Psrqk/BN/t1 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 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 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__ */ From patchwork Mon Oct 22 20:32:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Zwisler X-Patchwork-Id: 10652471 X-Patchwork-Delegate: rui.zhang@intel.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9AF0713B5 for ; Mon, 22 Oct 2018 20:32:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB29E2905C for ; Mon, 22 Oct 2018 20:32:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9FB53290A2; Mon, 22 Oct 2018 20:32:29 +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=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL 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 392432905C for ; Mon, 22 Oct 2018 20:32:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726166AbeJWEw2 (ORCPT ); Tue, 23 Oct 2018 00:52:28 -0400 Received: from mail-qt1-f202.google.com ([209.85.160.202]:52017 "EHLO mail-qt1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728748AbeJWEw1 (ORCPT ); Tue, 23 Oct 2018 00:52:27 -0400 Received: by mail-qt1-f202.google.com with SMTP id w5-v6so13790777qto.18 for ; Mon, 22 Oct 2018 13:32:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=qBkcULrk24lGYqTEeJPSqpxDS/GL/T8SH7WD8YBNpus=; b=EI2qS340NBQET5Mg5nPhP4aVB2ya2DI6ZnTdAQBQRROnGzihSXYVl9NGcOp51g+w1Q 16wCHIv1TtcHHFUzffZP0mrcMsomH02bIUPQM4cd4IWH1/EpoyQPCUNYybTQLt9UOtBk WFjhk6o50sbI43ObRR9uS/krPjeQNKJjIV3lAztiDMZYTFP0ofxj/gkG9dy5bZpxdTDT x7BjhrlJpAakuVwUHNXQBkSl2LmRgSrtHnbSg9As62BFNsc9CFbhRq/BIRNKSWKLjpL3 9EwiWk+WKYQVAAuTvbyCt+UTiwAyEsewQ58XZo1+VoYAvVauyHu4uByEqWR6vIpYE2KW BX4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=qBkcULrk24lGYqTEeJPSqpxDS/GL/T8SH7WD8YBNpus=; b=gnsgdNFDdchIIM1AQZ+P1bMXFWyrOsS6E4V2g2HNd/lzlpF+rj+Z3dcIXYSsfDJCpi i0FYDPbJmGx6Uy2sPYnl7SS2ph+nNHeylMh7tkQkHqd3uzHXAIDWFieAEtgH59KI6+gB 6KPGpVIKEC4EshhhPiUAHC7JpZUSu4rJTd49WTB1/l1jwuVSfGptLBgXe+Hi2BogBtbV KDof2kqOt1TGE0sN//n/tNqU4msIW0NSNFI6ZRdhInQPcon3Yn6z2FFgPqT2H+etbtSE zEAOiYB4K+4TQhlRqNGisnioJD0vtdSyMibbUfUSF8cUhckSvMBP6abg0nYhIFJowP/L XKHQ== X-Gm-Message-State: ABuFfoiIDsRBmIFXc1i9jLAU7ouM8BE1yG0kDXJibxr65R4RJ3J3E/RN jsY6iiHyEnU7XGJrcEstwnTHYrmONlsZ X-Google-Smtp-Source: ACcGV61oElCFzWpPPkjREg2GM1wmlI1Gbr81pf8+hAHR1llM3hQRmpJ9y8EnQ6g/yPd7uYRlDqzL4DDYdNLx X-Received: by 2002:ac8:6993:: with SMTP id o19-v6mr11319241qtq.35.1540240345255; Mon, 22 Oct 2018 13:32:25 -0700 (PDT) Date: Mon, 22 Oct 2018 14:32:18 -0600 In-Reply-To: <20181022203218.7007-1-zwisler@google.com> Message-Id: <20181022203218.7007-2-zwisler@google.com> Mime-Version: 1.0 References: <20181022203218.7007-1-zwisler@google.com> X-Mailer: git-send-email 2.19.1.568.g152ad8e336-goog Subject: [PATCH 2/2] gsmi: Log event for critical thermal thresholds 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 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 From: Duncan Laurie This registers a notifier for the new thermal notifier introduced in a previous commit and logs a kernel shutdown event when the notifier is called for crossing the THERMAL_TRIP_CRITICAL threshold. To test: 1) Modify critical shutdown threshold in the BIOS 2) Generate a load on the system to increase temperature 3) Wait until system powers off 4) Power back on and read the event log: 4 | 2012-07-18 10:47:02 | Kernel Event | Critical Thermal Threshold 5 | 2012-07-18 10:47:06 | Kernel Event | Clean Shutdown 6 | 2012-07-18 10:47:06 | ACPI Enter | S5 Signed-off-by: Duncan Laurie Reviewed-by: Vincent Palatin Reviewed-by: Olof Johansson [ rez: updated changelog for upstream ] Signed-off-by: Ross Zwisler --- drivers/firmware/google/gsmi.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/firmware/google/gsmi.c b/drivers/firmware/google/gsmi.c index c8f169bf2e27d..ee0c611b83e99 100644 --- a/drivers/firmware/google/gsmi.c +++ b/drivers/firmware/google/gsmi.c @@ -29,6 +29,7 @@ #include #include #include +#include #define GSMI_SHUTDOWN_CLEAN 0 /* Clean Shutdown */ /* TODO(mikew@google.com): Tie in HARDLOCKUP_DETECTOR with NMIWDT */ @@ -40,6 +41,7 @@ #define GSMI_SHUTDOWN_SOFTWDT 6 /* Software Watchdog */ #define GSMI_SHUTDOWN_MBE 7 /* Uncorrected ECC */ #define GSMI_SHUTDOWN_TRIPLE 8 /* Triple Fault */ +#define GSMI_SHUTDOWN_THERMAL 9 /* Critical Thermal Threshold */ #define DRIVER_VERSION "1.0" #define GSMI_GUID_SIZE 16 @@ -670,6 +672,18 @@ static struct notifier_block gsmi_panic_notifier = { .notifier_call = gsmi_panic_callback, }; +static int gsmi_thermal_callback(struct notifier_block *nb, + unsigned long reason, void *arg) +{ + if (reason == THERMAL_TRIP_CRITICAL) + gsmi_shutdown_reason(GSMI_SHUTDOWN_THERMAL); + return NOTIFY_DONE; +} + +static struct notifier_block gsmi_thermal_notifier = { + .notifier_call = gsmi_thermal_callback +}; + /* * This hash function was blatantly copied from include/linux/hash.h. * It is used by this driver to obfuscate a board name that requires a @@ -892,6 +906,7 @@ static __init int gsmi_init(void) goto out_remove_sysfs_files; } + register_thermal_notifier(&gsmi_thermal_notifier); register_reboot_notifier(&gsmi_reboot_notifier); register_die_notifier(&gsmi_die_notifier); atomic_notifier_chain_register(&panic_notifier_list, @@ -918,6 +933,7 @@ static __init int gsmi_init(void) static void __exit gsmi_exit(void) { + unregister_thermal_notifier(&gsmi_thermal_notifier); unregister_reboot_notifier(&gsmi_reboot_notifier); unregister_die_notifier(&gsmi_die_notifier); atomic_notifier_chain_unregister(&panic_notifier_list,